1. win32lib mouse question
- Posted by Mark Brown <mabrown at SENET.COM.AU> Jul 19, 2000
- 385 views
------=_NextPart_000_0005_01BFF125.C47D6760 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all. I have a win32lib question that I know has been asked before. Following an "onMouse" event, is there a simple way to receive another mouse event (like a second mouse button click) from within the onMouse=20 procedure? What I want to do is something simple like click at a point in the = window and draw a line from the first clicked point to whatever the current = mouse position is until the mouse is again clicked (or perhaps the button is released). I have achieved it by hacking at win32lib a bit (got a global to the MSG structure and "fetched" the message) but is there a simpler way? Also, my attempts at using getMousePos() results in the x,y being = different to the actual mouse position. I have a vague memory from the Amiga=20 regarding the difference between screen coords and logical coords and = functions to convert from one to the other. Is this the problem? Many thanks in advance. Mark ------=_NextPart_000_0005_01BFF125.C47D6760 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT size=3D2>Hi all.</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>I have a win32lib question that I know has been = asked=20 before.</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>Following an "onMouse" event, is there a simple way = to receive=20 another</FONT></DIV> <DIV><FONT size=3D2>mouse event (like a second mouse button click) from = within the=20 onMouse </FONT></DIV> <DIV><FONT size=3D2>procedure?</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>What I want to do is something simple like click at = a point in=20 the window</FONT></DIV> <DIV><FONT size=3D2>and draw a line from the first clicked point to = whatever the=20 current mouse</FONT></DIV> <DIV><FONT size=3D2>position is until the mouse is again clicked (or = perhaps the=20 button is</FONT></DIV> <DIV><FONT size=3D2>released).</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>I have achieved it by hacking at win32lib a bit (got = a global=20 to the MSG</FONT></DIV> <DIV><FONT size=3D2>structure and "fetched" the message) but is there a = simpler=20 way?</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>Also, my attempts at using getMousePos() results in = the x,y=20 being different</FONT></DIV> <DIV><FONT size=3D2>to the actual mouse position. I have a vague memory = from the=20 Amiga </FONT></DIV> <DIV><FONT size=3D2>regarding the difference between screen coords and = logical=20 coords and functions</FONT></DIV> <DIV><FONT size=3D2>to convert from one to the other. Is this the=20 problem?</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>Many thanks in advance.</FONT></DIV> <DIV> </DIV> ------=_NextPart_000_0005_01BFF125.C47D6760--
2. Re: win32lib mouse question
- Posted by Brian Broker <bkb at CNW.COM> Jul 19, 2000
- 399 views
- Last edited Jul 20, 2000
On Wed, 19 Jul 2000 02:05:10 +0930, Mark Brown wrote: >Hi all. > >I have a win32lib question that I know has been asked before. > >Following an "onMouse" event, is there a simple way to receive another >mouse event (like a second mouse button click) from within the onMouse >procedure? Your onMouse routine gets passed 4 variables: event, x, y, and shift. You can do different actions for different events (MouseMove, LeftDown, RightDown, LeftUp, etc. see win32lib.htm for more info) by using if-then statements. For Example (warning: untested code): -- global variables integer startX, startY, endX, endY procedure onMouse_Win( integer event, integer x, integer y, integer shift ) if event = LeftDown then -- starting point of line is (x,y) startX = x startY = y elsif event = LeftUp then -- ending point of line is new (x,y) endX = x endY = y -- since we actually draw the line here we really don't need -- endX nor endY, you could just pass x and y to drawLine... -- but you might want the end coordinates for another routine drawLine( Win, startX, startY, endX, endY ) end if end procedure onMouse[Win] = routine_id( "onMouse_Win" ) -- end example 1 if you wanted to use separate mouse clicks you could modify like so (again, this is an untested example): -- global variables integer startX, startY, endX, endY, first_click first_click = True procedure onMouse_Win( integer event, integer x, integer y, integer shift ) if event = LeftDown then if first_click then -- starting point of line is (x,y) first_click = False startX = x startY = y else -- ending point of line is new (x,y) first_click = True endX = x endY = y drawLine( Win, startX, startY, endX, endY ) end if end if end procedure onMouse[Win] = routine_id( "onMouse_Win" ) -- end example 2 >Also, my attempts at using getMousePos() results in the x,y being different >to the actual mouse position. I have a vague memory from the Amiga >regarding the difference between screen coords and logical coords and >functions to convert from one to the other. Is this the problem? getMousePos returns the screen coordinates for the mouse cursor (the position on your desktop, not the window). The x and y passed to your onMouse routine are the coordinates relative to your window... For a tested example, check out the 'Scribble.exw' demo included with Win32Lib. (Scribble is an example used to demonstrate David's IDE.) -- Brian
3. Re: win32lib mouse question
- Posted by Mark Brown <mabrown at SENET.COM.AU> Jul 19, 2000
- 405 views
------=_NextPart_000_000B_01BFF197.802928C0 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Many thanks Brian (and David). I think I understand how I should be using these events now. I busy looped my second mouse click. I guess that is a=20 no-no ! It looks so simple when someone does it for you. Mark ----- Original Message -----=20 From: Brian Broker=20 To: EUPHORIA at LISTSERV.MUOHIO.EDU=20 Sent: Thursday, July 20, 2000 11:17 Subject: Re: win32lib mouse question On Wed, 19 Jul 2000 02:05:10 +0930, Mark Brown wrote: >Hi all. > >I have a win32lib question that I know has been asked before. > >Following an "onMouse" event, is there a simple way to receive = another >mouse event (like a second mouse button click) from within the = onMouse >procedure? Your onMouse routine gets passed 4 variables: event, x, y, and shift. = You can do different actions for different events (MouseMove, LeftDown, RightDown, LeftUp, etc. see win32lib.htm for more info) by using = if-then statements. For Example (warning: untested code): -- global variables integer startX, startY, endX, endY procedure onMouse_Win( integer event, integer x, integer y, integer = shift ) if event =3D LeftDown then -- starting point of line is (x,y) startX =3D x startY =3D y elsif event =3D LeftUp then -- ending point of line is new (x,y) endX =3D x endY =3D y -- since we actually draw the line here we really don't need -- endX nor endY, you could just pass x and y to drawLine... -- but you might want the end coordinates for another routine drawLine( Win, startX, startY, endX, endY ) end if end procedure onMouse[Win] =3D routine_id( "onMouse_Win" ) -- end example 1 if you wanted to use separate mouse clicks you could modify like so = (again, this is an untested example): -- global variables integer startX, startY, endX, endY, first_click first_click =3D True procedure onMouse_Win( integer event, integer x, integer y, integer = shift ) if event =3D LeftDown then if first_click then -- starting point of line is (x,y) first_click =3D False startX =3D x startY =3D y else -- ending point of line is new (x,y) first_click =3D True endX =3D x endY =3D y drawLine( Win, startX, startY, endX, endY ) end if end if end procedure onMouse[Win] =3D routine_id( "onMouse_Win" ) -- end example 2 >Also, my attempts at using getMousePos() results in the x,y being = different >to the actual mouse position. I have a vague memory from the Amiga >regarding the difference between screen coords and logical coords and >functions to convert from one to the other. Is this the problem? getMousePos returns the screen coordinates for the mouse cursor (the position on your desktop, not the window). The x and y passed to your onMouse routine are the coordinates relative to your window... For a tested example, check out the 'Scribble.exw' demo included with Win32Lib. (Scribble is an example used to demonstrate David's IDE.) -- Brian ------=_NextPart_000_000B_01BFF197.802928C0 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT size=3D2>Many thanks Brian (and David).</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>I think I understand how I should be using these = events=20 now.</FONT></DIV> <DIV><FONT size=3D2>I busy looped my second mouse click. I guess that is = a=20 </FONT></DIV> <DIV><FONT size=3D2>no-no ! It looks so simple when someone does it for=20 you.</FONT></DIV> <DIV> </DIV> <DIV><FONT size=3D2>Mark</FONT></DIV> <BLOCKQUOTE=20 style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: = 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px"> <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV> <DIV=20 style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: = black"><B>From:</B>=20 <A href=3D"mailto:bkb at CNW.COM" title=3Dbkb at CNW.COM>Brian Broker</A> = </DIV> <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A=20 href=3D"mailto:EUPHORIA at LISTSERV.MUOHIO.EDU"=20 title=3DEUPHORIA at LISTSERV.MUOHIO.EDU>EUPHORIA at LISTSERV.MUOHIO.EDU</A> = </DIV> <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Thursday, July 20, 2000 = 11:17</DIV> <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Re: win32lib mouse=20 question</DIV> <DIV><BR></DIV>On Wed, 19 Jul 2000 02:05:10 +0930, Mark Brown=20 wrote:<BR><BR>>Hi all.<BR>><BR>>I have a win32lib question = that I=20 know has been asked before.<BR>><BR>>Following an "onMouse" = event, is=20 there a simple way to receive another<BR>>mouse event (like a = second mouse=20 button click) from within the onMouse<BR>>procedure?<BR><BR>Your = onMouse=20 routine gets passed 4 variables: event, x, y, and shift. = You<BR>can do=20 different actions for different events (MouseMove, = LeftDown,<BR>RightDown,=20 LeftUp, etc. see win32lib.htm for more info) by using=20 if-then<BR>statements.<BR><BR>For Example (warning: untested = code):<BR><BR>--=20 global variables<BR>integer startX, startY, endX, = endY<BR><BR>procedure=20 onMouse_Win( integer event, integer x, integer y, integer shift = )<BR> if=20 event =3D LeftDown then<BR> -- starting point of = line is=20 (x,y)<BR> startX =3D x<BR> startY = =3D=20 y<BR> elsif event =3D LeftUp then<BR> -- = ending point of=20 line is new (x,y)<BR> endX =3D = x<BR> endY =3D=20 y<BR> -- since we actually draw the line here we = really=20 don't need<BR> -- endX nor endY, you = could just=20 pass x and y to drawLine...<BR> -- but you might = want the=20 end coordinates for another routine<BR> drawLine( = Win,=20 startX, startY, endX, endY )<BR> end if<BR>end = procedure<BR>onMouse[Win]=20 =3D routine_id( "onMouse_Win" )<BR><BR>-- end example 1<BR><BR>if you = wanted to=20 use separate mouse clicks you could modify like so (again,<BR>this is = an=20 untested example):<BR><BR>-- global variables<BR>integer startX, = startY, endX,=20 endY, first_click<BR><BR>first_click =3D True<BR><BR>procedure = onMouse_Win(=20 integer event, integer x, integer y, integer shift )<BR> if = event =3D=20 LeftDown then<BR> if first_click=20 then<BR> -- starting point of line is=20 (x,y)<BR> first_click =3D=20 False<BR> startX =3D=20 x<BR> startY =3D y<BR> = else<BR> -- ending point of line is new=20 (x,y)<BR> first_click =3D=20 True<BR> endX =3D=20 x<BR> endY =3D = y<BR> =20 drawLine( Win, startX, startY, endX, endY )<BR> end=20 if<BR> end if<BR>end procedure<BR>onMouse[Win] =3D routine_id(=20 "onMouse_Win" )<BR><BR>-- end example 2<BR><BR><BR>>Also, my = attempts at=20 using getMousePos() results in the x,y being different<BR>>to the = actual=20 mouse position. I have a vague memory from the Amiga<BR>>regarding = the=20 difference between screen coords and logical coords = and<BR>>functions to=20 convert from one to the other. Is this the problem?<BR><BR>getMousePos = returns=20 the screen coordinates for the mouse cursor (the<BR>position on your = desktop,=20 not the window). The x and y passed to your<BR>onMouse routine = are the=20 coordinates relative to your window...<BR><BR>For a tested example, = check out=20 the 'Scribble.exw' demo included with<BR>Win32Lib. (Scribble is = an=20 example used to demonstrate David's IDE.)<BR><BR><BR><BR>--=20 ------=_NextPart_000_000B_01BFF197.802928C0--