문제

I am using below code in my application's view on particular event to simulate a left mouse click.

SendMessage(WM_LBUTTONDOWN); 
SendMessage(WM_LBUTTONUP);

Once this code executed a mouse drag view appears. How to avoid this drag view after simulating the mouse click?

When I monitored via SPY++ I got the both messages are sent like below,

WM_LBUTTONDOWN fwKeys: MK_LBUTTON xPos : 752 yPos:85

WM_BUTTONUP fwKeys:0000 xPos:752 yPos 85

I suspect the WM_LBUTTONUP message not sent properly. What is the fwKeys : 0000 indicates? Is there any think wrong in sendMessage of WM_LBUTTON up in the above code?

도움이 되었습니까?

해결책

First of all, if that is your real code, you are "simulating" the mouse click improperly. There's more to a WM_LBUTTONDOWN or WM_LBUTTONUP than the message itself: there's data packed in the wParam and lParam values of the message.

You could easily see that if you had taken a second to look at the MSDN pages for WM_LBUTTONDOWN and WM_LBUTTONUP. They describe exactly what the wParam and lParam values mean in this context. And, by the way, this would also answer your question about the meaning of "fwKeys" in Spy++.

But really, if you need to simulate mouse events, then do it the right way: call the mouse_event function. It's whole purpose in life is to synthesize mouse events.

On to your other question: how to disable the drag view: it depends on what kind of control you're dealing with. For example, if you had a tree view control, then you could set the TVS_DISABLEDRAGDROP style on the control, as stated on MSDN. If you want to disable drag & drop for that control permanently, then set the flag when you create the control. If you only want to disable it temporarily, during your synthesized input operations, then that's a bit trickier - you can use CWnd::ModifyStyle to temporarily remove the TVS_DISABLEDRAGDROP but you will also need to add code to enable it again, after you finish sending your synthesized mouse movements and the control has finished processing them.

With all that said, what exactly are you trying to achieve? There may be an easier way to solve the problem that you are trying to address.

다른 팁

Thanks for all your answers and support.

I am working on a already developed application which requires this solution. Finally I found that the WM_LBUTTONDOWN handler was already defined in my view. This takes time to execute. Since I used SendMessage which posts message to a thread's message queue and return immediately, before the WM_LBUTTONDOWN finished, the next message WM_LBUTTONUP is called. So the WM_LBUTTONUP was failing.

I used PostMessage as below,

PostMessage(WM_LBUTTONDOWN); 
PostMessage(WM_LBUTTONUP);

This resolves my problem.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top