PRB: OFNHookProcOldStyle Doesn't Set Keyboard Focus By Default

ID: Q166251

The information in this article applies to:

SYMPTOMS

Keyboard inputs generate a system beep instead of affecting an old-style File Open dialog box that has a hook procedure installed.

CAUSE

When you use a hook procedure with an old-style File Open dialog box, the keyboard focus is not set by default. Since the focus is not set to a valid control, keyboard input is disabled and generates a system beep.

RESOLUTION

To prevent this behavior, an application should manually set the focus for the File Open dialog box. This can be accomplished by handling the WM_INITDIALOG message in the old-style hook procedure:

   UINT APIENTRY HookProcOldStyle(HWND hDlg,
                                 UINT uMsgId,
                                 WPARAM wParam,
                                 LPARAM lParam)
   {
      switch (uMsgId){
          // WPARAM of this message contains the handle of the control
          // to receive focus.
          case WM_INITDIALOG:
              SetFocus((HWND)wParam);
              return 1;
          ...
          default:
              return 0;
      }
   }

Additional query words:
Keywords          : kbHook kbNTOS kbGrpUser kbWinOS 
Issue type        : kbprb

Last Reviewed: December 26, 1998