VOID ShowStatusLine( const HPS hps, const char Moves, const char Ships, const LONG Width, const LONG Height ) { RECTL Rect = { 0, Height, Width, Height + 30 }; POINTL Point = { Width, Height }; CHAR text[256]; WinFillRect( hps, &Rect, CLR_WHITE ); //SYSCLR_WINDOW ); // clear background GpiSetColor( hps, CLR_BLACK ); GpiSetLineType( hps, LINETYPE_SHORTDASH ); GpiSetLineWidth( hps, LINEWIDTH_NORMAL ); GpiSetMix( hps, FM_OVERPAINT ); GpiMove( hps, &Point ); Point.x = 0; GpiLine( hps, &Point ); Point.x += 10; Point.y += 10; GpiMove( hps, &Point ); if( Ships ) sprintf( text, "%d %s made %d %s still lost", Moves, Moves == 1 ? "move" : "moves", Ships, Ships == 1 ? "ship" : "ships" ); else sprintf( text, "%d %s made All ships found", Moves, Moves == 1 ? "move" : "moves" ); GpiCharString( hps, strlen(text), text ); DosSleep( 1 ); // free time slice }
INT APIENTRY HdrPuts (HPS hps, PPOINTL pptl, PCHAR szText) { INT iLength = strlen (szText) ; if (pptl == NULL) GpiCharString (hps, iLength, szText) ; else GpiCharStringAt (hps, pptl, iLength, szText) ; return iLength ; }
INT APIENTRY HdrPrintf (HPS hps, PPOINTL pptl, PCHAR szFormat, ...) { static CHAR chBuffer [1024] ; INT iLength ; va_list pArguments ; va_start (pArguments, szFormat) ; iLength = vsprintf (chBuffer, szFormat, pArguments) ; if (pptl == NULL) GpiCharString (hps, iLength, chBuffer) ; else GpiCharStringAt (hps, pptl, iLength, chBuffer) ; va_end (pArguments) ; return iLength ; }
VOID MainPaint(HWND hwnd) { RECTL rclUpdate; RECTL rclWnd; RECTL rclDraw; HPS hps; POINTL pt; LONG LineHeight; LONG Descender; PCHAR pText; LONG ptTextStart; static LONG Inc[] = { 10, 10, 10, 12, 12, 12, 14, 14, 14, 16, 16, 16, 18, 18, 18, 20, 20, 20, 22, 22, 22, 24, 24, 24 }; //BIDI static PCHAR TextLines[] = { "~DrawText", //0 "CharString", //1 "CharStringAt", //2 "CharStringPos", //3 "CharStringPosAt", //4 "DrawText(QueryRect)", //5 "QueryCharStringPos", //6 "QueryCharStringPosAt", //7 "QueryTextBox" //8 }; static PCHAR TextLines_API[] = { "WinDrawText:", //0 "GpiCharString:", //1 "GpiCharStringAt:", //2 "GpiCharStringPos:", //3 "GpiCharStringPosAt:", //4 "WinDrawText(QueryRect):", //5 "GpiQueryCharStringPos:", //6 "GpiQueryCharStringPosAt:", //7 "GpiQueryTextBox:", //8 "Current Clipboard TextBuffer:" //9 }; ULONG GpiBidiAttr; ULONG NullBidiAttr = 0L; hps = WinBeginPaint(hwnd, NULLHANDLE, (PRECTL)&rclUpdate); // Get the bidi attribute of the presentation space, so that // we can flip/flip between a NULL bidiattribute and this one // GpiBidiAttr = GpiQueryBidiAttr(hps); /* fill update rectangle with window color */ WinFillRect(hps, (PRECTL)&rclUpdate, SYSCLR_PAGEBACKGROUND ); CalcLineHeight(hps, &LineHeight, &Descender); GpiSetColor ( hps, CLR_BLUE ) ; GpiSetBackColor( hps, CLR_RED ) ; WinQueryWindowRect(hwnd, (PRECTL)&rclWnd); ptTextStart = rclWnd.xRight * 2/5 ; // ------------------------------------- // WinDrawText! // ------------------------------------- pt.x = 0; pt.y = rclWnd.yTop - LineHeight + Descender; rclDraw.xLeft = rclWnd.xLeft; rclDraw.xRight = rclWnd.xRight; rclDraw.yBottom = pt.y - Descender; rclDraw.yTop = rclDraw.yBottom + LineHeight ; GpiSetBidiAttr(hps, NullBidiAttr); pText = TextLines_API[0]; WinDrawText ( hps, strlen(pText), pText, &rclDraw, 0L, 0L, DT_LEFT | DT_ERASERECT | DT_TEXTATTRS | DT_MNEMONIC ); rclDraw.xLeft = ptTextStart; GpiSetBidiAttr(hps, GpiBidiAttr); pText = TextLines[0]; WinDrawText ( hps, strlen(pText), pText, &rclDraw, 0L, 0L, DT_LEFT | DT_ERASERECT | DT_TEXTATTRS | DT_MNEMONIC ); // ------------------------------------- // GpiCharString // ------------------------------------- pt.y -= LineHeight; pt.x = 0; GpiSetCurrentPosition( hps, &pt ) ; pText = TextLines_API[1]; GpiSetBidiAttr(hps, NullBidiAttr); GpiCharString(hps, strlen(pText), pText); pt.x = ptTextStart; GpiSetCurrentPosition( hps, &pt ) ; pText = TextLines[1]; GpiSetBidiAttr(hps, GpiBidiAttr); GpiCharString(hps, strlen(pText), pText); // ------------------------------------- // GpiCharStringAt // ------------------------------------- pt.y -= LineHeight ; pt.x = 0; pText = TextLines_API[2]; GpiSetBidiAttr(hps, NullBidiAttr); GpiCharStringAt(hps, &pt, strlen(pText), pText); pt.x = ptTextStart; pText = TextLines[2]; GpiSetBidiAttr(hps, GpiBidiAttr); GpiCharStringAt(hps, &pt, strlen(pText), pText); // ------------------------------------- // GpiCharStringPos // ------------------------------------- pt.y -= LineHeight ; pt.x = 0; GpiSetCurrentPosition( hps, &pt ) ; rclDraw.xLeft = rclWnd.xLeft; rclDraw.xRight = ptTextStart - 4; rclDraw.yBottom = pt.y - Descender; rclDraw.yTop = rclDraw.yBottom + LineHeight ; pText = TextLines_API[3]; GpiSetBidiAttr(hps, NullBidiAttr); GpiCharStringPos(hps, &rclDraw, CHS_VECTOR | CHS_OPAQUE, strlen(pText), pText, &Inc[0] ); rclDraw.xLeft = ptTextStart; rclDraw.xRight = rclWnd.xRight; rclDraw.yBottom = pt.y - Descender ; rclDraw.yTop = rclDraw.yBottom + LineHeight ; pt.x = ptTextStart; GpiSetCurrentPosition( hps, &pt ) ; pText = TextLines[3]; GpiSetBidiAttr(hps, GpiBidiAttr); GpiCharStringPos(hps, &rclDraw, CHS_VECTOR | CHS_OPAQUE, strlen(pText), pText, &Inc[0]); // ------------------------------------- // GpiCharStringPosAt // ------------------------------------- pt.y -= LineHeight ; pt.x = 0; rclDraw.xLeft = rclWnd.xLeft; rclDraw.xRight = ptTextStart - 4; rclDraw.yBottom = pt.y - Descender ; rclDraw.yTop = rclDraw.yBottom + LineHeight ; pText = TextLines_API[4]; GpiSetBidiAttr(hps, NullBidiAttr); GpiCharStringPosAt(hps, &pt, &rclDraw, CHS_VECTOR | CHS_OPAQUE, strlen(pText), pText, &Inc[0] ); rclDraw.xLeft = ptTextStart; rclDraw.xRight = rclWnd.xRight; rclDraw.yBottom = pt.y - Descender ; rclDraw.yTop = rclDraw.yBottom + LineHeight ; pt.x = ptTextStart; pText = TextLines[4]; GpiSetBidiAttr(hps, GpiBidiAttr); GpiCharStringPosAt(hps, &pt, &rclDraw, CHS_VECTOR | CHS_OPAQUE, strlen(pText), pText, &Inc[0]); // ------------------------------------- // Current Clipboard TextBuffer // // This is used as a means of "looking inside" the // clipbaord. (This is a clipboard viewer for the poor...) // This part shows the text in szPasteText. // To operate: // - Copy/Cut text from anywhere to the clipbaord. // - select: Edit --> Paste --> No Conversion // - The clipboard text will be shown (UNMODIFIED BUFFER) // in our window. // ------------------------------------- pt.y -= LineHeight ; pt.x = 0; pText = TextLines_API[9]; GpiSetBidiAttr(hps, NullBidiAttr); GpiCharStringAt(hps, &pt, strlen(pText), pText); pt.x = ptTextStart; pText = szPasteText; GpiCharStringAt(hps, &pt, strlen(pText), pText); //BIDI- end /* * Add painting routines here. Hps is now the HPS for * the window and rclUpdate contains the update rectangle. */ WinEndPaint(hps); } /* MainPaint() */