Page 1 of 1

Tip: ToolWindow (tiny code version)

Posted: Tue Jan 21, 2003 3:27 am
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

Posted: Tue Jan 21, 2003 3:49 am
by BackupUser
Restored from previous forum. Originally posted by vanleth.

Holy cow, Excellent Approach

Van

Posted: Tue Jan 21, 2003 8:17 am
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

Posted: Tue Jan 21, 2003 10:58 am
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.

Posted: Tue Jan 21, 2003 11:35 am
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

Posted: Tue Jan 21, 2003 5:42 pm
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

Posted: Tue Jan 21, 2003 10:21 pm
by BackupUser
Restored from previous forum. Originally posted by fred.

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

Fred - AlphaSND

Posted: Wed Jan 22, 2003 1:02 am
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.

Posted: Wed Jan 22, 2003 8:59 am
by BackupUser
Restored from previous forum. Originally posted by fred.

VB source was wrong :).

Fred - AlphaSND

Posted: Mon Oct 31, 2005 2:17 pm
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?

Posted: Mon Oct 31, 2005 2:37 pm
by GedB
Because tool windows don't appear in the taskbar.

Posted: Mon Oct 31, 2005 8:03 pm
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. ;)

Posted: Mon Oct 31, 2005 9:43 pm
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

Posted: Fri Nov 04, 2005 4:58 am
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:

Posted: Fri Nov 04, 2005 8:45 am
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.