Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / April 2007

Tip: Looking for answers? Try searching our database.

Subclassing question.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew - 27 Apr 2007 19:06 GMT
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.
Mattias Sjögren - 27 Apr 2007 20:59 GMT
>What was wrong here

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

>I need to be able to tell which Excel window is the
>active one programmatically. Was this a right approach for this purpose?

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

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Andrew - 27 Apr 2007 21:40 GMT
Hi, Mattias, thanks for the reply.

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

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

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

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.

> >What was wrong here
>
[quoted text clipped - 8 lines]
>
> Mattias

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.