Page 1 of 1

moving element inside window with mose ?

Posted: Thu Jun 22, 2006 2:31 pm
by z3phir2003
hi

is posible to move a element inside a window with the mouse and save the position ?
example :
i open a window and i add a image , some text and a ListIconGadget i need to be able to move the image,text and listicongadget with the mouse and save the new position so the next time the software runs it remembers the position of the elements. like the visual designer works.

a example would be great.

10x in advance

Posted: Thu Jun 22, 2006 6:07 pm
by srod
The following might get you started. It uses the #WM_NCLBUTTONDOWN message. As such, some gadgets need to be embedded within container gadgets for this to work.

It's not brilliant as you will see when overlapping gadgets etc.

As for saving the positions etc. You could use a preference file. Simply save the positions at program end and load at program beginning etc.

Code: Select all

Procedure.l MouseOverGadget()
      GetCursorPos_(@cursor_pos.POINT) 
      ScreenToClient_(WindowID(0),@cursor_pos) 
      hChild = ChildWindowFromPoint_(WindowID(0), cursor_pos\x,cursor_pos\y) 
      ProcedureReturn GetDlgCtrlID_(hChild) 
EndProcedure 

If OpenWindow(0,0,0,640,300,"",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_Invisible|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  ShowWindow_(WindowID(0), #SW_MAXIMIZE)

  ContainerGadget(1,20,50,40,15,#PB_Container_BorderLess)
    TextGadget(10, 0,0,40, 15, "Text 1")
  CloseGadgetList()
    StringGadget(11, 20,100,80, 15, "String gadget")
  ContainerGadget(3,20,150,40,15,#PB_Container_BorderLess)
    TextGadget(12, 0,0,40, 15, "Text 2")
  CloseGadgetList()
  ContainerGadget(4,20,200,40,15,#PB_Container_BorderLess)
    TextGadget(13, 0,0,40, 15, "Text 3")
  CloseGadgetList()
  ContainerGadget(5,20,250,40,15,#PB_Container_BorderLess)
    TextGadget(14, 0,0,40, 15, "Text 4")
  CloseGadgetList()

Repeat
  EventID = WaitWindowEvent()
  
  Select EventID
  
    Case #WM_LBUTTONDOWN
      gad = MouseOverGadget()
      If gad > 0
        ReleaseCapture_() 
        RedrawWindow_(GadgetID(gad), 0, 0, #RDW_FRAME|#RDW_INVALIDATE|#RDW_ERASE|#RDW_UPDATENOW)
        SendMessage_(GadgetID(gad), #WM_NCLBUTTONDOWN, #HTCAPTION, NULL) 
        RedrawWindow_(WindowID(0), 0, 0, #RDW_FRAME|#RDW_INVALIDATE|#RDW_ERASE|#RDW_ALLCHILDREN	|#RDW_UPDATENOW)
      EndIf 
    
  EndSelect

Until EventID = #PB_Event_CloseWindow

EndIf

10x a lot

Posted: Thu Jun 22, 2006 11:32 pm
by z3phir2003
10x a lot that is what i wanted :) i think i will resolve the saving part on my own if anyone has any other examples feal free to post