How to hide an external program from the desktop AND taskbar

Just starting out? Need help? Post your questions and find answers here.
Glow
User
User
Posts: 10
Joined: Sun Dec 18, 2005 9:03 pm

How to hide an external program from the desktop AND taskbar

Post 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
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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)
BERESHEIT
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Set a parent window to remove the taskbar button.
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

#PB_Program_Hide

Post 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... :wink:

HTH
Glow
User
User
Posts: 10
Joined: Sun Dec 18, 2005 9:03 pm

Post 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 ?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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)
Glow
User
User
Posts: 10
Joined: Sun Dec 18, 2005 9:03 pm

Post 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 ?
Glow
User
User
Posts: 10
Joined: Sun Dec 18, 2005 9:03 pm

Post 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 ??
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Is it an unowned window? And if so, what program? Why do you want it hidden from the user?
BERESHEIT
Glow
User
User
Posts: 10
Joined: Sun Dec 18, 2005 9:03 pm

Post 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 :(
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I've thrown my whole bag of tricks at it. Looks like a job for Sparkie... Image
BERESHEIT
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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. ;)
Last edited by PB on Thu Apr 06, 2006 11:03 am, edited 2 times in total.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Yup. That gets it here. Good job PB. :wink:
BERESHEIT
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post 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. :!: :D

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Post Reply