|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Block WM_MOUSEACTIVATE messagesI am developping an application (using C#) and I need, whenever the user click on the form, this one not to be activated. (the system mustn't give the focus to the form). After several search I saw a way : overriding the WndProc (wich belongs to form class) and replace the WM_MOUSEACTIVATE message with WM_NULL message. Here is the sample of code : //Override wndProc method [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] protected override void WndProc(ref Message m) { if (m.Msg == WM_MOUSEACTIVATE) { m = Message.Create(new IntPtr(0), 0, new IntPtr(0), new IntPtr(0)); } base.WndProc(ref m); } But this doesn't work, am I in the wrong way, is there any other messages... ? Thanks for your answer. Check out the following article on the WM_MOUSEACTIVATE message. According
to this article, you need to return one of the following return values: MA_ACTIVATE Activates the window, and does not discard the mouse message. MA_ACTIVATEANDEAT Activates the window, and discards the mouse message. MA_NOACTIVATE Does not activate the window, and does not discard the mouse message. MA_NOACTIVATEANDEAT Does not activate the window, but discards the mouse message. http://msdn2.microsoft.com/en-us/library/ms645612.aspx -- Show quoteHTH, Kevin Spencer Microsoft MVP Virtual Carpenter http://unclechutney.blogspot.com Never trust a dunderhead with a blunderbuss. "ai***@intechinfo.fr" <aimozintechinf***@discussions.microsoft.com> wrote in message news:19D575EF-98A4-4E8D-90C0-75745ACB53EB@microsoft.com... > Hello, > > I am developping an application (using C#) and I need, whenever the user > click on the form, this one not to be activated. (the system mustn't give > the > focus to the form). > > After several search I saw a way : overriding the WndProc (wich belongs to > form class) and replace the WM_MOUSEACTIVATE message with WM_NULL message. > Here is the sample of code : > > //Override wndProc method > [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, > Name = "FullTrust")] > protected override void WndProc(ref Message m) > { > if (m.Msg == WM_MOUSEACTIVATE) > { > m = Message.Create(new IntPtr(0), 0, new IntPtr(0), new > IntPtr(0)); > } > > base.WndProc(ref m); > } > > But this doesn't work, am I in the wrong way, is there any other > messages... ? > > Thanks for your answer. Thanks for your answer, but i've already saw this article and i don't
understand what is the return value of a notification. Do you have a sample of code ? Thanks in advance. Try this:
internal const uint WM_MOUSEACTIVATE = 0x21; internal const uint MA_NOACTIVATEANDEAT = 4; protected override void WndProc(ref System.Windows.Forms.Message m) { if (m.Msg == WM_MOUSEACTIVATE) { m.Result = (IntPtr)MA_NOACTIVATEANDEAT; }else base.WndProc(ref m); } HTH Ciaran O'Donnell Show quote "ai***@intechinfo.fr" wrote: > Hello, > > I am developping an application (using C#) and I need, whenever the user > click on the form, this one not to be activated. (the system mustn't give the > focus to the form). > > After several search I saw a way : overriding the WndProc (wich belongs to > form class) and replace the WM_MOUSEACTIVATE message with WM_NULL message. > Here is the sample of code : > > //Override wndProc method > [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] > protected override void WndProc(ref Message m) > { > if (m.Msg == WM_MOUSEACTIVATE) > { > m = Message.Create(new IntPtr(0), 0, new IntPtr(0), new > IntPtr(0)); > } > > base.WndProc(ref m); > } > > But this doesn't work, am I in the wrong way, is there any other messages... ? > > Thanks for your answer. I've tried your code but it's the same, the window get the focus after a click.
Is there another message which activate the window ? Thanks in advance. Here's the complete Windows API Mouse Input reference:
http://msdn2.microsoft.com/en-us/library/ms674720.aspx Also, a nice web site about using pinvoke: http://www.pinvoke.net/index.aspx -- Show quoteHTH, Kevin Spencer Microsoft MVP Virtual Carpenter http://unclechutney.blogspot.com Never trust a dunderhead with a blunderbuss. "ai***@intechinfo.fr" <aimozintechinf***@discussions.microsoft.com> wrote in message news:E9A009B8-4692-44F4-A12B-6E935B52F99E@microsoft.com... > I've tried your code but it's the same, the window get the focus after a > click. > Is there another message which activate the window ? > > Thanks in advance. Basically MA_NOACTIVATEANDEAT or MA_NOACTIVATE are what you need, but
notice that the choices are different between forms and controls. To my knowledge, if the form is expected to be always inactivated but still functional, for example, dragging to move, MA_NOACTIVATE is required. For a control such as the button, however, MA_NOACTIVATEANDEAT is better because MA_NOACTIVATE still propagate WM_NCACTIVATE and WM_ACTIVATE to its parent container. It is really a bad news that MA_NOACTIVATEANDEAT will also disable some mouse down/click event like "pushed button" visual effect. /Mike T. J. Jiang/ Ciaran O''Donnell ¼g¹D¡G Show quote > Try this: > internal const uint WM_MOUSEACTIVATE = 0x21; > internal const uint MA_NOACTIVATEANDEAT = 4; > protected override void WndProc(ref System.Windows.Forms.Message m) > { > if (m.Msg == WM_MOUSEACTIVATE) > { > m.Result = (IntPtr)MA_NOACTIVATEANDEAT; > }else > base.WndProc(ref m); > } > > HTH > > Ciaran O'Donnell > |
|||||||||||||||||||||||