Annotation of pmsdk/samples/petzold/chap05/devcaps.c, revision 1.1
1.1 ! root 1: /*--------------------------------------------------
! 2: DEVCAPS.C -- Device Capabilities Display Program
! 3: --------------------------------------------------*/
! 4:
! 5: #define INCL_WIN
! 6: #define INCL_GPI
! 7: #include <os2.h>
! 8: #include <stdlib.h>
! 9: #include <string.h>
! 10: #include "devcaps.h"
! 11:
! 12: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
! 13:
! 14: int main (void)
! 15: {
! 16: static CHAR szClientClass [] = "DevCaps" ;
! 17: static ULONG flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
! 18: FCF_SIZEBORDER | FCF_MINMAX |
! 19: FCF_SHELLPOSITION | FCF_TASKLIST ;
! 20: HAB hab ;
! 21: HMQ hmq ;
! 22: HWND hwndFrame, hwndClient ;
! 23: QMSG qmsg ;
! 24:
! 25: hab = WinInitialize (0) ;
! 26: hmq = WinCreateMsgQueue (hab, 0) ;
! 27:
! 28: WinRegisterClass (hab, szClientClass, ClientWndProc, 0L, 0) ;
! 29:
! 30: hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
! 31: &flFrameFlags, szClientClass, NULL,
! 32: 0L, NULL, 0, &hwndClient) ;
! 33:
! 34: WinSendMsg (hwndFrame, WM_SETICON,
! 35: WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
! 36: NULL) ;
! 37:
! 38: while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
! 39: WinDispatchMsg (hab, &qmsg) ;
! 40:
! 41: WinDestroyWindow (hwndFrame) ;
! 42: WinDestroyMsgQueue (hmq) ;
! 43: WinTerminate (hab) ;
! 44: return 0 ;
! 45: }
! 46:
! 47: LONG RtJustCharStringAt (HPS hps, POINTL *pptl, LONG lLength, CHAR *pchText)
! 48: {
! 49: POINTL aptlTextBox[TXTBOX_COUNT] ;
! 50:
! 51: GpiQueryTextBox (hps, lLength, pchText, TXTBOX_COUNT, aptlTextBox) ;
! 52:
! 53: pptl->x -= aptlTextBox[TXTBOX_CONCAT].x ;
! 54:
! 55: return GpiCharStringAt (hps, pptl, lLength, pchText) ;
! 56: }
! 57:
! 58: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
! 59: {
! 60: static HDC hdc ;
! 61: static SHORT cxClient, cyClient, cxCaps, cyChar, cyDesc ;
! 62: CHAR szBuffer [12] ;
! 63: FONTMETRICS fm ;
! 64: LONG lValue ;
! 65: POINTL ptl ;
! 66: HPS hps ;
! 67: SHORT sLine ;
! 68:
! 69: switch (msg)
! 70: {
! 71: case WM_CREATE:
! 72: hps = WinGetPS (hwnd) ;
! 73: GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm) ;
! 74: cxCaps = (SHORT) fm.lEmInc ;
! 75: cyChar = (SHORT) fm.lMaxBaselineExt ;
! 76: cyDesc = (SHORT) fm.lMaxDescender ;
! 77: WinReleasePS (hps) ;
! 78:
! 79: hdc = WinOpenWindowDC (hwnd) ;
! 80: return 0 ;
! 81:
! 82: case WM_SIZE:
! 83: cxClient = SHORT1FROMMP (mp2) ;
! 84: cyClient = SHORT2FROMMP (mp2) ;
! 85: return 0 ;
! 86:
! 87: case WM_PAINT:
! 88: hps = WinBeginPaint (hwnd, NULL, NULL) ;
! 89: GpiErase (hps) ;
! 90:
! 91: for (sLine = 0 ; sLine < NUMLINES ; sLine++)
! 92: {
! 93: ptl.x = cxCaps ;
! 94: ptl.y = cyClient - cyChar * (sLine + 2) + cyDesc ;
! 95:
! 96: if (sLine >= (NUMLINES + 1) / 2)
! 97: {
! 98: ptl.x += cxCaps * 35 ;
! 99: ptl.y += cyChar * (NUMLINES + 1) / 2 ;
! 100: }
! 101:
! 102: DevQueryCaps (hdc, devcaps[sLine].lIndex, 1L, &lValue) ;
! 103:
! 104: GpiCharStringAt (hps, &ptl,
! 105: (LONG) strlen (devcaps[sLine].szIdentifier),
! 106: devcaps[sLine].szIdentifier) ;
! 107:
! 108: ptl.x += 33 * cxCaps ;
! 109: RtJustCharStringAt (hps, &ptl,
! 110: (LONG) strlen (ltoa (lValue, szBuffer, 10)),
! 111: szBuffer) ;
! 112: }
! 113: WinEndPaint (hps) ;
! 114: return 0 ;
! 115: }
! 116: return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
! 117: }
! 118: