0

I have a property sheet with several pages. Most of the pages have one or more edit controls. Most controls are initialized not from the page dialogs but from the dialog that created the property sheet; some however are initialized in the page dialogs and they behave the same.

Everything starts out fine. One can move between the pages. None of the controls have the input focus.

If one clicks on one of the edit controls in a property sheet page establishing input focus one can modify the control. Again all seems in order.

If one then moves to a different property page, the first edit control in that page gets the input focus AND all the text in that control gets selected! This behavior applies to all the pages except one having an edit control with read only style. After that one can move back to other pages and the initial nothing selected no input focus behavior is restored.

All of the pages handle the PSN_QUERYINITIALFOCUS notification and return zero through the SetWindowLong mechanism.

Is this expected behavior?

And why isn't some control given focus initially?

My primary interest here is to somehow kill the selection. I have tried killing the selection with EM_SETSEL in the PSN_SETACTIVE notification to no avail.

The MSDN says the following under PSN_QUERYINITIALFOCUS "Otherwise, return zero and focus will go to the default control." How do I go about setting a control as default?

Mike D
  • 2,753
  • 8
  • 44
  • 77

1 Answers1

0

I find the the actions described above bizarre! I would still like to know

if they are normal.
why no control receives the focus initially.

I was able to kill the selection by adding code to the property sheet pages to handle the WM_COMMAND/EN_SETFOCUS message for any edit controls. I do not know if other controls send EN_SETFOCUS messages.

case EN_SETFOCUS:
    {
       char cn[16];
       HWND H = (HWND) lParam;
       GetClassName (H, cn, 15);
       if (strcmp (cn,"Edit") == 0)
       {
            SendMessage (H, EM_SETSEL, -1, 0);
       }
       return true;
    }                   

I presume it would be possible to save any selection in an EN_KILLFOCUS handler and restore it in the EN_SETFOCUS handler but doing so for an unknown number of controls would be tedious.

Mike D
  • 2,753
  • 8
  • 44
  • 77