all groups > dotnet framework > april 2007 >
You're in the

dotnet framework

group:

Subclassing question.


Subclassing question. Andrew
4/27/2007 11:06:02 AM
dotnet framework:
Hello,

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).

What was wrong here? I need to be able to tell which Excel window is the
active one programmatically. Was this a right approach for this purpose? Any
papers?

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.


Re: Subclassing question. Andrew
4/27/2007 1:40:02 PM
Hi, Mattias, thanks for the reply.

[quoted text, click to view]

Is there a way to track the window message in other processes? Thanks.

[quoted text, click to view]

Our app needs to know right away when the active window is change, so we can
not use this function at a certain point in time or controled by a timer.

[quoted text, click to view]
Re: Subclassing question. Mattias Sjögren
4/27/2007 9:59:15 PM

[quoted text, click to view]

Subclassing this way only works for windows in your own process, not
in other applications.


[quoted text, click to view]

If you just want to know which window is active at a certain point in
time, use GetForegroundWindow.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
AddThis Social Bookmark Button