How to save Printer HDC to .EMF file ?
-
I'd like to save the HDC content obtainbed from GetPrinterDC (which has just one ellipse drawn on it) to a .EMF file, I've tried with a window HDC and it works fine, but the same do not occurs with the printer related HDC. The function I've used for tests is below. Thanks for any tip ! void PrintStuff( HWND hWndParent ) { HDC hDC; DOCINFO di; hDC = GetPrinterDC(); InitDocStruct( &di, "MyDoc"); StartDoc( hDC, &di ); StartPage( hDC ); HPEN newPen = CreatePen(PS_SOLID,50,RGB(0,0,0)); HPEN oldPen = (HPEN)SelectObject(hdc,newPen); Ellipse(hdc, 0, 0, 200, 200); ******** I'D LIKE TO SAVE HDC TO AN EMF HERE EndPage( hDC ); EndDoc( hDC ); DeleteDC( hDC ); }
GuimaSun www.nexsun.com.br NEXSUN TechZone
-
I'd like to save the HDC content obtainbed from GetPrinterDC (which has just one ellipse drawn on it) to a .EMF file, I've tried with a window HDC and it works fine, but the same do not occurs with the printer related HDC. The function I've used for tests is below. Thanks for any tip ! void PrintStuff( HWND hWndParent ) { HDC hDC; DOCINFO di; hDC = GetPrinterDC(); InitDocStruct( &di, "MyDoc"); StartDoc( hDC, &di ); StartPage( hDC ); HPEN newPen = CreatePen(PS_SOLID,50,RGB(0,0,0)); HPEN oldPen = (HPEN)SelectObject(hdc,newPen); Ellipse(hdc, 0, 0, 200, 200); ******** I'D LIKE TO SAVE HDC TO AN EMF HERE EndPage( hDC ); EndDoc( hDC ); DeleteDC( hDC ); }
GuimaSun www.nexsun.com.br NEXSUN TechZone
I don't believe that will necessarily work with a printer DC, since the GDI commands sent to the DC may go right through to the driver. So, for example, you can't read back a bitmap from a printer DC. Can you draw to the metafile DC? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I don't believe that will necessarily work with a printer DC, since the GDI commands sent to the DC may go right through to the driver. So, for example, you can't read back a bitmap from a printer DC. Can you draw to the metafile DC? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
The interest is, as you said, to read back a bitmap\emf from the printer DC, because the real context that my code will work in is inside a Printing API (EndPage probably) hook. The final idea is to read details about what's being printed, these details must be addressed at the EMF level. This is part of my requirements. If the EMF can't be generated just from the Print HDC, I'll have more problems that I could imagine initially. Anyway, thanks a lot for the prompt reply.
GuimaSun www.nexsun.com.br NEXSUN TechZone
-
The interest is, as you said, to read back a bitmap\emf from the printer DC, because the real context that my code will work in is inside a Printing API (EndPage probably) hook. The final idea is to read details about what's being printed, these details must be addressed at the EMF level. This is part of my requirements. If the EMF can't be generated just from the Print HDC, I'll have more problems that I could imagine initially. Anyway, thanks a lot for the prompt reply.
GuimaSun www.nexsun.com.br NEXSUN TechZone
I personally would put the rendering code in a separate function/method that gets passed a DC. That way the drawing code only needs to be written once....you can call the method with a metafile DC, a printer DC, etc. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I personally would put the rendering code in a separate function/method that gets passed a DC. That way the drawing code only needs to be written once....you can call the method with a metafile DC, a printer DC, etc. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
Yes, this is the way if I was writing a regular app, but I'm writing a completely different thing: a hook at a lower level, so everything I have is a Printer HDC received from an unknown app :) Thanks again.
GuimaSun www.nexsun.com.br NEXSUN TechZone