• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Acquire a View HANDLE :: MFC

kuphryn

Senior member
Hi.

I often see function parameters requiring a handle to a window. I believe the handle to main fram is m_hWnd. In general, how do you get a handle to a window from main frame to any view including splitters?

Thanks,
Kuphryn
 
Any class that inherits from CWnd will have a public member variable m_hWnd. Therefore, CFrameWnd, CView, CDialog, even CButton have m_hWnd.

However, you usually do not even need to pass in the window handle if you're using MFC. Function calls that require the handle are *usually* Win32 APIs, and MFC will usually have an equivalent function. The only time you need to use the handle when using MFC is the rare occasion when you cannot find an MFC function to do something you need done, and have to resort to the Win32 function to do it.


Hope that helps,
🙂atwl
 
Thanks.

A member at CodeProject mentioned using IsWindow() to make sure a handle is a handle to a valid window. However, IsWindow() take not parameters and returns a BOOL. I am not sure how to "check" a handle using that function.

Kuphryn
 
Many times programmers will get a window handle and keep it around for reference purposes. IsWindow() allows you to verify that what you are using is correct.

If a window is not created the handle is null. That needs to be tested.
If a window was created then destroyed, IsWindow() will return false.
 
Okay thanks.

To clarify any confusions, the reason I am asking about HANDLE to MFC windows is, as Adrian Tung has mentioned, I need to pass it to API functions especially winsock. I am shifting gear to network programming in Windows.

Kuphryn
 
CWnd derivatives should have a member function called IsWindow() which would test the internal handle for you.
 
Back
Top