Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with WH_GETMESSAGE

10 views
Skip to first unread message

Number8

unread,
Jul 29, 2009, 8:52:01 AM7/29/09
to

Hello,

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...


Thor

unread,
Oct 27, 2009, 4:15:01 PM10/27/09
to
Maybe you have a Combobox and not a listbox - LB_GETCURSEL would then return 0
0 new messages