+ -
当前位置:首页 → 问答吧 → 怎么取得工具栏内控件的句柄

怎么取得工具栏内控件的句柄

时间:2011-12-07

来源:互联网

我在我的对话框内的工具栏上手动创建了一些子控件

但是我通过
CComboBox *pComb = (CComboBox *)pDlg->GetDlgItem(IDC_COMBOBOX);//IDC_COMBOBOX 是子控件ID,
却无法取得控件

CToolBar *pToolBar = (CToolBar *)pDlg->GetDlgItem(IDR_TOOLBAR); // 这里也取不到
CComboBox *pComb = (CComboBox *)pToolBar->GetDlgItem(IDC_COMBOBOX);

请问这种情况下怎么取得CComboBox控件的句柄或对象?
因为我这里pDlg是CDialog*类型传给外部的,在外面拿不到映射的对象

补充:
能不能通过在对话框类中设置一下,然后在外面能有一个统一地使用GetDlgItem取工具栏的子控件与其它的普通控件?

作者: kbr002   发布时间: 2011-12-07

自已回答了,散分
CWnd* GetDescendantWindow(
  int nID,
  BOOL bOnlyPerm = FALSE 
) const;
 

Parameters
nID
Specifies the identifier of the control or child window to be retrieved.

bOnlyPerm
Specifies whether the window to be returned can be temporary. If TRUE, only a permanent window can be returned; if FALSE, the function can return a temporary window. For more information on temporary windows see Technical Note 3.


我直接用
CComboBox *pComb = (CComboBox *)pDlg->GetDescendantWindow(IDC_COMBOBOX);
获得

作者: kbr002   发布时间: 2011-12-07

还可以用FindWindow等

作者: oyljerry   发布时间: 2011-12-07