Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with WH_CALLWNDPROCRET
    text
    copied!<p>I am trying to catch messages from an application for which I have no source code.<br> I install a Windows hook like this:</p> <pre><code>hhk = SetWindowsHookEx(WH_CALLWNDPROCRET, HookProcSetTextRet, hinst, threadID); </code></pre> <p>(The hhk variable is in shared data.)<br> I don't understand some of the behavior, though, specifically:</p> <pre><code>LRESULT CALLBACK HookProcSetTextRet(int code,WPARAM wParam,LPARAM lParam) { PCWPRETSTRUCT st = (PCWPRETSTRUCT)lParam; switch (HIWORD(st-&gt;wParam)) { case WM_COMMAND: { /* For lbn_xxx: wParam The low-order word is the list box identifier. The high-order word is the notification message. lParam Handle to the list box. */ switch (HIWORD(st-&gt;wParam)) { case LBN_DBLCLK: { log &lt;&lt; L"\tWM_COMMAND --- LBN_DBLCLK" &lt;&lt; endl; } break; case LBN_SELCHANGE: { log &lt;&lt; L"\t+++ WM_COMMAND -LBN_SELCHANGE" &lt;&lt; endl; log &lt;&lt; L"\t\tHandle to list box : " &lt;&lt; st-&gt;lParam &lt;&lt; endl; HWND lbHwnd = (HWND) st-&gt;lParam; res = SendMessage(lbHwnd, LB_GETCOUNT, 0, 0); curSel = SendMessage(lbHwnd, LB_GETCURSEL, 0, 0); log &lt;&lt; L"\t\t\tLB_GETCURSEL returned : " &lt;&lt; curSel &lt;&lt; endl; if (LB_ERR != curSel) { res = SendMessage(lbHwnd, LB_GETTEXT, curSel, (LPARAM)(LPTSTR) szBuf); log &lt;&lt; L"\t\tLB_GETTEXT returned : " &lt;&lt; res &lt;&lt; L"\t\tszBuf: " &lt;&lt; szBuf &lt;&lt; endl; } } break; default: break; } } // WM_COMMAND /* snip */ } return CallNextHookEx(0, code, wParam, lParam); } </code></pre> <p>LBN_SELCHANGE is caught, but the value returned by LB_GETCURSEL and LB_GETTEXT is always the same.<br> LBN_DBLCLK is never caught. </p> <p>There is similar inconsistnecy with other WM_ messages, as well. Is the app itself somehow eating these messages?<br> Thanks for any ideas...</p> <p>UPDATE:<br> Following a suggestion made below, I implemented a WH_GETMESSAGE hook. It appears to be getting the doubleclick message from the listbox.<br> Unfortunately, LB_GETCOUNT returns the correct number, but LB_GETCURSEL always returns 0, and LB_GETTEXT still returns nothing...</p> <pre><code> case WM_LBUTTONDBLCLK: { const unsigned int BUFFER_SIZE = 1024; wchar_t titleBuffer[BUFFER_SIZE]; UINT curSel = LB_ERR; LRESULT res = LB_ERR; MSG * pMsg = (MSG *) lParam; HWND lbHwnd = pMsg-&gt;hwnd; log &lt;&lt; L"\tGetMsgProc\t\tWM_LBUTTONDBLCLK" &lt;&lt; endl; // Sanity check HWND parent = GetParent(lbHwnd); GetWindowText(parent, titleBuffer, BUFFER_SIZE - 1); log &lt;&lt; L"\t\tParent Title : " &lt;&lt; titleBuffer &lt;&lt; L"\tParent HWND : " &lt;&lt; parent &lt;&lt; endl; // Sanity check GetClassName(lbHwnd, titleBuffer, BUFFER_SIZE - 1); log &lt;&lt; L"\t\tList box class name: " &lt;&lt; titleBuffer &lt;&lt; L"\tList box hwnd: " &lt;&lt; pMsg-&gt;hwnd &lt;&lt; endl; res = SendMessage(lbHwnd, LB_GETCOUNT, 0, 0); if (LB_ERR != res) { log &lt;&lt; L"\t\t\tLB_GETCOUNT : " &lt;&lt; res &lt;&lt; endl; } curSel = SendMessage(lbHwnd, LB_GETCURSEL, 0, 0); log &lt;&lt; L"\t\t\tLB_GETCURSEL returned : " &lt;&lt; curSel &lt;&lt; endl; if (LB_ERR != curSel) { res = SendMessage(lbHwnd, LB_GETTEXT, curSel, (LPARAM)(LPTSTR) titleBuffer); if (LB_ERR == res ) { log &lt;&lt; L"\t\t\tLB_GETTEXT Error -- invalid index" &lt;&lt; endl; } else { log &lt;&lt; L"\t\tLB_GETTEXT returned : " &lt;&lt; res &lt;&lt; L"\t\tszBuf: " &lt;&lt; titleBuffer &lt;&lt; endl; } } else { log &lt;&lt; L"\t\tLB_GETCURSEL returned LB_ERR" &lt;&lt; endl; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload