VOID ClkPaint (HWND hwnd) { RECTL rclUpdate; HPS hpsWnd; if (cp.usDispMode & DM_ANALOG) { WinBeginPaint (hwnd, hps, &rclUpdate); GpiCreateLogColorTable (hps, 0L, LCOLF_RGB, 0L, 0L, (PLONG)NULL); WinFillRect (hps, &rclUpdate, cp.clrBackground); if (fBufferDirty) { DrawClock (hpsBuffer); fBufferDirty = FALSE; } UpdateScreen (hps, &rclUpdate); /* * Draw the second hand last, so xor will work. */ if (fShowSecondHand && (cp.usDispMode & DM_SECONDHAND)) ClkDrawHand(hps, HT_SECOND, dt.seconds); WinEndPaint (hps); } else { /*For now, if it is not Analog, it must be digital*/ hpsWnd = WinBeginPaint (hwnd, NULLHANDLE, &rclUpdate); GpiCreateLogColorTable(hpsWnd, 0L, LCOLF_RGB, 0L, 0L, (PLONG) NULL); WinFillRect (hpsWnd, &rclUpdate, cp.clrBackground); memset (achOldTime, 0, sizeof(achOldTime)); memset (achOldAmPm, '0', sizeof(achOldAmPm)); memset (achOldDate, '0', sizeof(achOldDate)); DrawDigitalTime (hwnd); WinEndPaint (hpsWnd); } }
QT_BEGIN_NAMESPACE HPS qt_alloc_mem_ps(int w, int h, HPS compat = 0) { HDC hdcCompat = NULLHANDLE; if (compat) hdcCompat = GpiQueryDevice(compat); static PCSZ hdcData[4] = { "Display", NULL, NULL, NULL }; HDC hdc = DevOpenDC(0, OD_MEMORY, "*", 4, (PDEVOPENDATA) hdcData, hdcCompat); if (!hdc) { qWarning( "alloc_mem_dc: DevOpenDC failed with %08lX!", WinGetLastError(0)); return NULLHANDLE; } SIZEL size = { w, h }; HPS hps = GpiCreatePS(0, hdc, &size, PU_PELS | GPIA_ASSOC | GPIT_MICRO); if (hps == NULLHANDLE) { qWarning("alloc_mem_dc: GpiCreatePS failed wit %08lX!", WinGetLastError(0)); return NULLHANDLE; } // @todo later // if (QColor::hPal()) { // GpiSelectPalette(hps, QColor::hPal()); // } else { // direct RGB mode GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, NULL); // } return hps; }
static HPS hpsDrawText(HPS hPS, PTEXTFIELD ptf) { FONTMETRICS fm3D; /* Font Metrics Holder */ RECTL rcl; /* Rectangle Holder */ register LONG i, k, n; /* String Length Counter */ /* Get the presentation space for the control */ /* and set the colour table to RGB mode */ GpiCreateLogColorTable(hPS, 0L, LCOLF_RGB, 0L, 0L, (PLONG)NULL); /* Check to see if any text present and if the */ /* case, draw it within the rectangle */ if ( ptf->cText ) /* Check to see if the text is to be broken over */ /* more than one line if the length of the text */ /* is greater than the width of the control */ if ( ptf->flStyle & DT_WORDBREAK ) { /* Word break style specified, set the drawing */ /* of the text within a loop such that it can */ /* be drawn on successive lines */ n = ptf->cText; GpiQueryFontMetrics(hPS, sizeof(FONTMETRICS), &fm3D); rcl = ptf->rcl; i = 0; do { n -= (k = WinDrawText(hPS, n, &ptf->pszText[i], &rcl, ptf->lClrText, ptf->lClrBackground, ptf->flFormat)); i += k; if ( (rcl.yTop -= fm3D.lMaxBaselineExt) < rcl.yBottom ) break; } while ( n > 0 ); } else WinDrawText(hPS, ptf->cText, ptf->pszText, &ptf->rcl, ptf->lClrText, ptf->lClrBackground, ptf->flFormat); else WinFillRect(hPS, &ptf->rcl, ptf->lClrBackground); GpiSetColor(hPS, ptf->lClrLeftTop); GpiMove(hPS, &ptf->aptl[3]); GpiPolyLine(hPS, 2L, ptf->aptl); GpiSetColor(hPS, ptf->lClrBottomRight); GpiPolyLine(hPS, 2L, &ptf->aptl[2]); return(hPS); }
/*DOC CLASS XPalette FUNCTION Disable GROUP x-games/constructors/destructor REMARKS Disable this palette. */ void XPalette::Disable( BOOL flInvalidate ) { GpiCreateLogColorTable( hpsDesktop, LCOL_PURECOLOR | LCOL_REALIZABLE, LCOLF_CONSECRGB, 0, 256, (PLONG)aulWPSPalette ); if( !GreRealizeColorTable( hdcDesktop ) ) throw XGameException( "XPalette: unable to set physical palette", XGameException::XGERR_PALETTE ); if( flInvalidate ) WinInvalidateRect( HWND_DESKTOP, (PRECTL)NULL, TRUE ); } // XPalette::Disable
MRESULT clbPaint(PCLBOX pclb) { HPS hps; if (pclb && NULLHANDLE != (hps = WinBeginPaint(pclb->hwnd, NULLHANDLE, NULL))) { if (!(pclb->fl & (CLBXS_CHECK | CLBXS_NOCAPT))) { ULONG fl = DT_VCENTER | DT_ERASERECT | DT_MNEMONIC; GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, NULL); WinDrawText(hps, -1, pclb->psz, &pclb->rclcpt, pclb->lfgnd, pclb->lbkgnd, (pclb->is.enbl? fl: fl | DT_HALFTONE)); } /* endif */ WinEndPaint(hps); } /* endif */ return (MRESULT)FALSE; }
SOM_Scope void SOMLINK ShapePartDrawFrame(ShapePart *somSelf, Environment *ev, ODFacet* facet, ODShape* invalidShape) { ShapePartData *somThis = ShapePartGetData(somSelf); ShapePartMethodDebug("ShapePart","ShapePartDrawFrame"); ODFrame* displayFrame = facet->GetFrame(ev); TempODShape shape = displayFrame->AcquireFrameShape(ev, facet->GetCanvas(ev)); ODRect rect; shape->GetBoundingBox(ev, &rect); #if defined(_PLATFORM_WIN32_) Rect frameRect; SetRect(&frameRect, FixedToInt(rect.left), FixedToInt(rect.top), FixedToInt(rect.right), FixedToInt(rect.bottom)); HDC hdc; CFocus focus(facet, invalidShape, &hdc); HBRUSH hbr = CreateSolidBrush (_fBackgroundColor); FillRect (hdc, &frameRect, hbr); DeleteObject (hbr); #elif defined (_PLATFORM_OS2_) RECTL frameRect; frameRect.xLeft = FixedToInt(rect.left); frameRect.yTop = FixedToInt(rect.top); frameRect.xRight = FixedToInt(rect.right); frameRect.yBottom = FixedToInt(rect.bottom); HPS hdc; CFocus focus(facet, invalidShape, &hdc); GpiCreateLogColorTable (hdc, 0L, LCOLF_RGB, 0L, 0L, 0L); GpiSetColor(hdc, _fBackgroundColor); POINTL orig = {0, 0}; GpiMove(hdc, &orig); POINTL ptl = {frameRect.xRight, frameRect.yTop}; GpiBox(hdc, DRO_FILL, &ptl, 0, 0); #endif }
/*@ XToolBar::Draw(void) @group display @remarks Redraw the toolbar. */ void XToolBar::Draw(void) { RECTL rect; WinQueryWindowRect(winhandle, &rect); HPS hps = WinGetPS(winhandle); GpiCreateLogColorTable(hps, LCOL_RESET, LCOLF_RGB, 0,0,NULL); WinFillRect( hps, &rect, SYSCLR_BUTTONMIDDLE); WinDrawBorder(hps, &rect, 1,1,0,0,DB_PATCOPY|DB_RAISED); HENUM e; HWND hwnd; e = WinBeginEnumWindows(winhandle); while ((hwnd = WinGetNextWindow(e)) != 0) WinInvalidateRegion(hwnd, NULLHANDLE, TRUE); WinEndEnumWindows(e); }
/*------------------------------------------------------------------------*/ MRESULT EXPENTRY SplashWndProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2) { static HBITMAP hbm; static SWP swp; HPS hps; RECTL rcl; switch(msg) { case WM_CREATE: hps = WinGetPS (hwnd); hbm = GpiLoadBitmap(hps, (HMODULE)0L, IDB_LOGO, (ULONG)0, (ULONG)0); WinReleasePS (hps); WinQueryWindowPos(hwnd, (PSWP)&swp); return (MRESULT)0; case WM_PAINT: hps = WinBeginPaint (hwnd, NULLHANDLE, /* Get a cached PS */ (RECTL *)0); GpiErase (hps); GpiCreateLogColorTable (hps, LCOL_RESET, LCOLF_RGB, 0L, 0L, NULL) ; rcl.xLeft = 0; rcl.yBottom = 0; rcl.xRight = swp.cx; rcl.yTop = swp.cy; if ( hbm ) WinDrawBitmap(hps,hbm, NULL, (PPOINTL) &rcl, CLR_NEUTRAL, CLR_BACKGROUND, DBM_STRETCH ); WinDrawBorder(hps, &rcl,2L,2L,0L, 0L, DB_DEPRESSED); WinEndPaint(hps); return (MRESULT)0; } return( WinDefWindowProc(hwnd, msg, mp1, mp2) ); }
// disegna il controllo groupbox MRESULT PaintGroupBox(HWND hwnd) { PCTL pgb = stGetData(hwnd); if (pgb) { RECTL rcl = {0, 0, pgb->wr.cx, pgb->wr.cy}; HPS hps = WinBeginPaint(hwnd, NULLHANDLE, NULL); ULONG brd = pgb->fl & 0x7; ULONG frm = brd; GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, NULL); // disegna bordo groupbox WinDrawBorder(hps, &rcl, brd, brd, 0, 0, (pgb->fl & CCTL_RAISED? 0x400: 0x800)); // se necessario disegnare anche frame if (pgb->fl & CCTL_FRAME6) { frm = brd * ((pgb->fl & 0x38) >> 3); rcl.xLeft = frm; rcl.yBottom = frm; rcl.xRight -= frm; rcl.yTop -= frm; WinDrawBorder(hps, &rcl, brd, brd, 0, 0, (pgb->fl & CCTL_RAISED? 0x800: 0x400)); } /* endif */ // se il testo Š presente if (pgb->psz) { // cancella background rcl.xLeft = frm; rcl.yBottom = pgb->wr.cy - pgb->cyFont - 2 * frm - 2; rcl.xRight = pgb->wrtxt.cx + 2 * frm + 3; rcl.yTop = pgb->wr.cy - frm; WinFillRect(hps, &rcl, pgb->lbkgnd); // disegna testo rcl.yBottom += 2; WinDrawText(hps, -1, pgb->psz, &rcl, pgb->lfgnd, pgb->lbkgnd, DT_CENTER | DT_TOP | DT_MNEMONIC | DT_EXTERNALLEADING | ((pgb->fl & WS_DISABLED)? DT_HALFTONE: 0)); // disegna bordo inferiore e a destra del testo rcl.yBottom -= 2; GpiSetColor(hps, (pgb->fl & CCTL_RAISED? pgb->lshadow: pgb->lhilite)); GpiMove(hps, (PPOINTL)&rcl); rcl.xLeft = rcl.xRight; rcl.yTop -= 1; GpiPolyLine(hps, 2, (PPOINTL)&rcl); } /* endif */ WinEndPaint(hps); } /* endif */
/****************************************************************\ * *-------------------------------------------------------------- * Name:ClkCreate() * * Purpose:Intialize a newly created client window * * Returns: * 1 - if sucessful execution completed * 0 - if error \****************************************************************/ VOID ClkCreate ( HWND hwnd ) { LONG cxScreen , cyScreen; /* screen dimensions */ LONG xLeft , yBottom ; /* frame window location */ ULONG cbBuf; LONG cyHeight; LONG cxWidth; // hwndClient = hwnd; // extern SIZEL sizl; clkdata.h // SIZEL sizl = { 200 , 200 }; clkdata.c /* determine screen dimensions */ /* open a device context and create a presentation space */ hdc = WinOpenWindowDC (hwnd); hps = GpiCreatePS (hab, hdc, &sizl, PU_ARBITRARY | GPIT_MICRO | GPIA_ASSOC); /* * Create our off-screen 'buffer'. */ hdcBuffer = DevOpenDC ( (HAB)0L, OD_MEMORY, "*", 0L, NULL, hdc); hpsBuffer = GpiCreatePS (hab, hdcBuffer, &sizl, PU_ARBITRARY | GPIT_MICRO | GPIA_ASSOC); GpiCreateLogColorTable (hpsBuffer, 0, LCOLF_RGB, 0, 0, (PLONG)NULL); // ULONG cxRes , cyRes; clkdata.c // ULONG cColorPlanes, cColorBitcount; clkdata.c /* get the device resolutions so we can make the face appear circular */ DevQueryCaps (hdc, (LONG)CAPS_VERTICAL_RESOLUTION,(LONG) 1L, &cyRes); DevQueryCaps (hdc, CAPS_HORIZONTAL_RESOLUTION, 1L, &cxRes); DevQueryCaps (hdc, CAPS_COLOR_PLANES, 1L, &cColorPlanes); DevQueryCaps (hdc, CAPS_COLOR_BITCOUNT, 1L, &cColorBitcount); }
static MRESULT EXPENTRY woNewWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) { switch( msg ) { case WM_ERASEBACKGROUND : { HPS hpsFrame = ( HPS )mp1; PRECTL prcl = ( PRECTL )mp2; GpiCreateLogColorTable( hpsFrame, 0, LCOLF_RGB, 0, 0, NULL ); WinFillRect( hpsFrame, prcl, m_hwvs.ulKeyColor); return FALSE; } case WM_SIZE : case WM_MOVE : // WinMapWindowPoints() sometimes does a wrong conversion on WM_MOVE. // For examples, minimizing and restoring a window of Qt4. // So we need to setup on WM_PAINT as well in order to work around // this problem. case WM_PAINT : { RECTL rcl; kvaAdjustDstRect( &m_hwvs.rctlSrcRect, &rcl ); WinMapWindowPoints( hwnd, HWND_DESKTOP, ( PPOINTL )&rcl, 2 ); if( !WinEqualRect( WinQueryAnchorBlock( hwnd ), &rcl, &m_hwvs.rctlDstRect )) { m_hwvs.rctlDstRect = rcl; m_pfnHWVIDEOSetup( &m_hwvs ); } break; // fall through to old window proc } } return m_pfnwpOld( hwnd, msg, mp1, mp2 ); }
void icqskin_loadPallete(HPS hps, int size, const ULONG *clr) { int f; LONG *alTable; if(!size) size = ICQCLR_COUNTER; alTable = malloc(size * sizeof(ULONG)); if(!alTable) return; GpiQueryLogColorTable(hps, 0L, 0L, size, alTable); for(f=0;f<size;f++) { if(clr[f] != 0xFFFFFFFF) alTable[f] = clr[f]; } GpiCreateLogColorTable(hps,0L,LCOLF_CONSECRGB,0L,size,alTable); free(alTable); }
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 void draw_stuff( HWND hwnd ) { HPS win_dc; RECTL paint; RECTL intersect; #ifdef DRAW_ALL_AT_ONCE int old_top; int width, height; SIZEL sizl = { 0, 0 }; BITMAPINFOHEADER2 bmih; LONG formats[24]; POINTL pts[3]; LONG old_cursor; LONG hour_glass_cur; RECTL interior; DEVOPENSTRUC dop = { 0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L }; #endif win_dc = WinBeginPaint( hwnd, 0, &paint ); GpiCreateLogColorTable( win_dc, 0L, LCOLF_RGB, 0L, 0L, NULL ); #ifdef DRAW_ALL_AT_ONCE old_top = paint.yBottom; paint.yBottom = Draw_area.yTop; #endif WinFillRect( win_dc, &paint, SYSCLR_WINDOW ); #ifdef DRAW_ALL_AT_ONCE paint.yBottom = old_top; #endif if( WinIntersectRect( Main_hab, &intersect, &paint, &Draw_area ) ) { #ifdef DRAW_ALL_AT_ONCE width = Draw_area.xRight - Draw_area.xLeft; height = Draw_area.yTop - Draw_area.yBottom; interior.xLeft = 0; interior.yBottom = 0; interior.xRight = width; interior.yTop = height; if( Draw_bitmap == NULLHANDLE ) { Hdc = DevOpenDC( Main_hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE ); Mem_dc = GpiCreatePS( Main_hab, Hdc, &sizl, PU_PELS | GPIA_ASSOC ); memset( &bmih, 0, sizeof( BITMAPINFOHEADER2 ) ); GpiQueryDeviceBitmapFormats( Mem_dc, 24L, formats ); bmih.cbFix = sizeof( BITMAPINFOHEADER2 ); bmih.cx = width; bmih.cy = height; bmih.cPlanes = (USHORT) formats[0]; bmih.cBitCount = (USHORT) formats[1]; Draw_bitmap = GpiCreateBitmap( Mem_dc, &bmih, 0L, NULL, NULL ); Old_bitmap = GpiSetBitmap( Mem_dc, Draw_bitmap ); GpiCreateLogColorTable( Mem_dc, 0, LCOLF_RGB, 0, 0, NULL ); WinFillRect( Mem_dc, &interior, SYSCLR_WINDOW ); hour_glass_cur = WinQuerySysPointer( HWND_DESKTOP, SPTR_WAIT, FALSE ); old_cursor = WinQueryPointer( HWND_DESKTOP ); WinSetPointer( HWND_DESKTOP, hour_glass_cur ); hThree_d = three_d_begin( Mem_dc, &interior ); draw_room(); three_d_draw( hThree_d ); three_d_end( hThree_d ); WinSetPointer( HWND_DESKTOP, old_cursor ); } pts[0].x = Draw_area.xLeft; pts[0].y = Draw_area.yBottom; pts[1].x = Draw_area.xLeft + width; pts[1].y = Draw_area.yBottom + height; pts[2].x = 0; pts[2].y = 0; GpiBitBlt( win_dc, Mem_dc, 3, pts, ROP_SRCCOPY, BBO_IGNORE ); #else hThree_d = three_d_begin( win_dc, &Draw_area ); draw_room(); three_d_draw( hThree_d ); three_d_end( hThree_d ); #endif } WinEndPaint( win_dc ); }
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; }
/* 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; }
bool PaintButton( VRIconButton *somSelf, PUSERBUTTON pbtn ) { FONTMETRICS fm; HAB hab; RECTL rcl, rclTxt, rclImg; POINTL ptl, aptl[ TXTBOX_COUNT ]; LONG lFlags, flPic, flTxt, lStrW, lStrH, lOffset, lClr; ULONG cb; BOOL fPosition; //FILE *f = fopen("c:\\iconbtn.log", "a"); VRIconButtonData *somThis = VRIconButtonGetData(somSelf); lFlags = _vrGetWindowFlags( somSelf ); //fprintf(f, "----[ Entering PaintButton ] ----\n"); if ( !pbtn || ( ! WinQueryWindowRect( pbtn->hwnd, &rcl ))) return FALSE; // Get the current background colour cb = WinQueryPresParam( pbtn->hwnd, PP_BACKGROUNDCOLOR, PP_BACKGROUNDCOLORINDEX, NULL, sizeof( lClr ), &lClr, QPF_ID2COLORINDEX ); if ( cb ) GpiCreateLogColorTable( pbtn->hps, 0, LCOLF_RGB, 0, 0, NULL ); else lClr = GpiQueryRGBColor( pbtn->hps, 0, SYSCLR_BUTTONMIDDLE ); // Fill in the button background WinFillRect( pbtn->hps, &rcl, lClr ); ptl.x = rcl.xLeft; ptl.y = rcl.yBottom; GpiMove( pbtn->hps, &ptl ); ptl.x = rcl.xRight - 1; ptl.y = rcl.yTop - 1; // Draw the "default" state outline if applicable if ( pbtn->fsState & BDS_DEFAULT ) { GpiSetColor( pbtn->hps, SYSCLR_BUTTONDEFAULT ); GpiBox( pbtn->hps, DRO_OUTLINE, &ptl, 0, 0 ); } else { cb = WinQueryPresParam( WinQueryWindow( pbtn->hwnd, QW_PARENT ), PP_BACKGROUNDCOLOR, PP_BACKGROUNDCOLORINDEX, NULL, sizeof( lClr ), &lClr, QPF_ID2COLORINDEX ); if ( cb ) GpiSetColor( pbtn->hps, lClr ); else GpiSetColor( pbtn->hps, SYSCLR_DIALOGBACKGROUND ); GpiBox( pbtn->hps, DRO_OUTLINE, &ptl, 0, 0 ); } if ( !( lFlags & BS_NOBORDER )) { /* Draw the button border (if appropriate) depending on the current * state(s). */ GpiSetColor( pbtn->hps, ( _fDown || ( pbtn->fsState & BDS_HILITED )) ? CLR_BLACK: SYSCLR_BUTTONDARK ); ptl.x = rcl.xLeft + 1; ptl.y = rcl.yBottom + 2; GpiMove( pbtn->hps, &ptl ); ptl.y = rcl.yTop - 2; GpiLine( pbtn->hps, &ptl ); GpiMove( pbtn->hps, &ptl ); ptl.x = rcl.xRight - 2; GpiLine( pbtn->hps, &ptl ); GpiSetColor( pbtn->hps, ( _fDown || ( pbtn->fsState & BDS_HILITED )) ? SYSCLR_BUTTONDARK: CLR_BLACK ); ptl.x = rcl.xLeft + 1; ptl.y = rcl.yBottom + 1; GpiMove( pbtn->hps, &ptl ); ptl.x = rcl.xRight - 2; GpiLine( pbtn->hps, &ptl ); GpiMove( pbtn->hps, &ptl ); ptl.y = rcl.yTop - 3; GpiLine( pbtn->hps, &ptl ); GpiSetColor( pbtn->hps, ( _fDown || ( pbtn->fsState & BDS_HILITED )) ? SYSCLR_BUTTONLIGHT: SYSCLR_BUTTONDARK ); ptl.x = rcl.xLeft + 2; ptl.y = rcl.yBottom + 2; GpiMove( pbtn->hps, &ptl ); ptl.x = rcl.xRight - 3; GpiLine( pbtn->hps, &ptl ); GpiMove( pbtn->hps, &ptl ); ptl.y = rcl.yTop - 3; GpiLine( pbtn->hps, &ptl ); GpiSetColor( pbtn->hps, ( _fDown || ( pbtn->fsState & BDS_HILITED )) ? SYSCLR_BUTTONDARK: SYSCLR_BUTTONLIGHT ); ptl.x = rcl.xLeft + 2; ptl.y = rcl.yBottom + 3; GpiMove( pbtn->hps, &ptl ); ptl.y = rcl.yTop - 3; GpiLine( pbtn->hps, &ptl ); GpiMove( pbtn->hps, &ptl ); ptl.x = rcl.xRight - 3; GpiLine( pbtn->hps, &ptl ); if ( pbtn->fsState & BDS_HILITED ) { GpiSetColor( pbtn->hps, SYSCLR_BUTTONLIGHT ); ptl.x = rcl.xLeft + 3; ptl.y = rcl.yBottom + 3; GpiMove( pbtn->hps, &ptl ); ptl.x = rcl.xRight - 4; GpiLine( pbtn->hps, &ptl ); GpiMove( pbtn->hps, &ptl ); ptl.y = rcl.yTop - 4; GpiLine( pbtn->hps, &ptl ); GpiSetColor( pbtn->hps, SYSCLR_BUTTONDARK ); ptl.x = rcl.xLeft + 3; ptl.y = rcl.yBottom + 4; GpiMove( pbtn->hps, &ptl ); ptl.y = rcl.yTop - 4; GpiLine( pbtn->hps, &ptl ); GpiMove( pbtn->hps, &ptl ); ptl.x = rcl.xRight - 4; GpiLine( pbtn->hps, &ptl ); } } // if ( !( lFlags & BS_NOBORDER )) /* After this point, rcl is used for the clipping boundaries of the entire * button contents exclusive of the border. Separate bounding rectangles * for the image and the text will now be calculated within this area. */ if ( rcl.xRight > 6 ) { rcl.xLeft += 3; rcl.xRight -= 3; } if ( rcl.yTop > 6 ) { rcl.yBottom += 3; rcl.yTop -= 3; } memcpy( &rclTxt, &rcl, sizeof( RECTL )); if ( RECTL_WIDTH( rclTxt ) > 4 ) { rclTxt.xLeft += 2; rclTxt.xRight -= 2; } if ( RECTL_WIDTH( rclTxt ) > 4 ) { rclTxt.yBottom += 2; rclTxt.yTop -= 2; } if ( _pPic && ( _pPic->type & MEMP_BITMAP ) && _fResize ) memcpy( &rclImg, &rcl, sizeof( RECTL )); else { rclImg.xLeft = ( RECTL_WIDTH( rclTxt ) > 6 ) ? rclTxt.xLeft + 3 : rclTxt.xLeft; rclImg.xRight = ( RECTL_WIDTH( rclTxt ) > 6 ) ? rclTxt.xRight - 3 : rclTxt.xRight; rclImg.yBottom = ( RECTL_HEIGHT( rclTxt ) > 6 ) ? rclTxt.yBottom + 3 : rclTxt.yBottom; rclImg.yTop = ( RECTL_HEIGHT( rclTxt ) > 6 ) ? rclTxt.yTop - 3 : rclTxt.yTop; } //fprintf(f, "rcl = {%d %d %d %d}, width = %d, height= %d\n", rcl.xLeft, rcl.yBottom, rcl.xRight, rcl.yTop, RECTL_WIDTH(rcl), RECTL_HEIGHT(rcl) ); //fprintf(f, "rclImg = {%d %d %d %d}, width = %d, height= %d\n", rclImg.xLeft, rclImg.yBottom, rclImg.xRight, rclImg.yTop, RECTL_WIDTH(rclImg), RECTL_HEIGHT(rclImg) ); fPosition = _pPic && ( !_fResize || _pPic->type & MEMP_ICON ) && (( _bAlign == ALIGN_LEFT ) || ( _bAlign == ALIGN_RIGHT )) ? TRUE : FALSE; /* We won't draw the text until after the image... but unless we're scaling * the image into the whole button, we need to calculate how much space the * text is going to require so we can fit the image next to it. (Note that * we behave differently for top/bottom alignment vs left/right alignment - * with top/bottom, the text area is fixed to the height of the string plus * a certain margin. With left/right alignment, the image rectangle is set * to the physical image size, and the text rectangle is offset from that.) */ lStrW = 0; lStrH = 0; GpiQueryFontMetrics( pbtn->hps, sizeof( FONTMETRICS ), &fm ); if ( _pszText && *_pszText ) { // Get the width of the text as it would be rendered in the current font GpiQueryTextBox( pbtn->hps, strlen( _pszText ), _pszText, TXTBOX_COUNT, aptl ); lStrW = aptl[TXTBOX_TOPRIGHT].x - aptl[TXTBOX_TOPLEFT].x; lStrW += ( 2 * fm.lAveCharWidth ); lStrH = fm.lMaxBaselineExt + fm.lInternalLeading + fm.lMaxDescender; // Adjust the bounding rectangles for the text and image switch ( _bAlign ) { case ALIGN_TOP: rclTxt.yBottom = rclTxt.yTop - lStrH; if ( _pPic && ( !_fResize || _pPic->type & MEMP_ICON )) { if (( rclTxt.yBottom - rclImg.yBottom ) > _pPic->height ) rclImg.yTop = rclTxt.yBottom - 1; else if (( rcl.yTop - rclImg.yBottom ) > _pPic->height ) rclImg.yTop = rcl.yBottom + _pPic->height; } break; case ALIGN_BOTTOM: rclTxt.yTop = rclTxt.yBottom + lStrH; if ( _pPic && ( !_fResize || _pPic->type & MEMP_ICON )) { if ((( rclImg.yTop - rclTxt.yTop ) > _pPic->height )) rclImg.yBottom = rclTxt.yTop + 1; else if (( rclImg.yTop - rcl.yBottom ) > _pPic->height ) rclImg.yBottom = (LONG) ( rcl.yTop - _pPic->height ); } break; case ALIGN_LEFT: if ( fPosition ) { if (( rclTxt.xLeft + lStrW + _pPic->width ) < rclImg.xRight ) { rclImg.xLeft = rclImg.xRight - _pPic->width; rclTxt.xRight = rclImg.xLeft - 1; } else { rclTxt.xRight = rclTxt.xLeft + lStrW; if (( rclImg.xRight - _pPic->width ) < RECTL_WIDTH( rcl )) rclImg.xLeft = (LONG) ( rclImg.xRight - _pPic->width ); } } else rclTxt.xRight = rclTxt.xLeft + lStrW; break; case ALIGN_RIGHT: if ( fPosition ) { if (( rclImg.xLeft + _pPic->width + lStrW ) < rclImg.xRight ) { rclImg.xRight = rclImg.xLeft + _pPic->width; rclTxt.xLeft = rclImg.xRight + 1; } else { rclTxt.xLeft = rclTxt.xRight - lStrW; if (( rclImg.xLeft + _pPic->width ) < RECTL_WIDTH( rcl )) rclImg.xRight = rclImg.xLeft + _pPic->width; } } else rclTxt.xLeft = rclTxt.xRight - lStrW; break; default: break; // ALIGN_CENTER, no adjustment needed } if ( rclTxt.yBottom < rcl.yBottom ) rclTxt.yBottom = rcl.yBottom; if ( rclTxt.yTop > rcl.yTop ) rclTxt.yTop = rcl.yTop; if ( rclTxt.xLeft < rcl.xLeft ) rclTxt.xLeft = rcl.xLeft; if ( rclTxt.xRight > rcl.xRight ) rclTxt.xRight = rcl.xRight; } // Draw the image, if one is defined if ( _pPic ) { if (( pbtn->fsState & BDS_HILITED ) && !( _fResize && ( _pPic->type & MEMP_BITMAP ))) { rclImg.xLeft++; rclImg.xRight++; rclImg.yBottom--; rclImg.yTop--; } flPic = PICTDRAW_CENTER_ICON; if ( pbtn->fsState & BDS_DISABLED ) flPic |= PICTDRAW_DISABLE; if ( _pPic->type & MEMP_BITMAP ) { if ( _fResize ) flPic |= PICTDRAW_STRETCH_BITMAP; else { ptl.x = ((LONG)( RECTL_WIDTH( rclImg ) - _pPic->width ) / 2 ); ptl.y = ((LONG)( RECTL_HEIGHT( rclImg ) - _pPic->height ) / 2 ); if ( ptl.x > 0 ) rclImg.xLeft += ptl.x; if ( ptl.y > 0 ) rclImg.yBottom += ptl.y; } } VRPictDisplay( pbtn->hwnd, pbtn->hps, _pPic, &rclImg, flPic ); } // Now draw the text, if any if ( _pszText && *_pszText ) { // Get the current foreground colour if ( pbtn->fsState & BDS_DISABLED ) lClr = GpiQueryRGBColor( pbtn->hps, 0, SYSCLR_MENUDISABLEDTEXT ); else { cb = WinQueryPresParam( pbtn->hwnd, PP_FOREGROUNDCOLOR, PP_FOREGROUNDCOLORINDEX, NULL, sizeof( lClr ), &lClr, QPF_ID2COLORINDEX ); if ( !cb ) lClr = GpiQueryRGBColor( pbtn->hps, 0, SYSCLR_WINDOWTEXT ); } GpiSetColor( pbtn->hps, lClr ); // Now position and draw the button text switch ( _bAlign ) { case ALIGN_TOP: #ifdef GPI_DRAWTEXT ptl.x = rclTxt.xLeft + ( RECTL_WIDTH( rclTxt ) / 2 ); ptl.y = ( RECTL_HEIGHT( rclTxt ) < lStrH ) ? rclTxt.yTop : rclTxt.yTop - ( 2 * fm.lInternalLeading ); GpiSetTextAlignment( pbtn->hps, TA_CENTER, TA_TOP ); #else flTxt = DT_CENTER | (( RECTL_HEIGHT( rclTxt ) < lStrH ) ? DT_TOP : DT_VCENTER ) | DT_TEXTATTRS | DT_MNEMONIC; #endif break; case ALIGN_BOTTOM: #ifdef GPI_DRAWTEXT ptl.x = rclTxt.xLeft + ( RECTL_WIDTH( rclTxt ) / 2 ); ptl.y = ( RECTL_HEIGHT( rclTxt ) < lStrH ) ? rclTxt.yBottom : rclTxt.yBottom + ( 2 * fm.lInternalLeading ); GpiSetTextAlignment( pbtn->hps, TA_CENTER, TA_BOTTOM ); #else flTxt = DT_CENTER | (( RECTL_HEIGHT( rclTxt ) < lStrH ) ? DT_BOTTOM : DT_VCENTER ) | DT_TEXTATTRS | DT_MNEMONIC; #endif break; case ALIGN_LEFT: #ifdef GPI_DRAWTEXT ptl.x = rclTxt.xLeft + fm.lAveCharWidth; ptl.y = rclTxt.yBottom + (( RECTL_HEIGHT( rclTxt ) - fm.lXHeight ) / 2 ); GpiSetTextAlignment( pbtn->hps, TA_NORMAL_HORIZ, TA_BASE ); #else flTxt = DT_LEFT | DT_VCENTER | DT_TEXTATTRS | DT_MNEMONIC; rclTxt.xLeft += fm.lAveCharWidth; #endif break; case ALIGN_RIGHT: #ifdef GPI_DRAWTEXT ptl.x = rclTxt.xLeft + fm.lAveCharWidth; ptl.y = rclTxt.yBottom + (( RECTL_HEIGHT( rclTxt ) - fm.lXHeight ) / 2 ); GpiSetTextAlignment( pbtn->hps, TA_NORMAL_HORIZ, TA_BASE ); #else flTxt = (fPosition? DT_LEFT: DT_RIGHT) | DT_VCENTER | DT_TEXTATTRS | DT_MNEMONIC; if ( RECTL_WIDTH( rclTxt ) > fm.lAveCharWidth ) { if ( fPosition ) rclTxt.xLeft += fm.lAveCharWidth; else rclTxt.xRight -= fm.lAveCharWidth; } #endif break; default: // ALIGN_CENTER #ifdef GPI_DRAWTEXT ptl.x = rclTxt.xLeft + ( RECTL_WIDTH( rclTxt ) / 2 ); ptl.y = rclTxt.yBottom + (( RECTL_HEIGHT( rclTxt ) - fm.lXHeight ) / 2 ); GpiSetTextAlignment( pbtn->hps, TA_CENTER, TA_BASE ); #else flTxt = DT_CENTER | DT_VCENTER | DT_TEXTATTRS | DT_MNEMONIC; #endif break; } if ( pbtn->fsState & BDS_HILITED ) { ptl.x++; ptl.y--; } cb = strlen( _pszText ); #ifdef GPI_DRAWTEXT GpiCharStringPosAt( pbtn->hps, &ptl, &rclTxt, CHS_CLIP, cb, _pszText, NULL ); #else WinDrawText( pbtn->hps, cb, _pszText, &rclTxt, 0, 0, flTxt ); #endif } //fprintf(f, "----[ Leaving PaintButton ] ----\n\n"); //fclose(f); return TRUE; }
/* This Proc handles the on-the-fly data CD writing */ MRESULT EXPENTRY waveinfoStatusDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { char text[CCHMAXPATH*2 +10]; char title[CCHMAXPATH]; SWCNTRL swctl; PID pid; int a; switch (msg) { case WM_PAINT: { HPS hps; RECTL rcl, rclSource; POINTL ptl; LONG lTemp; BOOL bUseCustomPainting=TRUE; LONG lWidthX; LONG lWidthY; LONG lColor; ULONG attrFound; if(bUseCustomPainting) { // if(allBMPs[CTRLIDX_BG].hbm) { if(1) { hps=WinBeginPaint(hwnd, NULLHANDLE, &rcl); rclSource.xLeft=0; rclSource.yBottom=0; #if 0 rclSource.yTop=allBMPs[CTRLIDX_BG].bmpInfoHdr.cy; rclSource.xRight=allBMPs[CTRLIDX_BG].bmpInfoHdr.cx; lTemp=rcl.xLeft/rclSource.xRight; ptl.x=lTemp*rclSource.xRight; lTemp=rcl.yBottom/rclSource.yTop; lTemp*=rclSource.yTop; #endif // rcl.yBottom+=4; rclSource=rcl; rcl.yTop+=4; WinFillRect(hps, &rclSource, CLR_RED); /* Border */ lWidthX=WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER); lWidthY=WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER); GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, NULL); #if 0 if ( (WinQueryPresParam(hwnd, PP_BACKGROUNDCOLOR, 0, &attrFound, sizeof(attrFound), &lColor, QPF_PURERGBCOLOR)) == 0 ) lColor = WinQuerySysColor(HWND_DESKTOP, SYSCLR_DIALOGBACKGROUND, 0); #endif WinQueryWindowRect(hwnd, &rcl); ptl.x=1; ptl.y=0; GpiMove(hps, &ptl); GpiSetColor(hps, CLR_BLACK); ptl.x=rcl.xRight-1; GpiLine(hps,&ptl); ptl.y=rcl.yTop-1; GpiLine(hps,&ptl); GpiSetColor(hps, SYSCLR_SHADOW); ptl.x=rcl.xLeft; GpiLine(hps,&ptl); ptl.y=0; GpiLine(hps,&ptl); rcl.yTop-=1; rcl.yBottom+=1; rcl.xLeft+=1; rcl.xRight-=1; WinDrawBorder( hps,&rcl, 1, 1, 0, 0, 0x400); rcl.yTop-=1; rcl.yBottom+=1; rcl.xLeft+=1; rcl.xRight-=1; /* Get active border color */ if(WinQueryActiveWindow(HWND_DESKTOP)==hwnd) { if ( (WinQueryPresParam(hwnd, PP_BORDERCOLOR, 0, &attrFound, sizeof(attrFound), &lColor, QPF_PURERGBCOLOR)) == 0 ) lColor = WinQuerySysColor(HWND_DESKTOP, SYSCLR_DIALOGBACKGROUND, 0); } else { /* Inactive border color */ if ( (WinQueryPresParam(hwnd, PP_INACTIVECOLOR, 0, &attrFound, sizeof(attrFound), &lColor, QPF_PURERGBCOLOR)) == 0 ) lColor = WinQuerySysColor(HWND_DESKTOP, SYSCLR_DIALOGBACKGROUND, 0); } /* Get Border size */ WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP(&ptl),0); WinDrawBorder(hps,&rcl, ptl.x-2, ptl.y-2, lColor, 0, 0); #if 0 while(ptl.x<rcl.xRight) { ptl.y=lTemp; while(ptl.y<rcl.yTop) {/* y direction */ //DosBeep(5000,100); WinDrawBitmap(hps, allBMPs[CTRLIDX_BG].hbm, &rclSource, (PPOINTL)&ptl, 0, 0, DBM_IMAGEATTRS); ptl.y+=allBMPs[CTRLIDX_BG].bmpInfoHdr.cy; //DosSleep(200); }; ptl.x+=allBMPs[CTRLIDX_BG].bmpInfoHdr.cx; }; #endif WinEndPaint(hps); return (MRESULT)0; } } break; } case WM_DRAWITEM: switch(SHORT1FROMMP(mp1)) { case SLIDERID: return drawSlider(hwnd, msg, mp1, mp2, SHORT1FROMMP(mp1)); default: break; } break; case WM_INITDLG: /* Add switch entry */ memset(&swctl,0,sizeof(swctl)); WinQueryWindowProcess(hwnd,&pid,NULL); swctl.hwnd=hwnd; swctl.uchVisibility=SWL_VISIBLE; swctl.idProcess=pid; swctl.bProgType=PROG_DEFAULT; swctl.fbJump=SWL_JUMPABLE; WinAddSwitchEntry(&swctl); #if 0 WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, "", "", 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE ); #endif // oldProc=WinSubclassWindow(WinWindowFromID(hwnd, IDST_TEXT), newProc); hwndNew=WinCreateWindow(hwnd, CLASS_NAME, "Title", WS_VISIBLE |WS_TABSTOP, 10,50, SLIDERID, 40, hwnd, HWND_TOP, SLIDERID, NULLHANDLE, NULLHANDLE); WinShowWindow(hwnd, TRUE); // WinQueryWindowPos(hwndNew,&swpSl); return (MRESULT) TRUE; /* WM_APPTERMINATENOTIFY messages are sent from the helper programs e.g. format checker. */ case WM_CLOSE: WinDismissDlg(hwnd,0); return FALSE; case WM_CONTROL: { switch(SHORT2FROMMP(mp1)) { case SLN_SLIDERTRACK: { switch(SHORT1FROMMP(mp1)) { case SLIDERID: DosBeep(5000, 10); break; default: break; }/* switch */ return (MRESULT) 0; break; } case SLN_CHANGE: { switch(SHORT1FROMMP(mp1)) { case SLIDERID: DosBeep(500, 100); break; default: break; }/* switch */ return (MRESULT)TRUE; } default: break; }/* switch */ break; }/* WM_CONTROL */ case WM_COMMAND: switch(SHORT1FROMMP(mp1)) { case DID_OK: /* User pressed the OK button */ WinPostMsg(hwnd,WM_CLOSE,0,0); break; case IDPB_RIGHT: WinPostMsg( WinWindowFromID(hwnd, SLIDERID), SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE), MPFROMLONG( (LONG) 70 )); break; case IDPB_LEFT: WinPostMsg( WinWindowFromID(hwnd, SLIDERID), SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE), MPFROMLONG( (LONG) 20 )); break; case IDPB_SIZE: { SWP swp; RXSTRING arg[2]; /* argument string for REXX */ RXSTRING rexxretval; /* return value from REXX */ APIRET rc; /* return code from REXX */ SHORT rexxrc = 0; /* return code from function */ char chrThis[20]; char chrHwnd[20]; char *str = "These words will be swapped"; /* text to swap */ #if 0 RexxRegisterFunctionExe("CWRXFunc1", (PFN)rexxFunc1); sprintf(chrThis, "%d",123); sprintf(chrHwnd, "%d", WinQueryWindow(hwnd,QW_PARENT)); /* By setting the strlength of the output RXSTRING to zero, we */ /* force the interpreter to allocate memory and return it to us. */ /* We could provide a buffer for the interpreter to use instead. */ rexxretval.strlength = 0L; /* initialize return to empty*/ MAKERXSTRING(arg[0], chrHwnd, strlen(chrHwnd));/* create input argument */ MAKERXSTRING(arg[1], chrThis, strlen(chrThis));/* create input argument */ /* Here we call the interpreter. We don't really need to use */ /* all the casts in this call; they just help illustrate */ /* the data types used. */ rc=RexxStart((LONG) 2, /* number of arguments */ (PRXSTRING) &arg, /* array of arguments */ (PSZ) "G:\\Projects_working\\mmclasses-0.3.0\\testfunc.cwr",/* name of REXX file */ (PRXSTRING) 0, /* No INSTORE used */ (PSZ) "CWRXX", /* Command env. name */ (LONG) RXSUBROUTINE, /* Code for how invoked */ (PRXSYSEXIT) 0, /* No EXITs on this call */ (PSHORT) &rexxrc, /* Rexx program output */ (PRXSTRING) &rexxretval ); /* Rexx program output */ sprintf(text,"rc: %d, function return code: %d, %s ", rc, (int) rexxrc, rexxretval.strptr); WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, text, "", 1234, MB_OK|MB_MOVEABLE); DosFreeMem(rexxretval.strptr); /* Release storage given to us by REXX. */ #endif // WinQueryWindowPos(hwndNew,&swp); // WinSetWindowPos(hwndNew, NULLHANDLE, 0, 0, swp.cx-30, swp.cy+10,SWP_SIZE); break; } default: break; } return (MRESULT) FALSE; default: break; }/* switch */ return WinDefDlgProc( hwnd, msg, mp1, mp2); }
BOOL CandyBarZFrameBorderPaintProc(HWND hwnd, RECTL * rect, HPS hpsFrame, short sState) { CBZDATA *pCBZData; CBZSHARE *pCBZShare; PSPAINT *pPaint; TEMPPAINT *pFramePaint; BOOL rc; int i; ULONG ulDataOffset; if (DosGetNamedSharedMem((PPVOID) & pCBZShare, CBZ_SHARE, PAG_READ) != NO_ERROR) { return (FALSE); } ulDataOffset = pCBZShare->ulDataOffset; DosFreeMem(pCBZShare); // get window data if ((pCBZData = WinQueryWindowPtr(CandyBarZGetTopLevelFrameHWND(hwnd), ulDataOffset)) == NULL || !pCBZData->bFrameBorderEnabled ) { return (FALSE); } if (pCBZData->sFrameBorderIndex >= pCBZData->sPushButtonIndex) { return (FALSE); } // alloc paint struct if (DosAllocMem((PPVOID) & pFramePaint, sizeof(TEMPPAINT), PAG_READ | PAG_WRITE | PAG_COMMIT) != NO_ERROR) { return (FALSE); } memset(pFramePaint, 0, sizeof(TEMPPAINT)); pFramePaint->hab = WinQueryAnchorBlock(hwnd); // alloc paint struct if (DosAllocMem((PPVOID) & pPaint, sizeof(PSPAINT), PAG_READ | PAG_WRITE | PAG_COMMIT) != NO_ERROR) { DosFreeMem(pFramePaint); return (FALSE); } memset(pPaint, 0, sizeof(PSPAINT)); //Text plugin needs this for quering presentation parameters. pPaint->hwnd = hwnd; // entire window pPaint->rectlWindow = pPaint->rectlUpdate = *rect; // get PS pPaint->hpsWin = hpsFrame; // we will blt and draw gradient text into the hps associated with this dc if ((pFramePaint->hdc = DevOpenDC(pFramePaint->hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, NULLHANDLE)) == NULLHANDLE) { DosFreeMem(pPaint); DosFreeMem(pFramePaint); return (FALSE); } // create hps2 for hdc2. hps for hdc depends on size of bitmap, so it's not created until // we know if it's active or not. create for size of window, then we blt only portion // needed pFramePaint->slHPS.cx = pPaint->rectlWindow.xRight; pFramePaint->slHPS.cy = pPaint->rectlWindow.yTop; if ((pPaint->hps = GpiCreatePS(pFramePaint->hab, pFramePaint->hdc, &(pFramePaint->slHPS), PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC)) == NULLHANDLE) { DevCloseDC(pFramePaint->hdc); DosFreeMem(pPaint); DosFreeMem(pFramePaint); return (FALSE); } pFramePaint->bif2.cbFix = sizeof(BITMAPINFOHEADER2); pFramePaint->bif2.cx = pPaint->rectlWindow.xRight; pFramePaint->bif2.cy = pPaint->rectlWindow.yTop; pFramePaint->bif2.cBitCount = 24; pFramePaint->bif2.cPlanes = 1; if ((pFramePaint->hbmTemp = GpiCreateBitmap(pPaint->hps, // create bitmap (PBITMAPINFOHEADER2) & (pFramePaint->bif2), (ULONG) 0, (PSZ) NULL, (PBITMAPINFO2) & (pFramePaint->bif2))) == NULLHANDLE) { GpiDestroyPS(pPaint->hps); DevCloseDC(pFramePaint->hdc); DosFreeMem(pPaint); DosFreeMem(pFramePaint); return (FALSE); } if (GpiSetBitmap(pPaint->hps, pFramePaint->hbmTemp) == HBM_ERROR) { GpiDeleteBitmap(pFramePaint->hbmTemp); GpiDestroyPS(pPaint->hps); DevCloseDC(pFramePaint->hdc); DosFreeMem(pPaint); DosFreeMem(pFramePaint); return (FALSE); } // set color table into rgb mode. otherwise colors between 0 and // 15 are interpreted as indexes GpiCreateLogColorTable(pPaint->hps, 0, LCOLF_RGB, 0, 0, NULL); { //fill ps with default bg color... ULONG attrFound; long lColor; if ( (WinQueryPresParam(hwnd, PP_BACKGROUNDCOLOR, 0, &attrFound, sizeof(attrFound), &lColor, QPF_PURERGBCOLOR)) == 0 ) lColor = WinQuerySysColor(HWND_DESKTOP, SYSCLR_DIALOGBACKGROUND, 0); // fill with default color WinFillRect(pPaint->hps, &(pPaint->rectlUpdate), lColor); } // call Plugins Paint Procedures here for (i = pCBZData->sFrameBorderIndex; i < pCBZData->sPushButtonIndex; i++) { if ( !(pCBZData->Plugins[i].pfnPluginRender(pPaint, pCBZData->Plugins[i].pData, sState)) ) { GpiSetBitmap(pPaint->hps, NULLHANDLE); GpiDeleteBitmap(pFramePaint->hbmTemp); GpiDestroyPS(pPaint->hps); DevCloseDC(pFramePaint->hdc); DosFreeMem(pPaint); DosFreeMem(pFramePaint); return (FALSE); } } if ((rc = BltToWindow(pPaint)) == TRUE) { //paint sucessful, validate the window // WinQueryWindowRect(hwnd, &(pPaint->rectlUpdate)); WinValidateRect(hwnd, &(pPaint->rectlUpdate), FALSE); } GpiSetBitmap(pPaint->hps, NULLHANDLE); GpiDeleteBitmap(pFramePaint->hbmTemp); GpiDestroyPS(pPaint->hps); DevCloseDC(pFramePaint->hdc); DosFreeMem(pPaint); DosFreeMem(pFramePaint); return (rc); }
//=========================================================================== // Draw the titlebar. // Parameters -------------------------------------------------------------- // PSTLRFRAME p : windows data. // Return value ------------------------------------------------------------ // VOID //=========================================================================== static VOID DrawTitlebar(PSTLRFRAME p) { PTBARAIOPT ptbo = p->is.tbhilited? &o.tb.a : &o.tb.i; POINTL apt[3]; INT i; GpiCreateLogColorTable(p->hps, 0, LCOLF_RGB, 0, 0, NULL); // background ---------------------------------------------------------- switch (ptbo->bkgnd) { // shade -------------------------------------------------------- case TBARBKGNDSHADE: if (ptbo->shade) { // sfumatura orizzontale WsetRect(apt, 0, 0, p->wrclTitle.cx, p->wrclTitle.cy); WinDrawBitmap(p->hps, ptbo->hbmp, NULL, apt, 0, 0, DBM_STRETCH); } else { // sfumatura verticale WsetRect(apt, 0, 0, p->wrclTitle.cx, SHADEH_CY); for (i = 0; i < p->wrclTitle.cy; i += 2) { WinDrawBitmap(p->hps, ptbo->hbmp, NULL, apt, 0, 0, DBM_STRETCH); ((PRECTL)apt)->yBottom += SHADEH_CY; ((PRECTL)apt)->yTop += SHADEH_CY; } /* endfor */ } /* endif */ break; // bitmap ------------------------------------------------------- case TBARBKGNDBMP: WsetRect(&apt[1], 0, 0, p->wrclTitle.cx, p->wrclTitle.cy); if (ptbo->strch) { WinDrawBitmap(p->hps, ptbo->hbmp, NULL, &apt[1], 0, 0, DBM_STRETCH); } else { apt[0].x = apt[0].y = 0; while (apt[0].x <= p->wrclTitle.cx) { WinDrawBitmap(p->hps, ptbo->hbmp, (PRECTL)&apt[1], apt, 0, 0, 0); apt[0].x += ptbo->size.cx; apt[2].x = p->wrclTitle.cx - apt[0].x; } /* endwhile */ } /* endif */ break; // solid color -------------------------------------------------- default: apt[0].x = p->wrclTitle.cx - 1; apt[0].y = p->wrclTitle.cy - 1; GpiSetColor(p->hps, ptbo->clrLeftTop.l); GpiBox(p->hps, DRO_OUTLINEFILL, apt, 0L, 0L); break; } /* endswitch */ // text ---------------------------------------------------------------- if (!p->cyfont) { GpiQueryTextBox(p->hps, p->cchTxt, p->achTxt, 3, apt); p->yfont = - apt[1].y; p->cyfont = apt[0].y - apt[1].y; p->cxfont = apt[2].x - apt[0].x; } /* endif */ // se il testo Š pi— largo della finestra viene comunque allineato a sin. i = (p->cxfont < p->wrclTitle.cx) ? 8: 0; apt[0].x = (ptbo->center && i)? (p->wrclTitle.cx - p->cxfont) / 2 + 1: i + 3; apt[0].y = (p->wrclTitle.cy - p->cyfont) / 2 + p->yfont; apt[1].x = 0; apt[1].y = 0; apt[2].x = p->wrclTitle.cx - 1; apt[2].y = p->wrclTitle.cy - 1; if (ptbo->_3DTxt) { // disegna ombra testo GpiSetColor(p->hps, ptbo->clrBgTxt.l); GpiCharStringPosAt(p->hps, apt, (PRECTL)(apt + 1), CHS_CLIP, p->cchTxt, p->achTxt, NULL); } /* endif */ apt[0].x--; apt[0].y++; GpiSetColor(p->hps, ptbo->clrFgTxt.l); GpiCharStringPosAt(p->hps, apt, (PRECTL)(apt + 1), CHS_CLIP, p->cchTxt, p->achTxt, NULL); // border -------------------------------------------------------------- if (ptbo->border) { GpiMove(p->hps, &apt[1]); apt[1].y = apt[2].y; GpiSetColor(p->hps, ptbo->clrHiBkgnd.l); GpiPolyLine(p->hps, 2, &apt[1]); apt[1].x = apt[2].x; apt[1].y = 0; apt[2].x = 1; apt[2].y = 0; GpiSetColor(p->hps, ptbo->clrShBkgnd.l); GpiPolyLine(p->hps, 2, &apt[1]); } /* endif */ }
BOOL NextBarDlg::OCommand(ULONG msg, MPARAM mp1, MPARAM mp2) { switch(msg) { case WM_INITDLG: centerDlg(); Title.inherit(hwnd); Program.inherit(hwnd); Path.inherit(hwnd); Parms.inherit(hwnd); Icon.inherit(hwnd); Settings.inherit(hwnd); Settings.setFont("8.Helv"); setProgram2Dialog(); if (actualButton) WinSendMsg(WinWindowFromID(hwnd, NHX_ICONFIELD), SM_SETHANDLE, MPFROMP(actualButton->pIco->hptr), NULL); break; case WM_CONTROL: handleButtons(mp1); break; case DM_DRAGOVER: { PDRAGINFO pdinfo = (PDRAGINFO) mp1; PDRAGITEM pditem = NULL; DrgAccessDraginfo(pdinfo); pditem = DrgQueryDragitemPtr(pdinfo, 0); if (DrgVerifyRMF(pditem, "DRM_OS2FILE", NULL)) { DrgFreeDraginfo (pdinfo) ; return(TRUE); } else { DrgFreeDraginfo (pdinfo) ; return(FALSE); } } case DM_DROP: { PDRAGINFO pDragInfo; /* Pointer to DRAGINFO structure */ PDRAGITEM pDragItem; /* Pointer to DRAGITEM structure */ CHAR Buffer[CCHMAXPATH]; CHAR ObjectType[CCHMAXPATH]; PSZ pszBuffer; OString tmpBuf; pDragInfo = (PDRAGINFO)mp1; if(DrgAccessDraginfo(pDragInfo)==FALSE) break; pDragItem = DrgQueryDragitemPtr(pDragInfo, 0); DrgQueryStrName(pDragItem->hstrRMF, sizeof(ObjectType), ObjectType); if(!strstr(ObjectType, "<DRM_OBJECT, DRF_OBJECT>")) { // this is not a WPS object DrgQueryStrName(pDragItem->hstrContainerName, sizeof(Buffer), Buffer); pszBuffer = ((PSZ) Buffer)+strlen(Buffer); DrgQueryStrName(pDragItem->hstrSourceName, sizeof(Buffer)-strlen(pszBuffer), pszBuffer); tmpBuf << Buffer; strupr(tmpBuf); if (strstr(tmpBuf, ".ICO")) { hps = WinGetPS(WinWindowFromID(hwnd, NHX_ICONFIELD)); GpiCreateLogColorTable(hps, LCOL_RESET, LCOLF_RGB, 0L, 0L, NULL); WinQueryWindowRect(WinWindowFromID(hwnd, NHX_ICONFIELD), &rcl); GpiSetColor(hps, SYSCLR_DIALOGBACKGROUND); GpiBox(hps, DRO_FILL, (PPOINTL) &rcl.xRight, 0L, 0L); WinReleasePS(hps); if (actualButton->pIco) delete actualButton->pIco; try { actualButton->pIco = new OIcon(Buffer); } catch(...) { delete actualButton->pIco; actualButton->pIco = new OIcon(); } WinSendMsg(WinWindowFromID(hwnd, NHX_ICONFIELD), SM_SETHANDLE, MPFROMP(actualButton->pIco->hptr), NULL); WinSetDlgItemText(hwnd, NHX_ICON, Buffer); } else if ((!strstr(tmpBuf, ".EXE")) && (!strstr(tmpBuf, ".COM")) && (!strstr(tmpBuf, ".BAT")) && (!strstr(tmpBuf, ".CMD"))) install2Dialog(Buffer, TRUE); else install2Dialog(Buffer, FALSE); } else { DrgQueryStrName(pDragItem->hstrSourceName, sizeof(Buffer), Buffer); install2Dialog(Buffer, TRUE); } break; } case WM_COMMAND: switch(SHORT1FROMMP(mp1)) { case NHX_SAVE: setDialog2Program(); if (isCreation) WinPostMsg(nxh->toolbar->hwnd, WM_TOOLBAR_RESET, NULL, NULL); else WinPostMsg(nxh->toolbar->hwnd, WM_SAVE_BUTTONS, NULL, NULL); event = NULL; WinPostMsg(hwnd, WM_CLOSE, NULL, NULL); break; case NHX_CANCEL: WinSendMsg(hwnd, WM_CLOSE, NULL, NULL); break; case NHX_LOAD: loadProgram(); break; } break; case WM_HELP: nxh->toolbar->helpRequest(PANEL_CFGS); break; case WM_CLOSE: WinSendMsg(WinWindowFromID(hwnd, NHX_ICONFIELD), SM_SETHANDLE, MPFROMP(NULLHANDLE), NULL); if (isCreation) WinPostMsg(nxh->toolbar->hwnd, WM_CFG_CANCELED, MPFROMP(event), NULL); delete this; break; default: return(FALSE); } return(TRUE); #ifdef __BORLANDC__ #pragma warn -par #endif }
/**************************************************************************\ * * * ROUTINE: ClkColorsDlgProc ( ) * * * * COMMENT: "Clock Color Preferences" Dialog * * * * RETURNS: MRESULT, 0 or return value from WinDefDlgProc * * * \**************************************************************************/ MRESULT EXPENTRY ClkColorsDlgProc(HWND hwnd, ULONG usMsg, MPARAM mp1, MPARAM mp2) { static USHORT usCheckedPartID = 0, usCheckedColorID = 0; static LONG clrBackgroundNew; static LONG clrFaceNew; static LONG clrHourHandNew; static LONG clrMinuteHandNew; static LONG *pclrNew; switch (usMsg) { USHORT usButtonID; HWND hwndButton; HPS hpsT; RECTL rclButton, rclButtonInterior; case WM_INITDLG: hpsT = WinGetPS(hwnd); GpiCreateLogColorTable(hpsT, LCOL_RESET, LCOLF_RGB, 0L, 0L, NULL); /* Load the new values from the current ones. */ clrBackgroundNew = GpiQueryColorIndex(hpsT, 0L, cp.clrBackground); clrFaceNew = GpiQueryColorIndex(hpsT, 0L, cp.clrFace ); clrHourHandNew = GpiQueryColorIndex(hpsT, 0L, cp.clrHourHand ); clrMinuteHandNew = GpiQueryColorIndex(hpsT, 0L, cp.clrMinuteHand); WinReleasePS(hpsT); /* click the "Background" radio button */ WinPostMsg(WinWindowFromID(hwnd, CLKCLR_BACKGROUND), BM_CLICK, MPFROMSHORT(TRUE), MPVOID); /* Let the default dialog procedure handle anything else. */ break; case WM_COMMAND: switch (LOUSHORT(mp1)) { case DID_OK: hpsT = WinGetPS(hwnd); GpiCreateLogColorTable(hpsT, LCOLF_RGB, 0L, 0L, 0L, NULL); /* * Uupdate the one the user has selected. */ switch(usCheckedPartID) { case CLKCLR_BACKGROUND: cp.clrBackground = GpiQueryRGBColor(hpsT, 0L, clrBackgroundNew); break; case CLKCLR_FACE: cp.clrFace = GpiQueryRGBColor(hpsT, 0L, clrFaceNew); break; case CLKCLR_HOURHAND: cp.clrHourHand = GpiQueryRGBColor(hpsT, 0L, clrHourHandNew); break; case CLKCLR_MINUTEHAND: cp.clrMinuteHand = GpiQueryRGBColor(hpsT, 0L, clrMinuteHandNew); break; } WinReleasePS(hpsT); /* repaint with the new colors */ WinInvalidateRect(hwndFrame, NULL, TRUE); case DID_CANCEL: WinDismissDlg(hwnd, TRUE); } return NULL; case WM_CONTROL: usButtonID = SHORT1FROMMP(mp1); /* selecting a new object */ if (usButtonID & CLKCLR_OBJECTS) { MRESULT rc; switch (usButtonID) { case CLKCLR_BACKGROUND: pclrNew = &clrBackgroundNew; break; case CLKCLR_FACE: pclrNew = &clrFaceNew; break; case CLKCLR_HOURHAND: pclrNew = &clrHourHandNew; break; case CLKCLR_MINUTEHAND: pclrNew = &clrMinuteHandNew; } usCheckedPartID = usButtonID; /* click the button for the new object's current color */ rc = WinSendMsg(WinWindowFromID(hwnd, (CLKCLR_BUTTONSHIFT + *pclrNew)), BM_CLICK, MPFROMSHORT(TRUE), MPVOID); break; } switch (SHORT2FROMMP(mp1)) { case BN_CLICKED: *pclrNew = (LONG)usButtonID - CLKCLR_BUTTONSHIFT; /* Turn off the check state of the previously checked * button and turn on the check state of the button * just clicked. */ WinCheckButton(hwnd, usCheckedColorID, FALSE); WinCheckButton(hwnd, usButtonID, TRUE); usCheckedColorID = usButtonID; break; case BN_PAINT: /* Fill only the interior of the button, so we don't * conflict with the focus indicator */ hwndButton = ((PUSERBUTTON) mp2) -> hwnd; WinQueryWindowRect(hwndButton, &rclButton); rclButton.xLeft++; rclButton.yBottom++; rclButton.xRight--; rclButton.yTop--; WinFillRect(((PUSERBUTTON) mp2)->hps, &rclButton, (LONG)usButtonID - CLKCLR_BUTTONSHIFT); /* Hollow out those buttons which aren't checked */ if (!WinQueryButtonCheckstate(hwnd, usButtonID)) { rclButtonInterior.xLeft = rclButton.xLeft + 4; rclButtonInterior.yBottom = rclButton.yBottom + 4; rclButtonInterior.xRight = rclButton.xRight - 4; rclButtonInterior.yTop = rclButton.yTop - 4; WinFillRect(((PUSERBUTTON)mp2)->hps, &rclButtonInterior, SYSCLR_WINDOW); } break; } /* fall through to the default control processing */ } return WinDefDlgProc(hwnd, usMsg, mp1, mp2); }
/****************************************************************\ * *-------------------------------------------------------------- * * Name:ClkCreate() * * Purpose:Intialize a newly created client window * * * * Usage: * * Method: * - * * - * - * * - * - * * Returns: * 1 - if sucessful execution completed * 0 - if error \****************************************************************/ VOID ClkCreate ( HWND hwnd ) { LONG cxScreen , cyScreen; /* screen dimensions */ LONG xLeft , yBottom ; /* frame window location */ ULONG cbBuf; LONG cyHeight; LONG cxWidth; hwndClient = hwnd; WinLoadString(hab, NULLHANDLE, IDS_TITLE, 0, (PSZ)szTitle ); WinLoadString(hab, NULLHANDLE, IDS_HELPTITLE, 256, (PSZ)szHelpTitle); GetCountryDependent(); /* we are called before the global hwndFrame is valid */ hwndFrame = WinQueryWindow ( hwnd , QW_PARENT) ; hwndTitleBar = WinWindowFromID ( hwndFrame , FID_TITLEBAR ) ; hwndSysMenu = WinWindowFromID ( hwndFrame , FID_SYSMENU ) ; hwndMinMax = WinWindowFromID ( hwndFrame , FID_MINMAX ) ; /* load our menus */ hwndMenu = WinLoadMenu (hwndFrame, NULLHANDLE, IDR_MAIN); /* determine screen dimensions */ /* open a device context and create a presentation space */ hdc = WinOpenWindowDC (hwnd); hps = GpiCreatePS (hab, hdc, &sizl, PU_ARBITRARY | GPIT_MICRO | GPIA_ASSOC); /* * Create our off-screen 'buffer'. */ hdcBuffer = DevOpenDC ( (HAB)0L, OD_MEMORY, "*", 0L, NULL, hdc); hpsBuffer = GpiCreatePS (hab, hdcBuffer, &sizl, PU_ARBITRARY | GPIT_MICRO | GPIA_ASSOC); GpiCreateLogColorTable (hpsBuffer, 0, LCOLF_RGB, 0, 0, (PLONG)NULL); /* get the device resolutions so we can make the face appear circular */ DevQueryCaps (hdc, (LONG)CAPS_VERTICAL_RESOLUTION,(LONG) 1L, &cyRes); DevQueryCaps (hdc, CAPS_HORIZONTAL_RESOLUTION, 1L, &cxRes); DevQueryCaps (hdc, CAPS_COLOR_PLANES, 1L, &cColorPlanes); DevQueryCaps (hdc, CAPS_COLOR_BITCOUNT, 1L, &cColorBitcount); cxScreen = WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN); cyScreen = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN); /* * Calculate an initial window position and size. */ xLeft = cxScreen / 8; yBottom = cyScreen / 2; cxWidth = cxScreen / 3; cyHeight = cyScreen / 2; WinSetWindowPos (hwndFrame, NULLHANDLE, xLeft, yBottom, cxWidth, cyHeight, SWP_SIZE | SWP_MOVE | SWP_ACTIVATE); cbBuf = sizeof(cp); if (!PrfQueryProfileData(HINI_USER, SZ_APPNAME, SZ_KEYNAME, &cp, &cbBuf)) { cp.usMajorTickPref = CLKTM_ALWAYS; cp.usMinorTickPref = CLKTM_NOTICONIC; cp.clrBackground = 0x00008080; cp.clrFace = 0x00008080; cp.clrHourHand = RGB_RED; cp.clrMinuteHand = RGB_RED; cp.fControlsHidden = FALSE; cp.usDispMode = DM_TIME | DM_ANALOG | DM_SECONDHAND; cp.alarm.uchHour = 0; cp.alarm.uchMinutes = 0; cp.alarm.usMode = 0; SetRGBColors(); /* position the window and make it visible */ WinSetWindowPos( hwndFrame , NULLHANDLE , xLeft , yBottom , cxWidth , cyHeight , SWP_SIZE | SWP_MOVE | SWP_ACTIVATE); WinQueryWindowPos(hwndFrame, &cp.swp); } else { /*Protect against garbage swp*/ cp.swp.hwnd = hwndFrame; cp.swp.hwndInsertBehind = HWND_TOP; cp.swp.fl = (cp.swp.fl & (SWP_MINIMIZE | SWP_MAXIMIZE)) | SWP_SIZE | SWP_MOVE | SWP_ACTIVATE; SetRGBColors(); WinSetMultWindowPos(hab, &cp.swp, 1); } if (cp.fControlsHidden) ClkHideFrameControls (hwndFrame); /* * Check relevant items. */ WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT( IDM_TIME, TRUE), MPFROM2SHORT( MIA_CHECKED, ( (cp.usDispMode & DM_TIME)? MIA_CHECKED : ~MIA_CHECKED) ) ); WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT( IDM_DATE, TRUE), MPFROM2SHORT( MIA_DISABLED, ( (!(cp.usDispMode & DM_TIME))? MIA_DISABLED : ~MIA_DISABLED) ) ); WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT( IDM_DATE, TRUE), MPFROM2SHORT( MIA_CHECKED, ( (cp.usDispMode & DM_DATE)? MIA_CHECKED : ~MIA_CHECKED) ) ); WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT( IDM_TIME, TRUE), MPFROM2SHORT( MIA_DISABLED, ( ((!(cp.usDispMode & DM_DATE) || (cp.usDispMode & DM_ANALOG)))? MIA_DISABLED : ~MIA_DISABLED) ) ); WinSendMsg( hwndMenu, MM_SETITEMATTR, MPFROM2SHORT( (cp.usDispMode & DM_DIGITAL) ?IDM_DIGITAL :IDM_ANALOG, TRUE), MPFROM2SHORT( MIA_CHECKED, MIA_CHECKED)); WinSendMsg(hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(IDM_SECONDHAND, TRUE), MPFROM2SHORT( MIA_CHECKED, ( (cp.usDispMode & DM_SECONDHAND) ? MIA_CHECKED : ~MIA_CHECKED))); /* * Disable these items if the digital clock is visible * since they won't apply. */ if (cp.usDispMode & DM_DIGITAL) { WinSendMsg (hwndMenu, MM_SETITEMATTR, MPFROM2SHORT(IDM_SECONDHAND, TRUE), MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)); WinSendMsg (hwndMenu, MM_SETITEMATTR, MPFROM2SHORT( IDM_TICKS, TRUE), MPFROM2SHORT( MIA_DISABLED, MIA_DISABLED)); } /* have we been asked to start as an icon? */ if (fStartAsIcon) WinSetWindowPos(hwndFrame, NULLHANDLE, 0, 0, 0, 0, SWP_MINIMIZE); WinShowWindow(hwndFrame, TRUE); /* get the time in a format for dislaying */ DosGetDateTime(&dt); dt.hours = (UCHAR )(dt.hours * (UCHAR) 5) % (UCHAR) 60 + dt.minutes / (UCHAR)12; /* start a timer */ WinStartTimer (hab, hwnd, IDR_MAIN, 1000); WinLoadString(hab, NULLHANDLE, IDS_TITLE, 80, (PSZ)szTitle); GetCountryDependent(); }
MRESULT EXPENTRY ProgressDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { switch (msg) { // init ----------------------------------------------------------------- case WM_INITDLG: { PPRGSAPPDATA pad = (PPRGSAPPDATA)mp2; ULONG ul; POINTL aptl[] = {{1, 36}, {220, 24}}; WinSetWindowPtr(hwnd, 0L, (PVOID)mp2); WinSetWindowText(hwnd, pad->ppd->pszTitle); // dimensioni-coordinate varie pad->cyTitle = uGetSval(SV_CYTITLEBAR); pad->hButton = WinWindowFromID(hwnd, BTN_STOP); WinQueryWindowPos(pad->hButton, &pad->swp); WinQueryWindowRect(hwnd, &pad->rcl); WinMapDlgPoints(hwnd, aptl, 2, TRUE); pad->sldd.cbSize = sizeof(SLDCDATA); pad->sldd.usScale1Increments = 11; pad->sldd.usScale1Spacing = (pad->rcl.xRight - 2 * pad->cyTitle) / 10 - 1; pad->hProgress = WinCreateWindow(hwnd, WC_SLIDER, (PSZ)NULL, SLS_BOTTOM | SLS_OWNERDRAW | SLS_READONLY | SLS_RIBBONSTRIP | WS_VISIBLE, 3, aptl[0].y, pad->rcl.xRight - 6, aptl[1].y, hwnd, HWND_TOP, SLDR_PROGRESS, (PVOID)&pad->sldd, NULL); // controlla versione S.O. e setta font slider e bottone DosQuerySysInfo(QSV_VERSION_MINOR, QSV_VERSION_MINOR, &ul, sizeof(ULONG)); if (ul < 40) { WinSetPresParam(pad->hProgress, PP_FONTNAMESIZE, 7, "8.Helv"); WinSetPresParam(pad->hButton, PP_FONTNAMESIZE, 7, "8.Helv"); } else { WinSetPresParam(pad->hProgress, PP_FONTNAMESIZE, 11, "9.WarpSans"); } /* endif */ // rileva larghezza progress bar pad->cxPrgs = LOUSHORT((ULONG)WinSendMsg(pad->hProgress, SLM_QUERYSLIDERINFO, MPFROM2SHORT(SMA_SHAFTDIMENSIONS, 0), MPVOID)) - 6; // setta altezza barra pari a altezza barra titolo WinSendMsg(pad->hProgress, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SHAFTDIMENSIONS, 0), (MPARAM)pad->cyTitle); // setta testo e altezza barra graduata WinSendMsg(pad->hProgress, SLM_SETTICKSIZE, MPFROM2SHORT(SMA_SETALLTICKS, pad->cyTitle / 3), MPVOID); WinSendMsg(pad->hProgress, SLM_SETSCALETEXT, (MPARAM)0, (MPARAM)"0%"); WinSendMsg(pad->hProgress, SLM_SETSCALETEXT, (MPARAM)5, (MPARAM)"50%"); WinSendMsg(pad->hProgress, SLM_SETSCALETEXT, (MPARAM)10, (MPARAM)"100%"); // testo iniziale progesso e elapsed time: sprintf(pad->achElapsed, "%s: 00:00:00", pad->ppd->pszTime); WinSetDlgItemText(hwnd, TXT_TIME, pad->achElapsed); sprintf(pad->achCurPrg, "%s: 0%%", pad->ppd->pszPrgrss); WinSetDlgItemText(hwnd, TXT_PERCENT, pad->achCurPrg); // se specificato setta nuovo font dialogo if (pad->ppd->fl & PRGSS_FONT) WsetDlgFonts(hwnd, NULLHANDLE, pad->ppd->FontNameSize); // posiziona finestra al centro Parent window if (pad->ppd->fl & PRGSS_CENTER) { WcenterInWindow(hwnd, pad->ppd->hPos); } else { SWP swp; swp.hwnd = pad->ppd->hPos; swp.x = pad->ppd->ptl.x; swp.y = pad->ppd->ptl.y; swp.cx = swp.cy = 0; swp.fl = SWP_MOVE | SWP_SHOW | SWP_ACTIVATE | SWP_ZORDER; swp.hwndInsertBehind = HWND_TOP; WsetRelativePos(hwnd, &swp); } // end if // notifica creazione dialogo WinPostMsg(pad->ppd->hNotify, WM_PRGRSREADY, (MPARAM)hwnd, (MPARAM)0); break; } // end case WM_INITDLG case WM_DRAWITEM: if (((POWNERITEM)mp2)->idItem == SDA_RIBBONSTRIP) { PPRGSAPPDATA pad = GetData(hwnd); if (pad->ppd->fl & PRGSS_BITMAP) { // se deve disegnare la bitmap RECTL rcl = {0, 0, ((POWNERITEM)mp2)->rclItem.xRight - ((POWNERITEM)mp2)->rclItem.xLeft, pad->cyTitle}; POINTL ptl = {((POWNERITEM)mp2)->rclItem.xLeft, ((POWNERITEM)mp2)->rclItem.yBottom}; while (ptl.x < ((POWNERITEM)mp2)->rclItem.xRight) { WinDrawBitmap(((POWNERITEM)mp2)->hps, pad->ppd->hbmp, &rcl, &ptl, 0L, 0L, DBM_NORMAL); ptl.x += pad->cxbmp; rcl.xRight = ((POWNERITEM)mp2)->rclItem.xRight - ptl.x; } /* endwhile */ } else { // colore GpiCreateLogColorTable(((POWNERITEM)mp2)->hps, 0, LCOLF_RGB, 0, 0, NULL); WinFillRect(((POWNERITEM)mp2)->hps, &((POWNERITEM)mp2)->rclItem, pad->ppd->color); } /* endif */ return (MRESULT)TRUE; } // end if break; case PRGSM_INCREMENT: { // notifica incremento PPRGSAPPDATA pad = GetData(hwnd); ULONG ul; pad->incr = (ULONG)mp1; WinSendMsg(pad->hProgress, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE), (MPARAM)((pad->incr * pad->cxPrgs) / 1000)); ul = WinGetCurrentTime(pad->hab) / 1000; if (pad->current != ul) { pad->current = ul; pad->elapsed = pad->current - pad->start; sprintf(pad->achElapsed, "%s: %02d:%02d:%02d", pad->ppd->pszTime, pad->elapsed / 3600, (pad->elapsed % 3600) / 60, pad->elapsed % 60); WinSetDlgItemText(hwnd, TXT_TIME, pad->achElapsed); } // end if if (pad->ulCurPrg != (ul = (ULONG)mp1 / 10)) { pad->ulCurPrg = ul; sprintf(pad->achCurPrg, "%s: %3d %%", pad->ppd->pszPrgrss, pad->ulCurPrg); WinSetDlgItemText(hwnd, TXT_PERCENT, pad->achCurPrg); } // end if return (MRESULT)pad->flStop; } // end case PRGSM_INCREMENT case PRGSM_MSG: return (MRESULT)Wprint(hwnd, (PSZ)mp1, (ULONG)mp2); case WM_COMMAND: if ((ULONG)mp1 == BTN_STOP) { PPRGSAPPDATA pad = GetData(hwnd); pad->flStop = TRUE; WinEnableWindow(pad->hButton, FALSE); } /* endif */ break; case WM_CLOSE: { PPRGSAPPDATA pad = GetData(hwnd); // se elaborazione ancora in corso mostra messaggio if (pad->incr > 0 && pad->incr < 1000) { PSZ psz; if (!(psz = (PSZ)malloc(1024)) || // se la notify window restituisce NULL (BOOL)WinSendMsg(pad->ppd->hNotify, WM_PRGRSQUIT, (MPARAM)psz, MPVOID) || // o se la chiusura Š confermata Wprint(hwnd, psz, PMPRNT_QUERY)) { WinPostMsg(hwnd, PRGSM_END, MPVOID, MPVOID); WinPostMsg(pad->hOwner, WM_CLOSE, MPVOID, MPVOID); // se nel frattempo Š terminato } else { pad->qQuit.msg = 0; if (!pad->incr || pad->incr >= 1000) { WinPostMsg(hwnd, PRGSM_END, MPVOID, MPVOID); } else if ((BOOL)mp1) { WinCancelShutdown((HMQ)WinQueryWindowULong(hwnd, QWL_HMQ), FALSE); } // end if } // end if free (psz); } /* endif */ } break; default: return WinDefDlgProc(hwnd, msg, mp1, mp2); } /* endswitch */ return (MRESULT)FALSE; }
MRESULT EXPENTRY ROPsTestWndProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2) { CHAR szTitle[300]; /* Title Bar Text */ HPS hPS; /* Presentation Space Handle */ LONG lClrBack; /* Colour Holder */ LONG lClrFore; /* Colour Holder */ LONG lScrollInc;/* Scroll Increment */ PBITMAPARRAYFILEHEADER pbafh; /* Bitmap Array File Header Pointer */ PBITMAPARRAYFILEHEADER2 pbafh2; /* Bitmap Array File Header Pointer */ PBITMAPFILEHEADER pbfh; /* Bitmap File Header Pointer */ PBITMAPFILEHEADER2 pbfh2; /* Bitmap File Header Pointer */ PBITMAPINFO pbmi; /* Bitmap Info Pointer */ PBITMAPINFO2 pbmi2; /* Bitmap Info Pointer */ POINTL ptl; /* Pointer Position */ RECTL rcl; /* Window Rectangle */ register INT i; /* Index */ switch ( msg ) { /************************************************************************/ /* Window being created, perform window initialization */ /************************************************************************/ case WM_CREATE : hptrWait = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE); hptrArrow = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE); cxScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN); hmenuROPs = WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), FID_MENU); hwndHScroll = WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), FID_HORZSCROLL); hwndVScroll = WinWindowFromID(WinQueryWindow(hWnd, QW_PARENT), FID_VERTSCROLL); /************************************************/ /* PDSGetTemplate is used to allow controls in */ /* windows. Do not remove this function if you */ /* intend to include controls within the window.*/ /************************************************/ PDSGetTemplate(hWnd, WIN_ROPSTEST); break; /************************************************************************/ /* Window being sized */ /************************************************************************/ case WM_SIZE : if ( cBitmaps ) SizeBitmapStack(hWnd); WinQueryWindowRect(hWnd, &rcl); if ( (lHorzRange = cxROP - (cxWindow = rcl.xRight - rcl.xLeft)) < 0L ) { lHorzRange = 0L; rclROP.xLeft = 0L; rclROP.xRight = cxROP; } else rclROP.xRight = rclROP.xLeft + cxWindow; if ( (lVertRange = cyROP - (cyWindow = rcl.yTop - rcl.yBottom)) < 0L ) { lVertRange = 0L; rclROP.yBottom = 0L; rclROP.yTop = cyROP; } else rclROP.yBottom = (rclROP.yTop = cyROP - lVertPos) - cyWindow; WinSendMsg(hwndVScroll, SBM_SETSCROLLBAR, MPFROMSHORT(lVertPos), MPFROM2SHORT(0, lVertRange)); WinSendMsg(hwndVScroll, SBM_SETTHUMBSIZE, MPFROM2SHORT(cyWindow, cyROP), 0L); WinSendMsg(hwndHScroll, SBM_SETSCROLLBAR, MPFROMSHORT(lHorzPos), MPFROM2SHORT(0, lHorzRange)); WinSendMsg(hwndHScroll, SBM_SETTHUMBSIZE, MPFROM2SHORT(cxWindow, cxROP), 0L); WinInvalidateRect(hWnd, NULL, FALSE); break; /************************************************************************/ /* Perform menu initialization */ /************************************************************************/ case WM_INITMENU : switch ( SHORT1FROMMP(mp1) ) { case IDM_DISPLAY : WinSendMsg(hmenuROPs, MM_SETITEMATTR, MPFROM2SHORT(IDM_BITMAPARRAY, TRUE), MPFROM2SHORT(MIA_CHECKED, fBitmapArray ? MIA_CHECKED : 0)); WinSendMsg(hmenuROPs, MM_SETITEMATTR, MPFROM2SHORT(IDM_ROPARRAY, TRUE), MPFROM2SHORT(MIA_CHECKED, fBitmapArray ? 0 : MIA_CHECKED)); break; case IDM_FILE : break; } break; /************************************************************************/ /* Process key press from keyboard */ /************************************************************************/ case WM_CHAR : if ( CHARMSG(&msg)->fs & KC_VIRTUALKEY ) switch ( CHARMSG(&msg)->vkey ) { case VK_PAGEUP : WinSendMsg(hWnd, WM_VSCROLL, MPFROMSHORT(FID_VERTSCROLL), MPFROM2SHORT(0, SB_PAGEUP)); return(0L); case VK_PAGEDOWN : WinSendMsg(hWnd, WM_VSCROLL, MPFROMSHORT(FID_VERTSCROLL), MPFROM2SHORT(0, SB_PAGEDOWN)); return(0L); } /************************************************/ /* PDSKeyProc is used to allow controls in */ /* windows. Do not remove this function if you */ /* intend to include controls within the window.*/ /************************************************/ return(PDSKeyProc(hWnd, msg, mp1, mp2)); /************************************************************************/ /* Button 2 being depressed */ /************************************************************************/ case WM_BUTTON2DOWN : if ( !fBitmapArray && hbmROP ) { lHorzPos = SHORT1FROMMR(WinSendMsg(hwndHScroll, SBM_QUERYPOS, 0L, 0L)); lVertPos = SHORT1FROMMR(WinSendMsg(hwndVScroll, SBM_QUERYPOS, 0L, 0L)); lRop = (lVertPos + (cyWindow - SHORT2FROMMP(mp1))) / cyImage * 16 + (lHorzPos + SHORT1FROMMP(mp1)) / cxImage; WinDlgBox(HWND_DESKTOP, hwndROPsFrame, (PFNWP)ViewROPDlgProc, (HMODULE)NULL, DLG_VIEWROP, NULL); } break; /************************************************************************/ /* Process vertical scroll requests */ /************************************************************************/ case WM_VSCROLL : lVertPos = SHORT1FROMMR(WinSendMsg(hwndVScroll, SBM_QUERYPOS, 0L, 0L)); switch ( HIUSHORT(mp2) ) { case SB_LINEUP : lScrollInc = -cyImage; break; case SB_LINEDOWN : lScrollInc = cyImage; break; case SB_PAGEUP : lScrollInc = -cyWindow; break; case SB_PAGEDOWN : lScrollInc = cyWindow; break; case SB_SLIDERPOSITION : case SB_SLIDERTRACK : lScrollInc = SHORT1FROMMP(mp2) - lVertPos; break; default : return(0L); } if ( lScrollInc = max(-lVertPos, min(lScrollInc, lVertRange - lVertPos)) ) { rclROP.yBottom = (rclROP.yTop = cyROP - (lVertPos += lScrollInc)) - cyWindow; WinInvalidateRect(hWnd, NULL, FALSE); WinSendMsg(hwndVScroll, SBM_SETPOS, MPFROM2SHORT(lVertPos, 0), 0L); } break; /************************************************************************/ /* Process horizontal scroll requests */ /************************************************************************/ case WM_HSCROLL : lHorzPos = SHORT1FROMMR(WinSendMsg(hwndHScroll, SBM_QUERYPOS, 0L, 0L)); switch ( HIUSHORT(mp2) ) { case SB_LINELEFT : lScrollInc = -cxImage; break; case SB_LINERIGHT : lScrollInc = cxImage; break; case SB_PAGELEFT : lScrollInc = -cxWindow; break; case SB_PAGERIGHT : lScrollInc = cxWindow; break; case SB_SLIDERPOSITION : case SB_SLIDERTRACK : lScrollInc = SHORT1FROMMP(mp2) - lHorzPos; break; default : return(0L); } if ( lScrollInc = max(-lHorzPos, min(lScrollInc, lHorzRange - lHorzPos)) ) { rclROP.xRight = (rclROP.xLeft = (lHorzPos += lScrollInc)) + cxWindow; WinInvalidateRect(hWnd, NULL, FALSE); WinSendMsg(hwndHScroll, SBM_SETPOS, MPFROM2SHORT(lHorzPos, 0), 0L); } break; /************************************************************************/ /* Process control selections */ /************************************************************************/ case WM_CONTROL : switch ( SHORT2FROMMP(mp1) ) { } break; /************************************************************************/ /* Process menu and button selections */ /************************************************************************/ case WM_COMMAND : switch ( SHORT1FROMMP(mp1) ) { case IDM_OPTIONS : if ( WinDlgBox(HWND_DESKTOP, hwndROPsFrame, (PFNWP)OptionsDlgProc, (HMODULE)NULL, DLG_OPTIONS, NULL) ) { WinSetPointer(HWND_DESKTOP, hptrWait); CreateROPBitmap(hWnd); WinInvalidateRect(hWnd, NULL, FALSE); WinSetPointer(HWND_DESKTOP, hptrArrow); } break; case IDM_OPEN : if ( WinDlgBox(HWND_DESKTOP, hwndROPsFrame, (PFNWP)OpenBitmapDlgProc, (HMODULE)NULL, DLG_OPENBITMAP, NULL) ) { WinSetPointer(HWND_DESKTOP, hptrWait); hbmView = hbmGetBitmap(szBitmapFile); SizeBitmap(hWnd); if ( cBitmaps ) SizeBitmapStack(hWnd); CreateROPBitmap(hWnd); WinInvalidateRect(hWnd, NULL, FALSE); strcat(memcpy(szTitle, "Bitmap Viewer - ", 17), szBitmapFile); if ( fWindowsBitmap ) strcat(szTitle, " [Windows 3.x format]"); else if ( f20Bitmap ) strcat(szTitle, " [OS/2 2.x format]"); else strcat(szTitle, " [OS/2 1.x format]"); WinSetWindowText(hwndROPsFrame, szTitle); WinSetPointer(HWND_DESKTOP, hptrArrow); } break; case IDM_ROPARRAY : fBitmapArray = FALSE; WinInvalidateRect(hWnd, NULL, FALSE); break; case IDM_BITMAPARRAY : fBitmapArray = TRUE; WinInvalidateRect(hWnd, NULL, FALSE); break; } break; /************************************************************************/ /* Erase window background */ /************************************************************************/ case WM_ERASEBACKGROUND : WinQueryWindowRect(hWnd, &rcl); WinFillRect((HPS)LONGFROMMP(mp1), &rcl, CLR_PALEGRAY); break; /************************************************************************/ /* Paint client window */ /************************************************************************/ case WM_PAINT : GpiCreateLogColorTable(hPS = WinBeginPaint(hWnd, (HPS)NULL, &rcl), 0UL, LCOLF_RGB, 0L, 0L, (PLONG)NULL); /* Display the bitmap array images side-by-side */ if ( fBitmapArray ) { WinFillRect(hPS, &rcl, RGBCLR_PALEGRAY); for ( i = 0; i < cBitmaps; i++ ) { /* Check to see if the image is a 2-colour which */ /* menas that the colours have to be set */ /* explicitely */ if ( abm[i].cColours == 2L ) { lClrBack = lClrFore = 0L; /* Check to see if a 2.x format bitmap since the */ /* the structures are slightly different */ if ( f20Bitmap ) { /* Locate the bitmap information structure */ if ( (cBitmaps == 1) && !fBitmapArray ) { pbfh2 = (PBITMAPFILEHEADER2)abm[i].pb; pbmi2 = (PBITMAPINFO2)&pbfh2->bmp2; } else { pbafh2 = (PBITMAPARRAYFILEHEADER2)abm[i].pb; pbmi2 = (PBITMAPINFO2)&pbafh2->bfh2.bmp2; } /* Transfer the RGB info to the colour */ /* holders */ memcpy(&lClrBack, &pbmi2->argbColor[0], 3); memcpy(&lClrFore, &pbmi2->argbColor[1], 3); } else { /* Locate the bitmap information structure */ if ( (cBitmaps == 1) && !fBitmapArray ) { pbfh = (PBITMAPFILEHEADER)abm[i].pb; pbmi = (PBITMAPINFO)&pbfh->bmp; } else { pbafh = (PBITMAPARRAYFILEHEADER)abm[i].pb; pbmi = (PBITMAPINFO)&pbafh->bfh.bmp; } /* Transfer the RGB info to the colour */ /* holders */ memcpy(&lClrBack, &pbmi->argbColor[0], 3); memcpy(&lClrFore, &pbmi->argbColor[1], 3); } /* Draw the 2-colour bitmap using the */ /* provided colours from the bitmap */ WinDrawBitmap(hPS, abm[i].hbm, (PRECTL)NULL, (PPOINTL)(PVOID)&abm[i].rclDest, lClrFore, lClrBack, DBM_NORMAL); } else /* Draw the bitmap from the array */ WinDrawBitmap(hPS, abm[i].hbm, (PRECTL)NULL, (PPOINTL)(PVOID)&abm[i].rclDest, RGB_WHITE, RGB_BLACK, DBM_NORMAL); /* Draw the 3-D frame around the image */ GpiSetColor(hPS, RGBCLR_SHADOW); GpiMove(hPS, &abm[i].aptlArea[7]); GpiPolyLine(hPS, 2L, &abm[i].aptlArea[4]); GpiSetColor(hPS, RGB_WHITE); GpiPolyLine(hPS, 2L, &abm[i].aptlArea[6]); GpiSetColor(hPS, RGB_BLACK); GpiMove(hPS, &abm[i].aptlArea[3]); GpiPolyLine(hPS, 2L, &abm[i].aptlArea[0]); GpiSetColor(hPS, RGBCLR_PALEGRAY); GpiPolyLine(hPS, 2L, &abm[i].aptlArea[2]); } } else { if ( (rclROP.xRight < cxWindow) || (rclROP.yTop < cyWindow) ) WinFillRect(hPS, &rcl, RGBCLR_PALEGRAY); ptl.x = ptl.y = 0L; WinDrawBitmap(hPS, hbmROP, &rclROP, &ptl, 0L, 0L, DBM_NORMAL); } WinEndPaint(hPS); break; /************************************************************************/ /* Window being destroyed, perform clean-up operations */ /************************************************************************/ case WM_DESTROY : for ( i = 0; i < cBitmaps; i++ ) GpiDeleteBitmap(abm[i].hbm); if ( hbmROP ) GpiDeleteBitmap(hbmROP); if ( pb ) free(pb); break; /* Default message processing */ default : return(WinDefWindowProc(hWnd, msg, mp1, mp2)); } return(0L); }
/************************************************************************** * * 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 */
MRESULT EXPENTRY DriverWndProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2) { CHAR szFile[CCHMAXPATH]; /* File HOlder */ FILEFINDBUF3 findbuf; /* File Find Buffer */ FONTMETRICS fm; /* Font Metrics Structure */ HDIR hDir = (HDIR)HDIR_CREATE; /* Directory Handle */ HPS hPS; /* Presentation Space Handle */ HWND hwndListBox; /* List Box Window Handle */ LISTBOXCDATA lbwcd; /* List Box Window Control Data */ POWNERITEM poi; /* Owner Item */ RECTL rcl; /* Client Window Rectangle */ ULONG ulFileCnt = 1UL; /* File Counter Holder */ register INT i, k, n; /* Loop Counter */ switch ( msg ) { /* Perform window initialization */ case WM_CREATE : hptrArrow = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE); WinSetPointer(HWND_DESKTOP, hptrWait = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE)); memset(&lbwcd, 0, sizeof(LISTBOXCDATA)); lbwcd.cb = sizeof(LISTBOXCDATA); lbwcd.ulVersion = LBV_110; lbwcd.vdata.lbcd1_1.flExtStyles = LSXS_CHECKBOX | LSXS_EDITABLE; hwndList1 = WinCreateWindow(hWnd, "ListBoxWindow", "", LS_HORZSCROLL | LS_EXTENDEDSEL | WS_VISIBLE, 10L, 10L, 100L, 175L, hWnd, HWND_TOP, 1024UL, (PVOID)&lbwcd, (PVOID)NULL); hwndListx = WinCreateWindow(hWnd, "ListBoxWindow", "", LS_HORZSCROLL | LS_EXTENDEDSEL | WS_VISIBLE, 125L, 10L, 100L, 175L, hWnd, HWND_TOP, 1024UL, (PVOID)&lbwcd, (PVOID)NULL); hwndList2 = WinCreateWindow(hWnd, "ListBoxWindow", "", WS_VISIBLE, 10L, 190L, 250L, 200L, hWnd, HWND_TOP, 1025UL, (PVOID)&lbwcd, (PVOID)NULL); WinSendMsg(hwndList1, LMXM_SETSOUNDEVENT, MPFROMLONG(LSND_SINGLECLICK), MPFROMP("ahooga.wav")); WinSendMsg(hwndListx, LMXM_SETSOUNDEVENT, MPFROMLONG(LSND_DOUBLECLICK), MPFROMP("flush.wav")); hwndListA = WinCreateWindow(hWnd, WC_LISTBOX, "", LS_OWNERDRAW | LS_HORZSCROLL | LS_MULTIPLESEL | WS_VISIBLE, 275L, 10L, 100L, 175L, hWnd, HWND_TOP, 1026UL, (PVOID)NULL, (PVOID)NULL); /* Sub-class the default window procedure with */ /* new one which will handle specific messages */ /* allowing better control over the sizing frame */ hwndListB = WinCreateWindow(hWnd, WC_LISTBOX, "", WS_VISIBLE | LS_EXTENDEDSEL, 275L, 190L, 250L, 200L, hWnd, HWND_TOP, 1027UL, (PVOID)NULL, (PVOID)NULL); for ( i = 0; i < 10; i++ ) { sprintf(szFile, "Item %04d Item %04d Item %04d", i, i, i); WinSendMsg(hwndListx, LM_INSERTITEM, MPFROMLONG(LIT_END), MPFROMP(szFile)); } n = (INT)WinSendMsg(hwndList2, LMX_CALCLINECOUNT, MPFROMLONG(175L), 0L); k = 0; WinSendMsg(hwndList2, LM_SETITEMHEIGHT, MPFROMLONG(36L), 0L); if ( !DosFindFirst("*.*", &hDir, FILE_NORMAL, (PVOID)&findbuf, sizeof(FILEFINDBUF3), &ulFileCnt, FIL_STANDARD) ) { do { WinSendMsg(hwndList2, LM_INSERTITEM, MPFROMLONG(LIT_SORTDESCENDING), MPFROMP(findbuf.achName)); WinSendMsg(hwndList1, LM_INSERTITEM, MPFROMLONG(LIT_SORTASCENDING), MPFROMP(findbuf.achName)); if ( ++k > n ) WinSendMsg(hwndList2, LM_SETTOPINDEX, MPFROMLONG(k - n), 0L); WinSendMsg(hwndListB, LM_INSERTITEM, MPFROMLONG(LIT_SORTDESCENDING), MPFROMP(findbuf.achName)); WinSendMsg(hwndListA, LM_INSERTITEM, MPFROMLONG(LIT_SORTASCENDING), MPFROMP(findbuf.achName)); } while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) ); DosFindClose(hDir); } break; case WM_BUTTON1DOWN : WinEnableWindowUpdate(hwndListA, FALSE); WinEnableWindowUpdate(hwndList1, FALSE); WinSendMsg(hwndListA, LM_DELETEALL, 0L, 0L); WinSendMsg(hwndList1, LM_DELETEALL, 0L, 0L); i = 0; if ( !DosFindFirst("*.*", &hDir, FILE_NORMAL, (PVOID)&findbuf, sizeof(FILEFINDBUF3), &ulFileCnt, FIL_STANDARD) ) { do { WinSendMsg(hwndListA, LM_INSERTITEM, MPFROMLONG(LIT_SORTASCENDING), MPFROMP(findbuf.achName)); WinSendMsg(hwndList1, LM_INSERTITEM, MPFROMLONG(LIT_SORTASCENDING), MPFROMP(findbuf.achName)); ++i; } while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) ); DosFindClose(hDir); } WinShowWindow(hwndListA, TRUE); WinShowWindow(hwndList1, TRUE); while ( i ) { if ( i % 2 ) { WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(TRUE)); WinSendMsg(hwndList1, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(TRUE)); } --i; } break; case WM_CONTROL : switch ( SHORT2FROMMP(mp1) ) { /* Process double click on a List Box */ case LN_SELECT : switch ( SHORT1FROMMP(mp1) ) { case 1024UL : /* WinAlarm(HWND_DESKTOP, WA_NOTE); */ break; case 1027UL : /* WinAlarm(HWND_DESKTOP, WA_ERROR); */ break; } break; } break; case WM_MEASUREITEM : GpiQueryFontMetrics(hPS = WinGetPS(hWnd), sizeof(FONTMETRICS), &fm); WinReleasePS(hPS); return(MRFROMLONG(fm.lMaxBaselineExt)); /* Draw a list box item */ case WM_DRAWITEM : if ( SHORT1FROMMP(mp1) == 1024 ) hwndListBox = hwndList1; else if ( SHORT1FROMMP(mp1) == 1026 ) hwndListBox = hwndListA; /* Point to Owner Item information */ poi = (POWNERITEM)mp2; GpiCreateLogColorTable(poi->hps, 0L, LCOLF_RGB, 0L, 0L, (PLONG)NULL); i = (INT)LONGFROMMR(WinSendMsg(hwndListBox, LM_QUERYITEMTEXTLENGTH, MPFROMLONG(poi->idItem), 0L)); i = (INT)LONGFROMMR(WinSendMsg(hwndListBox, LM_QUERYITEMTEXT, MPFROM2SHORT(poi->idItem, CCHMAXPATH), MPFROMP(szFile))); /* Check to see if item to be drawn or */ /* highlighted */ if ( poi->fsState != poi->fsStateOld ) { WinFillRect(poi->hps, &poi->rclItem, RGBCLR_DIALOGBACKGROUND); if ( poi->fsState ) WinDrawText(poi->hps, -1L, szFile, &poi->rclItem, RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER | DT_ERASERECT); /* Set item highlighting by inverting the items */ /* rectangle colour */ WinInvertRect(poi->hps, &poi->rclItem); if ( !poi->fsState ) WinDrawText(poi->hps, -1L, szFile, &poi->rclItem, RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER | DT_ERASERECT); poi->fsState = poi->fsStateOld = 0; } else { /* Item needs to be drawn, get item rectangle */ /* item position */ WinFillRect(poi->hps, &poi->rclItem, RGBCLR_DIALOGBACKGROUND); WinDrawText(poi->hps, -1L, szFile, &poi->rclItem, RGB_BLACK, RGBCLR_DIALOGBACKGROUND, DT_LEFT | DT_VCENTER | DT_ERASERECT); } return(MRFROMLONG(TRUE)); case WM_BUTTON1DBLCLK : i = 0; if ( !DosFindFirst("*.*", &hDir, FILE_NORMAL, (PVOID)&findbuf, sizeof(FILEFINDBUF3), &ulFileCnt, FIL_STANDARD) ) { do { ++i; } while ( !DosFindNext(hDir, &findbuf, sizeof(FILEFINDBUF3), &ulFileCnt) ); DosFindClose(hDir); } while ( i ) { if ( i % 2 ) { WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(FALSE)); WinSendMsg(hwndList1, LM_SELECTITEM, MPFROMLONG(i - 1), MPFROMLONG(FALSE)); } --i; } break; case WM_BUTTON2DOWN : for ( i = 0; i < 5; i++ ) WinSendMsg(hwndListx, LM_DELETEITEM, MPFROMSHORT(2), 0L); #if 0 WinSendMsg(hwndListA, LM_SELECTITEM, MPFROMLONG(LIT_NONE), MPFROMLONG(TRUE)); i = LIT_FIRST; while ( (i = (INT)LONGFROMMR(WinSendMsg(hwndList1, LM_QUERYSELECTION, MPFROMLONG(i), 0L))) != LIT_NONE ) WinSendMsg(hwndList1, LM_SELECTITEM, MPFROMLONG(i), MPFROMLONG(FALSE)); #endif break; /* Erase background */ case WM_ERASEBACKGROUND : WinQueryWindowRect(hWnd, &rcl); WinFillRect((HPS)mp1, &rcl, SYSCLR_DIALOGBACKGROUND); break; /* Paint the main client window */ case WM_PAINT : WinSetPointer(HWND_DESKTOP, hptrWait); WinFillRect(hPS = WinBeginPaint(hWnd, (HPS)NULL, &rcl), &rcl, SYSCLR_DIALOGBACKGROUND); WinEndPaint(hPS); WinSetPointer(HWND_DESKTOP, hptrArrow); break; /* Close Down */ case WM_CLOSE : WinPostMsg(hWnd, WM_QUIT, 0L, 0L); break; case WM_DESTROY : WinDestroyPointer(hptrArrow); WinDestroyPointer(hptrWait); break; /* Default message processing */ default: return(WinDefWindowProc(hWnd, msg, mp1, mp2)); } return(0L); }
VOID DrawDigitalTime(HWND hwnd) { RECTL rcl; RECTL rclChar; RECTL rclCharOld; RECTL rclTime; RECTL rclAmPm; RECTL rclDate; HPS hpsWnd; SIZEF sizef; USHORT usi; ULONG ulCharWidth,ulCharModulu; char achTime[9]; char achFinalDate[9]; time_t tTime; struct tm *pLocalTime; WinQueryWindowRect (hwnd, &rcl); hpsWnd = WinGetPS (hwnd); memset(achTime,0,sizeof(achTime) ); memset(achFinalDate,0,sizeof(achFinalDate) ); GpiCreateLogColorTable (hpsWnd, LCOL_RESET, LCOLF_RGB, 0, 0, (PLONG) NULL); /* *if black hands and black background *selected force the background to *blue */ if( !cp.clrMinuteHand && !cp.clrBackground ) { cp.clrBackground = RGB_BLUE; } switch (cp.usDispMode & (DM_TIME | DM_DATE)) { case DM_DATE: rclDate = rcl; break; case DM_TIME | DM_DATE: if (!fIconic) { rclTime = rclDate = rcl; rclTime.yBottom = rclDate.yTop = rcl.yTop / 2; break; } /*else fall through*/ case DM_TIME: rclTime = rcl; break; } if (cp.usDispMode & DM_TIME) { rclAmPm = rclTime; time(&tTime); pLocalTime = localtime(&tTime); if (bTwelveHourFormat) { strftime(achTime, sizeof(achTime), "%I %M %S", pLocalTime); } else { strftime(achTime, sizeof(achTime), "%H %M %S", pLocalTime); } /*insert country time separator*/ achTime[2] = achTime[5] = szTimeSep[0]; achTime[8] = '\000'; /*Process 12 hours mode*/ if (bTwelveHourFormat) { if (fIconic) { rclTime.yBottom = rclAmPm.yTop = rclTime.yTop / 2; } else { rclTime.xRight = rcl.xRight * 8 / 11; rclAmPm.xLeft = rclTime.xRight; } strcpy(achAmPm,szAnteMeridian); if (pLocalTime->tm_hour >= 12) { strcpy(achAmPm,szPostMeridian); } } GpiSetCharMode(hpsWnd, CM_MODE3); if (fIconic) { sizef.cx = MAKEFIXED(LOUSHORT((rclTime.xRight - rclTime.xLeft) / 3), 0); sizef.cy = MAKEFIXED(LOUSHORT((rclTime.yTop - rclTime.yBottom) * 1400 / 1000), 0); } else { sizef.cx = MAKEFIXED(LOUSHORT((rclTime.xRight - rclTime.xLeft) / 6), 8000); sizef.cy = MAKEFIXED(LOUSHORT((rclTime.yTop - rclTime.yBottom) * 1000 / 1500), 0); } GpiSetCharBox(hpsWnd, &sizef); if (bTwelveHourFormat) { if( strcmp(achAmPm,achOldAmPm) ) { WinFillRect(hpsWnd, &rclAmPm, cp.clrBackground); WinDrawText(hpsWnd, sizeof(achAmPm) - 1, (PSZ)achAmPm, (PRECTL)&rclAmPm, cp.clrMinuteHand, cp.clrBackground, DT_CENTER | DT_VCENTER ); } } if (!fIconic) { WinDrawText(hpsWnd, sizeof(achTime) - 1 , (PSZ)achTime, (PRECTL)&rclTime, cp.clrMinuteHand, cp.clrBackground, DT_CENTER | DT_VCENTER | DT_QUERYEXTENT); ulCharWidth = (rclTime.xRight - rclTime.xLeft) / (sizeof(achTime) - 1 ); ulCharModulu = (rclTime.xRight - rclTime.xLeft) % (sizeof(achTime) - 1 ); rclCharOld.xRight = rclTime.xLeft; rclChar.yTop = rclTime.yTop; rclChar.yBottom = rclTime.yBottom; for (usi = 0; usi < (sizeof(achTime)); usi++) { rclChar.xLeft = rclCharOld.xRight + (ULONG)1; rclChar.xRight = rclChar.xLeft + ulCharWidth + ((ulCharModulu > 0L) ? 1L : 0L); if (ulCharModulu) ulCharModulu--; if (achTime[usi] == szTimeSep[0]) { rclChar.xRight -= 3; } else { rclChar.xRight += 1; } rclCharOld = rclChar; if (achTime[usi] != achOldTime[usi]) { WinFillRect (hpsWnd, &rclChar, cp.clrBackground); if (!((usi == 0) && (achTime[0] == '0') && (bTwelveHourFormat))) WinDrawText (hpsWnd, 1, (PSZ)&achTime[usi], &rclChar, cp.clrMinuteHand, cp.clrBackground, DT_CENTER | DT_VCENTER); } } } else { /*Iconic. just draw if minute changed*/ if (strncmp(achTime,achOldTime,5)) { WinFillRect(hpsWnd,&rclTime,cp.clrBackground); WinDrawText(hpsWnd, sizeof(achTime) - 4 , (PSZ)achTime, (PRECTL)&rclTime, cp.clrMinuteHand, cp.clrBackground, DT_CENTER | DT_VCENTER); } } } if ((!(cp.usDispMode & DM_TIME)) || ((cp.usDispMode & DM_DATE) && (!fIconic))) { GetArrangedDate(achFinalDate); if (strncmp(achFinalDate, achOldDate, sizeof(achFinalDate) - fIconic ? 4 : 1)) { WinFillRect (hpsWnd, &rclDate, cp.clrBackground); GpiSetCharMode (hpsWnd, CM_MODE3); sizef.cx = MAKEFIXED(LOUSHORT( (rclDate.xRight - rclDate.xLeft) / 5), 0); sizef.cy = MAKEFIXED(LOUSHORT( (rclDate.yTop - rclDate.yBottom) * 1000 / 1500), 0); GpiSetCharBox(hpsWnd, &sizef); WinDrawText(hpsWnd, (sizeof(achFinalDate) - (fIconic ? 4 : 1) ), (PSZ)achFinalDate,(PRECTL)&rclDate, (LONG)cp.clrMinuteHand, (LONG)cp.clrBackground, (ULONG )(DT_CENTER | DT_VCENTER ) ); } } WinReleasePS(hpsWnd); strncpy(achOldTime,achTime,sizeof(achOldTime)); strncpy(achOldAmPm,achAmPm,sizeof(achOldAmPm)); strncpy(achOldDate,achFinalDate,sizeof(achOldDate)); }
// Поток приложения вызывает WindowProc всякий раз, когда для окна есть сообщение. // Window - окно, Message - сообщение, *_parameter - данные, которые передаются вместе с сообщением. MRESULT EXPENTRY Installer_ClientWindowProc( HWND Window, ULONG Message, MPARAM First_parameter, MPARAM Second_parameter ) { switch( Message ) { // Выполняем действия при создании окна. case WM_CREATE: { WinPostMsg( Window, MY_CREATE, 0, 0 ); } return 0; case MY_CREATE: { // Задаем заголовок окна приложения. if( Installer.Code_page == RUSSIAN ) strcpy( Installer.Frame_window_title, StrConst_RU_Title ); else strcpy( Installer.Frame_window_title, StrConst_EN_Title ); WinSetWindowText( Installer.Frame_window, Installer.Frame_window_title ); // Устанавливаем картинку в левом верхнем углу окна. WinSendMsg( Installer.Frame_window, WM_SETICON, (MPARAM) WinLoadPointer( HWND_DESKTOP, NULLHANDLE, 1 ), 0 ); // Задаем расположение окна. { INT X_Screen = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ); INT Y_Screen = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ); INT Window_width = X_Screen / 3; if( X_Screen < 1024 ) Window_width *= 1.25; INT Window_height = Y_Screen / 3; if( X_Screen < 1024 ) Window_height *= 1.25; INT Window_position_X = ( X_Screen - Window_width ) / 2; INT Window_position_Y = ( Y_Screen - Window_height ) / 2 + ( Y_Screen - Window_height ) / 4 / 2; WinSetWindowPos( Installer.Frame_window, HWND_TOP, Window_position_X, Window_position_Y, Window_width, Window_height, SWP_ZORDER | SWP_MOVE | SWP_SIZE | SWP_NOADJUST ); WinSetActiveWindow( HWND_DESKTOP, Installer.Frame_window ); } // Добавляем его в список окон. { SWCNTRL Task; HSWITCH Switch_handle = NULLHANDLE; bzero( &Task, sizeof( SWCNTRL ) ); Task.hwnd = Installer.Frame_window; Task.hwndIcon = (HPOINTER) WinSendMsg( Installer.Frame_window, WM_QUERYICON, 0, 0 ); WinQueryWindowProcess( Installer.Frame_window, &Task.idProcess, NULL ); strcpy( Task.szSwtitle, Installer.Frame_window_title ); Task.uchVisibility = SWL_VISIBLE; Task.fbJump = SWL_JUMPABLE; Switch_handle = WinCreateSwitchEntry( Installer.Application, &Task ); WinChangeSwitchEntry( Switch_handle, &Task ); } // Создаем поля ввода в окне рабочей области. ClientWindow_CreatePage( Installer.Client_window ); } return 0; // Передвигаем поля ввода. case MY_APPLY_LAYOUT: { LitApplyLayout( &Client_Window.Layout ); } return 0; // Включаем и отключаем поля ввода. case MY_ENABLE_BUTTONS: { ULONG Action = (ULONG) First_parameter; WinEnableWindow( WinWindowFromID( WinWindowFromID( Window, Client_Window.Settings.Buttons_brick_ID ), Client_Window.Settings.Install_button_ID ), Action ); WinEnableWindow( WinWindowFromID( WinWindowFromID( Window, Client_Window.Settings.Buttons_brick_ID ), Client_Window.Settings.Remove_button_ID ), Action ); WinEnableWindow( WinWindowFromID( WinWindowFromID( Window, Client_Window.Settings.Buttons_brick_ID ), Client_Window.Settings.Cancel_button_ID ), Action ); if( !Action ) WinSendMsg( WinWindowFromID( Installer.Frame_window, FID_SYSMENU ), MM_SETITEMATTR, MPFROM2SHORT( SC_CLOSE, INCLUDE_SUBMENUS ), MPFROM2SHORT( MIA_DISABLED, MIA_DISABLED ) ); else WinSendMsg( WinWindowFromID( Installer.Frame_window, FID_SYSMENU ), MM_SETITEMATTR, MPFROM2SHORT( SC_CLOSE, INCLUDE_SUBMENUS ), MPFROM2SHORT( MIA_DISABLED, 0 ) ); } return 0; // Обрабатываем нажатия на кнопки. case WM_COMMAND: { ULONG WM_Control_Button_ID = SHORT1FROMMP( First_parameter ); if( WM_Control_Button_ID == Client_Window.Settings.Install_button_ID ) { StartInstallerThread( NIA_INSTALL ); } if( WM_Control_Button_ID == Client_Window.Settings.Remove_button_ID ) { StartInstallerThread( NIA_REMOVE ); } if( WM_Control_Button_ID == Client_Window.Settings.Cancel_button_ID ) { WinPostMsg( Installer.Frame_window, WM_SYSCOMMAND, (MPARAM) SC_CLOSE, 0 ); } } return 0; // Закрашиваем пространство окна. case WM_PAINT: { RECT Rectangle = {0}; HPS Presentation_space = WinBeginPaint( Window, 0, &Rectangle ); if( Presentation_space ) { LONG Color_table[ 256 ]; bzero( Color_table, sizeof( Color_table ) ); GpiQueryLogColorTable( Presentation_space, 0, 0, 256, Color_table ); LONG Color_index = ( 256 - 1 ); WinQueryPresParam( Window, PP_BACKGROUNDCOLOR, 0, NULL, sizeof( Color_table[ Color_index ] ), &Color_table[ Color_index ], QPF_NOINHERIT ); GpiCreateLogColorTable( Presentation_space, 0, LCOLF_CONSECRGB, 0, 256, Color_table ); WinFillRect( Presentation_space, &Rectangle, Color_index ); WinEndPaint( Presentation_space ); } } return 0; // Сообщаем окну рамки, что содержимое окна рабочей области закрашивать не следует. case WM_ERASEBACKGROUND: return (MPARAM) 0; // Выполняем действия при нажатии на кнопку закрытия окна. case WM_CLOSE: { // Убираем окно приложения из списка окон. WinRemoveSwitchEntry( WinQuerySwitchHandle( Installer.Frame_window, 0 ) ); // Передаем сообщение обработчику. WinDefWindowProc( Window, Message, First_parameter, Second_parameter ); } return 0; } // Возврат. return WinDefWindowProc( Window, Message, First_parameter, Second_parameter ); }