组合框怎么风格怎转变?只读,和可写的相互变化。

aaa278924248 2009-03-13 06:04:23
int CDdddddDlg::SetStyle(int Style)
{
//IDC_COMBO_BRANCHCODE 组合框ID

DWORD theStyle;
HWND theChild;

theChild = ::GetWindow( GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd ,GW_CHILD);
theStyle = GetWindowLong(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd, GWL_STYLE);


if (Style == 0 )//可写
{
::SetWindowLong(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd, CBS_DROPDOWN , theStyle);

::SetWindowPos(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd,//使SetWindowLong生效
0,
0,
0,
0,
0,
SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE);

theStyle &= ~CBS_DROPDOWNLIST;// 去掉DROPDOWNLIST
theStyle |= CBS_DROPDOWN ; //添加DROPDOWN
::DestroyWindow(theChild);
// SetWindowLong(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd, GWL_STYLE , theStyle);
SetWindowLong(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd, GWL_STYLE , theStyle);
::SetWindowPos(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd,
NULL,
0,
0,
0,
0,
SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE);
return 0;
}


if (Style == 1)//只读
{
::SetWindowLong(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd, CBS_DROPDOWNLIST , theStyle);
::SetWindowPos(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd,//使SetWindowLong生效
NULL,
0,
0,
0,
0,
SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE);
theStyle &= ~CBS_DROPDOWN ;//去掉DROPDOWN
theStyle |= CBS_DROPDOWNLIST ; //添加DROPDOWNLIST


::DestroyWindow(theChild);
SetWindowLong(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd, GWL_STYLE , theStyle);
::SetWindowPos(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd,//使SetWindowLong生效
NULL,
0,
0,
0,
0,
SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE);
return 1;
}
return -1;
}
...全文
132 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
ModifyStyle
zgl7903 2009-03-13
  • 打赏
  • 举报
回复
//把Edit控件修改为只读和非只读属性
//如果完全想和Combox控件一样,就得自己派生新类了,因为不同的Style在Comcobox创建时创建不同的子控件

BOOL CALLBACK EnumComboboxEditChildProc(
HWND hwnd, // handle to child window
LPARAM lParam // application-defined value
)
{
CEdit *pEdit = (CEdit *)CWnd::FromHandle(hwnd);
pEdit->SetReadOnly(lParam);
return false;
}

EnumChildWindows(m_ComboBox.m_hWnd, EnumComboboxEditChildProc, b_ReadOnly);
biweilun 2009-03-13
  • 打赏
  • 举报
回复
EnableWindow嘛,用EmunChildWindow查找Edit控件的句柄
cnzdgs 2009-03-13
  • 打赏
  • 举报
回复
用FindWindowEx获取ComboBox中的Edit子控件,用EnableWindow控制Edit子控件试试。
aaa278924248 2009-03-13
  • 打赏
  • 举报
回复
EnableWindow(false);
EnableWindow(true);
不行啊。EnableWindow(false);这样的话用户就不能下拉,来看组合框里面的东西了。
aaa278924248 2009-03-13
  • 打赏
  • 举报
回复
不行啊,这样的话用户就不能下拉,来看组合框里面的东西了。
aaa278924248 2009-03-13
  • 打赏
  • 举报
回复
说明:
可写:就是用户可以在框内写数据,可以取到数据。
路人乙2019 2009-03-13
  • 打赏
  • 举报
回复
EnableWindow(false);
EnableWindow(true);

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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