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

RE: Window subclassing and mouse events by NigelArmstrong

NigelArmstrong
Wed Dec 01 14:01:05 CST 2004

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

"Scott McChesney" wrote:

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

Re: Window subclassing and mouse events by Scott

Scott
Wed Dec 01 15:09:03 CST 2004

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

"Nigel Armstrong" <NigelArmstrong@discussions.microsoft.com> wrote in
message news:DCAF3AB4-1BE1-428B-8F28-9A1A98A1A214@microsoft.com...
> 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
>
> "Scott McChesney" wrote:
>
> > 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
> >
> >
> >



Re: Window subclassing and mouse events by Claes

Claes
Thu Dec 02 03:57:16 CST 2004

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


"Scott McChesney" <scott.mcchesneyNOSPAM@us.army.mil> wrote in message
news:ut6F7c81EHA.2156@TK2MSFTNGP10.phx.gbl...
> 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
>
>



Re: Window subclassing and mouse events by Claes

Claes
Thu Dec 02 04:01:29 CST 2004

I just tried it and that is indeed what happens

/claes

"Claes Bergefall" <claes.bergefall@online.nospam> wrote in message
news:OwelNVF2EHA.524@TK2MSFTNGP09.phx.gbl...
> 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
>
>
> "Scott McChesney" <scott.mcchesneyNOSPAM@us.army.mil> wrote in message
> news:ut6F7c81EHA.2156@TK2MSFTNGP10.phx.gbl...
> > 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
> >
> >
>
>