如何将类CWnd转换为struct HWND? (将AfxGetApp()-> m_pMainWnd转换为HWND) [英] How can I convert class CWnd to struct HWND? (Converting AfxGetApp()->m_pMainWnd to HWND)
本文介绍了如何将类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 theCWnd
pointer: using*AfxGetMainWnd()
is enough, sinceCWnd
implements theHWND
cast operator.
For instance:
::SetWindowText(*AfxGetMainWnd(), _T("Hi Folks"));
AfxGetApp()->m_pMainWnd
是CWnd*
,而CWnd
类具有名为m_hWnd
的HWND
成员.
因此,您可以将其用作AfxGetApp()->m_pMainWnd->m_hWnd
.
AfxGetApp()->m_pMainWnd
is aCWnd*
and theCWnd
class has aHWND
member calledm_hWnd
.
So you could use it asAfxGetApp()->m_pMainWnd->m_hWnd
.
这篇关于如何将类CWnd转换为struct HWND? (将AfxGetApp()-> m_pMainWnd转换为HWND)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文