473,387 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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::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
1 1519
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: BadOmen | last post by:
I want my program to send a mouse click to the window at the current mouse position, how do I do that? Example: I have my mouse over a button in Word and then my program is sending the left...
5
by: John Champaign | last post by:
Hi all, I'm working on an educational applet for a child with special needs. He's got a bit of a trick to make my life more difficult... To interact with the applet he needs to click on...
1
by: Zaidan | last post by:
I am running Excel2000 under WIN98 2nd edition, and I am writing a VBA code (I will consider using javascript if I have to) that does the following, at the user command: 1- Start MS Explorer and...
13
by: James Bond | last post by:
Hello. My 80+ year old father has recently decided to get his first computer. Due to his age (and I suspect lack of playing pong as a child like I did) he lacks the manual dexterity to use a mouse...
3
by: Vikash Yadav | last post by:
hi can any body tell me how to pick up events on toolbar buttons in vb.net i mean to say that i have one toolbar and buttons on it now i want mouseevents on those buttons like mouse over ,mouse...
2
by: scott_gui | last post by:
I am creating a Windows application: The mouse event <Double-Button-1> has a conflict when the <Button-1> event also has a binding. Double clicks will first perform the single click action. This...
7
by: Michael R | last post by:
It's an interesting question, as I see it. I have a form, in which there are a few command buttons, which change color when the mouse is on top of them (On Mouse Move). Now, I want the color to be...
6
by: shror | last post by:
i want to add a midi file to my pages and i want to put two radio buttons so that on is on and the other is off so that the users can start or stop the file playing by choosing one of the radio...
18
by: Shocky | last post by:
Hi there, I am trying to detect whether my IE6 users have pressed both right and left mouse buttons simultaneously in my Javascript code, by using: if(event.button==3) {alert("Both right and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.