
Hiding Window Item in the Taskbar
Hiding Window Item in the Taskbar
When a window is displayed, a taskbar gets a button (When you click this the window gets forcus. I want to remove this. How do I do it? 

Code: Select all
If OpenWindow(0,0,0,50,50,"HiddenWindow",#PB_Window_Invisible)
If OpenWindow(1,0,0,400,400,"Shown Window",#PB_Window_ScreenCentered|#PB_Window_SystemMenu,WindowID(0))
EndIf
EndIf
Repeat
Ev.l=WaitWindowEvent(9)
Until Ev=#PB_Event_CloseWindow
- Michael Vogel
- Addict
- Posts: 2797
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Here's the same thing but with only one window...
Code: Select all
i=OpenWindow(0,0,0,100,100,"*",#PB_Window_Invisible | #PB_Window_ScreenCentered)
SetWindowLong_(i,#GWL_EXSTYLE,GetWindowLong_(i,#GWL_EXSTYLE) | #WS_EX_TOOLWINDOW)
Repeat
WaitWindowEvent(1000)
HideWindow(0,0)
Delay(1000)
WaitWindowEvent(1000)
HideWindow(0,1)
Delay(1000)
Until 0
@Chirantha,
Would you be able to use a preference file to record whether the window needs to be created hidden / shown from the taskbar?
If so, you could call the openwindow() depending on the prefs file record.
e.g. if prefstatus=0, create the window hidden in the hidden parent or else create it as a normal window without parentid.
Sort of like this, just reading a value from a prefs file on app startup.
Would you be able to use a preference file to record whether the window needs to be created hidden / shown from the taskbar?
If so, you could call the openwindow() depending on the prefs file record.
e.g. if prefstatus=0, create the window hidden in the hidden parent or else create it as a normal window without parentid.
Sort of like this, just reading a value from a prefs file on app startup.
Code: Select all
Procedure Win1(Pref.l)
If IsWindow(1)
x.l=WindowX(1)
y.l=WindowY(1)
CloseWindow(1)
Else
poz.l=#PB_Window_ScreenCentered
EndIf
If Pref
OpenWindow(1,x,y,400,400,"Shown Window",poz|#PB_Window_SystemMenu)
Else
OpenWindow(1,x,y,400,400,"Shown Window",poz|#PB_Window_SystemMenu,WindowID(0))
EndIf
If IsWindow(1)
If CreateGadgetList(WindowID(1))
ButtonGadget(2,10,10,70,20,"Show\Hide")
EndIf
EndIf
EndProcedure
If OpenWindow(0,0,0,50,50,"HiddenWindow",#PB_Window_Invisible)
Win1(choice) ; choice would be read from prefs file
EndIf
Repeat
Ev.l=WaitWindowEvent(9)
If Ev=#PB_Event_Gadget
Select EventGadget()
Case 2 ; you would not do this. It is just to show it works..
choice!1
Win1(choice)
EndSelect
EndIf
Until Ev=#PB_Event_CloseWindow
Check out this link, should be what you want.
http://www.purebasic.fr/english/viewtop ... toolwindow
http://www.purebasic.fr/english/viewtop ... toolwindow
- Michael Vogel
- Addict
- Posts: 2797
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Hiding Window Item in the Taskbar
I am searching for a good idea handling multiple windows with only one button in the taskbar...
I am writing a tool where nearly everything is managed by a single window - but from time to time a second window is needed and then most of the actions are done there (but not all, so the main window can't be disabled).
The following code snippet works fine, but there's something I don't like: when using Alt+Tab in Windows, the program activates the MAIN window in all cases, never the SUB WINDOW. So I added a workaround using the ActivateWindow event but that means I can't use the main window but flickering as well. Any idea if I could change which of the two windows is the "main" (and seen in the taskbar) in runtime?
I am writing a tool where nearly everything is managed by a single window - but from time to time a second window is needed and then most of the actions are done there (but not all, so the main window can't be disabled).
The following code snippet works fine, but there's something I don't like: when using Alt+Tab in Windows, the program activates the MAIN window in all cases, never the SUB WINDOW. So I added a workaround using the ActivateWindow event but that means I can't use the main window but flickering as well. Any idea if I could change which of the two windows is the "main" (and seen in the taskbar) in runtime?
Code: Select all
OpenWindow(1,50,50,200,200,"MAIN")
ButtonGadget(1,10,10,180,40,"SHOW")
OpenWindow(2,200,100,200,100,"SUB WINDOW",#PB_Window_Invisible|#PB_Window_SystemMenu,WindowID(1))
ButtonGadget(2,10,10,180,40,"CLOSE")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
If visible
PostEvent(#PB_Event_Gadget,1,2)
Else
End
EndIf
Case #PB_Event_ActivateWindow
; If visible
; SetActiveWindow(2)
; EndIf
Case #PB_Event_Gadget
Select EventGadget()
Case 1
HideWindow(2,visible)
visible!1
Case 2
HideWindow(2,1)
visible=0
EndSelect
EndSelect
ForEver
Re: Hiding Window Item in the Taskbar
Code: Select all
OpenWindow(1,50,50,200,200,"MAIN")
ButtonGadget(1,10,10,180,40,"SHOW")
OpenWindow(2,200,100,200,100,"SUB WINDOW",#PB_Window_Invisible|#PB_Window_SystemMenu)
ButtonGadget(2,10,10,180,40,"CLOSE")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
If visible
PostEvent(#PB_Event_Gadget,1,2)
Else
End
EndIf
Case #PB_Event_Gadget
Select EventGadget()
Case 1
HideWindow(2,0)
SetWindowLongPtr_(WindowID(1),#GWL_HWNDPARENT,WindowID(2))
Case 2
SetWindowLongPtr_(WindowID(1),#GWL_HWNDPARENT,0)
HideWindow(2,1)
EndSelect
EndSelect
ForEver
Egypt my love
- Michael Vogel
- Addict
- Posts: 2797
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Hiding Window Item in the Taskbar
Thanks, there's one more small issue here: when using the task switcher (Alt+Tab), the second window will be seen below the main window...
Meanwhile I am doing this (seems to be fine):
Meanwhile I am doing this (seems to be fine):
Code: Select all
Procedure HideFromTaskBar(hWnd.l, Flag.l)
Protected TBL.ITaskbarList
CoInitialize_(0)
If CoCreateInstance_(?CLSID_TaskBarList, 0, 1, ?IID_ITaskBarList, @TBL) = #S_OK
TBL\HrInit()
If Flag
TBL\DeleteTab(hWnd)
Else
TBL\AddTab(hWnd)
EndIf
TBL\Release()
EndIf
CoUninitialize_()
DataSection
CLSID_TaskBarList:
Data.l $56FDF344
Data.w $FD6D, $11D0
Data.b $95, $8A, $00, $60, $97, $C9, $A0, $90
IID_ITaskBarList:
Data.l $56FDF342
Data.w $FD6D, $11D0
Data.b $95, $8A, $00, $60, $97, $C9, $A0, $90
EndDataSection
EndProcedure
OpenWindow(1,50,50,200,200,"MAIN")
ButtonGadget(1,10,10,180,40,"SHOW")
OpenWindow(2,200,100,200,100,"SUB WINDOW",#PB_Window_Invisible|#PB_Window_SystemMenu);,WindowID(1))
ButtonGadget(2,10,10,180,40,"CLOSE")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
If visible
PostEvent(#PB_Event_Gadget,1,2)
Else
End
EndIf
Case #PB_Event_ActivateWindow
If visible
;SetActiveWindow(2)
EndIf
Case #PB_Event_Gadget
Select EventGadget()
Case 1
HideWindow(2,visible)
visible!1
If visible
HideFromTaskBar(WindowID(1),1)
HideFromTaskBar(WindowID(2),0)
EndIf
Case 2
HideFromTaskBar(WindowID(1),0)
HideWindow(2,1)
visible=0
EndSelect
EndSelect
ForEver
Re: Hiding Window Item in the Taskbar
This might do the trick:Michael Vogel wrote:...handling multiple windows with only one button in the taskbar...
...when using Alt+Tab in Windows, the program activates the MAIN window in all cases, never the SUB WINDOW...
Code: Select all
OpenWindow(1,50,50,200,200,"MAIN")
ButtonGadget(1,10,10,180,40,"HIDE/SHOW")
OpenWindow(2,200,100,200,100,"SUB WINDOW",#PB_Window_Invisible|#PB_Window_SystemMenu,WindowID(1))
ButtonGadget(2,10,10,180,40,"CLOSE")
activeWindow = 1
Repeat
Select WaitWindowEvent()
Case #PB_Event_ActivateWindow
If appLostFocus
appLostFocus = #False
SetActiveWindow(activeWindow)
Else
activeWindow = EventWindow()
SetActiveWindow(activeWindow)
EndIf
Case #PB_Event_DeactivateWindow
If GetActiveWindow() = -1
appLostFocus = #True
EndIf
Case #PB_Event_CloseWindow
If EventWindow() = 1
appQuit = 1
Else
HideWindow(2, visible)
activeWindow = 1
visible = 0
EndIf
Case #PB_Event_Gadget
Select EventGadget()
Case 1, 2
HideWindow(2, visible)
visible!1
activeWindow = visible + 1
EndSelect
EndSelect
Until appQuit
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 

-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Hiding Window Item in the Taskbar
If one of the windows can be a "Tool" Window, that window will not display in the Task bar.
If that is not a good solution, the following API code does it (this is not coded by me):
If that is not a good solution, the following API code does it (this is not coded by me):
Code: Select all
Procedure HideFromTaskBar(iWin.i)
;#------------------------------
;Use to prevent upteen icons appearing on the task bar when child windows are displayed
DataSection
CLSID_TaskBarList:
Data.l $56FDF344
Data.w $FD6D, $11D0
Data.b $95, $8A, $00, $60, $97, $C9, $A0, $90
IID_ITaskBarList:
Data.l $56FDF342
Data.w $FD6D, $11D0
Data.b $95, $8A, $00, $60, $97, $C9, $A0, $90
EndDataSection
Protected hWnd.i = WindowID(iWin)
Protected TBL.ITaskbarList
CoInitialize_(0)
If CoCreateInstance_(?CLSID_TaskBarList, 0, 1, ?IID_ITaskBarList, @TBL) = #S_OK
TBL\HrInit()
TBL\DeleteTab(hWnd)
TBL\Release()
EndIf
CoUninitialize_()
EndProcedure
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.