views:

690

answers:

1

Hi, i have a WPF application that i would like to become the current focused window whenever the mouse cursor moves over it. Currently i have a onMouseEnter event that changes the cursor when the mouse moves over it so i know the system is recognizing that, however what i actually want is for the application itself to become focused as if the used had left clicked on it - so i can then perform other ops. At the moment if i move over it the cursor changes but if another app, eg - notepad had focus, focus would return to that after.

Within the onMouseEnter handler i have tried "this.Focus()" and "this.Activate()" but neither of them achive the same result as if i had clicked on the app.

Any ideas?

A: 

Edit: Posted answer will not work for WPF. Sorry.

Try looking at this instead for WPF: http://blogs.msdn.com/nickkramer/archive/2006/03/18/554235.aspx

Richard Hein
thanks Auxon, do you have any examples on how i would do this? and where is this done, in the event handler?
Grant
There is the SO question I just added via edit, and maybe http://dotnet.sys-con.com/node/39039. I tried finding something closer to your issue, but haven't found anything yet. Still looking.
Richard Hein
Thanks. appreaciated.
Grant
Sorry Grant, you need to do something different with WPF. It sounds possible though. Your WPF application will start receiving messages whenever the mouse moves over it. To find out exactly which messages are fired, you can use Spy++ in the Visual Studio tool set. I think the message you want to intercept is WM_HOVER. If you use the sample in the link above, and just intercert WM_HOVER instead, and try to activate the form then, you may have a better result.
Richard Hein
The message is WM_MOUSEHOVER = 0x02A1
Richard Hein
Sorry, normally I would try out stuff before posting, but I am downloading and installing VS 2010 Beta 1. :-/
Richard Hein
thanks Auxon. good luck with 2010 :).
Grant