开发者

window handle in MFC?

how开发者_如何学C to get window handle in MFC??


It's the m_hWnd member of your CWnd.


CWnd::GetSafeHwnd is a little "safer" because it can be used with a NULL CWnd pointer http://msdn.microsoft.com/en-US/library/d64ehwhz%28v=vs.80%29.aspx


Use CWnd::GetSafeHwnd() to get the HWND from a CWnd object; use CWnd::FromHandle to bind a HWND to a temporary CWnd object.


Access the m_hWnd member of your CWnd, like this:

HWND Handle = this->m_hWnd


There are two methodes: First one, you can use the m_hWnd member variable of your CWnd class to get the window handle.

If you want get the other window's handle, you can use FindWindow windows API. like this:

HANDLE hWind = FindWindow( your_win_class_name, your_win_name );


to use "getsafeHwnd" function, you must c before you use the return value


HANDLE hwnd =FindWindowW( __in_opt LPCWSTR lpClassName,__in_opt LPCWSTR lpWindowName);

first one is class name "Button" or "Edit control" second one is window name.Handler of the window (m_hWnd).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