您的位置:C++老鼠窝编程 新闻公告 正文
原作者:网摘 添加时间:2008-06-20 原文发表时间:2008-06-20 人气:8


如何将窗口文本或客户区内容以CF_BITMAP格式拷到剪贴板
(YangTze发表于2002-8-29 17:00:45)

/****************************************************************
* toClipboard
* Inputs:
* CWnd * wnd: Window whose contents are to be sent
* to the clipboard
* BOOL FullWnd: TRUE for entire window,
* FALSE for client area
* Result: void
*
* Effect:
* Copies the contents of the client area or the window
* to the clipboard in CF_BITMAP format.
*****************************************************************/

void toClipboard(CWnd * wnd, BOOL FullWnd)
{
CDC dc;
if(FullWnd)
{ /* full window */
HDC hdc = ::GetWindowDC(wnd->m_hWnd);
dc.Attach(hdc);
} /* full window */
else
{ /* client area only */
HDC hdc = ::GetDC(wnd->m_hWnd);
dc.Attach(hdc);
} /* client area only */

CDC memDC;
memDC.CreateCompatibleDC(&dc);

CBitmap bm;
CRect r;
if(FullWnd)
wnd->GetWindowRect(&r);
else
wnd->GetClientRect(&r);

CString s;
wnd->GetWindowText(s);
CSize sz(r.Width(), r.Height());
bm.CreateCompatibleBitmap(&dc, sz.cx, sz.cy);
CBitmap * oldbm = memDC.SelectObject(&bm);
memDC.BitBlt(0, 0, sz.cx, sz.cy, &dc, 0, 0, SRCCOPY);

wnd->GetParent()->OpenClipboard();
::EmptyClipboard();
::SetClipboardData(CF_BITMAP, bm.m_hObject);
CloseClipboard();

memDC.SelectObject(oldbm);
bm.Detach(); // make sure bitmap not deleted with CBitmap object
}



本页地址
相关文章

使用typename关键字解除疑惑
如何取得Windows的语言版本信息?
如何从程序中调用外壳的文件属性对话框?
如何改变对话或窗体视窗的背景颜色
C#编程如何获取与另一个进程关联的应用程序
C#编程如何获取某个进程的主窗口?
如何调试Windows外壳扩展程序(Shell Exten
获取硬盘ID信息及网卡MAC地址的代码
获取硬盘详细信息的源代码
一段日期和时间的处理例程代码
禁止/启用屏幕保护及系统热键等
如何激活当前屏幕保护程序
如何激活和关闭IE浏览器
用ATL的注册器来定制注册表入口
用注册表键存储用户程序的信息
调试ATL组件中的引用计数问题
避免在ATL中引发的不明确接口问题
在Direct3D中创建暗灯特效
作为对象的函数指针
用MFC和ClassWizard子类化Window的通用对话

相关评论


本文章所属分类:首页 新闻公告