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); }
MRESULT mainwmPaint(HWND hwnd,MPARAM mp1,MPARAM mp2) { HPS hps; RECTL rectlEntire,rectlUpdate; char str[203]; hps=WinBeginPaint(hwnd, NULLHANDLE, &rectlUpdate); #ifdef DEBUG assert(hps!=NULLHANDLE); #endif if (hps==NULLHANDLE) return 0; WinQueryWindowRect(hwnd,&rectlEntire); GpiSetBackMix(hps,BM_OVERPAINT); WinQueryWindowText(hwndHEF1,201,str); // printf("%d\n",strlen(str)); strcat(str," "); HanOut(hps,0,100,str); WinQueryWindowText(hwndHEF2,201,str); strcat(str," "); HanOut(hps,0,80,str); WinEndPaint(hps); return 0L; }
/************************************************************************** * * Name : InitClientArea() * * Description: Prepares the client area to accept the images * * Concepts : Called once by the Init() routine * - obtain a window device context * - define the image presentation space * - associate the two * - set foreground/background colours & * background mix for the presentation space * * API's : WinOpenWindowDC * GpiCreatePS * GpiSetColor * GpiSetBackColor * GpiSetBackMix * * Parameters : hwnd = client window handle * * Return : TRUE - client area successfully set up * FALSE - client area setup failed * *************************************************************************/ BOOL InitClientArea(HWND hwnd) { SIZEL sizl; sizl.cx = 0L; /* set size to default for device */ sizl.cy = 0L; /* (full screen) */ vhdc = WinOpenWindowDC(hwnd); if (!vhdc) return FALSE; vhps = GpiCreatePS(vhab, vhdc, &sizl, (ULONG)PU_PELS | GPIT_NORMAL | GPIA_ASSOC ); if (!vhps) return FALSE; GpiSetColor(vhps, vlForeClr); GpiSetBackColor(vhps, vlBackClr); GpiSetBackMix(vhps, BM_OVERPAINT); return TRUE; } /* End of InitClientArea */
void Paint(void) { HPS hps; RECTL rcl; hps = WinBeginPaint(hwndClient,(HPS)0,(PRECTL)&rcl); GpiSetColor(hps,CLR_WHITE); GpiSetBackColor(hps,CLR_BLUE); GpiSetBackMix(hps,BM_OVERPAINT); WinFillRect(hps,&rcl,CLR_WHITE); WinEndPaint(hps); }
/* * finiPRES - finished with our presentation space */ static void finiPRES( WPI_PRES pres ) { _wpi_getoldbrush( pres, oldBrush ); _wpi_getoldfont( pres, oldFont ); _wpi_setbackcolour( pres, oldBkColor ); #ifdef __OS2_PM__ GpiSetBackMix( pres, BM_LEAVEALONE ); #else SetTextColor( pres, oldTextColor ); #endif } /* finiPRES */
void ClearScreen(void) { HPS hps; RECTL rcl; WinInvalidateRect(hwndClient,(PRECTL)NULL,FALSE); hps = WinBeginPaint(hwndClient,(HPS)0,(PRECTL)&rcl); GpiSetColor(hps,CLR_WHITE); GpiSetBackColor(hps,CLR_BLUE); GpiSetBackMix(hps,BM_OVERPAINT); WinFillRect(hps,&rcl,CLR_WHITE); WinEndPaint(hps); }
/**************************************************************** DefaultOutlineFont: Set an outline font which is sizeable. ****************************************************************/ void SetOutlineFont(HPS hps, short height) {FONTMETRICS fm[80]; static FATTRS fat; static LONG cFonts=0; LONG ltemp=0; SIZEF size; int i; if (height<=2) return; if (cFonts==0) { GpiLoadFonts(WinQueryAnchorBlock(HWND_DESKTOP),"helv"); cFonts= GpiQueryFonts(hps,QF_PUBLIC|QF_PRIVATE,"Helv",<emp, sizeof(FONTMETRICS),(PFONTMETRICS)0); if (cFonts>sizeof(fm)/sizeof(FONTMETRICS)) cFonts=sizeof(fm)/sizeof(FONTMETRICS); GpiQueryFonts(hps,QF_PUBLIC|QF_PRIVATE,"Helv",&cFonts, sizeof(FONTMETRICS),fm); for (i=0; (!(fm[i].fsDefn&FM_DEFN_OUTLINE)) && //find outline and (!(fm[i].fsType&FM_TYPE_KERNING)) && //kerned if can (i<cFonts); i++); if (i==cFonts) for (i=0; (!(fm[i].fsDefn&FM_DEFN_OUTLINE))&& // Find outline atleast (i<cFonts); i++); if (i==cFonts) i=0; fat.usRecordLength =sizeof(FATTRS); fat.lMatch =fm[i].lMatch; fat.lMatch =0; fat.fsFontUse = FATTR_FONTUSE_OUTLINE; strcpy(fat.szFacename,fm[i].szFacename); } GpiCreateLogFont(hps,(PSTR8)0,1,&fat); GpiSetBackMix(hps,(LONG)BM_LEAVEALONE); GpiSetCharSet(hps,1); size.cx = MAKEFIXED(height,0); size.cy = MAKEFIXED(height,0); GpiSetCharBox(hps,&size); GpiSetTextAlignment(hps,TA_NORMAL_HORIZ,TA_BOTTOM); }
/* * initPRES - initialize our presentation space for drawing text */ static bool initPRES( statwnd *sw, WPI_PRES pres ) { if( sw->sectionDataFont == NULL ) { return( false ); } #ifdef __NT__ oldFont = _wpi_selectfont( pres, systemDataFont ); #else oldFont = _wpi_selectfont( pres, sw->sectionDataFont ); #endif oldBrush = _wpi_selectbrush( pres, brushButtonFace ); oldBkColor = _wpi_getbackcolour( pres ); _wpi_setbackcolour( pres, colorButtonFace ); #ifdef __OS2_PM__ GpiSetBackMix( pres, BM_OVERPAINT ); #else oldTextColor = GetTextColor( pres ); SetTextColor( pres, colorTextFace ); #endif return( true ); } /* initPRES */
/********************* 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; }
/************************************************************************** * * 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 PMfrWriteClipbrdBmp(HAB hab) { HDC hdcClip; /* memory DC and PS to extract from the clipboard */ HPS hpsClip; HBITMAP hbmClip; SIZEL sizl; BITMAPINFOHEADER bmp; ULONG _far *alRGBColors; LONG errorcode; char _far *fp1; char _far *fp2; int i; if (WinOpenClipbrd(hab)) { /* get the memory DC and PS to copy the bitmap */ hdcClip = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULL) ; sizl.cx = cp.cx; sizl.cy = cp.cy; hpsClip = GpiCreatePS (hab, hdcClip, &sizl, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC); bmp.cbFix = sizeof bmp; bmp.cx = cp.cx; bmp.cy = cp.cy; bmp.cPlanes = cp.cPlanes; bmp.cBitCount = cp.cBitCount; hbmClip = GpiCreateBitmap (hpsClip, &bmp, 0L, NULL, NULL); GpiSetBitmap(hpsClip, hbmClip); /* initialize and black out the bitmap */ alRGBColors = (ULONG _far *) _fmalloc(sizeof(ULONG) * cp.colors); /* beginning of source array */ fp2 = (char _far *) &cp.pbmiMemory->argbColor[0]; /* beginning of dest array */ fp1 = (char _far *) &alRGBColors[0]; for (i = 0; i < cp.colors; i++) { /* copy base bytes for number of screen colors */ alRGBColors[i] = 0; _fmemcpy(fp1, fp2, sizeof(RGB) ); fp1 += sizeof(ULONG); fp2 += sizeof(RGB); } GpiSetMix ( hpsClip, FM_OVERPAINT) ; GpiSetBackMix (hpsClip, BM_LEAVEALONE) ; GpiCreateLogColorTable(hpsClip, LCOL_RESET | LCOL_REALIZABLE, LCOLF_CONSECRGB, 0L, cp.colors, alRGBColors); /* now copy the bits */ cp.pbmiMemory->cx = cp.cx; cp.pbmiMemory->cy = cp.cy; cp.pbmiMemory->cPlanes = cp.cPlanes; cp.pbmiMemory->cBitCount = cp.cBitCount; errorcode = GpiSetBitmapBits(hpsClip, 0L, (LONG) cp.cy, cp.pixels, cp.pbmiMemory); /* unlink the new bitmap */ GpiSetBitmap(hpsClip, (HBITMAP) NULL); /* write to the clipboard */ WinEmptyClipbrd (hab); WinSetClipbrdData (hab, (ULONG) hbmClip, CF_BITMAP, CFI_HANDLE); /* now clean up */ _ffree(alRGBColors); GpiDestroyPS(hpsClip); DevCloseDC(hdcClip); WinCloseClipbrd(hab); } }
static grPMSurface* init_surface( grPMSurface* surface, grBitmap* bitmap ) { PBITMAPINFO2 bit; SIZEL sizl = { 0, 0 }; LONG palette[256]; LOG(( "Os2PM: init_surface( %08lx, %08lx )\n", (long)surface, (long)bitmap )); LOG(( " -- input bitmap =\n" )); LOG(( " -- mode = %d\n", bitmap->mode )); LOG(( " -- grays = %d\n", bitmap->grays )); LOG(( " -- width = %d\n", bitmap->width )); LOG(( " -- height = %d\n", bitmap->rows )); /* create the bitmap - under OS/2, we support all modes as PM */ /* handles all conversions automatically.. */ if ( grNewBitmap( bitmap->mode, bitmap->grays, bitmap->width, bitmap->rows, bitmap ) ) return 0; LOG(( " -- output bitmap =\n" )); LOG(( " -- mode = %d\n", bitmap->mode )); LOG(( " -- grays = %d\n", bitmap->grays )); LOG(( " -- width = %d\n", bitmap->width )); LOG(( " -- height = %d\n", bitmap->rows )); bitmap->pitch = -bitmap->pitch; surface->root.bitmap = *bitmap; /* create the image and event lock */ DosCreateEventSem( NULL, &surface->event_lock, 0, TRUE ); DosCreateMutexSem( NULL, &surface->image_lock, 0, FALSE ); /* create the image's presentation space */ surface->image_dc = DevOpenDC( gr_anchor, OD_MEMORY, (PSZ)"*", 0L, 0L, 0L ); surface->image_ps = GpiCreatePS( gr_anchor, surface->image_dc, &sizl, PU_PELS | GPIT_MICRO | GPIA_ASSOC | GPIF_DEFAULT ); GpiSetBackMix( surface->image_ps, BM_OVERPAINT ); /* create the image's PM bitmap */ bit = (PBITMAPINFO2)grAlloc( sizeof(BITMAPINFO2) + 256*sizeof(RGB2) ); surface->bitmap_header = bit; bit->cbFix = sizeof( BITMAPINFOHEADER2 ); bit->cx = surface->root.bitmap.width; bit->cy = surface->root.bitmap.rows; bit->cPlanes = 1; bit->argbColor[0].bBlue = 255; bit->argbColor[0].bGreen = 0; bit->argbColor[0].bRed = 0; bit->argbColor[1].bBlue = 0; bit->argbColor[1].bGreen = 255; bit->argbColor[1].bRed = 0; bit->cBitCount = (bitmap->mode == gr_pixel_mode_gray ? 8 : 1 ); if (bitmap->mode == gr_pixel_mode_gray) { RGB2* color = bit->argbColor; int x, count; count = bitmap->grays; for ( x = 0; x < count; x++, color++ ) { color->bBlue = color->bGreen = color->bRed = (((count-x)*255)/count); } } else { RGB2* color = bit->argbColor; color[0].bBlue = color[0].bGreen = color[0].bRed = 0; color[1].bBlue = color[1].bGreen = color[1].bRed = 255; } surface->os2_bitmap = GpiCreateBitmap( surface->image_ps, (PBITMAPINFOHEADER2)bit, 0L, NULL, NULL ); GpiSetBitmap( surface->image_ps, surface->os2_bitmap ); bit->cbFix = sizeof( BITMAPINFOHEADER2 ); GpiQueryBitmapInfoHeader( surface->os2_bitmap, (PBITMAPINFOHEADER2)bit ); surface->bitmap_header = bit; /* for gr_pixel_mode_gray, create a gray-levels logical palette */ if ( bitmap->mode == gr_pixel_mode_gray ) { int x, count; count = bitmap->grays; for ( x = 0; x < count; x++ ) palette[x] = (((count-x)*255)/count) * 0x010101; /* create logical color table */ GpiCreateLogColorTable( surface->image_ps, (ULONG) LCOL_PURECOLOR, (LONG) LCOLF_CONSECRGB, (LONG) 0L, (LONG) count, (PLONG) palette ); /* now, copy the color indexes to surface->shades */ for ( x = 0; x < count; x++ ) surface->shades[x] = GpiQueryColorIndex( surface->image_ps, 0, palette[x] ); } /* set up the blit points array */ surface->blit_points[1].x = surface->root.bitmap.width; surface->blit_points[1].y = surface->root.bitmap.rows; surface->blit_points[3] = surface->blit_points[1]; /* Finally, create the event handling thread for the surface's window */ DosCreateThread( &surface->message_thread, (PFNTHREAD) RunPMWindow, (ULONG) surface, 0UL, 32920 ); /* wait for the window creation */ LOCK(surface->image_lock); UNLOCK(surface->image_lock); surface->root.done = (grDoneSurfaceFunc) done_surface; surface->root.refresh_rect = (grRefreshRectFunc) refresh_rectangle; surface->root.set_title = (grSetTitleFunc) set_title; surface->root.listen_event = (grListenEventFunc) listen_event; /* convert_rectangle( surface, 0, 0, bitmap->width, bitmap->rows ); */ return surface; }
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 ); }
/************************************************************************** * * 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 */
MRESULT EXPENTRY XLogoWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { HPS hps; HWND hwndMenu; /* Menu resource */ RECTL rcl; /* For finding current window dimensions */ BOOL fSuccess; switch(msg) { 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 */ LONG Lx, Ly; /* Starting points for paths A and B */ POINTL PathAStart, PathBStart; POINTL PathAPolygon[5], PathBPolygon[5]; /* Paths A, B definitions */ /* Create a presentation space */ hps = WinBeginPaint( hwnd, 0L, &rc ); GpiSetColor(hps, CLR_BLACK); /* colour of the text, */ GpiSetBackColor(hps, CLR_BACKGROUND); /* its background and */ GpiSetBackMix(hps, BM_OVERPAINT); /* how it mixes, */ /* and draw the string...*/ WinFillRect( hps, &rc, SYSCLR_WINDOW); WinQueryWindowRect(hwnd, &rcl); Lx = rcl.xRight - rcl.xLeft; /* Calculate window dimensions! */ Ly = rcl.yTop - rcl.yBottom; /* Find starting points of the two paths which make up the X */ PathAStart.x = 0.061 * Lx; PathAStart.y = Ly; PathBStart.x = 0.864 * Lx; PathBStart.y = Ly; /* Find the points for path A, the left half of the X */ PathAPolygon[0].x = 0.404 * Lx; PathAPolygon[0].y = 0.483 * Ly; PathAPolygon[1].x = 0.06 * Lx; PathAPolygon[1].y = 0; PathAPolygon[2].x = 0.141 * Lx; PathAPolygon[2].y = 0; PathAPolygon[3].x = 0.556 * Lx; PathAPolygon[3].y = 0.589 * Ly; PathAPolygon[4].x = 0.288 * Lx; PathAPolygon[4].y = Ly; /* Find the points for path B, the right half of the X */ PathBPolygon[0].x = 0.455 * Lx; PathBPolygon[0].y = 0.417 * Ly; PathBPolygon[1].x = 0.722 * Lx; PathBPolygon[1].y = 0; PathBPolygon[2].x = 0.939 * Lx; PathBPolygon[2].y = 0; PathBPolygon[3].x = 0.6 * Lx; PathBPolygon[3].y = 0.517 * Ly; PathBPolygon[4].x = 0.939 * Lx; PathBPolygon[4].y = Ly; /* Define and draw path A */ GpiBeginPath(hps, 1L); GpiMove(hps, &PathAStart); GpiPolyLine(hps, 5L, PathAPolygon); GpiCloseFigure(hps); GpiEndPath(hps); GpiFillPath(hps, 1L, FPATH_ALTERNATE); /* Define and draw path B. Path number must be 1L */ GpiBeginPath(hps, 1L); GpiMove(hps, &PathBStart); GpiPolyLine(hps, 5L, PathBPolygon); GpiCloseFigure(hps); GpiEndPath(hps); GpiFillPath(hps, 1L, FPATH_ALTERNATE); WinEndPaint(hps); break; } case WM_BUTTON2DOWN: { /* Opens the popup menu at current mouse co-ordinates */ hwndMenu = WinLoadMenu(hwnd, (HMODULE)NULL, ID_X); fSuccess = WinPopupMenu(hwnd, hwndFrame, hwndMenu, MOUSEMSG(&msg)->x, MOUSEMSG(&msg)->y, IDM_EXIT, PU_POSITIONONITEM | PU_HCONSTRAIN | PU_VCONSTRAIN | PU_MOUSEBUTTON2DOWN | PU_MOUSEBUTTON2); break; } case WM_CLOSE: /* * This is the place to put your termination routines */ WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 ); break; case WM_COMMAND: switch (SHORT1FROMMP (mp1)) { case IDM_ABOUT: /* Show Product information dialog box */ WinDlgBox(HWND_DESKTOP, hwnd, AboutDlgProc, 0, IDD_ABOUT, 0); return ((MRESULT)0); case IDM_EXIT: WinSendMsg (hwnd, WM_CLOSE, 0L, 0L); return ((MRESULT)0); } 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 XLogoWndProc */