Page 1 of 1

Problem with WS_EX_TOOLWINDOW

Posted: Mon Jul 28, 2008 4:54 am
by Chirantha
Hi,

I'm creating a window with the WS_EX_TOOLWINDOW flag. Here is the code

Code: Select all

OpenWindow(0,0,0,320,240,"Window",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
HideWindow(0,1)
SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE) | #WS_EX_TOOLWINDOW) 
HideWindow(0,0)
If CreateGadgetList(WindowID(0))
  ButtonGadget(1, 60, 60, 60, 20, "blub")
EndIf

Repeat
WaitWindowEvent()
Delay(20)
ForEver
The window creates just fine but when I minimize the background window aka the window just behind my window. My window gets sent to the back of the previous window (it doesn't get forcus, nor can I bring it up with the ALT+TAB buttons). I believe this is not the behaviour of a normal window.

How do I fix it, all I wanted to do was to remove the app from the taskbar :(

Posted: Mon Jul 28, 2008 5:46 am
by superadnim
regarding your "cant close" problem... you are not handling the window's events, hence, you cannot close the window, ever.

try this:

Code: Select all

If OpenWindow(0,0,0,320,240,"Window",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
	
	HideWindow(0,1)
	SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE) | #WS_EX_TOOLWINDOW)
	HideWindow(0,0)
	
	If CreateGadgetList(WindowID(0))
	  ButtonGadget(1, 60, 60, 60, 20, "blub")
	EndIf
	
	Repeat
	    EventID = WaitWindowEvent()
	    Select EventID
	    	Case #PB_Event_CloseWindow
	      	Quit = 1
	    EndSelect
	Until Quit = 1
	
EndIf
WaitWindowEvent() already "waits" so there is NO need to add a Delay(), you can add a timeout value to WaitWindowEvent() though.

Posted: Mon Jul 28, 2008 5:52 am
by Chirantha
superadnim wrote:regarding your "cant close" problem... you are not handling the window's events, hence, you cannot close the window, ever.

try this:

Code: Select all

If OpenWindow(0,0,0,320,240,"Window",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
	
	HideWindow(0,1)
	SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE) | #WS_EX_TOOLWINDOW)
	HideWindow(0,0)
	
	If CreateGadgetList(WindowID(0))
	  ButtonGadget(1, 60, 60, 60, 20, "blub")
	EndIf
	
	Repeat
	    EventID = WaitWindowEvent()
	    Select EventID
	    	Case #PB_Event_CloseWindow
	      	Quit = 1
	    EndSelect
	Until Quit = 1
	
EndIf
WaitWindowEvent() already "waits" so there is NO need to add a Delay(), you can add a timeout value to WaitWindowEvent() though.
Have you read my post correctly? you are totally off topic here :S

Posted: Mon Jul 28, 2008 8:33 am
by Fluid Byte
Chirantha wrote:Have you read my post correctly? you are totally off topic here :S
He's totally ontopic, why you use Delay() with WaitWindowEvent()?
Chirantha wrote:I believe this is not the behaviour of a normal window.
In fact the behaviour is perfectly normal since you hide the window from the taskbar. So the question is what are you trying to achieve here? Is this is going to be some sort of systray application?

Posted: Mon Jul 28, 2008 10:39 am
by Chirantha
Fluid Byte wrote:
Chirantha wrote:Have you read my post correctly? you are totally off topic here :S
He's totally ontopic, why you use Delay() with WaitWindowEvent()?
Chirantha wrote:I believe this is not the behaviour of a normal window.
In fact the behaviour is perfectly normal since you hide the window from the taskbar. So the question is what are you trying to achieve here? Is this is going to be some sort of systray application?
1. launch some apps and maximie them and then launch pb.... (don't minimize them)
2. run this code
3. now minimize pb window or some other window..
now see that the app disappears... you won't be able to see app until you minimize all apps!

Posted: Tue Jul 29, 2008 4:42 pm
by Sparkie
Chirantha wrote:The window creates just fine but when I minimize the background window aka the window just behind my window. My window gets sent to the back of the previous window (it doesn't get forcus, nor can I bring it up with the ALT+TAB buttons). I believe this is not the behaviour of a normal window.
Once you add the #WS_EX_TOOLWINDOW you are no longer dealing with a normal window. The behavior you describe is correct for a Toolwindow.

Posted: Tue Jul 29, 2008 4:54 pm
by Kaeru Gaman
usually, a tool has a parent.
a correct and complete eventhandling would also help.

Code: Select all

If OpenWindow(0,320,240,320,240,"Parent" ) 
  If OpenWindow(1,0,0,320,240,"ToolWindow", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget, WindowID(0))
    HideWindow(1,1)
    SetWindowLong_(WindowID(1),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE) | #WS_EX_TOOLWINDOW)
    HideWindow(1,0)
    If CreateGadgetList(WindowID(0))
      ButtonGadget(0, 60, 60, 60, 20, "blub")
    EndIf
    Repeat
       EventID = WaitWindowEvent()
       EventWin = EventWindow()
       EventGad = EventGadget()
       Select EventID
          Case #PB_Event_Gadget
            Select EventGad
              Case 0
                HideWindow(1,0)
            EndSelect
          Case #PB_Event_CloseWindow
            Select EventWin
              Case 0
                Quit = 1
              Case 1
                HideWindow(1,1)
            EndSelect
       EndSelect
    Until Quit = 1
  EndIf
EndIf

Re: Problem with WS_EX_TOOLWINDOW

Posted: Tue Jul 29, 2008 11:05 pm
by Seldon

Code: Select all

SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE) | #WS_EX_TOOLWINDOW) 
After you change a normal window into a toolwindow, I do suggest to resize its width and height as there could be some weird problems with the window drawing on systems with no GUI themes set, like Windows 2000 .

Code: Select all

ResizeWindow(0,#PB_Ignore,#PB_Ignore,WindowWidth(0)+1,WindowHeight(0)+1)
Another suggestion is to open the window as 'hidden' and show it after you've changed its attributes. Not in topic, but some good tips I think. :)