The printwindow function, cximage, and gsoap are used to hide the window, capture the image to JPEG, and upload the image to the server through WebService.

Source: Internet
Author: User

Similar to the snapshot function, the premise is to move the window to be captured outside the view area to hide it, instead of setting the window attribute to invisible, my module is to open the IE control in the subform of the dialog box, browse to the specified website and.

Therefore, the main form generates a non-modal dialog box. The sub-dialog box is embedded with the IE control, and the sub-dialog box is moved out of the visible area. The environment is still vc6.0.

Code for creating a subdialog box:

Pshowbrowser = new cshowbrowser (); pshowbrowser-> Create (idd_showbrowser, this); pshowbrowser-> movewindow (1024,768 ); // move to pshowbrowser outside the video area> showwindow (sw_show); pshowbrowser-> navigate (www.baidu.com); // navigate to the specified website // capture the image and save it to the memory, sent by gsoap to the WebService server // pbinary: WebService binary parameter pointer void cnettestvdlg: saveimagetobinary (XSD _ base64binary * pbinary) {// printwindow is a hidden function for vc6.0, use typedef bool (_ stdcall * Pprintwindow) (hwnd, HDC hdcblt, uint nflags); hmodule h; H = loadlibrary (_ T ("user32.dll"); pprintwindow P; If (h) {P = (pprintwindow): getprocaddress (H, "printwindow");} // the pointer of the window to be captured by the pshowbrowser: hwnd = pshowbrowser-> getsafehwnd (); HDC =: getwindowdc (hwnd); Assert (HDC); HDC hmemdc =: createcompatibledc (HDC); Assert (hmemdc); rect RC;: getwindowrect (hwnd, & rc); hbitmap =: Createcompatiblebitmap (HDC, RC. right-RC. left, RC. bottom-RC. top); Assert (hbitmap); hbitmap holdbmp = (hbitmap): SelectObject (hmemdc, hbitmap); P (hwnd, hmemdc, 0 ); // capture Bitmap bitmap = {0};: GetObject (hbitmap, sizeof (Bitmap), & Bitmap); bitmapinfoheader Bi = {0}; bitmapfileheader BF = {0 }; const int nbitcount = 24; bi. bisize = sizeof (bitmapinfoheader); bi. biwidth = bitmap. bmwidth; bi. biheig Ht = bitmap. bmheight; bi. biplanes = 1; bi. bibitcount = nbitcount; bi. bicompression = bi_rgb; DWORD dwsize = (bitmap. bmwidth * nbitcount + 31)/32) * 4 * bitmap. bmheight; handle hdib = globalalloc (ghnd, dwsize + sizeof (bitmapinfoheader); lpbitmapinfoheader lpbi = (Signature) globallock (hdib); * lpbi = Bi;: getdibits (hmemdc, hbitmap, 0, bitmap. bmheight, (byte *) lpbi + sizeof (bitmapinfohead ER), (bitmapinfo *) lpbi, dib_rgb_colors); // use the caimage class to convert BMP to JPEG encoding and save it to the memory file try {cximage image (byte *) lpbi, dwsize, cximage_format_bmp); // If (image. isvalid () {If (! Image. isgrayscale () image. increasebpp (24); // Param nbit: 4, 8, 24 image. setjpegquality (99); // sets the image compression quality parameters (from 0 to 100, the larger the value, the higher the quality) cxmemfile memfile; // explicitly uses the cxmemfile object memfile. open (); image. encode (& memfile, cximage_format_jpg); // encoding byte * buffer = memfile. getbuffer (); long size = memfile. size (); int result =-1; // set the gsoap parameter XSD _ base64binary imag1; pbinary->__ PTR = (unsigned char *) soap_malloc (pservicesoap-> soap, size);/* size is the memory size */pbinary->__ size = size; memset (pbinary->__ PTR, 0, size); memcpy (pbinary->__ PTR, buffer, size);/* src_ptr is the source data block pointer */free (buffer); memfile. close () ;}} catch (cfileexception * E) {e-> reporterror (); e-> Delete () ;}globalunlock (hdib); globalfree (hdib );:: selectObject (hmemdc, holdbmp);: deleteobject (hbitmap);: deleteobject (hmemdc);: releasedc (hwnd, HDC );}

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.