Exemplo n.º 1
0
long WINAPI MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   long Tid;

   switch (message)
   {
      case WM_CREATE:
/*       Save the window handle in an external variable used elsewhere.     */
         hwndEyegaze = hwnd;

/*       On startup, create an eyetracking thread to produce gaze info.     */
         CreateThread(NULL, 0, GazeDemo, 0, 0, &Tid);
         break;

      case WM_ENDSESSION:
      case WM_CLOSE:
/*       Call the EgExit function to shut down the vision subsystem.        */
         EgExit(&stEgControl);
         PostMessage(hwnd, WM_DESTROY, (WORD)0, (LONG)0);
         break;

      case WM_DESTROY:
         PostQuitMessage(0);

      default:
         return DefWindowProc(hwnd, message, wParam, lParam);
   }
   return 0L;
}
Exemplo n.º 2
0
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT uiMessage,
                            WPARAM wParam, LPARAM lParam)
{
   PAINTSTRUCT ps;
   long        Tid;
   HMENU       hMenu;
   static HINSTANCE hInstance;
   POINT       point;

   switch (uiMessage)
   {
      case WM_CREATE:
/*       Save the instance handle for the dialog box calls below.           */
         hInstance = ((LPCREATESTRUCT) lParam)->hInstance;

/*       Determine the upper-left corner of the client area in screen       */
/*       coordinates.                                                       */
         point.x = 0;
         point.y = 0;
         ClientToScreen(hwnd,&point);
         GetClientRect(hwnd, &stWindowRect);

         iWindowWidthPix = stWindowRect.right - stWindowRect.left;
         iWindowHeightPix = stWindowRect.bottom - stWindowRect.top;
         iWindowHorzOffset = point.x;
         iWindowVertOffset = point.y;

/*       Create the virtual window.                                         */
         hdc    = GetDC(hwnd);
         memdc  = CreateCompatibleDC(hdc);
         hbit   = CreateCompatibleBitmap(hdc, iScreenWidth, iScreenHeight);
         SelectObject(memdc, hbit);
         hbrush = GetStockObject(BLACK_BRUSH);
         SelectObject(memdc, hbrush);
         PatBlt(memdc, 0, 0, iScreenWidth, iScreenHeight, PATCOPY);

         hwndEyegaze = hwnd;
         lctSetWindowHandle(hwnd, memdc, hdc, szAppName, wcslen(szAppName));

/*       Assume loopback connection.                                        */
         wcscpy_s(achCommAddress, 20, TEXT("127.0.0.1"));
         if (_tcslen(achCmdLine) > 0)
            wcscpy_s(achCommAddress, 20, achCmdLine);

/*       Before calling InitEgClientDemo, set stEgControl.hEyegaze to a     */
/*       NULL so the functions that need it won't use it until it's been    */
/*       initialized.                                                       */
         stEgControl.hEyegaze = NULL;

         CreateThread(NULL, 0, InitEgClientDemo, 0, 0, &Tid);
         break;;

      case WM_PAINT:
         BeginPaint(hwnd, &ps);
         BitBlt(hdc,
               // ps.rcPaint.left + iWindowHorzOffset, ps.rcPaint.top + iWindowVertOffset,
                ps.rcPaint.left, ps.rcPaint.top,
                ps.rcPaint.right  - ps.rcPaint.left,
                ps.rcPaint.bottom - ps.rcPaint.top,
                memdc,
                ps.rcPaint.left, ps.rcPaint.top,
                SRCCOPY);
         EndPaint(hwnd, &ps);
         break;

/*    If the user sizes or moves the window, obtain the new size and        */
/*    offsets from screen origin.                                           */
      case WM_MOVE:
         point.x = 0;
         point.y = 0;
         ClientToScreen(hwnd,&point);
         iWindowHorzOffset = point.x;
         iWindowVertOffset = point.y;
       break;

      case WM_SIZE:
         iWindowWidthPix  = LOWORD(lParam);
         iWindowHeightPix = HIWORD(lParam);
         break;

      case WM_SETFOCUS:
         InvalidateRect(hwnd,NULL,TRUE);
         return 0;

      case WM_COMMAND:
         hMenu = GetMenu(hwnd);
         switch(LOWORD (wParam))
         {
            case ID_FILE_EXIT:
               bStopCommunications = TRUE;
               SendMessage(hwnd, WM_CLOSE, 0, 0);
/*             Close the eyegaze communications.                            */
               EgExit(&stEgControl);
               SendMessage(hwnd, WM_CLOSE, 0, 0);
               break;

            case ID_COMMUNICATIONS_CALIBRATE:
               bStopCommunications = FALSE;
               EnableMenuItem(hMenu, ID_COMMUNICATIONS_CALIBRATE,    MF_GRAYED);
               EnableMenuItem(hMenu, ID_COMMUNICATIONS_BEGIN,        MF_GRAYED);
               EnableMenuItem(hMenu, ID_COMMUNICATIONS_END,          MF_ENABLED);
/*             Perform Eyegaze 'C'alibration on the client monitor.         */
               CreateThread(NULL, 0, SupportEyegazeCalibration, 0, 0, &Tid);

               break;

            case ID_COMMUNICATIONS_BEGIN:
               bStopCommunications = FALSE;
               EnableMenuItem(hMenu, ID_COMMUNICATIONS_CALIBRATE,    MF_GRAYED);
               EnableMenuItem(hMenu, ID_COMMUNICATIONS_BEGIN,        MF_GRAYED);
               EnableMenuItem(hMenu, ID_COMMUNICATIONS_END,          MF_ENABLED);
               CreateThread(NULL, 0, ProcessGazepointData, hfEyegazePort, 0, &Tid);
               break;

            case ID_COMMUNICATIONS_END:
               bStopCommunications = TRUE;
               EnableMenuItem(hMenu, ID_COMMUNICATIONS_CALIBRATE,    MF_ENABLED);
               EnableMenuItem(hMenu, ID_COMMUNICATIONS_BEGIN,        MF_ENABLED);
               EnableMenuItem(hMenu, ID_COMMUNICATIONS_END,          MF_GRAYED);
               break;

            case ID_DATALOG_OPENFILE:
/*             'O'pen a file and receive file header data.                  */
               if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_OPENFILE),
                         hwnd, OpenFileDialogProc) == TRUE)
               {
                  EnableMenuItem(hMenu, ID_DATALOG_OPENFILE,            MF_GRAYED);
                  EnableMenuItem(hMenu, ID_DATALOG_BEGINDATACOLLECTION, MF_ENABLED);
                  EnableMenuItem(hMenu, ID_DATALOG_MARKEVENT,           MF_ENABLED);
                  EnableMenuItem(hMenu, ID_DATALOG_CLOSEFILE,           MF_ENABLED);

                  EgLogFileOpen(&stEgControl, achFileName, "a");

/*                Write the log file column headers to the file.            */
                  EgLogWriteColumnHeader(&stEgControl);
               }
               break;

            case ID_DATALOG_BEGINDATACOLLECTION:
               EnableMenuItem(hMenu, ID_DATALOG_ENDDATACOLLECTION,   MF_ENABLED);
               EnableMenuItem(hMenu, ID_DATALOG_BEGINDATACOLLECTION, MF_GRAYED);

