|
-
Oct 7th, 2006, 03:35 PM
#1
Thread Starter
No place like 127.0.0.1
[2005] Hide window of a process that has already started
I did some searching on the subject, and all I could find was how to hide the window of a process that YOU are starting.
Is there anyway to hide the window of a process that is already started?
-
Oct 7th, 2006, 04:05 PM
#2
Re: [2005] Hide window of a process that has already started
I don't know if there is a better way in .Net, but you can use APIs, FindWindow to find the window you want to minimize, and SetWindowPlacement to minimize it (uses WINDOWPLACEMENT type/enum with SW_SHOWNORMAL, SW_SHOWMAXIMIZED, and SW_SHOWMINIMIZED values).
Use GetWindowPlacement to check if it's not already minimized.
-
Oct 7th, 2006, 04:17 PM
#3
Thread Starter
No place like 127.0.0.1
Re: [2005] Hide window of a process that has already started
Sorry. I wasn't clear. When I said "hide" I meant make the window invisible and unable to receive focus. I also don't want it to show up in the taskbar.
The reason is because I have a program that is converting songs and it uses Windows Media Player to "listen" to the song digital (at 4x speed) and every couple of minutes WMP automatically focuses itself because the song is switching and it gets really annoying.
If someone can think of a different way to solve that problem, I'd love to hear it, but the only thing I can think of is to basically make the window non-existant.
-
Oct 7th, 2006, 04:20 PM
#4
Re: [2005] Hide window of a process that has already started
Sorry, just realised that you want to hide the window, my mistake.
You could look into ShowWindow API and use SW_HIDE constant value on the handle of the WMP. This should work.
-
Oct 7th, 2006, 04:36 PM
#5
Re: [2005] Hide window of a process that has already started
Do you just want to hide a window?? Because doing so won't destroy it from the Processes list. You would then need CloseHandle API to close the running WMP process.
-
Oct 7th, 2006, 11:06 PM
#6
Thread Starter
No place like 127.0.0.1
Re: [2005] Hide window of a process that has already started
No. I don't want to destroy it. I just want to make it so it can't receive focus. Like I said, every couple of minutes it automatically gives itself focus and if I'm typing or doing ANYTHING when that happens, I have to refocus on the window I want.
I'll try that API tomorrow when I work on it some more.
-
Oct 8th, 2006, 06:23 AM
#7
Re: [2005] Hide window of a process that has already started
VB Code:
Const SW_SHOWNORMAL = 1
Const SW_HIDE = 0
Const SW_RESTORE = 9
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
Public Declare Function GetFocus Lib "user32" () As Integer
Public Declare Function SetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Integer) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ShowWindow(FindWindow(vbNullString, "AppCaptionStealingFocus"), SW_HIDE)
End Sub
'You can use a timer, to check "getfocus", and then setfocus back on your window. The get/setforeground API may be helpful too, where you can update the current foreground window, and focus in a variable.
If GetFocus = FindWindow(vbNullString, "AppCaptionStealingFocus") Then
SetFocus(YourWindowHandle)
End If
Last edited by TTn; Oct 8th, 2006 at 06:29 AM.
-
Oct 8th, 2006, 02:06 PM
#8
Thread Starter
No place like 127.0.0.1
Re: [2005] Hide window of a process that has already started
The part about hiding the window should work (I haven't had time to test it yet), but the problem with the GetFocus and SetFocus is that I'm not trying to set focus back to my program, I just need for the other window to never get focus. If it's hidden, I'm assuming it won't get focus, but I still need to test that.
The reason I don't need to set focus back to my program is because my program is running behind the scences as well. It's just when I'm surfing the internet or typing a message or something, and WMP gets focus, I have to refocus on firefox to continue typing or whatever else I was doing.
-
Oct 8th, 2006, 06:12 PM
#9
Re: [2005] Hide window of a process that has already started
Yeah, that's why I mentioned the timer, so when wmp steals the focus, you have the handle of the last window with focus, whatever it is. So you can reset it within the closest second.
You may try EnableWindow API, to avoid focus .
This might work too:
VB Code:
Public Declare Function EnableWindow Lib "user32" (ByVal hwnd As Integer, ByVal fEnable As Integer) As Integer
EnableWindow(FindWindow(vbnullstring, "Windows Media Player"), False)
Not sure though.
You'll need a workaround, if the user has the full screen option on, in wmp.
-
Oct 9th, 2006, 03:12 PM
#10
Thread Starter
No place like 127.0.0.1
Re: [2005] Hide window of a process that has already started
EnableWindow didn't have any effect on the window at all.
The timer method doens't work because I need it to NEVER get focus. With your timer idea, it gets focus for a second and then switches back to what I was looking at before.
-
Oct 9th, 2006, 05:12 PM
#11
Re: [2005] Hide window of a process that has already started
Okay, so it is very important, that it never recieve focus ever.
Even for a tenth of a second?
Then, I think you'll have to intercept the windows message, and block it.
This may make the wmp, malfuction, if it really needs focus for that moment.
I'll see what I can dig up, since I too inter-operate with wmp.
Anyone else got any ideas?
[EDIT]:
What happens if the media player is in a minimized state?
I thought that it couldn't get focus then. I'll try a few things.
Last edited by TTn; Oct 9th, 2006 at 05:15 PM.
-
Oct 9th, 2006, 05:16 PM
#12
Thread Starter
No place like 127.0.0.1
Re: [2005] Hide window of a process that has already started
You MIGHT be right about it being minimized and not getting focus. I thought I had tested that, but maybe not.
None of it's processing is going to be messed up if it doesn't get focus. I'm sure of that.
-
Oct 9th, 2006, 09:50 PM
#13
Thread Starter
No place like 127.0.0.1
Re: [2005] Hide window of a process that has already started
Yeah. It definitely still steals focus if it's minimized. It's probably because the application that is digitally "listening" to WMP is probably forcing that to happen.
Any other ideas?
-
Oct 10th, 2006, 01:19 PM
#14
Thread Starter
No place like 127.0.0.1
Re: [2005] Hide window of a process that has already started
I've skimmed through a few more APIs and haven't found anything. Anyone else have some thoughts?
-
Oct 10th, 2006, 08:43 PM
#15
Re: [2005] Hide window of a process that has already started
I'm stumped on this one too!
I've tried a few sub classing techniques, but it doesn't respond.
I tried PeekMessage with no results, but maybe someone in the API forum can help better with that.
Sorry, if I find anything I'll repost.
-
Oct 11th, 2006, 08:20 AM
#16
Re: [2005] Hide window of a process that has already started
This seems to be the way to go for you:
SubClassingHooks
PeekMessage
Also, the API GUIDE, has a decent example of PeekMessage.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|