Window subclassing and mouse events

  • Thread starter Scott McChesney
  • Start date
S

Scott McChesney

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
 
S

Scott McChesney

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
 
C

Claes Bergefall

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top