动态修改下拉组合框 [英] dynamically modifu drop-down combobox

查看:164
本文介绍了动态修改下拉组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个通过可视设计器创建的组合框(不是动态创建的),我想通过代码修改其下拉列表限制.我必须这样做,因为在我的代码中我将组合框移到了某个位置,因此下拉参数已更改(为零).

我发现了一些如下代码,使修改限制成为可能


hi all,

i have a combobox created via the visual designer (not dynamically) and i wanna modify its drop-down liste limit via code. I have to do in that way because in my code i moved the combobox to some place so the dropdown parameter has changed (to zero).

i found some code as below wich make the modification limit possible


void SetDropDownHeight(CComboBox* pMyComboBox, int itemsToShow)
{
    //Get rectangles
    CRect rctComboBox, rctDropDown;
    //Combo rect
    pMyComboBox->GetClientRect(&rctComboBox);
    //DropDownList rect
    pMyComboBox->GetDroppedControlRect(&rctDropDown);

    //Get Item height
    int itemHeight = pMyComboBox->GetItemHeight(-1);
    //Converts coordinates
    pMyComboBox->GetParent()->ScreenToClient(&rctDropDown);
    //Set height
    rctDropDown.bottom = rctDropDown.top + rctComboBox.Height() + itemHeight*itemsToShow;
    //apply changes
    pMyComboBox->MoveWindow(&rctDropDown);
}



问题:当我尝试执行此行时,应用程序崩溃



the prob : the application crashes when i try to execute this line

SetDropDownHeight(&m_CodeAgence, 5);



谢谢



thank you

推荐答案

如果有机会,请与调试器一起进入这些函数,您将确切看到程序崩溃的地方.

从仅静态查看您的代码,我的最佳猜测是pMyComboBox是无效的指针,并且您遇到访问冲突.

第二次机会是pMyComboBox指向CComboBox对象,但是其中的m_hWnd尚未初始化,即您的对话框初始化尚未完成.

希望能帮助您查明问题.
If you have the chance then step with your debugger into the functions and you will see exactly at which point your program crashes.

From just statically looking at your code, my best guess would be that pMyComboBox is an invalid pointer and that you get an access violation.

Second chance is that pMyComboBox points to a CComboBox object, but the m_hWnd in it is not yet initialized, i.e. your dialog initialization has not been completed yet.

Hope that helps you pin-point the problem.


我从CWnd中检索到与ComboBox相关的CComboBox,并开始工作.

谢谢您的回答.
After I retrieve a CComboBox from the CWnd related to the ComboBox and worked.

thank you for your answers.


这篇关于动态修改下拉组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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