|
|
1.1 ! root 1: /*------------------------- ! 2: RULER.C -- Draw a Ruler ! 3: -------------------------*/ ! 4: ! 5: #define INCL_WIN ! 6: #define INCL_GPI ! 7: #include <os2.h> ! 8: #include <stdio.h> ! 9: ! 10: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ; ! 11: ! 12: int main (void) ! 13: { ! 14: static CHAR szClientClass [] = "Ruler" ; ! 15: static ULONG flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU | ! 16: FCF_SIZEBORDER | FCF_MINMAX | ! 17: FCF_SHELLPOSITION | FCF_TASKLIST ; ! 18: HAB hab ; ! 19: HMQ hmq ; ! 20: HWND hwndFrame, hwndClient ; ! 21: QMSG qmsg ; ! 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, WS_VISIBLE, ! 29: &flFrameFlags, szClientClass, NULL, ! 30: 0L, NULL, 0, &hwndClient) ; ! 31: ! 32: WinSendMsg (hwndFrame, WM_SETICON, ! 33: WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE), ! 34: NULL) ; ! 35: ! 36: while (WinGetMsg (hab, &qmsg, NULL, 0, 0)) ! 37: WinDispatchMsg (hab, &qmsg) ; ! 38: ! 39: WinDestroyWindow (hwndFrame) ; ! 40: WinDestroyMsgQueue (hmq) ; ! 41: WinTerminate (hab) ; ! 42: return 0 ; ! 43: } ! 44: ! 45: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2) ! 46: { ! 47: static SHORT sTick[16] = { 100, 25, 35, 25, 50, 25, 35, 25, ! 48: 70, 25, 35, 25, 50, 25, 35, 25 } ; ! 49: static SHORT cxClient, cyClient, cxChar, cyChar, cyDesc ; ! 50: static SIZEL sizl ; ! 51: CHAR szBuffer [4] ; ! 52: FONTMETRICS fm ; ! 53: HPS hps ; ! 54: POINTL ptl ; ! 55: SHORT sIndex ; ! 56: ! 57: switch (msg) ! 58: { ! 59: case WM_CREATE: ! 60: hps = WinGetPS (hwnd) ; ! 61: GpiSetPS (hps, &sizl, PU_LOENGLISH) ; ! 62: ! 63: GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm) ; ! 64: cxChar = (SHORT) fm.lAveCharWidth ; ! 65: cyChar = (SHORT) fm.lMaxBaselineExt ; ! 66: cyDesc = (SHORT) fm.lMaxDescender ; ! 67: ! 68: WinReleasePS (hps) ; ! 69: return 0 ; ! 70: ! 71: case WM_SIZE: ! 72: ptl.x = SHORT1FROMMP (mp2) ; ! 73: ptl.y = SHORT2FROMMP (mp2) ; ! 74: ! 75: hps = WinGetPS (hwnd) ; ! 76: GpiSetPS (hps, &sizl, PU_LOENGLISH) ; ! 77: GpiConvert (hps, CVTC_DEVICE, CVTC_PAGE, 1L, &ptl) ; ! 78: WinReleasePS (hps) ; ! 79: ! 80: cxClient = (SHORT) ptl.x ; ! 81: cyClient = (SHORT) ptl.y ; ! 82: return 0 ; ! 83: ! 84: case WM_PAINT: ! 85: hps = WinBeginPaint (hwnd, NULL, NULL) ; ! 86: GpiSetPS (hps, &sizl, PU_LOENGLISH) ; ! 87: GpiErase (hps) ; ! 88: ! 89: for (sIndex = 0 ; sIndex < 16 * (SHORT) cxClient / 100 ; ! 90: sIndex ++) ! 91: { ! 92: ptl.x = 100 * sIndex / 16 ; ! 93: ptl.y = 0 ; ! 94: GpiMove (hps, &ptl) ; ! 95: ! 96: ptl.y = sTick [sIndex % 16] ; ! 97: GpiLine (hps, &ptl) ; ! 98: ! 99: if (sIndex % 16 == 0) ! 100: { ! 101: ptl.x -= cxChar / (sIndex > 160 ? 1 : 2) ; ! 102: ptl.y += cyDesc ; ! 103: GpiCharStringAt (hps, &ptl, ! 104: (LONG) sprintf (szBuffer, "%d", sIndex / 16), ! 105: szBuffer) ; ! 106: } ! 107: } ! 108: WinEndPaint (hps) ; ! 109: return 0 ; ! 110: } ! 111: return WinDefWindowProc (hwnd, msg, mp1, mp2) ; ! 112: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.