Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2004

Tip: Looking for answers? Try searching our database.

Mouse buttons choosing color

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
darrellm58 - 12 Jul 2004 21:39 GMT
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::OnMouseMove(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_iPrevx, m_iPrevy);
        dc.LineTo(point.x, point.y);
        m_iPrevx = point.x;
        m_iPrevy = point.y;
        dc.SelectObject(pPrevPen);
    }
    CDialog::OnMouseMove(nFlags, point);
    }

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

void CMouseDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
    m_iPrevx = point.x;
    m_iPrevy = point.y;
    CDialog::OnRButtonDown(nFlags, point);
}
*******************
Abhinaba Basu - 13 Jul 2004 10:48 GMT
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_iPrevx, 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.

> 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::OnMouseMove(UINT nFlags, CPoint point)
[quoted text clipped - 38 lines]
> }
> *******************

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.