|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to tell which window becomes the foregroud window right away?I followed the MS instructions to subclass Windows using C#.net (http://support.microsoft.com/kb/815775) as the follows. I then opened several Excel files, and selected anyone of them as foreground window. I was expecting to see windows message, saying WM_ACTIVATE, or something like that, however, to my surprise, I saw NO windows message when I randomly selected those Excel windows, (although I could see other window messages, e.g., WM_GETTEXT). It was said that this was because "Subclassing this way only works for windows in its own process, not in other applications." Then, is there a way to make it work on other processes? Will automation will make the "other application" in the same process of our application? My goad is: Tell which (e.g. Excel) window becomes the active one AS SOON AS a (e.g. Excel) window becomes active. Thanks a lot. -------------------- Add a new Class module that is named SubclassHWND.cs to the Visual C# .NET or Visual C# 2005 application. To do this, click Add Class on the Project menu. 2. In the Name text box, type SubclassHWND.cs, and then click Open. 3. Replace the SubclassHWND class code with the following code:public class SubclassHWND : NativeWindow { protected override void WndProc(ref Message m) { // Perform whatever custom processing you must have for this message System.Diagnostics.Debug.WriteLine(m.ToString()); // forward message to base WndProc base.WndProc(ref m); } } 4. To demonstrate its use, add the following code to the Load event of Form1:SubclassHWND s = new SubclassHWND(); s.AssignHandle(this.Handle); //Now s should be listening to the messages of the form. |
|||||||||||||||||||||||