Thread: Confuse With The Simple Things~~the console programming.look for help!

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    17

    Exclamation Confuse With The Simple Things~~the console programming.look for help!

    The code like this:
    Code:
    #include <stdio.h>#include <windows.h>
    
    
    int main(int argc, char *argv[])
    {
    	DWORD cNumRead, fdwMode, i, numInput; 
        INPUT_RECORD irInBuf[128]; 
        INPUT_RECORD InputInfo;
        HANDLE hIn;
        hIn = GetStdHandle( STD_INPUT_HANDLE);
    	while( 1)
    	{
    		GetNumberOfConsoleInputEvents( hIn, &numInput);
     		if( !numInput)
     			continue;
    		ReadConsoleInput( hIn, &InputInfo, 1, &cNumRead);
        	printf("%d, %d\n", 
    			InputInfo.Event.MouseEvent.dwMousePosition.X,
    			InputInfo.Event.MouseEvent.dwMousePosition.Y);
    	}
    }
    but the result dose not like what i want.

    value
    InputInfo.Event.MouseEvent.dwMousePosition.Y
    was wrong~ i don't no why~
    help~~~
    SOS

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    17
    thank for your reply

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Perhaps check that InputInfo.EventType == MOUSE_EVENT before trying to print anything mouse related.
    INPUT_RECORD structure
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Dec 2011
    Posts
    17
    I thinke about it, I just wanna try the Mouse Event.
    I add the
    if( InputInfo.EventType != MOUSE_EVENT) continue;
    but the result has nothing change.the value Y was also wrong.
    it increase to about 300.

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    17
    i modify the code Reading Input Buffer Events
    but the result was also the same ~
    next is the changed
    Code:
        while (1)     { 
            // Wait for the events. 
     
            if (! ReadConsoleInput( 
                    hStdin,      // input buffer handle 
                    irInBuf,     // buffer to read into 
                    128,         // size of read buffer 
                    &cNumRead) ) // number of records read 
                ErrorExit("ReadConsoleInput"); 
     
            // Dispatch the events to the appropriate handler. 
     
            for (i = 0; i < cNumRead; i++) 
            {
                if( irInBuf[i].EventType != MOUSE_EVENT) continue;
    			printf("%d, %d\n", 
    				irInBuf[i].Event.MouseEvent.dwMousePosition.X,
    				irInBuf[i].Event.MouseEvent.dwMousePosition.Y);
            }
        }

  6. #6
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Because as you print new lines, the console scrolls down its buffer till it gets to the bottom (which defaults to 300).

    The docs point it out:
    dwMousePosition
    A COORD structure that contains the location of the cursor, in terms of the console screen buffer's character-cell coordinates.

  7. #7
    Registered User
    Join Date
    Dec 2011
    Posts
    17
    Thank very very very much ~ i think it over!~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Programming Robots and things with C!
    By Darwin Froese in forum C Programming
    Replies: 15
    Last Post: 05-27-2011, 09:22 PM
  2. a little confuse o_0???
    By omarbags in forum C++ Programming
    Replies: 15
    Last Post: 01-24-2008, 01:03 AM
  3. Simple Sorts Confuse ME =/
    By otchster in forum C Programming
    Replies: 5
    Last Post: 12-03-2005, 02:02 PM
  4. Too confuse
    By dv007 in forum C++ Programming
    Replies: 6
    Last Post: 07-25-2002, 05:33 PM
  5. What is your favorite things about programming?
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 10-21-2001, 12:13 PM

Tags for this Thread