combobox控件的背景色的修改

time_exceed 2014-06-08 12:03:54
HBRUSH MenuDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);

// TODO: 在此更改 DC 的任何特性

// TODO: 如果默认的不是所需画笔,则返回另一个画笔
if(pWnd->m_hWnd==m_ComboBox.m_hWnd)
{
//m_ComboBox.GetEditCtrl();
[code=c]pDC->SetBkColor(RGB(0,240,0));//单步进去,这些语句都执行了
pDC->SetTextColor(RGB(250,0,0));
pDC->SetBkMode(TRANSPARENT);

return (HBRUSH)myBrush;
}
return hbr;
}[/code]

结果 只有返回的myBrush修改了控件的边框,而其他的并没有改变。

我想明白两个问题,
pDC->SetBkColor(RGB(0,240,0));//单步进去,这些语句都执行了
pDC->SetTextColor(RGB(250,0,0));
pDC->SetBkMode(TRANSPARENT);

为什么这些语句执行了却没有任何作用?要怎样修改combobox的编辑框的背景色?
...全文
832 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
schlafenhamster 2014-06-09
  • 打赏
  • 举报
回复
GetComboBoxInfo
schlafenhamster 2014-06-09
  • 打赏
  • 举报
回复
COMBOBOXINFO A version of this page is also available for Windows Embedded CE 6.0 R3 4/8/2010 This structure contains combo box status information. Syntax typedef struct tagCOMBOBOXINFO { DWORD cbSize; RECT rcItem; RECT rcButton; DWORD stateButton; HWND hwndCombo; HWND hwndItem; HWND hwndList; } COMBOBOXINFO, *PCOMBOBOXINFO, *LPCOMBOBOXINFO; Members cbSize Specifies the size, in bytes, of the structure. The caller must set this to sizeof(COMBOBOXINFO). rcItem RECT structure that specifies the coordinates of the edit box. rcButton RECT structure that specifies the coordinates of the button that contains the drop-down arrow. stateButton Unsupported. hwndCombo Handle to the combo box. hwndItem Handle to the edit box. hwndList Handle to the drop-down list.
time_exceed 2014-06-09
  • 打赏
  • 举报
回复
引用 6 楼 schlafenhamster 的回复:
vc6 以上可以: GetEdit() GetList()
vs2010不可以啊,怎么修改啊,大神提示一下
schlafenhamster 2014-06-09
  • 打赏
  • 举报
回复
“还是nCtlColor == CTRCOLOR_EDIT,” 后 再检查 是不是 “无辜的 ” edit 窗口 m_hwnd
time_exceed 2014-06-09
  • 打赏
  • 举报
回复
引用 12 楼 schlafenhamster 的回复:
if(pWnd->m_hWnd==m_ComboBox.hwndItem) 不会有 m_ComboBox.hwndItem 需要 上贴 红色 的 hwndItem hwndList 要不就 检查 nCtlColor == CTRCOLOR_EDIT 或 CTRLCOLOR_LIST
还是nCtlColor == CTRCOLOR_EDIT,再去修改其他的edit,让它们那些无辜的变回白色
schlafenhamster 2014-06-09
  • 打赏
  • 举报
回复
if(pWnd->m_hWnd==m_ComboBox.hwndItem) 不会有 m_ComboBox.hwndItem 需要 上贴 红色 的 hwndItem hwndList 要不就 检查 nCtlColor == CTRCOLOR_EDIT 或 CTRLCOLOR_LIST
time_exceed 2014-06-09
  • 打赏
  • 举报
回复
引用 8 楼 schlafenhamster 的回复:
COMBOBOXINFO A version of this page is also available for Windows Embedded CE 6.0 R3 4/8/2010 This structure contains combo box status information. Syntax typedef struct tagCOMBOBOXINFO { DWORD cbSize; RECT rcItem; RECT rcButton; DWORD stateButton; HWND hwndCombo; HWND hwndItem; HWND hwndList; } COMBOBOXINFO, *PCOMBOBOXINFO, *LPCOMBOBOXINFO; Members cbSize Specifies the size, in bytes, of the structure. The caller must set this to sizeof(COMBOBOXINFO). rcItem RECT structure that specifies the coordinates of the edit box. rcButton RECT structure that specifies the coordinates of the button that contains the drop-down arrow. stateButton Unsupported. hwndCombo Handle to the combo box. hwndItem Handle to the edit box. hwndList Handle to the drop-down list.
如果给combobox控件绑定 COMBOBOXINFO类型的变量,在OnCtlColor函数里面的 if(pWnd->m_hWnd==m_ComboBox.hwndItem)的判断语句不会成立,即使改成m_ComboBox.hwdCombo,也不会成立 CComboBox类型的句柄和COMBOBOXINFO类型的句柄不相等 该怎么解决啊
time_exceed 2014-06-09
  • 打赏
  • 举报
回复
引用 8 楼 schlafenhamster 的回复:
COMBOBOXINFO A version of this page is also available for Windows Embedded CE 6.0 R3 4/8/2010 This structure contains combo box status information. Syntax typedef struct tagCOMBOBOXINFO { DWORD cbSize; RECT rcItem; RECT rcButton; DWORD stateButton; HWND hwndCombo; HWND hwndItem; HWND hwndList; } COMBOBOXINFO, *PCOMBOBOXINFO, *LPCOMBOBOXINFO; Members cbSize Specifies the size, in bytes, of the structure. The caller must set this to sizeof(COMBOBOXINFO). rcItem RECT structure that specifies the coordinates of the edit box. rcButton RECT structure that specifies the coordinates of the button that contains the drop-down arrow. stateButton Unsupported. hwndCombo Handle to the combo box. hwndItem Handle to the edit box. hwndList Handle to the drop-down list.
HBRUSH MenuDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);

	// TODO:  在此更改 DC 的任何特性

	// TODO:  如果默认的不是所需画笔,则返回另一个画笔
	if(pWnd->m_hWnd==m_ComboBox.hwndItem)//这个判断语句总是不会成立
	{
		//m_ComboBox.GetEditCtrl();
	//	pDC->
		
		pDC->SetBkColor(RGB(0,240,0));
		pDC->SetTextColor(RGB(250,0,0));
		pDC->SetBkMode(TRANSPARENT);
		return (HBRUSH)myBrush;
	}
	return hbr;
}
我单步,进不了if里面的语句,所以这个判断语句不会成立
time_exceed 2014-06-08
  • 打赏
  • 举报
回复
坐等大神回复
schlafenhamster 2014-06-08
  • 打赏
  • 举报
回复
vc6 以上可以: GetEdit() GetList()
time_exceed 2014-06-08
  • 打赏
  • 举报
回复
引用 4 楼 schlafenhamster 的回复:
combobox 有2个 成员 edit 和 list (combo 首先是 edit ) 你要 改变的 是 list
那怎么得到这两个成员呢?
schlafenhamster 2014-06-08
  • 打赏
  • 举报
回复
combobox 有2个 成员 edit 和 list (combo 首先是 edit ) 你要 改变的 是 list
time_exceed 2014-06-08
  • 打赏
  • 举报
回复
引用 1 楼 q5390498 的回复:
坐等大神回复
赋值了,在构造函数里头
Jackxan 2014-06-08
  • 打赏
  • 举报
回复
请问 return (HBRUSH)myBrush;里面的myBrush在哪?没有赋值吗?

15,980

社区成员

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

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