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