Solved

code specifc; mouse move

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

705 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

20 Experts available now in Live!

Get 1:1 Help Now