Exemplo n.º 1
0
//----------------------------------------------------------------------
BOOL CALLBACK x_DialogProc(HWND hDlgWnd, UINT message, WPARAM wParam, LPARAM lParam) { 
 
  switch (message) {
  
    case WM_COMMAND: 
      if (HIWORD(wParam) == BN_CLICKED) { 
        switch (LOWORD(wParam)) { 
          case IDC_CMD_EXIT:  // Exit button
            PostMessage( hDlgWnd, WM_CLOSE, 0,0);
            return TRUE;
          case IDC_CMD_START:  // Start button
            g_CmdStart();
            DrawBackground( hDlgWnd );
            return TRUE;
          case IDC_CMD_STOP:  // Stop button
            g_CmdStop();
            DrawBackground( hDlgWnd );
            return TRUE;

/*
          case IDC_BOX1: 
            // Retrieve the state of the check box. 
            lState = SendDlgItemMessage( hDlg, IDC_BOX1, BM_GETSTATE, 0, 0); 
            DoSomething(lState); 
            break; 
*/
        } // switch
      }  // if BN_CLICKED
      break;

    case WM_TIMER:
      OnTimer( hDlgWnd );
      return TRUE;

    case WM_PAINT:
      DrawBackground( hDlgWnd );
      return FALSE;

    case WM_DESTROY:
      PostQuitMessage(0);
      return TRUE;

    case WM_CLOSE:
      // TODO: check status and ask for confirmation
      g_Release_EyeTrack();
      CP_printfDestroy(); // close console window    
      DestroyWindow (hDlgWnd);
      return TRUE;

    } 
    return FALSE;       // did not process a message 
} 
Exemplo n.º 2
0
//----------------------------------------------------------------------
// This is  a DialogProc, not a WindowProc
// It should not call "return DefWindowProc()" at the end
// It returns TRUE for handled messages and FALSE otherwise
BOOL CALLBACK x_DialogProc(HWND hDlgWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 
  LRESULT  lngRes;
  char * szResult;
  int  iResult; 

  switch (uMsg) {

    case WM_PI_RAWDATA_READY:
      g_OnNewData( wParam, lParam);
      return TRUE;

    case WM_PI_DATA_STARTED:
      CP_printf("\nLiberty data started.\n");
      return TRUE;
      
    case WM_PI_DATA_STOPPED:
      CP_printf("\nLiberty data stopped.\n");
      InvalidateRgn( hDlgWnd, NULL, TRUE); // refresh the window
      return TRUE;
      
    case WM_PI_RAWDATA_ERROR :
      g_GetLibertyResult( &szResult, &iResult  );
      CP_printf("\nLiberty data error: %s   Code: %X\n", szResult, iResult);
      return TRUE;
      
    case WM_PI_RAWDATA_WARNING :
      CP_printf("\nLiberty data warning.\n");
      return TRUE;
      
 
    case WM_COMMAND: 
      if (HIWORD(wParam) == BN_CLICKED) { 
        switch (LOWORD(wParam)) { 
          case IDC_CMD_EXIT:  // Exit button
            PostMessage( hDlgWnd, WM_CLOSE, 0,0);
            return TRUE;
          case IDC_CMD_START:  // Start button
            g_CmdStart();
            return TRUE;
          case IDC_CMD_STOP:  // Stop button
            g_CmdStop();
            return TRUE;
          case IDC_CHK_SHOWLOG: 
            // Retrieve the state of the check box. 
            lngRes = SendDlgItemMessage( hDlgWnd, IDC_CHK_SHOWLOG, BM_GETCHECK, 0, 0); 
            if( lngRes == BST_CHECKED ) CP_printfShow();
            if( lngRes == BST_UNCHECKED ) CP_printfHide();
            return TRUE; 

        } // switch
      }  // if BN_CLICKED
      break;

    case WM_TIMER:
      OnTimer( hDlgWnd );
      return TRUE;

    case WM_DESTROY:
      PostQuitMessage(0);
      return TRUE;

    case WM_CLOSE:
      g_Release_LibertyTrack();
      CP_printfDestroy(); // close console window    
      DestroyWindow (hDlgWnd);
      return TRUE;
    } 
  return FALSE;
} 
Exemplo n.º 3
0
//===========================================================================
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                                LPTSTR lpCmdLine, int nShowCmd ) {

  HANDLE hMutex;
  int iRet;
  HRESULT hRes;
  TCHAR szTokens[] = _T("-/");

  // Check for another instance
  hMutex = OpenMutex( SYNCHRONIZE,  // requested access (lowest possible)
                      FALSE,  // allow inheritance (does not matter)
                      x_szMutexName);  // unique name

  if(hMutex){
    MessageBox( NULL, "Cannot start the application because another instance is already running.\n", 
                g_szAppTitile, MB_OK | MB_ICONERROR );
    return 1;
  }

  hMutex = CreateMutex( NULL,  // default security
                        TRUE,  // obtain ownership
                        x_szMutexName);  // unique name
  if(!hMutex){
    MessageBox( NULL, "Cannot create application mutex.\n", 
                g_szAppTitile, MB_OK | MB_ICONERROR );
    return 1;
  }
    

  hRes = CoInitialize(NULL);  // single-threaded apartment 
  _ASSERTE(SUCCEEDED(hRes));
  _Module.Init(ObjectMap, hInstance, &LIBID_CP_DISPLAYLib);
  hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE);
  _ASSERTE(SUCCEEDED(hRes));

  lpCmdLine = GetCommandLine(); //this line is necessary for _ATL_MIN_CRT


  // Parse the command line for options
  LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
  while (lpszToken != NULL) {
    if (lstrcmpi(lpszToken, "UnregServer")==0) {
      _Module.UpdateRegistryFromResource(IDR_CP_Display, FALSE);
      iRet = _Module.UnregisterServer(TRUE);
	  //	iRet = g_UnregisterCOM();


      if( iRet != 0 ) { 
        MessageBox( NULL, "Error: Can't unregister server. UnregisterServer() failed.", g_szAppTitile, MB_OK);
      }
      else {
        MessageBox( NULL, "Success: the server is unregistered.", g_szAppTitile, MB_OK);
      }
      _Module.Term();
      CoUninitialize();
      return iRet;
    }
    if (lstrcmpi(lpszToken, "RegServer")==0) {
      iRet = _Module.UpdateRegistryFromResource(IDR_CP_Display, TRUE);
      iRet = _Module.RegisterServer(TRUE);
      //iRet = g_RegisterCOM();

      if( iRet != 0 ) { 
		  char str[200];
		  sprintf(str,"Error: Can't register server. g_RegisterCOM() failed (%lx).",(unsigned long)iRet);
        MessageBox( NULL, str, g_szAppTitile, MB_OK);
		//MessageBox( NULL, "Error: Can't register server. g_RegisterCOM() failed.", g_szAppTitile, MB_OK);
      }
      else {
        MessageBox( NULL, "Success: the server is registered.", g_szAppTitile, MB_OK);
      }
      _Module.Term();
      CoUninitialize();
      return iRet;
    }
    lpszToken = FindOneOf(lpszToken, szTokens);
  } // while there are tokens


  CP_printfCreate( g_szAppTitile );  // Creates log window (console)
  CP_printf("%s\n", g_szVersion );


  CP_printf("----------------------------------------\n");
  CP_printf("Build options:\n\n");
