Total members 9950 | Gratitudes |It is currently Sat Feb 11, 2012 2:22 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: Mouse position in C++
PostPosted: Sun May 25, 2008 5:17 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 56 time

This C/C++ show the position of mouse (X,Y) at the screen :
Code:
#include <windows.h>
#include <iostream>
using namespace std;

int main()
{
    HANDLE hIn;
    HANDLE hOut;
    COORD MouseWhere  = {30, 20};
    COORD DClickWhere = {30, 20};
   
   
   
   
   
    bool Continue = TRUE;
    DWORD EventCount;
    int LoopCount = 0;
    int KeyEvents = 0;
    INPUT_RECORD InRec;
    DWORD NumRead;

    hIn = GetStdHandle(STD_INPUT_HANDLE);
    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    cout << "Mouse is at     : " << endl;
    cout << "Double Click at : " << endl;
   
   


    while (Continue)
    {
   

       
        Sleep(10); // To slow it down!!

        GetNumberOfConsoleInputEvents(hIn,&EventCount);
        while (EventCount > 0)
        {
           ReadConsoleInput(hIn,&InRec,1,&NumRead);

            if (InRec.EventType == KEY_EVENT)
            {
                if (InRec.Event.KeyEvent.uChar.AsciiChar == 'x')
                {
   

                            cout << "Exiting..." << endl;
                            Continue = FALSE;
                }
            }
            else if (InRec.EventType == MOUSE_EVENT)
            {
     
                 if (InRec.Event.MouseEvent.dwEventFlags == MOUSE_MOVED)
                {
                    SetConsoleCursorPosition(hOut,
                                             MouseWhere);
                    cout << InRec.Event.MouseEvent.dwMousePosition.X << "," <<
                            InRec.Event.MouseEvent.dwMousePosition.Y << "  " << flush;
                }
                else if (InRec.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK)
                {
                    SetConsoleCursorPosition(hOut,
                                             DClickWhere);
                    cout << InRec.Event.MouseEvent.dwMousePosition.X << "," <<
                            InRec.Event.MouseEvent.dwMousePosition.Y << "  " << flush;
                }             
             }
             
          GetNumberOfConsoleInputEvents(hIn,&EventCount);
        }
    }

    return 0;
}


I hope it is helpfull

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 Change the mouse cursor to hand pointer  HTML examples  msi_333  0
 Change background position when mouse over  HTML examples  msi_333  0
 setting div background position  HTML examples  msi_333  0
 static vs fixed div position  HTML examples  msi_333  0
 right bottom background image position  HTML examples  msi_333  0

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team