Save the screen as an image and use vs2008 for compilation.
View plaincopy to clipboardprint?
-
- # Include "stdafx. H"
-
- # Include <windows. h>
-
- # Include <atlimage. h>
-
-
- Int _ stdcall winmain (
-
- Hinstance,
-
- Hinstance hprevinstance,
-
- Lpstr lpcmdline,
- Int nshowcmd)
-
- {
-
- Hwnd =: getdomaintopwindow ();
-
- HDC =: getdc (hwnd); // obtain the screen DC
-
-
- Rect;
-
- : Getclientrect (hwnd, & rect );// Obtain the screen size
-
- HDC hdcmem =: createcompatibledc (HDC); // create compatible DC
-
-
- Hbitmap =: createcompatiblebitmap (HDC, rect. Right, rect. Bottom); // create a compatible bitmap
- Hbitmap holdmap = (hbitmap): SelectObject (hdcmem, hbitmap); // select the bitmap into the DC and save the returned value.
-
-
- : Bitblt (hdcmem, 0, 0, rect. Right, rect. Bottom, HDC, 0, 0, srccopy );// Copy the DC image of the screen to the memory DC
-
-
- Cimage image;
-
- Image. Attach (hbitmap );
-
- Image. Save (_ T ("C: \ B .jpg"); // if the file suffix is .bmp, save it as BMP.
-
- Image. Detach ();
-
-
- : SelectObject (hdcmem, holdmap );// Select the last returned value
-
- // Release
-
- : Deleteobject (hbitmap );
-
- : Deletedc (hdcmem );
-
- : Deletedc (HDC );
-
-
- Return 0;
-
- }
# Include "stdafx. H "# include <windows. h> # include <atlimage. h> int _ stdcall winmain (hinstance, hinstance hprevinstance, lpstr lpcmdline, int nshowcmd) {hwnd =: get1_topwindow (); HDC =: getdc (hwnd ); // obtain the screen DC rect;: getclientrect (hwnd, & rect); // obtain the screen size HDC hdcmem =: createcompatibledc (HDC ); // create compatible DC hbitmap =: createcompatiblebitmap (HDC, rect. right, rect. bottom); // create a compatible bitmap hbitmap holdmap = (hbitmap): SelectObject (hdcmem, hbitmap); // select the bitmap into the DC and save the returned value: bitblt (hdcmem, 0, 0, rect. right, rect. bottom, HDC, 0, 0, srccopy); // copy the DC image to the memory DC. attach (hbitmap); image. save (_ T ("C: \ B .jpg"); // if the file suffix is .bmp, save it as a BMP image. detach ();: SelectObject (hdcmem, holdmap); // select the last returned value // release: deleteobject (hbitmap);: deletedc (hdcmem );:: deletedc (HDC); Return 0 ;}
Set the current MFCProgram(Here is a single document program) Save as an image, use vs2005. The first one uses the cimage class to save the image, and the second one uses bitmapinfo.
Save the screen as an image Save the current MFC program as an image C ++ VC
Favorites
Save the screen as an image and use vs2008 for compilation.
View plaincopy to clipboardprint?
-
- # Include "stdafx. H"
-
- # Include <windows. h>
-
- # Include <atlimage. h>
-
-
- Int _ stdcall winmain (
-
- Hinstance,
-
- Hinstance hprevinstance,
- Lpstr lpcmdline,
-
- Int nshowcmd)
-
- {
-
- Hwnd =: getdomaintopwindow ();
-
- HDC =: getdc (hwnd); // obtain the screen DC
-
-
- Rect;
-
- : Getclientrect (hwnd, & rect );// Obtain the screen size
-
- HDC hdcmem =: createcompatibledc (HDC); // create compatible DC
-
- Hbitmap =: createcompatiblebitmap (HDC, rect. Right, rect. Bottom); // create a compatible bitmap
-
- Hbitmap holdmap = (hbitmap): SelectObject (hdcmem, hbitmap); // select the bitmap into the DC and save the returned value.
-
-
- : Bitblt (hdcmem, 0, 0, rect. Right, rect. Bottom, HDC, 0, 0, srccopy );// Copy the DC image of the screen to the memory DC
-
-
- Cimage image;
-
- Image. Attach (hbitmap );
-
- Image. Save (_ T ("C: \ B .jpg"); // if the file suffix is .bmp, save it as BMP.
-
- Image. Detach ();
-
- : SelectObject (hdcmem, holdmap );// Select the last returned value
-
-
- // Release
-
- : Deleteobject (hbitmap );
-
- : Deletedc (hdcmem );
-
- : Deletedc (HDC );
-
-
- Return 0;
-
- }
# Include "stdafx. H "# include <windows. h> # include <atlimage. h> int _ stdcall winmain (hinstance, hinstance hprevinstance, lpstr lpcmdline, int nshowcmd) {hwnd =: get1_topwindow (); HDC =: getdc (hwnd ); // obtain the screen DC rect;: getclientrect (hwnd, & rect); // obtain the screen size HDC hdcmem =: createcompatibledc (HDC ); // create compatible DC hbitmap =: createcompatiblebitmap (HDC, rect. right, rect. bottom); // create a compatible bitmap hbitmap holdmap = (hbitmap): SelectObject (hdcmem, hbitmap); // select the bitmap into the DC and save the returned value: bitblt (hdcmem, 0, 0, rect. right, rect. bottom, HDC, 0, 0, srccopy); // copy the DC image to the memory DC. attach (hbitmap); image. save (_ T ("C: \ B .jpg"); // if the file suffix is .bmp, save it as a BMP image. detach ();: SelectObject (hdcmem, holdmap); // select the last returned value // release: deleteobject (hbitmap);: deletedc (hdcmem );:: deletedc (HDC); Return 0 ;}
Save the current MFC Program (here is a single document program) as an image and use vs2005. The first one uses the cimage class to save the image, and the second one uses bitmapinfo.
First:
View plaincopy to clipboardprint?
-
- Void cmainframe: ongetmap ()
-
- {
-
-
- Hwnd = This-> getsafehwnd ();
-
- HDC =: getwindowdc (hwnd); // obtain the DC
-
-
-
- Rect;
-
- : Getwindowrect (hwnd, & rect );// Obtain the screen size
- HDC hdcmem =: createcompatibledc (HDC); // create compatible DC
-
-
- Hbitmap =: createcompatiblebitmap (HDC, rect. right-rect.left, rect. bottom-rect.top); // create compatible bitmap
-
- Hbitmap holdmap = (hbitmap): SelectObject (hdcmem, hbitmap); // select the bitmap into the DC and save the returned value.
-
-
- : Bitblt (hdcmem, 0, 0, rect. right-rect.left, rect. bottom-rect.top, HDC, 0, 0, srccopy );// Copy the DC image of the screen to the memory DC
-
- Cimage image;// Required # include <atlimage. h>
-
- Image. Attach (hbitmap );
-
- Image. Save (_ T ("C: \ B .jpg"); // if the file suffix is .bmp, save it as BMP.
-
- Image. Detach ();
-
-
- : SelectObject (hdcmem, holdmap );// Select the last returned value
-
-
- // Release
-
- : Deleteobject (hbitmap );
-
- : Deletedc (hdcmem );
- : Deletedc (HDC );
-
- }
Void cmainframe: ongetmap () {hwnd = This-> getsafehwnd (); HDC =:: getwindowdc (hwnd); // obtain DC rect ;:: getwindowrect (hwnd, & rect); // obtain the screen size HDC hdcmem =: createcompatibledc (HDC); // create compatible DC hbitmap =: createcompatiblebitmap (HDC, rect. right-rect.left, rect. bottom-rect.top); // create compatible bitmap hbitmap holdmap = (hbitmap): SelectObject (hdcmem, hbitmap); // select the bitmap to DC and save the returned value: bitblt (hdcmem, 0, 0, rect. right-rect.left, rect. bottom-rect.top, HDC, 0, 0, srccopy); // copy the screen DC image to the memory DC cimage image; // need # include <atlimage. h> image. attach (hbitmap); image. save (_ T ("C: \ B .jpg"); // if the file suffix is .bmp, save it as a BMP image. detach ();: SelectObject (hdcmem, holdmap); // select the last returned value // release: deleteobject (hbitmap);: deletedc (hdcmem );:: deletedc (HDC );}
Second:
- Void cmainframe: ongetmap ()
-
- {
-
-
- CDC * PDC = getwindowdc ();
-
- Cbitmap bitmap;
-
- CDC memdc;
-
- Crect rect;
-
- Getwindowrect (rect );
-
- Memdc. createcompatibledc (PDC );
-
-
- Bitmap. createcompatiblebitmap (PDC, rect. Width (), rect. Height ());
-
- Memdc. SelectObject (& Bitmap );
- Memdc. bitblt (0, 0, rect. Width (), rect. Height (), PDC, 0, srccopy );
-
-
- Cfiledialog fdlg (false, _ T ("BMP"), null, ofn_hidereadonly | ofn_overwriteprompt, _ T ("bitmap file | *. BMP"), this );
-
- If (fdlg. domodal () = idok)
-
- {
-
-
- Cstring BMP file = fdlg. getpathname ();
-
-
- Cfile file (BMP file, cfile: modecreate | cfile: modewrite );
-
- Bitmap binfo;
-
- Bitmap. getbitmap (& binfo );
-
-
- // Calculate the palette size
-
- Int panelsize = 0;
-
- If (binfo. bmbitspixel <24) // non-real color
-
- {
-
- Panelsize = POW ((Double) 2, binfo. bmbitspixel) * sizeof (rgbquad );
-
- }
-
- // Define bitmap Information
-
- Bitmapinfo * bmapinfo = (bitmapinfo *) localalloc (lptr,Sizeof (bitmapinfo) + panelsize );
-
- Bmapinfo-> bmiheader. bibitcount = binfo. bmbitspixel;
-
- Bmapinfo-> bmiheader. biclrimportant = 0;
-
- Bmapinfo-> bmiheader. bicompression = 0;
-
- Bmapinfo-> bmiheader. biheight = binfo. bmheight;
- Bmapinfo-> bmiheader. biplanes = binfo. bmplanes;
-
- Bmapinfo-> bmiheader. bisize =Sizeof (bitmapinfo );
-
- Bmapinfo-> bmiheader. bisizeimage = binfo. bmheight * binfo. bmwidthbytes;
-
- Bmapinfo-> bmiheader. biwidth = binfo. bmwidth;
-
- Bmapinfo-> bmiheader. bixpelspermeter = 0;
-
- Bmapinfo-> bmiheader. biypelspermeter = 0;
-
- // Obtain the actual bitmap data
-
- Char * pdata = new char [bmapinfo-> bmiheader. bisizeimage];
-
- Int Len = getdibits (PDC-> m_hdc, bitmap, 0, binfo. bmheight, pdata, bmapinfo, dib_rgb_colors );
-
-
- Bitmapfileheader bfileheader;
-
- Bfileheader. bftype = 0x4d42;
-
- Bfileheader. bfreserved1 = 0;
-
- Bfileheader. bfreserved2 = 0;
- Bfileheader. bfsize =Sizeof (bitmapfileheader );
-
- Bfileheader. bfoffbits =Sizeof (bitmapfileheader) + sizeof (bitmapinfoheader) + panelsize;
-
-
- // Write bitmap data to the file
-
- File. Write (& bfileheader,Sizeof (bitmapfileheader ));
-
- File. Write (& bmapinfo-> bmiheader,Sizeof (bitmapinfoheader ));
-
- File. Write (pdata, bmapinfo-> bmiheader. bisizeimage + panelsize );
- File. Close ();
-
- Delete pdata;
-
- Localfree (bmapinfo );
-
- }
-
- Bitmap. deleteobject ();
-
- Memdc. deletedc ();
-
-
- }