//~~~~~~~~~~~~~~~~~
#ifdef _DEBUG
  CP_printf("Debug version.\n");
#else
  CP_printf("Release version. \n\n");
#endif  // #ifdef _DEBUG
//~~~~~~~~~~~~~~~~~
  CP_printf("SET_FULLSCREEN_MODE: %d\n", SET_FULLSCREEN_MODE);
  CP_printf("DEBUG_THRESHOLD: %d\n", DEBUG_THRESHOLD);
  CP_printf("----------------------------------------\n");

  srand( (unsigned)123 );
  try {
    if ( !g_StartGL_Engine( hInstance, nShowCmd ) ){
      g_MainLoop();
    }
  }
  catch( ... ) {
    MessageBox( NULL, "Exception!!! SOS!!! The program will shut down!", 
               g_szAppTitile, MB_OK | MB_ICONERROR );
    exit(1);
  }

  CP_printf("N objects before quitting: %d\n", _Module.GetLockCount() );

  _Module.RevokeClassObjects();
  Sleep(COM_THREAD_WAIT_MS); //wait for any threads to finish


  // WrapUp
  _Module.Term();
  CoUninitialize();
  // Left-over objects are deleted in CoUninitialize(). Since they call RequestUpdate 
  // in the destuctor, we have to delete GL_Window after CoUninitialize()
  g_StopGL_Engine( );  
  InvalidateRect(NULL, NULL, TRUE); // redraw the desktop
  Sleep(5000); // show log window for 5 sec before quitting
  CP_printfDestroy( );  // Kills log window (console)
  ReleaseMutex(hMutex); 

  return 0;
}
Exemplo n.º 4
0
//============================================================================================
//   MAIN
//============================================================================================
extern "C" int WINAPI WinMain(  HINSTANCE hInstance,      // handle to current instance
                                HINSTANCE hPrevInstance,  // handle to previous instance
                                LPSTR lpCmdLine,          // command line
                                int nCmdShow   ){         // show state

  HANDLE hMutex;
  TCHAR szTokens[] = "-/";
  LPCTSTR lpszToken;
  int iRes;
  HRESULT hRes;

  x_hInstance = hInstance;

  // Check for another instance
  hMutex = OpenMutex( SYNCHRONIZE,  // requested access (lowest possible)
                      FALSE,  // allow inheritance (does not matter)
                      x_szMutexName);  // unique name

  if(hMutex){
    MessageBox( NULL, "Cannot start the application because another instance is already running.\n", 
                x_szTitle, MB_OK | MB_ICONERROR );
    return 1;
  }

  hMutex = CreateMutex( NULL,  // default security
                        TRUE,  // obtain ownership
                        x_szMutexName);  // unique name
  if(!hMutex){
    MessageBox( NULL, "Cannot create application mutex.\n", 
                x_szTitle, MB_OK | MB_ICONERROR );
    return 1;
  }


  // Parse the command line for options
  lpszToken = FindOneOf(lpCmdLine, szTokens);
  while (lpszToken != NULL) {
    if (lstrcmpi(lpszToken, "UnregServer")==0) {
      iRes = g_UnregisterCOM();
      if( iRes != 0 ) { 
        MessageBox( NULL, "Error: Can't unregister server. g_UnregisterCOM() failed.", x_szTitle, MB_OK);
      }
      else {
        MessageBox( NULL, "Success: the server is unregistered.", x_szTitle, MB_OK);
      }
      return iRes;
    }
    if (lstrcmpi(lpszToken, "RegServer")==0) {
      iRes = g_RegisterCOM();
      if( iRes != 0 ) { 
        MessageBox( NULL, "Error: Can't register server. g_RegisterCOM() failed.", x_szTitle, MB_OK);
      }
      else {
        MessageBox( NULL, "Success: the server is registered.", x_szTitle, MB_OK);
      }
      return iRes;
    }
    lpszToken = FindOneOf(lpszToken, szTokens);
  } // while there are tokens

//-------  Regular run starts here
  // Init COM using single-threaded model
  hRes = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); 
  if( hRes != S_OK) { 
    MessageBox( NULL, "Error in CoInitializeEx()", x_szTitle, MB_OK);
    return 1;
  }
  
  CP_printfCreate(x_szTitle); // create console window
  CP_printf(g_szVersion);
  CP_printf("\n\n");
  CP_printfHide(); // hide console window

  //-------  Windows main loop is here
  DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN_DIALOG), NULL, x_DialogProc); 

  CP_printfDestroy();
	CoUninitialize();

  return 0;
}