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 / Windows Forms / WinForm General / May 2006

Tip: Looking for answers? Try searching our database.

Filtering focus messages/events

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
paulo - 29 May 2006 18:04 GMT
Hello,

I'm developing a Windows Forms application with .NET 2.0 and I need to
centrally get all focus messages / events. For example, when a user tabs
from one TextBox to another in the application, I want to know that
TextoBox1 lost focus and TextBox2 got focus. I tried to add a
IMessageFilter to the application, but i don't seem to get anything
relevant, other than keyup and keydowns.
Is there anyway to do this?
Thanks in advance for any help given.

Regards,
paulo
"Jeffrey Tan[MSFT]" - 30 May 2006 03:36 GMT
Hi paulo,

Thanks for your post!

IMessageFilter is not a reliable way to catch all the messages in the
application. Actually, IMessageFilter is preprocessing before the normal
translate/dispatch cycle of the message pump, and it will only see posted
messages. The messages that pass to the Windows procedure through
SendMessage method will not be placed in the message pump, so the
IMessageFilter will not see them.

If you only want to catch all the messages to the main Form, you may
override Form class's WndProc method. Normally all the messages to Form
class will first pass this method first. However, in your scenario, the
TextBoxes themselves are separate windows, they have their own WndProc, so
the focus messages of TextBoxes will not be passed to Form's WndProc, while
are passed to TextBoxes' WndProc.

The only reliable way to catch all the messages in a Winform application is
Windows Message Hook. You can install a WH_GETMESSAGE to the main GUI
thread of your application, and then you will get all the messages in your
main GUI thread. Because this is a Local Windows Hook, there is no need to
write the hook procedure in a dll, you can just use p/invoke in C# to get
this done. Please refer to the KB below:
"How to set a Windows hook in Visual C# .NET"
http://support.microsoft.com/kb/318804/en-us

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
paulo - 30 May 2006 10:24 GMT
Hello Jeffrey!

Thank you so much for your reply.
I will definitely look into Windows hooks.

Kind regards,
paulo

Jeffrey Tan[MSFT] wrote:
> Hi paulo,
>
[quoted text clipped - 33 lines]
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Jeffrey Tan[MSFT]" - 31 May 2006 02:39 GMT
Ok, if you need further help, please feel free to post. Thanks!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

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.