Capture all the GUI Windows ' Image that Running on the Desktop

Source: Internet
Author: User


Here I captured all the GUI images this running on the desktop including the GUI that running on the virtual desktop that is created via "task View" under WIN 10.

Please note that the GUI-is-in minimize status cannot are captured in this method. Also, the Internet Explorer cannot is captured with this method.

#include <gdiplus.h>using namespace Gdiplus; Gdiplusstartupinput Gdiplusstartupinput; ULONG_PTR Gdiplustoken; BOOL Cvirtualdesktopdlg::oninitdialog () {cdialogex::oninitdialog ();//Set The icon for this dialog.    The framework does this automatically//when the application's main window is not a Dialogseticon (M_hicon, TRUE);    Set Big Iconseticon (M_hicon, FALSE); Set Small icon//Todo:add extra initialization heregdiplusstartup (&gdiplustoken, &gdiplusstartupinput, NULL) ; Std::ofstream mylog ("MyLog.log"); cwnd* Pdesktopwnd = Cwnd::getdesktopwindow (); cwnd* pWnd = Pdesktopwnd->getwindow (gw_child); int jpgnum = 0;while (pWnd! = NULL) {mylog << "number:" << jpg Num << Endl; CString strClassName = _t ("");:: GetClassName (Pwnd->getsafehwnd (), Strclassname.getbuffer (), MyLog < < "class Name\t:" << (CT2A) (LPCTSTR) strClassName << Endl; CString Strwindowtext = _t ("");:: GetWindowText (Pwnd->getsafehwnd (), Strwindowtext.getbuffer (256),MyLog << "window text\t:" << (CT2A) (LPCTSTR) Strwindowtext << Endl;char jpgfilename[1024]; sprintf_s (Jpgfilename, "jpg_%d.jpg", jpgnum++);//jpgfilename. Format (_t ("jpg_%d"), jpgnum++); Uses_conversion;savedesktoptojpg (A2T (jpgfilename), pwnd->m_hwnd);p wnd = Pwnd->getwindow (GW_HWNDNEXT);} Mylog.close (); return TRUE; Return TRUE unless you set the focus to a control}void cvirtualdesktopdlg::savedesktoptojpg (TCHAR *jpgfilepathname, hwn D hwnd) {//get desktop Dc/*hwnd Hdeskwnd =:: GetDesktopWindow (); CDC *PDESTDC = Cdc::fromhandle (:: GetDC (Hdeskwnd)); */CDC *pdestdc = Cdc::fromhandle (:: GetDC (hwnd)); int screenwidth = Pdestdc->getdevicecaps (horzres); int screenheight = Pdestdc->getdevicecaps (vertres);//Create Bitmap Comatible with Desktopcbitmap Membitmap;membitmap.createcompatiblebitmap (PDESTDC, ScreenWidth, screenHeight);// Create memory DC for DESKTOPCDC Memdc;memdc.createcompatibledc (PDESTDC); Memdc.selectobject (&membitmap);//copy Desktop DC to the MEMEry dcmemdc.bitblt (0, 0, screenwidth, screenheight, PDESTDC, 0, 0, srccopy);//obtain the bitmap informationbitmap bmpInfo; Membitmap.getbitmap (&bmpinfo);//generate bitmapinfobitmapinfo m_bitmapinfo;memset (&m_BITMAPINFO, 0, sizeof (Bitmapinfo)); m_BITMAPINFO.bmiHeader.biSize = sizeof (bitmapinfo); m_BITMAPINFO.bmiHeader.biPlanes = 1;m_ BITMAPINFO.bmiHeader.biBitCount = Bmpinfo.bmbitspixel;m_bitmapinfo.bmiheader.bicompression = Bi_rgb;m_ BITMAPINFO.bmiHeader.biWidth = Bmpinfo.bmwidth;m_bitmapinfo.bmiheader.biheight = bmpinfo.bmheight;//get the data of bitmapbyte* pbuffer = new Byte[bmpinfo.bmwidthbytes*bmpinfo.bmheight]; GetDIBits (MEMDC.M_HDC, (hbitmap) membitmap.m_hobject, 0, ScreenHeight, pbuffer, (Lpbitmapinfo) &m_BITMAPINFO, DIB_ rgb_colors);//generate bitmapbitmap *psrcbmp = Bitmap::frombitmapinfo (&m_bitmapinfo, (void*) pBuffer);//save to Jpgclsid Encoderclsid; Getencoderclsid (L "Image/jpeg", &encoderclsid);//Psrcbmp->save (L "d:\\desktop.jpg", &encoderclsid); Psrcbmp-> Save (Jpgfilepathname, &encoderclsid);d elete psrcbmp;delete pbuffer; ReleaseDC (PDESTDC);} int Cvirtualdesktopdlg::getencoderclsid (const wchar* format, clsid* pClsid) {/*the preceding code produces the following O Utput:image/bmpimage/jpegimage/gifimage/x-emfimage/x-wmfimage/tiffimage/pngimage/x-icon*/uint num = 0; Number of image decodersuint size = 0; Size, in bytes, of the image decoder arrayimagecodecinfo* Pimagecodecinfo = null;//How many decoders is there?//how Big (in bytes) are the array of all ImageCodecInfo objects? Getimageencoderssize (&num, &size); if (size = = 0) {return-1;} Create a buffer large enough to hold the array of imagecodecinfo//objects that'll be returned by Getimagedecoders.pi Magecodecinfo = (imagecodecinfo*) (malloc (size)); if (pimagecodecinfo = = NULL) {return-1;} Getimagedecoders creates an array of ImageCodecInfo objects//and copies that array into a previously allocated buffer. The third argument, Imagecodecinfos, is a pointer to that BUffer. Getimageencoders (num, size, pimagecodecinfo); for (UINT j = 0; j< num; ++j) {if (wcscmp (PIMAGECODECINFO[J). MimeType, format) = = 0) {*pclsid = Pimagecodecinfo[j]. Clsid;free (Pimagecodecinfo); return J; Success}}free (pimagecodecinfo); return-1; Failure

Rusult:

File: <mylog.log>

number:0
Class Name:msctfime UI
Window Text:msctfime UI
Number:1
Class Name:ime
Window Text:default IME
Number:2
Class Name:msctfime UI
Window Text:msctfime UI
Number:3
Class Name:ime
Window Text:default IME
Number:4
Class Name:foregroundstaging
Window text:
Number:5
Class Name:foregroundstaging
Window text:
Number:6
Class Name:tasklistthumbnailwnd
Window text:
Number:7
Class Name:tooltips_class32
Window text:
Number:8
Class Name:tooltips_class32
Window text:

Capture all the GUI Windows ' Image that Running on the Desktop

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.