Acquire a View HANDLE :: MFC

kuphryn

Senior member
Jan 7, 2001
400
0
0
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
 

Adrian Tung

Golden Member
Oct 10, 1999
1,370
1
0
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
 

kuphryn

Senior member
Jan 7, 2001
400
0
0
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
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
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.
 

kuphryn

Senior member
Jan 7, 2001
400
0
0
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
 

Argo

Lifer
Apr 8, 2000
10,045
0
0
CWnd derivatives should have a member function called IsWindow() which would test the internal handle for you.