VOID ClientPaint(HWND hwnd) { POINTL pt; HPS hps; RECTL rcl; LONG lLen; LONG lCenter; WinInvalidateRect(hwnd,(PRECTL)NULL,FALSE); hps = WinBeginPaint(hwnd,(HPS)NULL,&rcl ); // if (bShowingProgress) // rcl.yBottom = 60L; WinFillRect(hps,&rcl,CLR_WHITE); lCenter = (INITWIDTH / 2); if (bDebug) { GpiSetBackColor(hps,CLR_WHITE); GpiSetBackMix(hps,BM_OVERPAINT); GpiCreateLogFont(hps,NULL,3,&fattMsgFont); GpiSetColor(hps,CLR_BLACK); GpiSetCharSet(hps,3); pt.x = 10; if (szDebugLineOne[0] != 0) { pt.y = 82L; GpiCharStringAt(hps,&pt,strlen(szDebugLineOne),szDebugLineOne); } if (szDebugLineTwo[0] != 0) { pt.y = 62L; GpiCharStringAt(hps,&pt,strlen(szDebugLineTwo),szDebugLineTwo); } } else { GpiSetColor(hps,CLR_CYAN); GpiSetBackColor(hps,CLR_WHITE); GpiSetBackMix(hps,BM_OVERPAINT); GpiCreateLogFont(hps, NULL, 2, &fattBigFont); GpiSetCharSet(hps,2); pt.x = (lCenter - (10 * stBigCell.cx)); pt.y = 60L; GpiCharStringAt(hps,&pt,21,"OS/tools Installation"); } if (!bShowingProgress) PrintBanners(szBannerOne,szBannerTwo); WinEndPaint(hps); }
/****************************************************************\ * Main client painting routine *-------------------------------------------------------------- * * Name: MainPaint(hwnd) * * Purpose: Paints the main client window. * * Usage: Routine is called whenver the client window * procedure receives a WM_PAINT message * * Method: * - begins painting by calling WinBeginPaint * and retrieving the HPS for the window * - performs any painting desired * - ends painting by calling WinEndPaint * * Returns: * \****************************************************************/ VOID MainPaint(HWND hwnd, /* handle to window */ CHAR PipeMsgs[MAX_MESSAGES][MESSAGE_LEN], /* array of messages */ unsigned int uiIndex, /* beginning of circular array */ SHORT sTotalMsgs) /* total number of messages */ { RECTL rclInvalid; HPS hps; LONG sPaintBeg, sPaintEnd, sLine; POINTL ptl; unsigned int uiOffset; uiOffset = (sTotalMsgs < MAX_MESSAGES) ? 0 : uiIndex; hps = WinBeginPaint(hwnd, NULLHANDLE, (PRECTL)&rclInvalid); GpiErase(hps); sPaintBeg = max(0, sVscrollPos + (cyClient - rclInvalid.yTop) / cyChar); sPaintEnd = min(sTotalMsgs, sVscrollPos + (cyClient - rclInvalid.yBottom) / cyChar + 1); for (sLine = sPaintBeg ; sLine < sPaintEnd ; sLine++) { ptl.x = cxCaps - sHscrollPos ; ptl.y = cyClient - cyChar * (BUFF_OFFSET(uiOffset,sLine) + 1 - sVscrollPos) + cyDesc ; GpiCharStringAt (hps, &ptl, (LONG) strlen (PipeMsgs[BUFF_OFFSET(uiOffset,sLine)]), PipeMsgs[BUFF_OFFSET(uiOffset,sLine)]) ; } WinEndPaint (hps) ; } /* MainPaint() */
void PaintClient (HPS hps, SHORT cxClient, SHORT cyClient) { static CHAR szText [] = "ZED" ; POINTL ptl, ptlShear ; // Create the logical font CreateOutlineFont (hps, LCID_FONT, "Times New Roman", 0, 0) ; GpiSetCharSet (hps, LCID_FONT) ; // Display the shadow GpiSetColor (hps, CLR_DARKBLUE) ; ScaleOutlineFont (hps, 2160, 720) ; ptlShear.x = 1 ; //was 2 ptlShear.y = 1 ; GpiSetCharShear (hps, &ptlShear) ; ptl.x = cxClient / 8 ; ptl.y = cyClient / 4 ; GpiCharStringAt (hps, &ptl, strlen (szText), szText) ; // Display the text GpiSetColor (hps, CLR_WHITE) ; ScaleOutlineFont (hps, 720, 720) ; ptlShear.x = 0 ; ptlShear.y = 1 ; GpiSetCharShear (hps, &ptlShear) ; GpiCharStringAt (hps, &ptl, strlen (szText), szText) ; // Select the default font; delete the logical font GpiSetCharSet (hps, LCID_DEFAULT) ; GpiDeleteSetId (hps, LCID_FONT) ; }
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 ; }
/************************************************************************** * * Name : CTPOKA(HPS* phps, BOOL bAll) * * Description: рисует буквы * * Concepts: Получает указатель на пространство отображения * и пишет текущие атрибуты игры: уровень и очки. * * API's : * * Parameters : phps - указатель на hps * usAll = перерисовывать все или только очки * 0 - очки * 1 - все * 2 - время *************************************************************************/ VOID CTPOKA(PHPS phps, USHORT usAll) { POINTL ptl;//где рисовать RECTL rec;//фон char sz[20]; if(usAll)rec.xLeft = 0;//пишем все,время,уровень else rec.xLeft = LevelEndptl.x;//очки if(usAll == 2)//пишем время rec.xRight = TimeEndptl.x;//TimeEndptl уже вызывалось else rec.xRight = Col*BmpSize+2;//пишем все,очки,уровень rec.yBottom = BmpSize*Row; rec.yTop = BmpSize*Row+LineHeight; WinFillRect(*phps, &rec, CLR_STRING); GpiSetColor(*phps,CLR_CHAR);//цвет внутренности ptl.y=BmpSize*Row+5; if(usAll == 2 || usAll == 1){//пишем все или время sprintf(sz,"Tijd-%d ",usTime); ptl.x = 5; GpiCharStringAt(*phps,&ptl,strlen(sz),sz); GpiQueryCurrentPosition(*phps,&TimeEndptl);} if(usAll == 1){//если пишем все sprintf(sz,"Niveau-%d ",usLevel); ptl.x = LevelBeginptl.x; GpiCharStringAt(*phps,&ptl,strlen(sz),sz); GpiQueryCurrentPosition(*phps,&LevelEndptl);} if(usAll == 0 || usAll == 1){//пишем все или очки sprintf(sz,"Punten-%d(%d%%) ", sScore, ((sScore - sOScore)*125)/((Row-2)*(Col-2)));// 4/5 поля=100% ptl.x = LevelEndptl.x; GpiCharStringAt(*phps,&ptl,strlen(sz),sz); GpiQueryCurrentPosition(*phps,&ScoreEndptl);} if(usAll == 1 && (ScoreEndptl.x > Col*BmpSize || LevelBeginptl.x < TimeEndptl.x )) { //sprintf(sz,"T-%d,L-%d,S-%d,CB-%d",TimeEndptl.x+5,LevelBeginptl.x,ScoreEndptl.x,Col*BmpSize); //WinMessageBox(HWND_DESKTOP,HWND_DESKTOP, // sz,"OneMore",0,MB_OK); LevelBeginptl.x = MAX(TimeEndptl.x+5, LevelBeginptl.x-(ScoreEndptl.x - Col*BmpSize+5)); CTPOKA(phps, usAll);} } /* End of CTPOKA */
void drawGrid(HPS hps,long gridX,long gridY,int drawIt,char *str,BOOL tracename) { POINTL p; if (!tracename) return; if (drawIt ) GpiSetColor (hps,CLR_CYAN ); else GpiSetColor (hps,CLR_BLACK ); p.x=gridX-10; p.y=gridY-10; GpiMove(hps,&p); p.x=gridX-13; p.y=gridY-9; GpiLine(hps,&p); p.x=gridX-13; p.y=gridY+9; GpiLine(hps,&p); p.x=gridX-10; p.y=gridY+10; GpiLine(hps,&p); p.x=gridX+10; p.y=gridY-10; GpiMove(hps,&p); p.x=gridX+13; p.y=gridY-9; GpiLine(hps,&p); p.x=gridX+13; p.y=gridY+9; GpiLine(hps,&p); p.x=gridX+10; p.y=gridY+10; GpiLine(hps,&p); p.x=gridX; p.y=gridY-15; if (drawIt ) GpiSetColor (hps,CLR_WHITE ); GpiCharStringAt(hps,&p,strlen(str),str); }
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 PrintString(char szMessage[],ULONG ulLine) { HPS hps; RECTL rcl; POINTL ptl; ptl.y = (ulWindowHeight - (ulLine * (stCell.cy + 3))); ptl.x = stCell.cx; rcl.yBottom = (ptl.y - 3); rcl.yTop = (ptl.y + stCell.cy); rcl.xLeft = 0; rcl.xRight = ulWindowWidth; hps = WinGetPS(hwndClient); WinFillRect(hps,&rcl,CLR_WHITE); GpiCharStringAt(hps,&ptl,strlen(szMessage),szMessage); WinReleasePS(hps); }
void ErrorNotify(char szMessage[]) { HPS hps; RECTL rcl; POINTL ptl; ptl.y = 2; ptl.x = stCell.cx; rcl.yBottom = 0; rcl.yTop = stCell.cy; rcl.xLeft = 0; rcl.xRight = ulWindowWidth; hps = WinGetPS(hwndClient); WinFillRect(hps,&rcl,CLR_WHITE); GpiCharStringAt(hps,&ptl,strlen(szMessage),szMessage); WinReleasePS(hps); }
void XText::Draw( XGraphicDevice * dev) { if (!(settings & GO_HIDE)) { SetupDevice(dev); if (p2.GetX() == 0) { POINTL pnt; pnt.x = p.GetX(); pnt.y = p.GetY(); GpiCharStringAt(dev->hps, &pnt, text.GetLength(), (PSZ) (char*) text); } else { RECTL rc; rc.yBottom = p.y + dev->yOffset; rc.yTop = p2.y + dev->yOffset; rc.xLeft = p.x + dev->xOffset; rc.xRight = p2.x + dev->xOffset; char *t = text; if (style & DT_WORDBREAK) { int drawn = 0, totalDrawn, length = text.GetLength(); for (totalDrawn = 0; totalDrawn < length; rc.yTop -= (LONG) (font->realSize)) { drawn = WinDrawText(dev->hps, length - totalDrawn, (PSZ) t + totalDrawn, &rc, color.GetColor(), 0, style); if (drawn) totalDrawn += drawn; else break; } } else WinDrawText(dev->hps, text.GetLength(), (PCH) t, &rc, color.GetColor(), 0, style); } return; } }
MRESULT EXPENTRY HelloWndProc(HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2) { switch (msg) { case WM_PAINT: { static char *message = "Hello world! I'm running under OS/2!"; POINTL pt; HPS hps; /* where to put it. NTS: OS/2 window coordinates are done Cartesian style where Y increases upward on the screen */ pt.x = 40; pt.y = 40; hps = WinBeginPaint(hwnd,0/*NULLHANDLE*/,NULL); GpiErase(hps); GpiCharStringAt(hps,&pt,strlen(message),message); WinEndPaint(hps); } return 0; } return WinDefWindowProc(hwnd,msg,mp1,mp2); }
void PaintClient (HPS hps, SHORT cxClient, SHORT cyClient) { static CHAR szText [] = "Hello!" ; FONTMETRICS fm ; int iPtHt, iPtWd ; POINTL ptl, aptl[TXTBOX_COUNT] ; // Create the logical font, select it, and scale it CreateOutlineFont (hps, LCID_FONT, "Helvetica", 0, 0) ; GpiSetCharSet (hps, LCID_FONT) ; ScaleOutlineFont (hps, 120, 120) ; // Scale font to client window size GpiQueryTextBox (hps, strlen (szText), szText, TXTBOX_COUNT, aptl) ; iPtHt = (int) (120 * cyClient / (aptl[TXTBOX_TOPLEFT].y - aptl[TXTBOX_BOTTOMLEFT].y)) ; iPtWd = (int) (120 * cxClient / aptl[TXTBOX_CONCAT].x) ; ScaleOutlineFont (hps, iPtHt, iPtWd) ; // Display the text string GpiQueryFontMetrics (hps, sizeof (FONTMETRICS), &fm) ; ptl.x = 0 ; ptl.y = cyClient - fm.lMaxAscender ; GpiCharStringAt (hps, &ptl, strlen (szText), szText) ; // Select the default font; delete the logical font GpiSetCharSet (hps, LCID_DEFAULT) ; GpiDeleteSetId (hps, LCID_FONT) ; }
/**************************************************************************** Titlebar Dialog Procedure *****************************************************************************/ MRESULT EXPENTRY TitleBarProc (HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2) { BOOL Handled = TRUE; MRESULT mReturn = 0; RECTL Rectl; POINTL Pointl; CHARBUNDLE cb; FONTMETRICS Fontsz; PSZ TitleText = szTitle; ULONG temp; HPS hps; switch (msg) { case WM_SETWINDOWPARAMS: if( ((WNDPARAMS*)mp1)->fsStatus & WPM_TEXT ) { TitleText = ((WNDPARAMS*)mp1)->pszText; } Handled = FALSE; break; case TBM_SETHILITE: mReturn = (MRESULT)TRUE; hps = WinGetPS(hWnd); WinQueryWindowRect(hWnd,&Rectl); WinFillRect(hps, &Rectl, CLR_BLACK); GpiQueryFontMetrics(hps,sizeof(FONTMETRICS),(PFONTMETRICS)&Fontsz); Pointl.x = 10; Pointl.y = (Rectl.yTop - Fontsz.lMaxAscender) / 2; cb.lColor = CLR_GREEN; cb.lBackColor = CLR_BLACK; cb.usMixMode = BM_OVERPAINT; cb.usBackMixMode = BM_OVERPAINT; GpiSetAttrs(hps,PRIM_CHAR, CBB_COLOR | CBB_BACK_COLOR | CBB_MIX_MODE | CBB_BACK_MIX_MODE, 0,(PBUNDLE)&cb); GpiCharStringAt(hps, &Pointl, strlen(TitleText), TitleText); WinEndPaint(hps); WinReleasePS(hps); break; case WM_PAINT: hps = WinBeginPaint(hWnd, 0, 0); WinQueryWindowRect(hWnd,&Rectl); WinFillRect(hps, &Rectl, CLR_BLACK); GpiQueryFontMetrics(hps,sizeof(FONTMETRICS),(PFONTMETRICS)&Fontsz); Pointl.x = 10; Pointl.y = (Rectl.yTop - Fontsz.lMaxAscender) / 2; cb.lColor = CLR_GREEN; cb.lBackColor = CLR_BLACK; cb.usMixMode = BM_OVERPAINT; cb.usBackMixMode = BM_OVERPAINT; GpiSetAttrs(hps,PRIM_CHAR, CBB_COLOR | CBB_BACK_COLOR | CBB_MIX_MODE | CBB_BACK_MIX_MODE, 0,(PBUNDLE)&cb); GpiCharStringAt(hps, &Pointl, strlen(TitleText), TitleText); WinEndPaint(hps); break; default: Handled = FALSE; break; } if (!Handled) mReturn = (*TitleDefProc)(hWnd, msg, mp1, mp2); return (mReturn); }
static MRESULT EXPENTRY MyWindowProc( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2 ) { HPS hps; RECTL rc; switch( msg ) { case WM_CREATE: break; case WM_COMMAND: switch( SHORT1FROMMP( mp1 ) ) { case ID_UNLOCK: Say( "Unlocked" ); UnLockIt(); if( FocusWnd != NULL ) { WinSetFocus( HWND_DESKTOP, FocusWnd ); } WinSetActiveWindow( HWND_DESKTOP, hwndClient ); if( ActiveWnd != NULL ) { WinSetActiveWindow( HWND_DESKTOP, ActiveWnd ); } break; case ID_SWITCH: Say( "Switched" ); SwitchBack(); break; case ID_EXITPROG: WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 ); break; default: return( WinDefWindowProc( hwnd, msg, mp1, mp2 ) ); } break; case WM_ERASEBACKGROUND: return( (MRESULT)TRUE ); case WM_PAINT: hps = WinBeginPaint( hwnd, 0L, &rc ); #ifdef DEBUG { POINTL pt; pt.x = 0; pt.y = 50; GpiSetColor( hps, CLR_NEUTRAL ); GpiSetBackColor( hps, CLR_BACKGROUND ); GpiSetBackMix( hps, BM_OVERPAINT ); GpiCharStringAt( hps, &pt, (LONG)strlen( Message ), Message ); } #endif WinEndPaint( hps ); break; case WM_CLOSE: WinPostMsg( hwnd, WM_QUIT, 0, 0 ); break; case WM_DESTROY: UnLockIt(); // fall thru default: return( WinDefWindowProc( hwnd, msg, mp1, mp2 ) ); } return( FALSE ); }
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() */
MRESULT EXPENTRY windowproc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { HPS hps; RECTL rcl; DRAGITEM dit; PDRAGINFO pdin; HOBJECT hobj; static a=0; switch(msg) { /* control tray icon specific messages */ case DM_DROP: pdin = (PDRAGINFO)mp1; DrgAccessDraginfo(pdin); DrgQueryDragitem(pdin,sizeof(DRAGITEM),&dit,0); DrgQueryStrName(dit.hstrContainerName,256,cbuf); DrgQueryStrName(dit.hstrSourceName,256,buf); strcat(cbuf,buf); hobj=WinQueryObject("<WP_DRIVES>"); if(hobj)DosBeep(1000,100); //WinOpenObject(hobj,0,TRUE); WinMessageBox(HWND_DESKTOP,hwnd,"Drag Succeed!",cbuf,0,MB_OK | MB_INFORMATION); DrgFreeDraginfo(pdin); break; case DM_DRAGOVER: return MPFROM2SHORT(DOR_DROP,DO_LINK); case WM_TIMER: a++; a%=5; WinSendMsg(hwndFrame,WM_SETICON,(MPARAM)hIcon[a],NULL); ChangeTrayIcon(hwnd,NULLHANDLE); break; case WM_BUTTON1CLICK|0x2000: case WM_BUTTON2CLICK|0x2000: /* activate frame window */ WinSetWindowPos(hwndFrame,HWND_TOP,0,0,0,0,SWP_ACTIVATE | SWP_SHOW | SWP_ZORDER | SWP_RESTORE); break; case WM_CREATE: /* initialize window */ /* initialize tray api */ InitializeTrayApi(hwnd); break; case WM_DDE_INITIATEACK: /* aswer dde server */ AnswerTrayApiDdeAck(mp1); AddTrayIcon(hwnd,WinSendMsg(hwndFrame,WM_QUERYICON,NULL,NULL)); WinStartTimer(hab,hwnd,1,500); return (MRESULT)0L; case WM_PAINT: hps = WinBeginPaint(hwnd,NULL,NULL); WinQueryWindowRect(hwnd, &rcl); WinFillRect(hps, &rcl, CLR_CYAN); GpiSetColor(hps, CLR_DARKBLUE); GpiSetBackColor(hps, CLR_CYAN); rcl.xLeft=(rcl.xLeft+rcl.xRight)/2-40; rcl.yBottom=(rcl.yBottom+rcl.yTop)/2-7; GpiCharStringAt(hps, (PPOINTL)&rcl, 13, "Hello, world!"); WinEndPaint(hps); break; case WM_DESTROY: /* delete application icon from system tray */ return (MRESULT)DeleteTrayIcon(hwnd); } return WinDefWindowProc(hwnd, msg, mp1, mp2); }
void _RepaintWindow( LPWDATA w, PRECT rcPaint, HDC ph ) #endif { WORD i; WORD ptop, pbot, pleft, pright, poff, pdown; WORD width; #ifdef _MBCS mb_char _WCI86FAR *image; unsigned char mbc[MB_CUR_MAX + 1]; #else LPSTR image; #endif #if !defined( __OS2__ ) HFONT oldfont; #endif /* * get area to redraw */ ptop = rcPaint->top / w->ychar; if( ptop > 0 && ( rcPaint->top % w->ychar ) != 0 ) ptop--; pbot = rcPaint->bottom / w->ychar ; if( pbot == 0 ) return; if( pbot >= w->height ) pbot = w->height - 1; if( ( rcPaint->bottom % w->ychar ) == 0 ) pbot--; pleft = 0; pright = w->width - 1; width = w->width; poff = pleft * w->xchar; pdown = ptop * w->ychar; /* * draw all lines */ #if defined( __OS2__ ) #else oldfont = SelectObject( (HDC)ph, _FixedFont ); #endif for( i = ptop; i <= pbot; i++ ) { image = &w->image[i * w->width]; #if defined( __OS2__ ) { POINTL ptl; ptl.x = poff; ptl.y = ( w->y2 - w->y1 ) - ( pdown + w->ychar ) + w->base_offset; #ifdef _MBCS { WORD count; LPSTR buff; buff = FARmalloc( sizeof( mb_char ) * ( width + 1 ) ); if( buff == NULL ) _OutOfMemoryExit(); *buff = '\0'; for( count = 0; count < width; count++ ) { _mbvtop( image[pleft + count], mbc ); mbc[_mbclen( mbc )] = '\0'; FARstrcat( buff, (char *)mbc ); } GpiCharStringAt( (HPS)ph, &ptl, FAR_mbsnbcnt( (PBYTE)buff, width ), buff ); FARfree( buff ); } #else GpiCharStringAt( (HPS)ph, &ptl, width, &image[pleft] ); #endif } #else SetBkColor( (HDC)ph, _ColorMap[w->background_color] ); SetTextColor( (HDC)ph, _ColorMap[w->text_color] ); #ifdef _MBCS { WORD count; size_t bytes; LPSTR buff; buff = FARmalloc( sizeof( mb_char ) * ( width + 1 ) ); if( buff == NULL ) _OutOfMemoryExit(); *buff = '\0'; for( count = 0; count < width; count++ ) { _mbvtop( image[pleft + count], mbc ); mbc[_mbclen( mbc )] = '\0'; FARstrcat( buff, (LPSTR)mbc ); } bytes = FARstrlen( buff ); TextOut( (HDC)ph, poff, pdown, buff, bytes ); FARfree( buff ); } #else TextOut( (HDC)ph, poff, pdown, &image[pleft], width ); #endif #endif pdown += w->ychar; } #if !defined( __OS2__ ) SelectObject( (HDC)ph, oldfont ); #endif } /* _RepaintWindow */
/********************* Start of window procedure **********************/ MRESULT EXPENTRY MyWindowProc( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2 ) { USHORT command; /* WM_COMMAND command value */ HPS hps; /* Presentation Space handle */ RECTL rc; /* Rectangle coordinates */ POINTL pt; /* String screen coordinates */ switch( msg ) { case WM_CREATE: if( State == RUNNING ) break; /******************************************************************/ /* Window initialization is performed here in WM_CREATE processing*/ /* WinLoadString loads strings from the resource file. */ /******************************************************************/ InitIt( "DSTD32", Hab, hwnd ); ReDraw( hwnd ); break; case WM_COMMAND: /******************************************************************/ /* When the user chooses option 1, 2, or 3 from the Options pull- */ /* down, the text string is set to 1, 2, or 3, and */ /* WinInvalidateRegion sends a WM_PAINT message. */ /* When Exit is chosen, the application posts itself a WM_CLOSE */ /* message. */ /******************************************************************/ command = SHORT1FROMMP(mp1); /* Extract the command value */ switch (command) { case ID_LOAD: if( State == RUNNING ) break; if( State != NONE ) { KillIt(); State = NONE; } if( LoadIt() ) { State = LOADED; } ReDraw( hwnd ); break; case ID_RUN: if( State == RUNNING ) break; State = RUNNING; ReDraw( hwnd ); if( InHardMode ) { WinLockInput( 0, FALSE ); InHardMode = FALSE; } State = RunIt() ? BROKE : TERMINATED; if( HardMode ) { WinLockInput( 0, TRUE ); InHardMode = TRUE; } ReDraw( hwnd ); break; case ID_KILL: if( State == RUNNING ) break; if( InHardMode ) { WinLockInput( 0, FALSE ); InHardMode = FALSE; } if( State != NONE ) { KillIt(); State = NONE; } ReDraw( hwnd ); break; case ID_HARD: if( State == RUNNING ) break; HardMode = !HardMode; TellHardMode( HardMode ? (char)-1 : 0 ); ReDraw( hwnd ); break; case ID_EXITPROG: if( InHardMode ) { WinLockInput( 0, FALSE ); InHardMode = FALSE; } if( State == RUNNING ) break; WinPostMsg( hwnd, WM_CLOSE, 0L, 0L ); break; default: return WinDefWindowProc( hwnd, msg, mp1, mp2 ); } break; case WM_ERASEBACKGROUND: /******************************************************************/ /* Return TRUE to request PM to paint the window background */ /* in SYSCLR_WINDOW. */ /******************************************************************/ return (MRESULT)( TRUE ); case WM_PAINT: /******************************************************************/ /* Window contents are drawn here in WM_PAINT processing. */ /******************************************************************/ /* Create a presentation space */ hps = WinBeginPaint( hwnd, NULL, &rc ); pt.x = 50; pt.y = 50; /* Set the text coordinates, */ GpiSetColor( hps, CLR_NEUTRAL ); /* colour of the text, */ GpiSetBackColor( hps, CLR_BACKGROUND ); /* its background and */ GpiSetBackMix( hps, BM_OVERPAINT ); /* how it mixes, */ /* and draw the string...*/ strcpy( WhatItIs[ State ] +HARD_POS, IsHardMode[ HardMode ] ); GpiCharStringAt( hps, &pt, (LONG)strlen( WhatItIs[ State ] ), WhatItIs[ State ] ); WinEndPaint( hps ); /* Drawing is complete */ break; case WM_CLOSE: /******************************************************************/ /* This is the place to put your termination routines */ /******************************************************************/ if( State == RUNNING ) break; FiniIt(); WinPostMsg( hwnd, WM_QUIT, 0L, 0L ); /* Cause termination */ break; default: /******************************************************************/ /* Everything else comes here. This call MUST exist */ /* in your window procedure. */ /******************************************************************/ return WinDefWindowProc( hwnd, msg, mp1, mp2 ); } return FALSE; }
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) { RECTL clientrect; /* Rectangle coordinates */ HPS hpsPaint; POINTL pt; /* String screen coordinates */ BOOL Invalid; int Line; ERRORID Err; HWND Focus,Active; HMQ hmqDeb; PID pid,cpid; TID tid,ctid; switch( msg ) { case WM_CREATE: WinStartTimer(hab,hwnd,1234,500); break; /* end the application. */ case WM_TIMER: rc=DosOpen("KBD$", &hKbd, &Action, 0, FILE_NORMAL, FILE_OPEN, OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE | OPEN_FLAGS_FAIL_ON_ERROR, 0); if (rc) { char Buf[80]; sprintf(Buf,"Open rc = %d",rc); WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, Buf, "TRAPIT", 1234, MB_OK); } /* endif */ Dlen= sizeof(State); rc = DosDevIOCtl( hKbd, 4, 0x73, 0, 0, 0, &State, sizeof(State), &Dlen ); Shift=(USHORT)State; DosClose(hKbd); Invalid=FALSE; if ((State&0x0500)==0x0500) { if (Color!=CLR_RED) { Color=CLR_RED; Invalid=TRUE; } /* endif */ Focus=WinQueryFocus(HWND_DESKTOP); Active=WinQueryActiveWindow(HWND_DESKTOP); WinQueryWindowProcess(Focus,&pid,&tid); hmqDeb=(HMQ)WinQueryWindowULong(Focus,QWL_HMQ); if (hmqDeb==hmq) { sprintf(Buffer,"Sorry Can't unhang Myself"); } else { DosKillProcess(DKP_PROCESS,pid); } /* endif */ } else { if ((State&0x0A00)==0x0A00) { if (Color!=CLR_BLUE) { Color=CLR_BLUE; Invalid=TRUE; } /* endif */ Focus=WinQueryFocus(HWND_DESKTOP); Active=WinQueryActiveWindow(HWND_DESKTOP); WinQueryWindowProcess(Focus,&pid,&tid); hmqDeb=(HMQ)WinQueryWindowULong(Focus,QWL_HMQ); if (hmqDeb==hmq) { sprintf(Buffer,"Sorry Can't trap Myself"); } else { HENUM hEnum; CHAR Class[20]; HWND Child; hEnum = WinBeginEnumWindows(HWND_OBJECT); while ( (Child=WinGetNextWindow(hEnum)) != 0) { WinQueryWindowProcess(Child,&cpid,&ctid); if (cpid==pid) { Class[0]=0; WinQueryClassName(Child,sizeof(Class)-1,Class); if (strcmp(Class,"Killer")==0) { if (WinPostMsg(Child,WM_USER+1,0,0)) { DosBeep(1800,80); DosBeep(600,80); DosBeep(1800,80); } } /* endif */ } /* endif */ } WinEndEnumWindows(hEnum); } /* endif */ } else { if (Color!=CLR_BACKGROUND) { Color=CLR_BACKGROUND; Invalid=TRUE; } } /* endif */ } /* endif */ if (Invalid) { WinInvalidateRect( hwnd, NULL, TRUE ); } /* endif */ break; case WM_PAINT: hpsPaint=WinBeginPaint( hwnd,0, &clientrect ); WinFillRect( hpsPaint, &clientrect,Color );/* Fill invalid rectangle */ pt.x = 10; pt.y = 190; /* Set the text coordinates, */ GpiCharStringAt( hpsPaint, &pt, (LONG)strlen(Buffer),Buffer); for (Line=0;Line<8;Line++ ) { pt.x = 10; pt.y = 170-(20*Line); /* Set the text coordinates, */ GpiCharStringAt( hpsPaint, &pt, (LONG)strlen(LabelText[Line]),LabelText[Line]); } /* endfor */ WinEndPaint( hpsPaint ); /* Drawing is complete */ break; case WM_CLOSE: /******************************************************************/ /* This is the place to put your termination routines */ /******************************************************************/ WinPostMsg( hwnd, WM_QUIT, 0L, 0L ); /* Cause termination */ break; default: /******************************************************************/ /* Everything else comes here. This call MUST exist */ /* in your window procedure. */ /******************************************************************/ return WinDefWindowProc( hwnd, msg, mp1, mp2 ); } return FALSE; }
void ColumnPaint(SCREEN *pstScreen) { HPS hps; RECTL rclRect; WORD wChar; BOOL bLastWasNewLine = FALSE; WORD wDirection; LONG lReadIndex; WORD wFilterMask; BOOL bTestNewLine; WORD wNewLine; BOOL bWrap; BOOL bSkip; WORD wFunc; LONG lPacketCount; LONG lOldTop; DosRequestMutexSem(hmtxColGioBlockedSem,10000); WinInvalidateRect(pstScreen->hwndClient,(PRECTL)NULL,FALSE); hps = WinBeginPaint(pstScreen->hwndClient,(HPS)NULL,&rclRect); if (WinIsWindowShowing(pstScreen->hwndClient)) { rclRect.yBottom = 0; rclRect.yTop = (pstScreen->lHeight + stCell.cy); rclRect.xLeft = 0; rclRect.xRight = (pstScreen->lWidth + stCell.cx); WinFillRect(hps,&rclRect,pstScreen->lBackgrndColor); if (pstScreen->wDirection == CS_WRITE) { if ((stRead.lBackgrndColor == stWrite.lBackgrndColor) && (stWrite.hwndScroll == (HWND)NULL)) { rclRect.xRight = stWrite.rcl.xRight; rclRect.xLeft = stWrite.rcl.xRight - 1; rclRect.yBottom = 0; rclRect.yTop = stWrite.rcl.yTop; if (stWrite.lBackgrndColor == CLR_WHITE) WinFillRect(hps,&rclRect,CLR_BLACK); else WinFillRect(hps,&rclRect,(stWrite.lBackgrndColor ^ stWrite.lBackgrndColor)); stWrite.rclDisp.xRight = (stWrite.lWidth + stCell.cx - 1); } else stWrite.rclDisp.xRight = (stWrite.lWidth + stCell.cx); } if (stCFG.fDisplaying & (DISP_DATA | DISP_FILE)) { pstScreen->Pos.y = pstScreen->lHeight; pstScreen->Pos.x = 0; lReadIndex = pstScreen->lScrollIndex; pstScreen->rclDisp.xLeft = 0L; if (pstScreen->wDirection == CS_READ) GpiCreateLogFont(hps,(PSTR8)"HEXFONTS",2,&astFontAttributes[stCFG.wColReadFont]); else GpiCreateLogFont(hps,(PSTR8)"HEXFONTS",2,&astFontAttributes[stCFG.wColWriteFont]); GpiSetCharSet(hps,2); GpiSetColor(hps,pstScreen->lForegrndColor); if (pstScreen->bFilter) wFilterMask = (WORD)pstScreen->byDisplayMask; else wFilterMask = 0x00ff; wNewLine = (WORD)pstScreen->byNewLineChar; wDirection = pstScreen->wDirection; bTestNewLine = pstScreen->bTestNewLine; bSkip = pstScreen->bSkipBlankLines; bWrap = pstScreen->bWrap; lPacketCount = 0; while (lReadIndex < lScrollCount) { if (lPacketCount == 0) { wChar = pwScrollBuffer[lReadIndex]; wFunc = (pwScrollBuffer[lReadIndex++] & 0x0ff00); switch (wFunc) { case CS_PACKET_DATA: lPacketCount = (wChar & 0x00ff); break; case CS_WRITE_IMM: if (wFunc != CS_READ) wFunc = CS_WRITE; case CS_READ_IMM: if (wFunc != CS_WRITE) wFunc = CS_READ; case CS_WRITE: case CS_READ: if (wFunc != wDirection) continue; wChar &= wFilterMask; if (bTestNewLine && (wChar == wNewLine)) { if (bSkip && bLastWasNewLine) continue; if (CharPrintable((BYTE *)&wChar,pstScreen)) if (bWrap || (pstScreen->Pos.x <= pstScreen->lWidth)) GpiCharStringAt(hps,&pstScreen->Pos,1,(BYTE *)&wChar); if (pstScreen->Pos.y <= 0) break; pstScreen->Pos.y -= stCell.cy; bLastWasNewLine = TRUE; pstScreen->Pos.x = 0L; } else { if (CharPrintable((BYTE *)&wChar,pstScreen)) { bLastWasNewLine = FALSE; if (pstScreen->Pos.x <= pstScreen->lWidth) { GpiCharStringAt(hps,&pstScreen->Pos,1,(BYTE *)&wChar); pstScreen->Pos.x += stCell.cx; } else { if (pstScreen->bWrap) { pstScreen->Pos.x = 0; pstScreen->Pos.y -= stCell.cy; GpiCharStringAt(hps,&pstScreen->Pos,1,(BYTE *)&wChar); pstScreen->Pos.x += stCell.cx; } if (pstScreen->Pos.y < 0 ) break; } } } } } else { lPacketCount--; lReadIndex++; } } } else { // pstScreen->lLeadRow = pstScreen->lHeight; pstScreen->Pos.y = pstScreen->lHeight; pstScreen->Pos.x = 0L; } } WinEndPaint(hps); DosReleaseMutexSem(hmtxColGioBlockedSem); // WinInvalidateRect(hwndStatus,(PRECTL)NULL,FALSE); }
/* * * BrowseWndProc * * DESCRIPTION: * * Processes messages for the Browse-O-Matic client window. * */ MRESULT EXPENTRY BrowseWndProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { switch( msg){ case WM_CREATE: { CHAR pszTitle[ MAX_TITLE_LENGTH]; PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA)mp1; WinSetWindowPtr( hwnd, QWL_USER, pWindowData); /*******************/ /* Load the object */ /*******************/ _LoadObject( pWindowData->somSelf, pWindowData->pszObjectName, &pWindowData->ulFileLength, &pWindowData->pBuffer, &pWindowData->pLines, &pWindowData->usNumberOfTextLines, &pWindowData->usNumberOfTextColumns); _GetLinesAndColumns( pWindowData->somSelf, pWindowData->bDisplay, &pWindowData->sTotalLines, &pWindowData->sTotalColumns, pWindowData->usNumberOfTextLines, pWindowData->usNumberOfTextColumns, pWindowData->ulFileLength); /*********************************************/ /* Get the window handle for the scroll bars */ /*********************************************/ pWindowData->hwndVscroll = WinWindowFromID( WinQueryWindow( hwnd, QW_PARENT), FID_VERTSCROLL); pWindowData->hwndHscroll = WinWindowFromID( WinQueryWindow( hwnd, QW_PARENT), FID_HORZSCROLL); /*************************/ /* Save font information */ /*************************/ WinSendMsg( hwnd, IDL_SETFONTINFO, (MPARAM)0, (MPARAM)0); /*****************/ /* Get the focus */ /*****************/ WinSetFocus( HWND_DESKTOP, hwnd); /*****************************************************/ /* Create the title for the Browse-O-Matic title bar */ /*****************************************************/ if( pWindowData->bDisplay == PMBROWSE_HEX_DISPLAY_MODE) sprintf( pszTitle, "Object: %s (%d Bytes)", pWindowData->pszObjectName, pWindowData->ulFileLength); else sprintf( pszTitle, "Object: %s (%hd Lines)", pWindowData->pszObjectName, pWindowData->sTotalLines); /************************************************/ /* Register the current open view of the object */ /************************************************/ _wpAddToObjUseList( pWindowData->somSelf, &(pWindowData->UseItem)); _wpRegisterView( pWindowData->somSelf, WinQueryWindow( hwnd, QW_PARENT), pszTitle); } break; case WM_CLOSE: { HWND hwndFrame; PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr( hwnd, QWL_USER); hwndFrame = WinQueryWindow( hwnd, QW_PARENT); /*****************************************************/ /* Save the window info - size, location, and fonts. */ /*****************************************************/ WinStoreWindowPos( APPL_NAME, pWindowData->pszApplKey, hwndFrame); /**********************************************************/ /* Free the window data and unload the file system object */ /**********************************************************/ if( pWindowData){ if( pWindowData->pszObjectName) _wpFreeMem( pWindowData->somSelf, ( PBYTE)pWindowData->pszObjectName); _wpFreeMem( pWindowData->somSelf, ( PBYTE)pWindowData); } _UnloadObject( pWindowData->somSelf, pWindowData->pBuffer, pWindowData->pLines); _wpDeleteFromObjUseList( pWindowData->somSelf, &pWindowData->UseItem); /*******************/ /* Kill the window */ /*******************/ WinPostMsg( hwnd, WM_QUIT, 0, 0 ); WinDestroyWindow( hwndFrame); } break; /*******************************************************************/ /* The font characteristics have changed. This happens when a font */ /* from the font palette is dropped on the client window. */ /*******************************************************************/ case WM_PRESPARAMCHANGED: { PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr( hwnd, QWL_USER); if( (ULONG)mp1 == PP_FONTNAMESIZE){ /***********************************************/ /* Get the new font information and redraw the */ /* window with the new font/font size. */ /***********************************************/ WinSendMsg( hwnd, IDL_SETFONTINFO, (MPARAM)0, (MPARAM)0); WinSendMsg( hwnd, WM_SIZE, 0, MPFROM2SHORT( pWindowData->sClientWidth, pWindowData->sClientHeight)); } } break; case WM_SIZE: { PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr( hwnd, QWL_USER); /***************************************/ /* Save client window size information */ /***************************************/ pWindowData->sClientWidth = SHORT1FROMMP( mp2); pWindowData->sClientHeight = SHORT2FROMMP( mp2); pWindowData->sPageHeight = pWindowData->sClientHeight/ pWindowData->sCharHeight; pWindowData->sPageWidth = pWindowData->sClientWidth / pWindowData->sCharWidth; /**************************************/ /* Set the ranges for the scroll bars */ /**************************************/ WinPostMsg( pWindowData->hwndVscroll, SBM_SETSCROLLBAR, (MPARAM)pWindowData->sCurrentLine, MPFROM2SHORT( 0, pWindowData->sTotalLines - pWindowData->sPageHeight)); WinPostMsg( pWindowData->hwndHscroll, SBM_SETSCROLLBAR, (MPARAM)pWindowData->sCurrentColumn, MPFROM2SHORT( 0, pWindowData->sTotalColumns - pWindowData->sPageWidth)); /*************************************/ /* Set scroll bar thumb control size */ /*************************************/ WinPostMsg( pWindowData->hwndVscroll, SBM_SETTHUMBSIZE, MPFROM2SHORT( pWindowData->sPageHeight, pWindowData->sTotalLines), (MPARAM) 0); WinPostMsg( pWindowData->hwndHscroll, SBM_SETTHUMBSIZE, MPFROM2SHORT( pWindowData->sPageWidth, pWindowData->sTotalColumns), (MPARAM) 0); /************************************************************/ /* If the all the lines and/or columns can fit in the new */ /* sized window, set the sCurrentLine and/or sCurrentColumn */ /* to the top/right side. */ /************************************************************/ if( pWindowData->sPageHeight >= pWindowData->sTotalLines) pWindowData->sCurrentLine = 0; if( pWindowData->sPageWidth >= pWindowData->sTotalColumns) pWindowData->sCurrentColumn = 0; /********************************************/ /* Repaint window with new size information */ /********************************************/ WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); case WM_PAINT: { HPS hps; CHAR pszText[255]; UINT nLength = 0; RECTL rect; POINTL point; SHORT sLine; SHORT sTopLine; SHORT sBottomLine; SHORT sLinesFromTop; PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr( hwnd, QWL_USER); hps = WinBeginPaint( hwnd, NULLHANDLE, &rect); /*******************************************/ /* Clear the area that needs to be redrawn */ /*******************************************/ GpiErase( hps); /********************************/ /* Determine first clipped line */ /********************************/ sLinesFromTop = ( pWindowData->sClientHeight - rect.yTop) / pWindowData->sCharHeight; rect.yTop = pWindowData->sClientHeight - ( pWindowData->sCharHeight * sLinesFromTop); /***************************************************************/ /* Determine the first position to write at. NOTE: PM handles */ /* clipping for point.x < 0. Any characters written before the */ /* the first column or after the last column are clipped. */ /***************************************************************/ point.y = rect.yTop - pWindowData->sCharHeight + pWindowData->sCharDescender; point.x = pWindowData->sCurrentColumn*pWindowData->sCharWidth * -1; /***********************************************/ /* Determine the top and bottom lines to write */ /***********************************************/ sTopLine = rect.yTop / pWindowData->sCharHeight; sBottomLine = rect.yBottom / pWindowData->sCharHeight; /*********************************************************/ /* Make sure that we aren't trying to display more lines */ /* then are available. */ /*********************************************************/ if( pWindowData->sPageHeight - sBottomLine + 1 > pWindowData->sTotalLines - pWindowData->sCurrentLine) sBottomLine=pWindowData->sPageHeight-(pWindowData->sTotalLines - pWindowData->sCurrentLine) + 1; /********************************/ /* Redraw the invalid rectangle */ /********************************/ for( sLine = sTopLine; sLine >= sBottomLine; sLine--){ /*******************************************/ /* Get the line of text or hex information */ /* that we are going to write. */ /*******************************************/ if( pWindowData->bDisplay == PMBROWSE_HEX_DISPLAY_MODE) nLength = _GetHexLine( pWindowData->somSelf, pWindowData->sPageHeight-sLine+pWindowData->sCurrentLine +1, pWindowData->pBuffer, pWindowData->ulFileLength, pszText); else nLength = _GetTextLine( pWindowData->somSelf, pWindowData->sPageHeight-sLine+pWindowData->sCurrentLine +1, pWindowData->pLines, pszText); /******************/ /* Write the text */ /******************/ if( nLength != 0) GpiCharStringAt( hps, &point, nLength, pszText); point.y -= pWindowData->sCharHeight; } WinEndPaint( hps); } return( 0); /*******************************************/ /* Keyboard support for scrolling and help */ /*******************************************/ case WM_CHAR: /****************************************/ /* Show general help if user selects F1 */ /****************************************/ if( CHARMSG( &msg)->vkey == VK_F1){ PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr(hwnd,QWL_USER); _wpDisplayHelp( pWindowData->somSelf, PANEL_MAIN, "browse.hlp"); return 0; } if( (CHARMSG( &msg)->fs & KC_KEYUP)) return 0; switch( CHARMSG( &msg)->vkey){ case VK_UP: WinPostMsg( hwnd, WM_VSCROLL, 0, MPFROM2SHORT( 0, SB_LINEUP)); return 0; case VK_DOWN: WinPostMsg( hwnd, WM_VSCROLL, 0, MPFROM2SHORT( 0, SB_LINEDOWN)); return 0; case VK_RIGHT: /************************************************************/ /* Ctrl-Right scrolls one page to the right. Right scrolls */ /* to the right. */ /************************************************************/ if( (CHARMSG( &msg)->fs & KC_CTRL)) WinPostMsg( hwnd, WM_HSCROLL, 0, MPFROM2SHORT(0, SB_PAGERIGHT)); else WinPostMsg( hwnd, WM_HSCROLL, 0, MPFROM2SHORT(0, SB_LINERIGHT)); return 0; case VK_LEFT: /*********************************************************/ /* Ctrl-Left scrolls one page to the left. Left scrolls */ /* to the Left. */ /*********************************************************/ if( (CHARMSG( &msg)->fs & KC_CTRL)) WinPostMsg( hwnd, WM_HSCROLL, 0, MPFROM2SHORT( 0, SB_PAGELEFT)); else WinPostMsg( hwnd, WM_HSCROLL, 0, MPFROM2SHORT( 0, SB_LINELEFT)); return 0; case VK_PAGEUP: WinPostMsg( hwnd, WM_VSCROLL, 0, MPFROM2SHORT( 0, SB_PAGEUP)); return 0; case VK_PAGEDOWN: WinPostMsg( hwnd, WM_VSCROLL, 0, MPFROM2SHORT( 0, SB_PAGEDOWN)); return 0; case VK_HOME: { PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr(hwnd,QWL_USER); /*********************************************************/ /* Ctrl-Home positions at the first line, Home positions */ /* at the beginning of the current line. */ /*********************************************************/ if( (CHARMSG( &msg)->fs & KC_CTRL)){ WinPostMsg( hwnd, WM_VSCROLL, (MPARAM)0, MPFROM2SHORT( 0, SB_SLIDERPOSITION)); WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, MPFROMSHORT( 0), 0); } else{ WinPostMsg( hwnd, WM_HSCROLL, (MPARAM)0, MPFROM2SHORT( 0, SB_SLIDERPOSITION)); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, MPFROMSHORT( 0), 0); } return 0; } case VK_END: { PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr(hwnd,QWL_USER); /*********************************************************/ /* Ctrl-End positions at the last line, End positions at */ /* the end of the current line. */ /*********************************************************/ if( (CHARMSG( &msg)->fs & KC_CTRL)){ WinPostMsg( hwnd, WM_VSCROLL, (MPARAM)0, MPFROM2SHORT( pWindowData->sTotalLines - pWindowData->sPageHeight, SB_SLIDERPOSITION)); WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, MPFROMSHORT( pWindowData->sTotalLines - pWindowData->sPageHeight), 0); } else{ WinPostMsg( hwnd, WM_HSCROLL, (MPARAM)0, MPFROM2SHORT( pWindowData->sTotalColumns - pWindowData->sPageWidth, SB_SLIDERPOSITION)); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, MPFROMSHORT( pWindowData->sTotalColumns - pWindowData->sPageWidth), 0); } return 0; } } break; /******************/ /* Scroll Up/Down */ /******************/ case WM_VSCROLL: { PBROWSEDATA pWindowData; pWindowData = (PBROWSEDATA) WinQueryWindowPtr(hwnd,QWL_USER); switch( SHORT2FROMMP( mp2)){ case SB_LINEUP: if( pWindowData->sCurrentLine > 0){ pWindowData->sCurrentLine--; WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentLine, 0); WinScrollWindow( hwnd, 0, pWindowData->sCharHeight * -1, NULL, NULL, NULLHANDLE, NULL, SW_INVALIDATERGN); } return( 0); case SB_LINEDOWN: if( pWindowData->sCurrentLine < pWindowData->sTotalLines - pWindowData->sPageHeight){ pWindowData->sCurrentLine++; WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentLine, 0); WinScrollWindow( hwnd, 0, pWindowData->sCharHeight, NULL, NULL, NULLHANDLE, NULL, SW_INVALIDATERGN); } return( 0); case SB_PAGEUP: if( pWindowData->sCurrentLine > 0){ pWindowData->sCurrentLine = max( 0, pWindowData->sCurrentLine - pWindowData->sPageHeight); WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentLine,0); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); case SB_PAGEDOWN: if( pWindowData->sCurrentLine < pWindowData->sTotalLines - pWindowData->sPageHeight){ pWindowData->sCurrentLine= min( pWindowData->sTotalLines - pWindowData->sPageHeight, pWindowData->sCurrentLine + pWindowData->sPageHeight); WinPostMsg( pWindowData->hwndVscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentLine,0); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); case SB_SLIDERPOSITION: /***********************************************************/ /* Can't change current line if all the text fits in the */ /* window. */ /***********************************************************/ if( pWindowData->sTotalLines > pWindowData->sPageHeight){ pWindowData->sCurrentLine = SHORT1FROMMP( mp2); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); } } break; /*********************/ /* Scroll Right/Left */ /*********************/ case WM_HSCROLL: { PBROWSEDATA pWindowData; pWindowData = ( PBROWSEDATA)WinQueryWindowPtr( hwnd, QWL_USER); switch( SHORT2FROMMP( mp2)){ case SB_LINELEFT: if( pWindowData->sCurrentColumn > 0){ pWindowData->sCurrentColumn = max( 0, pWindowData->sCurrentColumn - 1); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentColumn,0); WinScrollWindow( hwnd, pWindowData->sCharWidth, 0, NULL, NULL, NULLHANDLE, NULL, SW_INVALIDATERGN); } return( 0); case SB_LINERIGHT: if(pWindowData->sCurrentColumn < pWindowData->sTotalColumns - pWindowData->sPageWidth){ pWindowData->sCurrentColumn=min(pWindowData->sTotalColumns, pWindowData->sCurrentColumn + 1); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentColumn, 0); WinScrollWindow( hwnd, pWindowData->sCharWidth * -1, 0, NULL, NULL, NULLHANDLE, NULL, SW_INVALIDATERGN); } return( 0); case SB_PAGELEFT: if( pWindowData->sCurrentColumn > 0){ pWindowData->sCurrentColumn = max( 0, pWindowData->sCurrentColumn - pWindowData->sPageWidth); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentColumn, 0); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); case SB_PAGERIGHT: if(pWindowData->sCurrentColumn < pWindowData->sTotalColumns - pWindowData->sPageWidth){ pWindowData->sCurrentColumn=min(pWindowData->sTotalColumns - pWindowData->sPageWidth, pWindowData->sCurrentColumn + pWindowData->sPageWidth); WinPostMsg( pWindowData->hwndHscroll, SBM_SETPOS, (MPARAM)pWindowData->sCurrentColumn, 0); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); case SB_SLIDERPOSITION: /***********************************************************/ /* Can't change current column if all the text fits in the */ /* window. */ /***********************************************************/ if( pWindowData->sTotalColumns > pWindowData->sPageWidth){ pWindowData->sCurrentColumn = SHORT1FROMMP( mp2); WinInvalidateRect( hwnd, NULL, FALSE); } return( 0); } } break; /*****************************/ /* Get font size information */ /*****************************/ case IDL_SETFONTINFO: { HPS hps; FONTMETRICS fm; PBROWSEDATA pWindowData; pWindowData = ( PBROWSEDATA)WinQueryWindowPtr( hwnd, QWL_USER); hps = WinGetPS( hwnd); GpiQueryFontMetrics( hps, sizeof( fm), &fm); WinReleasePS( hps); /***********************************************************/ /* The character width is average of the average uppercase */ /* and average lower case widths. */ /***********************************************************/ pWindowData->sCharWidth = (SHORT)fm.lMaxCharInc; pWindowData->sCharHeight = (SHORT)fm.lMaxBaselineExt; pWindowData->sCharDescender = (SHORT)fm.lMaxDescender; } return( 0); /*********************************************/ /* Display no help available message to user */ /*********************************************/ case HM_HELPSUBITEM_NOT_FOUND: return( ( MRESULT)FALSE); /**************************************/ /* Return name of help for keys panel */ /**************************************/ case HM_QUERY_KEYS_HELP: return( ( MRESULT)PANEL_HELPKEYS); } /********************************************************/ /* Let the default window procedure process the message */ /********************************************************/ return( WinDefWindowProc( hwnd, msg, mp1, mp2)); }
/************************************************************************** * * Name : MyWindowProc * * Description: The window procedure associated with the client area in * the standard frame window. It processes all messages * either sent or posted to the client area, depending on * the message command and parameters. * * Concepts : * * API's : WinLoadString * WinInvalidateRegion * WinPostMsg * WinDefWindowProc * WinBeginPaint * GpiSetColor * GpiSetBackColor * GpiSetBackMix * GpiCharStringAt * WinEndPaint * * Parameters : hwnd = window handle * msg = message code * mp1 = first message parameter * mp2 = second message parameter * * Return : depends on message sent * *************************************************************************/ MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) { switch( msg ) { case WM_CREATE: /* * Window initialization is performed here in WM_CREATE processing * WinLoadString loads strings from the resource file. */ WinLoadString( hab, (HMODULE)0L, IDS_HELLO, STRINGLENGTH, szHello ); WinLoadString( hab, (HMODULE)0L, IDS_1, STRINGLENGTH, sz1 ); WinLoadString( hab, (HMODULE)0L, IDS_2, STRINGLENGTH, sz2 ); WinLoadString( hab, (HMODULE)0L, IDS_3, STRINGLENGTH, sz3 ); strcpy( szString, szHello ); /* Copy text Hello into szString*/ break; case WM_COMMAND: /* * When the user chooses option 1, 2, or 3 from the Options pull- * down, the text string is set to 1, 2, or 3, and * WinInvalidateRegion sends a WM_PAINT message. * When Exit is chosen, the application posts itself a WM_CLOSE * message. */ { USHORT command; /* WM_COMMAND command value */ command = SHORT1FROMMP(mp1); /* Extract the command value */ switch (command) { case ID_OPTION1: strcpy( szString, sz1 ); WinInvalidateRegion( hwnd, 0L, false ); LockIt(); break; case ID_OPTION2: strcpy( szString, sz2 ); WinInvalidateRegion( hwnd, 0L, false ); UnLockIt(); break; case ID_OPTION3: #pragma aux int3 = "int 3"; int3(); strcpy( szString, sz3 ); WinInvalidateRegion( hwnd, 0L, false ); break; case ID_EXITPROG: WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 ); break; default: return WinDefWindowProc( hwnd, msg, mp1, mp2 ); } break; } case WM_ERASEBACKGROUND: /* * Return true to request PM to paint the window background * in SYSCLR_WINDOW. */ return (MRESULT)( true ); case WM_PAINT: /* * Window contents are drawn here in WM_PAINT processing. */ { HPS hps; /* Presentation Space handle */ RECTL rc; /* Rectangle coordinates */ POINTL pt; /* String screen coordinates */ char buff[256]; /* Create a presentation space */ sprintf( buff, "hab = %8.8x, hmq = %8.8x, hwnd = %8.8x", hab, hmq, hwnd ); hps = WinBeginPaint( hwnd, 0L, &rc ); pt.x = 0; pt.y = 50; /* Set the text coordinates, */ GpiSetColor( hps, CLR_NEUTRAL ); /* colour of the text, */ GpiSetBackColor( hps, CLR_BACKGROUND ); /* its background and */ GpiSetBackMix( hps, BM_OVERPAINT ); /* how it mixes, */ /* and draw the string...*/ GpiCharStringAt( hps, &pt, (LONG)strlen( buff ), buff ); WinEndPaint( hps ); /* Drawing is complete */ break; } case WM_CLOSE: /* * This is the place to put your termination routines */ WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );/* Cause termination*/ break; default: /* * Everything else comes here. This call MUST exist * in your window procedure. */ return WinDefWindowProc( hwnd, msg, mp1, mp2 ); } return( (MRESULT)false ); } /* End of MyWindowProc */
/************************************************************************** * * Name : MyWindowProc * * Description: The window procedure associated with the client area in * the standard frame window. It processes all messages * either sent or posted to the client area, depending on * the message command and parameters. * * Concepts : * * API's : WinLoadString * WinInvalidateRegion * WinPostMsg * WinDefWindowProc * WinBeginPaint * GpiSetColor * GpiSetBackColor * GpiSetBackMix * GpiCharStringAt * WinEndPaint * * Parameters : hwnd = window handle * msg = message code * mp1 = first message parameter * mp2 = second message parameter * * Return : depends on message sent * *************************************************************************/ MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) { switch( msg ) { case WM_TIMER: { WinInvalidateRegion( hwnd, 0L, FALSE ); break; } case WM_CREATE: /* * Window initialization is performed here in WM_CREATE processing * WinLoadString loads strings from the resource file. */ WinLoadString( hab, (HMODULE)0L, IDS_HELLO, STRINGLENGTH, szHello ); WinLoadString( hab, (HMODULE)0L, IDS_1, STRINGLENGTH, sz1 ); WinLoadString( hab, (HMODULE)0L, IDS_2, STRINGLENGTH, sz2 ); WinLoadString( hab, (HMODULE)0L, IDS_3, STRINGLENGTH, sz3 ); strcpy( szString, szHello ); /* Copy text Hello into szString*/ break; case WM_COMMAND: /* * When the user chooses option 1, 2, or 3 from the Options pull- * down, the text string is set to 1, 2, or 3, and * WinInvalidateRegion sends a WM_PAINT message. * When Exit is chosen, the application posts itself a WM_CLOSE * message. */ { USHORT command; /* WM_COMMAND command value */ command = SHORT1FROMMP(mp1); /* Extract the command value */ switch (command) { case ID_EXITPROG: WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 ); break; default: return WinDefWindowProc( hwnd, msg, mp1, mp2 ); } break; } case WM_ERASEBACKGROUND: /* * Return TRUE to request PM to paint the window background * in SYSCLR_WINDOW. */ return (MRESULT)( TRUE ); case WM_PAINT: /* * Window contents are drawn here in WM_PAINT processing. */ { HPS hps; /* Presentation Space handle */ RECTL rc; /* Rectangle coordinates */ POINTL pt; /* String screen coordinates */ POINTL pPos; LONG lColor,r,g,b; FATTRS fat; HPS shps = WinGetScreenPS(HWND_DESKTOP); fat.usRecordLength = sizeof(FATTRS); /* sets size of structure */ fat.fsSelection = 0; /* uses default selection */ fat.lMatch = 0L; /* does not force match */ fat.idRegistry = 0; /* uses default registry */ fat.usCodePage = 0; /* code-page 850 */ fat.lMaxBaselineExt = 14L; /* requested font height is 12 pels */ fat.lAveCharWidth = 14L; /* requested font width is 12 pels */ fat.fsType = 0; /* uses default type */ fat.fsFontUse = FATTR_FONTUSE_NOMIX;/* doesn't mix with graphics */ strcpy(fat.szFacename ,"Courier"); WinQueryPointerPos(HWND_DESKTOP, &pPos); hps = WinBeginPaint( hwnd, 0L, &rc ); GpiCreateLogColorTable(shps, 0, LCOLF_RGB, 0, 0, NULL); GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, NULL); pt.x = 10; pt.y = 27; /* Set the text coordinates, */ lColor=GpiQueryPel(shps, &pPos); GpiSetBackColor( hps, 16777215); /* its background and */ WinFillRect( hps, &rc, lColor); GpiSetBackMix( hps, BM_OVERPAINT ); /* how it mixes, */ b = lColor & 0x000000FF; lColor = lColor >> 8; g = lColor & 0x000000FF; lColor = lColor >> 8; r = lColor & 0x000000FF; WinReleasePS(shps); sprintf(szString,"Color: #%.2X%.2X%.2X",r,g,b); GpiCreateLogFont(hps, NULL, 1L, &fat); GpiSetCharSet(hps, 1L); GpiSetCharMode(hps, CM_MODE1); GpiCharStringAt( hps,&pt ,(LONG)strlen( szString ), szString ); WinEndPaint( hps ); /* Drawing is complete */ break; } case WM_CLOSE: WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );/* Cause termination*/ break; default: /* * Everything else comes here. This call MUST exist * in your window procedure. */ return WinDefWindowProc( hwnd, msg, mp1, mp2 ); } return (MRESULT)FALSE; } /* End of MyWindowProc */
/*---------------------------------------------------------------------------*/ void paintText( HPS hps,WINDOWINFO *pwi,POBJECT pObj,RECTL *prcl, int iMode ) { int iBreakCount, iSurplus ; PCHAR pStart, pEnd ; PCHAR pText; POINTL ptlStart, aptlTextBox [TXTBOX_COUNT] ; blocktext *pT; RECTL rclColumn; SIZEF sizfx; FIXED fxBreakExtra; int iLineBreak; int iLen; iSurplus = 0; pT = (blocktext *)pObj; if (iMode != MODE_PREPPRINTING) { if (pwi->usdrawlayer != pT->bt.usLayer) return; } /* ** Just in case the text starts with a linebreak... */ memset ((void *)aptlTextBox,0,( sizeof(POINTL) * TXTBOX_COUNT)); /* ** Get column rectangle of first column.. */ getColumnOutline(pT,&rclColumn,pwi,0,(BOOL)(iMode == MODE_PREPPRINTING)); pText = (PCHAR)pT->pszText; ptlStart.y = rclColumn.yTop ; if (!pText) return; if (prcl) { RECTL rclDest; /* ** prcl is only true for screen operations! ** For this moment we only check on the first column ** TODO !!! All columns */ if (!WinIntersectRect(hab,&rclDest,prcl,&rclColumn)) return; } if (iMode == MODE_PREPPRINTING) { sizfx.cx = pT->sizfx.fcx * pwi->usWidth; sizfx.cy = pT->sizfx.fcy * pwi->usHeight; } else { sizfx.cx = pT->sizfx.fcx * pwi->usFormWidth; sizfx.cy = pT->sizfx.fcy * pwi->usFormHeight; } setFont(pwi,&pT->fattrs,sizfx); if (iMode == MODE_PREPPRINTING) GpiQueryWidthTable(pwi->hps,0,MAX_NRWIDTH,pObj->lWidth); if (paintColumn(hps,pwi,pObj,rclColumn,iMode)) { rclColumn.xLeft += 20; rclColumn.yBottom += 20; rclColumn.xRight -= 20; rclColumn.yTop -= 20; } if (iMode != MODE_OUTLINE) GpiSetColor(hps,pT->bt.fColor); if (pwi->bPrinter) { /* ** Set the text on paper and get out!! */ PrintBlockText(pObj,pwi); return; } do // until end of text { iBreakCount = 0; fxBreakExtra = 0; iLineBreak = 0; while (*pText == ' ') // Skip over leading blanks pText++ ; pStart = pText ; do // until line is known { iLineBreak = 0; while (*pText == ' ') // Skip over leading blanks pText++ ; // Find next break point while (*pText != '\x00' && *pText != ' ' && *pText != '\r' && *pText != '\n') pText++ ; if (*pText == '\r'|| *pText == '\n') { pText++; iLineBreak = 1; if (*pText == '\n' || *pText == '\r') { pText++; iLineBreak = 2; } } /* ** A line with only a cariage return linefeed? */ if ( ((pText - pStart) - iLineBreak) <= 0) { pEnd = pText ; break; } // Determine text width GpiQueryTextBox (hps, (pText - pStart) - iLineBreak, pStart, TXTBOX_COUNT, aptlTextBox) ; // Normal case: text less wide than column if (aptlTextBox[TXTBOX_CONCAT].x < (rclColumn.xRight - rclColumn.xLeft)) { iBreakCount++ ; pEnd = pText; } // Text wider than window with only one word else if (iBreakCount == 0) { pEnd = pText ; break ; } // Text wider than window, so fix up and get out else { iBreakCount-- ; pText = pEnd ; /* ** Although we could have found a line break the ** text did not fit the line at all. So... */ iLineBreak = 0; break ; } } while (*pText != '\x00' && !iLineBreak) ; // Get the final text box iLen = (int)(pEnd - pStart); if (iLen - iLineBreak > 0) GpiQueryTextBox (hps, (pEnd - pStart)-iLineBreak, pStart, TXTBOX_COUNT, aptlTextBox) ; // Drop down by maximum ascender ptlStart.y -= aptlTextBox[TXTBOX_TOPLEFT].y ; // Find surplus space in text line iSurplus = rclColumn.xRight - rclColumn.xLeft - aptlTextBox[TXTBOX_CONCAT].x ; // Adjust starting position and // space and character spacing switch (pT->nAlign) { case ALIGN_LEFT: ptlStart.x = rclColumn.xLeft ; break ; case ALIGN_RIGHT: ptlStart.x = rclColumn.xLeft + iSurplus ; break ; case ALIGN_CENTER: ptlStart.x = rclColumn.xLeft + iSurplus / 2 ; break ; case ALIGN_JUST: ptlStart.x = rclColumn.xLeft ; if (*pText == '\x00') break ; if (iBreakCount > 0) { fxBreakExtra = 65536 * iSurplus / iBreakCount; GpiSetCharBreakExtra (hps,fxBreakExtra); } else if (pEnd - pStart - 1 > 0) { fxBreakExtra = 65536 * iSurplus / (pEnd - pStart - 1 - iLineBreak); GpiSetCharExtra (hps,fxBreakExtra); } break ; } // Drop down by maximum descender if (pT->nSpace != SPACE_NONE) ptlStart.y += aptlTextBox[TXTBOX_BOTTOMLEFT].y ; // Display the string & return to normal if ((pEnd - pStart)) GpiCharStringAt (hps, &ptlStart, (pEnd - pStart ) - iLineBreak, pStart) ; if (iMode == MODE_PREPPRINTING) { bTextMakePrintBlock(pObj, pwi, fxBreakExtra, iBreakCount, ptlStart, (LONG)((pEnd - pStart) -iLineBreak), pStart); } GpiSetCharExtra (hps, 0) ; GpiSetCharBreakExtra (hps, 0) ; // Do additional line-spacing switch (pT->nSpace) { case SPACE_HALF: ptlStart.y -= (aptlTextBox[TXTBOX_TOPLEFT].y - aptlTextBox[TXTBOX_BOTTOMLEFT].y) / 2 ; break ; case SPACE_DOUBLE: ptlStart.y -= aptlTextBox[TXTBOX_TOPLEFT].y - aptlTextBox[TXTBOX_BOTTOMLEFT].y ; break ; } } while (*pText != '\x00' && ptlStart.y > rclColumn.yBottom) ; }
/* QWL_USER+8 - reserved for text */ MRESULT EXPENTRY TestWndProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) { PMYCDATA pCData = (PMYCDATA)WinQueryWindowULong(hwnd, QWL_USER+4); PSZ pszText = (PSZ)WinQueryWindowULong(hwnd, QWL_USER+8); PMYCDATA pCreate; PCREATESTRUCT pCreateStruct; switch (msg) { /* we are creating our control */ case WM_CREATE: /* if data was passed in */ if (pCreate=(PMYCDATA)PVOIDFROMMP(mp1)) { /* allocate memory for the control data */ DosAllocMem((PPVOID) &pCData, (ULONG) pCreate->cb, PAG_COMMIT|PAG_READ | PAG_WRITE); /* copy the data that is passed in */ memcpy((PBYTE)pCData, (PBYTE) pCreate, pCreate->cb); /* save the control data pointer */ WinSetWindowULong(hwnd, QWL_USER+4, (ULONG)pCData); } /* endif */ /* allocate memory for the text */ DosAllocMem((PPVOID) &pszText, (ULONG) MAXTEXTLENGTH+1, PAG_COMMIT|PAG_READ | PAG_WRITE); /* save the text pointer */ WinSetWindowULong(hwnd, QWL_USER+8, (ULONG)pszText); /* initialize to a NULL string */ strcpy(pszText,""); pCreateStruct=(PCREATESTRUCT)mp2; if (pCreateStruct) { /* copy the text into the buffer provided */ strncpy(pszText, pCreateStruct->pszText, MAXTEXTLENGTH); /* NULL terminate the string */ pszText[MAXTEXTLENGTH]=0; } break; case WM_QUERYWINDOWPARAMS: { PWNDPARAMS pWndParams = (PWNDPARAMS)PVOIDFROMMP(mp1); MRESULT mr; /* call the default window proc first so that presentation /* parameters are handled */ mr = WinDefWindowProc( hwnd, msg, mp1, mp2 ); if (pWndParams) { if (pCData) { if (pWndParams->fsStatus & WPM_CBCTLDATA) { pWndParams->cbCtlData = pCData->cb; mr=(MRESULT)TRUE; } /* endif */ if (pWndParams->fsStatus & WPM_CTLDATA) { pWndParams->cbCtlData = pCData->cb; memcpy((PBYTE)pWndParams->pCtlData, (PBYTE)pCData, pCData->cb); mr=(MRESULT)TRUE; } /* endif */ } /* endif */ /* responding to WinQueryWindowTextLength */ if (pWndParams->fsStatus & WPM_CCHTEXT) { pWndParams->cchText = strlen(pszText); mr=(MRESULT)TRUE; } /* endif */ /* responding to WinQueryWindowText */ if (pWndParams->fsStatus & WPM_TEXT) { /* copy the text into the buffer provided */ strncpy(pWndParams->pszText, pszText, pWndParams->cchText); /* NULL terminate the string */ pWndParams->pszText[pWndParams->cchText]=0; mr=(MRESULT)TRUE; } /* endif */ } /* endif */ return mr; } break; case WM_SETWINDOWPARAMS: { PWNDPARAMS pWndParams = (PWNDPARAMS)PVOIDFROMMP(mp1); MRESULT mr; mr = WinDefWindowProc( hwnd, msg, mp1, mp2 ); if (pWndParams) { if (pWndParams->fsStatus & WPM_CTLDATA) { if (pCData) { DosFreeMem(pCData); } /* endif */ DosAllocMem((PPVOID) &(pCData), (ULONG) pWndParams->cbCtlData, PAG_COMMIT|PAG_READ | PAG_WRITE); WinSetWindowULong(hwnd, QWL_USER+4, (ULONG)pCData); memcpy((PBYTE)pCData, (PBYTE)pWndParams->pCtlData, pWndParams->cbCtlData); WinInvalidateRect(hwnd, 0, 0); mr=(MRESULT)TRUE; } /* endif */ /* responding to WinQueryWindowText */ if (pWndParams->fsStatus & WPM_TEXT) { /* copy the text into the buffer provided */ strncpy(pszText, pWndParams->pszText, MAXTEXTLENGTH); /* NULL terminate the string */ pszText[MAXTEXTLENGTH]=0; WinInvalidateRect(hwnd, 0, 0); mr=(MRESULT)TRUE; } /* endif */ } /* endif */ return mr; } break; case WM_PAINT: { HPS hps; RECTL rectlPaint; ULONG lTextColor, lBackColor; ULONG ulPPIndex; SWP swp; POINTL ptlPoint; WinQueryWindowPos(hwnd,&swp); hps=WinBeginPaint(hwnd, 0, &rectlPaint); /* put PS into RGB color mode */ GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, 0 ); if (!WinQueryPresParam(hwnd,PP_BACKGROUNDCOLOR,0,&ulPPIndex, sizeof(LONG),&lBackColor,QPF_NOINHERIT)) { lBackColor=WinQuerySysColor(HWND_DESKTOP,SYSCLR_WINDOW, 0); } /* endif */ if (!WinQueryPresParam(hwnd,PP_FOREGROUNDCOLOR,0,&ulPPIndex, sizeof(LONG),&lTextColor,QPF_NOINHERIT)) { lTextColor=WinQuerySysColor(HWND_DESKTOP,SYSCLR_ICONTEXT, 0); } /* endif */ WinFillRect(hps, &rectlPaint, lBackColor); ptlPoint.x=0; ptlPoint.y=0; GpiMove(hps,&ptlPoint); ptlPoint.x=swp.cx-1; ptlPoint.y=swp.cy-1; GpiBox(hps,DRO_OUTLINE,&ptlPoint,0,0); /* draw your control and its text here */ ptlPoint.x=0; ptlPoint.y=0; GpiSetCharAngle(hps,&pCData->gradient); GpiSetCharMode(hps,CM_MODE3); GpiSetColor(hps,lTextColor); GpiSetDrawControl(hps,DCTL_DISPLAY,DCTL_OFF); GpiSetDrawControl(hps,DCTL_BOUNDARY,DCTL_ON); GpiCharStringAt(hps, &ptlPoint,strlen(pszText),pszText); GpiQueryBoundaryData(hps,&rectlPaint); GpiSetDrawControl(hps,DCTL_DISPLAY,DCTL_ON); GpiSetDrawControl(hps,DCTL_BOUNDARY,DCTL_OFF); ptlPoint.x=-rectlPaint.xLeft; ptlPoint.y=-rectlPaint.yBottom; GpiCharStringAt(hps, &ptlPoint,strlen(pszText),pszText); WinEndPaint(hps); } break; case WM_DESTROY: if (pCData) DosFreeMem(pCData); if (pszText) DosFreeMem(pszText); break; case WM_PRESPARAMCHANGED: WinInvalidateRect(hwnd,0,FALSE); break; default: return WinDefWindowProc( hwnd, msg, mp1, mp2 ); } /* endswitch */ return (MRESULT) FALSE; }
/* * _DisplayLineInWindowWithColor - as it sounds! */ void _DisplayLineInWindowWithColor( LPWDATA w, int line, LPSTR text, int c1, int c2, int extra, int startcol ) { #ifdef _MBCS LPBYTE tmp; #else LPSTR tmp; #endif char buff[256]; int start,end,a,spend,cnt1,cnt2; WORD i; HWND hwnd; hwnd = w->hwnd; /*** Find dimensions of line ***/ #ifdef _MBCS tmp = FAR_mbsninc( (LPBYTE)text, startcol ); a = FAR_mbslen( tmp ); if( line < 1 || line >= w->height ) return; start = 0; spend = end = w->width - extra; if( end > a ) end = a; cnt1 = FAR_mbsnbcnt( tmp, end - start ); cnt2 = spend - end; FAR_mbsnbcpy( (LPBYTE)buff, tmp, cnt1 - start ); FARmemset( buff + cnt1, ' ', cnt2 ); tmp = FAR_mbsninc( (LPBYTE)buff, cnt1 + cnt2 ); *tmp = '\0'; #else tmp = text; tmp += startcol; a = FARstrlen( tmp ); if( line < 1 || line >= w->height ) return; start = 0; spend = end = w->width - extra; if( end > a ) end = a; cnt1 = end - start; cnt2 = spend - end; FARmemcpy( buff, tmp, cnt1 ); FARmemset( buff + cnt1, ' ', cnt2 ); buff[cnt1 + cnt2] = 0; #endif line--; #if defined( __OS2__ ) { RECTL rcl; HPS ps; POINTL ptl; POINTL points[TXTBOX_COUNT]; ptl.x = 0; ptl.y = (w->y2 - w->y1) - (line+1)*w->ychar + w->base_offset; ps = WinGetPS( hwnd ); _SelectFont( ps ); GpiQueryTextBox( ps, startcol, w->tmpbuff->data, TXTBOX_COUNT, points ); rcl.xLeft = points[TXTBOX_BOTTOMRIGHT].x; #ifdef _MBCS GpiQueryTextBox( ps, __mbslen( (unsigned char *)buff ), buff, TXTBOX_COUNT, points ); #else GpiQueryTextBox( ps, strlen( buff ), buff, TXTBOX_COUNT, points ); #endif rcl.xRight = points[TXTBOX_BOTTOMRIGHT].x; rcl.yTop = (w->y2 - w->y1) - line*w->ychar; rcl.yBottom = rcl.yTop - w->ychar; WinFillRect( ps, &rcl, c1 ); GpiSetColor( ps, c2 ); #ifdef _MBCS GpiCharStringAt( ps, &ptl, _mbsnbcnt(buff,w->width), buff ); #else GpiCharStringAt( ps, &ptl, w->width, buff ); #endif WinReleasePS( ps ); } #else { HDC dc; // SIZE size; // RECT rect; dc = GetDC( hwnd ); _SetMyDC( dc, _ColorMap[c2], _ColorMap[c1] ); // #ifdef __NT__ // GetTextExtentPoint32( dc, buff, strlen(buff), &size ); // #else // GetTextExtentPoint( dc, buff, strlen(buff), &size ); // #endif // #ifdef _MBCS TextOut( dc, 0, line * w->ychar, (LPSTR)buff, FAR_mbsnbcnt( (LPBYTE)buff, w->width ) ); #else TextOut( dc, 0, line * w->ychar, buff, w->width ); #endif /*** Clear to end of line to remove any residue ***/ // GetClientRect( w->hwnd, &rect ); // rect.top = line * w->ychar; // rect.bottom = (line+1) * w->ychar ; // rect.left = size.cx; // FillRect( dc, &rect, w->brush ); ReleaseDC( hwnd, dc ); } #endif /*** Update the w->image array ***/ #ifdef _MBCS { mb_char mbc; unsigned char *curMbc; int count; i = line * w->width + startcol; for( count = 0, curMbc = (unsigned char *)buff; count < w->width - startcol; count++ ) { mbc = _mbsnextc( curMbc ); /* get the character */ curMbc = _mbsinc( curMbc ); /* point to next char */ w->image[i + count] = mbc; /* store it in w->image */ } } #else i = line * w->width + startcol; FARmemcpy( &w->image[i], buff, w->width - startcol ); #endif } /* _DisplayLineInWindowWithColor */
MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { static CHAR szErrorMsg [] = "File not found or could not be opened" ; static INT cxClient, cyClient, cxChar, cyChar, cyDesc ; CHAR *pcReadBuffer ; FILE *fileInput ; FONTMETRICS fm ; HPS hps ; INT iLength ; POINTL ptl ; switch (msg) { case WM_CREATE: hps = WinGetPS (hwnd) ; EzfQueryFonts (hps) ; if (!EzfCreateLogFont (hps, LCID_FIXEDFONT, FONTFACE_MONO, FONTSIZE_10, 0)) { WinReleasePS (hps) ; WinMessageBox (HWND_DESKTOP, HWND_DESKTOP, "Cannot find a fixed-pitch font. Load the Courier " "fonts from the Control Panel and try again.", szClientClass, 0, MB_OK | MB_WARNING) ; return MRFROMSHORT (1) ; } GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm) ; cxChar = fm.lAveCharWidth ; cyChar = fm.lMaxBaselineExt ; cyDesc = fm.lMaxDescender ; GpiSetCharSet (hps, LCID_DEFAULT) ; GpiDeleteSetId (hps, LCID_FIXEDFONT) ; WinReleasePS (hps) ; return 0 ; case WM_SIZE: cxClient = SHORT1FROMMP (mp2) ; cyClient = SHORT2FROMMP (mp2) ; return 0 ; case WM_COMMAND: switch (COMMANDMSG(&msg)->cmd) { case IDM_OPEN: if (WinDlgBox (HWND_DESKTOP, hwnd, OpenDlgProc, NULLHANDLE, IDD_OPEN, NULL)) WinInvalidateRect (hwnd, NULL, FALSE) ; return 0 ; case IDM_ABOUT: WinDlgBox (HWND_DESKTOP, hwnd, AboutDlgProc, NULLHANDLE, IDD_ABOUT, NULL) ; return 0 ; } break ; case WM_PAINT: hps = WinBeginPaint (hwnd, NULLHANDLE, NULL) ; GpiErase (hps) ; if (szFileName [0] != '\0') { EzfCreateLogFont (hps, LCID_FIXEDFONT, FONTFACE_MONO, FONTSIZE_10, 0) ; EzfCreateLogFont (hps, LCID_BOLDFONT, FONTFACE_MONO, FONTSIZE_10, FATTR_SEL_BOLD) ; GpiSetCharSet (hps, LCID_BOLDFONT) ; ptl.x = cxChar ; ptl.y = cyClient - cyChar + cyDesc ; GpiCharStringAt (hps, &ptl, strlen (szFileName), szFileName) ; ptl.y -= cyChar ; if ((fileInput = fopen (szFileName, "r")) != NULL) { GpiSetCharSet (hps, LCID_FIXEDFONT) ; pcReadBuffer = (PCHAR) malloc (cxClient / cxChar) ; while ((ptl.y -= cyChar) > 0 && fgets (pcReadBuffer, cxClient / cxChar - 2, fileInput) != NULL) { iLength = strlen (pcReadBuffer) ; if (pcReadBuffer [iLength - 1] == '\n') iLength-- ; if (iLength > 0) GpiCharStringAt (hps, &ptl, iLength, pcReadBuffer) ; } free (pcReadBuffer) ; fclose (fileInput) ; } else // file cannot be opened { ptl.y -= cyChar ; GpiCharStringAt (hps, &ptl, strlen (szErrorMsg), szErrorMsg) ; } GpiSetCharSet (hps, LCID_DEFAULT) ; GpiDeleteSetId (hps, LCID_FIXEDFONT) ; GpiDeleteSetId (hps, LCID_BOLDFONT) ; } WinEndPaint (hps) ; return 0 ; } return WinDefWindowProc (hwnd, msg, mp1, mp2) ; }