home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_12 / 1012056a < prev    next >
Text File  |  1992-10-09  |  2KB  |  103 lines

  1.  
  2. #include <windows.h>
  3. #include "bogus.h"
  4. #include "wintest.h"
  5.  
  6. HANDLE hPgmInstance ;
  7.  
  8. #define IDM_BOGUSEVENT 0x3000
  9.  
  10.  
  11. void CenterWindow(HWND hWnd)
  12.     {
  13.     int xSize, ySize, xPos, yPos ;
  14.     RECT rc ;
  15.  
  16.     xSize = GetSystemMetrics(SM_CXSCREEN) ;
  17.     ySize = GetSystemMetrics(SM_CYSCREEN) ;
  18.     GetWindowRect(hWnd, &rc) ;
  19.     xPos = (xSize - (rc.right - rc.left)) / 2 ;
  20.     yPos = (ySize - (rc.bottom - rc.top)) / 2 ;
  21.     SetWindowPos(hWnd, NULL, xPos, yPos, 0, 0,
  22.         SWP_DRAWFRAME | SWP_NOSIZE | SWP_NOZORDER) ;
  23.     }
  24.  
  25.  
  26. LRESULT _loadds FAR PASCAL MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam,
  27. LPARAM lParam)
  28. {
  29.     static WORD wCountTotal = 0;
  30.     WORD wCount ;
  31.  
  32.     lParam = lParam ;
  33.  
  34.     switch (msg)
  35.     {
  36.     case WM_INITDIALOG:
  37.         RemoveMenu(GetSystemMenu(hwndDlg,0),SC_CLOSE,MF_BYCOMMAND) ;
  38.         BogusStart(hwndDlg, IDM_BOGUSEVENT) ;
  39.         break ;
  40.  
  41.     case WM_SHOWWINDOW:
  42.         if (wParam)
  43.         CenterWindow(hwndDlg) ;
  44.         break ;
  45.  
  46.     case WM_COMMAND:
  47.         switch(wParam)
  48.         {
  49.         case IDM_BOGUSEVENT:
  50.             wCount = BogusGetEvent() ;
  51.             while (wCount)
  52.             {
  53.             wCountTotal += wCount ;
  54.             wCount = BogusGetEvent() ;
  55.             }
  56.             SetDlgItemInt(hwndDlg, IDM_COUNT, wCountTotal, FALSE) ;
  57.             break ;
  58.  
  59.         case IDCANCEL:
  60.             EndDialog(hwndDlg, 0) ;
  61.             break ;
  62.         }
  63.         break ;
  64.  
  65.     default:
  66.         return FALSE ;
  67.     }
  68.  
  69.     return TRUE ;
  70. }
  71.  
  72.  
  73.  
  74. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int
  75. nCmdShow)
  76. {
  77.     hPgmInstance = hInstance ;
  78.     hPrevInstance = hPrevInstance ;
  79.     lpCmdLine = lpCmdLine ;
  80.     nCmdShow = nCmdShow ;
  81.  
  82.     if (!hPrevInstance)
  83.     {
  84.     if (BogusCheck())
  85.         {
  86.         if (MessageBox(0, "Press OK to begin bogus I/O", "WinTest",
  87. MB_OKCANCEL|MB_APPLMODAL) == IDOK)
  88.         {
  89.         DialogBox(hPgmInstance, "MainDlg", 0, (FARPROC) MainDlgProc) ;
  90.         BogusStop() ;
  91.         }
  92.         }
  93.     else
  94.         MessageBox(0, "Bogus device not found", "WinTest",
  95. MB_ICONHAND|MB_OK|MB_APPLMODAL) ;
  96.     }
  97.     else
  98.     MessageBox(0, "Another instance already running", "WinTest",
  99. MB_ICONEXCLAMATION|MB_OK|MB_APPLMODAL) ;
  100.  
  101.     return 0 ;
  102. }
  103.