PDA

View Full Version : Q on dragging the mouse in a Canvas Window



dcromley
04-09-2010, 05:02
Hi,

Here's a short program that works -- just drag the mouse in the Canvas Window to draw tracks in the window.

My question -- am I missing anything? -- are there other thinBasic features that I should be using?

Thanks, Dave


Uses "UI"

Begin Const
%xLeft = 40
%yUpper = 30
End Const

Sub TBMain()
Local hwnd, x1, y1 As Long
GetAsyncKeyState(-1)
hWnd = Canvas_Window "Drag the mouse - ESC to exit", %xLeft, %yUpper, 400, 300
Canvas_Attach hWnd, 0, %FALSE
Do While CkWin(hwnd)
If MouseDown(x1, y1) Then
Canvas_Ellipse x1-3, y1-3, x1+3, y1+3, , -1
End If
loop
End Sub

Function CkWin(hwnd As Long) ' stop if no window or ESC
If Not IsWindow(hwnd) Then Stop
If GetAsyncKeyState(%VK_ESCAPE) <> 0 Then Stop
Function = -1
End Function

Function MouseDown(ByRef px As Long, ByRef py As Long) As Long
Local p1 As pointapi
Function = GetAsyncKeyState(%VK_LBUTTON) ' mousedown
Win_GetCursorPos(p1)
px = p1.x - %xLeft - 3: py = p1.y - %yUpper - 29 ' correction ?
End Function

ErosOlmi
04-09-2010, 13:14
Your code is correct I think.

Recently I added a new canvas feature that let you check is mouse has been clicked since last time function has been executed:

Do While CkWin(hwnd)
If Canvas_Window Click hWnd To x1, y1 Then
Canvas_Ellipse x1-3, y1-3, x1+3, y1+3, , -1
End If
Loop

Problem of the above code is that it will not return a mouse still down event.

dcromley
12-09-2010, 17:04
Thanks Eros,

You are always so responsive.

I'm getting into learning Dialogs and Callback.
Such wonderful samples and writeups in SampleScripts and
Tutorials and thinBasic Journals. Dave