Page 1 of 1

Borderless Window - Drag, Minimize, Close and TitleBar

Posted: Mon Aug 16, 2004 9:52 pm
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

Posted: Fri Apr 29, 2005 1:39 am
by J. Baker
No longer seems to work in the latest PB and I'm not sure why?

Posted: Fri Apr 29, 2005 2:43 am
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)

Posted: Fri Apr 29, 2005 3:33 am
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?

Posted: Fri Apr 29, 2005 4:24 am
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)

Posted: Fri Apr 29, 2005 9:41 am
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") 

Posted: Fri Apr 29, 2005 3:21 pm
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.

Posted: Fri Apr 29, 2005 3:41 pm
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

Posted: Fri Apr 29, 2005 4:19 pm
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)

Posted: Sat Apr 30, 2005 2:52 pm
by NoahPhense
Very nice code..

- np

Posted: Mon Jun 20, 2005 6:34 am
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

Posted: Mon Jun 20, 2005 4:11 pm
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

Posted: Mon Jun 20, 2005 5:16 pm
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...