Start New Discussion within our Software Development Community

I want to make a native win32 program that simply moves the cursor to x=100 y=200 on the screen, and then clicks the left mouse button once. Where do I start? For once, Google got me nowhere. I use VC++ 2010 to compile.

>>Google got me nowhere
Then you didn't do enough of it. There are tons of tutorials on web. Some are here at DaniWeb & I've posted to at least 5 such queries in past 3 days. Search properly.

They all use either #import or #using, which yields "error C2773: #import and #using available only in C++ compiler" ...

Ok, so I'm trying to do this in native, not managed C++. Which means I can't use code such as this

using namespace System;
using namespace System::Runtime::InteropServices;


I'm running this C program through the Java Native Interface, and it doesn't seem to handle managed code... Is there another way?

Thanks a lot. I couldn't get the other examples to work, so for anyone else who might stumble upon this thread with the same problems ... here's what i did:

#define _WIN32_WINNT 0x0501
#include "C:\Program Files\Java\jdk1.6.0_20\include\jni.h"
#include <stdio.h>
#include <windows.h>
#include <winuser.h>
#include "hio.h"
#pragma comment(lib, "User32.lib" ) // Probably compiler (VC++) specific

void move(int x, int y);
void press(void);
void release(void);

int ix,iy;
INPUT *click;

JNIEXPORT void JNICALL Java_hio_click(JNIEnv *env, jobject obj) {
	printf("it works!\n");
	click = new INPUT;
	ix = GetSystemMetrics(SM_CXSCREEN);
	iy = GetSystemMetrics(SM_CYSCREEN);
void move(int x, int y) {
	click->type = INPUT_MOUSE;
	click->mi.dx = x*65535/ix;
	click->mi.dy = y*65535/iy;
void press(void) {
	click->type = INPUT_MOUSE;
	click->mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
void release(void) {
	click->type = INPUT_MOUSE;
	click->mi.dwFlags = MOUSEEVENTF_LEFTUP;

Probably not good code, but it works. Compiled with VC++ 2010. Also, thread should be moved to the C++ forum.

This is a bit of code showing how to move the cursor, using one API, in the console window.

//you need to include <windows.h>

void Gotoxy(int x, int y) {
   COORD coord;
   coord.X = x;
   coord.Y = y;
   SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

void function Where I want to move the console cursor(void)  {
This question has already been answered. Start a new discussion instead.