Printing a window through device context
- From: ajay.sonawane@xxxxxxxxx
- Date: 9 Jul 2006 23:16:14 -0700
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
.
- Follow-Ups:
- Re: Printing a window through device context
- From: William DePalo [MVP VC++]
- Re: Printing a window through device context
- Prev by Date: How to read GDI comments containing GDI+ calls
- Next by Date: Re: PropertyNotSupported returned for sample code
- Previous by thread: How to read GDI comments containing GDI+ calls
- Next by thread: Re: Printing a window through device context
- Index(es):
Relevant Pages
|