INFO: Do Not Forward DDEML Messages from a Hook ProcedureLast reviewed: January 12, 1998Article ID: Q89828 |
The information in this article applies to:
SUMMARYIf an application for Windows uses the Dynamic Data Exchange Management Library (DDEML) in addition to a message hook [for example, by calling SetWindowsHook() or SetWindowsHookEx()], it is possible that your hook procedure will receive messages that are intended for the DDEML libraries. For the DDEML libraries to work properly, you must make sure that your hook function does not forward on any messages that are intended for the DDEML libraries.
MORE INFORMATIONIf your hook procedure receives a code of type MSGF_DDEMGR, you should return FALSE instead of calling the CallNextHookEx() function. Use the following code to handle this situation:
// This needs to be defined if you haven't already. #ifndef MSGF_DDEMGR #define MSGF_DDEMGR 0x8001 #endif if (MSGF_DDEMGR == code) return FALSE; else { ... }In cases where the callback function processes the message, it should return TRUE. Note, however, how the message filter function is called from within DDEML:
while (TimeOutHasntExpired) { GetMesage (&msg, (HWND)NULL, 0, 0); if ( !CallMsgFilter (&msg, MSGF_DDEMGR)) DispatchMessage (&msg); }Given this, a callback function that just returns would cause the CallMsgFilter() call above to return TRUE, and never dispatch the message. This inevitably causes an infinite loop in the application, because GetMessage() ends up retrieving the same message over and over, without dispatching it to the appropriate window for processing. Therefore, a callback function that processes the message may not just return TRUE, but should also translate and dispatch messages appropriately. The Windows 3.1 SDK's DDEMLCL sample demonstrates how to do this correctly in its MessageFilterProc() found in DDEMLCL.C:
if (nCode == MSGF_DDEMGR) { /* * If a keyboard message is for MDI, let MDI client take care of it. * Otherwise, check to see if it is a normal accelerator key. * Otherwise, just handle the message as usual. */ if ( !TranslateMDISysAccel (hWndMDIClient, lpmsg) && !TranslateAccelerator (hWndFrame, hAccel, lpmsg)) { TranslateMessage (lpmsg); DispatchMessage (lpmsg); } return 1; }For more information about message hooks and DDEML, please see the above mentioned functions in the Windows SDK manual or the online help facility.
|
Additional query words: 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |