By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,960 Members | 2,459 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,960 IT Pros & Developers. It's quick & easy.

Mouse buttons choosing color

P: n/a
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);
}
*******************
Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.

"darrellm58" <da********@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.com...
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);
}
*******************

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.