Solved

code specifc; mouse move

Posted on 2007-11-28
1
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

636 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