如何将子窗口的客户区保存到位图文件? [英] How to save the client area of a child Window to a Bitmap file?
问题描述
我使用核心WIN32和VC ++创建了一个Windows应用程序。在我的父窗口中,我有一个子窗口和两个按钮保存和发送。
I have created a windows application using core WIN32 and VC++. In my parent window I have a child window and two buttons "save" and "send".
当用户点击保存按钮时, c> savefileDialog 即可打开,用户应该能够将图像保存为位图文件。
When user clicks the "save" button I want the savefileDialog
to be opened and user should be able to save the image as a bitmap file.
同一个文件应发送到远程用户使用WinSock API ....我的问题是,我不知道如何保存窗口的屏幕截图到一个位图文件...
The same file should be sent to a remote user using WinSock API.... My problem is, I don't know how to save the screen shot of the window to a bitmap file...
请帮助我退出这个...我没有使用MFC,ATL或WTL ....
please help me out of this ... I have not used MFC, ATL or WTL....
提前感谢,
推荐答案
RECT rect = {0};
GetWindowRect( hwnd, &rect );
ATL::CImage* image_ = new CImage();
image_ -> Create( rect.right - rect.left, rect.bottom - rect.top, 32 );
HDC device_context_handle = image_ -> GetDC();
PrintWindow( hwnd, device_context_handle, PW_CLIENTONLY );
image_ -> Save( filename );
image_ -> ReleaseDC();
delete image_;
PrintWindow()
应该做的。
PrintWindow()
should do the trick.
要保存为HBITMAP:
To save as HBITMAP:
HDC hDC = GetDC( hwnd );
HDC hTargetDC = CreateCompatibleDC( hDC );
RECT rect = {0};
GetWindowRect( hwnd, &rect );
HBITMAP hBitmap = CreateCompatibleBitmap( hDC, rect.right - rect.left,
rect.bottom - rect.top );
SelectObject( hTargetDC, hBitmap );
PrintWindow( hwnd, hTargetDC, PW_CLIENTONLY );
SaveBMPFile( filename, hBitmap, hTargetDC, rect.right - rect.left,
rect.bottom - rect.top );
DeleteObject( hBitmap );
ReleaseDC( hwnd, hDC );
DeleteDC( hTargetDC );
我将SaveBMPFile的实现留给你; )
I will leave the implementation of SaveBMPFile up to you ; )
这篇关于如何将子窗口的客户区保存到位图文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!