Dear all,

I am currently working on a mini-application using Visual C++, and it goes pretty much like this:

The program, using mousehook, will retrieve the coordinates of the current mouse position using getcursorpos when a right click is executed, and it will return with a red dot on the retrieved coordinates.

Currently, I am done with the mousehook and the getcursorpos part, which I've set for it to return a messagebox showing the coordinates of the mouse when I execute a right click (will be changed to left click after this, keeping it as right click at the moment as it's less annoying). However, I am stumped with ideas for the showing the red dot on the retrieved coordinates part. This program is not meant to be ran in a frame, but on windows in a global manner, which means the red dot will show on a desktop, or on any other application.

Is there any advises from the professionals around here? And if you guys want me to upload a copy of my code, I'd be glad to do so. =) But it won't look elegant, as I never had any prior knowledge in C++ programming at all before this, and hell.. I believe programming is my weakest area. >_<

Thanks in advanced!

PS: Do let me know if I've forgotten anything or what not. Relatively new on the boards around here. Thanks!

Recommended Answers

Answered by tkud 0 in a post from

Post some code, no matter how 'unelegant' it is.

Jump to Post

All 3 Replies

Post some code, no matter how 'unelegant' it is.

What tkud already said ^^ and also if you can describe what's the purpose of this program and the red dot, then people might come up with suggestions.

#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <iostream>

HHOOK MouseHook;

LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam){

        if(wParam == WM_RBUTTONDOWN)	//specifies right click. Use WM_LBUTTONDOWN for left click

	POINT cursorPos;
        float x = 0;
        x = cursorPos.x;
        float y = 0;
        y = cursorPos.y;

        char msg[50];

        sprintf(msg, "x: %.2f\n" "y : %.2f\n", x, y);

        MessageBox(0, msg, "Mouse Position", 0);

	//dot indicator section should go here

        return CallNextHookEx(NULL,nCode,wParam,lParam);

void StayAlive(){
        MSG message;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        LPSTR lpCmdLine, int nShowCmd){
        MouseHook = SetWindowsHookEx(WH_MOUSE_LL,MouseHookProc,hInstance,0);

        return 0;

This is the whole block of code for the application itself.

Basically, the red dot is suppose to just show where a person had clicked. It's actually for a current research which is still ongoing, so I'd better refrain from giving out too much information. But regardless, everytime someone executes a click, a red dot should appear on the place the person clicked, in a global manner.

Thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.