loosing messages leakes my app...
hello everyone...
i have a htread-aware ctrl-class that posts commands from other
threads automatically to the gui-thread before executing them. looks
like this:
//-----------------------------------------------------------------------------
// prepares a message
bool CQControl::_GUIPost(QUAD qMsg, PCVOID pMsg, DWORD dwLen) const {
SQMsgBlock* pMB = NULL;
try {
pMB = new SQMsgBlock;
pMB->dwLen = dwLen;
if (dwLen == NULL)
pMB->ptBlock = NULL;
else {
pMB->ptBlock = malloc(dwLen);
memcpy(pMB->ptBlock, pMsg, dwLen);
}
pMB->qType = qMsg;
pMB->hReturn = 0;
if (_GUIPost(pMB))
return true;
_GUIPostDelete(pMB);
return false;
} catch (...) {
_GUIPostDelete(pMB);
return false;
}
}
//-----------------------------------------------------------------------------
// post a message to the GUI-thread or execute it if called from GUI-
thread
bool CQControl::_GUIPost(SQMsgBlock* pMB) const {
if (AfxGetThread() == _GUI()) {
// we are the GUI-thread, so we call receicve-fn directly...
const_cast<CQControl&>(*this)._GUIReceived(pMB);
return false; // delete block
}
if (_HWND() == 0)
return false;
pMB->hControl = _HWND();
return (::PostMessage(_HWND(), WM_QWCOMMAND, 0, (LPARAM) pMB) != 0);
}
//-----------------------------------------------------------------------------
// delete and free a Msg-Block
void CQControl::_GUIPostDelete(SQMsgBlock* pMB) {
if (pMB == NULL)
return;
free(pMB->ptBlock);
delete pMB;
}
//-----------------------------------------------------------------------------
// returns true if GUIPost received
bool CQControl::QPreTranslateMessage(MSG* pMsg) {
if (pMsg == NULL)
return false;
if (pMsg->message != WM_QWCOMMAND)
return false;
SQMsgBlock* pMB = reinterpret_cast<SQMsgBlock*>(pMsg->lParam);
_GUIReceived(pMB);
_GUIPostDelete(pMB);
return true;
}
in the CWnd, the fn PreTranslateMessage() calls QPreTranslateMessage()
to catch my commands; all runns fine exept that i still have some
leaks, so even if ::PostMessage() returns that the message was posted,
it never gets to the PreTranslateMessage() of the ctrl.
So the question is: is there an application-wide PreTranslateMessage()
for the GUI-Thread that i can override to dispatch certain messages
myself?