Solved

code specifc; mouse move

Posted on 2007-11-28
1
183 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

919 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now