Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

code specifc; mouse move

Posted on 2007-11-28
1
Medium Priority
?
194 Views
Last Modified: 2010-04-01
#include <windows.h>
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;

void mousemove( HWND hwnd1, POINT p);
void left_mouseclick( POINT p );
int main()
{
      POINT p;
      p.x = 200;
      p.y = 200;

      HWND hwnd1;  // placeholder
      
      mousemove ( hwnd1, &p );
      left_mouseclick ( p );

      
      
      return 0;
}


void mousemove( HWND hwnd1, POINT p)
{
      ClientToScreen(hwnd1, p);
      SetCursorPos(p.x, p.y);
}

void left_mouseclick( POINT p )
{
      mouse_event(MOUSEEVENTF_LEFTDOWN,   p.x, p.y, 0, 0); // Left Key Down
      mouse_event(MOUSEEVENTF_LEFTDOWN,   p.x, p.y, 0, 0); // Left Key Down

}





I don't why, I know that my use of hwnd is problematic, but i don't know how other things are wrong.
0
Comment
Question by:Troudeloup
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 20368799
Well, you have to initialize the HWND to hold a valid handle. Otherwise, that looks OK, except that you should give a short delay between the two clickes, e.g.

void left_mouseclick( POINT p )
{
      mouse_event(MOUSEEVENTF_LEFTDOWN,   p.x, p.y, 0, 0); // Left Key Down
      Sleep(400);
      mouse_event(MOUSEEVENTF_LEFTDOWN,   p.x, p.y, 0, 0); // Left Key Down

}
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question