home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / PCTV3N1.ZIP / SKETCH.ZIP / QSKETCH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-06  |  8.9 KB  |  211 lines

  1. /* QuickCase:W KNB Version 1.00 */
  2. /* QSKETCH.C by Tom Swan */
  3. #include "QSKETCH.h"
  4.  
  5. /*!*/ int dragging;
  6. /*!*/ HDC dc;
  7.  
  8. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  9.   LPSTR lpszCmdLine, int nCmdShow)
  10. {
  11.  /*************************************************************/
  12.  /* HANDLE hInstance;       handle for this instance          */
  13.  /* HANDLE hPrevInstance;   handle for possible prev instances*/
  14.  /* LPSTR  lpszCmdLine;     long pointer to exec command line */
  15.  /* int    nCmdShow;        Show code for main window display */
  16.  /*************************************************************/
  17.  MSG        msg;    /* MSG structure to store your messages */
  18.  int        nRc;    /* return value from Register Classes   */
  19.  
  20.  strcpy(szAppName, "QSKETCH");
  21.  hInst = hInstance;
  22.  if(!hPrevInstance)
  23.    {
  24.    /* register window classes if first instance of application*/
  25.     if ((nRc = nCwRegisterClasses()) == -1)
  26.       {
  27.        /* registering one of the windows failed */
  28.        LoadString(hInst, IDS_ERR_REGISTER_CLASS, szString,
  29.          sizeof(szString));
  30.        MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION);
  31.        return nRc;
  32.       }
  33.    }
  34.  
  35.  /* create application's Main window */
  36.  hWndMain = CreateWindow(
  37.                 szAppName,             /* Window class name    */
  38.                 "QuickCase:W Sketch",  /* Window's title       */
  39.                 WS_CAPTION      |      /* Title and Min/Max    */
  40.                 WS_SYSMENU      |      /* Add system menu box  */
  41.                 WS_MINIMIZEBOX  |      /* Add minimize box     */
  42.                 WS_MAXIMIZEBOX  |      /* Add maximize box     */
  43.                 WS_THICKFRAME   |      /* thick sizeable frame */
  44.                 WS_CLIPCHILDREN | /*don't draw in child windows*/
  45.                 WS_OVERLAPPED,
  46.                 CW_USEDEFAULT, 0,     /* Use default X, Y      */
  47.                 CW_USEDEFAULT, 0,     /* Use default X, Y      */
  48.                 NULL,                 /* Parent window's handle*/
  49.                 NULL,                 /* Default to Class Menu */
  50.                 hInst,                /* Instance of window    */
  51.                 NULL);          /* Create struct for WM_CREATE */
  52.  if(hWndMain == NULL)
  53.    {
  54.     LoadString(hInst, IDS_ERR_CREATE_WINDOW, szString,
  55.       sizeof(szString));
  56.     MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION);
  57.     return IDS_ERR_CREATE_WINDOW;
  58.    }
  59.  ShowWindow(hWndMain, nCmdShow); /* display main window      */
  60.  
  61. /*!*/ dragging = FALSE;
  62.  
  63.  while(GetMessage(&msg, NULL, 0, 0)) /* Until WM_QUIT message */
  64.    {
  65.     TranslateMessage(&msg);
  66.     DispatchMessage(&msg);
  67.    }
  68.  /* Do clean up before exiting from the application */
  69.  CwUnRegisterClasses();
  70.  return msg.wParam;
  71. } /*  End of WinMain */
  72. /***************************************************************/
  73. /*                                                             */
  74. /* Main Window Procedure                                       */
  75. /*                                                             */
  76. /* This procedure provides routines for the Windows events     */
  77. /* (messages) that Windows sends to the window, plus user      */
  78. /* initiated events (messages) generated when the user selects */
  79. /* the action bar and pulldown menu controls or corresponding  */
  80. /* keyboard accelerators.                                      */
  81. /*                                                             */
  82. /***************************************************************/
  83. LONG FAR PASCAL WndProc(HWND hWnd, WORD Message, WORD wParam,
  84.   LONG lParam)
  85. {
  86.  HMENU      hMenu=0;   /* handle for the menu                 */
  87.  HBITMAP    hBitmap=0; /* handle for bitmaps                  */
  88.  HDC        hDC;       /* handle for the display device       */
  89.  PAINTSTRUCT ps;       /* holds PAINT information             */
  90.  int        nRc=0;     /* return code                         */
  91.  
  92.  switch (Message)
  93.    {
  94.     case WM_COMMAND:
  95.          /* The Windows messages for action bar and menu items*/
  96.          /* are processed here.                               */
  97.          switch (wParam)
  98.            {
  99.             case IDM_M_ERASE:
  100.                  /* Place User Code to respond to the         */
  101.                  /* Menu Item Named "&Erase" here.            */
  102. /*!*/            InvalidateRect(hWnd, NULL, TRUE);
  103.                  break;
  104.             case IDM_M_EXIT:
  105.                  /* Place User Code to respond to the         */
  106.                  /* Menu Item Named "E&xit" here.             */
  107. /*!*/            PostQuitMessage(0);
  108.                  break;
  109.             default:
  110.                 return DefWindowProc(hWnd, Message, wParam,
  111.                   lParam);
  112.            }
  113.          break;        /* End of WM_COMMAND                   */
  114. /*!*/   case WM_LBUTTONDOWN:
  115. /*!*/        if (!dragging) {
  116. /*!*/          dragging = TRUE;
  117. /*!*/          SetCapture(hWnd);
  118. /*!*/           dc = GetDC(hWnd);
  119. /*!*/           MoveTo(dc, LOWORD(lParam), HIWORD(lParam));
  120. /*!*/         }
  121. /*!*/         break;
  122. /*!*/    case WM_LBUTTONUP:
  123. /*!*/         if (dragging) {
  124. /*!*/           ReleaseCapture();
  125. /*!*/           ReleaseDC(hWnd, dc);
  126. /*!*/           dragging = FALSE;
  127. /*!*/          }
  128. /*!*/         break;
  129. /*!*/    case WM_MOUSEMOVE:
  130. /*!*/         if (dragging)
  131. /*!*/           LineTo(dc, LOWORD(lParam), HIWORD(lParam));
  132. /*!*/         break;
  133.     case WM_CREATE:
  134.          break;       /*  End of WM_CREATE                    */
  135.     case WM_MOVE:     /*  code for moving the window          */
  136.          break;
  137.     case WM_SIZE:     /*  code for sizing client area         */
  138.          break;       /* End of WM_SIZE                       */
  139.     case WM_PAINT:    /* code for the window's client area    */
  140.          /* Obtain a handle to the device context             */
  141.          /* BeginPaint will sends WM_ERASEBKGND if appropriate*/
  142.          memset(&ps, 0x00, sizeof(PAINTSTRUCT));
  143.          hDC = BeginPaint(hWnd, &ps);
  144.          /* Included in case the background is not pure color */
  145.          SetBkMode(hDC, TRANSPARENT);
  146.          /* Inform Windows painting is complete               */
  147.          EndPaint(hWnd, &ps);
  148.          break;       /*  End of WM_PAINT                     */
  149.     case WM_CLOSE:  /* close the window                       */
  150.          /* Destroy child windows, modeless dialogs, window   */
  151.          DestroyWindow(hWnd);
  152.          if (hWnd == hWndMain)
  153.            PostQuitMessage(0);  /* Quit the application       */
  154.         break;
  155.     default:
  156. /* For any message for which you don't specifically provide a */
  157. /* service routine, you should return the message to Windows  */
  158. /* for default message processing.                            */
  159.          return DefWindowProc(hWnd, Message, wParam, lParam);
  160.    }
  161.  return 0L;
  162. }     /* End of WndProc */
  163.  
  164. /**************************************************************/
  165. /*                                                            */
  166. /* nCwRegisterClasses Function                                */
  167. /*                                                            */
  168. /* The following function registers classes of all windows    */
  169. /* associated with this application. Returns an error code    */
  170. /* if unsuccessful, otherwise it returns 0.                   */
  171. /*                                                            */
  172. /**************************************************************/
  173.  
  174. int nCwRegisterClasses(void)
  175. {
  176.  WNDCLASS   wndclass;    /* struct to define a window class   */
  177.  memset(&wndclass, 0x00, sizeof(WNDCLASS));
  178.  
  179.  /* load WNDCLASS with window's characteristics               */
  180.  wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW;
  181.  wndclass.lpfnWndProc = WndProc;
  182.  /* Extra storage for Class and Window objects                */
  183.  wndclass.cbClsExtra = 0;
  184.  wndclass.cbWndExtra = 0;
  185.  wndclass.hInstance = hInst;
  186.  wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  187.  wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  188.  /* Create brush for erasing background                       */
  189.  wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  190.  wndclass.lpszMenuName = szAppName;  /* Menu Name is App Name */
  191.  wndclass.lpszClassName = szAppName;/* Class Name is App Name */
  192.  if(!RegisterClass(&wndclass))
  193.    return -1;
  194.  return(0);
  195. } /* End of nCwRegisterClasses */
  196.  
  197. /**************************************************************/
  198. /*  CwUnRegisterClasses Function                              */
  199. /*                                                            */
  200. /*  Deletes refrences to windows resources created for this   */
  201. /*  application, frees memory, deletes instance, handles and  */
  202. /*  cleans up prior to exiting the window                     */
  203. /*                                                            */
  204. /**************************************************************/
  205. void CwUnRegisterClasses(void)
  206. {
  207.  WNDCLASS   wndclass;    /* struct to define a window class */
  208.  memset(&wndclass, 0x00, sizeof(WNDCLASS));
  209.  UnregisterClass(szAppName, hInst);
  210. }    /* End of CwUnRegisterClasses */
  211.