THIS PROGRAM SUCKS HELP ME~~~!!!!! (Counts intervals between clicks=>supposed to)

This is a discussion on THIS PROGRAM SUCKS HELP ME~~~!!!!! (Counts intervals between clicks=>supposed to) within the Windows Programming forums, part of the Platform Specific Boards category; Code: #ifndef HITIMER_H #define HITIMER_H #endif #define WIN32_LEAN_AND_MEAN #include <windows.h> #define TimerResolution 1000 //Milliseconds class HiTimer { private : LARGE_INTEGER ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    123

    THIS PROGRAM SUCKS HELP ME~~~!!!!! (Counts intervals between clicks=>supposed to)

    Code:
    #ifndef HITIMER_H
    #define HITIMER_H
    #endif
    
    #define WIN32_LEAN_AND_MEAN
    
    #include <windows.h>
    
    #define TimerResolution 1000 //Milliseconds
    
    class HiTimer
    {
     private :
     
    		LARGE_INTEGER freq;
    		LARGE_INTEGER start;
    		LARGE_INTEGER stop;
    		bool available;
     public  :
     
    		HiTimer();
    		
    		
    		void SetTimer();
    		
    		
    		void StopTimer();
    		
    	LONGLONG GetelapsedCount();
    
    		bool isavailable();
    		
    		
    };
    
    
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    HiTimer Watch;
    unsigned int Count = 0;
    
    void MouseEventProc(MOUSE_EVENT_RECORD, ofstream & Output);
    
    bool _hasclick(void);
    
    	int main(VOID) 
    { 
      HANDLE handleIn;
      INPUT_RECORD recordIn;
      DWORD NumRead;
         ofstream outputdata;
    	 outputdata.open("sample.txt");
    	 if( !outputdata )
    	  cerr << "Error: file could not be opened" << endl;
    
    	 //Get the handle to the console instance
    	 handleIn = GetStdHandle(STD_INPUT_HANDLE); 
        if (handleIn == INVALID_HANDLE_VALUE) 
             cerr << "Error:could not get instance"<<endl;
     
       // Enable the window and mouse input events. 
     
        DWORD fdwMode = ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT; 
        if (! SetConsoleMode(handleIn, fdwMode) ) 
             cerr << "Error:could not set mode"<<endl;
    		
    		
    		
    		 while (Count < 100)
         {
             ReadConsoleInput(handleIn, &recordIn, 1, &NumRead);
    
             switch (recordIn.EventType)
             {
               
             case MOUSE_EVENT:
         		MouseEventProc(recordIn.Event.MouseEvent, outputdata);
                 break;
             }
         }
    	 
    	 outputdata.close();
    
          cout<< "Finished check sample file"<<endl;
    	  cin.get();
    
          return 0;
    }
    
    
    bool _hasclick(void)
    {
     static bool click = false;
     
     if(click = true )
     return true;
     
     click = true;
     return false;
    }
    
    void MouseEventProc(MOUSE_EVENT_RECORD mer, ofstream & Output)
    {
       
     switch(mer.dwEventFlags)
        {
         case 0:
    	 if( mer.dwButtonState ==FROM_LEFT_1ST_BUTTON_PRESSED)
    	 {
    	   //do what you need to do 
    	  if( _hasclick() )
    	  {
    	    cout<<"You click"<<endl;
    	    Watch.StopTimer();
    		Output << Watch.GetelapsedCount() <<endl;
    	  }
    	    Watch.SetTimer();
    		
    	 }
    	 break;
    	}
    }
    
    HiTimer::HiTimer()
             {
    		 start = 0;
    		 stop =  0;
    		 available = false;
    		 if(QueryPerformanceFrequency(&freq))
    		 available = true;
    		}
    		
    void HiTime:: SetTimer()
    		{
    		 QueryPerformanceCounter(&start);
    		}
    		
    void HiTime:: StopTimer()
    		{
    		  QueryPerformanceCounter(&stop);
    		}
    		
    LONGLONG HiTime:: GetelapsedCount()
    		{
    		  long long Time_elapsed = (stop.QuadPart - start.QuadPart) * TimerResolution / freq.QuadPart ;
    		  return Time_elapsed;
    		}
    		
    bool	HiTime:: isavailable()
    		{
    		return available;
    		}
    Compiler: Default compiler
    Executing g++.exe...
    g++.exe "C:\Users\Jim\Desktop\Samplecollector.cpp" -o "C:\Users\Jim\Desktop\Samplecollector.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
    C:\Users\Jim\Desktop\Samplecollector.cpp: In constructor `HiTimer::HiTimer()':

    C:\Users\Jim\Desktop\Samplecollector.cpp:128: error: no match for 'operator=' in '((HiTimer*)this)->HiTimer::start = 0'
    C:/Dev-Cpp/include/winnt.h:1979: note: candidates are: _LARGE_INTEGER& _LARGE_INTEGER:perator=(const _LARGE_INTEGER&)
    C:\Users\Jim\Desktop\Samplecollector.cpp:129: error: no match for 'operator=' in '((HiTimer*)this)->HiTimer::stop = 0'
    C:/Dev-Cpp/include/winnt.h:1979: note: candidates are: _LARGE_INTEGER& _LARGE_INTEGER:perator=(const _LARGE_INTEGER&)
    C:\Users\Jim\Desktop\Samplecollector.cpp: At global scope:
    C:\Users\Jim\Desktop\Samplecollector.cpp:135: error: `HiTime' has not been declared
    C:\Users\Jim\Desktop\Samplecollector.cpp: In function `void SetTimer()':
    C:\Users\Jim\Desktop\Samplecollector.cpp:137: error: `start' undeclared (first use this function)
    C:\Users\Jim\Desktop\Samplecollector.cpp:137: error: (Each undeclared identifier is reported only once for each function it appears in.)
    C:\Users\Jim\Desktop\Samplecollector.cpp: At global scope:
    C:\Users\Jim\Desktop\Samplecollector.cpp:140: error: `HiTime' has not been declared
    C:\Users\Jim\Desktop\Samplecollector.cpp: In function `void StopTimer()':
    C:\Users\Jim\Desktop\Samplecollector.cpp:142: error: `stop' undeclared (first use this function)
    C:\Users\Jim\Desktop\Samplecollector.cpp: At global scope:
    C:\Users\Jim\Desktop\Samplecollector.cpp:145: error: `HiTime' has not been declared
    C:\Users\Jim\Desktop\Samplecollector.cpp: In function `LONGLONG GetelapsedCount()':
    C:\Users\Jim\Desktop\Samplecollector.cpp:147: error: `stop' undeclared (first use this function)
    C:\Users\Jim\Desktop\Samplecollector.cpp:147: error: `start' undeclared (first use this function)
    C:\Users\Jim\Desktop\Samplecollector.cpp:147: error: `freq' undeclared (first use this function)
    C:\Users\Jim\Desktop\Samplecollector.cpp: At global scope:
    C:\Users\Jim\Desktop\Samplecollector.cpp:151: error: `HiTime' has not been declared
    C:\Users\Jim\Desktop\Samplecollector.cpp: In function `bool isavailable()':
    C:\Users\Jim\Desktop\Samplecollector.cpp:153: error: `available' undeclared (first use this function)

    Execution terminated

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Large integer is a union, not a value data type.

    LARGE_INTEGER Union (Windows)

    PS Please format your code. Normally I would not take the time to bother answering your question, simply because you did not take the time to make your code readable.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Ok... are you trying to time intervals only for your window... or for all windows?

    If it's the latter you will need to set a low level mouse hook, which can only be done in a DLL.

    SetWindowsHookEx Function (Windows)

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Put another way, the compile errors are because there is no equals operator for LARGE_INTEGER

    Code:
    LARGE_INTEGER start;
    
    start = 0; //error
    start.QuadPart = 0; //no error
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Program that counts total prime number?
    By exe101 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 01:18 AM
  2. Replies: 3
    Last Post: 10-07-2003, 08:37 PM
  3. My program is not doing what it's supposed to do, help!!
    By TrazPFloyd in forum C++ Programming
    Replies: 5
    Last Post: 11-08-2002, 10:25 PM
  4. program exits when it isn't supposed to
    By Captain Penguin in forum C++ Programming
    Replies: 2
    Last Post: 10-25-2002, 03:54 PM
  5. about program that counts a character frequency
    By Unregistered in forum C++ Programming
    Replies: 15
    Last Post: 04-23-2002, 01:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21