原程序
 CRect rect;
((CComboBox *)(GetDlgItem(IDC_COMBO1)))->GetWindowRect(&rect);rt.bottom+=100;
((CComboBox *)(GetDlgItem(IDC_COMBO1)))->MoveWindow(rect);
我的原意是想让CComboBox拉长100(bottom值增加100, 以显示列表),执行上面二句后CComboBox确定是更高了,但问题是整个ccombobox向右下方移动了,我该怎么做才能保证ccombobox的位置不变呢?谢谢!

解决方案 »

  1.   

    ((CComboBox *)(GetDlgItem(IDC_COMBO1)))->GetWindowRect(&rect);
    ScreenToClient(rect);
    rt.bottom+=100;
      

  2.   

    经过我的反复测试,发现combobox的高度是不能被改变的
      

  3.   

    你指的是看到那个Edit或者Static控件的高度吗?
    那个是可以改变 CComboBox::SetItemHeight(-1, XXXX);
      

  4.   

    int SetItemHeight(
       int nIndex,
       UINT cyItemHeight 
    );
     Parameters
    nIndex
    Specifies whether the height of list items or the height of the edit-control (or static-text) portion of the combo box is set. If the combo box has the CBS_OWNERDRAWVARIABLE style, nIndex specifies the zero-based index of the list item whose height is to be set; otherwise, nIndex must be 0 and the height of all list items will be set. If nIndex is –1, the height of the edit-control or static-text portion of the combo box is to be set. 
    cyItemHeight
    Specifies the height, in pixels, of the combo-box component identified by nIndex. 
      

  5.   

    combobox高度看上去是不变,但问题是如果不加长100,下拉的列表就没法显示,加长100后就能显示下拉了。
      

  6.   

    GetWindowRect(&rect)
    这句代码是获得相对于桌面的你的窗口的位置,当然会不对
    GetWindowRect(&rect);
    this->GetParent()->ScreentoClient(&rect);
    这样就可以获得你的窗口在父窗口的位置了