Window with no titlebar but resizable

Just starting out? Need help? Post your questions and find answers here.
USCode
Addict
Addict
Posts: 924
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Window with no titlebar but resizable

Post by USCode »

Is it possible with PB-only commands (cross-platform, no API) to create a window that is resizable and that has NO titlebar?
Just a window with the resize border around it? I'm probably staring right at it in the doc but no matter what I try I can't find a combination that works ... ?
Last edited by USCode on Fri May 25, 2012 4:34 am, edited 4 times in total.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Window with no titlebar but resizable

Post by IdeasVacuum »

You would imagine that if the #PB_Window_TitleBar flag was not used, the Window would not have a title bar, but it does unless you specify #PB_Window_BorderLess. Of course, you might want a border, just not a title bar :?

So then, if you add the #PB_Window_SizeGadget flag - that puts a title bar on as well. :shock:

These seem to be the limits of what PB can currently offer, perhaps because the API's of the different OS's are so, erm, different.

Perhaps one answer could be a DIY window, using a Canvas gadget?

The other would be to use the API's of each platform of course. Pita.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: Window with no titlebar but resizable

Post by Foz »

Afraid not.

Here's something cobbled together using the Windows API though. Not great or wonderful, but perhaps someone here can run with it...

Code: Select all

sizewe   = LoadCursor_(0, #IDC_SIZEWE) 
sizeall  = LoadCursor_(0, #IDC_SIZEALL) 
sizenwse = LoadCursor_(0, #IDC_SIZENWSE) 
sizenesw = LoadCursor_(0, #IDC_SIZENESW) 
sizens   = LoadCursor_(0, #IDC_SIZENS) 
arrow    = LoadCursor_(0, #IDC_ARROW) 

hWnd = OpenWindow(0,0,0,640,480,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
SetWindowColor(0,$000000)
If OSVersion() >= #PB_OS_Windows_Vista
  SetWindowLongPtr_(WindowID(0), #GWL_STYLE, GetWindowLongPtr_(WindowID(0), #GWL_STYLE)|#WS_THICKFRAME)
  WindowBounds(0, 640, 480, 640, 480)
Else
  dc=GetDC_(WindowID(0))
  SelectObject_(dc,CreatePen_(#PS_SOLID, 12 ,GetSysColor_(#COLOR_ACTIVECAPTION)))  
  BeginPath_(dc) 
  Rectangle_(dc,0,0,640,480)
  ;RoundRect_(dc,0,0,640,480,10,10)              ;Round Rect
  EndPath_(dc)
EndIf

TextGadget(1,WindowWidth(0)/2-120, 20, 240, 40,"Hi Everyone!",#SS_CENTERIMAGE | #SS_CENTER| #WS_BORDER)
LoadFont(1, "BroadWay", 16)
SetGadgetFont(1, FontID(1))
SetGadgetColor(1, #PB_Gadget_FrontColor, $0102FE)
SetGadgetColor(1, #PB_Gadget_BackColor, $B5FFFE)

ButtonGadget(2, WindowWidth(0)/2-30, WindowHeight(0)-40, 60, 20, "Close") 

quit = 0 
Repeat 
  StrokePath_(dc)
  
  ev = WaitWindowEvent() 
  Select ev 
      
    Case #PB_Event_Gadget 
      quit = 1 
      
    Case #WM_SIZE 
      If OSVersion() < #PB_OS_Windows_Vista
        r.RECT
        r\left = 6
        r\top = 6
        r\right = WindowWidth(0) - 6
        r\bottom = WindowHeight(0) - 6
        
        InvalidateRect_(WindowID(0), r, #True)
        dc=GetDC_(WindowID(0))
        SelectObject_(dc,CreatePen_(#PS_SOLID,12,GetSysColor_(#COLOR_ACTIVECAPTION)))  
        BeginPath_(dc) 
        Rectangle_(dc,0,0,WindowWidth(0),WindowHeight(0))
        EndPath_(dc)
      EndIf
      
      ResizeGadget(1, WindowWidth(0)/2-120, 20, #PB_Ignore, #PB_Ignore) 
      ResizeGadget(2, WindowWidth(0)/2-30, WindowHeight(0)-40, #PB_Ignore, #PB_Ignore) 
      
      
    Case #WM_MOUSEMOVE 
      x = WindowMouseX(0) 
      y = WindowMouseY(0) 
      
      If GetAsyncKeyState_(#VK_LBUTTON) & 32768 = 0
        If y >  0 And y < 6 
          sizing = 7 
          SetCursor_(sizens) 
        Else 
          sizing = 0 
        EndIf 
        
        If Not sizing 
          If WindowWidth(0)-x <= 6 
            If WindowHeight(0)-y <= 6 ; nwse 
              SetCursor_(sizenwse) 
              sizing = 3 
            Else ; we 
              SetCursor_(sizewe) 
              sizing = 2 
            EndIf 
          Else 
            sizing = 0 
          EndIf 
        EndIf 
        
        If Not sizing 
          If x <= 6 
            If WindowHeight(0)-y <= 6 
              SetCursor_(sizenesw) 
              sizing = 5 
            Else ; we 
              SetCursor_(sizewe) 
              sizing = 6 
            EndIf 
          Else 
            sizing = 0 
          EndIf      
        EndIf 
        
        If Not sizing 
          If WindowHeight(0)-y <= 6 
            If WindowWidth(0)-x <= 6 ; nwse 
              SetCursor_(sizenwse) 
              sizing = 3 
            ElseIf x <= 6 
              SetCursor_(sizenesw) 
              sizing = 5 
            Else ; ns 
              SetCursor_(sizens) 
              sizing = 4 
            EndIf 
          Else 
            sizing = 0 
          EndIf 
        EndIf 
        
      EndIf
      
      If x < 0 Or y < 0 
        sizing = 0 
        SetCursor_(arrow) 
        SendMessage_(WindowID(0), #WM_LBUTTONUP, 0,0) 
      EndIf 
      
    Case #WM_LBUTTONDOWN 
      Select sizing 
        Case 2 
          SetCursor_(sizewe) 
          SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTRIGHT , #Null) 
        Case 3 
          SetCursor_(sizenwse) 
          SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTBOTTOMRIGHT , #Null) 
        Case 4 
          SetCursor_(sizens) 
          SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTBOTTOM , #Null) 
        Case 5 
          SetCursor_(sizenesw) 
          SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTBOTTOMLEFT , #Null) 
        Case 6 
          SetCursor_(sizewe) 
          SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTLEFT , #Null) 
        Case 7 
          SetCursor_(sizens) 
          SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTTOP, #Null)        
        Case 8
          SetCursor_(sizeall) 
          SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTCAPTION , #Null)        
      EndSelect 
  EndSelect 
  
Until quit 
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Window with no titlebar but resizable

Post by Danilo »

Foz wrote:Afraid not.

Here's something cobbled together using the Windows API though. Not great or wonderful, but perhaps someone here can run with it...
With WinAPI you could just use the style #WS_SIZEBOX together with #PB_Window_BorderLess

Code: Select all

OpenWindow(1,0,0,800,600,"title",#WS_SIZEBOX|#PB_Window_BorderLess|#PB_Window_ScreenCentered)

ButtonGadget(1,10,10,60,20,"Close") 

Repeat
    Select WaitWindowEvent()
        Case #PB_Event_CloseWindow, #PB_Event_Gadget
            Break
        Case #WM_LBUTTONDOWN
            SendMessage_(WindowID(1), #WM_NCLBUTTONDOWN, #HTCAPTION , #Null)
    EndSelect
ForEver
Maybe '#PB_Window_SizeGadget|#PB_Window_BorderLess' should look like '#WS_SIZEBOX|#PB_Window_BorderLess'
if it is possible on all platforms.
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: Window with no titlebar but resizable

Post by Foz »

Heh, much easier!
BarryG
Addict
Addict
Posts: 4178
Joined: Thu Apr 18, 2019 8:17 am

Re: Window with no titlebar but resizable

Post by BarryG »

Hi, I tried Danilo's code but it leaves a small border around the window. Is there a way to have a resizable window with NO border? So I can (for example) have a video playing with nothing showing but the video itself, and the user can resize it during playback by dragging a corner? But also for non-video windows. I don't want a 3D window or anything fancy like that. Just a standard OpenWindow() call.
Micoute
User
User
Posts: 28
Joined: Sat Jun 22, 2013 4:06 pm
Location: La Mézière FRANCE

Re: Window with no titlebar but resizable

Post by Micoute »

Code: Select all

EnableExplicit

Enumeration
  #Fenetre_principale
  #Canvas
  #Btn_Quitter
EndEnumeration

Global Btn_SourisPresse, DecalageX, DecalageY, Quitter

OpenWindow(#Fenetre_principale, 100, 100, 300, 90, "", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
CanvasGadget(#Canvas, 0, 0, 300, 90, #PB_Canvas_Container)
ButtonGadget(#Btn_Quitter, 50, 30, 200, 30, "Quitter")

Repeat
  Select WaitWindowEvent(1)
     Case #PB_Event_Gadget
       
       Select EventGadget()
          Case #Canvas
            
            Select EventType()  
                 
               Case #PB_EventType_LeftButtonDown
                 Btn_SourisPresse = 1
                 DecalageX = DesktopMouseX() - WindowX(#Fenetre_principale)
                   DecalageY = DesktopMouseY() - WindowY(#Fenetre_principale)
                 
               Case #PB_EventType_MouseMove
                 If Btn_SourisPresse
                    ResizeWindow(#Fenetre_principale, 
                          DesktopMouseX() - DecalageX, 
                          DesktopMouseY() - DecalageY,
                          #PB_Ignore, #PB_Ignore)
                 EndIf
                 
               Case #PB_EventType_LeftButtonUp
                 Btn_SourisPresse = 0
                 
            EndSelect
            
          Case #Btn_Quitter
            Quitter = 1 
            
       EndSelect  
  EndSelect
Until Quitter = 1
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Window with no titlebar but resizable

Post by RASHAD »

Hi BarryG

Code: Select all

#MONITORINFOF_PRIMARY=1
#MONITOR_DEFAULTTONULL=0
#MONITOR_DEFAULTTOPRIMARY=1
#MONITOR_DEFAULTTONEAREST=2

#SC_Leftsize      = $F001
#SC_Rightsize     = $F002
#SC_Upsize        = $F003
#SC_UpLeftsize    = $F004
#SC_UpRightsize   = $F005
#SC_Dnsize        = $F006
#SC_DnLeftsize    = $F007
#SC_DnRightsize   = $F008
#SC_DragMove      = $F012

; CompilerIf #PB_Compiler_Unicode = 0
;   MessageRequester("Info","Unicode compiler option not set",#MB_ICONINFORMATION)
;   End
; CompilerEndIf

Global  hwnd,r.RECT,hmon,mi.MONITORINFO,x,y,w,h,snap
mi\cbSize=SizeOf(mi)

Procedure sizeCB()
  ResizeGadget(0,10,WindowHeight(0)-36,60,24)
EndProcedure

hwnd=OpenWindow(0,0,0,800,600,"PB_Player",#PB_Window_BorderLess |  #PB_Window_Invisible)
;SetWindowColor(0,$838383)

ButtonGadget(0,10,564,60,24,"Quit")
HideWindow(0,0,#PB_Window_ScreenCentered)
BindEvent(#PB_Event_SizeWindow,@sizeCB())
SmartWindowRefresh(0,1)

snap = 50
sw = 10
sww = 2*sw
Repeat
  Select WaitWindowEvent(1)         
    Case #PB_Event_MoveWindow
        If IsWindow(0)
          GetWindowRect_(hWnd,r)
          w = r\right - r\left
          h = r\bottom - r\top
        EndIf  
        hmon = MonitorFromWindow_(hWnd,#MONITOR_DEFAULTTONEAREST)
        GetMonitorInfo_(hmon,mi)
        If mi\rcWork\left + snap > r\left : r\left = mi\rcWork\left - 2: EndIf
        If r\left + w >= (mi\rcWork\right - snap): r\left = mi\rcWork\right - w + 2: EndIf
        If mi\rcWork\top + snap > r\top : r\top = mi\rcWork\top - 2 : EndIf
        If r\top + h >= (mi\rcWork\bottom - snap): r\top = mi\rcWork\bottom - h + 2 : EndIf
        MoveWindow_(hWnd,r\left,r\top,w,h,1)
    
    Case #WM_MOUSEMOVE;,#WM_NCMOUSEMOVE
        GetWindowRect_(hWnd,r.RECT)
        mx = DesktopMouseX()
        my = DesktopMouseY()
        Flag = 0
        If mx > r\left+sww And mx < r\right-sww And my > r\top-sw And my < r\top+sw
          SetCursor_(LoadCursor_(0, #IDC_SIZENS))
          Flag = 1
        ElseIf mx > r\left+sww And mx < r\right-sww And my > r\bottom-sw And my < r\bottom+sw
          SetCursor_(LoadCursor_(0, #IDC_SIZENS))
          Flag = 2
        ElseIf mx > r\left-sw And mx < r\left+sw And my > r\top+sww And my < r\bottom-sww
          SetCursor_(LoadCursor_(0, #IDC_SIZEWE))
          Flag = 3
        ElseIf mx > r\right-sw And mx < r\right+sw And my > r\top+sww And my < r\bottom-sww
          SetCursor_(LoadCursor_(0, #IDC_SIZEWE))
          Flag = 4
        ElseIf mx > r\left-sw And mx < r\left+sw And my > r\top-sw And my < r\top+sw
          SetCursor_(LoadCursor_(0, #IDC_SIZENWSE))
          Flag = 5
        ElseIf mx > r\right-sw And mx < r\right+sw And my > r\bottom-sw And my < r\bottom+sww
          SetCursor_(LoadCursor_(0, #IDC_SIZENWSE))
          Flag = 6
        ElseIf mx > r\right-sw And mx < r\right+sw And my > r\top-sw And my < r\top+sw
          SetCursor_(LoadCursor_(0, #IDC_SIZENESW))
          Flag = 7
        ElseIf mx > r\left-sw And mx < r\left+sw And my > r\bottom-sw And my < r\bottom+sww
          SetCursor_(LoadCursor_(0, #IDC_SIZENESW))
          Flag = 8
        EndIf
       
    Case #WM_LBUTTONDOWN
        If Flag > 0
          ReleaseCapture_()
        EndIf
        If Flag = 0
          SetCursor_(LoadCursor_(0, #IDC_HAND))
          SendMessage_(hWnd, #WM_SYSCOMMAND , #SC_DragMove,0)
        ElseIf Flag = 1
          SetCursor_(LoadCursor_(0, #IDC_SIZENS))
          SendMessage_(hWnd, #WM_SYSCOMMAND , #SC_Upsize,0)        
        ElseIf Flag = 2
          SetCursor_(LoadCursor_(0, #IDC_SIZENS))
          SendMessage_(hWnd, #WM_SYSCOMMAND , #SC_Dnsize,0)  
        ElseIf Flag = 3
          SetCursor_(LoadCursor_(0, #IDC_SIZEWE))
          SendMessage_(hWnd, #WM_SYSCOMMAND , #SC_Leftsize,0) 
        ElseIf Flag = 4
          SetCursor_(LoadCursor_(0, #IDC_SIZEWE))
          SendMessage_(hWnd, #WM_SYSCOMMAND , #SC_Rightsize,0) 
        ElseIf Flag = 5
          SetCursor_(LoadCursor_(0, #IDC_SIZENWSE))
          SendMessage_(hWnd, #WM_SYSCOMMAND , #SC_UpLeftsize,0) 
        ElseIf Flag = 6
          SetCursor_(LoadCursor_(0, #IDC_SIZENWSE))
          SendMessage_(hWnd, #WM_SYSCOMMAND , #SC_DnRightsize,0) 
        ElseIf Flag = 7
          SetCursor_(LoadCursor_(0, #IDC_SIZENESW))
          SendMessage_(hWnd, #WM_SYSCOMMAND , #SC_UpRightsize,0) 
        ElseIf Flag = 8
          SetCursor_(LoadCursor_(0, #IDC_SIZENESW))
          SendMessage_(hWnd, #WM_SYSCOMMAND , #SC_DnLeftsize,0)  
        EndIf
      
    Case #WM_LBUTTONUP
        Flag = 0
        ReleaseCapture_()
        SendMessage_(hWnd, #WM_SYSCOMMAND, 0, 0)
        
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Quit = 1
      EndSelect

EndSelect        
      
Until Quit = 1
Egypt my love
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

Re: Window with no titlebar but resizable

Post by chi »

Take a look at Borderless window with native shadow (Vista+) if you want shadow, fullscreen and AeroSnap too...
Et cetera is my worst enemy
BarryG
Addict
Addict
Posts: 4178
Joined: Thu Apr 18, 2019 8:17 am

Re: Window with no titlebar but resizable

Post by BarryG »

Thanks Rashad. A bit more code than I expected, but it works great.

Chi, thanks for your link and I replied in the link about a problem.
Post Reply