color the text in MFC Dialog
-
Hi, everyone: Can someone provide a EZ way to change an individual text in a dialog? I knew that I can use CDC functions to realize that, but can I do this on a Static Control? To talk in detail, I wanna use SetWindowText() or SetDlgItemText( ) to change the text of a control containing some text string. And what should I do to change the reulting text? Or don't think about that, simply use CDC functions? Thanks!
-
Hi, everyone: Can someone provide a EZ way to change an individual text in a dialog? I knew that I can use CDC functions to realize that, but can I do this on a Static Control? To talk in detail, I wanna use SetWindowText() or SetDlgItemText( ) to change the text of a control containing some text string. And what should I do to change the reulting text? Or don't think about that, simply use CDC functions? Thanks!
Handle the WM_CTLCOLOR message. In VS call the properties for the dialog, there you can set handlers for messages, in that list is a WM_CTLCOLOR message. Choose a function to handle this. Write something like this in it:
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); CBrush *brush; brush = NULL; // TODO: Change any attributes of the DC here CWnd* pStaticWnd = (CWnd*)GetDlgItem(IDC_STATIC_STATUS); if(pWnd == pStaticWnd){ pDC->SetTextColor(RGB(0, 0, 255)); } //end if pStaticWnd = (CWnd*)GetDlgItem(IDC_STATIC_INFO_DOC); if(pWnd == pStaticWnd){ if(lock_docstatus_text){ pDC->SetTextColor(RGB(0, 100, 200)); } //end if else{ pDC->SetTextColor(RGB(0, 0, 255)); } //end else } //end if pStaticWnd = (CWnd*)GetDlgItem(IDC_STATIC_INFO_SEND); if(pWnd == pStaticWnd){ if(lock_sendstatus_text){ pDC->SetTextColor(RGB(0, 100, 200)); } //end if else{ pDC->SetTextColor(RGB(0, 0, 255)); } //end else } //end if // TODO: Return a different brush if the default is not desired return hbr;
for more info check out msdn. Hope this helps, good luck. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix -
Hi, everyone: Can someone provide a EZ way to change an individual text in a dialog? I knew that I can use CDC functions to realize that, but can I do this on a Static Control? To talk in detail, I wanna use SetWindowText() or SetDlgItemText( ) to change the text of a control containing some text string. And what should I do to change the reulting text? Or don't think about that, simply use CDC functions? Thanks!
ytod wrote: To talk in detail, I wanna use SetWindowText() or SetDlgItemText( ) to change the text of a control containing some text string. And what should I do to change the reulting text? You just answered your own question. Use
SetWindowText()
.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
ytod wrote: To talk in detail, I wanna use SetWindowText() or SetDlgItemText( ) to change the text of a control containing some text string. And what should I do to change the reulting text? You just answered your own question. Use
SetWindowText()
.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
DavidCrow wrote: ytod wrote: To talk in detail, I wanna use SetWindowText() or SetDlgItemText( ) to change the text of a control containing some text string. And what should I do to change the reulting text? ;P Miss one word "color": And what should I do to change the reulting text "color"? But I need to try what the previous post described first, thanks!
-
Handle the WM_CTLCOLOR message. In VS call the properties for the dialog, there you can set handlers for messages, in that list is a WM_CTLCOLOR message. Choose a function to handle this. Write something like this in it:
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); CBrush *brush; brush = NULL; // TODO: Change any attributes of the DC here CWnd* pStaticWnd = (CWnd*)GetDlgItem(IDC_STATIC_STATUS); if(pWnd == pStaticWnd){ pDC->SetTextColor(RGB(0, 0, 255)); } //end if pStaticWnd = (CWnd*)GetDlgItem(IDC_STATIC_INFO_DOC); if(pWnd == pStaticWnd){ if(lock_docstatus_text){ pDC->SetTextColor(RGB(0, 100, 200)); } //end if else{ pDC->SetTextColor(RGB(0, 0, 255)); } //end else } //end if pStaticWnd = (CWnd*)GetDlgItem(IDC_STATIC_INFO_SEND); if(pWnd == pStaticWnd){ if(lock_sendstatus_text){ pDC->SetTextColor(RGB(0, 100, 200)); } //end if else{ pDC->SetTextColor(RGB(0, 0, 255)); } //end else } //end if // TODO: Return a different brush if the default is not desired return hbr;
for more info check out msdn. Hope this helps, good luck. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix -
DavidCrow wrote: ytod wrote: To talk in detail, I wanna use SetWindowText() or SetDlgItemText( ) to change the text of a control containing some text string. And what should I do to change the reulting text? ;P Miss one word "color": And what should I do to change the reulting text "color"? But I need to try what the previous post described first, thanks!
Using
OnCtlColor()
, or handling theWM_CTLCOLOR
message, is the preferred method.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow