Tech Support > Microsoft Windows > Development Resources > Please Help Me Get Hooks Working.
Please Help Me Get Hooks Working.
Posted by Larry Lindstrom on May 10th, 2007


Hi Folks:

Developing with XP Media Edition, VC6, WIN32, no MFC.

This is a second request for help from the Win32 group,
and a first request from the UI group.

A year ago I attempted to get tabs working in some modeless
child dialogs, and had to give up. Now I'd like to try again.

This is my first MDI application. I'm a big believer in
using the Resource editor to lay out dialogs.

As I understand it, MDI children don't lend themselves to
being laid out with the resource editor. So the MDI children's
WM_CREATE call CreateDialogParam() to invoke a modeless child
dialog that will be sized to fit into the client area of the MDI
child, and is laid out with the Resource Editor.

So I lay out a simple test dialog, with a line of static text
and two buttons, to serve as a child of the MDI children.

Before attempting to set any hooks, this dialog is displayed
as desired, with the static text and the two buttons on the
typical gray background. The tab button seems to have no effect.

I attempt to implement a hook, and the dialog is now white,
with no controls visible.

Here is what I've done:

In the modeless dialog children dialog proc I've added the
following to the WM_INITDIALOG trap:

switch (message)
{
case WM_INITDIALOG:

global_active_test_modeless_dialog_handle = hdlg;

global_test_modeless_dialog_hook_handle =
SetWindowsHookEx(WH_GETMESSAGE,
test_message_hook_proc,
NULL, GetCurrentThreadId());


This is in the dialog proc's WM_DESTROY trap:

case WM_DESTROY:
global_active_test_modeless_dialog_handle = NULL;

if(global_test_modeless_dialog_hook_handle != NULL)
{
UnhookWindowsHookEx(
global_test_modeless_dialog_hook_handle);
}


The C++ module for the modeless dialog child has this definition of
test_message_hook_proc:

LRESULT CALLBACK test_message_hook_proc(int code, WPARAM wparam,
LPARAM lparam)
{
LRESULT return_val = 0;

if(code!=HC_ACTION)
{
return_val = CallNextHookEx(
global_test_modeless_dialog_hook_handle,
code,
wparam,
lparam);
}
else
{
if(wparam != PM_NOREMOVE)
{
if((global_active_test_modeless_dialog_handle != NULL) &&
(IsDialogMessage(
global_active_test_modeless_dialog_handle,
(MSG *)lparam)))
{
((MSG *)lparam)->message = WM_NULL;
}
}

return_val = CallNextHookEx(
global_test_modeless_dialog_hook_handle, code,
wparam, lparam);
}

return return_val;
}

The message loop in the app's WinMain:

while (GetMessage (&msg, NULL, 0, 0))
{
bool pass_to_translate = true;

if(global_active_list_modeless_dialog_handle != NULL)
{
pass_to_translate = false;
}

if (!TranslateMDISysAccel (hwndClient, &msg) &&
!TranslateAccelerator (hwndFrame, hAccel, &msg))
{
if(pass_to_translate)
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
}
}

Moving the "if(pass_to_translate)" to embrace the
TranslateMDISysAccel() clause had no effect.

I've added processing for WM_GETDLGCODE, DM_GETDEFID and
DM_SETDEFID message processing to the modeless child.

A breakepoint in the DM_GETDEFID trap shows that message is
being received, and I've tried returning

MAKELPARAM(IDOK, DC_HASDEFID)

with no effect. Returning 0 also has no effect.

The dialog then comes up blank, as before, and the
WM_GETDLGCODE message is never received by the modeless child.

Any suggestins?

Thanks
Larry

Posted by aleksa on May 11th, 2007


Yes, the link below

Seriously, you have complicated it too much,
all I can say is give GWH a try.

--
Generic Window Handler - easy dialogs & MDI - no MFC
www.beotel.net/~gwh


Posted by news@rtrussell.co.uk on May 11th, 2007


On May 10, 7:58 pm, Larry Lindstrom <nob...@aracnet.com> wrote:
Why are you using MDI if all you want is tabs? Won't a Tab Control or
a Property Sheet do it much more easily?

http://msdn2.microsoft.com/en-us/library/ms650933.aspx
http://msdn2.microsoft.com/en-us/library/ms652415.aspx

Richard.
http://www.rtrussell.co.uk/
To reply by email change 'news' to my forename.


Posted by Larry Lindstrom on May 11th, 2007


aleksa wrote:
Thanks Aleska:

I appreciate your advice, but I have another application with
modeless popup dialogs, which also won't recognize tab stops.

So I need to understand hooks.

Thanks
Larry

Posted by Larry Lindstrom on May 11th, 2007


news@rtrussell.co.uk wrote:
Thanks Richard:

I'm trying to learn MDI so I can build an application that
has an MDI interface. I'd like to try an application with
child dialogs that are contained inside the application's
client area, like the child windows in Word. There are some
other features of the MDI interface that also seem interesting.

The issue isn't tab controls, it's tab stops. I've had
another application with a bunch of modeless dialogs, which
ignored the tab key once one was selected. Getting hooks
working here will help me get hooks working there.

Now that I'm building an MDI application, and the MDI
clients have modeless children of their own, these children
being laid out with the Resource editor, the tab key is
again ignored.

I appreciate your suggestions.

Thanks
Larry

Posted by news@rtrussell.co.uk on May 11th, 2007


On May 11, 5:46 pm, Larry Lindstrom <nob...@aracnet.com> wrote:
The tab key being ignored is often a symptom of not calling
IsDialogMessage in your message loop. That's definitely where I would
look first, rather than any possible interaction with MDI.

Richard.
http://www.rtrussell.co.uk/
To reply by email change 'news' to my forename.



Similar Posts