PDA

View Full Version : canvas move control experiment



largo_winch
14-12-2011, 18:55
here's a little canvas example for moving controls. but only the second canvas can be moved. this example isn't perfect programmed for callback part, but it does work for one control. perhaps anybody can give some hints how to move first canvas box?


' Empty GUI script created on 12-14-2011 17:11:18 by (ThinAIR)

Uses "console", "ui"

Type POINT'API
x As Long
y As Long
End Type
Begin ControlID
%CanvasA
%CanvasB
End ControlID

Declare Function GetDlgCtrlID Lib "USER32.DLL" Alias "GetDlgCtrlID" (ByVal hWnd As DWord) As Long
Declare Function ChildWindowFromPoint Lib "USER32.DLL" Alias "ChildWindowFromPoint" (ByVal hwndParent As DWord, ByVal x As Long, ByVal y As Long) As DWord

Global hDlg As DWord

Function TBMain() As Long
Dialog New Pixels, 0, "my Drag Control Test",50,50,300,300, %WS_OVERLAPPEDWINDOW To hDlg
Control Add Canvas, hDlg, %CanvasA,"", 50,10,85,85, %WS_VISIBLE Or %WS_BORDER
Control Add Canvas, hDlg, %CanvasB,"", 50,125,85,85, %WS_VISIBLE Or %WS_BORDER
Dialog Show Modal hDlg Call DlgProc
End Function

CallBack Function DlgProc() As Long
Local pt As POINTAPI, x,y As Long
Static ddx,ddy,ChildID,ChildID2 As Long
Select Case CBMSG

Case %WM_INITDIALOG
' -- Put code to be executed after dialog creation here
Canvas_Attach(CBHNDL, %CanvasA, %FALSE)
Canvas_Attach(CBHNDL, %CanvasB, %FALSE)
Canvas_Scale Pixels

Case %WM_MOUSEMOVE
If (CBWPARAM And %MK_LBUTTON) And ChildID Then
'Control Get Loc CBHNDL, %CanvasA To ddx, ddy
Control Set Loc hDlg, ChildID, LO(Word,CBLPARAM)+ddx, HI(Word,CBLPARAM)+ddy

'Control Get Loc CBHNDL, %CanvasB To ddx, ddy
Control Set Loc hDlg, ChildID2, LO(Word,CBLPARAM)+ddx, HI(Word,CBLPARAM)+ddy
End If
Case %WM_LBUTTONDOWN
pt.x = LO(Word,CBLPARAM) : pt.y = HI(Word,CBLPARAM)
ChildID = GetDlgCtrlID(ChildWindowFromPoint(hDlg, pt.x, pt.y))

Control Get Loc hDlg, ChildID To x,y '
ddx = x - LO(Word, CBLPARAM)
ddy = y - HI(Word, CBLPARAM)

pt.x = LO(Word,CBLPARAM) : pt.y = HI(Word,CBLPARAM)
ChildID2 = GetDlgCtrlID(ChildWindowFromPoint(hDlg, pt.x, pt.y))

Control Get Loc hDlg, ChildID2 To x,y
ddx = x - LO(Word, CBLPARAM)
ddy = y - HI(Word, CBLPARAM)

Case %WM_LBUTTONUP
End Select
End Function


2) also what I've noticed: if I am not using "Function TBMain() As Long... End Function" the example for all UI examples works although I've desacitvated these lines just for a test. What's the background of "tbmain()" ? Something like an entry point for interpreting?

bye, largo

ErosOlmi
14-12-2011, 22:00
Something like that:



Uses "console", "ui"

Begin ControlID
%CanvasA
%CanvasB
End ControlID

Function TBMain() As Long
Local hDlg As DWord

Dialog New Pixels, 0, "my Drag Control Test",50,50,300,300, %WS_OVERLAPPEDWINDOW To hDlg
Control Add Canvas, hDlg, %CanvasA,"", 50,10,85,85, %WS_VISIBLE Or %WS_BORDER
Control Add Canvas, hDlg, %CanvasB,"", 50,125,85,85, %WS_VISIBLE Or %WS_BORDER
Dialog Show Modal hDlg Call DlgProc


End Function

CallBack Function DlgProc() As Long
Local pt As POINTAPI, x,y As Long
Static ddx,ddy,ChildID As Long
Static lDown As Long


Select Case CBMSG

Case %WM_INITDIALOG
' -- Put code to be executed after dialog creation here
Canvas_Scale Pixels

