Annotation of pmsdk/samples/petzold/chap11/drawline.c, revision 1.1

1.1     ! root        1: /*--------------------------------------------
        !             2:    DRAWLINE.C -- Draw line from radio buttons
        !             3:   --------------------------------------------*/
        !             4: 
        !             5: #define INCL_WIN
        !             6: #define INCL_GPI
        !             7: #include <os2.h>
        !             8: 
        !             9: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
        !            10: 
        !            11: int main (void)
        !            12:      {
        !            13:      static CHAR  szClientClass[] = "DrawLine" ;
        !            14:      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU |
        !            15:                                  FCF_SIZEBORDER    | FCF_MINMAX  |
        !            16:                                  FCF_SHELLPOSITION | FCF_TASKLIST ;
        !            17:      HAB          hab ;
        !            18:      HMQ          hmq ;
        !            19:      HWND         hwndFrame, hwndClient ;
        !            20:      QMSG         qmsg ;
        !            21: 
        !            22:      hab = WinInitialize (0) ;
        !            23:      hmq = WinCreateMsgQueue (hab, 0) ;
        !            24: 
        !            25:      WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ;
        !            26: 
        !            27:      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
        !            28:                                      &flFrameFlags, szClientClass, NULL,
        !            29:                                      0L, NULL, 0, &hwndClient) ;
        !            30: 
        !            31:      WinSendMsg (hwndFrame, WM_SETICON,
        !            32:                  WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
        !            33:                  NULL) ;
        !            34: 
        !            35:      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
        !            36:           WinDispatchMsg (hab, &qmsg) ;
        !            37: 
        !            38:      WinDestroyWindow (hwndFrame) ;
        !            39:      WinDestroyMsgQueue (hmq) ;
        !            40:      WinTerminate (hab) ;
        !            41:      return 0 ;
        !            42:      }
        !            43: 
        !            44: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
        !            45:      {
        !            46:      static CHAR   *szGroupText[] = { "Color", "Type" } ;
        !            47:      static CHAR   *szColorText[] = { "Background", "Blue",      "Red",
        !            48:                                        "Pink",       "Green",     "Cyan",
        !            49:                                        "Yellow",     "Neutral",   "Dark Gray",
        !            50:                                        "Dark Blue",  "Dark Red",  "Dark Pink",
        !            51:                                        "Dark Green", "Dark Cyan", "Brown",     
        !            52:                                        "Pale Gray" } ;
        !            53:      static CHAR   *szTypeText [] = { "Dot",       "Short Dash",
        !            54:                                        "Dash Dot",  "Double Dot",
        !            55:                                        "Long Dash", "Dash Double Dot",
        !            56:                                        "Solid",     "Invisible" } ;
        !            57:      static HWND   hwndGroup[2], hwndRadioColor[8], hwndRadioType[8] ;
        !            58:      static POINTL aptl[5] ;
        !            59:      static SHORT  sCurrentColor = 7,   // Neutral
        !            60:                    sCurrentType  = 6 ;  // Solid
        !            61:      FONTMETRICS   fm ;
        !            62:      HPS           hps ;
        !            63:      SHORT         s, id, cxChar, cyChar ;
        !            64: 
        !            65:      switch (msg)
        !            66:           {
        !            67:           case WM_CREATE :
        !            68:                hps = WinGetPS (hwnd) ;
        !            69:                GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm) ;
        !            70:                cxChar = (SHORT) fm.lAveCharWidth ;
        !            71:                cyChar = (SHORT) fm.lMaxBaselineExt ;
        !            72:                WinReleasePS (hps) ;
        !            73: 
        !            74:                for (s = 0 ; s < 2 ; s++)
        !            75: 
        !            76:                     hwndGroup[s] = WinCreateWindow (
        !            77:                                         hwnd,               // Parent
        !            78:                                         WC_STATIC,          // Class
        !            79:                                         szGroupText[s],     // Text
        !            80:                                         WS_VISIBLE |        // Style
        !            81:                                              SS_GROUPBOX,
        !            82:                                         (8 + 42 * s) * cxChar,
        !            83:                                         4 * cyChar,         // Position
        !            84:                                         (26 + 12 * (1 - s)) *
        !            85:                                              cxChar,        // Width
        !            86:                                         14 * cyChar,        // Height
        !            87:                                         hwnd,               // Owner
        !            88:                                         HWND_TOP,           // Placement
        !            89:                                         s + 24,             // ID
        !            90:                                         NULL,               // Ctrl Data
        !            91:                                         NULL) ;             // Pres Params
        !            92: 
        !            93:                for (s = 0 ; s < 16 ; s++)
        !            94: 
        !            95:                     hwndRadioColor[s] = WinCreateWindow (
        !            96:                                         hwnd,               // Parent
        !            97:                                         WC_BUTTON,          // Class
        !            98:                                         szColorText[s],     // Text
        !            99:                                         WS_VISIBLE |        // Style
        !           100:                                              BS_RADIOBUTTON,
        !           101:                                         (10 + (s > 7 ? 18 : 0))
        !           102:                                              * cxChar,      // X Position
        !           103:                                         (31 - 3 * (s % 8))
        !           104:                                              * cyChar / 2,  // Y Position
        !           105:                                         16 * cxChar,        // Width
        !           106:                                         3 * cyChar / 2,     // Height
        !           107:                                         hwnd,               // Owner
        !           108:                                         HWND_BOTTOM,        // Placement
        !           109:                                         s,                  // ID
        !           110:                                         NULL,               // Ctrl Data
        !           111:                                         NULL) ;             // Pres Params
        !           112: 
        !           113:                for (s = 0 ; s < 8 ; s++)
        !           114: 
        !           115:                     hwndRadioType[s]  = WinCreateWindow (
        !           116:                                         hwnd,               // Parent
        !           117:                                         WC_BUTTON,          // Class
        !           118:                                         szTypeText[s],      // Text
        !           119:                                         WS_VISIBLE |        // Style
        !           120:                                              BS_RADIOBUTTON,
        !           121:                                         52 * cxChar,        // Position
        !           122:                                         (31 - 3 * s) * cyChar / 2,
        !           123:                                         22 * cxChar,        // Width
        !           124:                                         3 * cyChar / 2,     // Height
        !           125:                                         hwnd,               // Owner
        !           126:                                         HWND_BOTTOM,        // Placement
        !           127:                                         s + 16,             // ID
        !           128:                                         NULL,               // Ctrl Data
        !           129:                                         NULL) ;             // Pres Params
        !           130:                     
        !           131:                WinSendMsg (hwndRadioColor[sCurrentColor],
        !           132:                            BM_SETCHECK, MPFROMSHORT (1), NULL) ;
        !           133: 
        !           134:                WinSendMsg (hwndRadioType[sCurrentType],
        !           135:                            BM_SETCHECK, MPFROMSHORT (1), NULL) ;
        !           136: 
        !           137:                aptl[0].x = aptl[3].x = aptl[4].x = 4 * cxChar ;
        !           138:                aptl[1].x = aptl[2].x = 80 * cxChar ;
        !           139: 
        !           140:                aptl[0].y = aptl[1].y = aptl[4].y = 2 * cyChar ;
        !           141:                aptl[2].y = aptl[3].y = 20 * cyChar ;
        !           142: 
        !           143:                return 0 ;
        !           144: 
        !           145:           case WM_CONTROL:
        !           146:                id = SHORT1FROMMP (mp1) ;
        !           147: 
        !           148:                if (id < 16)             // Color IDs
        !           149:                     {
        !           150:                     WinSendMsg (hwndRadioColor[sCurrentColor],
        !           151:                                 BM_SETCHECK, MPFROMSHORT (0), NULL) ;
        !           152: 
        !           153:                     sCurrentColor = id ;
        !           154: 
        !           155:                     WinSendMsg (hwndRadioColor[sCurrentColor],
        !           156:                                 BM_SETCHECK, MPFROMSHORT (1), NULL) ;
        !           157:                     }
        !           158: 
        !           159:                else if (id < 24)        // Line Type IDs
        !           160:                     {
        !           161:                     WinSendMsg (hwndRadioType[sCurrentType],
        !           162:                                 BM_SETCHECK, MPFROMSHORT (0), NULL) ;
        !           163: 
        !           164:                     sCurrentType = id - 16 ;
        !           165: 
        !           166:                     WinSendMsg (hwndRadioType[sCurrentType],
        !           167:                                 BM_SETCHECK, MPFROMSHORT (1), NULL) ;
        !           168:                     }
        !           169:                WinInvalidateRect (hwnd, NULL, TRUE) ;
        !           170:                return 0 ;
        !           171: 
        !           172:           case WM_PAINT:
        !           173:                hps = WinBeginPaint (hwnd, NULL, NULL) ;
        !           174:                GpiErase (hps) ;
        !           175: 
        !           176:                GpiSetColor (hps, (LONG) sCurrentColor) ;
        !           177:                GpiSetLineType (hps, sCurrentType + LINETYPE_DOT) ;
        !           178:                GpiMove (hps, aptl) ;
        !           179:                GpiPolyLine (hps, 4L, aptl + 1) ;
        !           180: 
        !           181:                WinEndPaint (hps) ;
        !           182:                return 0 ;
        !           183:           }
        !           184:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
        !           185:      }

unix.superglobalmegacorp.com

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