How to capture a form's Image

G

Guest

I´m trying to save graphical contents of a form into a HBITMAP object.

At first, using CreateCompatibleDC ,CreateCompatibleBitmap and BitBlt, but it doesn't works 'cause
when function runs, all screen contents is pulled into the bitmap object like a screen capture function, since I just wanna save client region... In other words, if I have another window over the form that i wanna save finally i
got a picture of both windows...

So I started a intensive search to fix this problem. Solution seems to be like this:

- Use MFC eVC++ with cWnd Class in a dll exporting the following procedure:

# define EXPORTA extern "C" __declspec(dllexport)
EXPORTA int __stdcall _SalvarFondo (HWND hWnd)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CWnd oControlador;
CDC oBitmap;
oControlador.FromHandle(hWnd);
oControlador.Print(oBitmap,PRF_CLIENT);
return 0;
}

There's a problem with this... when I tried to compile i got this error message:

E:\LogiMap\Edward\MFCLogimap\MFCLogimap.cpp(77) : error C2039: 'Print' : is not a member of 'CWnd'
C:\Archivos de programa\Windows CE Tools\wce420\POCKET PC 2003\mfc\include\afxwin.h(1868) : see declaration of 'CWnd'
E:\LogiMap\Edward\MFCLogimap\MFCLogimap.cpp(77) : error C2065: 'PRF_CLIENT' : undeclared identifier
Error executing cl.exe.


there's a preprocessor directive in afxwin.h :

#if !defined(_WIN32_WCE_NO_PRINTING)
void Print(CDC* pDC, DWORD dwFlags) const;
void PrintClient(CDC* pDC, DWORD dwFlags) const;
#endif // _WIN32_WCE_NO_PRINTING



Does anyone know how to fix it or another way to save form's content?
 
A

Alex Feinman [MVP]

1. When you do BitBlt, you can specify the region. To get the screen
coordinates of the form's client area use Form.Rectangle.ToScreen()
2. AFAIK PrintWindow is not supported under Windows CE

--
Alex Feinman
---
Visit http://www.opennetcf.org
Edward said:
I´m trying to save graphical contents of a form into a HBITMAP object.

At first, using CreateCompatibleDC ,CreateCompatibleBitmap and BitBlt, but it doesn't works 'cause
when function runs, all screen contents is pulled into the bitmap object
like a screen capture function, since I just wanna save client region... In
other words, if I have another window over the form that i wanna save
finally i
got a picture of both windows...

So I started a intensive search to fix this problem. Solution seems to be like this:

- Use MFC eVC++ with cWnd Class in a dll exporting the following procedure:

# define EXPORTA extern "C" __declspec(dllexport)
EXPORTA int __stdcall _SalvarFondo (HWND hWnd)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CWnd oControlador;
CDC oBitmap;
oControlador.FromHandle(hWnd);
oControlador.Print(oBitmap,PRF_CLIENT);
return 0;
}

There's a problem with this... when I tried to compile i got this error message:

E:\LogiMap\Edward\MFCLogimap\MFCLogimap.cpp(77) : error C2039: 'Print' : is not a member of 'CWnd'
C:\Archivos de programa\Windows CE Tools\wce420\POCKET PC
2003\mfc\include\afxwin.h(1868) : see declaration of 'CWnd'
E:\LogiMap\Edward\MFCLogimap\MFCLogimap.cpp(77) : error C2065:
'PRF_CLIENT' : undeclared identifier
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top