Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ATL Dialog Template - Modal/Modeless Tab Stop Behaviour

46 views
Skip to first unread message

Vladislav Dubov

unread,
Feb 22, 2001, 3:09:06 AM2/22/01
to
I created a simple dialog class using the ATL object wizard. When I open it
as a modal dialog box in my program by using the DoModal() member function,
I can move between controls by pressing the TAB key. When I open it as a
modeless window, I can't. I cannot capture any of the WM_KEY... messages
either.

Does anyone know why this happens? Hope someone cam help.

Kind regards,

Vladislav Dubov


Mike Ryan

unread,
Feb 22, 2001, 11:52:32 AM2/22/01
to

I belive your message map needs to handle the IsDialogMessage function...
Like so:

MSG msg;
while (::GetMessage(&msg, NULL, 0, 0))
{
if (!::IsDialogMessage(hYourDialogHwnd, &msg))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}

Note that if IsDialogMessage returns true then you should not process the
message as it has already been done by the IsDialogMessage function.


"Vladislav Dubov" <du...@alliedpickfords.ru> wrote in message
news:eiqeWZKnAHA.1916@tkmsftngp04...

Vladislav Dubov

unread,
Feb 23, 2001, 12:04:58 AM2/23/01
to
Thank you for the advice. I also posted this message in the
microsoft.public.vc.atl newsgroup. Igor Tandetnik pointed me to KB Article
Q187988 "PRB: ActiveX Control Is the Parent Window of Modeless Dialog". I
followed the pattern laid out in the article and installed a WH_GETMESSAGE
hook in my dialog class. The hook procedure is as follows.

static LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM
lParam)
{
LPMSG lpMsg = (LPMSG) lParam;
LRESULT lResult = 0;

if( (nCode >= 0) &&
PM_REMOVE == wParam &&
(lpMsg->message >= WM_KEYFIRST && lpMsg->message <= WM_KEYLAST))
{
if (! ::IsDialogMessage(pThis->m_hWnd, (LPMSG)lParam))
{
::TranslateMessage((LPMSG)lParam);
::DispatchMessage((LPMSG)lParam);
}
else
{
lpMsg->message = WM_NULL;
lpMsg->lParam = 0L;
lpMsg->wParam = 0;
}
}

return ::CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
}

It was not until I read your message that I could get the above procedure
working! The sample code in the KB article is based on MFC and is using the
PreTranslateMessage member function of the CWinApp class. I suppose
internally it expands to something similar to the code portion inside the
outer 'if' statement.

The only question I have now is whether installing a message-intercepting
hook procedure is the only solution to the problem of modeless dialog boxes
not owning the message pump by default?

Thank you for all your help.

with best regards,

Vladislav Dubov


Mike Ryan <mi...@codexia.com> wrote in message
news:Ofd95#OnAHA.1828@tkmsftngp03...

Alexander Nickolov

unread,
Feb 23, 2001, 2:19:32 PM2/23/01
to
You are wrong about MFC :)... MFC doesn't support modal dialogs
altogether. It emulates them via modeless dialogs. That's why
there's PreTranslateMessage in MFC dialogs...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnic...@geocities.com
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

"Vladislav Dubov" <du...@alliedpickfords.ru> wrote in message

news:eopgIXVnAHA.1396@tkmsftngp05...

0 new messages