我用Visual Studio 2008建立了一個對話框程式。使用MFC實作視窗最大化或者調整尺寸后下拉串列里的選項顯示不了,不能下拉顯示所有選項。我呼叫GetDlgItem->ResetContent和GetDlgItem->AddString也不解決問題。先謝謝了。
void CSimApplianceDlg::ReSize(void)
{
float fsp[2];
POINT Newp; //獲取現在對話框的大小
CRect recta;
GetClientRect(&recta); //取客戶區大小
Newp.x=recta.right-recta.left;
Newp.y=recta.bottom-recta.top;
fsp[0]=(float)Newp.x/old.x;
fsp[1]=(float)Newp.y/old.y;
CRect Rect;
int woc;
CPoint OldTLPoint,TLPoint; //左上角
CPoint OldBRPoint,BRPoint; //右下角
HWND hwndChild=::GetWindow(m_hWnd,GW_CHILD); //列出所有控制元件
while(hwndChild){
woc=::GetDlgCtrlID(hwndChild);//取得ID
GetDlgItem(woc)->GetWindowRect(Rect);
ScreenToClient(Rect);
OldTLPoint = Rect.TopLeft();
TLPoint.x = long(OldTLPoint.x*fsp[0]);
TLPoint.y = long(OldTLPoint.y*fsp[1]);
OldBRPoint = Rect.BottomRight();
BRPoint.x = long(OldBRPoint.x *fsp[0]);
BRPoint.y = long(OldBRPoint.y *fsp[1]);
Rect.SetRect(TLPoint,BRPoint);
GetDlgItem(woc)->MoveWindow(Rect,TRUE);
hwndChild=::GetWindow(hwndChild, GW_HWNDNEXT);
}
old=Newp;
}
uj5u.com熱心網友回復:
mCombox.SetItemHeight(-1, nHeight) 調整一下uj5u.com熱心網友回復:
把這一條陳述句添加到哪里啊,能詳細說一下嗎?uj5u.com熱心網友回復:
我在呼叫ReSize()函式后又添加了如下代碼,可是依然不起作用。
// Set the height of every item to be the
// vertical size of the item's text extent.
CString str;
CSize sz;
CDC* pDC = ((CComboBox*)GetDlgItem(IDC_COMBO_AC_MODE1))->GetDC();
for (int i = 0; i < ((CComboBox*)GetDlgItem(IDC_COMBO_AC_MODE1))->GetCount(); i++)
{
((CComboBox*)GetDlgItem(IDC_COMBO_AC_MODE1))->GetLBText(i, str);
sz = pDC->GetTextExtent(str);
((CComboBox*)GetDlgItem(IDC_COMBO_AC_MODE1))->SetItemHeight(i, sz.cy);
}
((CComboBox*)GetDlgItem(IDC_COMBO_AC_MODE1))->ReleaseDC(pDC);
uj5u.com熱心網友回復:
能 上傳一張 圖 看看 嗎 ?uj5u.com熱心網友回復:
void CDlg3Dlg::ReSize(void)
{
SIZE Newp; //獲取現在對話框的大小
CRect recta;
GetClientRect(&recta); //取客戶區大小
Newp.cx= recta.Width();
Newp.cy = recta.Height();
double fxZoom = (double)Newp.cx/(double)old.cx;
double fyZoom = (double)Newp.cy/(double)old.cy;
HWND hwndChild=::GetWindow(m_hWnd,GW_CHILD); //列出所有控制元件
while(hwndChild)
{
CRect Rect;
::GetWindowRect(hwndChild, &Rect);
ScreenToClient(&Rect);
Rect.left = (int)(Rect.left * fxZoom + 0.5);
Rect.right = (int)(Rect.right * fxZoom + 0.5);
Rect.top = (int)(Rect.top * fyZoom + 0.5);
Rect.bottom = (int)(Rect.bottom * fyZoom + 0.5);
::MoveWindow(hwndChild, Rect.left, Rect.top, Rect.Width(), Rect.Height(), TRUE);
//修改COMBOBOX 高度
TCHAR szClass[64+1]={0};
if(GetClassName(hwndChild, szClass, 64)
&& _tcscmp(szClass, _T("COMBOBOX")) == 0)
{
::SendMessage(hwndChild, CB_SETITEMHEIGHT, -1, Rect.Height());
}
hwndChild=::GetWindow(hwndChild, GW_HWNDNEXT);
}
old=Newp; //SIZE old
}
uj5u.com熱心網友回復:
上面的 _tcscmp 改一下, _tcsicmp(szClass, _T("COMBOBOX")uj5u.com熱心網友回復:
樓主 我也跟你遇到同樣的問題 網上搜索試了很多辦法 都未解決 你的問題最后解決了沒?怎么解決的?求分享方法qq272710437,跪謝uj5u.com熱心網友回復:
解決了嗎?Helpuj5u.com熱心網友回復:
網上找的處理CBN_DROPDOWN訊息那個就可以吧//獲取ComboBox控制元件的大小,再重新設定
CRect rc;
GetDlgItem(IDC_COMBO1)->GetClientRect(&rc);
m_ComBox.SetWindowPos(NULL, 0, 0, rc.Width(), rc.Height()+100, SWP_NOZORDER|SWP_NOMOVE|SWP_SHOWWINDOW);
參考:
https://zhidao.baidu.com/question/540471281.html
http://blog.csdn.net/youyongyoumou/article/details/46363633
uj5u.com熱心網友回復:
下來串列框用movewindow調整大小時,rect的大小決定了下拉框的大小uj5u.com熱心網友回復:
這個rect指的是哪塊?
uj5u.com熱心網友回復:
movewindow的引數uj5u.com熱心網友回復:
去掉 while(hwndChild) ,只針對 Combo ,不應該有這個問題
uj5u.com熱心網友回復:
樓主,請問你對話框最大化后combo box不能下拉的問題解決了么?我的對話框最大化后不但combo box不能下拉,而且picture control也有問題、uj5u.com熱心網友回復:
combo box 中的 list 不是 對話框的 子視窗,是桌面的 子視窗 !對話框 全屏 時 沒 桌面
uj5u.com熱心網友回復:
在MoveWindow之前改一下rectif (woc == IDC_COMBO_MODE)
{
BRPoint.y += 100;
}
Rect.SetRect(TLPoint, BRPoint);
GetDlgItem(woc)->MoveWindow(Rect, TRUE);
這個是可以的。
uj5u.com熱心網友回復:
根據CComboBox的Create函式的引數里CRect是下拉串列的大小推測MoveWindow應該也是修改的是下拉串列的大小轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/59499.html
標籤:界面
