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 / December 2004

Tip: Looking for answers? Try searching our database.

Window subclassing and mouse events

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Scott McChesney - 01 Dec 2004 17:00 GMT
VS.NET 2003, VB.NET, .NET 1.1

I'm working on a part of a project that is re-creating the Office 2003 mail
notification window.  I have almost everything done except for one part.  I
need to allow the user to move the window by clicking and dragging anywhere
in the window (the window has no title bar.)

Per many different sources, I have overridden the WndProc() method of my
window thusly:

---------------------------------

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
   Call MyBase.WndProc(m)

   Select Case m.Msg
       Case WM_NCHITTEST
           If m.Result.ToInt32 = HTCLIENT Then m.Result = New
IntPtr(HTCAPTION)
   End Select
End Sub

---------------------------------

When I run the form, all is well - almost.  I have found that when I do
this, I don't get any of my form's mouse events.

I am doing a lot of hand-work here, so I have MouseEnter, MouseLeave, and
MouseDown events coded.  These perform various functions that simulate
functionality I would normally get by using controls (buttons, linklabels,
etc.) but chose not to use.  My reasons for not using them is because of the
functionality I am trying to simulate:

1. The form fades in to 20% transparency when it's shown.  It then begins a
timer for fade-out (time set by the user, with an application default
provided.)
2. If the mouse moves into the form, it goes to 0% transparency (opaque).
3. If the mouse leaves the form, it returns to 20% transparency.
4. The form will fade away at the first opportunity - either when reaching
the fade-out time, or when the mouse leaves the form, whichever happens
*last*.

Using controls caused MouseEnter and MouseLeave events to fire on the
controls and form multiple all over the place, and I wasn't able to handle
them in any sort of satisfactory way.  So I dumped the controls and wrote it
all by hand.

Since I don't get the mouse events, nothing happens when the mouse moves
within the form.  The form does not go opaque, and the fade-out will happen
even if the mouse is within the form.  I suppose I could re-create the
functionality within the WndProc() method, but I don't understand why I have
to - since my custom WndProc() is not trapping mouse events, and the first
thing I do is call the base method, those should still fire - right?

What am I missing?  Any help would be appreciated.

TIA

- Scott
Nigel Armstrong - 01 Dec 2004 20:01 GMT
Hi Scott

If you look on the Syncfusion FAQ, you should find an alternate method for
dragging which doesn't use the WndProc mechanism:

http://www.syncfusion.com/FAQ/WinForms/FAQ_c50c.asp#q699q

HTH

Nigel Armstrong

> VS.NET 2003, VB.NET, .NET 1.1
>
[quoted text clipped - 55 lines]
>
> - Scott
Scott McChesney - 01 Dec 2004 21:09 GMT
Thanks - that did the trick.  But can you explain to me why overriding the
WndProc() form routine ate my mouse messages?  I just don't get that...

- Scott

> Hi Scott
>
[quoted text clipped - 66 lines]
> >
> > - Scott
Claes Bergefall - 02 Dec 2004 09:57 GMT
Taking a wild guess here but...

Since you're returning HTCAPTION when you're actually
in the client area Windows sends WM_NCMOUSEMOVE etc
instead of WM_MOUSEMOVE, and those are not mapped
to the Mouse events in .NET

   /claes

> VS.NET 2003, VB.NET, .NET 1.1
>
[quoted text clipped - 55 lines]
>
> - Scott
Claes Bergefall - 02 Dec 2004 10:01 GMT
I just tried it and that is indeed what happens

   /claes

> Taking a wild guess here but...
>
[quoted text clipped - 72 lines]
> >
> > - Scott

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.