Mouse buttons choosing color

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • darrellm58

    Mouse buttons choosing color

    THis code is straight out of a text book but the color is always black. It is suppossed to draw black with one mouse button and red with the other. Can anyone spot a problem? Thanks.
    ************
    void CMouseDlg::OnMo useMove(UINT nFlags, CPoint point)
    {

    if (((nFlags & MK_LBUTTON) == MK_LBUTTON) ||
    ((nFlags & MK_RBUTTON) == MK_RBUTTON))
    {

    CPen lpen;
    CClientDC dc(this);
    CPen* pPrevPen = NULL;



    if ((nFlags & MK_LBUTTON) == MK_LBUTTON)
    CPen lpen(PS_SOLID, 16, RGB(255,0,0));

    if ((nFlags & MK_RBUTTON) == MK_RBUTTON)
    CPen lpen(PS_SOLID, 16, RGB(255,0,0));

    pPrevPen = dc.SelectObject (&lpen);
    dc.MoveTo(m_iPr evx, m_iPrevy);
    dc.LineTo(point .x, point.y);
    m_iPrevx = point.x;
    m_iPrevy = point.y;
    dc.SelectObject (pPrevPen);
    }
    CDialog::OnMous eMove(nFlags, point);
    }




    void CMouseDlg::OnLB uttonDown(UINT nFlags, CPoint point)
    {
    m_iPrevx = point.x;
    m_iPrevy = point.y;
    CDialog::OnLBut tonDown(nFlags, point);
    }

    void CMouseDlg::OnRB uttonDown(UINT nFlags, CPoint point)
    {
    m_iPrevx = point.x;
    m_iPrevy = point.y;
    CDialog::OnRBut tonDown(nFlags, point);
    }
    *************** ****


  • Abhinaba Basu

    #2
    Re: Mouse buttons choosing color

    try the following code MouseMove
    =============== =============== =============== ========
    CPen lpen;
    CClientDC dc(this);
    CPen* pPrevPen = NULL;


    if ((nFlags & MK_LBUTTON) == MK_LBUTTON)
    lpen.CreatePen( PS_SOLID, 16, RGB(255,0,0));

    if ((nFlags & MK_RBUTTON) == MK_RBUTTON)
    lpen.CreatePen( PS_SOLID, 16, RGB(255,0,0));

    pPrevPen = dc.SelectObject (&lpen);
    dc.MoveTo(m_iPr evx, m_iPrevy);
    dc.LineTo(point .x, point.y);
    m_iPrevx = point.x;
    m_iPrevy = point.y;
    dc.SelectObject (pPrevPen);
    =============== =============== =============== ========

    Notice that I have changed the CPen lpen(....) to lpen.CreatePen

    I think this will work for you.

    "darrellm58 " <darrellm58@dis cussions.micros oft.com> wrote in message
    news:ED954013-2B3C-47F9-BE46-0B739856F499@mi crosoft.com...[color=blue]
    > THis code is straight out of a text book but the color is always black. It[/color]
    is suppossed to draw black with one mouse button and red with the other. Can
    anyone spot a problem? Thanks.[color=blue]
    > ************
    > void CMouseDlg::OnMo useMove(UINT nFlags, CPoint point)
    > {
    >
    > if (((nFlags & MK_LBUTTON) == MK_LBUTTON) ||
    > ((nFlags & MK_RBUTTON) == MK_RBUTTON))
    > {
    >
    > CPen lpen;
    > CClientDC dc(this);
    > CPen* pPrevPen = NULL;
    >
    >
    >
    > if ((nFlags & MK_LBUTTON) == MK_LBUTTON)
    > CPen lpen(PS_SOLID, 16, RGB(255,0,0));
    >
    > if ((nFlags & MK_RBUTTON) == MK_RBUTTON)
    > CPen lpen(PS_SOLID, 16, RGB(255,0,0));
    >
    > pPrevPen = dc.SelectObject (&lpen);
    > dc.MoveTo(m_iPr evx, m_iPrevy);
    > dc.LineTo(point .x, point.y);
    > m_iPrevx = point.x;
    > m_iPrevy = point.y;
    > dc.SelectObject (pPrevPen);
    > }
    > CDialog::OnMous eMove(nFlags, point);
    > }
    >
    >
    >
    >
    > void CMouseDlg::OnLB uttonDown(UINT nFlags, CPoint point)
    > {
    > m_iPrevx = point.x;
    > m_iPrevy = point.y;
    > CDialog::OnLBut tonDown(nFlags, point);
    > }
    >
    > void CMouseDlg::OnRB uttonDown(UINT nFlags, CPoint point)
    > {
    > m_iPrevx = point.x;
    > m_iPrevy = point.y;
    > CDialog::OnRBut tonDown(nFlags, point);
    > }
    > *************** ****
    >
    >[/color]


    Comment

    Working...