如何在mfc中处理ccombobox [英] How to get handle of ccombobox in mfc

查看:87
本文介绍了如何在mfc中处理ccombobox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我无法处理CComboBox。



Hi,

I am not able to get handle of CComboBox.

CComboBox *pComboBox = reinterpret_cast<ccombobox>(GetDlgItem(IDC_COMBO1));





我检查pComboBox的值为null 。



我很惊讶,同样的代码行在我的其他小应用程序中工作正常,但在这里它失败了。



请提供您的意见?我需要处理组合框并使用手柄。



问候,

欢乐



我尝试过:





I checked value of pComboBox is null.

I am surprised, The same line of code is working fine in my other small application but here it fails.

Please provide your input? I need to get handle to combo Box and use the handle.

Regards,
Joy

What I have tried:

CComboBox *pComboBox = reinterpret_cast<ccombobox>(GetDlgItem(IDC_COMBO1));

推荐答案

你提出的代码行没有得到任何东西的处理 - 显然试图恢复指向 CComboBox MFC包装器对象的指针,该对象是提供指针代码的窗口的子窗口执行。



所以...



如果你真的想要一个指向MFC包装器的指针对象永远不要使用 reinterpret_cast ,使用静态强制转换。



The line of code you've presented isn't getting the handle to anything - it's apparently trying to recover the pointer to a CComboBox MFC wrapper object that's a child of the window that supplies the this pointer the code is executed under.

So...

IF you really want a pointer to the MFC wrapper object NEVER use reinterpret_cast, use static cast.

auto pComboBox = static_cast<ccombobox>( GetDlgItem( IDC_COMBO1 ) );</ccombobox>





如果你真的想要使用手柄 m_hWnd GetDlgItem 返回的成员,例如





IF you actually want the handle use the m_hWnd member of whatever is returned by GetDlgItem, e.g.

auto handle = GetDlgItem( IDC_COMBO1 )->m_Hwnd;





尝试这些代码行,看看会发生什么。如果两者都没有做你想要的,也许修改你的问题以反映你想要做的事情!



Try those lines of code and see what happens. If neither do what you want perhaps modify your question to reflect what you want to do!


这篇关于如何在mfc中处理ccombobox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