如何将类CWnd转换为struct HWND? (将AfxGetApp()-> m_pMainWnd转换为HWND) [英] How can I convert class CWnd to struct HWND? (Converting AfxGetApp()->m_pMainWnd to HWND)

查看:175
本文介绍了如何将类CWnd转换为struct HWND? (将AfxGetApp()-> m_pMainWnd转换为HWND)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想在某些情况下使用Win32 API函数时,需要使用App的HWND作为输入参数.
在MFC中,我使用了AfxGetApp()->m_pMainWnd,但是我从VC6编译器中收到了以下消息:

Hi, When I want to use Win32 API functions in some cases it''s need to use the HWND of App as an input parameter.
In MFC I used AfxGetApp()->m_pMainWnd but I got this message from VC6 compiler:

error C2440: ''='' : cannot convert from ''class CWnd *'' to ''struct HWND__ *''.



顺便说一下,我对HINSTANCE参数也有同样的问题.

谢谢.



By the way I have the same problem with HINSTANCE parameters.

Thanks.

推荐答案

您应该尊重CWnd指针:使用*AfxGetMainWnd()就足够了,因为CWnd实现了HWND强制转换运算符. > 例如:
You should deference the CWnd pointer: using *AfxGetMainWnd() is enough, since CWnd implements the HWND cast operator.
For instance:
::SetWindowText(*AfxGetMainWnd(), _T("Hi Folks"));


AfxGetApp()->m_pMainWndCWnd*,而CWnd类具有名为m_hWndHWND成员.
因此,您可以将其用作AfxGetApp()->m_pMainWnd->m_hWnd.
AfxGetApp()->m_pMainWnd is a CWnd* and the CWnd class has a HWND member called m_hWnd.

So you could use it as AfxGetApp()->m_pMainWnd->m_hWnd.


这篇关于如何将类CWnd转换为struct HWND? (将AfxGetApp()-> m_pMainWnd转换为HWND)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