Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6 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 2:18am
Edited 12-Feb-10 3:05am
CPallini333.3K
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
0 Sergey Alexandrovich Kryukov 8,488
1 OriginalGriff 6,516
2 Peter Leow 3,647
3 Zoltán Zörgő 3,416
4 Richard MacCutchan 2,397


Advertise | Privacy | Mobile
Web04 | 2.8.150123.1 | Last Updated 12 Feb 2010
Copyright © CodeProject, 1999-2015
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