|
-
June 4th, 2011, 06:53 PM
#1
Help Drawing Custom Radio Button
I am working on an application that we are "customizing" the dialog controls by changing background colors, forecolors, etc.
Have it working really well except we have a Radio Button with the PUSHLIKE option turned on. Because of that it "looks" and operates like a button. Problem is, it is using the windows defaults instead of our custom code for buttons.
Most likely, I need to modify my code, somewhere, to get this to look like the other buttons. Because alot of this code was "borrowed" from the web, I am not sure where or how to modify it for these PUSHLIKE controls.
Here is the code....
The buttons are changed in the OnDrawItem for the dialog with:
Code:
CRect rect;
HBRUSH hbr;
HPEN hpen,holdpen;
COLORREF crOldColor;
switch(lpDrawItemStruct->CtlType)
{
case ODT_BUTTON:
if(lpDrawItemStruct->hwndItem == m_help.m_hWnd)
break;
if(m_logo != NULL)
if(lpDrawItemStruct->hwndItem == m_logo->m_hWnd)
break;
UINT uStyle = DFCS_BUTTONPUSH;
// If drawing selected, add the pushed style to DrawFrameControl.
if (lpDrawItemStruct->itemState & ODS_SELECTED)
uStyle |= DFCS_PUSHED;
if (lpDrawItemStruct->itemState & ODS_DISABLED)
uStyle |= DFCS_INACTIVE;
// Draw the button frame.
::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem,DFC_BUTTON, uStyle);
// Fill the button
rect=lpDrawItemStruct->rcItem;
rect.left+=2;
rect.right-=2;
rect.top+=2;
rect.bottom-=2;
if (lpDrawItemStruct->itemState & ODS_DISABLED)
::FillRect(lpDrawItemStruct->hDC,&rect,m_bkBrush);
else
::FillRect(lpDrawItemStruct->hDC,&rect,m_brushButton);
// Get the button's text.
::GetDlgItemText(this->m_hWnd, lpDrawItemStruct->CtlID, sTemp.GetBuffer(255), 255);
sTemp.ReleaseBuffer();
// Draw the button text using the text color
if (lpDrawItemStruct->itemState & ODS_DISABLED)
{
crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(150,150,150));
::SetBkMode(lpDrawItemStruct->hDC,TRANSPARENT);
}
else
crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, m_colorButtonText);
::DrawText(lpDrawItemStruct->hDC, sTemp, sTemp.GetLength(),&lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
return;
}
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
The other controls are modified in the OnCtlColor with the following code:
Code:
HBRUSH hbr = NULL;
switch(nCtlColor)
{
case CTLCOLOR_MSGBOX:
break;
case CTLCOLOR_EDIT:
pDC->SetBkColor(m_colorListBoxBk);
pDC->SetTextColor(m_colorListBoxText);
hbr = m_brushListBox;
break;
case CTLCOLOR_SCROLLBAR:
break;
case CTLCOLOR_MAX:
break;
case CTLCOLOR_STATIC:
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(m_colorStaticText);
hbr = m_bkBrush;
break;
case CTLCOLOR_DLG:
hbr = m_bkBrush;
break;
case CTLCOLOR_LISTBOX:
pDC->SetBkColor(m_colorListBoxBk);
pDC->SetTextColor(m_colorListBoxText);
hbr = m_brushListBox;
break;
case CTLCOLOR_BTN:
pDC->SetBkColor(m_colorButtonBk);
hbr = m_brushButton;
break;
default:
break;
}
if(hbr == NULL)
hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
Any help would be greatly appreciated. If I can't get this to work I am going to have to turn of the PUSHLIKE feature and/or change the control altogether.
Thanks ahead of time.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|