Borderless Window - Drag, Minimize, Close and TitleBar

Share your advanced PureBasic knowledge/code with the community.
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Borderless Window - Drag, Minimize, Close and TitleBar

Post by J. Baker »

Code updated For 5.20+

I did not make this, the community did. I just searched the forum and put it all together. Thanks to GreenGiant for helping me on the minimizing. :D

Code: Select all

#Win=0
#Button1=3
#Button2=4

Procedure SetFlat(gadgetnr)
  #BS_FLAT=$8000
  SetWindowLong_(GadgetID(gadgetnr),#GWL_STYLE,GetWindowLong_(GadgetID(gadgetnr),#GWL_STYLE) |#BS_FLAT)
EndProcedure

wnd = OpenWindow(#Win,0,0,400,300,"Borderless",#PB_Window_ScreenCentered | #PB_Window_BorderLess)


CreateImage(1, 398,28)

StartDrawing(ImageOutput(1))
Box(0,0,398,28, RGB(0,0,255))
BackColor(RGB(0,0,255))
FrontColor(RGB(255,255,255))
DrawText(10, 6,"Borderless")
StopDrawing()
ImageGadget(2, 1,1,398,28, ImageID(1))
DisableGadget(2,1)

ButtonGadget(#Button1,340,5,20,20,"_")
ButtonGadget(#Button2,370,5,20,20,"X")

FrameGadget(5, 0, 0, 400, 300, "", #PB_Frame_Flat)


SetFlat(3)
SetFlat(4)

Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget
    GadgetID = EventGadget()
    Select GadgetID
        
      Case #Button1
        ShowWindow_(WindowID(#Win),#SW_MINIMIZE)
        
      Case #Button2
        End
        
    EndSelect
  EndIf
  
  If Event = #WM_LBUTTONDOWN
    SendMessage_(wnd,#WM_NCLBUTTONDOWN, #HTCAPTION,0)
  EndIf
  
Until Event = #PB_Event_CloseWindow
End
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

No longer seems to work in the latest PB and I'm not sure why?
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

The reason for this is that an ImageGadget now generates a Gadget event when
you click on it. (As a result, #WM_LBUTTONDOWN is no longer sent.)

Instead of doing it like this:

Code: Select all

If Event = #WM_LBUTTONDOWN
   SendMessage_(wnd,#WM_NCLBUTTONDOWN, #HTCAPTION,0)
EndIf
you must now catch the gadget event and act there:

Code: Select all

  Case 2
    SendMessage_(wnd,#WM_NCLBUTTONDOWN, #HTCAPTION,0)
(inside the select statement)
quidquid Latine dictum sit altum videtur
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

Thanks freak but this new way kills because now the buttons don't work if there over an image gadget unless something about that needs changed as well?
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Try removing the #SS_NOTIFY from the ImageGadget...

Code: Select all

SetWindowLong_(GadgetID(2), #GWL_STYLE, GetWindowLong_(GadgetID(2), #GWL_STYLE) &~#SS_NOTIFY)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Le Soldat Inconnu
Enthusiast
Enthusiast
Posts: 306
Joined: Wed Jul 09, 2003 11:33 am
Location: France

Post by Le Soldat Inconnu »

to have a systemmenu with minimize available, you could use this :

Code: Select all

wnd = OpenWindow(#Win,0,0,400,300,#PB_Window_ScreenCentered | #PB_Window_BorderLess | #WS_SYSMENU | #WS_MINIMIZEBOX,"Borderless") 
LSI
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

Sparkie wrote:Try removing the #SS_NOTIFY from the ImageGadget...

Code: Select all

SetWindowLong_(GadgetID(2), #GWL_STYLE, GetWindowLong_(GadgetID(2), #GWL_STYLE) &~#SS_NOTIFY)
...
Le Soldat Inconnu wrote:to have a systemmenu with minimize available, you could use this :

Code: Select all

wnd = OpenWindow(#Win,0,0,400,300,#PB_Window_ScreenCentered | #PB_Window_BorderLess | #WS_SYSMENU | #WS_MINIMIZEBOX,"Borderless")
That doesn't help.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

This works fine for me on WinXPhome SP2 / PB 3.93

Code: Select all

#Win=0 
#Button1=3 
#Button2=4 

Procedure SetFlat(gadgetnr) 
  #BS_FLAT=$8000 
  SetWindowLong_(GadgetID(gadgetnr),#gwl_style,GetWindowLong_(GadgetID(gadgetnr),#gwl_style) |#BS_FLAT) 
EndProcedure 

wnd = OpenWindow(#Win,0,0,400,300,#PB_Window_ScreenCentered | #PB_Window_BorderLess,"Borderless") 
If CreateGadgetList(WindowID()) 
  
  CreateImage(1, 398,28) 
  UseImage(1) 
  StartDrawing(ImageOutput()) 
  Box(0,0,398,28, RGB(0,0,255)) 
  BackColor(0,0,255) 
  FrontColor(255,255,255) 
  Locate(10, 6) 
  DrawText("Borderless") 
  StopDrawing() 
  ImageGadget(2, 1,1,398,28, UseImage(1)) 
  
  ButtonGadget(#Button1,340,5,20,20,"_") 
  ButtonGadget(#Button2,370,5,20,20,"X") 
  
  Frame3DGadget(5, 0, 0, 400, 300, "", #PB_Frame3D_Flat) 
  SetWindowLong_(GadgetID(2), #gwl_style, GetWindowLong_(GadgetID(2), #gwl_style) &~#SS_NOTIFY)
EndIf 

SetFlat(3) 
SetFlat(4) 

Repeat 
  event = WaitWindowEvent() 
  If event = #PB_EventGadget 
    GadgetID = EventGadgetID() 
    Select GadgetID 
      
      Case #Button1 
        ShowWindow_(WindowID(),#SW_MINIMIZE) 
        
      Case #Button2 
        End 
        
    EndSelect 
  EndIf 
  
  If event = #WM_LBUTTONDOWN 
    SendMessage_(wnd,#WM_NCLBUTTONDOWN, #HTCAPTION,0) 
  EndIf 
  
Until event = #PB_Event_CloseWindow 
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

Thanks Sparkie! :D

Your comment above confused me as it said to remove and not add the following line.

Code: Select all

SetWindowLong_(GadgetID(2), #GWL_STYLE, GetWindowLong_(GadgetID(2), #GWL_STYLE) &~#SS_NOTIFY)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Very nice code..

- np
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

Now it drags the window by the title bar and not the whole window. :wink:

Code: Select all

#Win=0 
#Button1=3 
#Button2=4 

Procedure SetFlat(gadgetnr) 
  #BS_FLAT=$8000 
  SetWindowLong_(GadgetID(gadgetnr),#gwl_style,GetWindowLong_(GadgetID(gadgetnr),#gwl_style) |#BS_FLAT) 
EndProcedure 

wnd = OpenWindow(#Win,0,0,400,300,#PB_Window_ScreenCentered | #PB_Window_BorderLess,"Borderless") 
If CreateGadgetList(WindowID()) 
  
  CreateImage(1, 398,28) 
  UseImage(1) 
  StartDrawing(ImageOutput()) 
  Box(0,0,398,28, RGB(0,0,255)) 
  BackColor(0,0,255) 
  FrontColor(255,255,255) 
  Locate(10, 6) 
  DrawText("Borderless") 
  StopDrawing() 
  ImageGadget(2, 1,1,398,28, UseImage(1)) 
  
  ButtonGadget(#Button1,340,5,20,20,"_") 
  ButtonGadget(#Button2,370,5,20,20,"X") 
  
  Frame3DGadget(5, 0, 0, 400, 300, "", #PB_Frame3D_Flat) 
  SetWindowLong_(GadgetID(2), #gwl_style, GetWindowLong_(GadgetID(2), #gwl_style) &~#SS_NOTIFY) 
EndIf 

SetFlat(3) 
SetFlat(4) 

Repeat 
  event = WaitWindowEvent() 
  If event = #PB_EventGadget 
    GadgetID = EventGadgetID() 
    Select GadgetID 
      
      Case #Button1 
        ShowWindow_(WindowID(),#SW_MINIMIZE) 
        
      Case #Button2 
        End 
        
    EndSelect 
  EndIf 
  
  For Xmouse = 0 To 400
   For Ymouse = 0 To 28
      If WindowMouseX() = Xmouse And WindowMouseY() = Ymouse And event = #WM_LBUTTONDOWN
         SendMessage_(wnd,#WM_NCLBUTTONDOWN, #HTCAPTION,0)
      EndIf
   Next
  Next 
  
Until event = #PB_Event_CloseWindow 
End
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

More optimized if you don't use For/Next loop to check every pixel :)

Code: Select all

#Win=0
#Button1=3
#Button2=4

If OpenWindow(#Win,0,0,400,300,#PB_Window_ScreenCentered|#PB_Window_BorderLess|#WS_DLGFRAME,"Borderless")
  If CreateGadgetList(WindowID(#Win)) 
    CreateImage(1, 398,28)
    UseImage(1)
    StartDrawing(ImageOutput())
      Box(0,0,398,28, RGB(0,0,255))
      BackColor(0,0,255)
      FrontColor(255,255,255)
      Locate(10, 6)
      DrawText("Borderless")
    StopDrawing()
    ImageGadget(2, 1,1,398,28, UseImage(1))
  
    ButtonGadget(#Button1,350,5,20,20,"_")
    ButtonGadget(#Button2,375,5,20,20,"X")
  
    SetWindowLong_(GadgetID(2), #gwl_style, GetWindowLong_(GadgetID(2), #gwl_style) &~#SS_NOTIFY)
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_EventGadget
          Select EventGadgetID() 
            Case #Button1
              ShowWindow_(WindowID(#Win),#SW_MINIMIZE) 
            Case #Button2
              quit=1 
          EndSelect
    
        Case #WM_LBUTTONDOWN
          If WindowMouseX()<400 And WindowMouseY()<28
            SendMessage_(WindowID(#Win),#WM_NCLBUTTONDOWN, #HTCAPTION,0)
          EndIf
          
      EndSelect 
    Until quit
  EndIf
EndIf
Image Image
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post by va!n »

Here is my small optimized version of Pauls version (this is 2,5k smaller :wink:
In this version even the buttons are directly visible !

Code: Select all

#Win=0
#Button1=3
#Button2=4

If OpenWindow(#Win,0,0,400,300,#PB_Window_ScreenCentered|#PB_Window_BorderLess|#WS_DLGFRAME,"Borderless")
  If CreateGadgetList(WindowID(#Win))

    ButtonGadget(#Button1,350,5,20,20,"_")
    ButtonGadget(#Button2,375,5,20,20,"X")
 
    StartDrawing(WindowOutput())
      Box(0,0,398,28, RGB(0,0,255))
      BackColor(0,0,255)
      FrontColor(255,255,255)
      Locate(10, 6)
      DrawText("Borderless")
    StopDrawing()
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_EventGadget
          Select EventGadgetID()
            Case #Button1
              ShowWindow_(WindowID(#Win),#SW_MINIMIZE)
            Case #Button2
              quit=1
          EndSelect
          
        Case #WM_LBUTTONDOWN
          If WindowMouseX()<400 And WindowMouseY()<28
            SendMessage_(WindowID(#Win),#WM_NCLBUTTONDOWN, #HTCAPTION,0)
          EndIf
          
      EndSelect
    Until quit
  EndIf
EndIf 

Edit:
If you move the window, the blue titlebar will be destroyed! But you can check for #WM_Paint event and draw it new...
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
Post Reply