views:

281

answers:

2

My app runs as a plugin inside another windowed app. Thus, my window often doesn't have the focus. Now, if someone moves the mouse over a button/menu and clicks once, all it does is set focus to my window. Then (s)he needs to click again to get the actual button functionality.

This is a minor annoyance but I'd like to get rid of it. First I tried claiming focus whenever the mouse enters my dialog space, but this proved to be even more annoying. So what I'd like to do is repeat the mouse click, so it looks as though a single click both changed focus AND pressed the button.

Obviously I should ONLY do this when the click resulted into a SetFocus, otherwise it will run the button function twice.

Any suggestions?

Deeply and eternally indebted, David

+1  A: 

I would suggest that you keep the behavior as is; this is standard behavior for the operating system and changing it could break standard usability guidelines.

Randolpho
Point taken, I do not like to depart from UI conventions either, but the conventional behaviour *is* annoying.
David Rutten
+1  A: 

Mouse click simulation seems a little messy here, but you can always simulate any mouse click at any (X,Y) via the SendInput API through P/Invoke:

[DllImport("user32.dll", SetLastError=true)]
static extern uint SendInput(uint nInputs, INPUT [] pInputs, int cbSize);

You can also fiddle around with propagating/generating WM_MOUSEXXXXX messages directly but I've played with this a lot and believe me when I say it's a total kludge.

James D
Thanks, I'll experiment with these.
David Rutten