通过HWND获得CWnd指针
来源:互联网 发布:初请失业金数据公布 编辑:程序博客网 时间:2024/05/22 12:06
1
2
3
4
5
6
7
//获得当前窗口的句柄
HWND
hWnd = GetSafeHwnd();
//通过HWND获得CWnd指针
CWnd *pWnd = CWnd::FromHandle(hWnd);
CString strText = _T(
""
);
strText.Format(
"pWnd = 0x%X\nthis = 0x%X\n"
, pWnd,
this
);
AfxMessageBox(strText);
1、GetSafeHwnd方法:该函数获得窗口对象的窗口句柄。
Returns the window handle for a window. Returns NULL if the CWnd is not attached to a window or if it is used with a NULL CWnd pointer。
这个函数用途很广,很多函数的参数要求是HWND,这时就需要使用GetSafeHwnd函数了。如:
1
2
3
4
5
HWND
hwnd;
CWnd* pWnd;
pWnd=((CFrameWnd*)(AfxGetApp()->m_pMainWnd))->GetActiveView();
hwnd=pWnd->GetDlgItem(IDC_EDIT2)->GetSafeHwnd();
::SetWindowText(hwnd,m_strResult);
其它的一些情况:
AfxWinInit 被WinMain调用的一个函数,用做MFC GUI程序初始化的一部份
AfxBeginThread 开始一个新的执行线程
AfxEndThread 结束一个旧的执行线程
AfxMessageBox 类似Windows API 函数MessageBox
AfxGetApp 取得application object(CWinApp衍生对象)的指针
AfxGetMainWnd 取得程序主窗口的指针
AfxGetInstance 取得程序的instance handle
AfxRegisterClass 以自定的WNDCLASS 注册窗口类别
2、FromHandle方法:FromHandle(HANDLE h) 先查找由用户定义的内核对象对象的封装类, 如果找到直接返回,没有找到构造一个临时对象返回.
Life is like a box of chocolate, you never know what you are going to get.
- 通过HWND 获得CWnd指针
- 通过HWND获得CWnd指针
- 通过HWND获得CWnd指针
- 通过HWND获得CWnd指针
- 通过HWND获得CWnd指针/通过CWnd获取HWND
- 实例1.1:通过HWND获得CWnd指针
- 001、通过HWND获得CWnd指针
- CWnd指针和HWnd
- CWnd指针和HWnd
- CWnd指针和HWnd
- CWnd指针和HWnd
- CWnd指针和HWnd
- CWnd指针和HWnd
- CWnd指针和HWnd
- CWnd类指针和HWnd句柄
- CWnd指针和HWnd(转)
- VC中的CWnd指针和HWnd的区别于联系
- VC中的CWnd指针和HWnd的区别于联系
- 2013-02-21
- Double Delete caused by 2 shared library has global object of same name, 3) Insight
- Drupal入门教程之——站点构建
- php5中date()获得的时间不是当前时间的解决方法
- Linux下svn 安装搭建配置流程
- 通过HWND获得CWnd指针
- sed简明教程
- 编程风格
- WINDOWPOS结构
- 如何遍历对话框里面的子控件
- 了解mysql中drop,truncate、delete的区别
- [总结]jsp完成文件上传中遇到的“法克”路径解决办法
- WM_CHAR、WM_KEYDOWN和WM_SYSKEYDOWN消息
- wince 学习笔记1.1 创建模拟器