/*             Start storing Eyegaze data to file.                          */
               EgLogStart(&stEgControl);
               break;

            case ID_DATALOG_MARKEVENT:
               EgLogMark(&stEgControl);
               break;

            case ID_DATALOG_ENDDATACOLLECTION:
/*             Stop storing Eyegaze data to file.                           */
               EgLogStop(&stEgControl);

               EnableMenuItem(hMenu, ID_DATALOG_ENDDATACOLLECTION,   MF_GRAYED);
               EnableMenuItem(hMenu, ID_DATALOG_BEGINDATACOLLECTION, MF_ENABLED);

               break;

            case ID_DATALOG_CLOSEFILE:
/*             Close the file.                                              */
               EgLogFileClose(&stEgControl);

               EnableMenuItem(hMenu, ID_DATALOG_OPENFILE,            MF_ENABLED);
               EnableMenuItem(hMenu, ID_DATALOG_BEGINDATACOLLECTION, MF_GRAYED);
               EnableMenuItem(hMenu, ID_DATALOG_MARKEVENT,           MF_GRAYED);
               EnableMenuItem(hMenu, ID_DATALOG_CLOSEFILE,           MF_GRAYED);

               break;

            case ID_HELP_ABOUT:
               MessageBox(hwnd,TEXT ("EgClientDemo Demonstration Program\n")
                               TEXT ("(c) LC Technologies, 2003-2010 "),
                          szAppName, MB_ICONINFORMATION | MB_OK);
               break;
         }
         break;

      case ID_CALIBRATION_ENDED:
         hMenu = GetMenu(hwnd);
         EnableMenuItem(hMenu, ID_COMMUNICATIONS_CALIBRATE,    MF_ENABLED);
         EnableMenuItem(hMenu, ID_COMMUNICATIONS_BEGIN,        MF_ENABLED);
         EnableMenuItem(hMenu, ID_COMMUNICATIONS_END,          MF_GRAYED);
         break;

      case WM_DESTROY:
/*       Close the eyegaze communications port.                             */
//         EgExit(&stEgControl);

         ReleaseDC(hwnd, hdc);
         DeleteDC(memdc);
         PostQuitMessage(0);
         break;

      default:
         return DefWindowProc(hwnd, uiMessage, wParam, lParam);
         break;
   }
   return 0;
}