📄 得到当前窗口句柄或者指针2.txt
字号:
CWnd::GetSafeHwnd
This method obtains the window handle for a window. It returns NULL if the CWnd is not attached to a window or if it is used with a null CWnd pointer.
HWND GetSafeHwnd( )
const;
Return Value
Returns the window handle for a window. Returns NULL if the CWnd is not attached to a window or if it is used with a NULL CWnd pointer.
Example
This is the example for the CWnd::SubclassWindow method.
// The following code shows how to subclass the edit control and list box
// controls inside a combo box. It uses WM_CTLCOLOR for subclassing.
// CSuperComboBox represents the combo box.
HBRUSH CSuperComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if (nCtlColor == CTLCOLOR_EDIT)
{
//Edit control
if (m_edit.GetSafeHwnd() == NULL)
m_edit.SubclassWindow(pWnd->GetSafeHwnd());
}
else if (nCtlColor == CTLCOLOR_LISTBOX)
{
//ListBox control
if (m_listbox.GetSafeHwnd() == NULL)
m_listbox.SubclassWindow(pWnd->GetSafeHwnd());
}
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
return hbr;
}
void CSuperComboBox::OnDestroy()
{
// Unsubclass edit and list box before destruction.
if (m_edit.GetSafeHwnd() != NULL)
m_edit.UnsubclassWindow();
if (m_listbox.GetSafeHwnd() != NULL)
m_listbox.UnsubclassWindow();
CComboBox::OnDestroy();
}
Requirements
Windows CE versions: 1.0 and later
Header file: Declared in Afxwin.h
Platform: H/PC Pro, Palm-size PC, Pocket PC
如果类的转化有问题,即从CWnd*过来,需要用宏Dynamic_cast
如果要从指针转化为句柄,则可以用GetFromHandle()
对于在某个类中,比如是视图类或者是框架类,可以采用将本类的实例指针强制转换为CWnd型,比如(CWnd *)this,而后用它调用GetSafeHwnd( )
this->GetActiveWindow()
或者this->GetSafeHwnd();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -