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
' 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