home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / mag&info / msjv7_5.zip / CQA.ARJ / PUMP_C7.C < prev    next >
Text File  |  1992-09-01  |  7KB  |  196 lines

  1. // pump_c7.c
  2.  
  3. #include <windows.h>
  4. #include <toolhelp.h>
  5. #include "resource.h"
  6.  
  7.  
  8.  
  9. long      m_lMsgCount;
  10. TIMERINFO m_ti;
  11. DWORD     m_dwStartTime,
  12.           m_dwStopTime,
  13.           m_dwCalibrationTime;
  14.  
  15.  
  16. long FAR PASCAL WndProc (HWND, unsigned, UINT, LONG) ;
  17.  
  18. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  19.                     LPSTR lpszCmdLine, int nCmdShow)
  20.      {
  21.      static char szAppName [] = "Pump Demo w/o MFC" ;
  22.      HWND        hWnd ;
  23.      WNDCLASS    wc ;
  24.  
  25.      if (!hPrevInstance)
  26.           {
  27.           wc.style         = CS_HREDRAW | CS_VREDRAW ;
  28.           wc.lpfnWndProc   = WndProc ;
  29.           wc.cbClsExtra    = 0 ;
  30.           wc.cbWndExtra    = 0 ;
  31.           wc.hInstance     = hInstance ;
  32.           wc.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  33.           wc.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  34.           wc.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  35.           wc.lpszMenuName  = "MainMenu";
  36.           wc.lpszClassName = szAppName ;
  37.  
  38.           if (!RegisterClass (&wc)) return FALSE ;
  39.           }
  40.  
  41.      hWnd = CreateWindow (szAppName,         /* window class name       */
  42.                     "Message Pump w/o MFC",  /* window caption          */
  43.                     WS_OVERLAPPEDWINDOW,     /* window style            */
  44.                     CW_USEDEFAULT,           /* initial x position      */
  45.                     0,                       /* initial y position      */
  46.                     CW_USEDEFAULT,           /* initial x size          */
  47.                     0,                       /* initial y size          */
  48.                     NULL,                    /* parent window handle    */
  49.                     NULL,                    /* window menu handle      */
  50.                     hInstance,               /* program instance handle */
  51.                     NULL) ;                  /* create parameters       */
  52.  
  53.      ShowWindow   (hWnd, nCmdShow) ;
  54.      UpdateWindow (hWnd) ;
  55.  
  56.          MSG msg;
  57.  
  58.          while (GetMessage (&msg, NULL, 0, 0))
  59.          {
  60.          TranslateMessage (&msg) ;
  61.          DispatchMessage  (&msg) ;
  62.          }
  63.  
  64.      return msg.wParam ;
  65.      }
  66.  
  67.  
  68. long FAR PASCAL WndProc (HWND hwnd, unsigned iMessage,
  69.                          UINT wParam, LONG lParam)
  70.      {
  71.      switch (iMessage)
  72.           {
  73.           case WM_COMMAND:
  74.                {
  75.                switch (wParam)
  76.                     {
  77.                     case IDM_STARTPOSTMESSAGE:
  78.                          {
  79.                          SetWindowText (hwnd, "Calibrating Message Pump...");
  80.                          m_lMsgCount   = 0;
  81.                          m_ti.dwSize = sizeof (TIMERINFO);
  82.                          TimerCount (&m_ti);
  83.                          m_dwStartTime = m_ti.dwmsSinceStart;
  84.  
  85.                          if (m_lMsgCount < 10000)
  86.                            {
  87.                            m_lMsgCount++;
  88.                            }
  89.  
  90.                          TimerCount (&m_ti);
  91.                          m_dwStopTime = m_ti.dwmsSinceStart;
  92.                          m_dwCalibrationTime = m_dwStopTime - m_dwStartTime;
  93.  
  94.                          //   Now Start message pump
  95.                          //
  96.                          SetWindowText (hwnd,
  97.                                         "Posting 10,000 messages thru pump...");
  98.                          m_lMsgCount   = 0;
  99.                          TimerCount (&m_ti);
  100.                          m_dwStartTime = m_ti.dwmsSinceStart;
  101.                          PostMessage (hwnd, WM_USER, 0, 0);
  102.                          }
  103.                         return 0;
  104.  
  105.                     case IDM_STARTSENDMESSAGE:
  106.                          {
  107.                          SetWindowText (hwnd, "Calibrating Message Pump...");
  108.                          m_lMsgCount = 0;
  109.                          m_ti.dwSize = sizeof (TIMERINFO);
  110.                          TimerCount (&m_ti);
  111.                          m_dwStartTime = m_ti.dwmsSinceStart;
  112.  
  113.                          if (m_lMsgCount < 10000)
  114.                            {
  115.                            m_lMsgCount++;
  116.                            }
  117.  
  118.                          TimerCount (&m_ti);
  119.                          m_dwStopTime = m_ti.dwmsSinceStart;
  120.                          m_dwCalibrationTime = m_dwStopTime - m_dwStartTime;
  121.  
  122.                          //   Now Start message pump
  123.                          //
  124.                          SetWindowText (hwnd,
  125.                                         "Sending 10,000 messages thru pump...");
  126.                          m_lMsgCount   = 0;
  127.                          TimerCount (&m_ti);
  128.                          m_dwStartTime = m_ti.dwmsSinceStart;
  129.  
  130.                          while (m_lMsgCount < 10000)
  131.                            {
  132.                            SendMessage (hwnd, WM_USER+1, 0, 0);
  133.                            }
  134.  
  135.                          }
  136.                         return 0;
  137.                     }
  138.                }
  139.                return DefWindowProc (hwnd, iMessage, wParam, lParam) ;
  140.  
  141.           case WM_USER:
  142.                {
  143.                char string [40];
  144.  
  145.                m_lMsgCount++;
  146.  
  147.                if (m_lMsgCount < 10000)
  148.                  {
  149.                  // Keep message pump going
  150.                  //
  151.                  PostMessage (hwnd, WM_USER, 0, 0L);
  152.                  }
  153.  
  154.                else
  155.                  {
  156.                  // Stop message pump & display msg rate
  157.                  //
  158.                  TimerCount (&m_ti);
  159.                  m_dwStopTime = m_ti.dwmsSinceStart;
  160.  
  161.                  DWORD dwElapsedTime=(m_dwStopTime-m_dwStartTime) -
  162.                                       m_dwCalibrationTime;
  163.                  wsprintf(string, "Posted Msgs per second = %ld",
  164.                          (LONG) (1000. * ((double)m_lMsgCount/dwElapsedTime)));
  165.                  SetWindowText (hwnd, string);
  166.                  }
  167.                }
  168.               return 0;
  169.  
  170.            case WM_USER+1:
  171.                {
  172.                char string [40];
  173.  
  174.                m_lMsgCount++;
  175.  
  176.                if (m_lMsgCount >= 10000)
  177.                  {
  178.                  // Stop message pump & display msg rate
  179.                  //
  180.                  TimerCount (&m_ti);
  181.                  m_dwStopTime = m_ti.dwmsSinceStart;
  182.  
  183.                  DWORD dwElapsedTime = (m_dwStopTime - m_dwStartTime) -
  184.                                        m_dwCalibrationTime;
  185.                  wsprintf (string, "NO MFC: Sent Msgs per second = %ld",
  186.                           (LONG) (1000. * ((double)m_lMsgCount/dwElapsedTime)));
  187.                  SetWindowText (hwnd, string);
  188.                  }
  189.                }
  190.               return 0;
  191.  
  192.           }
  193.  
  194.          return DefWindowProc (hwnd, iMessage, wParam, lParam) ;
  195.      }
  196.