none
¿How to know when other windows are created? RRS feed

  • Question

  • Hi,

     

    I'm developing a C# application with .NET 3.5 (using WPF). I Need to know when other windows (win32 windows) are created, so I can hide one. Is there a way to do so using the .NET Framework, or should I use Interop?

    I've tried using SetWindowHookEx with platform invoke, but I do not receive any notifications. Perhaps it is because I'm setting the hook in a thread that is not the main thread and the thread dies before getting any notification?

     

    Any help will be welcome!

    Friday, January 23, 2009 10:29 AM

Answers

  • You've got a chicken-and-egg problem.  You can't get the notification unless you have the window handle.  You can't get the window handle until it is created.  Not much you can do but enumerate windows to find it back after making whatever call you make that gets the window created.   Please use this forum only to ask questions about the CLR.
    Hans Passant.
    Friday, January 23, 2009 12:03 PM
    Moderator
  • Windows in your own application or in other applications?

    A global WH_SHELL hook should get notified of all top-level windows created. But global hooks can't be implemented in managed code.

     


    Mattias, C# MVP
    Monday, January 26, 2009 2:04 PM
    Moderator

All replies

  • You've got a chicken-and-egg problem.  You can't get the notification unless you have the window handle.  You can't get the window handle until it is created.  Not much you can do but enumerate windows to find it back after making whatever call you make that gets the window created.   Please use this forum only to ask questions about the CLR.
    Hans Passant.
    Friday, January 23, 2009 12:03 PM
    Moderator
  • Windows in your own application or in other applications?

    A global WH_SHELL hook should get notified of all top-level windows created. But global hooks can't be implemented in managed code.

     


    Mattias, C# MVP
    Monday, January 26, 2009 2:04 PM
    Moderator
  • Maybe you can check the list from System.Diagnostics.Process.GetProcesses() regulary on new processes as they contain the Main Window handle. Though this is not the best way finding new windows it allows easy implementation without Interop.
    Tuesday, January 27, 2009 2:32 PM