Page 1 of 1

How to create a tool window

Posted: Fri Aug 29, 2008 7:55 am
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

Posted: Fri Aug 29, 2008 9:37 am
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:

Posted: Mon Sep 01, 2008 9:17 pm
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