Click here to Skip to main content
12,948,567 members (63,219 online)
Rate this:
Please Sign up or sign in to 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.

Posted 12-Feb-10 1:18am
Updated 12-Feb-10 2:05am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You should deference the CWnd pointer: using *AfxGetMainWnd() is enough, since CWnd implements the HWND cast operator.
For instance:
::SetWindowText(*AfxGetMainWnd(), _T("Hi Folks"));
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,344
CHill60 3,275
Maciej Los 2,703
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web01 | 2.8.170524.1 | Last Updated 12 Feb 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100