You can use the GetDlgItem function with any parent-child window pair, not just with dialog boxes. As long as the hDlg parameter specifies a parent window and the child window has a unique identifie
您所说的这个方法我已经用过了,我先获取主窗口的句柄HWND,然后再根据ID调用这个函数,所获得的HWND是空的 建议你把那段msdn好好读读 As long as the hDlg parameter specifies a parent window and the child window has a unique identifie
您所说的这个方法我已经用过了,我先获取主窗口的句柄HWND,然后再根据ID调用这个函数,所获得的HWND是空的 建议你把那段msdn好好读读 As long as the hDlg parameter specifies a parent window and the child window has a unique identifie
只有这一种办法了吗?谢谢了
我项目里建立的是CBCGPDialogBar,这个控件是帖在主界面上的,没办法通过ID获取其指针了吗?
hdlg参数来自
HWND WINAPI GetDlgItem(
_In_opt_ HWND hDlg,
_In_ int nIDDlgItem
);
建议你把那段msdn好好读读
As long as the hDlg parameter specifies a parent window and the child window has a unique identifie
建议你把那段msdn好好读读
As long as the hDlg parameter specifies a parent window and the child window has a unique identifie
那就是hDlg应该是父窗口的句柄吧?楼上说了AboutDialog不是子控件,那就是这种方式不行咯?
void CMultiDocTestApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
他是当你点击关于时候,建立了临时的局部CAboutDlg对象,然后你关闭,这个对象就消亡了。如果你想获取到CAboutDlg对象的指针,你不能用GetDlgItem,因为它只能获得对话框中控件的指针,而现在你要获取的是一个dialog的指针。你可以在主程序文件.cpp类中建立指针CAboutDlg× m_pAboutDlg;
然后用这样的语句m_pAboutDlg = new CAboutDlg();在堆上创建CAboutDlg对象,并将指针保存在主程序中。
最后在主程序文件中创建一个函数,例如:CAboutDlg* GetAboutDlgPt(),将这个指针返回给调用它的人就行,这样你可以随时在其他类中调用GetAboutDlgPt()这个函数获取CAboutDlg对象的指针了。