Case %WM_MOUSEMOVE
If lDown = %TRUE And ChildID <> 0 Then
Control Set Loc CBHNDL, ChildID, LO(Word,CBLPARAM)+ddx, HI(Word,CBLPARAM)+ddy
End If

Case %WM_LBUTTONDOWN
pt.x = LO(Word,CBLPARAM)
pt.y = HI(Word,CBLPARAM)

ChildID = Win_GetDlgCtrlID(Win_ChildWindowFromPoint(CBHNDL, pt))
PrintL pt.x, pt.y, ChildID
If ChildID Then
Control Get Loc CBHNDL, ChildID To x,y '
ddx = x - LO(Word, CBLPARAM)
ddy = y - HI(Word, CBLPARAM)
lDown = %TRUE
End If

Case %WM_LBUTTONUP
ChildID = 0
lDown = %FALSE
End Select


End Function

largo_winch
15-12-2011, 07:27
yes, something like that! thank you eros.


' Empty GUI script created on 12-15-2011 06:19:09 by (ThinAIR)

Uses "console", "ui"

Begin ControlID
%CanvasA
%CanvasB
End ControlID

Function TBMain() As Long
Local hDlg As DWord

Dialog New Pixels, 0, "my Drag Control Test",50,50,300,300, %WS_OVERLAPPEDWINDOW To hDlg
Control Add Canvas, hDlg, %CanvasA,"", 50,10,85,85, %WS_VISIBLE Or %WS_BORDER
Control Add Canvas, hDlg, %CanvasB,"", 50,125,85,85, %WS_VISIBLE Or %WS_BORDER
Dialog Show Modal hDlg Call DlgProc


End Function

CallBack Function DlgProc() As Long
Local pt As POINTAPI, x,y As Long
Static ddx,ddy,ChildID As Long
Static lDown As Long


Select Case CBMSG

Case %WM_INITDIALOG
' -- Put code to be executed after dialog creation here
Canvas_Scale Pixels

Case %WM_MOUSEMOVE
If lDown = %TRUE And ChildID <> 0 Then
Control Set Loc CBHNDL, ChildID, LO(Word,CBLPARAM)+ddx, HI(Word,CBLPARAM)+ddy
End If

Case %WM_LBUTTONDOWN
pt.x = LO(Word,CBLPARAM)
pt.y = HI(Word,CBLPARAM)

ChildID = Win_GetDlgCtrlID(Win_ChildWindowFromPoint(CBHNDL, pt.x, pt.y))
PrintL pt.x, pt.y, ChildID
If ChildID Then
Control Get Loc CBHNDL, ChildID To x,y '
ddx = x - LO(Word, CBLPARAM)
ddy = y - HI(Word, CBLPARAM)
lDown = %TRUE
End If

Case %WM_LBUTTONUP
ChildID = 0
lDown = %FALSE
End Select


End Function

didn't know that these functions already exist in thinbasic

a) Win_GetDlgCtrlID
b) Win_ChildWindowFromPoint

correct line should looks like this:

ChildID = Win_GetDlgCtrlID(Win_ChildWindowFromPoint(CBHNDL, pt.x, pt.y))

now example works: pick the control with mouse and "drag" it over dialog frame to another place.

bye, largo

ErosOlmi
15-12-2011, 08:10
didn't know that these functions already exist in thinbasic
a) Win_GetDlgCtrlID
b) Win_ChildWindowFromPoint

There are a lot of Windows API functions wrapped fro programmer convenience. Are all gouped under UI/Windows help athttp://www.thinbasic.com/public/products/thinBasic/help/html/windows.htm
There are also a lot of predefined UDT. When you type the name of an UDT into thinAir and you see its syntax colored like a standard keyword, it usually means it is recognized as native. If you press F1 you should have help about that UDT. In this case POINTAPI (http://www.thinbasic.com/public/products/thinBasic/help/html/pointapi.htm) UDT



correct line should looks like this:

ChildID = Win_GetDlgCtrlID(Win_ChildWindowFromPoint(CBHNDL, pt.x, pt.y))


Yes, in thinBasic 1.8.9.0 syntax of Win_ChildWindowFromPoint is

Win_ChildWindowFromPoint(CBHNDL, pt.x, pt.y)
but only because I made a mistake in parsing. In reality I wrote help in the correct way: http://www.thinbasic.com/public/products/thinBasic/help/html/win_childwindowfrompoint.htm

Thanks to your example I've discovered it and in next thinBasic version Win_ChildWindowFromPoint syntax will be:

Win_ChildWindowFromPoint(CBHNDL, pt)
like in Windows API:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632676(v=vs.85).aspx

Ciao
Eros