It is currently Mon Dec 11, 2017 5:11 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Move form by dragging imagegadget
PostPosted: Mon Nov 20, 2017 5:36 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4138
Location: Not Sydney!!!
I want to move a borderless form window by clicking on and holding down the mouse on a imagegadget.

Does anyone know how to do this? (I don't know what I am looking for.

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
 Post subject: Re: Move form by dragging imagegadget
PostPosted: Mon Nov 20, 2017 6:23 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1032
Based on someone else's code:

Code:
If OpenWindow(1,150,150,300,100,"",#PB_Window_BorderLess)
  CreateImage(1,100,50,24,#Red)
  ImageGadget(1,10,10,100,50,ImageID(1))
  Repeat
    event=WaitWindowEvent()
    If GetAsyncKeyState_(#VK_LBUTTON)<>0
      GetCursorPos_(@cursor_pos.POINT)
      ScreenToClient_(WindowID(1),@cursor_pos)
      hChild=RealChildWindowFromPoint_(WindowID(1),PeekQ(cursor_pos))
      If hChild=GadgetID(1)
        ReleaseCapture_()
        SendMessage_(WindowID(1),#WM_NCLBUTTONDOWN,#HTCAPTION,0)
      EndIf
    EndIf
  Until event=#PB_Event_CloseWindow
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: Move form by dragging imagegadget
PostPosted: Mon Nov 20, 2017 6:33 am 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 2853
Hi Fang
Cross platform
Code:
If OpenWindow(0, 0, 0, 400, 400, "Moving Borderless Window", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
  SetWindowColor(0,$B9B9B9)
  CanvasGadget(0,10,10,380,40)
  CanvasGadget(1,10,350,40,40)
   
  StartDrawing(CanvasOutput(0))
    Box(0,0,OutputWidth(),OutputHeight(),$0F)
    Box(2,2,OutputWidth()-4,OutputHeight()-4,$B3FEA8)
  StopDrawing()
 
  StartDrawing(CanvasOutput(1))
    Box(0,0,OutputWidth(),OutputHeight(),$0F)
    Box(2,2,OutputWidth()-4,OutputHeight()-4,$111FFF)
    DrawingMode(#PB_2DDrawing_Transparent )
    DrawText(15,12,"X",$FFFFFF)
  StopDrawing()
   
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Select EventType()
            Case #PB_EventType_LeftButtonDown
              If run = 0
                run = 1
                ox = WindowMouseX(0)
                oy = WindowMouseY(0)
              EndIf
             
            Case #PB_EventType_LeftButtonUp
              run = 0
             
            Case #PB_EventType_MouseMove
              If GetGadgetAttribute(0,#PB_Canvas_Buttons ) =  #PB_Canvas_LeftButton
                ResizeWindow(0,DesktopMouseX()-ox,DesktopMouseY()-oy,#PB_Ignore,#PB_Ignore)
              EndIf
          EndSelect
         
        Case 1
          Select EventType()
            Case #PB_EventType_LeftButtonDown
              End
          EndSelect           
      EndSelect
  EndSelect
ForEver
EndIf

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Move form by dragging imagegadget
PostPosted: Mon Nov 20, 2017 8:59 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4138
Location: Not Sydney!!!
Thanks Dude and RASHAD. I now have something to do before my minority intellect ossifies:):)

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
 Post subject: Re: Move form by dragging imagegadget
PostPosted: Mon Nov 20, 2017 9:09 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4138
Location: Not Sydney!!!
RASHAD wrote:
Hi Fang
Cross platform
Code:
If OpenWindow(0, 0, 0, 400, 400, "Moving Borderless Window", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
  SetWindowColor(0,$B9B9B9)
  CanvasGadget(0,10,10,380,40)
  CanvasGadget(1,10,350,40,40)
   
  StartDrawing(CanvasOutput(0))
    Box(0,0,OutputWidth(),OutputHeight(),$0F)
    Box(2,2,OutputWidth()-4,OutputHeight()-4,$B3FEA8)
  StopDrawing()
 
  StartDrawing(CanvasOutput(1))
    Box(0,0,OutputWidth(),OutputHeight(),$0F)
    Box(2,2,OutputWidth()-4,OutputHeight()-4,$111FFF)
    DrawingMode(#PB_2DDrawing_Transparent )
    DrawText(15,12,"X",$FFFFFF)
  StopDrawing()
   
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Select EventType()
            Case #PB_EventType_LeftButtonDown
              If run = 0
                run = 1
                ox = WindowMouseX(0)
                oy = WindowMouseY(0)
              EndIf
             
            Case #PB_EventType_LeftButtonUp
              run = 0
             
            Case #PB_EventType_MouseMove
              If GetGadgetAttribute(0,#PB_Canvas_Buttons ) =  #PB_Canvas_LeftButton
                ResizeWindow(0,DesktopMouseX()-ox,DesktopMouseY()-oy,#PB_Ignore,#PB_Ignore)
              EndIf
          EndSelect
         
        Case 1
          Select EventType()
            Case #PB_EventType_LeftButtonDown
              End
          EndSelect           
      EndSelect
  EndSelect
ForEver
EndIf


RASHAD, can this be done with an imagegadget instead? (No canvas involved)

I tried to add your code to my form and it didn't work predictably. I thought I did it right:)

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
 Post subject: Re: Move form by dragging imagegadget
PostPosted: Mon Nov 20, 2017 11:43 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4138
Location: Not Sydney!!!
Dude wrote:
Based on someone else's code:

Code:
If OpenWindow(1,150,150,300,100,"",#PB_Window_BorderLess)
  CreateImage(1,100,50,24,#Red)
  ImageGadget(1,10,10,100,50,ImageID(1))
  Repeat
    event=WaitWindowEvent()
    If GetAsyncKeyState_(#VK_LBUTTON)<>0
      GetCursorPos_(@cursor_pos.POINT)
      ScreenToClient_(WindowID(1),@cursor_pos)
      hChild=RealChildWindowFromPoint_(WindowID(1),PeekQ(cursor_pos))
      If hChild=GadgetID(1)
        ReleaseCapture_()
        SendMessage_(WindowID(1),#WM_NCLBUTTONDOWN,#HTCAPTION,0)
      EndIf
    EndIf


This one works with my code, thanks.

Until event=#PB_Event_CloseWindow
EndIf
[/code]

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
 Post subject: Re: Move form by dragging imagegadget
PostPosted: Mon Nov 20, 2017 12:27 pm 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 2853
As per your request
Code:
LoadImage(0, #PB_Compiler_Home + "examples/Sources/Data/PureBasicLogo.bmp")

If OpenWindow(0, 0, 0, 400, 400, "Moving Borderless Window", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
  SetWindowColor(0,$B9B9B9)
  ImageGadget(0,10,10,380,40,ImageID(0))
  DisableGadget(0,1)
  CreateImage(1,40,40,24,$0000FF)
  StartDrawing(ImageOutput(1))
    DrawingMode(#PB_2DDrawing_Transparent )
    DrawText(14,12,"X",$FFFFFF)
  StopDrawing()
  ImageGadget(1,10,350,40,40,ImageID(1))
Repeat
  Select WaitWindowEvent()
    Case #WM_LBUTTONDOWN
        If WindowMouseX(0) > 10 And WindowMouseX(0) < GadgetWidth(0) And WindowMouseY(0) > 10 And WindowMouseY(0) < (GadgetHeight(0)+10)
          SendMessage_(WindowID(0),#WM_NCLBUTTONDOWN,#HTCAPTION,0)
        EndIf
       
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          End
      EndSelect
  EndSelect
ForEver
EndIf

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Move form by dragging imagegadget
PostPosted: Mon Nov 20, 2017 8:35 pm 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4138
Location: Not Sydney!!!
Thank you master RASHAD. It was 35 degrees yesterday and my brains are currently mushy goo.

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye