How can I change lines color? 
Author Message
 How can I change lines color?

Hi,

How can I change lines color in a function?
The following code does not work.

for(int i=0; i<5000; i++)
{
        // Draw with color1
        HPEN hPen1 = ::CreatePen(PS_SOLID, 0, Color1);
        HPEN hOldPen1 = (HPEN)::SelectObject(m_hDC, hPen1);

        ::MoveToEx(m_hDC, x1[i], y1[i], NULL);
        ::LineTo(m_hDC, x2[i], y2[i]);

        ::SelectObject(m_hDC, hOldPen1);
        ::DeleteObject(hPen1);  

        // Draw with color2
        HPEN hPen2 = ::CreatePen(PS_SOLID, 0, Color2);
        HPEN hOldPen2 = (HPEN)::SelectObject(m_hDC, hPen2);

        ::MoveToEx(m_hDC, x1[i], y3[i], NULL);
        ::LineTo(m_hDC, x2[i], y4[i]);

        ::SelectObject(m_hDC, hOldPen2);
        ::DeleteObject(hPen2);  

Quote:
}

Regards,
Russel


Sat, 05 Jun 2004 19:23:28 GMT  
 How can I change lines color?
You should debug your application to see whether the pens are created
successfully and selected into HDC successfully.
There is no clear error in your code.


Sat, 05 Jun 2004 19:56:55 GMT  
 How can I change lines color?
Curious: are yu using MFC? If so, why are you using raw C drawing methods? I don't see
anything wrong with this code. What effect are you seeing? All you said is "does not
work".
                        joe

Quote:

>Hi,

>How can I change lines color in a function?
>The following code does not work.

>for(int i=0; i<5000; i++)
>{
>    // Draw with color1
>    HPEN hPen1 = ::CreatePen(PS_SOLID, 0, Color1);
>    HPEN hOldPen1 = (HPEN)::SelectObject(m_hDC, hPen1);

>    ::MoveToEx(m_hDC, x1[i], y1[i], NULL);
>    ::LineTo(m_hDC, x2[i], y2[i]);

>    ::SelectObject(m_hDC, hOldPen1);
>    ::DeleteObject(hPen1);  

>    // Draw with color2
>    HPEN hPen2 = ::CreatePen(PS_SOLID, 0, Color2);
>    HPEN hOldPen2 = (HPEN)::SelectObject(m_hDC, hPen2);

>    ::MoveToEx(m_hDC, x1[i], y3[i], NULL);
>    ::LineTo(m_hDC, x2[i], y4[i]);

>    ::SelectObject(m_hDC, hOldPen2);
>    ::DeleteObject(hPen2);  
>}

>Regards,
>Russel

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Sun, 06 Jun 2004 03:22:10 GMT  
 How can I change lines color?
Hi,

How can I change lines color in a function?
The following code does not work. That is, the line colors
do not change. all are black. what's wrong with this?

for(int i=0; i<5000; i++)
{
        // Draw with color1
        HPEN hPen1 = ::CreatePen(PS_SOLID, 0, Color1);
        HPEN hOldPen1 = (HPEN)::SelectObject(m_hDC, hPen1);

        ::MoveToEx(m_hDC, x1[i], y1[i], NULL);
        ::LineTo(m_hDC, x2[i], y2[i]);

        ::SelectObject(m_hDC, hOldPen1);
        ::DeleteObject(hPen1);  

        // Draw with color2
        HPEN hPen2 = ::CreatePen(PS_SOLID, 0, Color2);
        HPEN hOldPen2 = (HPEN)::SelectObject(m_hDC, hPen2);

        ::MoveToEx(m_hDC, x1[i], y3[i], NULL);
        ::LineTo(m_hDC, x2[i], y4[i]);

        ::SelectObject(m_hDC, hOldPen2);
        ::DeleteObject(hPen2);  

Quote:
}

Please explain in more detail.

Regards,
Russel.



Sun, 06 Jun 2004 12:57:19 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Change text color of single line in CListBox?

2. How to change color of line (or row) in CListCtrl

3. Changing color of the background of a line

4. Changing text color in CListCtrl for only one line

5. How to change color in CListView (per line)

6. CListCtrl -- Changing the color of the selected line

7. Change CButton color and CButton text color in CDialog

8. Changing text colors(2 different colors) in ToolTips

9. Change text color and background color in CEditView

10. Change a part of Background color or a part of text color from CListCtrl

11. how to change my child window's border color and title bar color

12. How do I change the color of a Push Button color

 

 
Powered by phpBB® Forum Software