changing text color using CColorDialog

Here you can talk about C++ And C# And Other languages programming.

changing text color using CColorDialog

Postby asha » Sun Feb 28, 2010 2:12 pm


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;

Code: Select all
             
                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.
asha
 
Posts: 2
Joined: Sun Feb 28, 2010 2:02 pm

Re: changing text color using CColorDialog

Postby Chike » Sun Feb 28, 2010 6:37 pm

sprintf?

Why do you cast strlen to char?
Image
Chike
imFiles Master
imFiles Master
 
Posts: 581
Joined: Sun May 13, 2007 6:20 pm

Re: changing text color using CColorDialog

Postby asha » Mon Mar 01, 2010 3:33 am

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

Code: Select all
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 ?
asha
 
Posts: 2
Joined: Sun Feb 28, 2010 2:02 pm

Re: changing text color using CColorDialog

Postby Chike » Mon Mar 01, 2010 2:52 pm

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.
Image
Chike
imFiles Master
imFiles Master
 
Posts: 581
Joined: Sun May 13, 2007 6:20 pm


Return to C++, C# And Others Programming

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 0 guests