Page 1 of 2
How to hide an external program from the desktop AND taskbar
Posted: Wed Apr 05, 2006 6:40 pm
by Glow
Hi
I don´t get it:
I´m launching an external program with my tool (with RunProgram). So I have the PID and the hwnd. Now I wanna hide the external program with one click from my own app. The problem is: ShowWindow_(hwnd,#SW_HIDE) hides the program from the desktop, but not from the taskbar. It does not have a minimize function, so maybe it has something to do with that.
With other external program (e.g the windows calculator) it works, but not with the program I need to hide. Is there a way to hide it from the taskbar too ? I already tried GetParent_(hwnd), but it returns "0" so there is no parent window

Any tips ?
Regards,
Glow
Posted: Wed Apr 05, 2006 6:43 pm
by netmaestro
Code: Select all
ShowWindow_(WindowID(#window),#SW_HIDE)
SetWindowLong_(WindowID(#window),#GWL_EXSTYLE,GetWindowLong_(WindowID(#window),#GWL_EXSTYLE)|#WS_EX_TOOLWINDOW)
ShowWindow_(WindowID(#window),#SW_SHOW)
Posted: Wed Apr 05, 2006 6:58 pm
by Trond
Set a parent window to remove the taskbar button.
#PB_Program_Hide
Posted: Wed Apr 05, 2006 7:12 pm
by USCode
I don't work with this command much so maybe I dont understand your issue, but couldn't you just do this (for PB4), e.g.:
RunProgram("notepad.exe","","",#PB_Program_Hide)
Then use ProgramID() to get the PID and OpenProcess_() to get the handle (as per the ProgramID docs) ?
Or maybe functionally you have to launch it so it's initially visible to the user then hide later with a push button? If so then this won't work for you, just ignore me...
HTH
Posted: Wed Apr 05, 2006 7:34 pm
by Glow
netmaestro wrote:Code: Select all
ShowWindow_(WindowID(#window),#SW_HIDE)
SetWindowLong_(WindowID(#window),#GWL_EXSTYLE,GetWindowLong_(WindowID(#window),#GWL_EXSTYLE)|#WS_EX_TOOLWINDOW)
ShowWindow_(WindowID(#window),#SW_SHOW)
Thx, but it doesnt work either. I still have it on the taskbar
Trond wrote:
Set a parent window to remove the taskbar button.
How would that look like ?
parent_hwnd = SetParent_(hwnd_external_program,0)
this way ? and then use ShowWindow_(parent_hwnd,#SW_HIDE) to make it invisible for the taskbar ?
Posted: Wed Apr 05, 2006 7:47 pm
by Trond
What program is this? Using ShowWindow_(hWnd, #SW_SHOW) should both make the window invisible and remove it from the taskbar. Are you sure you're using the correct window handle?
Edit: Try this.
Code: Select all
hWnd = 2098800
OpenWindow(0, 0, 0, 0, 0, "", #PB_Window_Invisible)
SetParent_(hWnd, WindowID(0))
ShowWindow_(hWnd, #SW_HIDE)
Posted: Wed Apr 05, 2006 9:32 pm
by Glow
Yeah, I´m getting the hwnd of the external program with FindWindow_
Your example is in no way connected with an external program, or am I totaly wrong ?
Code: Select all
hWnd = 2098800 <- static handle
OpenWindow(0, 0, 0, 0, 0, "", #PB_Window_Invisible) <- new screen - new handle
SetParent_(hWnd, WindowID(0)) <- use static handle with new handle
ShowWindow_(hWnd, #SW_HIDE) <- will hide the program itself
When I use it that way:
Code: Select all
task_hwnd = FindWindow_(0,"Caption of the external program")
OpenWindow(2, 0, 0, 0, 0,#PB_Window_Invisible, "")
SetParent_(task_hwnd, WindowID(2))
ShowWindow_(task_hwnd, #SW_HIDE)
I have the same result as just using ShowWindow_ with the original hwnd of the external program. It will be hidden from the desktop, but still shown in the taskbar. Clicking on it on the taskbar will just result in some short flickering where the window of the program should be.
Maybe that program has some kind of routine to force to be shown in the taskbar ? And if yes, if there a way to check that and to change it ?
Posted: Wed Apr 05, 2006 10:25 pm
by Glow
I just tried some "commercial" tool to hide the app I wanna hide - it does not work. It has the same effect like my own tool

Are there "unhideable" tasks ??
Posted: Wed Apr 05, 2006 10:58 pm
by PB
> Are there "unhideable" tasks ??
Well, there's no reason why an app can't check its visibility state and do its
own #SW_SHOW if it's invisible, but it's highly unlikely. What app are you
running that seems immune to netmaestro's tip? I'd like to see it for myself.
Posted: Wed Apr 05, 2006 11:26 pm
by netmaestro
Is it an unowned window? And if so, what program? Why do you want it hidden from the user?
Posted: Thu Apr 06, 2006 7:39 am
by Glow
The program I´m trying to hide is:
http://images.tomshardware.com/2004/05/ ... assign.zip
I tried some other things in the meanwhile, but with no success

Posted: Thu Apr 06, 2006 8:15 am
by netmaestro
I've thrown my whole bag of tricks at it. Looks like a job for Sparkie...

Posted: Thu Apr 06, 2006 10:44 am
by PB
@Glow: The window of "TaskAssign.exe" actually has a hidden parent window,
so changing the parent is the trick:
Code: Select all
; RemoveFromTaskbar by PB.
Procedure RemoveFromTaskbar(hwnd)
If IsWindow_(hwnd)
a=hwnd : b=GetWindowLong_(a,#GWL_HWNDPARENT) : If b<>0 : a=b : EndIf ; Needed for "TaskAssign.exe".
ShowWindow_(a,#SW_HIDE) : GetWindowRect_(a,win.RECT) : w=win\right-win\left : h=win\bottom-win\top
SetWindowLong_(a,#GWL_EXSTYLE,#WS_EX_TOOLWINDOW) : SetWindowPos_(a,0,0,0,w-1,h-1,#SWP_NOMOVE)
SetWindowPos_(a,0,0,0,w,h,#SWP_NOMOVE|#SWP_SHOWWINDOW) : ProcedureReturn 1
EndIf
EndProcedure
Debug RemoveFromTaskbar(FindWindow_(0,"THG Task Assignment Manager V1.0"))
Debug RemoveFromTaskbar(FindWindow_(0,"Untitled - Notepad"))
Debug RemoveFromTaskbar(FindWindow_(0,"Calculator"))
EDIT: I changed my code above to be a procedure instead, because my
original code didn't work with Windows Calculator. So now the procedure
above, from what I've tested so far, seems to work with any window handle
that you throw at it.

Posted: Thu Apr 06, 2006 10:49 am
by netmaestro
Yup. That gets it here. Good job PB.

Posted: Thu Apr 06, 2006 11:43 am
by nco2k
@Glow
its not very good to mess with a 3rd party window style, because you can screw up a lot. some apps need the size or whatever of the titlebar, statusbar, window(client) rect etc. and if you change the style, the app may get unwanted or unexpected results. it shouldt cause much trouble in most cases, but it depends on how "bulletproof" the app was written. however, its not good and keep that in mind.
c ya,
nco2k