PDA

View Full Version : Questions About Focus



gungadout
11-11-2010, 08:24
Hi Folks,

I have two questions about focus.

1. %EN_SETFOCUS not triggered.

When I first display a window, as I would expect, unless I issue a Control Set Focus command, none of the text boxes receives focus. If I issue the Control Set Focus command for a text box, the cursor starts blinking in that box and typing is permitted, but %EN_SETFOCUS seems not to be triggered.

If I don't issue the Control Set Focus command, but click on the text box to get focus, the %EN_SETFOCUS is triggered.

Is that the way it is supposed to happen?

How can I ensure that the %EN_SETFOCUS is triggered (if indeed it is not being)?

2. Loss and regain of window focus.

When the window loses focus then regains it (e.g. by clicking on the task bar icon), the text box that was already in focus has another %EN_SETFOCUS generated for it. This seems to be illogical, because the text box always had focus within the window; it was the overall window that lost focus.

The resulting problem is that sometimes %EN_SETFOCUS processing involves unrepeatable logic (say, incrementing an auditable control number, as a poor but simple example). So the multiple issuing of the %EN_SETFOCUS status could be troubling.

I guess I need to record the control that has current focus, and ignore any subsequent %EN_SETFOCUS statuses issued for that control.

Or is there a more elegant solution?

Regards,

Peter H.

ErosOlmi
11-11-2010, 11:11
A preliminar question: how do you create your main window? MODAL or MODELESS?

If MODAL, it will have automatic behave driven by Windows. Modal windows are like message box windows.

If MODELESS, you will have more precise control and more precise events will occur.

Ciao
Eros

gungadout
12-11-2010, 03:44
Hi Eros,

The window is created MODAL.

It needs to be MODAL because the menu window that activates it must remain inactive until the invoked dialog window is destroyed.

So I'll just have to live with whatever Windows decides to throw at me, and learn how to construct the necessary work-arounds.

I assume that the solution I have in mind for Problem 2 is practical, unless you or someone can suggest a better idea.

To overcome Problem 1, I guess I could move my %EN_SETFOCUS logic to a separate function and call that function whenever %EN_SETFOCUS is entered. Then, after triggering the first Control Set Focus action, I could send a command to discretely trigger the associated %EN_SETFOCUS function logic. (In the absence of a more elegant method, that is.)

(I have yet to test whether or not Control Set Focus triggers %EN_SETFOCUS as a general case. If %EN_SETFOCUS is not so triggered, my above solution could be used to handle that situation as well.)

Thanks for your help,

Peter H.