Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

how do you change 'static text box' text color...

grahamojgrahamoj Member Posts: 366
hiya i have a popup dialog for login, and want to change the text of the static text box.. the class of this dialog is called 'CLoginDialog' so this is what i tried..

// set static text color
CColorDialog *pStatic;
pStatic = (CColorDialog*)AfxGetApp()->GetMainWnd();
pStatic->GetDlgItem( IDC_STATIC );
pStatic->SetCurrentColor(RGB(0,0,255));

but know this is wrong...any ideas??

thanks,
grahamoj.

Comments

  • pingpongpingpong Member Posts: 937
    grahamoj,

    In your CLoginDialog, add a handler of OnCtlColor, check out MSDN help for OnCtlColor for an example.

    Note that I recommend you change the static control ID you are trying to work with to something other than the default IDC_STATIC, IDC_STATIC is -1, there's no way of distinguishing one static from the other, all are -1, morever, I think (not 100% sure) that if the ID is -1, the control wont send any notifications back to its parent, it probably wont send OnCtlColor either.

    : hiya i have a popup dialog for login, and want to change the text of the static text box.. the class of this dialog is called 'CLoginDialog' so this is what i tried..
    :
    : // set static text color
    : CColorDialog *pStatic;
    : pStatic = (CColorDialog*)AfxGetApp()->GetMainWnd();
    : pStatic->GetDlgItem( IDC_STATIC );
    : pStatic->SetCurrentColor(RGB(0,0,255));
    :
    : but know this is wrong...any ideas??
    :
    : thanks,
    : grahamoj.
    :

  • grahamojgrahamoj Member Posts: 366
    : grahamoj,
    :
    : In your CLoginDialog, add a handler of OnCtlColor, check out MSDN help for OnCtlColor for an example.
    :
    : Note that I recommend you change the static control ID you are trying to work with to something other than the default IDC_STATIC, IDC_STATIC is -1, there's no way of distinguishing one static from the other, all are -1, morever, I think (not 100% sure) that if the ID is -1, the control wont send any notifications back to its parent, it probably wont send OnCtlColor either.
    :
    : : hiya i have a popup dialog for login, and want to change the text of the static text box.. the class of this dialog is called 'CLoginDialog' so this is what i tried..
    : :
    : : // set static text color
    : : CColorDialog *pStatic;
    : : pStatic = (CColorDialog*)AfxGetApp()->GetMainWnd();
    : : pStatic->GetDlgItem( IDC_STATIC );
    : : pStatic->SetCurrentColor(RGB(0,0,255));
    : :
    : : but know this is wrong...any ideas??
    : :
    : : thanks,
    : : grahamoj.
    : :
    :
    :

    hiya thanks, this is what i did..

    HBRUSH CLoginDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here

    CLoginDialog *pLogin;
    pLogin = (CLoginDialog*)AfxGetApp()->GetMainWnd();
    pLogin->GetDlgItem( IDC_WARNING );
    pDC->SetTextColor(RGB(0,0,255));

    // TODO: Return a different brush if the default is not desired
    return hbr;
    }

    (i changed the name as suggested) the only problem is that it changes ALL static text on dialog to blue. am i doing something wrong to change just the IDC_WARNING text??

    thanks,
    grahamoj.

  • pingpongpingpong Member Posts: 937
    Try this
    [code]
    HBRUSH CLoginDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here

    // is this the IDC_WARNING control?
    if(pWnd->GetDlgCtrlID() == IDC_WARNING)
    {
    // yes, change text color
    pDC->SetTextColor(RGB(0,0,255));
    }

    // TODO: Return a different brush if the default is not desired
    return hbr;
    }
    [/code]
    I dont know why are you using
    [code]
    CLoginDialog *pLogin = (CLoginDialog*)AfxGetApp()->GetMainWnd();
    [/code]
    You dont need that as far as I can tell from your code, you are already inside CLoginDialog.


    : : grahamoj,
    : :
    : : In your CLoginDialog, add a handler of OnCtlColor, check out MSDN help for OnCtlColor for an example.
    : :
    : : Note that I recommend you change the static control ID you are trying to work with to something other than the default IDC_STATIC, IDC_STATIC is -1, there's no way of distinguishing one static from the other, all are -1, morever, I think (not 100% sure) that if the ID is -1, the control wont send any notifications back to its parent, it probably wont send OnCtlColor either.
    : :
    : : : hiya i have a popup dialog for login, and want to change the text of the static text box.. the class of this dialog is called 'CLoginDialog' so this is what i tried..
    : : :
    : : : // set static text color
    : : : CColorDialog *pStatic;
    : : : pStatic = (CColorDialog*)AfxGetApp()->GetMainWnd();
    : : : pStatic->GetDlgItem( IDC_STATIC );
    : : : pStatic->SetCurrentColor(RGB(0,0,255));
    : : :
    : : : but know this is wrong...any ideas??
    : : :
    : : : thanks,
    : : : grahamoj.
    : : :
    : :
    : :
    :
    : hiya thanks, this is what i did..
    :
    : HBRUSH CLoginDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    : {
    : HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    :
    : // TODO: Change any attributes of the DC here
    :
    : CLoginDialog *pLogin;
    : pLogin = (CLoginDialog*)AfxGetApp()->GetMainWnd();
    : pLogin->GetDlgItem( IDC_WARNING );
    : pDC->SetTextColor(RGB(0,0,255));
    :
    : // TODO: Return a different brush if the default is not desired
    : return hbr;
    : }
    :
    : (i changed the name as suggested) the only problem is that it changes ALL static text on dialog to blue. am i doing something wrong to change just the IDC_WARNING text??
    :
    : thanks,
    : grahamoj.
    :
    :

  • grahamojgrahamoj Member Posts: 366
    : Try this
    : [code]
    : HBRUSH CLoginDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    : {
    : HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    :
    : // TODO: Change any attributes of the DC here
    :
    : // is this the IDC_WARNING control?
    : if(pWnd->GetDlgCtrlID() == IDC_WARNING)
    : {
    : // yes, change text color
    : pDC->SetTextColor(RGB(0,0,255));
    : }
    :
    : // TODO: Return a different brush if the default is not desired
    : return hbr;
    : }
    : [/code]
    : I dont know why are you using
    : [code]
    : CLoginDialog *pLogin = (CLoginDialog*)AfxGetApp()->GetMainWnd();
    : [/code]
    : You dont need that as far as I can tell from your code, you are already inside CLoginDialog.
    :
    :
    : : : grahamoj,
    : : :
    : : : In your CLoginDialog, add a handler of OnCtlColor, check out MSDN help for OnCtlColor for an example.
    : : :
    : : : Note that I recommend you change the static control ID you are trying to work with to something other than the default IDC_STATIC, IDC_STATIC is -1, there's no way of distinguishing one static from the other, all are -1, morever, I think (not 100% sure) that if the ID is -1, the control wont send any notifications back to its parent, it probably wont send OnCtlColor either.
    : : :
    : : : : hiya i have a popup dialog for login, and want to change the text of the static text box.. the class of this dialog is called 'CLoginDialog' so this is what i tried..
    : : : :
    : : : : // set static text color
    : : : : CColorDialog *pStatic;
    : : : : pStatic = (CColorDialog*)AfxGetApp()->GetMainWnd();
    : : : : pStatic->GetDlgItem( IDC_STATIC );
    : : : : pStatic->SetCurrentColor(RGB(0,0,255));
    : : : :
    : : : : but know this is wrong...any ideas??
    : : : :
    : : : : thanks,
    : : : : grahamoj.
    : : : :
    : : :
    : : :
    : :
    : : hiya thanks, this is what i did..
    : :
    : : HBRUSH CLoginDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    : : {
    : : HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    : :
    : : // TODO: Change any attributes of the DC here
    : :
    : : CLoginDialog *pLogin;
    : : pLogin = (CLoginDialog*)AfxGetApp()->GetMainWnd();
    : : pLogin->GetDlgItem( IDC_WARNING );
    : : pDC->SetTextColor(RGB(0,0,255));
    : :
    : : // TODO: Return a different brush if the default is not desired
    : : return hbr;
    : : }
    : :
    : : (i changed the name as suggested) the only problem is that it changes ALL static text on dialog to blue. am i doing something wrong to change just the IDC_WARNING text??
    : :
    : : thanks,
    : : grahamoj.
    : :
    : :
    :
    :

  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    _________ / http://forcoder.org / free video tutorials and ebooks about / JavaScript, Visual Basic .NET, PL/SQL, Visual Basic, Perl, Go, Java, Python, Ruby, R, C#, C, Objective-C, MATLAB, PHP, Assembly, C++, Scratch, Delphi, Swift Dart, Alice, COBOL, Erlang, Lisp, Prolog, Fortran, Hack, Clojure, Awk, Scala, Logo, ABAP, ML, FoxPro, Transact-SQL, Bash, LabVIEW, Ada, Kotlin, Scheme, Julia, SAS, F#, Apex, D, Crystal, VBScript, Lua, Rust / _

Sign In or Register to comment.