Any chance to make a borderless window sizeable?

Everything else that doesn't fall into one of the other PB categories.
es_91
Enthusiast
Enthusiast
Posts: 298
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Any chance to make a borderless window sizeable?

Post by es_91 »

Hi

#PB_Window_BorderLess disables any #PB_Window_SizeGadget functionalities... so to say.

It's not implemented to have a frame-less window do any resizing, except the maximizing and restoring.

I want to create an owner-drawn windows frame but i do not know how to code a proper resizing job. I'd need to (1) change the mouse cursor and (2) resize and redraw the window content every mouse movement made. How to change the cursor?

Any help or even a workaround for this? Just wanted to toy with some owner-made frames.
:mrgreen:
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Any chance to make a borderless window sizeable?

Post by Michael Vogel »

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)

OpenWindow(0,0,0,320,240,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
ButtonGadget(0, WindowWidth(0)/2-30, WindowHeight(0)-40, 60, 20, "Close")

quit = 0
Repeat
	ev = WaitWindowEvent()
	Select ev

	Case #PB_Event_Gadget
		quit = 1

	Case #WM_SIZE
		ResizeGadget(0, 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 < 20
				sizing = 7
				SetCursor_(sizeall)
			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_(sizeall)
			SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTCAPTION , #Null)
		EndSelect
	EndSelect

Until quit
es_91
Enthusiast
Enthusiast
Posts: 298
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Re: Any chance to make a borderless window sizeable?

Post by es_91 »

This is a very beautiful code! Have so many thanks for that, Herr Vogel !!!! :mrgreen:
:mrgreen:
Axolotl
Addict
Addict
Posts: 802
Joined: Wed Dec 31, 2008 3:36 pm

Re: Any chance to make a borderless window sizeable?

Post by Axolotl »

yes.

Code: Select all


;/---
;| Change sizability of a window 
;| 
;| don't need the Flag #PB_Window_SizeGadget on OpenWindow() 
;| 
;\-

Procedure SizableWindow(Window, State)    ; State = #False or #True  .. 
  Protected hwnd 

  hwnd = WindowID(Window) 
  If State    ; == TRUE ------------------------------------------> add control 
    SetWindowLongPtr_(hwnd, #GWL_STYLE, GetWindowLongPtr_(hwnd, #GWL_STYLE) | #WS_THICKFRAME)     :Debug "Sizable = ON " 
  Else    ; == FALSE ---------------------------------------------> remove control 
    SetWindowLongPtr_(hwnd, #GWL_STYLE, GetWindowLongPtr_(hwnd, #GWL_STYLE) & ~#WS_THICKFRAME)    :Debug "Sizable = OFF "  
  EndIf 
  SetWindowPos_(hWnd, 0, 0, 0, 0, 0, #SWP_NOZORDER | #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)  
EndProcedure 


If OpenWindow(0, 0, 0, 240, 120, "Sizable ... ", #PB_Window_ScreenCentered | #PB_Window_BorderLess) 
  StickyWindow(0, 1)  ; don't hide the window behind the IDE :)  

  ButtonGadget(1,  2, 4, 72, 20, "Quit")  
  ButtonGadget(2, 80, 4, 72, 20, "Sizeable", #PB_Button_Toggle) 

  Repeat 
    Select WaitWindowEvent() 
      Case #PB_Event_CloseWindow  ; ALT+F4 works 
        Break 
      Case #PB_Event_Gadget 
        Select EventGadget() 
          Case 1 ; button Quit 
            Break 
          Case 2 ; button Sizeable 
            SizableWindow(0, GetGadgetState(2))  ; <--- 
        EndSelect
    EndSelect 
  ForEver 
EndIf 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Axolotl
Addict
Addict
Posts: 802
Joined: Wed Dec 31, 2008 3:36 pm

Re: Any chance to make a borderless window sizeable?

Post by Axolotl »

And of course you can also do this directly.....

Code: Select all

OpenWindow(0, 0, 0, 240, 120, "Sizable ... ", #PB_Window_ScreenCentered | #PB_Window_BorderLess | #WS_THICKFRAME) 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Post Reply