I have a simple form with a string gadget on it.
I can move and resize the gadget through code no probs.
But how do I do this using the mouse on a live form??
Is this even possible ??
Thanks for any pointers.
Captain_S


Code: Select all
If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
hWnd = ButtonGadget(0, 10, 10, 200, 40, "Standard Button")
SetWindowLongPtr_(hWnd, #GWL_STYLE, GetWindowLongPtr_(hWnd, #GWL_STYLE)|#WS_SIZEBOX)
Repeat
eventID = WaitWindowEvent()
Select eventID
Case #WM_LBUTTONDOWN
If WindowFromPoint_(DesktopMouseX() + DesktopMouseY() <<32) = hWnd
ReleaseCapture_()
SendMessage_(hWnd, #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
EndIf
EndSelect
Until eventID = #PB_Event_CloseWindow
EndIf

Code: Select all
Structure SubClassGadget
hWnd.l
oldWndProc.l
mouseDown.l
mouseOffX.l
mouseOffY.l
EndStructure
Global NewList gadgets.SubClassGadget()
;//////////////////////////////////////////////
Procedure GadgetCallback(hWnd,Msg,wParam,lParam)
Select Msg
Case #WM_LBUTTONDOWN
ForEach gadgets()
If gadgets()\hWnd = hWnd
gadgets()\mouseOffX = lParam & $FFFF
gadgets()\mouseOffY = (lParam>>16) & $FFFF
gadgets()\mouseDown = 1
SetFocus_(hWnd)
SetCursor_(LoadCursor_(0,#IDC_SIZEALL))
ProcedureReturn 0
EndIf
Next
Case #WM_MOUSEMOVE
If wParam & #MK_LBUTTON
ForEach gadgets()
If gadgets()\hWnd = hWnd And gadgets()\mouseDown
GetCursorPos_(p.POINT)
MapWindowPoints_(0,WindowID(0),@p,1)
x = p\x - gadgets()\mouseOffX
y = p\y - gadgets()\mouseOffY
If x < 0 : x = 0 : EndIf
If y < 0 : y = 0 : EndIf
GetClientRect_(hWnd,rect.RECT)
GetClientRect_(WindowID(0),rect2.RECT)
If x > rect2\right - rect\right : x = rect2\right - rect\right : EndIf
If y > rect2\bottom - rect\bottom : y = rect2\bottom - rect\bottom : EndIf
ResizeGadget(GetWindowLong_(hWnd,#GWL_ID),x,y,#PB_Ignore,#PB_Ignore)
SetCursor_(LoadCursor_(0,#IDC_SIZEALL))
SetCapture_(hWnd)
ProcedureReturn 0
EndIf
Next
ElseIf wParam = 0
SetCursor_(LoadCursor_(0,#IDC_SIZEALL))
EndIf
Case #WM_LBUTTONUP
ForEach gadgets()
If gadgets()\hWnd = hWnd
gadgets()\mouseDown = 0
EndIf
Next
SetCursor_(LoadCursor_(0,#IDC_SIZEALL))
SetCapture_(0)
ProcedureReturn 0
EndSelect
ForEach gadgets()
If gadgets()\hWnd = hWnd
ProcedureReturn CallWindowProc_(gadgets()\oldWndProc,hWnd,Msg,wParam,lParam)
EndIf
Next
EndProcedure
;//////////////////////////////////////////////
Procedure AddGadget(hGadget)
If IsGadget(hGadget)
hWnd = GadgetID(hGadget) ; for #PB_Any
Else
hWnd = hGadget
EndIf
If hWnd
LastElement(gadgets())
AddElement(gadgets())
gadgets()\hWnd = hWnd
gadgets()\oldWndProc = SetWindowLong_(hWnd,#GWL_WNDPROC,@GadgetCallback())
EndIf
ProcedureReturn hGadget
EndProcedure
;//////////////////////////////////////////////
If OpenWindow(0,0,0,400,300,"WinDesigner",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
AddGadget(ButtonGadget (#PB_Any,10, 10,100,20,"Button"))
AddGadget(CheckBoxGadget(#PB_Any,10, 40,100,20,"Checkbox"))
AddGadget(ComboBoxGadget(#PB_Any,10, 80,100,20))
Addgadget(SpinGadget (#PB_Any,10,120,100,20,0,100))
Addgadget(StringGadget (#PB_Any,10,160,100,20,"Stringfield"))
AddGadget(TrackBarGadget(#PB_Any,10,200,100,20,0,100))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
If EventWindow()=0
If MessageBox_(0,"Do you really want to close this app?","WinDesigner - Close",#MB_YESNO|#MB_ICONQUESTION|#MB_DEFBUTTON2|#MB_TASKMODAL)=#IDYES
Break
EndIf
EndIf
EndSelect
ForEver
EndIf

Code: Select all
OpenWindow(0,146,267,751,349,"test")
B=ButtonGadget(#PB_Any,79,106,99,27,"test")
Debug GadgetX(B)
Debug GadgetY(B)
Debug GadgetWidth(B)
Debug GadgetHeight(B)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindowIf you're talking about allowing the user to move/size gadgets by dragging the cursor etc. like some kind of designer then, when thinking about cross-platform code without recourse to the various API's... tricky, especially when you throw container gadgets and the like into the mix.USCode wrote:Is it possible to do this in a cross-platform way?