ComboBox下拉框的颜色修改,该怎么解决
1个回答
展开全部
void CxxxList::OnPaint()
{
// TODO: Add your message handler code here
CListBox::OnPaint();// for painting messages
//注意这里顺序!
CDC *pDC=GetDC();
if(pDC)
{
CRect rc;
GetClientRect(&rc);
……
------解决方案--------------------
如果派生了combo,也可以这样:
C/C++ code/////////////// red border for list in combo
LRESULT CALLBACK NewCbListProc(HWND hWnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
WNDPROC oldProc=(WNDPROC)GetProp(hWnd,"MyCbList");
HDC hdc=0;
HBRUSH hbrsh=0;
CRect rc;
switch(msg)
{
case WM_WINDOWPOSCHANGED:
hdc=::GetWindowDC(hWnd);
::GetWindowRect(hWnd,&rc);
// map to list
MapWindowPoints(NULL,hWnd,(CPoint*)&rc,2);// (-1,-1,..
rc.OffsetRect(1,1);// because -1,-1
hbrsh=CreateSolidBrush(RGB(255,0,0));// red
FrameRect(hdc,&rc,hbrsh);
ReleaseDC(hWnd,hdc);
break;
}
return CallWindowProc(oldProc,hWnd,msg,wparam,lparam);
}
HBRUSH CMyComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if((m_hCbList==0) && (nCtlColor))
{// subclass the list
m_hCbList=pWnd->m_hWnd;
WNDPROC oldProc=(WNDPROC)GetWindowLong(m_hCbList,GWL_WNDPROC);
SetWindowLong(m_hCbList,GWL_WNDPROC,(long)NewCbListProc);
// save in window
SetProp(m_hCbList,"MyCbList",(HANDLE)oldProc);
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
{
// TODO: Add your message handler code here
CListBox::OnPaint();// for painting messages
//注意这里顺序!
CDC *pDC=GetDC();
if(pDC)
{
CRect rc;
GetClientRect(&rc);
……
------解决方案--------------------
如果派生了combo,也可以这样:
C/C++ code/////////////// red border for list in combo
LRESULT CALLBACK NewCbListProc(HWND hWnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
WNDPROC oldProc=(WNDPROC)GetProp(hWnd,"MyCbList");
HDC hdc=0;
HBRUSH hbrsh=0;
CRect rc;
switch(msg)
{
case WM_WINDOWPOSCHANGED:
hdc=::GetWindowDC(hWnd);
::GetWindowRect(hWnd,&rc);
// map to list
MapWindowPoints(NULL,hWnd,(CPoint*)&rc,2);// (-1,-1,..
rc.OffsetRect(1,1);// because -1,-1
hbrsh=CreateSolidBrush(RGB(255,0,0));// red
FrameRect(hdc,&rc,hbrsh);
ReleaseDC(hWnd,hdc);
break;
}
return CallWindowProc(oldProc,hWnd,msg,wparam,lparam);
}
HBRUSH CMyComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if((m_hCbList==0) && (nCtlColor))
{// subclass the list
m_hCbList=pWnd->m_hWnd;
WNDPROC oldProc=(WNDPROC)GetWindowLong(m_hCbList,GWL_WNDPROC);
SetWindowLong(m_hCbList,GWL_WNDPROC,(long)NewCbListProc);
// save in window
SetProp(m_hCbList,"MyCbList",(HANDLE)oldProc);
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询