Thread: Moving the mouse with SendMessage / PostMessage

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    I Write C++ Apps, Sue Me.
    Join Date
    Feb 2006
    Location
    In My Computer
    Posts
    44

    Moving the mouse with SendMessage / PostMessage

    Hi,
    I have a few questions:

    1. What is the difference between SendMessage and PostMessage?

    2. Am I using SendMessage correctly? I want to emulate mouse movement in a certain window while still being able to use the computer.

    Code:
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    int main() {
        POINT btn;
        HWND mWindow;
        cout<<"Set Mouse Over button and press ENTER";
        cin.get();
        GetCursorPos(&btn);
        cout<<"\nAfter Pressing ENTER, you have 5 seconds to set focus to the correct window.";
        cin.get();
        Sleep(5000);
        mWindow = GetFocus();
    
       SendMessage(mWindow,WM_MOUSEMOVE,0,MAKELPARAM(btn.x,btn.y));
       SendMessage(mWindow,WM_LBUTTONDOWN,0,MAKELPARAM(btn.x,btn.y));
       SendMessage(mWindow,WM_LBUTTONUP,0,MAKELPARAM(btn.x,btn.y));
       return 0;
    }
    Please DO NOT suggest SendInput / mouse_event. They do not do what I am looking for. (AKA they hijack the mouse)

    Thanks!
    Last edited by comwiz; 07-31-2007 at 10:22 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving objects with mouse in 3D.
    By psychopath in forum Game Programming
    Replies: 15
    Last Post: 07-10-2011, 04:20 PM
  2. Moving mouse
    By Bill83 in forum Windows Programming
    Replies: 1
    Last Post: 04-02-2006, 08:58 AM
  3. Replies: 2
    Last Post: 03-23-2006, 07:08 AM
  4. mouse click coords and moving a rect
    By techrolla in forum Windows Programming
    Replies: 1
    Last Post: 03-07-2004, 09:49 PM
  5. Moving a Static box with the mouse
    By AtomRiot in forum Windows Programming
    Replies: 4
    Last Post: 06-26-2003, 11:34 PM