Click here to Skip to main content
12,354,349 members (72,654 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VC6 C++ MFC
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 12-Feb-10 1:18am
Edited 12-Feb-10 2:05am
CPallini385.4K
v4
Rate this: bad
 
good
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"));
  Permalink  
Rate this: bad
 
good
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.
  Permalink  

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


Advertise | Privacy | Mobile
Web01 | 2.8.160621.1 | Last Updated 12 Feb 2010
Copyright © CodeProject, 1999-2016
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