Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <commctrl.h>
- #include <stdio.h>
- void drawPage(HDC hdc)
- {
- HBITMAP logo = (HBITMAP)LoadImage(NULL, "logo.bmp", IMAGE_BITMAP, 0,0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
- int pageWidth, pageHeight;
- pageWidth = GetDeviceCaps( hdc, HORZRES ),
- pageHeight = GetDeviceCaps( hdc, VERTRES );
- int dpiX, dpiY;
- dpiX = GetDeviceCaps(hdc, LOGPIXELSX);
- dpiY = GetDeviceCaps(hdc, LOGPIXELSY);
- double dpiMmX, dpiMmY;
- dpiMmX = dpiX / 25.4;
- dpiMmY = dpiY / 25.4;
- HBRUSH redBrush = CreateSolidBrush( RGB(255,0,0) );
- RECT pageRect = {0,0,pageWidth,pageHeight};
- int borderWidth = dpiMmX * 10;
- int borderHeight = dpiMmY * 10;
- RECT borderRect = {borderWidth, borderHeight, pageWidth-(0.5*dpiMmX)-borderWidth, pageHeight-(0.5*dpiMmY)-borderHeight};
- FrameRect(hdc, &pageRect, redBrush);
- int i;
- for (i=0; i<5; i++)
- {
- FrameRect(hdc, &borderRect, redBrush);
- InflateRect(&borderRect, -1, -1);
- }
- HDC memDC = CreateCompatibleDC(hdc);
- HBITMAP old = (HBITMAP)SelectObject(memDC, logo);
- StretchBlt(hdc,
- 2*borderWidth,2*borderHeight,
- 1000,540, // <-- should be calculated in code. I know the aspect ratio of the image
- memDC, // so am using these values. Divide these by dpiMmX and dpiMmY for size in
- 0,0, // mm
- 250,125,
- SRCCOPY);
- SelectObject(memDC, old);
- DeleteObject(logo);
- DeleteDC(memDC);
- printf("Logo size: %d x %d mm\n", (int)(1000/dpiMmX), (int)(540/dpiMmY) );
- DeleteObject(redBrush);
- }
- void testPrint(char *szPrinterName)
- {
- DOCINFO diDocInfo = {0};
- diDocInfo.cbSize = sizeof( DOCINFO );
- diDocInfo.lpszDocName = "printTest";
- HANDLE printerHandle;
- if (OpenPrinter(szPrinterName, &printerHandle, NULL) != 0)
- {
- HDC pDC2 = CreateDC("", szPrinterName, NULL, NULL);
- if( StartDoc( pDC2, &diDocInfo ) > 0 )
- {
- if( StartPage( pDC2 ) > 0 )
- {
- drawPage(pDC2);
- EndPage(pDC2);
- }
- EndDoc( pDC2 );
- }
- ClosePrinter(printerHandle);
- }
- }
- int main()
- {
- testPrint("CutePDF Writer");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement