CComboBox 为什么在执行GetWindowRect(rect);MoveWindow(rect);后位置会移动,谢谢!

yhgfriend 2012-08-22 03:25:45
原程序
CRect rect;
((CComboBox *)(GetDlgItem(IDC_COMBO1)))->GetWindowRect(&rect);rt.bottom+=100;
((CComboBox *)(GetDlgItem(IDC_COMBO1)))->MoveWindow(rect);
我的原意是想让CComboBox拉长100(bottom值增加100, 以显示列表),执行上面二句后CComboBox确定是更高了,但问题是整个ccombobox向右下方移动了,我该怎么做才能保证ccombobox的位置不变呢?谢谢!
...全文
218 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
yhgfriend 2012-08-23
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

经过我的反复测试,发现combobox的高度是不能被改变的
[/Quote]
combobox高度看上去是不变,但问题是如果不加长100,下拉的列表就没法显示,加长100后就能显示下拉了。
yhgfriend 2012-08-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

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

没错,就是屏幕坐标与客户坐标的问题,转换一下就好了。
Eleven 2012-08-23
  • 打赏
  • 举报
回复
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.
Eleven 2012-08-23
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
经过我的反复测试,发现combobox的高度是不能被改变的
[/Quote]
你指的是看到那个Edit或者Static控件的高度吗?
那个是可以改变 CComboBox::SetItemHeight(-1, XXXX);

傻X 2012-08-23
  • 打赏
  • 举报
回复
这个高度是定死的没办法改变,除非重绘。
  • 打赏
  • 举报
回复
经过我的反复测试,发现combobox的高度是不能被改变的
miliggate 2012-08-23
  • 打赏
  • 举报
回复
GetWindowRect(&rect)
这句代码是获得相对于桌面的你的窗口的位置,当然会不对
GetWindowRect(&rect);
this->GetParent()->ScreentoClient(&rect);
这样就可以获得你的窗口在父窗口的位置了
昨夜无风 2012-08-22
  • 打赏
  • 举报
回复
((CComboBox *)(GetDlgItem(IDC_COMBO1)))->GetWindowRect(&rect);
ScreenToClient(rect);
rt.bottom+=100;
Freedom 2012-08-22
  • 打赏
  • 举报
回复
你纵坐标加100能不移动吗

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