Hiding Window Item in the Taskbar
Posted: Sat Jul 26, 2008 9:28 am
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? 

http://www.purebasic.com
https://www.purebasic.fr/english/
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
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
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
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
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
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
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
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