How to make a CWnd-derived class draw on CImage (or equivalent) instead of on screen?
Posted on 2004-11-25
I have an application which displays some windows. Specifically, it displays a CFormView-derived window. That works fine.
Now, I have an idea about making a jpeg which looks exactly like the content of that window (preferably excluting frame border).
The window contains
1) controls which are added using the resource view in VS, and the controls are derived of CEdit and CStatic.
2) controls which are added at runtime via Create methods. Those controls are derived of CButton
3) lines which are drawn using LineTo
I want the jpeg saved to disk when I do an export of all data in my application, so I don't want the view to be visible on screen while it saves the image.
How can I do this?
I had some idea to use CImage, and draw on its CDC, and then use CImage::Save to save it as a jpeg. But in that case... how can I make my CFormView-derived class draw its contents on the correct CDC? And will it work, since the window doesn't hav a CWnd-parent?
Just making a screen capture is out of the question, since the window should not be visible.
Using the CImage is just my first guess. Any other solution is just as welcome...
I think I need some code to help me along the way...