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;
}
{
//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;
}
EnableWindow(true);
EnableWindow(true);
不行啊。EnableWindow(false);这样的话用户就不能下拉,来看组合框里面的东西了。
//如果完全想和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);