Click here to Skip to main content
15,908,776 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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__ *'.


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

Thanks.
Posted
Updated 12-Feb-10 2:05am
v4

You should deference the CWnd pointer: using *AfxGetMainWnd() is enough, since CWnd implements the HWND cast operator.
For instance:
::SetWindowText(*AfxGetMainWnd(), _T("Hi Folks"));
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900