![]() |
Does simulating click affect GetMessagePos()?
I want to select one item of CTreeCtrl by sending message
WM_LBUTTONDOWN to it, but the CTreeCtrl's message processing function uses API GetMessagePos() to fetch the last message's position which is always not the one corresponding to my simulating WM_LBUTTONDOWN. The CTreeCtrl's message processing function further uses CTreeCtrl::HitTest() to check whether that item was clicked, and inevitably HitTest() returns NULL. My code is as follows: Code:
POINT ap={0x0027, 0x0289}, cp={0x0025, 0x00AE};I have used SetCursorPos() to check them. And I have also tried the following code to activate the tree item, yet it was selected but not activated(its corresponding code was not executed): Code:
SendMessage((HWND)hTreeView, TVM_SELECTITEM, TVGN_CARET, hLstRetract);simulating message, it only returns the position of the last physical message say one actual click. Does anyone have an idea to defeat GetMessagePos()? Thank you. |
It seems that no one has encountered such a problem.
Yesterday, I resorted to patch the message processing function so that it can accept the item selected by my simulating message: Code:
extern "C" __declspec(naked) void hook_tc(void)I cannot defeat that damn GetMessagePos(). |
Hi BlackWhite,
I found your question rather interesting so I decided to spend some time on it. First of all, do not forget to set the focus to the tree control, before sending the message, else no selection is performed! Next, you can have 4 cases (note that in all 4 cases the simulated selection works, in the sense that the wanted item is highlighted): (1) send message without setting the cursor: Code:
hTreeView.SetFocus();(2) send message preceeded by set cursor: Code:
hTreeView.SetFocus();(3) post message without setting the cursor Code:
hTreeView.SetFocus();(4) post message preceeded by set cursor: Code:
hTreeView.SetFocus();Best regards bilbo |
Hi, bilbo. Thank you for your experiments.
But I found that SetFocus() did not work in my case, GetMessagePos() still returned the wrong value. Code:
SetFocus((HWND)hTreeView);hTreeView, and the message being processed is WM_NOTIFY, here is the code for processing WM_NOTIFY: Code:
0442D470 83EC 08 sub esp, 8 |
As I showed you, GetMessagePos does not work with SendMessage, but only with PostMessage.
In fact the GetMessagePos function retrieves the cursor position for the last message retrieved by the message queue, but SendMessage does not put the message on the queue. Best regards bilbo |
Quote:
Will you please try intercepting WM_NOTIFY in message processing instead of WM_LBUTTON ? Thank you. |
I now see your problem: you must not intercept the first WM_NOTIFY which arrives, with notify code NM_CLICK (0xFFFFFFFE), but the following WM_NOTIFY, with notify code TVN_SELCHANGED (0xFFFFFE6E in ascii version, 0xFFFFFE3D in Unicode version)!
Best regards bilbo |
Quote:
instead of NM_CLICK, but that program was not written by myself. It stubbornly sticks to NM_CLICK. I have done several experiments to defy GetMessagePos(), but got no success: Experiment1: It did not trigger the WM_NOTIFY event processing. And if I change hWnd to hTreeView itself instead of its father, the result is the same. Code:
POINT ap={0x0027, 0x0289}, cp={0x0025, 0x00AE};but GetMessagePos() got the wrong coordinates. Code:
POINT ap={0x0027, 0x0289}, cp={0x0025, 0x00AE};Code:
TV_ITEM ti;why Experiment3 failed: Code:
73D322C3 FF75 08 push dword ptr [ebp+8]contain an item related to TVN_SELCHANGED. So I have fallen into a dilemma. If I PostMessage(WM_LBUTTON), that will not trigger WM_NOTIFY's processing; If I SendMessage(WM_NOTIFY), that program gets the wrong coordinates. Do you have any good idea to defeat that damn program? |
I finally figure out why WM_LBUTTON does not trigger message processing of WM_NOTIFY. WM_NOTIFY should be simulated by posting two messages:
WM_LBUTTONDOWN WM_LBUTTONUP Here is the code: Code:
POINT ap={0x0027, 0x0289}, cp={0x0025, 0x00AE};If I substitute SendMessage() for PostMessage(), the above code will not work. So, I'm much indebted to bilbo. |
Nice trick, BlackWhite, to put a WM_LBUTTONUP message in the message queue too!
This way both notifications (TVN_SELCHANGED and NM_CLICK) now work! Best regards bilbo |
Try this one, it simulates an actual click, in combination with SetMousePos you can click anywhere:
Code:
void LeftClick() |
| All times are GMT +8. The time now is 21:48. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX