Annotation of q_a/samples/angle/angle.c, revision 1.1.1.3

1.1.1.3 ! root        1: 
        !             2: /******************************************************************************\
        !             3: *       This is a part of the Microsoft Source Code Samples. 
        !             4: *       Copyright (C) 1993 Microsoft Corporation.
        !             5: *       All rights reserved. 
        !             6: *       This source code is only intended as a supplement to 
        !             7: *       Microsoft Development Tools and/or WinHelp documentation.
        !             8: *       See these sources for detailed information regarding the 
        !             9: *       Microsoft samples programs.
        !            10: \******************************************************************************/
1.1       root       11: 
                     12: 
                     13: #include <windows.h>
                     14: #include <math.h>
                     15: #include <string.h>
                     16: #include "angle.h"
                     17: 
1.1.1.3 ! root       18: HANDLE              hInst;
        !            19: HWND                hwndMain, hwndDlg;
1.1       root       20: 
                     21: 
                     22: /**************************************************************************\
                     23: *
                     24: *  function:  WinMain()
                     25: *
                     26: *  input parameters:  c.f. generic sample
                     27: *
                     28: \**************************************************************************/
1.1.1.3 ! root       29: int APIENTRY 
        !            30: WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        !            31:         LPSTR lpCmdLine, int nCmdShow)
1.1       root       32: {
1.1.1.3 ! root       33:     MSG                 msg;
        !            34:     RECT                rect;
1.1       root       35: 
1.1.1.3 ! root       36:     UNREFERENCED_PARAMETER(lpCmdLine);
1.1       root       37: 
                     38: 
1.1.1.3 ! root       39:  /* Check for previous instance.  If none, then register class. */
        !            40:     if (!hPrevInstance)
        !            41:     {
        !            42:         WNDCLASS            wc;
1.1       root       43: 
1.1.1.3 ! root       44:         wc.style = 0;
        !            45:         wc.lpfnWndProc = (WNDPROC) MainWndProc;
1.1       root       46: 
                     47:         wc.cbClsExtra = 0;
                     48:         wc.cbWndExtra = 0;
                     49:         wc.hInstance = hInstance;
                     50:         wc.hIcon = LoadIcon(hInstance, "AngleIcon");
                     51:         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
                     52:         wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
1.1.1.3 ! root       53:         wc.lpszMenuName = NULL;
1.1       root       54:         wc.lpszClassName = "angle";
                     55: 
1.1.1.3 ! root       56:         if (!RegisterClass(&wc))
        !            57:             return (FALSE);
        !            58:     }   /* class registered o.k. */
        !            59:  /*  Create the main window.  Return false if CreateWindow() fails */
1.1       root       60:     hInst = hInstance;
                     61: 
                     62:     hwndMain = CreateWindow(
1.1.1.3 ! root       63:                             "angle",
        !            64:                             "AngleArc",
        !            65:                             WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
        !            66:                             CW_USEDEFAULT,
        !            67:                             CW_USEDEFAULT,
        !            68:                             CW_USEDEFAULT,
        !            69:                             CW_USEDEFAULT,
        !            70:                             NULL,
        !            71:                             NULL,
        !            72:                             hInstance,
        !            73:                             NULL);
1.1       root       74: 
1.1.1.3 ! root       75:     if (!hwndMain)
        !            76:         return (FALSE);
1.1       root       77:     ShowWindow(hwndMain, nCmdShow);
                     78:     UpdateWindow(hwndMain);
                     79: 
                     80: 
1.1.1.3 ! root       81:  /* create the top dialog as a child of the main window. */
        !            82:     hwndDlg = CreateDialog(hInst, "AngleDlg", hwndMain, (DLGPROC) DlgProc);
1.1       root       83: 
1.1.1.3 ! root       84:  /*
        !            85:   * Send main window a WM_SIZE message so that it will size the top dialog
        !            86:   * correctly.  Also, force a repaint of the main window now that the dialog is
        !            87:   * there and we can draw the arc. 
        !            88:   */
        !            89:     GetClientRect(hwndMain, &rect);
        !            90:     SendMessage(hwndMain, WM_SIZE, 0, (rect.right - rect.left));
        !            91:     ShowWindow(hwndDlg, SW_SHOW);
        !            92:     InvalidateRect(hwndMain, NULL, FALSE);
        !            93: 
        !            94:  /* Loop getting messages and dispatching them. */
        !            95:     while (GetMessage(&msg, NULL, 0, 0))
        !            96:     {
        !            97:         if (!IsDialogMessage(hwndDlg, &msg))
        !            98:         {
        !            99:             TranslateMessage(&msg);
        !           100:             DispatchMessage(&msg);
        !           101:         }
1.1       root      102:     }
                    103: 
                    104:     return (msg.wParam);
                    105: }
                    106: 
                    107: 
                    108: 
                    109: /**************************************************************************\
                    110: *
                    111: *  function:  MainWndProc()
                    112: *
                    113: *  input parameters:  normal window procedure parameters.
                    114: *
                    115: *  global variables:
                    116: *   hwndDlg - dialog with entry fields containing arc parameters.
                    117: *
                    118: \**************************************************************************/
