How can I print a dialog WYSIWYG

I'm trying to print an active dialog (when user presses a button in this dialog). I do this with the SendMessage command of WM_PRINT.
The problem is, that I get a picture of a lousy quality. How is it possible to get the same result as with Shift-PrintScreen and Paste into MS Word?
Is there another possibility to define the size of the picture on the printer than selecting another resolution?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

UandIAuthor Commented:
Adjusted points to 100
Here's some code from MSDN - hope it helps...

This article demonstrates one technique for capturing the entire contents of a window (including the non-client area) and printing it to the default printer. To do this, the code creates an intermediate surface that is 24- bits per pixel, copies the contents of the specified window to the intermediate surface, and then stretches the intermediate surface to fill the entire display area in the printer DC.

ample Code

   // Return a HDC for the default printer.
   HDC GetPrinterDC(void)
      PRINTDLG pdlg;

      memset( &pdlg, 0, sizeof( PRINTDLG ) );
      pdlg.lStructSize = sizeof( PRINTDLG );
      PrintDlg( &pdlg );
      return pdlg.hDC;

   // Create a copy of the current system palette.
   HPALETTE GetSystemPalette()
       HDC hDC;
       HPALETTE hPal;
       HANDLE hLogPal;
       LPLOGPALETTE lpLogPal;

       // Get a DC for the desktop.
       hDC = GetDC(NULL);

       // Check to see if you are a running in a palette-based video mode.
       if (!(GetDeviceCaps(hDC, RASTERCAPS) & RC_PALETTE)) {
           ReleaseDC(NULL, hDC);
           return NULL;

       // Allocate memory for the palette.
       lpLogPal = GlobalAlloc(GPTR, sizeof(LOGPALETTE) + 256 *
       if (!hLogPal)
           return NULL;

       // Initialize.
       lpLogPal->palVersion = 0x300;
       lpLogPal->palNumEntries = 256;

       // Copy the current system palette into the logical palette.
       GetSystemPaletteEntries(hDC, 0, 256,

       // Create the palette.
       hPal = CreatePalette(lpLogPal);

       // Clean up.
       ReleaseDC(NULL, hDC);

       return hPal;

   // Create a 24-bit-per-pixel surface.
   HBITMAP Create24BPPDIBSection(HDC hDC, int iWidth, int iHeight)
       BITMAPINFO bmi;
       HBITMAP hbm;
       LPBYTE pBits;

       // Initialize to 0s.
       ZeroMemory(&bmi, sizeof(bmi));

       // Initialize the header.
       bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
       bmi.bmiHeader.biWidth = iWidth;
       bmi.bmiHeader.biHeight = iHeight;
       bmi.bmiHeader.biPlanes = 1;
       bmi.bmiHeader.biBitCount = 24;
       bmi.bmiHeader.biCompression = BI_RGB;

       // Create the surface.
       hbm = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, &pBits, NULL, 0);


   // Print the entire contents (including the non-client area) of
   // the specified window to the default printer.
   BOOL PrintWindowToDC(HWND hWnd)
       HBITMAP hbm;
       HDC     hdcPrinter;
       HDC     hdcMemory;
       HDC     hdcWindow;
       int     iWidth;
       int     iHeight;
       DOCINFO di;
       RECT    rc;
       DIBSECTION ds;
       HPALETTE   hPal;

       // Do you have a valid window?
       if (!IsWindow(hWnd))
           return FALSE;

       // Get a HDC for the default printer.
       hdcPrinter = GetPrinterDC();
       if (!hdcPrinter)
           return FALSE;

       // Get the HDC for the entire window.
       hdcWindow  = GetWindowDC(hWnd);

       // Get the rectangle bounding the window.
       GetWindowRect(hWnd, &rc);

       // Adjust coordinates to client area.
       OffsetRect(&rc, -rc.left,;

       // Get the resolution of the printer device.
       iWidth  = GetDeviceCaps(hdcPrinter, HORZRES);
       iHeight = GetDeviceCaps(hdcPrinter, VERTRES);

       // Create the intermediate drawing surface at window resolution.
       hbm = Create24BPPDIBSection(hdcWindow, rc.right, rc.bottom);
       if (!hbm) {
           ReleaseDC(hWnd, hdcWindow);
           return FALSE;

       // Prepare the surface for drawing.
       hdcMemory = CreateCompatibleDC(hdcWindow);
       SelectObject(hdcMemory, hbm);

       // Get the current system palette.
       hPal = GetSystemPalette();

       // If a palette was returned.
       if (hPal) {
           // Apply the palette to the source DC.
           SelectPalette(hdcWindow, hPal, FALSE);

           // Apply the palette to the destination DC.
           SelectPalette(hdcMemory, hPal, FALSE);

       // Copy the window contents to the memory surface.
       BitBlt(hdcMemory, 0, 0, rc.right, rc.bottom,
           hdcWindow, 0, 0, SRCCOPY);

       // Prepare the DOCINFO.
       ZeroMemory(&di, sizeof(di));
       di.cbSize = sizeof(di);
       di.lpszDocName = "Window Contents";

       // Initialize the print job.
       if (StartDoc(hdcPrinter, &di) > 0) {

           // Prepare to send a page.
           if (StartPage(hdcPrinter) > 0) {

               // Retrieve the information describing the surface.
               GetObject(hbm, sizeof(DIBSECTION), &ds);

               // Print the contents of the surface.
                   0, 0, iWidth, iHeight,
                   0, 0, rc.right, rc.bottom,

               // Let the driver know the page is done.

           // Let the driver know the document is done.

       // Clean up the objects you created.
       ReleaseDC(hWnd, hdcWindow);
       if (hPal)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
How many colors does the picture have?
UandIAuthor Commented:
Perfect!! Thank you very much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.