Results 1 to 16 of 16

Thread: [2005] Hide window of a process that has already started

  1. #1

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    [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?
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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.
    Show Appreciation. Rate Posts.

  3. #3

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    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.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  4. #4
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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.
    Show Appreciation. Rate Posts.

  5. #5
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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.
    Show Appreciation. Rate Posts.

  6. #6

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    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.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  7. #7
    Fanatic Member TTn's Avatar
    Join Date
    Jul 2004
    Posts
    708

    Re: [2005] Hide window of a process that has already started

    VB Code:
    1. Const SW_SHOWNORMAL = 1
    2.     Const SW_HIDE = 0
    3.     Const SW_RESTORE = 9
    4.  
    5.     Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    6.  
    7.    Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
    8.  
    9.     Public Declare Function GetFocus Lib "user32" () As Integer
    10.  
    11.     Public Declare Function SetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Integer) As Integer
    12.  
    13.  
    14.  
    15.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    16.         ShowWindow(FindWindow(vbNullString, "AppCaptionStealingFocus"), SW_HIDE)
    17.     End Sub
    18.  
    19. '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.
    20.         If GetFocus = FindWindow(vbNullString, "AppCaptionStealingFocus") Then
    21.             SetFocus(YourWindowHandle)
    22.         End If
    Last edited by TTn; Oct 8th, 2006 at 06:29 AM.

  8. #8

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    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.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  9. #9
    Fanatic Member TTn's Avatar
    Join Date
    Jul 2004
    Posts
    708

    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:
    1. Public Declare Function EnableWindow Lib "user32" (ByVal hwnd As Integer, ByVal fEnable As Integer) As Integer
    2.  
    3.    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.

  10. #10

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    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.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  11. #11
    Fanatic Member TTn's Avatar
    Join Date
    Jul 2004
    Posts
    708

    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.

  12. #12

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    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.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  13. #13

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    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?
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  14. #14

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    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?
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  15. #15
    Fanatic Member TTn's Avatar
    Join Date
    Jul 2004
    Posts
    708

    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.

  16. #16
    Fanatic Member TTn's Avatar
    Join Date
    Jul 2004
    Posts
    708

    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
  •  



Click Here to Expand Forum to Full Width