1.1.1.3 ! root      119: LONG APIENTRY 
        !           120: MainWndProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
1.1       root      121: {
1.1.1.3 ! root      122:     char                buffer[MAXCHARS];
        !           123:     static HANDLE       hPenGrid, hPenArc;
1.1       root      124: 
1.1.1.3 ! root      125:     switch (message)
        !           126:     {
1.1       root      127: 
1.1.1.3 ! root      128:         /**********************************************************************\
        !           129:         *  WM_CREATE
        !           130:         *
        !           131:         *  Then create three pens for drawing with later.
        !           132:         \**********************************************************************/
        !           133:         case WM_CREATE:
        !           134:             hPenGrid = CreatePen(PS_SOLID, 1, GRIDCOLOR);
        !           135:             hPenArc = CreatePen(PS_SOLID, 2, (COLORREF) 0x01000005);
        !           136:             break;
1.1       root      137: 
                    138: 
1.1.1.3 ! root      139:         /**********************************************************************\
        !           140:         *  WM_DESTROY
        !           141:         *
        !           142:         * Complement of the WM_CREATE message.  Delete the pens that were
        !           143:         *  created and then call postquitmessage.
        !           144:         \**********************************************************************/
        !           145:         case WM_DESTROY:
        !           146:             DeleteObject(hPenGrid);
        !           147:             DeleteObject(hPenArc);
1.1       root      148: 
1.1.1.3 ! root      149:             PostQuitMessage(0);
1.1       root      150:             break;
                    151: 
                    152: 
1.1.1.3 ! root      153:         /**********************************************************************\
        !           154:         *  WM_SIZE
        !           155:         *
        !           156:         * Stretch the top dialog to fill the width of the main window.
        !           157:         \**********************************************************************/
        !           158:         case WM_SIZE:
        !           159:             SetWindowPos(hwndDlg, NULL, 0, 0, LOWORD(lParam), DIALOGHEIGHT, 0);
1.1       root      160:             break;
                    161: 
                    162: 
                    163: 
1.1.1.3 ! root      164:         /**********************************************************************\
        !           165:         *  WM_PAINT
        !           166:         *
        !           167:         * First shift the viewport origin down so that 0,0 is the top left
        !           168:         *  most visible point (out from underneath the top dialog).  Second,
        !           169:         *  draw the grid with wider lines on the axes.  Finally, read the
        !           170:         *  values out of the top dialog, do elementary validation, and then
        !           171:         *  try to call AngleArc() with the values.  If a value fails validation,
        !           172:         *  then write a small error message, and don't draw the arc.
        !           173:         \**********************************************************************/
        !           174:         case WM_PAINT:
        !           175:             {
        !           176:                 HDC                 hdc;
        !           177:                 PAINTSTRUCT         ps;
        !           178:                 RECT                rect;
        !           179:                 int                 i;
        !           180:                 int                 x, y, radius;
        !           181:                 float               start, sweep;
        !           182:                 BOOL                success;
        !           183: 
        !           184:                 hdc = BeginPaint(hwnd, &ps);
        !           185: 
        !           186:                 SetViewportOrgEx(hdc, 0, DIALOGHEIGHT, NULL);
        !           187: 
        !           188:                 GetClientRect(hwndMain, &rect);
        !           189: 
        !           190:                 SelectObject(hdc, hPenGrid);
        !           191:             /* Draw vertical lines.  */
        !           192:                 for (i = 0; i <= rect.right; i += TICKSPACE)
        !           193:                 {
        !           194:                     MoveToEx(hdc, i, rect.top, NULL);
        !           195:                     LineTo(hdc, i, rect.bottom);
        !           196:                 }
        !           197:                 MoveToEx(hdc, 1, 0, NULL);
        !           198:                 LineTo(hdc, 1, rect.bottom);
        !           199: 
        !           200:             /* Draw horizontal lines.  */
        !           201:                 for (i = 0; i <= rect.bottom; i += TICKSPACE)
        !           202:                 {
        !           203:                     MoveToEx(hdc, rect.left, i, NULL);
        !           204:                     LineTo(hdc, rect.right, i);
        !           205:                 }
        !           206:                 MoveToEx(hdc, 0, 1, NULL);
        !           207:                 LineTo(hdc, rect.right, 1);
        !           208: 
        !           209:             /* new color pen for the actual arc. */
        !           210:                 SelectObject(hdc, hPenArc);
        !           211: 
        !           212: 
        !           213:             /*
        !           214:              * Query the top dialog parameters, if a value is bad, report that
        !           215:              * and break out of conditional. if all values are good, then set
        !           216:              * the current point and call AngleArc(). 
        !           217:              */
        !           218:                 if (IsWindow(hwndDlg))
        !           219:                 {
        !           220:                     x = GetDlgItemInt(hwndDlg, DID_X, &success, TRUE);
        !           221:                     if (!success)
        !           222:                     {
        !           223:                         TextOut(hdc, 10, rect.bottom - 2 * DIALOGHEIGHT, "Bad X", 5);
        !           224:                         break;
        !           225:                     }
        !           226:                     y = GetDlgItemInt(hwndDlg, DID_Y, &success, TRUE);
        !           227:                     if (!success)
        !           228:                     {
        !           229:                         TextOut(hdc, 30, rect.bottom - 2 * DIALOGHEIGHT, "Bad Y", 5);
        !           230:                         break;
        !           231:                     }
        !           232:                     radius = GetDlgItemInt(hwndDlg, DID_RADIUS, &success, TRUE);
        !           233:                     if (!success)
        !           234:                     {
        !           235:                         TextOut(hdc, 50, rect.bottom - 2 * DIALOGHEIGHT, "Bad Radius", 10);
        !           236:                         break;
        !           237:                     }
        !           238: 
        !           239:                 /*
        !           240:                  * Hard to validate these floating point numbers. Good chance
        !           241:                  * that invalid values will just map to 0.0 
        !           242:                  */
        !           243:                     if (!GetDlgItemText(hwndDlg, DID_START, buffer, MAXCHARS))
        !           244:                     {
        !           245:                         TextOut(hdc, 70, rect.bottom - 2 * DIALOGHEIGHT, "Bad Start", 9);
        !           246:                         break;
        !           247:                     }
        !           248:                     start = (float) atof(buffer);
        !           249: 
        !           250:                     if (!GetDlgItemText(hwndDlg, DID_SWEEP, buffer, MAXCHARS))
        !           251:                     {
        !           252:                         TextOut(hdc, 90, rect.bottom - 2 * DIALOGHEIGHT, "Bad Sweep", 9);
        !           253:                         break;
        !           254:                     }
        !           255:                     sweep = (float) atof(buffer);
        !           256: 
        !           257:                     MoveToEx(hdc, x, y, NULL);
        !           258: 
        !           259:                 /**********************************************************/
        !           260:                 /**********************************************************/
        !           261:                     AngleArc(hdc, x, y, (DWORD) radius, start, sweep);
        !           262:                 /**********************************************************/
        !           263:                 /**********************************************************/
        !           264:                 }
        !           265:                 EndPaint(hwnd, &ps);
1.1       root      266: 
1.1.1.3 ! root      267:             } return FALSE;
1.1       root      268: 
1.1.1.3 ! root      269:     }   /* end switch */
        !           270:     return (DefWindowProc(hwnd, message, wParam, lParam));
1.1       root      271: }
                    272: 
                    273: 
                    274: 
                    275: 
                    276: /**************************************************************************\
                    277: *
                    278: *  function:  DlgProc()
                    279: *
                    280: *  input parameters:  normal window procedure parameters.
                    281: *
                    282: *  global variables:
                    283: *   hwndmain - the main window.  also the parent of this dialog
                    284: *
                    285: \**************************************************************************/
