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();
::SendMessage((HWND)hTreeView, WM_LBUTTONDOWN, MK_LBUTTON, cp.y<<16 | cp.x);
GetMessagePos() KO, GetCursorPos() KO, HitTest() KO
(2) send message preceeded by set cursor:
Code:
hTreeView.SetFocus();
SetCursorPos(screen.x, screen.y);
::SendMessage((HWND)hTreeView, WM_LBUTTONDOWN, MK_LBUTTON, cp.y<<16 | cp.x);
GetMessagePos() KO, GetCursorPos() OK, HitTest() KO
(3) post message without setting the cursor
Code:
hTreeView.SetFocus();
::PostMessage((HWND)hTreeView, WM_LBUTTONDOWN, MK_LBUTTON, cp.y<<16 | cp.x);
GetMessagePos() OK, GetCursorPos() KO, HitTest() OK
(4) post message preceeded by set cursor:
Code:
hTreeView.SetFocus();
SetCursorPos(screen.x, screen.y);
::PostMessage((HWND)hTreeView, WM_LBUTTONDOWN, MK_LBUTTON, cp.y<<16 | cp.x);
GetMessagePos() OK, GetCursorPos() OK, HitTest() OK
Best regards
bilbo