I am trying to get the contents of a listbox in another application. To do
that, I am trying to install a windows hook to monitor messages to the
listbox. When the user double-clicks on an item, I'd like to get the text
of the item.
Trying to use a WH_GETMESSAGE hook:
g_hGetMsgProc = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, hinst, 0);
LRESULT CALLBACK GetMsgProc(int code, WPARAM wParam, LPARAM lParam ) {
switch (pmsg->message) {
case WM_LBUTTONUP:
// log << L"\tGetMsgProc\t\tWM_LBUTTONUP" << endl;
break;
case WM_LBUTTONDBLCLK: {
int curSel = LB_ERR;
LRESULT res = LB_ERR;
TCHAR szBuf[1024];
MSG * pMsg = (MSG *) lParam;
HWND lbHwnd = pMsg->hwnd;
log << _T("\tGetMsgProc\t\tWM_LBUTTONDBLCLK") << endl;
// Sanity check
HWND parent = GetParent(lbHwnd);
GetWindowText(parent, szBuf, BUFFER_SIZE - 1);
log << _T("\t\tParent Title : ") << szBuf << _T("\tParent HWND :
") << parent << endl;
// Sanity check
GetClassName(lbHwnd, szBuf, BUFFER_SIZE - 1);
log << _T("\t\tList box class name: ") << szBuf << _T("\tList
box hwnd: ") << pMsg->hwnd << endl;
res = SendMessage(lbHwnd, LB_GETCOUNT, 0, 0);
if (LB_ERR != res) { log << _T("\t\t\tLB_GETCOUNT : ") << res <<
endl; }
curSel = SendMessage(lbHwnd, LB_GETCURSEL, 0, 0);
if (LB_ERR != curSel) {
_tcscpy(szBuf, _T("DUMMY"));
HRESULT res = SendMessage(lbHwnd, LB_GETTEXT, curSel,
(LPARAM)(LPTSTR) szBuf);
if (LB_ERR == res ) { /* log error */ }
else { log << _T("\t\tLB_GETTEXT returned : ") << res <<
_T("\t\tszBuf: ") << pBuf << endl; }
}
else { log << _T("\t\tLB_GETCURSEL returned LB_ERR") << endl; }
} // WM_LBUTTONDBLCLK
break;
default:
break;
} // switch
return CallNextHookEx(0,code,wParam,lParam);
}
The hook proc gets the WM_LBUTTONDBLCLK message. However, LB_GETCURSEL
always returns 0, and LB_GETTEXT always returns 0.
(The listbox is not multi-select.)
Is the application somehow eating the LB_* messages?
Thanks for any insights...