Skip to content

changing text color using CColorDialog

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #191115
    asha
    Member

    i have a string whose textcolor is to be changed as selected by user from colordialog ?

    CDC *hWndDC;//declared this globally
    COLORREF m_crColor; //in header file

     

    CString strTitle;
    
    void CMainWnd::OnTimer(UINT_PTR nIDEvent)
    {
    ......................
    hWndDC->TextOut(pt.x,5,strTitle,(char)strlen(strTitle));
    .........
    }
    
    void CMainWnd::OnTimeSettings() //menu p0
    {
    CColorDialog colorDlg;
    
    if (colorDlg.DoModal() == IDOK)
    {
    
    m_crColor = colorDlg.GetColor();
    hWndDC->SetTextColor(m_crColor);
    
    }
    }

    m_crColor is to be assigned to strTitle ( SDI );

    how should i do ?plz give me an idea

    i found (when i debugged the program) that m_crColor has the color that i selected from the color dialog but i am not able to assign it to the strTitle.

    #191118
    Chike
    Member

    sprintf?

    Why do you cast strlen to char?

    #191117
    asha
    Member

    because the last argument is
    nCount = Specifies the number of bytes in the string

    void CMainWnd::OnTimeSettings()//is a menu item
    {
    CColorDialog colorDlg;
    if (colorDlg.DoModal() == IDOK)
    {
    m_crColor = colorDlg.GetColor();
    hWndDC->SetTextColor(m_crColor);
    
    }
    }

     

    why is this not working ? what should i do ?

    #191116
    Chike
    Member

    @asha wrote:

    because the last argument is
    nCount = Specifies the number of bytes in the string

    Of type int. Type char is 8 bit signed integer, any value over 127 will turn into negative number.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.