Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simulate mouse over a window in another application 1

Status
Not open for further replies.

FaneDuru

Technical User
Jul 15, 2002
141
RO
I need to simulate the mouse over a window of another application. I mean to trigger Mouse Move event... When I manually move the mouse over that specific window another window appears. I can determine the handle of that specific window, I know its X and Y, Top and Bottom positions and I can set the mouse cursor exactly over the area where it should be moved but I CAN NOT MOVE IT...
The code I use is VBA for Corel X5 that's why do not post it here... I try to pragmatically insert a new menu. I was able to do:
' Find main window handle using FindWindow(vbNullString, AppTitle), AppTitle = "CorelDRAW X5 - [" & ActiveDocument.FilePath & ActiveDocument.Name & "]"
' Find menu handle allocated dynamically but having the parent window handle (obtained using Spy++). Menu handle using FindWindowEx
' Simulate mouse right click SendMessage(Menu, BM_CLICK, 0, 0) for Press and SendMessage(Menu, RBM_UP, 0, 0) for Up .
' The window which appears at mouse right click receives a dynamic handle but respecting some rule for its class. Based on that I am able to obtain its handle. Based on that I am able to put mouse cursor on it (using SetCursorPos).

Now I need to move the mouse cursor over that window in order to trigger the Mouse Move event. Can anybody guide me in the right direction? Until now I tried 'mouse-event' API but I think is something which I do wrong and mouse cursor goes in the upper left corner of the screen...

Thanks in advance!
 
Solved...
I looped 10 times through the sequence of SetCursorPos. I tried that before posting but now I added DoEvents.
Code:
Dim i As Long
    For i = 1 To 10
        SetCursorPos ContextMenuInfo(2) - (30 + i), ContextMenuInfo(4) + 15 
        DoEvents
    Next
ContextMenuInfo(2) keeps window rightX in twips
ContextMenuInfo(4) keeps window topY in twips
 
>I tried 'mouse-event' API but I think is something which I do wrong and mouse cursor goes in the upper left corner of the screen

Perhaps a glance at my code in thread222-1342585 might help for that
 
Thanks Strongm! Nice piece of code. But I usually use SendMessage API to maipulate mouse cursor, click etc. I thought that mouse-move is able to 'move' the cursor not to bring it in a specific position. On my taste, SetCursorPos is a little easyer to use... I found the problem in my 'mouse_move' code (I had already the screen in twips and I wrongly did the transformation from pixels...).
I needed a real 'move' over the window in order to trriger the Mouse Move evend. I succeeded doing that setting some diferent cursor positions on the window area but using DoEVents between each move...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top