How to create a tool window

Share your advanced PureBasic knowledge/code with the community.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

How to create a tool window

Post by Mistrel »

If anyone has ever wondered how to create a tool window (small title bar) here is an example.

Code: Select all

WndID=OpenWindow(#PB_Any,0,0,320,240,"Tool Window")

; Set the extended window style to tool window
SetWindowLong_(WindowID(WndID),#GWL_EXSTYLE,OldStyle|#WS_EX_TOOLWINDOW)
OldStyle=GetWindowLong_(WindowID(WndID),#GWL_EXSTYLE)

; Update the window frame
SetWindowPos_(WindowID(WndID),0,0,0,0,0,#SWP_NOSIZE|#SWP_NOREPOSITION|#SWP_NOMOVE|#SWP_FRAMECHANGED) 

Repeat: Delay(1)
	WaitWindowEvent()
ForEver
#PB_Window_SizeGadget doesn't appear to work with the tool window style. If you want the window to be resizable use this instead:

Code: Select all

WndID=OpenWindow(#PB_Any,0,0,320,240,"Tool Window")

; Set the extended window style to tool window
SetWindowLong_(WindowID(WndID),#GWL_EXSTYLE,OldStyle|#WS_EX_TOOLWINDOW)
OldStyle=GetWindowLong_(WindowID(WndID),#GWL_EXSTYLE)

; Update the window frame
SetWindowPos_(WindowID(WndID),0,0,0,0,0,#SWP_NOSIZE|#SWP_NOREPOSITION|#SWP_NOMOVE|#SWP_FRAMECHANGED)

; Set the window style to thick frame to be resizable
OldStyle=GetWindowLong_(WindowID(WndID),#GWL_STYLE)
SetWindowLong_(WindowID(WndID),#GWL_STYLE,OldStyle|#WS_THICKFRAME)

Repeat: Delay(1)
	WaitWindowEvent()
ForEver
Last edited by Mistrel on Mon Sep 01, 2008 9:18 pm, edited 1 time in total.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You don't need to set the thickframe style Mistrel because you have the two lines :

Code: Select all

OldStyle=GetWindowLong_(WindowID(WndID),#GWL_EXSTYLE) 
SetWindowLong_(WindowID(WndID),#GWL_EXSTYLE,OldStyle|#WS_EX_TOOLWINDOW) 
the wrong way around in your code! :wink:
I may look like a mule, but I'm not a complete ass.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

You're right! I must have forgotten to remove it after testing. :)

A slight update here. The window frame should be updated after setting the #WS_THICKFRAME style not before.

Code: Select all

WndID=OpenWindow(#PB_Any,0,0,320,240,"Tool Window")

; Set the extended window style to tool window
SetWindowLong_(WindowID(WndID),#GWL_EXSTYLE,OldStyle|#WS_EX_TOOLWINDOW)
OldStyle=GetWindowLong_(WindowID(WndID),#GWL_EXSTYLE)

; Set the window style to thick frame to be resizable
OldStyle=GetWindowLong_(WindowID(WndID),#GWL_STYLE)
SetWindowLong_(WindowID(WndID),#GWL_STYLE,OldStyle|#WS_THICKFRAME)

; Update the window frame
SetWindowPos_(WindowID(WndID),0,0,0,0,0,#SWP_NOSIZE|#SWP_NOREPOSITION|#SWP_NOMOVE|#SWP_FRAMECHANGED)

Repeat: Delay(1)
   WaitWindowEvent()
ForEver
Post Reply