Hello.
I used win32 API 'SetWindowsHookEx()' to override wndproc of excel.
For the versions below office365, codes are working well.
But for office365 excel, they do not work.
I just call 'XlWndProcStart()' and simply sends a message to excel 'WM_USER+WM_USER' like below.
HWND hwnd = ::FindWindowEx(NULL, NULL, "XLMAIN", NULL);
::SendMessage(hwnd, WM_USER + WM_USER, wp, lp);
I cannot guess what is wrong.
Please Help.
Thank you.
What I have tried:
Codes are simple.
__declspec(dllexport) void XlWndProcStart(DWORD threadId)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_hHookWndProc = SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc,
(HINSTANCE)AfxGetInstanceHandle(), threadId);
if (m_hHookWndProc == NULL) {
DWORD dw = GetLastError();
TRACE("Error = %d, 0x%X\n", dw, dw);
}
}
m_hHookWndProc has Value and it means SetWindowsHookEx() succeeded.
And CallWndProc() is like below.
LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0) {
AfxMessageBox("if (nCode < 0)");
return CallNextHookEx(m_hHookWndProc, nCode, wParam, lParam);
}
PCWPSTRUCT pMsg = (PCWPSTRUCT)lParam;
switch (pMsg->message) {
case WM_USER + WM_USER:
AfxMessageBox("WM_USER + WM_USER");
break;
case WM_USER + WM_USER + 1:
AfxMessageBox("WM_USER + WM_USER + 1");
break;
case WM_CLOSE:
AfxMessageBox("XL CLOSE");
break;
default:
break;
}
return CallNextHookEx(m_hHookWndProc, nCode, wParam, lParam);
}