Getting active window
-
How can i get the currently active window in VB.Net without declaring an external user32.dll function and use it? There's a function i can call directly? Thanks, Ale.
-
I don't know of a Framework call that will do that. Anyway, what's wrong with calling into Win32?
What i want to do is a background process getting notified of system messages, such as WM_APPACTIVATE and get a reference or an handle of activated process/app. I had some bad experience with NativeWindow class, i think i've not completely got all the triks it offers. Could you suggest any solution? Thanks.
-
What i want to do is a background process getting notified of system messages, such as WM_APPACTIVATE and get a reference or an handle of activated process/app. I had some bad experience with NativeWindow class, i think i've not completely got all the triks it offers. Could you suggest any solution? Thanks.
OK. First, there is no WM_APPACTIVATE message. The closest match to what your looking for is WM_ACTIVATE. It is sent once to two windows. First, to the window being deactivated, then to the window being activated. The WPARAM part of the message contains the details of the ACTIVATE command and the LPARAM part will contain the handle of the window being activated or deactivated and, strangely enough, CAN BE NULL! Full details on the WM_ACTIVE message are here[^]. Second, the WM_ACTIVATE message is NOT broadcast to the entire system. In order to get your hands on that message your going to have to write a CBT Hook. With this you'll get notified of all Activate, Create, Destroy, Minimize, Maximize, Move, and Size messages going to any window, along with a bunch of other things. I'm saying this because you're hook routine is going to have to pick out the messages you want, do any processing you want, and then send the message down the hook chain quickly and efficiently or else you'll degrade system performance. The top of the Windows Hooks documentation starts here[^], and the docs for writing a CBTProc hook function are here[^]. If your not familiar with writing Windows Hook functions, it's going to be a bit confusing to read at first. You might want to start with the basics of how Windows Messaging works, and that is
-
What i want to do is a background process getting notified of system messages, such as WM_APPACTIVATE and get a reference or an handle of activated process/app. I had some bad experience with NativeWindow class, i think i've not completely got all the triks it offers. Could you suggest any solution? Thanks.
Just curious, but what is this project doing? RageInTheMachine9532
-
Just curious, but what is this project doing? RageInTheMachine9532
Very, very helpfull. Thank you very much. I'm working on a webapp controlling a very old application, i need to simulate a terminal server session via web browser. I'm new to .net development, i come from years of java programming. Just another little question, i start a process and i do the following : startedProcess = Process.Start(startInfo) startedProcess.WaitForInputIdle(5000) Dim name = startedProcess.MainWindowTitle() Dim mwHandle = startedProcess.MainWindowHandle() Dim topForm = Form.FromHandle(mwHandle) topForm is always null. How can i get a Form object from a window handle? thanks again.