home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / msysjour / vol07 / 01 / heappeep / hp1.c < prev    next >
Text File  |  1991-12-31  |  7KB  |  237 lines

  1. //   HeapPeep (c) 1991 Chiverton Graphics, Inc.
  2. //
  3. //               Microsoft Windows Debugging Utility
  4. //               This version does not use ToolHelp.DLL
  5. //
  6. #include <windows.h>
  7. #include "hp2.h"
  8.  
  9.  
  10. #define IDM_ABOUT   1
  11. #define IDD_LOGO  101
  12.  
  13.  
  14. long  FAR PASCAL WndProc      (HWND hWnd, unsigned message, WORD wParam,
  15.                                                             LONG lParam);
  16. BOOL  FAR PASCAL AboutDlgProc (HWND hWnd, unsigned message, WORD wParam,
  17.                                                             LONG lParam);
  18.  
  19.  
  20. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine,
  21.                                                               int nCmdShow)
  22.      {
  23.      MSG      msg;
  24.      WNDCLASS wc;
  25.      HWND     hwnd;
  26.  
  27.  
  28.       if (hwnd = FindWindow ("HeapPeep", NULL))
  29.          {
  30.          // Found another running application with the same class
  31.          // name... so one instance is already running. Don't run a 2nd instance
  32.  
  33.          BringWindowToTop (hwnd);
  34.          return (FALSE);
  35.          }
  36.  
  37.      if (GetWinFlags() & WF_LARGEFRAME)
  38.         {
  39.         MessageBox (GetFocus(),
  40.         "HeapPeep cannot run with Large Frame EMS memory. (Try c:> win /r/n).",
  41.         "HeapPeep", MB_OK | MB_SYSTEMMODAL);
  42.         return (FALSE);
  43.         }
  44.  
  45.      wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
  46.      wc.hIcon         = LoadIcon (hInstance, "HeapPeep");
  47.      wc.cbClsExtra    = 0;
  48.      wc.cbWndExtra    = 0;
  49.      wc.lpszMenuName  = NULL;
  50.      wc.lpszClassName = "HeapPeep";
  51.      wc.hbrBackground = GetStockObject (WHITE_BRUSH);
  52.      wc.hInstance     = hInstance;
  53.      wc.style         = CS_VREDRAW | CS_HREDRAW;
  54.      wc.lpfnWndProc   = WndProc;
  55.  
  56.      RegisterClass (&wc);
  57.  
  58.      hwnd = CreateWindow ("HeapPeep",
  59.                           "HeapPeep (non-ToolHelp version)",
  60.                           WS_OVERLAPPEDWINDOW,
  61.                           CW_USEDEFAULT, 0,
  62.                           CW_USEDEFAULT, 0,
  63.                           NULL, NULL, hInstance,
  64.                           NULL);
  65.  
  66.      ShowWindow (hwnd, nCmdShow);
  67.  
  68.  
  69.      //    set up timer (2 updates/sec)
  70.      //
  71.      if (!SetTimer (hwnd, 1, 500, NULL))
  72.           {
  73.           MessageBox (GetFocus(), "Too many Timers or Clocks!",
  74.                                   "HeapPeep", MB_OK | MB_SYSTEMMODAL);
  75.           return (FALSE);
  76.           }
  77.  
  78.  
  79.      while (GetMessage (&msg, NULL, 0, 0))
  80.           {
  81.           TranslateMessage (&msg);
  82.           DispatchMessage  (&msg);
  83.           }
  84.  
  85.      return (int) msg.wParam;
  86.      }
  87.  
  88.  
  89.  
  90. BOOL FAR PASCAL AboutDlgProc (HWND hDlg, unsigned m, WORD w, LONG l)
  91.      {
  92.      static HBITMAP hbm;
  93.  
  94.      switch (m)
  95.           {
  96.           case WM_INITDIALOG:
  97.                {
  98.                int cxScreen, cyScreen, cxDialog, cyDialog;
  99.                RECT rcDialog;
  100.  
  101.                //
  102.                //   Create the logo bitmap, and
  103.                //   center the dialogbox on the display.
  104.                //
  105.                hbm = LoadBitmap (GetWindowWord (hDlg, GWW_HINSTANCE), "logo");
  106.  
  107.  
  108.                //   Get the Display size
  109.                //
  110.                cxScreen = GetSystemMetrics (SM_CXSCREEN);
  111.                cyScreen = GetSystemMetrics (SM_CYSCREEN);
  112.  
  113.                //   Get the DialogBox size
  114.                //
  115.                GetWindowRect (hDlg, &rcDialog);
  116.                cxDialog = rcDialog.right  - rcDialog.left;
  117.                cyDialog = rcDialog.bottom - rcDialog.top ;
  118.  
  119.                SetWindowPos (hDlg, NULL, (cxScreen - cxDialog)/2, // x
  120.                                          (cyScreen - cyDialog)/2, // y
  121.                                           cxDialog,               // cx
  122.                                           cyDialog,               // cy
  123.                                           SWP_NOZORDER);
  124.                }
  125.                return FALSE;
  126.  
  127.           case WM_PAINT:
  128.                {
  129.                HDC hdcMem;
  130.                PAINTSTRUCT ps;
  131.                HBITMAP hbmOld;
  132.                HWND hwndLogo;
  133.                RECT rcLogo,
  134.                     rcDialog;
  135.                int  x,y;
  136.  
  137.                BeginPaint (hDlg, &ps);
  138.  
  139.                hdcMem = CreateCompatibleDC (ps.hdc);
  140.                hbmOld = SelectObject (hdcMem, hbm);
  141.  
  142.                SetTextColor (ps.hdc, RGB (255, 0, 255));
  143.  
  144.                hwndLogo = GetDlgItem (hDlg, IDD_LOGO);
  145.                GetWindowRect (hwndLogo, &rcLogo);
  146.                GetWindowRect (hDlg,     &rcDialog );
  147.                x = rcLogo.left - rcDialog.left;
  148.                y = rcLogo.top  - rcDialog.top ;
  149.  
  150.                BitBlt (ps.hdc, x, y, 200, 200, hdcMem, 0, 0, SRCCOPY);
  151.                SelectObject (hdcMem, hbmOld) ;
  152.                DeleteDC (hdcMem);
  153.  
  154.                EndPaint (hDlg, &ps);
  155.  
  156.                return FALSE;
  157.                }
  158.  
  159.           case WM_DESTROY:
  160.                DeleteObject (hbm);
  161.                return FALSE;
  162.  
  163.           case WM_COMMAND:
  164.                EndDialog (hDlg, 0);
  165.                return TRUE;
  166.           }
  167.  
  168.      return FALSE ;
  169.      }
  170.  
  171.  
  172.  
  173. long FAR PASCAL WndProc (HWND hwnd, unsigned message, WORD wParam, LONG lParam)
  174.      {
  175.      switch (message)
  176.           {
  177.           case WM_CREATE:
  178.                {
  179.                HMENU hMenu    = GetSystemMenu (hwnd, FALSE);
  180.                int   cxScreen = GetSystemMetrics (SM_CXSCREEN),
  181.                      cyScreen = GetSystemMetrics (SM_CYSCREEN);
  182.  
  183.                dds_create (hwnd);
  184.  
  185.  
  186.                //   Add "About Heappeep..." to system menu
  187.  
  188.                ChangeMenu (hMenu, 0, NULL, 0, MF_APPEND);
  189.                ChangeMenu (hMenu, 0, "A&bout Heappeep...", IDM_ABOUT,
  190.                                                            MF_APPEND);
  191.  
  192.  
  193.                //   Position the window in the lower 1/3 of the display.
  194.  
  195.                SetWindowPos (hwnd, NULL, 0,                 // x
  196.                                          (2 * cyScreen)/3,  // y
  197.                                          cxScreen,          // cx
  198.                                          cyScreen/3,        // cy
  199.                                          SWP_NOZORDER);
  200.                }
  201.                return  0L;
  202.  
  203.           case WM_TIMER:
  204.                dds_walk ();
  205.                return  0L;
  206.  
  207.           case WM_SYSCOMMAND:
  208.                if (wParam == IDM_ABOUT)
  209.                     {
  210.                     HANDLE  hInstance = (HANDLE)GetWindowWord (hwnd,
  211.                                                                GWW_HINSTANCE);
  212.                     FARPROC lpfn      = MakeProcInstance ((FARPROC)AboutDlgProc,
  213.                                                                      hInstance);
  214.  
  215.                     DialogBox (hInstance, "AboutBox", hwnd, lpfn);
  216.                     FreeProcInstance (lpfn) ;
  217.                     return 0L;
  218.                     }
  219.                break;
  220.  
  221.           case WM_PAINT:
  222.                dds_paint ();
  223.                return  0L;
  224.  
  225.           case WM_DESTROY:
  226.                dds_destroy ();
  227.                KillTimer (hwnd, 1);
  228.                PostQuitMessage (0);
  229.                return  0L;
  230.  
  231.           default:
  232.                break;
  233.           }
  234.  
  235.      return DefWindowProc (hwnd, message, wParam, lParam);
  236.      }
  237.