Hi
Does anyone know if the Windows operating system exposes events to the Win32 API when it creates new windows.
I have written a shell to replace explorer.exe for a kiosk terminal. The kiosk terminal has multiple screens. My shell is configured with a list of applications to run, and on what screen to run them. It starts the applications and then manipulates the main window of each, moving it to the configured screen.
The issue I have is that one application, although it allows me to move it, when it opens child windows they always appear on screen 1, even if the main window is say on screen 3.
I want to intercept the creation of the child window and move it before it is displayed.
I already have all the code needed to determine the parent of any child window and be able to move it to any screen desired. What I cannot figure out is how to attach an event handler to the window creation event or if this is even possible, though I guess it is.
Anyone ?????????
Loading
Andy WebsterPosted Feb 16, 2010, 6:40 AM
More info can be found here:
http://msdn.microsoft.com/en-gb/library/ms644977(VS.85).aspx
I will try and add some code when I have figure it out.
Andy WebsterPosted Feb 15, 2010, 3:54 PM
I am sorry for the slow reply and can only say I am truly grateful for your response. I have been working on other projects and have only just got back to this.
It would seem that hooks must be the way to do it and the closest seems to be SetWindowsHookEx using the ShellProc function with the parameter HSHELL_WINDOWCREATED.
The documenetation describes this as "A top-level, unowned window has been created. The window exists when the system calls this hook."
This can be seen at http://msdn.microsoft.com/en-us/library/ms644991(VS.85).aspx
This is exactly what I want but I need the hook to be called after the window has been created but before it is shown. This hook fires after the Window has been shown.
Anyone have any ideas how I can create a hook with this characteristic?
Sam HobbsPosted Feb 5, 2010, 2:54 PM
There are at least two possibilities, and I don't know if either can be done using C#. You can definitely do them using C++ although there might be some security issues to overcome. For one thing, the antivirus software that you use might get confused and think that your code is a virus. Hopefully you can solve that problem one way or another, but you might need to contact the AV software vendor for help.
You can use hooks (see Windows API function SetWindowsHookEx) to intercept messages. I am not sure if the WH_CALLWNDPROC or the WH_GETMESSAGE hook would be best. You might need a month to learn enough about Windows to be able to develop the hook. If the problem can be solved entirely by altering a Windows message, then you can likely solve it using a hook. I don't know how Windows determines what screen to use for new windows; if you know then that will help in deciding how to solve the problem.
You can inject code into the other application. Whether that would work and how you do it depends on the other application. There are a few libraries, such as Microsoft's Detours, that might make it easier. You can search for articles about code injection. This is the ype of thing that AV software gets really irritated with, so be prepared for that if you choose to try it. The most common technique for injecting code uses the Windows API CreateRemoteThread function, although there are definitely others.