Tip: ToolWindow (tiny code version)

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Tip: ToolWindow (tiny code version)

Post by BackupUser »

Code updated For 5.20+

Restored from previous forum. Originally posted by PB.

Opens a window without a button for it in the Taskbar.

Various versions of this have already been posted, but some use ASM,
and some use very long API routines with CreateWindowEx, etc... this
is simple, compact and neat. Thanks to vanleth and Bericko for helping.

Code: Select all

; MENULESS VERSION -- Requires ResizeWindow as a result.
WinW=400 : WinH=200
If OpenWindow(0,200,200,WinW-1,WinH-1,"ToolWindow",#PB_Window_Invisible|#PB_Window_SystemMenu)
  SetWindowLong_(WindowID(0),#GWL_EXSTYLE,#WS_EX_TOOLWINDOW)
  ResizeWindow(0,#PB_Ignore,#PB_Ignore,WinW,WinH) : ShowWindow_(WindowID(0),#SW_SHOW)
  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf

Code: Select all

; MENU VERSION -- Create your menu before showing the window!
If OpenWindow(0,200,200,400,200,"ToolWindow",#PB_Window_Invisible|#PB_Window_SystemMenu)
  SetWindowLong_(WindowID(0),#GWL_EXSTYLE,#WS_EX_TOOLWINDOW)
  ; Define your menus here!
  ShowWindow_(WindowID(0),#SW_SHOW)
  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by vanleth.

Holy cow, Excellent Approach

Van
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Berikco.

A resizewindow will also remove the glitch.
It believe it was posted before, but i can't find it...

Code: Select all

If OpenWindow(0,200,200,399,199,#PB_Window_Invisible|#PB_Window_SystemMenu,"ToolWindow")
  SetWindowLong_(WindowID(),#GWL_EXSTYLE,GetWindowLong_(WindowID(),#GWL_EXSTYLE)!#WS_EX_TOOLWINDOW)
  ResizeWindow(400, 200) : ShowWindow_(WindowID(),#SW_SHOW)
  Repeat : Until WaitWindowEvent()=#PB_EventCloseWindow
EndIf
Regards,

Berikco

http://www.benny.zeb.be/purebasic.htm
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> A resizewindow will also remove the glitch.

Thanks for that... it'll use less resources (I assume) due to not
having an unused menu.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Berikco.
Originally posted by PB
it'll use less resources (I assume) due to not
having an unused menu.
yep :)

Regards,

Berikco

http://www.benny.zeb.be/purebasic.htm
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Dumb question:
Why is before #WS_EX_TOOLWINDOW the "!" :)
I thought there should be a "|".

Both method are working though.

Have a nice day...

Franco
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

True, the '!' is wrong here, an | is more correct.

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> True, the '!' is wrong here, an | is more correct.

I got the code snippet from a VB source originally, which used Xor in
the code, and in PureBasic, the ! character is used for Xor, so that's
why I used it.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

VB source was wrong :).

Fred - AlphaSND
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

You can also set a parent window if you have one. This will make the child window's button disappear.

Creation:

Code: Select all

OpenWindow(... WindowID(#MainWindow)
Runtime:

Code: Select all

SetParent_(WindowID(), WindowID(#MainWindow))
Edit: just realized this topic was about making a tool window. Why does the FAQ entry "How do I stop my app's window showing in the TaskBar?" lead here?
User avatar
GedB
Addict
Addict
Posts: 1312
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Because tool windows don't appear in the taskbar.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> Why does the FAQ entry "How do I stop my app's window showing in the
> TaskBar?" lead here?

Because that's what a newbie is more likely to ask when they don't want
their app to show in the Taskbar. ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

But what if you want a NORMAL window which doesn't show in the taskbar?

Edit: To those who came here for that, here is how:

Code: Select all

OpenWindow(1, 0, 0, 0, 0, #PB_Window_Invisible, "Parent")
OpenWindow(0,0,0,222,200,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"App without taskbar button", WindowID())
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

Nice trick there Trond!
And by the looks of it, there appears to be no significant change in the memory usage either.
(to test this comment the first open window line)
Heh, here is seemed the extra window trick actualy uses a few KB less memory. :shock:
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Rescator wrote:Heh, here is seemed the extra window trick actualy uses a few KB less memory. :shock:
Yes you are right. That's very strange.
Post Reply