Re: SendMessage WM_NOTIFY across process
I make no apologies for the tattiness of my code I just wanted the
mechanism to work and tried lot's
of things out. Anyhow, I decided to redouble my efforts and have found
out exactly why this doesn't work.
Examining the call stack you can see that CWnd::OnNotify the first
parameter has value 0x000001aa.
This is the window's ID (426 decimal). In the next call to CMainFrame
this has morphed into an nID
parameter of 0x00003c38.
mfc71d.dll!AfxFindMessageEntry(const AFX_MSGMAP_ENTRY * lpEntry=0x00426028, unsigned int nMsg=0x0000004e, unsigned int nCode=0x0000fffe, unsigned int nID=0x00003c38) Line 1659 C++
mfc71d.dll!CCmdTarget::OnCmdMsg(unsigned int nID=0x00003c38, int
nCode=0x0000fffe, void * pExtra=0x0013fb74, AFX_CMDHANDLERINFO *
pHandlerInfo=0x00000000) Line 383 + 0x18 C++
mfc71d.dll!CFrameWnd::OnCmdMsg(unsigned int nID=0x00003c38, int
nCode=0x004efffe, void * pExtra=0x0013fb74, AFX_CMDHANDLERINFO *
pHandlerInfo=0x00000000) Line 897 + 0x18 C++
WmNotify.exe!CMainFrame::OnCmdMsg(unsigned int nID=0x00003c38, int
nCode=0x004efffe, void * pExtra=0x0013fb74, AFX_CMDHANDLERINFO *
pHandlerInfo=0x00000000) Line 170 C++
mfc71d.dll!CWnd::OnNotify(unsigned int __formal=0x000001aa, long
lParam=0x00037970, long * pResult=0x0013fc70) Line 2576 C++
mfc71d.dll!CWnd::OnWndMsg(unsigned int message=0x0000004e, unsigned
int wParam=0x000001aa, long lParam=0x00037970, long *
pResult=0x0013fca4) Line 1771 + 0x28 C++
mfc71d.dll!CWnd::WindowProc(unsigned int message=0x0000004e,
unsigned int wParam=0x000001aa, long lParam=0x00037970) Line 1745 +
0x1e C++
This is the reason why:
BOOL CWnd::OnNotify(WPARAM, LPARAM lParam, LRESULT* pResult)
{
ASSERT(pResult != NULL);
NMHDR* pNMHDR = (NMHDR*)lParam;
HWND hWndCtrl = pNMHDR->hwndFrom;
// get the child ID from the window itself
UINT_PTR nID = _AfxGetDlgCtrlID(hWndCtrl);
OnNotify ignores the NMHDR.idFrom field and instead recalculates it
from _AfxGetDlgCtrlID(hWndCtrl).
Now the hWndFrom that I passed was from my MainFrame window so the ID
becomes that of my MainFrame
window and not the control.
I think some of you hinted at this. The HWND and ID should both tie
up.
Breaking out a WM_NOTIFY message in the command map looks like this:
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo)
{
TRACE(_T("HIWORD(nCode) = %x\n"), HIWORD(nCode));
TRACE(_T("LOWORD(nCode) = %x\n"), LOWORD(nCode));
TRACE(_T("WM_NOTIFY = %x\n"), WM_NOTIFY);
TRACE(_T("NM_CLICK = %x\n"), NM_CLICK);
// TODO: Add your specialized code here and/or call the base class
if ( (HIWORD(nCode) == WM_NOTIFY) && (LOWORD(nCode) ==
LOWORD(NM_CLICK)) )
{
CString str;
str.Format(_T("nID = %ld, nCode = %ld\n"), nID, nCode);
TRACE(str);
}
return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
You have to do LOWORD(nCode) == LOWORD(NM_CLICK) because
only the low word of NM_CLICK (defined as 0xFFFFFFFE) is placed into
nCode.
As an aside it appears impossible to write a program where the
mainframe notifies itself
(*VIA STATIC MAP ENTRIES*) as the Mainframe's ID is decided at run-
time.
Well, I said I was trying something arcane out. Now to get back to
looking at RemoteSendMessage API or whatever
it's called.