Hi

Can somebody tell me how to draw a line from a given point in a window to the mouse cursor point when the mousebutton is clicked.

Regards
Posted on 2003-04-26 10:57:58 by minor28
The LineTo function draws a line from the current position up to, but not including, the specified point.

(I'm "assuming" you wanted the Windows API function.)

Raymond
Posted on 2003-04-26 12:25:45 by Raymond
here a sample i found on the web ...

LineDemo

This is another demo based on a "C" example in Charles Petzold's
"Programming Windows" 5th edition. It demonstrates how to draw lines, rectangles,
ellipses and rectangles with round corners. It also shows how we can fill
areas with colour and with patterns.

Files included are:-

Linedemo.exe The demo
Linedemo.asm the source
Makefile

Ron Thomas.

Ron_Thom@Compuserve.com

www.rbthomas.freeserve.co.uk

10/5/99

here:
Posted on 2003-04-26 12:38:21 by Nguga
Thanks for your hints

I will try to draw a line now.

Regards
Posted on 2003-04-26 13:17:13 by minor28
It will not work. The API LineTo succeeds but no line is drawn. I want to draw a line in a special window of another process. I get the window handle and the hitpoint by a mousehook. To ensure the right window I enumerate the windows and do the function LineTo in the callback function of enumerate child windows.

The messagebeep beeps so the function has succeeded but no line is drawn. Any suggestions.

Here is a excerpt from my code
MouseProc proc nCode:DWORD,wParam:DWORD,lParam:DWORD

LOCAL hitpoint:POINT
.if wParam==WM_LBUTTONDOWN
invoke CallNextHookEx,hMouseHook,nCode,wParam,lParam
mov edx,lParam
assume edx:PTR MOUSEHOOKSTRUCT
mov ax,word ptr [edx].pt.x
mov hitpoint.x,eax
mov ax,word ptr [edx].pt.y
mov hitpoint.y,eax
invoke WindowFromPoint,hitpoint.x,hitpoint.y
invoke PostMessage,hWnd,WM_MOUSEHOOKWND,addr hitpoint,eax
assume edx:nothing
.endif
xor eax,eax
ret
MouseProc endp

DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
.elseif eax==WM_MOUSEHOOKWND
mov eax,wParam
and eax,0ffffh
mov hitpoint.x,eax
mov eax,wParam
shr eax,16
mov hitpoint.y,eax
invoke EnumWindows,addr FindMapProc,lParam

FindMapProc proc hwnd:HWND,lParam:LPARAM
invoke FindWindow,addr lpClassName1,0
.if eax==hwnd
invoke EnumChildWindows,hwnd,addr FindChildMapProc,lParam
.endif
mov eax,TRUE
ret
FindMapProc endp

FindChildMapProc proc hwnd:HWND,lParam:LPARAM
invoke FindWindowEx,hwnd,0,addr lpClassName2,0
.if eax!=0
invoke GetWindowDC,lParam
.if eax!=0
mov hDC,eax
invoke LineTo,hDC,hitpoint.x,hitpoint.y
.if eax==TRUE
invoke MessageBeep,0FFFFFFFFh
.endif
.endif
FindChildMapProc endp

Regards
Posted on 2003-04-26 16:18:48 by minor28
Hi minor28,

You have to use LineTo and MoveToEx in combination. This is an exerpt from a proggy that draws points at mouseclick location then joins the points:



.ELSE
invoke MoveToEx,hdc,hitpoint_old.x,hitpoint_old.y,NULL
invoke LineTo,hdc,hitpoint.x,hitpoint.y
mov eax,hitpoint.x
mov hitpoint_old.x,eax
mov eax,hitpoint.y
mov hitpoint_old.y,eax



best regards,

czDrillard
Posted on 2003-04-26 19:42:44 by czDrillard
Hi czDrillard

I had a try on this
invoke GetWindowDC,lParam

.if eax!=0
mov hDC,eax
invoke MoveToEx,hDC,hitpoint.x-100,hitpoint.y-100,NULL
.if eax==TRUE
invoke LineTo,hDC,hitpoint.x,hitpoint.y
.if eax==TRUE
invoke MessageBeep,0FFFFFFFFh
.endif
.endif


It beeps but no line. The point is that I want to draw the line from a given point in the window, like hitpoint.x-100. Any suggestions.

Regards
Posted on 2003-04-27 10:38:06 by minor28
Im surprised that assembled.

Your not dealing with a high level syntax like C++. If your getting a value, that would be unknown at compile time (such as the future choice of a persons click poin), you can not ask the assembler to subtract 100 from it. It doesnt know what to subtract from.

If it compliled, then your hitpoint.x/y is already preset as a number (and the assembler is hard-coding one invariant line which is probably off the hDC viewing area.)

:NaN:
Posted on 2003-04-27 10:54:03 by NaN
Hi minor28,

Can't help much on that. Not sure what your goal is. Subtracting 100 from your x,y co-ordinates just re-maps the co-ordinates in a different screen location. What happens if you end up with a negative number? If you get stuck I can email you the source for my line drawing proggy.

best regards,

czDrillard
Posted on 2003-04-27 13:46:11 by czDrillard
Hi NaN,czDrillard,

I only have a litle experience in VBA and VB high level syntax, but on a level lower than my masm knowledge. That's why I am grateful for all eruditions I can get.

The code assembled alright but the value of hitpont.x-100 was equal to 0. So the erudition from your contribution is this.
invoke GetWindowDC,lParam

.if eax!=0
mov hDC,eax
mov eax,point.x
sub eax,50
mov x,eax
mov eax,point.y
sub eax,50
mov y,eax
invoke MoveToEx,hDC,x,y,NULL
.if eax==TRUE
invoke LineTo,hDC,point.x,point.y
.if eax==TRUE
invoke wsprintf,addr lpOut,SADD('x=%ld(%ld) / y=%ld(%ld)'),x,point.x,y,point.y
invoke SetDlgItemText,hDlg,IDC_EDT1,addr lpOut
.endif
.endif
.endif

Don't take the subtracting too serious. It's only a little stand alone testing code to get the knowhow to draw a line. The purpose of the subracting is only to achieve an "old position". However no line is drawn but the MoveToEx and LineTo functions have succeeded.

Since the point.x and point.y have got their values from a POINT structure in a MOUSEHOOKSTRUCT structure I suppose the values represent screen coordinates.

Should theese values be in DC coordinates or something else and in that case how do I convert the values.

Best regards
Posted on 2003-04-29 08:16:26 by minor28
I found the solution. API GetDCOrgEx.
invoke GetWindowDC,lParam

.if eax!=0
mov hDC,eax
invoke GetDCOrgEx,hDC,addr lpPoint
.if eax==TRUE
mov eax,point.x
sub eax,lpPoint.x
sub eax,50
mov x,eax
mov eax,point.y
sub eax,lpPoint.y
sub eax,50
mov y,eax
invoke MoveToEx,hDC,x,y,NULL
.if eax==TRUE
mov eax,point.x
sub eax,lpPoint.x
mov x,eax
mov eax,point.y
sub eax,lpPoint.y
mov y,eax
invoke LineTo,hDC,x,y
.endif
.endif
.endif

This has drawn a line.

Best regards
Posted on 2003-04-29 09:55:19 by minor28