1.1.1.3 ! root      286: LONG APIENTRY 
        !           287: DlgProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
1.1       root      288: {
1.1.1.3 ! root      289:     UNREFERENCED_PARAMETER(lParam);
1.1       root      290: 
1.1.1.3 ! root      291:     switch (message)
        !           292:     {
        !           293:         /**********************************************************************\
        !           294:         *  WM_INITDIALOG
        !           295:         *
        !           296:         * Fill the entry fields with sensible original values.
        !           297:         \**********************************************************************/
        !           298:         case WM_INITDIALOG:
        !           299:             SetDlgItemText(hwnd, DID_X, "100");
        !           300:             SetDlgItemText(hwnd, DID_Y, "100");
        !           301:             SetDlgItemText(hwnd, DID_RADIUS, "50");
        !           302:             SetDlgItemText(hwnd, DID_START, "0.0");
        !           303:             SetDlgItemText(hwnd, DID_SWEEP, "270.0");
        !           304:             return TRUE;
1.1       root      305: 
                    306: 
                    307: 
1.1.1.3 ! root      308:         /**********************************************************************\
        !           309:         *  WM_COMMAND, DID_DRAW
        !           310:         *
        !           311:         * Invalidate the main window so that we force a repaint.
        !           312:         \**********************************************************************/
        !           313:         case WM_COMMAND:
        !           314:             if (LOWORD(wParam) == DID_DRAW)
        !           315:             {
        !           316:                 InvalidateRect(hwndMain, NULL, TRUE);
        !           317:             }
        !           318:             return FALSE;
1.1       root      319: 
                    320: 
1.1.1.3 ! root      321:     }   /* end switch */
        !           322:     return 0;
1.1       root      323: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.