Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding handle (hwnd) in a MFC Appwizard (exe) project

Status
Not open for further replies.

RiderJon

Programmer
Aug 26, 2002
190
0
0
FR
When creating a Visual C++ project using MFC AppWizard (exe), where is the handle HWND. I need to use it in the test.cpp file (where "test" is the name of my project)

To be precise, I need to use hwnd right below the following lines:

#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in
// a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking
// to MFC statically
#endif

// Here's where I use functions that need the handle Hwnd.
 
Hello!!

The handle I think you need is the handle of your application window, it should be in the data member variable of CWnd class. Also is a public variable, then you can access it calling referencing dictly.

CWnd::m_hWnd. It stores the HWND you are looking for.

Try it. I Hope it can help you
 
I had this problem before. After I read MSDN, I think EnumWindows() is the answer.
 
Try this:

CYourClass::SomeMethod()
{
HWND hWnd = NULL;
CWnd* pWnd = NULL;

pWnd = ::AfxGetMainWnd();
// pWnd = ::AfxGetApp()->m_pMainWnd; will work also.

if (pWnd)
hWnd = pWnd->m_hWnd;

// All being well, hWnd should contain the HWND of your main window.
}

This will give you the HWND of your main application window.

Hope this helps! :)
*~-> EOR Candy <-~*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top