Hiding Window Item in the Taskbar

Just starting out? Need help? Post your questions and find answers here.
Chirantha
User
User
Posts: 54
Joined: Sat Jul 16, 2005 7:22 pm

Hiding Window Item in the Taskbar

Post by Chirantha »

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? :(
Baldrick
Addict
Addict
Posts: 860
Joined: Fri Jul 02, 2004 6:49 pm
Location: Australia

Post by Baldrick »

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 
Chirantha
User
User
Posts: 54
Joined: Sat Jul 16, 2005 7:22 pm

Post by Chirantha »

And what if I want to bring back the button? I tried SetParent_() and gave the Desktop Window ID but the button didn't come back :(
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

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
Baldrick
Addict
Addict
Posts: 860
Joined: Fri Jul 02, 2004 6:49 pm
Location: Australia

Post by Baldrick »

@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.

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 
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Check out this link, should be what you want.

http://www.purebasic.fr/english/viewtop ... toolwindow
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Hiding Window Item in the Taskbar

Post by Michael Vogel »

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?

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
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Hiding Window Item in the Taskbar

Post by RASHAD »

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
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Hiding Window Item in the Taskbar

Post by Michael Vogel »

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):

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
User avatar
TI-994A
Addict
Addict
Posts: 2700
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Hiding Window Item in the Taskbar

Post by TI-994A »

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...
This might do the trick:

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 :D
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Hiding Window Item in the Taskbar

Post by IdeasVacuum »

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):

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.
Post Reply