home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_12 / 2n12008a < prev    next >
Text File  |  1991-10-29  |  5KB  |  172 lines

  1. /*****************************************************/
  2. /*  mlebug.c                                         */
  3. /* -- This program attempts to create and destroy    */
  4. /*    MultiLine EditItems to test if the leaky MLE   */
  5. /*    bug is present.                                */
  6. /*****************************************************/
  7.  
  8. #define NOCOMM
  9. #include <windows.h>
  10. #include <stdio.h>
  11.  
  12. LONG                CwndTestMle(HWND);
  13. int     FAR PASCAL  WinMain(HANDLE, HANDLE, LPSTR,
  14.                         int);
  15. LONG    FAR PASCAL  WndProc(HWND, WORD, WORD, DWORD);
  16.  
  17. /* Status message. */
  18. static  char    szMessage[80]   = "Ready";
  19.  
  20. /* Maximum of MLE create/destroy pairs. */
  21. #define cwndTest    0x10000L
  22. #define szMleBug    "MLEBug"    /* Class name. */
  23. #define IDM_TEST    1           /* Menu command. */
  24.  
  25. int FAR PASCAL
  26. WinMain(HANDLE hins, HANDLE hinsPrev, LPSTR lsz, int w)
  27. /*****************************************************/
  28. /* -- hins        : This program's instance.         */
  29. /* -- hinsPrev    : Previous program's instance.     */
  30. /* -- lsz         : Command line I was invoked with. */
  31. /* -- w           : ShowWindow command.              */
  32. /*****************************************************/
  33.     {
  34.     MSG     msg;
  35.     POINT   pt;
  36.  
  37.     if (hinsPrev == NULL)
  38.         {
  39.         WNDCLASS    wcs;
  40.  
  41.         /* First instance is responsible for */
  42.         /* registering a class. */
  43.         wcs.style = CS_HREDRAW | CS_VREDRAW;
  44.         wcs.lpfnWndProc = WndProc;
  45.         wcs.cbClsExtra = 0;
  46.         wcs.cbWndExtra = 0;
  47.         wcs.hInstance = hins;
  48.         wcs.hIcon = NULL;
  49.         wcs.hCursor = LoadCursor(NULL, IDC_ARROW);
  50.         wcs.hbrBackground =
  51.             GetStockObject(WHITE_BRUSH);
  52.         wcs.lpszMenuName = szMleBug;
  53.         wcs.lpszClassName = szMleBug;
  54.  
  55.         if (!RegisterClass(&wcs))
  56.             return FALSE;
  57.         }
  58.  
  59.     *(LONG *)&pt = GetDialogBaseUnits();
  60.     if (CreateWindow(
  61.         szMleBug,
  62.         "MLE Bug Tester",
  63.         WS_OVERLAPPEDWINDOW | WS_VISIBLE,
  64.         CW_USEDEFAULT,
  65.         w,
  66.         pt.x * 40,      /* 40 chars wide. */
  67.         pt.y * 5,       /* 5 char high. */
  68.         NULL,
  69.         NULL,
  70.         hins,
  71.         NULL) == NULL)
  72.         return FALSE;
  73.  
  74.         while (GetMessage(&msg, NULL, 0, 0))
  75.             {
  76.             TranslateMessage(&msg);
  77.             DispatchMessage(&msg);
  78.             }
  79.  
  80.         return 0;
  81.         }
  82.  
  83. LONG FAR PASCAL
  84. WndProc(HWND hwnd, WORD wm, WORD mp1, DWORD mp2)
  85. /*****************************************************/
  86. /* -- WindowProc for our main window.                */
  87. /* -- hwnd    : Main window.                         */
  88. /* -- wm      : Message type.                        */
  89. /* -- mp1, mp2: Message parameters.                  */
  90. /*****************************************************/
  91.     {
  92.     switch (wm)
  93.         {
  94.     default:
  95.         return DefWindowProc(hwnd, wm, mp1, mp2);
  96.  
  97.     case WM_DESTROY:
  98.         PostQuitMessage(0);
  99.         break;
  100.  
  101.     case WM_COMMAND:
  102.         if (mp1 == IDM_TEST)
  103.             {
  104.             LONG    cwnd    = CwndTestMle(hwnd);
  105.  
  106.             sprintf(szMessage, "%ld edits: %s", cwnd,
  107.                 cwnd == cwndTest ? "Ok" :
  108.                    "Leaky edit");
  109.             InvalidateRect(hwnd, NULL, TRUE);
  110.             }
  111.         break;
  112.  
  113.     case WM_PAINT:
  114.         {
  115.         PAINTSTRUCT wps;
  116.         RECT        rect;
  117.  
  118.         BeginPaint(hwnd, &wps);
  119.         GetClientRect(hwnd, &rect);
  120.         DrawText(wps.hdc, szMessage, -1, &rect,
  121.             DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  122.         EndPaint(hwnd, &wps);
  123.         }
  124.         break;  /* End case WM_PAINT. */
  125.         }       /* End switch wm. */
  126.     return 0L;
  127.     }
  128.  
  129. LONG
  130. CwndTestMle(HWND hwndReport)
  131. /*****************************************************/
  132. /* -- We do the actual work here.                    */
  133. /* -- Create and destroy an MLE window, repeatedly,  */
  134. /*    cwndTest times or until CreateWindow() fails.  */
  135. /* -- Return the number of MLE's we were able to     */
  136. /*    create.                                        */
  137. /* -- hwndReport  : Window to display results into.  */
  138. /*****************************************************/
  139.     {
  140.     LONG    iwnd;
  141.     HANDLE    hins;
  142.  
  143.     hins = GetWindowWord(hwndReport, GWW_HINSTANCE);
  144.     for (iwnd = 1L; iwnd <= cwndTest; iwnd++)
  145.         {
  146.         HWND    hwnd;
  147.  
  148.         if ((hwnd = CreateWindow(
  149.             "edit",
  150.             NULL,
  151.             WS_CHILD | ES_MULTILINE | WS_VSCROLL,
  152.             0, 0, 0, 0,
  153.             hwndReport,
  154.             1,
  155.             hins, NULL)) == NULL)
  156.             break;
  157.  
  158.         DestroyWindow(hwnd);
  159.  
  160.         if (iwnd % 10L == 0L)
  161.             {
  162.             /* Display every 10 times. */
  163.             sprintf(szMessage, "%ld MLEs", iwnd);
  164.             InvalidateRect(hwndReport, NULL, TRUE);
  165.             UpdateWindow(hwndReport);
  166.             }
  167.         }
  168.  
  169.     return iwnd - 1L;
  170.     }
  171.  
  172.