Printing a window through device context

Tech-Archive recommends: Speed Up your PC by fixing your registry



Hello Everybody,
I am trying to print the contents or drawing of a window using device
context. The code I written to do so is here


// Call function from WndProc
WM_COMMAND:
case SOME_ID:
hClientDC = GetDC(hWnd);
PrintSelected(hWnd,hClientDC);
break;


void PrintSelected(HWND hWndMain,HDC hClientDC)
{
try{
DOCINFO lpdi;

lpdi.cbSize = sizeof( DOCINFO );
lpdi.lpszDocName = _T( "ReadMe.txt" );
lpdi.lpszOutput = NULL;
lpdi.lpszDatatype = _T("RAW");
lpdi.fwType = 0;

// CreateDC for printer
HDC hPrinterDC = CreateDC(_T("HP LaserJet 1020"),_T("HP LaserJet
1020"),NULL,0);
if(!hPrinterDC)
{
return;
}

if(!StartDoc(hPrinterDC, &lpdi))
{
return;
}

// Start Page
if(!StartPage(hPrinterDC))
{
return;
}


// Do BitBlt
if(!::BitBlt(hPrinterDC,0,0, GetDeviceCaps(hClientDC, HORZRES),
GetDeviceCaps(hClientDC, VERTRES),hClientDC,0,0,SRCCOPY))
{
return;
}

// Actual Printing occurs here
if(!EndPage(hPrinterDC))
{
return;
}

// End Document !!!
if(!EndDoc(hPrinterDC))
{
return;
}

MessageBox(NULL,_T("Success"),_T("Success"),MB_OK);
}



It prints the document but
Problelms I am facing:
1: The size of drawing is very small ( Not the actual size as Like
MSWORD or any other applications printing size)
2: It does not print only the client area but also the entire desktop
( Just Like PrintScreen ),

I am copying device context of client area of windows and still it
prints the entire window. I am quite skeptical about the use of BitBlt,
I am missing something but I am not sure where I am wrong. Can anyone
shed some light on this ?


-AJay

.



Relevant Pages

  • Re: clipping region of a device context.
    ... If a clipping region is set on a DC, drawing will only occur within that ... Windows that redraw the entire client area while resizing probably have the ... You can mark an area of a window for updating with the Invalidate___APIs. ...
    (microsoft.public.vc.mfc)
  • Re: clipping region of a device context.
    ... reason to assume that the area that is in the window represents the entire drawing area. ... Windows that redraw the entire client area while resizing probably have the ... CS_HREDRAW and/or CS_VREDRAW window class style. ... drawn is in the clipping region before doing any actual drawing. ...
    (microsoft.public.vc.mfc)
  • Problem drawing in the window
    ... I have a problem drawing in the application window. ... client area is covered with a bitmap. ...
    (microsoft.public.win32.programmer.gdi)
  • Problem drawing in the window
    ... I have a problem drawing in the application window. ... Drawing on the bitmap is sluggish and the drawing ... drawing into the client area was smooth without blinking. ...
    (microsoft.public.win32.programmer.ui)
  • Displaying Text
    ... text for the user in the client area. ... context, and use the .TextOut method to display CStrings. ... hides the text pops - once the menu is closed, or after the window has ... and thus I tried displaying the text from there - ...
    (microsoft.public.vc.mfc)