HBITMAP PSBMBLTToSize(HAB hab, HPS hps, HBITMAP hbm, float fScale, ULONG ulOptions) { BITMAPINFOHEADER2 bif2Before; BITMAPINFOHEADER2 bif2After; SIZEL slAfter; ULONG ulScreenWidth; ULONG ulScreenHeight; HDC hdcAfter; HPS hpsAfter; HBITMAP hbmAfter; POINTL aptl[4]; float fAspect; HBITMAP hbmOld; if ((hbmOld = GpiSetBitmap(hps, hbm)) == HBM_ERROR) { return (NULLHANDLE); } memset(&bif2Before, 0, sizeof(bif2Before)); // get current info bif2Before.cbFix = sizeof(bif2Before); if (GpiQueryBitmapInfoHeader(hbm, &bif2Before) != TRUE) { GpiSetBitmap(hps, hbmOld); return (NULLHANDLE); } ulScreenWidth = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN); // screen width ulScreenHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN); // screen height fAspect = (bif2Before.cx * 1.0) / (bif2Before.cy * 1.0); // calculate aspect ratio if (ulOptions & SCALE_LARGEST) { if (bif2Before.cx > bif2Before.cy) { slAfter.cx = (LONG) (ulScreenWidth * fScale); slAfter.cy = (LONG) (slAfter.cx / fAspect); } else { slAfter.cy = (LONG) (ulScreenHeight * fScale); slAfter.cx = (LONG) (slAfter.cy * fAspect); } } else if (ulOptions & SCALE_SMALLEST) { if (bif2Before.cx < bif2Before.cy) { slAfter.cx = (LONG) (ulScreenWidth * fScale); slAfter.cy = (LONG) (slAfter.cx / fAspect); } else { slAfter.cy = (LONG) (ulScreenHeight * fScale); slAfter.cx = (LONG) (slAfter.cy * fAspect); } } else if (ulOptions & SCALE_HORIZONTAL) { slAfter.cx = (LONG) (ulScreenWidth * fScale); if (ulOptions & SCALE_VERTICAL) // basically, screw the aspect { slAfter.cy = (LONG) (ulScreenHeight * fScale); } else { slAfter.cy = (LONG) (slAfter.cx / fAspect); } } else if (ulOptions & SCALE_VERTICAL) { slAfter.cy = (LONG) (ulScreenHeight * fScale); slAfter.cx = (LONG) (slAfter.cy * fAspect); } else { GpiSetBitmap(hps, hbmOld); return (NULLHANDLE); } if ((hdcAfter = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, NULLHANDLE)) == NULLHANDLE) { GpiSetBitmap(hps, hbmOld); return (NULLHANDLE); } if ((hpsAfter = GpiCreatePS(hab, hdcAfter, &slAfter, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC)) == NULLHANDLE) { DevCloseDC(hdcAfter); GpiSetBitmap(hps, hbmOld); return (NULLHANDLE); } memset(&bif2After, 0, sizeof(bif2After)); bif2After.cbFix = sizeof(bif2After); bif2After.cx = slAfter.cx; bif2After.cy = slAfter.cy; bif2After.cBitCount = bif2Before.cBitCount; bif2After.cPlanes = bif2Before.cPlanes; if ((hbmAfter = GpiCreateBitmap(hpsAfter, // create bitmap (PBITMAPINFOHEADER2) & (bif2After), (ULONG) FALSE, NULL, NULL)) == NULLHANDLE) { GpiDestroyPS(hpsAfter); DevCloseDC(hdcAfter); GpiSetBitmap(hps, hbmOld); return (NULLHANDLE); } if (GpiSetBitmap(hpsAfter, hbmAfter) == HBM_ERROR) { GpiDeleteBitmap(hbmAfter); GpiDestroyPS(hpsAfter); DevCloseDC(hdcAfter); GpiSetBitmap(hps, hbmOld); return (NULLHANDLE); } aptl[0].x = 0; aptl[0].y = 0; aptl[1].x = slAfter.cx; aptl[1].y = slAfter.cy; aptl[2].x = 0; aptl[2].y = 0; aptl[3].x = bif2Before.cx; aptl[3].y = bif2Before.cy; if (GpiBitBlt(hpsAfter, hps, 4L, aptl, ROP_SRCCOPY, BBO_IGNORE) == GPI_ERROR) { GpiSetBitmap(hpsAfter, NULLHANDLE); GpiDeleteBitmap(hbmAfter); GpiDestroyPS(hpsAfter); DevCloseDC(hdcAfter); GpiSetBitmap(hps, hbmOld); return (NULLHANDLE); } GpiSetBitmapDimension(hbmAfter, &slAfter); GpiSetBitmap(hpsAfter, NULLHANDLE); GpiDestroyPS(hpsAfter); DevCloseDC(hdcAfter); GpiSetBitmap(hps, hbmOld); return (hbmAfter); }
MRESULT EXPENTRY FlyWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { SIZEL sizl; int rc, key, mou_r, mou_c, mou_ev, new_vio_rows, new_vio_cols; int deltaX, deltaY, pix_rows, pix_cols, new_x0, new_y0; static int mou_c1=-1, mou_r1=-1; struct _item *L; HWND hwndMenu; SWP swp; QMSG *qmsg; USHORT vk, fl; switch (msg) { case WM_CREATE: hdc = WinOpenWindowDC (hwnd); sizl.cx = sizl.cy = 0; grab_video (); hps = GpiCreatePS (hab, hdc, &sizl, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC); rc = VioCreatePS (&hvps, 80, 25, 0, 1, 0); VioGetDeviceCellSize (&cyChar, &cxChar, hvps); set_cursor (0); VioSetCurType (pci, hvps); release_video (); DosPostEventSem (hev_VideoReady); return 0; case WM_MOUSEMOVE: mou_ev = MOUEV_MOVE; goto MOUSE; case WM_BUTTON1CLICK: mou_ev = MOUEV_B1SC; goto MOUSE; case WM_BUTTON1DBLCLK: mou_ev = MOUEV_B1DC; goto MOUSE; case WM_BUTTON1MOTIONSTART: mou_ev = MOUEV_B1MS; goto MOUSE; case WM_BUTTON1MOTIONEND: mou_ev = MOUEV_B1ME; goto MOUSE; case WM_BUTTON1DOWN: mou_ev = MOUEV_B1DN; goto MOUSE; case WM_BUTTON1UP: mou_ev = MOUEV_B1UP; goto MOUSE; case WM_BUTTON2CLICK: mou_ev = MOUEV_B2SC; goto MOUSE; case WM_BUTTON2DBLCLK: mou_ev = MOUEV_B2DC; goto MOUSE; case WM_BUTTON2MOTIONSTART: mou_ev = MOUEV_B2MS; goto MOUSE; case WM_BUTTON2MOTIONEND: mou_ev = MOUEV_B2ME; goto MOUSE; case WM_BUTTON2DOWN: mou_ev = MOUEV_B2DN; goto MOUSE; case WM_BUTTON2UP: mou_ev = MOUEV_B2UP; goto MOUSE; case WM_BUTTON3DBLCLK: mou_ev = MOUEV_B3DC; goto MOUSE; case WM_BUTTON3CLICK: mou_ev = MOUEV_B3SC; goto MOUSE; case WM_BUTTON3MOTIONSTART: mou_ev = MOUEV_B3MS; goto MOUSE; case WM_BUTTON3MOTIONEND: mou_ev = MOUEV_B3ME; goto MOUSE; case WM_BUTTON3DOWN: mou_ev = MOUEV_B3DN; goto MOUSE; case WM_BUTTON3UP: mou_ev = MOUEV_B3UP; goto MOUSE; MOUSE: if (fl_opt.mouse_active != TRUE) break; mou_r = vio_rows - 1 - (SHORT2FROMMP (mp1)/cyChar); mou_c = SHORT1FROMMP (mp1)/cxChar; if (mou_r < 0 || mou_c < 0) break; // prevent MOUEV_MOVE message with same coordinates if (mou_ev == MOUEV_MOVE && mou_r == mou_r1 && mou_c == mou_c1) break; mou_r1 = mou_r, mou_c1 = mou_c; que_put (FMSG_BASE_MOUSE + FMSG_BASE_MOUSE_EVTYPE*mou_ev + FMSG_BASE_MOUSE_X*mou_c + FMSG_BASE_MOUSE_Y*mou_r); break; case WM_PAINT: WinBeginPaint (hwnd, hps, NULL); grab_video (); VioShowBuf (0, 2 * vio_rows * vio_cols, hvps); release_video (); WinEndPaint (hps); return 0; case WM_CHAR: if (SHORT1FROMMP (mp1) & KC_KEYUP) return 0; if (SHORT2FROMMP (mp2) == VK_SHIFT || SHORT2FROMMP (mp2) == VK_CTRL || SHORT2FROMMP (mp2) == VK_ALT) return 0; key = pmkey2asvkey (SHORT2FROMMP(mp2), CHAR4FROMMP(mp1), SHORT1FROMMP(mp2), CHAR3FROMMP(mp1), SHORT1FROMMP(mp1)); if (key != -1) que_put (key); return 0; case WM_TRANSLATEACCEL: qmsg = (QMSG *)mp1; vk = SHORT2FROMMP (qmsg->mp2); fl = SHORT1FROMMP (qmsg->mp1) & (KC_ALT | KC_SHIFT | KC_CTRL | KC_KEYUP); if (vk == VK_MENU || vk == VK_F1) return FALSE; //if ((fl & KC_ALT) && vk >= VK_F1 && vk <= VK_F24) return FALSE; break; case WM_CLOSE: que_put (FMSG_BASE_SYSTEM + FMSG_BASE_SYSTEM_TYPE*SYSTEM_QUIT); return 0; case WM_SIZE: if (cxChar != 0 && cyChar != 0) { pix_rows = SHORT2FROMMP (mp2); pix_cols = SHORT1FROMMP (mp2); new_vio_rows = pix_rows / cyChar; new_vio_cols = pix_cols / cxChar; if (new_vio_rows != vio_rows || new_vio_cols != vio_cols) { grab_video (); VioAssociate (0, hvps); VioDestroyPS (hvps); rc = VioCreatePS (&hvps, new_vio_rows, new_vio_cols, 0, 1, 0); VioSetDeviceCellSize (cyChar, cxChar, hvps); VioGetDeviceCellSize (&cyChar, &cxChar, hvps); rc = VioAssociate (hdc, hvps); VioSetCurType (pci, hvps); release_video (); que_put (FMSG_BASE_SYSTEM + FMSG_BASE_SYSTEM_TYPE*SYSTEM_RESIZE + FMSG_BASE_SYSTEM_INT2*new_vio_rows + FMSG_BASE_SYSTEM_INT1*new_vio_cols); } deltaX = new_vio_cols*cxChar - pix_cols; deltaY = new_vio_rows*cyChar - pix_rows; //if (deltaX != 0 || deltaY != 0) if (abs(deltaX) > MAX_DELTA || abs(deltaY) > MAX_DELTA) { WinPostMsg (hwndFrame, WM_FLY_RESIZE, MPFROM2SHORT (SHORTBASE+deltaX, SHORTBASE+deltaY), NULL); } } WinDefAVioWindowProc (hwnd, msg, (ULONG)mp1, (ULONG)mp2); return 0; case WM_COMMAND: que_put (FMSG_BASE_MENU + LOUSHORT (mp1)); break; case WM_FLY_LOADMENU: L = PVOIDFROMMP (mp1); // obtain handle for window menu hwndMenu = WinWindowFromID (WinQueryWindow (hwnd, QW_PARENT), FID_MENU); fill_submenu (hwndMenu, L); fly_active_menu = L; break; case WM_FLY_UNLOADMENU: L = PVOIDFROMMP (mp1); // obtain handle for window menu hwndMenu = WinWindowFromID (WinQueryWindow (hwnd, QW_PARENT), FID_MENU); empty_submenu (hwndMenu, L); fly_active_menu = NULL; break; case WM_FLY_RESIZE: deltaX = SHORT1FROMMP (mp1) - SHORTBASE; deltaY = SHORT2FROMMP (mp1) - SHORTBASE; rc = WinQueryWindowPos (hwndFrame, &swp); rc = WinSetWindowPos (hwndFrame, 0, swp.x, swp.y-deltaY, swp.cx+deltaX, swp.cy+deltaY, SWP_SIZE|SWP_MOVE); break; case WM_FLY_MOVE_CANVAS: new_x0 = SHORT1FROMMP (mp1) - SHORTBASE; new_y0 = SHORT2FROMMP (mp1) - SHORTBASE; rc = WinQueryWindowPos (hwndFrame, &swp); WinSetWindowPos (hwndFrame, 0, new_x0, new_y0-swp.cy, 0, 0, SWP_MOVE); //DosPostEventSem (hev_VideoReady); break; case WM_FLY_MENU_CHSTATUS: hwndMenu = WinWindowFromID (WinQueryWindow (hwnd, QW_PARENT), FID_MENU); WinEnableMenuItem (hwndMenu, SHORT1FROMMP(mp1), SHORT2FROMMP(mp1)); item_status_change++; break; case WM_FLY_MENU_CHSTATE: hwndMenu = WinWindowFromID (WinQueryWindow (hwnd, QW_PARENT), FID_MENU); WinSendMsg (hwndMenu, MM_SETITEMATTR, MPFROM2SHORT (SHORT1FROMMP(mp1), TRUE), MPFROM2SHORT (MIA_CHECKED, SHORT2FROMMP(mp1) ? MIA_CHECKED : 0)); break; case WM_DESTROY: grab_video (); VioAssociate (0, hvps); VioDestroyPS (hvps); GpiDestroyPS (hps); release_video (); que_put (FMSG_BASE_SYSTEM + FMSG_BASE_SYSTEM_TYPE*SYSTEM_DIE); return 0; } return WinDefWindowProc (hwnd, msg, mp1, mp2); }
HBITMAP CreateThumbnailBmp( CAMRecPtr pcr, char * pBuf) { HBITMAP hBmp = 0; uint32_t ctr; HDC hdc = 0; HPS hps = 0; char * pErr = 0; BITMAPINFOHEADER2 * pbmih = 0; RGB2 * pRGB; SIZEL sizl; CAMJThumb cjt; do { // decode the JPEG data from the camera memset( &cjt, 0, sizeof(cjt)); cjt.pSrc = pBuf; cjt.cbSrc = pcr->tnsize; ctr = JpgDecodeThumbnail( &cjt); if (ctr) { printf( "JpgDecodeThumbnail - rc= 0x%x\n", (int)ctr); break; } // allocate a BITMAPINFOHEADER2 / BITMAPINFO2 // suitable for 24-bit color or 8-bit grayscale ctr = sizeof(BITMAPINFOHEADER2); if (cjt.cbPix == 1) ctr += 256 * sizeof(RGB2); pbmih = (BITMAPINFOHEADER2*)malloc( ctr); memset( pbmih, 0, ctr); // if grayscale, create a default colormap if (cjt.cbPix == 1) for (ctr = 0, pRGB = (RGB2*)&pbmih[1]; ctr < 256; ctr++, pRGB++) { pRGB->bBlue = ctr; pRGB->bGreen = ctr; pRGB->bRed = ctr; } // init the BMIH pbmih->cbFix = sizeof(BITMAPINFOHEADER2); pbmih->cx = cjt.cxDst; pbmih->cy = cjt.cyDst; pbmih->cPlanes = 1; pbmih->cBitCount = cjt.cbPix * 8; pbmih->ulCompression = BCA_UNCOMP; pbmih->cbImage = cjt.cbDst; // create a memory DC hdc = DevOpenDC( 0, OD_MEMORY, "*", 0L, 0, 0); if (!hdc) { pErr = "DevOpenDC"; break; } // create a square PS using the longer side so we can // reuse the PS if we have to rotate the bitmap sizl.cx = ((pbmih->cx >= pbmih->cy) ? pbmih->cx : pbmih->cy); sizl.cy = sizl.cx; hps = GpiCreatePS( 0, hdc, &sizl, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC); if (!hps) { pErr = "GpiCreatePS"; break; } // create a bitmap from the data hBmp = GpiCreateBitmap( hps, pbmih, CBM_INIT, cjt.pDst, (BITMAPINFO2*)pbmih); if (!hBmp) { pErr = "GpiCreateBitmap"; break; } // if the bitmap should be rotated, replace the original one if (STAT_GETROT(pcr->status)) { HBITMAP hBmpRot = RotateBitmap( hps, hBmp, pbmih, STAT_GETROT(pcr->status)); if (hBmpRot) { GpiDeleteBitmap( hBmp); hBmp = hBmpRot; } } } while (0); if (pErr) printf( "CreateThumbnailBmp - %s failed\n", pErr); if (hps) { GpiSetBitmap( hps, 0); GpiDestroyPS( hps); } if (hdc) DevCloseDC( hdc); if (pbmih) free( pbmih); if (cjt.pDst) free( cjt.pDst); return (hBmp); }
VOID FAR PMfrThread (VOID) { int sub_rc; habThread = WinInitialize(0); WinGetLastError(habThread); /* get the memory DC */ cp.hdcMemory = DevOpenDC (habThread, OD_MEMORY, "*", 0L, NULL, NULL) ; /* this says that we don't have a PS yet; not one to destroy */ cp.hpsMemory = (HPS) NULL; /* let each sub-driver have a crack at it now */ PrintDriverInit(); CalcDriverInit(); /* Initialization here is done. Post main thread that we are going to work */ WinPostMsg(cp.hwnd, WM_THRD_POST, MPFROM2SHORT(SUB_INIT_DONE, 0), MPFROMP(NULL) ); for (;;) { /* wait for something to do */ DosSemWait (&cp.ulSemTrigger, SEM_INDEFINITE_WAIT) ; /* take an early exit for Shutdown */ if (cp.sSubAction == SUB_ACT_TERM) break; /* posted out of wait. do something */ switch(cp.sSubAction) { case SUB_ACT_CALC: sub_rc = CalcDriver(); break; case SUB_ACT_PRINT: sub_rc = PrintDriver(); break; case SUB_ACT_SAVE: sub_rc = SaveDriver(); break; case SUB_ACT_LOAD: sub_rc = LoadDriver(); break; default: sub_rc = 0x9999; /* let the main task figure it out */ break; } /* test here for shutdown also */ if (cp.sSubAction == SUB_ACT_TERM) break; /* not shutdown. */ /* indicate ready for the next cycle */ DosSemSet (&cp.ulSemTrigger) ; WinPostMsg (cp.hwnd, WM_THRD_POST, MPFROM2SHORT(sub_rc, 0) , MPFROMP(NULL) ) ; } /* shutdown has been triggered. release resources obtained by us. NOTE: Serialize using DosEnterCritSec so that the main thread is dormant until we get everything cleaned up and go away. The main thread will be re-dispatched following our final DosExit. */ DosEnterCritSec(); if (cp.hpsMemory != (HPS) 0) { /* protection from a failed WM_CREATE or IDM_GO */ GpiSetBitmap(cp.hpsMemory, (HBITMAP) NULL); GpiDestroyPS(cp.hpsMemory); GpiDeleteBitmap (cp.hbmMemory); } cp.hpsMemory = (HPS) 0; if ( cp.pixels != NULL) hfree(cp.pixels); cp.pixels = NULL; if (cp.hdcMemory != (HDC) 0) DevCloseDC (cp.hdcMemory); cp.hdcMemory = (HDC) 0; /* say good-bye to PM */ WinTerminate(habThread); /* flag we done */ DosSemClear ((HSEM) &cp.ulSemSubEnded); /* and go away */ DosExit(EXIT_THREAD, 0); }
MRESULT EXPENTRY miscMainWinProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { static HPS hpsMain; static ULONG lCodePage; static LONG lFontHeight, lAveWidth; static LONG desk_cx, desk_cy; RECTL rectl; HWND hwndEditorWin, hwndEditorClient; ULONG flCreate; FONTDLG fontDlg; char szFamilyname[FACESIZE]; char szExmpl[128]; ULONG stringID[NUM_MAINTEXT] = {IDS_MAINTEXT1, IDS_MAINTEXT2, IDS_MAINTEXT3 }; static char* sText=NULL; static char* sTextEnjoy; void setFont( HWND hwnd, HPS hps, PFATTRS pAttrs ); switch(msg) { case WM_CREATE: { int i; SIZEL sizl; HDC hdc; HWND hwndFrame; ULONG dataLength; char buf[BUFSIZ]; LONG x,y,cx,cy; /* Read message text */ for (i = 0; i < NUM_MAINTEXT; i++) { WinLoadString( hab, NULLHANDLE, stringID[i], sizeof(buf), buf ); if( sText == NULL ) { sText = malloc(strlen(buf)+1); *sText = '\0'; } else sText = realloc( sText, strlen(sText)+strlen(buf)+1 ); strcat( sText, buf ); } WinLoadString( hab, NULLHANDLE, IDS_TEXTENJOY, sizeof(buf), buf ); sTextEnjoy = malloc( strlen(buf)+1 ); strcpy( sTextEnjoy, buf ); sizl.cx = 0L; sizl.cy = 0L; hdc = WinOpenWindowDC( hwnd ); hpsMain = GpiCreatePS( hab, hdc, (PSIZEL)&sizl, (ULONG)PU_PELS | GPIT_MICRO | GPIA_ASSOC ); /* Query the environment */ DosQueryCp( sizeof(lCodePage), &lCodePage, &dataLength ); GetFontSize( hpsMain, &lAveWidth, &lFontHeight ); hwndFrame = WinQueryWindow(hwnd, QW_PARENT); desk_cx = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN ); desk_cy = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ); /* set window width to show maximum 40 SBCS characters */ cx = (lAveWidth*MAIN_WIN_WIDTH>desk_cx) ? desk_cx : lAveWidth*MAIN_WIN_WIDTH; /* set window height large enough to show a string pointed to by sText.*/ cy = (((strlen(sText)/MAIN_WIN_WIDTH)+10)*lFontHeight>desk_cy) ? desk_cy : ((strlen(sText)/40) + 10)*lFontHeight; x = (cx<desk_cx) ? (desk_cx-cx)/2 : 0; y = (cy<desk_cy) ? (desk_cy-cy)/2 : 0; WinSetWindowPos(hwndFrame, HWND_BOTTOM, x, y, cx, cy, SWP_MOVE | SWP_SIZE | SWP_ACTIVATE); return(MRESULT)(FALSE); } case WM_COMMAND: switch (SHORT1FROMMP(mp1)) { case MID_CONV: /* CPCONV */ { WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP) cpConvDlgProc, NULLHANDLE, DID_CONV, &lCodePage); break; } case MID_EDITOR: /* Simple Editor */ flCreate= FCF_SIZEBORDER | FCF_MENU | FCF_MAXBUTTON | FCF_MINBUTTON | FCF_SYSMENU | FCF_TITLEBAR | FCF_DBE_APPSTAT; hwndEditorWin = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE, &flCreate, "editorWindow", "Simple Editor", 0L, NULLHANDLE, WID_EDITOR, (PHWND) & hwndEditorClient); WinSetWindowPos(hwndEditorWin, HWND_BOTTOM, 190, 130, 500, 300, SWP_MOVE | SWP_SIZE | SWP_ACTIVATE); break; case MID_WORD: /* Word Break */ { WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP) wordDlgProc, NULLHANDLE, DID_WORD, &lCodePage); break; } case MID_EXIT: /* Exit */ WinSendMsg (hwnd, WM_CLOSE,mp1,mp2); break; } break; case WM_PAINT: { int i; LONG lTotLen, lWrittenLen, lDrawn; SWP swp; WinBeginPaint( hwnd, hpsMain, (PRECTL)&rectl ); /* Always update whole window - CS_SIZEREDRAW? */ WinQueryWindowPos( hwnd, &swp ); rectl.xLeft = rectl.yBottom = 0; rectl.xRight = swp.cx; rectl.yTop = swp.cy; WinFillRect( hpsMain, (PRECTL) &rectl, CLR_BACKGROUND ); lTotLen = (LONG)strlen(sText); /* make some space between the text and the frame window */ rectl.xLeft+=lAveWidth; rectl.xRight-=lAveWidth; rectl.yTop-=lFontHeight; for (lWrittenLen = 0; lWrittenLen != lTotLen; rectl.yTop -= lFontHeight) { lDrawn = WinDrawText( hpsMain, lTotLen - lWrittenLen, sText+lWrittenLen, &rectl, 0L, 0L, DT_WORDBREAK | DT_TOP | DT_LEFT | DT_TEXTATTRS); if( lDrawn != 0 ) lWrittenLen += lDrawn; else break; } rectl.yTop -= lFontHeight; WinDrawText( hpsMain, strlen(sTextEnjoy), sTextEnjoy, &rectl, CLR_RED, CLR_BACKGROUND, DT_TOP | DT_CENTER ); WinEndPaint( hpsMain ); break; } case WM_DESTROY: GpiDestroyPS( hpsMain ); break; default: return(WinDefWindowProc(hwnd,msg,mp1,mp2)); } return(MRFROMLONG(NULL)); }
BOOL CreateImages(PLUGINSHARE *pPluginData) { int i; HBITMAP hbmTemp; HAB hab = WinQueryAnchorBlock(HWND_DESKTOP); HDC hdcSrc, hdcDest; HPS hpsSrc, hpsDest; SIZEL slHPS; BITMAPINFOHEADER2 bif2Src, bif2Dest; POINTL aptl[4]; if (pPluginData == NULL) return (FALSE); hbmTemp = SetupBitmapFromFile(HWND_DESKTOP, pPluginData->szImageFile/*, 22*/); if (hbmTemp == NULLHANDLE) return FALSE; memset(&bif2Src, 0, sizeof(bif2Src)); bif2Src.cbFix = sizeof(bif2Src); GpiQueryBitmapInfoHeader(hbmTemp, &bif2Src); hdcSrc = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, NULLHANDLE); slHPS.cx = bif2Src.cx; slHPS.cy = bif2Src.cy; pPluginData->ulCx=slHPS.cx; pPluginData->ulCy=slHPS.cy; hpsSrc = GpiCreatePS(hab, hdcSrc, &slHPS, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC); GpiSetBitmap(hpsSrc, hbmTemp); hdcDest = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, NULLHANDLE); slHPS.cx = bif2Src.cx / 2; slHPS.cy = bif2Src.cy / 5; hpsDest = GpiCreatePS(hab, hdcDest, &slHPS, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC); memset(&bif2Dest, 0, sizeof(bif2Dest)); bif2Dest.cbFix = sizeof(bif2Dest); bif2Dest.cx = slHPS.cx; bif2Dest.cy = slHPS.cy; bif2Dest.cBitCount = 24; bif2Dest.cPlanes = 1; //Close Button pPluginData->hbmActiveClose = GpiCreateBitmap(hpsDest, &bif2Dest, 0L, NULL, NULL); GpiSetBitmap(hpsDest, pPluginData->hbmActiveClose); aptl[0].x = 0; aptl[0].y = 0; aptl[1].x = slHPS.cx; aptl[1].y = slHPS.cy; aptl[2].x = 0; aptl[2].y = 0; aptl[3].x = slHPS.cx; aptl[3].y = slHPS.cy; GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE); //Minimize Button pPluginData->hbmActiveMinimize = GpiCreateBitmap(hpsDest, &bif2Dest, 0L, NULL, NULL); GpiSetBitmap(hpsDest, pPluginData->hbmActiveMinimize); aptl[0].x = 0; aptl[0].y = 0; aptl[1].x = slHPS.cx; aptl[1].y = slHPS.cy; aptl[2].x = 0; aptl[2].y = slHPS.cy * 1; aptl[3].x = aptl[2].x + slHPS.cx; aptl[3].y = aptl[2].y + slHPS.cy; GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE); //Maximize Button pPluginData->hbmActiveMaximize = GpiCreateBitmap(hpsDest, &bif2Dest, 0L, NULL, NULL); GpiSetBitmap(hpsDest, pPluginData->hbmActiveMaximize); aptl[0].x = 0; aptl[0].y = 0; aptl[1].x = slHPS.cx; aptl[1].y = slHPS.cy; aptl[2].x = 0; aptl[2].y = slHPS.cy * 2; aptl[3].x = aptl[2].x + slHPS.cx; aptl[3].y = aptl[2].y + slHPS.cy; GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE); //Restore Button pPluginData->hbmActiveRestore = GpiCreateBitmap(hpsDest, &bif2Dest, 0L, NULL, NULL); GpiSetBitmap(hpsDest, pPluginData->hbmActiveRestore); aptl[0].x = 0; aptl[0].y = 0; aptl[1].x = slHPS.cx; aptl[1].y = slHPS.cy; aptl[2].x = 0; aptl[2].y = slHPS.cy * 3; aptl[3].x = aptl[2].x + slHPS.cx; aptl[3].y = aptl[2].y + slHPS.cy; GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE); //Hide Button pPluginData->hbmActiveHide = GpiCreateBitmap(hpsDest, &bif2Dest, 0L, NULL, NULL); GpiSetBitmap(hpsDest, pPluginData->hbmActiveHide); aptl[0].x = 0; aptl[0].y = 0; aptl[1].x = slHPS.cx; aptl[1].y = slHPS.cy; aptl[2].x = 0; aptl[2].y = slHPS.cy * 4; aptl[3].x = aptl[2].x + slHPS.cx; aptl[3].y = aptl[2].y + slHPS.cy; GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE); /* Inactive... */ //Close Button pPluginData->hbmInactiveClose = GpiCreateBitmap(hpsDest, &bif2Dest, 0L, NULL, NULL); GpiSetBitmap(hpsDest, pPluginData->hbmInactiveClose); aptl[0].x = 0; aptl[0].y = 0; aptl[1].x = slHPS.cx; aptl[1].y = slHPS.cy; aptl[2].x = slHPS.cx ; aptl[2].y = 0; aptl[3].x = aptl[2].x + slHPS.cx; aptl[3].y = aptl[2].y + slHPS.cy; GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE); //Minimize Button pPluginData->hbmInactiveMinimize = GpiCreateBitmap(hpsDest, &bif2Dest, 0L, NULL, NULL); GpiSetBitmap(hpsDest, pPluginData->hbmInactiveMinimize); aptl[0].x = 0; aptl[0].y = 0; aptl[1].x = slHPS.cx; aptl[1].y = slHPS.cy; aptl[2].x = slHPS.cx; aptl[2].y = slHPS.cy * 1; aptl[3].x = aptl[2].x + slHPS.cx; aptl[3].y = aptl[2].y + slHPS.cy; GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE); //Maximize Button pPluginData->hbmInactiveMaximize = GpiCreateBitmap(hpsDest, &bif2Dest, 0L, NULL, NULL); GpiSetBitmap(hpsDest, pPluginData->hbmInactiveMaximize); aptl[0].x = 0; aptl[0].y = 0; aptl[1].x = slHPS.cx; aptl[1].y = slHPS.cy; aptl[2].x = slHPS.cx; aptl[2].y = slHPS.cy * 2; aptl[3].x = aptl[2].x + slHPS.cx; aptl[3].y = aptl[2].y + slHPS.cy; GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE); //Restore Button pPluginData->hbmInactiveRestore = GpiCreateBitmap(hpsDest, &bif2Dest, 0L, NULL, NULL); GpiSetBitmap(hpsDest, pPluginData->hbmInactiveRestore); aptl[0].x = 0; aptl[0].y = 0; aptl[1].x = slHPS.cx; aptl[1].y = slHPS.cy; aptl[2].x = slHPS.cx; aptl[2].y = slHPS.cy * 3; aptl[3].x = aptl[2].x + slHPS.cx; aptl[3].y = aptl[2].y + slHPS.cy; GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE); //Hide Button pPluginData->hbmInactiveHide = GpiCreateBitmap(hpsDest, &bif2Dest, 0L, NULL, NULL); GpiSetBitmap(hpsDest, pPluginData->hbmInactiveHide); aptl[0].x = 0; aptl[0].y = 0; aptl[1].x = slHPS.cx; aptl[1].y = slHPS.cy; aptl[2].x = slHPS.cx; aptl[2].y = slHPS.cy * 4; aptl[3].x = aptl[2].x + slHPS.cx; aptl[3].y = aptl[2].y + slHPS.cy; GpiBitBlt(hpsDest, hpsSrc, 4, aptl, ROP_SRCCOPY, BBO_IGNORE); GpiSetBitmap(hpsSrc, NULLHANDLE); if (hbmTemp != NULLHANDLE) GpiDeleteBitmap(hbmTemp); if (hpsSrc != NULLHANDLE) GpiDestroyPS(hpsSrc); if (hdcSrc != NULLHANDLE) DevCloseDC(hdcSrc); GpiSetBitmap(hpsDest, NULLHANDLE); if (hpsDest != NULLHANDLE) GpiDestroyPS(hpsDest); if (hdcDest != NULLHANDLE) DevCloseDC(hdcDest); return TRUE; }
MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { static BITMAPINFOHEADER2 bmp ; static BOOL fButton1Down, fButton2Down ; static HBITMAP hbm ; static HDC hdcMemory ; static HPS hpsMemory ; static POINTL ptlPointerPos, aptl [3] ; HPS hpsWindow ; LONG cxFullScrn, cyFullScrn ; SIZEL sizl ; switch (msg) { case WM_CREATE: cxFullScrn = WinQuerySysValue (HWND_DESKTOP, SV_CXFULLSCREEN) ; cyFullScrn = WinQuerySysValue (HWND_DESKTOP, SV_CYFULLSCREEN) ; // Create Memory DC and PS hdcMemory = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, 0) ; sizl.cx = 0 ; sizl.cy = 0 ; hpsMemory = GpiCreatePS (hab, hdcMemory, &sizl, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC) ; // Create monochrome bitmap, return 1 if cannot bmp.cbFix = sizeof (BITMAPINFOHEADER2) ; bmp.cx = cxFullScrn ; bmp.cy = cyFullScrn ; bmp.cPlanes = 1 ; bmp.cBitCount = 1 ; hbm = GpiCreateBitmap (hpsMemory, &bmp, 0L, 0L, NULL) ; if (hbm == 0) { GpiDestroyPS (hpsMemory) ; DevCloseDC (hdcMemory) ; return MRFROMSHORT (1) ; } // Set bitmap in memory PS and clear it GpiSetBitmap (hpsMemory, hbm) ; aptl[1].x = cxFullScrn ; aptl[1].y = cyFullScrn ; GpiBitBlt (hpsMemory, 0, 2L, aptl, ROP_ZERO, BBO_OR) ; return 0 ; case WM_BUTTON1DOWN: if (!fButton2Down) WinSetCapture (HWND_DESKTOP, hwnd) ; ptlPointerPos.x = MOUSEMSG(&msg)->x ; ptlPointerPos.y = MOUSEMSG(&msg)->y ; fButton1Down = TRUE ; break ; // do default processing case WM_BUTTON1UP: if (!fButton2Down) WinSetCapture (HWND_DESKTOP, NULLHANDLE) ; fButton1Down = FALSE ; return 0 ; case WM_BUTTON2DOWN: if (!fButton1Down) WinSetCapture (HWND_DESKTOP, hwnd) ; ptlPointerPos.x = MOUSEMSG(&msg)->x ; ptlPointerPos.y = MOUSEMSG(&msg)->y ; fButton2Down = TRUE ; break ; // do default processing case WM_BUTTON2UP: if (!fButton1Down) WinSetCapture (HWND_DESKTOP, NULLHANDLE) ; fButton2Down = FALSE ; return 0 ; case WM_MOUSEMOVE: if (!fButton1Down && !fButton2Down) break ; hpsWindow = WinGetPS (hwnd) ; GpiSetColor (hpsMemory, fButton1Down ? CLR_TRUE : CLR_FALSE) ; GpiSetColor (hpsWindow, fButton1Down ? CLR_NEUTRAL : CLR_BACKGROUND) ; GpiMove (hpsMemory, &ptlPointerPos) ; GpiMove (hpsWindow, &ptlPointerPos) ; ptlPointerPos.x = MOUSEMSG(&msg)->x ; ptlPointerPos.y = MOUSEMSG(&msg)->y ; GpiLine (hpsMemory, &ptlPointerPos) ; GpiLine (hpsWindow, &ptlPointerPos) ; WinReleasePS (hpsWindow) ; break ; // do default processing case WM_PAINT: hpsWindow = WinBeginPaint (hwnd, NULLHANDLE, (PRECTL) aptl) ; aptl[2] = aptl[0] ; GpiBitBlt (hpsWindow, hpsMemory, 3L, aptl, ROP_SRCCOPY, BBO_OR) ; WinEndPaint (hpsWindow) ; return 0 ; case WM_DESTROY: GpiDestroyPS (hpsMemory) ; DevCloseDC (hdcMemory) ; GpiDeleteBitmap (hbm) ; return 0 ; } return WinDefWindowProc (hwnd, msg, mp1, mp2) ; }
/*@ XPrinterDevice::SetupPrinter(char *title, XFrameWindow * owner, XString * queueName, XString * fileName) @remarks Let the user select the printer-queue in a dialog. The dialog is loaded from OOLRES.DLL which must be installed. @parameters <t 'ø' c=2> øchar *title øthe title of the dialog øXFrameWindow * owner øowner window. If NULL, the dialog for the printer-setup is not opened and the queue given in parameter 3 is initialized directly øXString * queueName ødefault queue-name (can be null) øXString * fileName øbuffer for a fileName if the user wants to print to a file (if NULL no fiflename is stored) </t> @returns BOOL success */ BOOL XPrinterDevice::SetupPrinter(const char *title, const XFrameWindow * owner, XString * queueName, XString * fileName) { BOOL fOK; CHAR szDefaultQueue[196]; CHAR szSavedQueue[196]; CHAR szWork[196]; PCHAR pch; PPRQINFO3 pqi; SIZEL sizel; ULONG cReturned; ULONG cTotal; ULONG cbNeeded; ULONG ul; ULONG ulrc; // Caller must set these items before calling. if (!pSetup->hab || !pSetup->lWorldCoordinates) return FALSE; // no good unless I can open a PS pSetup->pDevOpenData = NULL; // Close the info DC's and PS's from any previous call. if (pSetup->hpsPrinterInfo) { GpiAssociate(pSetup->hpsPrinterInfo, (HDC) 0); GpiDestroyPS(pSetup->hpsPrinterInfo); pSetup->hpsPrinterInfo = (HPS) 0; } if (pSetup->hdcPrinterInfo) { DevCloseDC(pSetup->hdcPrinterInfo); pSetup->hdcPrinterInfo = (HDC) 0; } if (pSetup->pQueueInfo) { // Free the array of PRQINFO3 from previous call. free(pSetup->pQueueInfo); pSetup->pQueueInfo = NULL; } // Query how many queues exist on this computer and the // number of bytes needed to hold the array. ul = SplEnumQueue(NULL, 3, NULL, 0, &cReturned, &cTotal, &cbNeeded, NULL); if (cTotal == 0) { // There are no queues on this computer! pSetup->cQueues = 0; return FALSE; } // Allocate memory to store the newly enumerated queue information. pSetup->pQueueInfo = (PRQINFO3 *) malloc(cbNeeded); if (!pSetup->pQueueInfo) return FALSE; // Call system again to get the array of PRQINFO3 structures. ul = SplEnumQueue(NULL, 3, pSetup->pQueueInfo, cbNeeded, &cReturned, &cTotal, &cbNeeded, NULL); if (ul != 0 || cReturned != cTotal) return FALSE; pSetup->cQueues = cReturned; // Establish a default queue -- might need it. // Profiled queue name ends with a semicolon. ul = PrfQueryProfileString(HINI_PROFILE, (PSZ) "PM_SPOOLER", (PSZ) "QUEUE", NULL, szDefaultQueue, 196); if (ul > 1) { // Trim off semicolon. pch = strchr(szDefaultQueue, ';'); *pch = 0; } else { // Hmmmm. Use the first one queue from the enumeration. strcpy(szDefaultQueue, (char*) pSetup->pQueueInfo->pszName); } if (!strlen(szDefaultQueue)) return FALSE; if (0 == strlen(pSetup->szPreferredQueue)) { // No queue preference; use default. strcpy(pSetup->szPreferredQueue, szDefaultQueue); // Don't expect to see DRIVDATA without queue name. // if(! pSetup->pDriverData ) return FALSE; } if (queueName) { if (!queueName->IsEmpty()) { pSetup->fToFile = FALSE; strcpy(pSetup->szPreferredQueue, (char *) *queueName); } if (fileName) { if (!fileName->IsEmpty()) { pSetup->fToFile = TRUE; strcpy(pSetup->szFileName, (char *) *fileName); } } } pqi = FindQueue(pSetup); if (!pqi) { strcpy(pSetup->szPreferredQueue, szDefaultQueue); if (pSetup->pDriverData) { free(pSetup->pDriverData); pSetup->pDriverData = NULL; } } else { fOK = TRUE; if (pSetup->pDriverData) { fOK = fOK && (pqi->pDriverData->cb == pSetup->pDriverData->cb); fOK = fOK && (0 == strcmp(pqi->pDriverData->szDeviceName, pSetup->pDriverData->szDeviceName)); } if (!fOK) { free(pSetup->pDriverData); pSetup->pDriverData = NULL; } } pqi = FindQueue(pSetup); if (!pSetup->pDriverData) { pSetup->pDriverData = (DRIVDATA *) malloc(pqi->pDriverData->cb); if (!pSetup->pDriverData) { ulrc = FALSE; return ulrc; } memcpy(pSetup->pDriverData, pqi->pDriverData, pqi->pDriverData->cb); } if (!pSetup->pDriverData || pSetup->pDriverData->cb <= 0 || pSetup->pDriverData->cb != pqi->pDriverData->cb || strcmp(pqi->pDriverData->szDeviceName, pSetup->pDriverData->szDeviceName)) return FALSE; memcpy(pqi->pDriverData, pSetup->pDriverData, pSetup->pDriverData->cb); strcpy(szSavedQueue, pSetup->szPreferredQueue); if (owner) { XCountryInfo info; XResourceLibrary lib( "oolres"); LONG dlgID; switch (info.GetCountry()) { case 39: // italy dlgID = IDD_SELPRINT_ITA; break; case 2: // can francais case 33: // france case 32: // belgien dlgID = IDD_SELPRINT_FRA; break; case 49: // german dlgID = IDD_SELPRINT_GER; break; default: // english dlgID = IDD_SELPRINT_ENG; } XResource res(dlgID, &lib); PrinterDialog *printerDialog = new PrinterDialog(owner, pSetup, &res); // printerDialog->SetText((char*) title); LONG result = printerDialog->Start(); if (result == DID_CANCEL) return FALSE; } else { if (queueName) { pSetup->fToFile = FALSE; strcpy(pSetup->szPreferredQueue, (char *) *queueName); if (fileName) { pSetup->fToFile = TRUE; strcpy(pSetup->szFileName, (char *) *fileName); } } } *queueName = ""; *fileName = ""; pqi = FindQueue(pSetup); if (!pqi) return FALSE; if (0 != strcmp(szSavedQueue, pSetup->szPreferredQueue)) { if (!pSetup->pDriverData) return FALSE; free(pSetup->pDriverData); pSetup->pDriverData = (DRIVDATA *) malloc(pqi->pDriverData->cb); if (!pSetup->pDriverData) { ulrc = FALSE; return ulrc; } pSetup->pDriverData->cb = pqi->pDriverData->cb; } if (!pSetup->pDriverData || !pSetup->pDriverData->cb == pqi->pDriverData->cb) return FALSE; memcpy(pSetup->pDriverData, pqi->pDriverData, pqi->pDriverData->cb); if (pSetup->fToFile) { pSetup->lDCType = OD_DIRECT; pSetup->devopenstruc.pszLogAddress = (PSZ) pSetup->szFileName; } else { pSetup->lDCType = OD_QUEUED; pSetup->devopenstruc.pszLogAddress = (PSZ) pSetup->szPreferredQueue; } strcpy(szWork, (char*) pqi->pszDriverName); pch = strchr(szWork, '.'); if (pch) *pch = 0; if (pSetup->devopenstruc.pszDriverName) free(pSetup->devopenstruc.pszDriverName); pSetup->devopenstruc.pszDriverName = (PSZ) malloc(1 + strlen(szWork)); if (!pSetup->devopenstruc.pszDriverName) return FALSE; strcpy( (char*) pSetup->devopenstruc.pszDriverName, szWork); pSetup->devopenstruc.pdriv = pSetup->pDriverData; pSetup->devopenstruc.pszDataType = (PSZ) "PM_Q_STD"; pSetup->hdcPrinterInfo = DevOpenDC(pSetup->hab, OD_INFO, (PSZ) "*", 4, (PDEVOPENDATA) & pSetup->devopenstruc, (HDC) 0); if (!pSetup->hdcPrinterInfo) return FALSE; sizel.cx = 0; sizel.cy = 0; pSetup->hpsPrinterInfo = GpiCreatePS(pSetup->hab, pSetup->hdcPrinterInfo, &sizel, pSetup->lWorldCoordinates | GPIA_ASSOC); if (GPI_ERROR == pSetup->hpsPrinterInfo) { DevCloseDC(pSetup->hdcPrinterInfo); pSetup->hdcPrinterInfo = (HDC) 0; pSetup->hpsPrinterInfo = (HPS) 0; return FALSE; } pSetup->pDevOpenData = (PDEVOPENDATA) & pSetup->devopenstruc; *queueName = pSetup->szPreferredQueue; if (pSetup->fToFile) *fileName = pSetup->szFileName; return TRUE; }
// tiles an image across preview window BOOL DrawImage(PSPAINT * pPaint, HBITMAP hbm, HBITMAP hbmMask) { SIZEL slHps; BITMAPINFOHEADER2 bif2; BITMAPINFOHEADER2 bif; POINTL aptl[3]; HDC hdc; HPS hps; HAB hab = WinQueryAnchorBlock(pPaint->hwnd); long starty; RECTL rectl; rectl.xLeft = pPaint->rectlWindow.xLeft; /* if ( pPaint->rectlWindow.xRight < (pPaint->rectlWindow.xLeft + 16) ) rectl.xRight = pPaint->rectlWindow.xRight; else rectl.xRight = pPaint->rectlWindow.xLeft + 16; */ if ( (pPaint->rectlWindow.yTop - pPaint->rectlWindow.yBottom) < 16) { rectl.yTop = pPaint->rectlWindow.yTop; rectl.yBottom = pPaint->rectlWindow.yBottom; } else { rectl.yBottom = ((pPaint->rectlWindow.yTop + pPaint->rectlWindow.yBottom + 1) / 2) - 8; rectl.yTop = rectl.yBottom + 16; } // setup source bitmap hdc = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, NULLHANDLE); // get bitmap info memset(&bif2, 0, sizeof(bif2)); bif2.cbFix = sizeof(bif2); GpiQueryBitmapInfoHeader(hbm, &bif2); // create source hps slHps.cx = bif2.cx; slHps.cy = bif2.cy; hps = GpiCreatePS(hab, hdc, &slHps, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC); if ( pPaint->rectlWindow.xRight < (pPaint->rectlWindow.xLeft + slHps.cx) ) rectl.xRight = pPaint->rectlWindow.xRight; else rectl.xRight = pPaint->rectlWindow.xLeft + slHps.cx; // initial blt location aptl[0].x = rectl.xLeft; aptl[0].y = rectl.yBottom; aptl[1].x = rectl.xRight; aptl[1].y = rectl.yTop; aptl[2].x = 0; aptl[2].y = 0; if(hbmMask) { // set mask bmp into hps GpiSetBitmap(hps, hbmMask); GpiBitBlt(pPaint->hps, hps, 3L, aptl, ROP_MERGEPAINT, BBO_IGNORE); // set bmp into hps GpiSetBitmap(hps, hbm); GpiBitBlt(pPaint->hps, hps, 3L, aptl, ROP_SRCAND, BBO_IGNORE); } else { // set bmp into hps GpiSetBitmap(hps, hbm); GpiBitBlt(pPaint->hps, hps, 3L, aptl, ROP_SRCCOPY, BBO_IGNORE); } // clean up GpiSetBitmap(hps, NULLHANDLE); GpiDestroyPS(hps); DevCloseDC(hdc); return (TRUE); }
//---------------------------------------------------------------------------- // NPP_SetWindow: //---------------------------------------------------------------------------- NPError NP_LOADDS NPP_SetWindow(NPP instance, NPWindow* window) { if (instance == 0 ) return NPERR_INVALID_INSTANCE_ERROR; PluginInstance* This = (PluginInstance*) instance->pdata; // // *Developers*: Before setting fWindow to point to the // new window, you may wish to compare the new window // info to the previous window (if any) to note window // size changes, etc. // if((window->window != 0 ) && (This->hWnd == 0 )) { This->fWindow = window; This->hWnd = (HWND)This->fWindow->window; // subclass the window This->lpfnOldWndProc = WinSubclassWindow(This->hWnd, SubClassFunc); AssociateInstance(This->hWnd, This); // create a PS if (! This->hps) { HDC hdc = WinQueryWindowDC(This->hWnd); if (! hdc) hdc = WinOpenWindowDC(This->hWnd); SIZEL siz = { 0, 0 }; This->hps = GpiCreatePS(WinQueryAnchorBlock(This->hWnd), hdc, &siz, PU_PELS | GPIT_MICRO | GPIA_ASSOC); } } else { // if window handle changed if(This->hWnd != (HWND)window->window) { // remember the new window This->fWindow = window; // Remove the subclass for the old client window WinSubclassWindow(This->hWnd, This->lpfnOldWndProc); // remember the new window handle This->hWnd = (HWND)This->fWindow->window; if(This->hWnd != 0 ) { // subclass the new one This->lpfnOldWndProc = WinSubclassWindow(This->hWnd, SubClassFunc); AssociateInstance(This->hWnd, This); } // stop old timer and start a new timer WinStopTimer(WinQueryAnchorBlock(This->hWnd), This->hWnd, kTimerId); WinStartTimer(WinQueryAnchorBlock(This->hWnd), This->hWnd, kTimerId, kTimerFrequency); // destroy old PS and create new PS if (! This->hps) GpiDestroyPS(This->hps); HDC hdc = WinQueryWindowDC(This->hWnd); if (! hdc) hdc = WinOpenWindowDC(This->hWnd); SIZEL siz = { 0, 0 }; This->hps = GpiCreatePS(WinQueryAnchorBlock(This->hWnd), hdc, &siz, PU_TWIPS | GPIT_MICRO | GPIA_ASSOC); } } return NPERR_NO_ERROR; }
MRESULT EXPENTRY fnwpReadColumnClient(HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2) { static HDC hdcPs; RECTL rclRect; POINTL ptl; LONG lSaveEdge; SWP swp; HWND hwndMenu; static USHORT usMenuStyle; static CLRDLG stColor; static USHORT usLastPopupItem; switch(msg) { case WM_CHAR: if (bSendNextKeystroke) if (ProcessKeystroke(&stCFG,mp1,mp2)) return((MRESULT)TRUE); return( WinDefWindowProc(hwnd,msg,mp1,mp2)); case WM_CREATE: hdcPs = WinOpenWindowDC(hwnd); usLastPopupItem = IDMPU_SYNC; stRead.lBackgrndColor = stCFG.lReadColBackgrndColor; stRead.bActive = FALSE; stRead.lScrollIndex = 0; stRead.hwndScroll = (HWND)NULL; stRead.wDirection = CS_READ; stColor.cbSize = sizeof(CLRDLG); usMenuStyle = (PU_POSITIONONITEM | PU_MOUSEBUTTON2 | PU_HCONSTRAIN | PU_VCONSTRAIN | PU_KEYBOARD | PU_MOUSEBUTTON1); WinSendMsg(hwnd,UM_TRACKFRAME,0L,0L); break; case WM_ACTIVATE: if(SHORT1FROMMP(mp1)) { if (!bFrameActivated) { WinSetFocus(HWND_DESKTOP,hwndFrame); WinSendMsg(WinQueryHelpInstance(hwndClient),HM_SET_ACTIVE_WINDOW,0L,0L); bFrameActivated = TRUE; } } else bFrameActivated = FALSE; break; case WM_VSCROLL: switch(HIUSHORT(mp2)) { case SB_LINEDOWN: ColScroll(&stRead,1,FALSE); break; case SB_LINEUP: ColScroll(&stRead,-1,FALSE); break; case SB_PAGEDOWN: ColScroll(&stRead,stRead.lCharHeight,FALSE); break; case SB_PAGEUP: ColScroll(&stRead,-stRead.lCharHeight,FALSE); break; case SB_SLIDERPOSITION: ColScroll(&stRead,LOUSHORT(mp2),TRUE); break; } break; case WM_COMMAND: switch (SHORT1FROMMP(mp1)) { case IDMPU_ASCII_FONT: if (!stCFG.bStickyMenus) usLastPopupItem = IDMPU_FONT; else usLastPopupItem = IDMPU_SYNC; if (stCFG.wColReadFont != wASCIIfont) { stCFG.wColReadFont = wASCIIfont; WinInvalidateRect(stRead.hwndClient,(PRECTL)NULL,FALSE); } break; case IDMPU_HEX_FONT: if (!stCFG.bStickyMenus) usLastPopupItem = IDMPU_FONT; else usLastPopupItem = IDMPU_SYNC; if (stCFG.wColReadFont != wHEXfont) { stCFG.wColReadFont = wHEXfont; WinInvalidateRect(stRead.hwndClient,(PRECTL)NULL,FALSE); } break; case IDMPU_SYNC: usLastPopupItem = IDMPU_SYNC; if (bStopDisplayThread) stRead.lScrollIndex = stWrite.lScrollIndex; else stRead.lScrollIndex = 0; stRead.lScrollRow = GetColScrollRow(&stRead,0); WinSendMsg(stRead.hwndScroll, SBM_SETPOS, MPFROMSHORT(stRead.lScrollRow), MPFROMSHORT(0)); if (stRead.bSync) { stRow.lScrollIndex = stRead.lScrollIndex; stRow.lScrollRow = GetRowScrollRow(&stRow); } WinInvalidateRect(stRead.hwndClient,(PRECTL)NULL,FALSE); break; case IDMPU_COLORS: if (!stCFG.bStickyMenus) usLastPopupItem = IDMPU_COLORS; else usLastPopupItem = IDMPU_SYNC; stColor.lForeground = stCFG.lReadColForegrndColor; stColor.lBackground = stCFG.lReadColBackgrndColor; sprintf(stColor.szCaption,"Lexical Receive Data Display Colors"); if (WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)fnwpSetColorDlg, (USHORT)NULL, CLR_DLG, MPFROMP(&stColor))) { stCFG.lReadColForegrndColor = stColor.lForeground; stCFG.lReadColBackgrndColor = stColor.lBackground; stRead.lBackgrndColor = stColor.lBackground; stRead.lForegrndColor = stColor.lForeground; WinInvalidateRect(stRead.hwndClient,(PRECTL)NULL,FALSE); } break; case IDMPU_LOCK_WIDTH: if (!stCFG.bStickyMenus) usLastPopupItem = IDMPU_LOCK_WIDTH; else usLastPopupItem = IDMPU_SYNC; if (stCFG.fLockWidth == LOCK_READ) stCFG.fLockWidth = LOCK_NONE; else { stCFG.lLockWidth = ((stRead.lWidth / stCell.cx) + 1); stCFG.fLockWidth = LOCK_READ; } break; case IDMPU_DISP_FILTERS: if (!stCFG.bStickyMenus) usLastPopupItem = IDMPU_DISP_FILTERS; else usLastPopupItem = IDMPU_SYNC; if (WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)fnwpDisplaySetupDlgProc, (USHORT)NULL, DISP_FILTER_DLG, MPFROMP(&stRead))) { stCFG.bReadTestNewLine = stRead.bTestNewLine; stCFG.bSkipReadBlankLines = stRead.bSkipBlankLines; stCFG.byReadNewLineChar = stRead.byNewLineChar; stCFG.bFilterRead = stRead.bFilter; stCFG.fFilterReadMask = stRead.fFilterMask; stCFG.byReadMask = stRead.byDisplayMask; if (stRead.bSync) { if (!stCFG.bSyncToRead) { stWrite.bSync = FALSE; stCFG.bSyncToWrite = FALSE; stCFG.bSyncToRead = TRUE; if (stCFG.fDisplaying & (DISP_DATA | DISP_FILE)) { ClearColScrollBar(&stWrite); SetupColScrolling(&stRead); } } } else { if (stCFG.bSyncToRead) { stCFG.bSyncToRead = FALSE; if (stCFG.fDisplaying & (DISP_DATA | DISP_FILE)) SetupColScrolling(&stWrite); } } WinInvalidateRect(stRead.hwndClient,(PRECTL)NULL,FALSE); } break; } break; // case WM_CHORD: case WM_BUTTON2DOWN: if(bFrameActivated) { hwndMenu = WinLoadMenu(stRead.hwnd,(HMODULE)NULL,IDMPU_COL_DISP_POPUP); if (mp1 != 0) { WinQueryPointerPos(HWND_DESKTOP,&ptl); if (!stCFG.bStickyMenus) usMenuStyle |= PU_MOUSEBUTTON2DOWN; else usMenuStyle &= ~PU_MOUSEBUTTON2DOWN; } else { usMenuStyle &= ~PU_MOUSEBUTTON2DOWN; WinQueryWindowPos(hwndFrame,&swp); ptl.x = (swp.x + (swp.cx - (swp.cx / 4))); ptl.y = (swp.y + (swp.cy / 2)); } if (stCFG.wColReadFont == wASCIIfont) PopupMenuItemCheck(hwndMenu,IDMPU_ASCII_FONT,TRUE); else PopupMenuItemCheck(hwndMenu,IDMPU_HEX_FONT,TRUE); if (stCFG.fLockWidth == LOCK_READ) PopupMenuItemCheck(hwndMenu,IDMPU_LOCK_WIDTH,TRUE); if (!bStopDisplayThread) WinSendMsg(hwndMenu,MM_SETITEMTEXT,(MPARAM)IDMPU_SYNC,"~Reset Display"); WinPopupMenu(HWND_DESKTOP,stRead.hwndClient,hwndMenu,ptl.x,ptl.y,usLastPopupItem,usMenuStyle); } else return WinDefWindowProc(hwnd,msg,mp1,mp2); break; case WM_BUTTON1DOWN: if(bFrameActivated) { WinCopyRect(habAnchorBlock,&rclRect,&stRead.rcl); lSaveEdge = rclRect.xLeft; if (TrackChildWindow(habAnchorBlock,hwndClient,&rclRect,TF_LEFT)) { if (rclRect.xLeft != lSaveEdge) { WinSendMsg(stWrite.hwndClient,UM_TRACKSIB,0L,(MPARAM)rclRect.xLeft); WinSendMsg(stRead.hwndClient,UM_TRACKSIB,(MPARAM)rclRect.xLeft,0L); if (stCFG.fLockWidth == LOCK_WRITE) stCFG.lLockWidth = ((stWrite.lWidth / stCell.cx) + 1); else stCFG.lLockWidth = ((stRead.lWidth / stCell.cx) + 1); } } } else return WinDefWindowProc(hwnd,msg,mp1,mp2); break; case WM_DESTROY: GpiDestroyPS(hdcPs); break; case UM_SHOWNEW: stRead.lScrollIndex = 0; stRead.lScrollRow = 0; ClearColScrollBar(&stRead); case UM_SHOWAGAIN: stRead.bActive = TRUE; if ((stCFG.fDisplaying & (DISP_DATA | DISP_FILE)) && !stCFG.bSyncToWrite) SetupColScrolling(&stRead); WinShowWindow(stRead.hwnd,TRUE); WinSendMsg(hwnd,UM_TRACKFRAME,0L,0L); WinInvalidateRect(stRead.hwndClient,(PRECTL)NULL,FALSE); WinInvalidateRect(hwndStatus,(PRECTL)NULL,FALSE); break; case UM_HIDEWIN: ClearColScrollBar(&stRead); stRead.bActive = FALSE; WinShowWindow(hwnd,FALSE); WinSetWindowPos(stRead.hwnd,HWND_BOTTOM,0L,0L,0L,0L,(SWP_MOVE | SWP_SIZE | SWP_ZORDER)); break; case WM_PAINT: #ifdef this_junk if (!pstCFG->bDisplayingData && (stCFG.bSyncToRead || stCFG.bSyncToWrite)) ColumnPaint(&stRead,WinPeekMsg(habAnchorBlock,&stQmsg,stWrite.hwndClient,WM_PAINT,WM_PAINT,PM_REMOVE)); else #endif ColumnPaint(&stRead); break; case UM_TRACKSIB: ColumnSize(&stRead,(LONG)mp1,(LONG)mp2,TRUE); break; case UM_TRACKFRAME: ColumnSize(&stRead,(LONG)mp1,(LONG)mp2,FALSE); break; case WM_ERASEBACKGROUND: return (MRESULT)(TRUE); case WM_CLOSE: WinPostMsg(hwnd,WM_QUIT,0L,0L); default: return WinDefWindowProc(hwnd,msg,mp1,mp2); } return(FALSE); }
//----------------------------------------------------------------------------- // NPP_Destroy: //----------------------------------------------------------------------------- NPError NP_LOADDS NPP_Destroy(NPP instance, NPSavedData** save) { if (instance == 0 ) return NPERR_INVALID_INSTANCE_ERROR; PluginInstance* This = (PluginInstance*) instance->pdata; // // *Developers*: If desired, call NP_MemAlloc to create a // NPSavedDate structure containing any state information // that you want restored if this plugin instance is later // recreated. // if (This != 0 ) { // stop the timer if (This->fTimer) { WinStopTimer(WinQueryAnchorBlock(This->hWnd), This->hWnd, kTimerId); This->fTimer = FALSE; } // destroy old PS and create new PS if (! This->hps) GpiDestroyPS(This->hps); // delete clock delete This->pClock; // Remove the subclass for the client window if(This->hWnd) { WinSubclassWindow(This->hWnd, This->lpfnOldWndProc); } // make some saved instance data if necessary if(This->pSavedInstanceData == 0 ) { // make a struct header for the data This->pSavedInstanceData = (NPSavedData*)NPN_MemAlloc(sizeof (struct _NPSavedData)); // fill in the struct if(This->pSavedInstanceData != 0 ) { This->pSavedInstanceData->len = 0; This->pSavedInstanceData->buf = 0 ; // replace the def below and references to it with your data #define SIDATA "aSavedInstanceDataBlock" // the data This->pSavedInstanceData->buf = NPN_MemAlloc(sizeof SIDATA); if(This->pSavedInstanceData->buf != 0 ) { strcpy((char*)This->pSavedInstanceData->buf, SIDATA); This->pSavedInstanceData->len = sizeof SIDATA; } } } // save some instance data *save = This->pSavedInstanceData; NPN_MemFree(instance->pdata); instance->pdata = 0 ; } return NPERR_NO_ERROR; }
static void _cairo_os2_surface_get_pixels_from_screen (cairo_os2_surface_t *surface, HPS hps_begin_paint, PRECTL prcl_begin_paint_rect) { HPS hps; HDC hdc; HAB hab; SIZEL sizlTemp; HBITMAP hbmpTemp; BITMAPINFO2 bmi2Temp; POINTL aptlPoints[4]; int y; unsigned char *pchTemp; /* To copy pixels from screen to our buffer, we do the following steps: * * - Blit pixels from screen to a HBITMAP: * -- Create Memory Device Context * -- Create a PS into it * -- Create a HBITMAP * -- Select HBITMAP into memory PS * -- Blit dirty pixels from screen to HBITMAP * - Copy HBITMAP lines (pixels) into our buffer * - Free resources * * These steps will require an Anchor Block (HAB). However, * WinQUeryAnchorBlock () documentation says that HAB is not * used in current OS/2 implementations, OS/2 deduces all information * it needs from the TID. Anyway, we'd be in trouble if we'd have to * get a HAB where we only know a HPS... * So, we'll simply use a fake HAB. */ hab = (HAB) 1; /* OS/2 doesn't really use HAB... */ /* Create a memory device context */ hdc = DevOpenDC (hab, OD_MEMORY,"*",0L, NULL, NULLHANDLE); if (!hdc) { return; } /* Create a memory PS */ sizlTemp.cx = prcl_begin_paint_rect->xRight - prcl_begin_paint_rect->xLeft; sizlTemp.cy = prcl_begin_paint_rect->yTop - prcl_begin_paint_rect->yBottom; hps = GpiCreatePS (hab, hdc, &sizlTemp, PU_PELS | GPIT_NORMAL | GPIA_ASSOC); if (!hps) { DevCloseDC (hdc); return; } /* Create an uninitialized bitmap. */ /* Prepare BITMAPINFO2 structure for our buffer */ memset (&bmi2Temp, 0, sizeof (bmi2Temp)); bmi2Temp.cbFix = sizeof (BITMAPINFOHEADER2); bmi2Temp.cx = sizlTemp.cx; bmi2Temp.cy = sizlTemp.cy; bmi2Temp.cPlanes = 1; bmi2Temp.cBitCount = 32; hbmpTemp = GpiCreateBitmap (hps, (PBITMAPINFOHEADER2) &bmi2Temp, 0, NULL, NULL); if (!hbmpTemp) { GpiDestroyPS (hps); DevCloseDC (hdc); return; } /* Select the bitmap into the memory device context. */ GpiSetBitmap (hps, hbmpTemp); /* Target coordinates (Noninclusive) */ aptlPoints[0].x = 0; aptlPoints[0].y = 0; aptlPoints[1].x = sizlTemp.cx; aptlPoints[1].y = sizlTemp.cy; /* Source coordinates (Inclusive) */ aptlPoints[2].x = prcl_begin_paint_rect->xLeft; aptlPoints[2].y = surface->bitmap_info.cy - prcl_begin_paint_rect->yBottom; aptlPoints[3].x = prcl_begin_paint_rect->xRight; aptlPoints[3].y = surface->bitmap_info.cy - prcl_begin_paint_rect->yTop; /* Blit pixels from screen to bitmap */ GpiBitBlt (hps, hps_begin_paint, 4, aptlPoints, ROP_SRCCOPY, BBO_IGNORE); /* Now we have to extract the pixels from the bitmap. */ pchTemp = surface->pixels + (prcl_begin_paint_rect->yBottom)*surface->bitmap_info.cx*4 + prcl_begin_paint_rect->xLeft*4; for (y = 0; y < sizlTemp.cy; y++) { /* Get one line of pixels */ GpiQueryBitmapBits (hps, sizlTemp.cy - y - 1, /* lScanStart */ 1, /* lScans */ pchTemp, &bmi2Temp); /* Go for next line */ pchTemp += surface->bitmap_info.cx*4; } /* Clean up resources */ GpiSetBitmap (hps, (HBITMAP) NULL); GpiDeleteBitmap (hbmpTemp); GpiDestroyPS (hps); DevCloseDC (hdc); }
MRESULT EXPENTRY fnwpClient(HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2) { POINTL ptl; HPS hps; RECTL rcl; ORIG Origin; BYTE bVkey; BYTE chKey; PSWP pswp; USHORT usCxMaxWnd; static ORIG OrigRestor; USHORT Command; CHAR szMessage[100]; CHAR szCaption[81]; ULONG cbDataSize; switch(msg) { case WM_CREATE: CreatePS(hwnd); if (bFalseStart) WinPostMsg(hwndClient,UM_FALSE_START,0,0); else WinPostMsg(hwndClient,UM_INITMENUS,0,0); break; case UM_FALSE_START: if (bConfigurationOnly > 1) MessageBox(HWND_DESKTOP,szFalseStart2); else MessageBox(HWND_DESKTOP,szFalseStart1); case WM_CLOSE: WinPostMsg(hwnd,WM_QUIT,0L,0L); break; case UM_INITMENUS: sprintf(pszPath,"~%s...",szConfigDDname); WinSendMsg(WinWindowFromID(stInst.hwndFrame,FID_MENU),MM_SETITEMTEXT,(MPARAM)IDM_CONFIG_DD,pszPath); if (strlen(szConfigAppName) != 0) { sprintf(pszPath,"~%s...",szConfigAppName); WinSendMsg(WinWindowFromID(stInst.hwndFrame,FID_MENU),MM_SETITEMTEXT,(MPARAM)IDM_CONFIG_APP,pszPath); PrfQueryProfileString(HINI_USERPROFILE,szConfigAppName,"Configuration",0L, stInst.paszStrings[CONFIGAPPLIBRARYSPEC], stInst.ulMaxPathLen); if (strlen(stInst.paszStrings[CONFIGAPPLIBRARYSPEC]) == 0) MenuItemEnable(stInst.hwndFrame,IDM_CONFIG_APP,FALSE); cbDataSize = sizeof(HOBJECT); if (!PrfQueryProfileData(hSourceProfile,szConfigAppName,"WPSobject",&stPageCFG.hObject,&cbDataSize)) stPageCFG.hObject = 0; } if (bConfigurationOnly) MenuItemEnable(stInst.hwndFrame,IDM_SELECT,FALSE); if (!bUninstall) MenuItemEnable(stInst.hwndFrame,IDM_UNINSTALL,FALSE); if (!bPreviousInstallation) if (!bCOMiInstalled) MenuItemEnable(stInst.hwndFrame,IDM_SETUP,FALSE); // MenuItemEnable(stInst.hwndFrame,IDM_TRANSFER,FALSE); break; case WM_DESTROY: GpiDestroyPS(hpsPs); break; case WM_HELP: if (SHORT1FROMMP(mp2) & CMDSRC_PUSHBUTTON) { DisplayHelpPanel(SHORT1FROMMP(mp1)); return((MRESULT)FALSE); } break; case HM_QUERY_KEYS_HELP: return (MRESULT)HLPP_KEYS; case WM_ACTIVATE: if(SHORT1FROMMP(mp1)) { WinSetFocus(HWND_DESKTOP,stInst.hwndFrame); WinSendMsg(WinQueryHelpInstance(hwndClient),HM_SET_ACTIVE_WINDOW,0L,0L); } break; case WM_PAINT: ClientPaint(hwnd); break; case WM_COMMAND: InstallCommand(hwnd,SHORT1FROMMP(mp1)); break; default: return WinDefWindowProc(hwnd,msg,mp1,mp2); } return(FALSE); }
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); }
static VOID CreateROPBitmap(HWND hWnd) { BITMAPINFOHEADER bmp; /* Bitmap Information Header */ BITMAPINFOHEADER2 bminfo2; /* Bitmap Information Header */ HBITMAP hbmConstruct; /* Bitmap Handle */ HDC hDC; /* Device Context Handle */ HPS hpsBitmap; /* Bitmap Presentation Space Handle */ LONG cFormats; /* Formats Count */ LONG lROP = 0L; /* ROP Value */ PLONG plFormats; /* Formats Array */ POINTL aptl[4]; /* Conversion Point */ RECTL rcl; /* Window Rectangle */ SIZEL sizl; /* Sizing Structure */ register INT i, n; /* Loop Counters */ if ( hbmROP ) GpiDeleteBitmap(hbmROP); GpiQueryBitmapParameters(hbmView, &bmp); /* Get bitmap device context handle for the main */ /* Client Window */ if ( !(hDC = DevOpenDC(hAB, OD_MEMORY, "*", 0L, 0L, 0L)) ) return((HBITMAP)NULL); /* Create bitmap presentation space specifying */ /* entire map Client Window for size required */ WinQueryWindowRect(hWnd, &rcl); lHorzRange = (cxROP = sizl.cx = bmp.cx * 16L + 150L) - (cxWindow = rcl.xRight - rcl.xLeft); lVertRange = (cyROP = sizl.cy = bmp.cy * 16L + 150L) - (cyWindow = rcl.yTop - rcl.yBottom); 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); rclROP.xLeft = 0L; rclROP.yBottom = cyROP - cyWindow; rclROP.xRight = cxWindow; rclROP.yTop = cyROP; cxImage = bmp.cx + 10L; cyImage = bmp.cy + 10L; if ( !(hpsBitmap = GpiCreatePS(hAB, hDC, &sizl, PU_PELS | GPIT_NORMAL | GPIA_ASSOC)) ) { /* Error occurred during creation of */ /* presentation space, close device context */ DevCloseDC(hDC); return((HBITMAP)NULL); } /* Get the number of bitmap formats that the */ /* display driver supports */ DevQueryCaps(hDC, CAPS_BITMAP_FORMATS, 1L, &cFormats); /* Get the bitmap display formats. The first */ /* set within the array will be the one that */ /* most closely matches the display device. */ GpiQueryDeviceBitmapFormats(hpsBitmap, cFormats * 2L, plFormats = (PLONG)malloc(2UL * cFormats * sizeof(LONG))); /* Create actual bitmap storage for colour wheel */ /* having the default plane and bit count */ memset(&bminfo2, 0, sizeof(BITMAPINFOHEADER2)); bminfo2.cbFix = sizeof(BITMAPINFOHEADER2); bminfo2.cx = (ULONG)sizl.cx; bminfo2.cy = (ULONG)sizl.cy; bminfo2.cPlanes = (USHORT)plFormats[0]; bminfo2.cBitCount = (USHORT)plFormats[1]; free(plFormats); if ( !(hbmConstruct = GpiCreateBitmap(hpsBitmap, &bminfo2, 0L, 0L, 0L)) ) { /* Error occurred during creation of bitmap */ /* storage, destroy presentation space created */ /* and close device context opened */ GpiDestroyPS(hpsBitmap); DevCloseDC(hDC); return((HBITMAP)NULL); } /* Set bitmap as current bitmap to use */ GpiSetBitmap(hpsBitmap, hbmConstruct); /* Draw the page */ GpiErase(hpsBitmap); aptl[0].x = 0L; aptl[0].y = sizl.cy - bmp.cy; aptl[1].x = bmp.cx; aptl[1].y = sizl.cy; aptl[2].x = aptl[2].y = 0L; aptl[3].x = bmp.cx; aptl[3].y = bmp.cy; GpiSetPattern(hpsBitmap, lPattern); for ( i = 0; i < 16; i++ ) { for ( n = 0; n < 16; n++ ) { rcl.xLeft = aptl[0].x; rcl.xRight = aptl[1].x + 1L; rcl.yBottom = aptl[0].y; rcl.yTop = aptl[1].y + 1L; WinFillRect(hpsBitmap, &rcl, lFillColour); GpiWCBitBlt(hpsBitmap, hbmView, 4L, aptl, lROP++, BBO_IGNORE); aptl[0].x += (bmp.cx + 10L); aptl[1].x += (bmp.cx + 10L); } aptl[0].y -= (bmp.cy + 10L); aptl[1].y -= (bmp.cy + 10L); aptl[0].x = 0L; aptl[1].x = bmp.cx; } /* Set the bitmap to allow completion of bitmap */ /* in memory */ GpiSetBitmap(hpsBitmap, (HDC)NULL); /* Destroy the memory device context */ GpiAssociate(hpsBitmap, (HDC)NULL); /* Destroy the presentation spaces used */ GpiDestroyPS(hpsBitmap); DevCloseDC(hDC); /* Return the bitmap handle that will be used in */ /* painting the image on the window */ hbmROP = hbmConstruct; }
HBITMAP SetupBitmapFromFile(HWND hwnd, char *pszFileName /*, long lVertical2*/) { HAB hab = WinQueryAnchorBlock(hwnd); PSTBFILE *pFile; HBITMAP hbm; if (DosAllocMem((PPVOID) & pFile, sizeof(PSTBFILE), PAG_READ | PAG_WRITE | PAG_COMMIT) != NO_ERROR) { return (NULLHANDLE); } memset(pFile, 0, sizeof(PSTBFILE)); if (PSMMFillImageFormat(pszFileName, &(pFile->mmFormat), &(pFile->mmioInfo)) != TRUE) { DosFreeMem(pFile); return (NULLHANDLE); } if ((pFile->hmmio = PSMMInitializeImageFile(pszFileName, &(pFile->mmioInfo), &(pFile->mmImgHdr))) == NULLHANDLE) { DosFreeMem(pFile); return (NULLHANDLE); } pFile->cbRow = ((pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx * pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount + 31) / 32) * 4; pFile->cbData = pFile->cbRow * pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy; if (DosAllocMem(&(pFile->pvImage), pFile->cbData, PAG_READ | PAG_WRITE | PAG_COMMIT) != NO_ERROR) { PSMMCloseImageFile(pFile->hmmio); DosFreeMem(pFile); return (NULLHANDLE); } if (PSMMReadImageFile(pFile->hmmio, pFile->pvImage, pFile->cbData) != TRUE) { DosFreeMem(pFile->pvImage); PSMMCloseImageFile(pFile->hmmio); DosFreeMem(pFile); } PSMMCloseImageFile(pFile->hmmio); // convert data to system bitcount pFile->hdc = DevOpenDC(hab, OD_MEMORY, "*", 0L, (PDEVOPENDATA) NULL, NULLHANDLE); pFile->slHPS.cx = pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx; pFile->slHPS.cy = pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy; pFile->hps = GpiCreatePS(hab, pFile->hdc, &(pFile->slHPS), PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC); pFile->hbm = GpiCreateBitmap(pFile->hps, &(pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2), 0L, NULL, NULL); GpiSetBitmap(pFile->hps, pFile->hbm); GpiSetBitmapBits(pFile->hps, 0L, (long) pFile->slHPS.cy, (PBYTE) pFile->pvImage, (PBITMAPINFO2) & (pFile->mmImgHdr.mmXDIBHeader.BMPInfoHeader2)); hbm = pFile->hbm; GpiDeleteBitmap(pFile->hbm); // free everything up GpiSetBitmap(pFile->hps, NULLHANDLE); GpiDestroyPS(pFile->hps); DevCloseDC(pFile->hdc); DosFreeMem(pFile->pvImage); DosFreeMem(pFile); return (hbm); }
static void _cairo_os2_surface_get_pixels_from_screen (cairo_os2_surface_t *surface, HPS hps_begin_paint, PRECTL prcl_begin_paint_rect) { HPS hps; HDC hdc; SIZEL sizlTemp; HBITMAP hbmpTemp; BITMAPINFO2 bmi2Temp; POINTL aptlPoints[4]; int y; unsigned char *pchTemp; /* To copy pixels from screen to our buffer, we do the following steps: * * - Blit pixels from screen to a HBITMAP: * -- Create Memory Device Context * -- Create a PS into it * -- Create a HBITMAP * -- Select HBITMAP into memory PS * -- Blit dirty pixels from screen to HBITMAP * - Copy HBITMAP lines (pixels) into our buffer * - Free resources */ /* Create a memory device context */ hdc = DevOpenDC (0, OD_MEMORY,"*",0L, NULL, NULLHANDLE); if (!hdc) { return; } /* Create a memory PS */ sizlTemp.cx = prcl_begin_paint_rect->xRight - prcl_begin_paint_rect->xLeft; sizlTemp.cy = prcl_begin_paint_rect->yTop - prcl_begin_paint_rect->yBottom; hps = GpiCreatePS (0, hdc, &sizlTemp, PU_PELS | GPIT_NORMAL | GPIA_ASSOC); if (!hps) { DevCloseDC (hdc); return; } /* Create an uninitialized bitmap. */ /* Prepare BITMAPINFO2 structure for our buffer */ memset (&bmi2Temp, 0, sizeof (bmi2Temp)); bmi2Temp.cbFix = sizeof (BITMAPINFOHEADER2); bmi2Temp.cx = sizlTemp.cx; bmi2Temp.cy = sizlTemp.cy; bmi2Temp.cPlanes = 1; bmi2Temp.cBitCount = 32; hbmpTemp = GpiCreateBitmap (hps, (PBITMAPINFOHEADER2) &bmi2Temp, 0, NULL, NULL); if (!hbmpTemp) { GpiDestroyPS (hps); DevCloseDC (hdc); return; } /* Select the bitmap into the memory device context. */ GpiSetBitmap (hps, hbmpTemp); /* Target coordinates (Noninclusive) */ aptlPoints[0].x = 0; aptlPoints[0].y = 0; aptlPoints[1].x = sizlTemp.cx; aptlPoints[1].y = sizlTemp.cy; /* Source coordinates (Inclusive) */ aptlPoints[2].x = prcl_begin_paint_rect->xLeft; aptlPoints[2].y = surface->bitmap_info.cy - prcl_begin_paint_rect->yBottom; aptlPoints[3].x = prcl_begin_paint_rect->xRight; aptlPoints[3].y = surface->bitmap_info.cy - prcl_begin_paint_rect->yTop; /* Blit pixels from screen to bitmap */ GpiBitBlt (hps, hps_begin_paint, 4, aptlPoints, ROP_SRCCOPY, BBO_IGNORE); /* Now we have to extract the pixels from the bitmap. */ pchTemp = surface->pixels + (prcl_begin_paint_rect->yBottom)*surface->bitmap_info.cx*4 + prcl_begin_paint_rect->xLeft*4; for (y = 0; y < sizlTemp.cy; y++) { /* Get one line of pixels */ GpiQueryBitmapBits (hps, sizlTemp.cy - y - 1, /* lScanStart */ 1, /* lScans */ (PBYTE)pchTemp, &bmi2Temp); /* Go for next line */ pchTemp += surface->bitmap_info.cx*4; } /* Clean up resources */ GpiSetBitmap (hps, (HBITMAP) NULL); GpiDeleteBitmap (hbmpTemp); GpiDestroyPS (hps); DevCloseDC (hdc); }
nsresult nsIconChannel::MakeInputStream(nsIInputStream **_retval, bool nonBlocking) { // get some details about this icon nsCOMPtr<nsIFile> localFile; uint32_t desiredImageSize; nsXPIDLCString contentType; nsAutoCString filePath; nsresult rv = ExtractIconInfoFromUrl(getter_AddRefs(localFile), &desiredImageSize, contentType, filePath); NS_ENSURE_SUCCESS(rv, rv); // if the file exists, get its path bool fileExists = false; if (localFile) { localFile->GetNativePath(filePath); localFile->Exists(&fileExists); } // get the file's icon from either the WPS or PM bool fWpsIcon = false; HPOINTER hIcon = GetIcon(filePath, fileExists, desiredImageSize <= 16, &fWpsIcon); if (hIcon == NULLHANDLE) return NS_ERROR_FAILURE; // get the color & mask bitmaps used by the icon POINTERINFO IconInfo; if (!WinQueryPointerInfo(hIcon, &IconInfo)) { DestroyIcon(hIcon, fWpsIcon); return NS_ERROR_FAILURE; } // if we need a mini-icon, use those bitmaps if present; // otherwise, signal that the icon needs to be shrunk bool fShrink = FALSE; if (desiredImageSize <= 16) { if (IconInfo.hbmMiniPointer) { IconInfo.hbmColor = IconInfo.hbmMiniColor; IconInfo.hbmPointer = IconInfo.hbmMiniPointer; } else { fShrink = TRUE; } } // various resources to be allocated PBITMAPINFO2 pBMInfo = 0; uint8_t* pInBuf = 0; uint8_t* pOutBuf = 0; HDC hdc = 0; HPS hps = 0; // using this dummy do{...}while(0) "loop" guarantees that resources will // be deallocated, but eliminates the need for nesting, and generally makes // testing for & dealing with errors pretty painless (just 'break') do { rv = NS_ERROR_FAILURE; // get the details for the color bitmap; if there isn't one // or this is 1-bit color, exit BITMAPINFOHEADER2 BMHeader; BMHeader.cbFix = sizeof(BMHeader); if (!IconInfo.hbmColor || !GpiQueryBitmapInfoHeader(IconInfo.hbmColor, &BMHeader) || BMHeader.cBitCount == 1) break; // alloc space for the color bitmap's info, including its color table uint32_t cbBMInfo = sizeof(BITMAPINFO2) + (sizeof(RGB2) * 255); pBMInfo = (PBITMAPINFO2)nsMemory::Alloc(cbBMInfo); if (!pBMInfo) break; // alloc space for the color bitmap data uint32_t cbInRow = ALIGNEDBPR(BMHeader.cx, BMHeader.cBitCount); uint32_t cbInBuf = cbInRow * BMHeader.cy; pInBuf = (uint8_t*)nsMemory::Alloc(cbInBuf); if (!pInBuf) break; memset(pInBuf, 0, cbInBuf); // alloc space for the BGRA32 bitmap we're creating uint32_t cxOut = fShrink ? BMHeader.cx / 2 : BMHeader.cx; uint32_t cyOut = fShrink ? BMHeader.cy / 2 : BMHeader.cy; uint32_t cbOutBuf = 2 + ALIGNEDBPR(cxOut, 32) * cyOut; pOutBuf = (uint8_t*)nsMemory::Alloc(cbOutBuf); if (!pOutBuf) break; memset(pOutBuf, 0, cbOutBuf); // create a DC and PS DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL}; hdc = DevOpenDC((HAB)0, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE); if (!hdc) break; SIZEL sizel = {0,0}; hps = GpiCreatePS((HAB)0, hdc, &sizel, GPIA_ASSOC | PU_PELS | GPIT_MICRO); if (!hps) break; // get the color bits memset(pBMInfo, 0, cbBMInfo); *((PBITMAPINFOHEADER2)pBMInfo) = BMHeader; GpiSetBitmap(hps, IconInfo.hbmColor); if (GpiQueryBitmapBits(hps, 0L, (LONG)BMHeader.cy, (BYTE*)pInBuf, pBMInfo) <= 0) break; // The first 2 bytes are the width & height of the icon in pixels, // the remaining bytes are BGRA32 (B in first byte, A in last) uint8_t* outPtr = pOutBuf; *outPtr++ = (uint8_t)cxOut; *outPtr++ = (uint8_t)cyOut; // convert the color bitmap pBMInfo->cbImage = cbInBuf; ConvertColorBitMap(pInBuf, pBMInfo, outPtr, fShrink); // now we need to tack on the alpha data, so jump back to the first // pixel in the output buffer outPtr = pOutBuf+2; // Get the mask info BMHeader.cbFix = sizeof(BMHeader); if (!GpiQueryBitmapInfoHeader(IconInfo.hbmPointer, &BMHeader)) break; // if the existing input buffer isn't large enough, reallocate it cbInRow = ALIGNEDBPR(BMHeader.cx, BMHeader.cBitCount); if ((cbInRow * BMHeader.cy) > cbInBuf) // Need more for mask { cbInBuf = cbInRow * BMHeader.cy; nsMemory::Free(pInBuf); pInBuf = (uint8_t*)nsMemory::Alloc(cbInBuf); memset(pInBuf, 0, cbInBuf); } // get the mask/alpha bits memset(pBMInfo, 0, cbBMInfo); *((PBITMAPINFOHEADER2)pBMInfo) = BMHeader; GpiSetBitmap(hps, IconInfo.hbmPointer); if (GpiQueryBitmapBits(hps, 0L, (LONG)BMHeader.cy, (BYTE*)pInBuf, pBMInfo) <= 0) break; // convert the mask/alpha bitmap pBMInfo->cbImage = cbInBuf; ConvertMaskBitMap(pInBuf, pBMInfo, outPtr, fShrink); // create a pipe nsCOMPtr<nsIInputStream> inStream; nsCOMPtr<nsIOutputStream> outStream; rv = NS_NewPipe(getter_AddRefs(inStream), getter_AddRefs(outStream), cbOutBuf, cbOutBuf, nonBlocking); if (NS_FAILED(rv)) break; // put our data into the pipe uint32_t written; rv = outStream->Write(reinterpret_cast<const char*>(pOutBuf), cbOutBuf, &written); if (NS_FAILED(rv)) break; // success! so addref the pipe NS_ADDREF(*_retval = inStream); } while (0); // free all the resources we allocated if (pOutBuf) nsMemory::Free(pOutBuf); if (pInBuf) nsMemory::Free(pInBuf); if (pBMInfo) nsMemory::Free(pBMInfo); if (hps) { GpiAssociate(hps, NULLHANDLE); GpiDestroyPS(hps); } if (hdc) DevCloseDC(hdc); if (hIcon) DestroyIcon(hIcon, fWpsIcon); return rv; }
// ******************************************************************************* // FUNCTION: DuplicateBitmap // // FUNCTION USE: Duplicates a bitmap // // DESCRIPTION: Uses GpiBitBlt to make a copy of a bitmap by bit-bliting the // contents of the source PS containing the bitmap, to the target // presentation space. // // PARAMETERS: HBITMAP source bitmap handle to copy // // RETURNS: HBITMAP target bitmap handle // // HISTORY: // // ******************************************************************************* HBITMAP DuplicateBitmap (HBITMAP hbmSource, HPS hpsSource) { HAB hab; HBITMAP hbmTarget; HBITMAP hbmOld; HDC hdcSource = NULLHANDLE; HDC hdcTarget = NULLHANDLE; HPS hpsTarget; SIZEL sizl; POINTL aptl[3]; BOOL bError = FALSE; BITMAPINFOHEADER2 bmp2; ERRORID errorid; CHAR szBuffer[CCHMAXPATH]; PSZ pszDevData[9] = {0, "MEMORY", 0, 0, 0, 0, 0, 0, 0}; // -------------------------------------------------------------------------- // Get an anchor block handle // -------------------------------------------------------------------------- hab = WinQueryAnchorBlock(HWND_DESKTOP); // -------------------------------------------------------------------------- // Create memory device context handles and presentation space handles // -------------------------------------------------------------------------- hdcSource = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULLHANDLE); if (!hdcSource) DisplayMessages(NULLHANDLE, "no hdcSource", MSG_INFO); hdcTarget = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULLHANDLE); if (!hdcTarget) DisplayMessages(NULLHANDLE, "no hdcSource", MSG_INFO); // -------------------------------------------------------------------------- // Set presentation space size // -------------------------------------------------------------------------- sizl.cx = 0; sizl.cy = 0; // -------------------------------------------------------------------------- // If we don't have a source PS get one // -------------------------------------------------------------------------- if (!hpsSource) { hpsSource = GpiCreatePS (hab, hdcSource, &sizl, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC); if (!hpsSource) DisplayMessages(NULLHANDLE, "no hpsSource", MSG_INFO); } // -------------------------------------------------------------------------- // Create our target presentation space // -------------------------------------------------------------------------- hpsTarget = GpiCreatePS (hab, hdcTarget, &sizl, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC); if (!hpsTarget) DisplayMessages(NULLHANDLE, "no hpsTarget", MSG_INFO); // -------------------------------------------------------------------------- // Initialize the bitmap info header structure // -------------------------------------------------------------------------- memset(&bmp2, 0, sizeof(BITMAPINFOHEADER2)); // -------------------------------------------------------------------------- // Set the size of the structure // -------------------------------------------------------------------------- bmp2.cbFix = sizeof (BITMAPINFOHEADER2); // -------------------------------------------------------------------------- // Get the bitmap information header from the source bitmap // -------------------------------------------------------------------------- GpiQueryBitmapInfoHeader (hbmSource, &bmp2); // -------------------------------------------------------------------------- // Create our target bitmap using the bitmap information header from // our source bitmap. // -------------------------------------------------------------------------- hbmTarget = GpiCreateBitmap (hpsTarget, &bmp2, 0L, NULL, NULL); if (hbmTarget == GPI_ERROR) { // -------------------------------------------------------------------------- // If we get an error creating the bitmap set the bError flag to TRUE // so we can return GPI_ERROR telling the caller that the function failed. // -------------------------------------------------------------------------- bError = TRUE; } // -------------------------------------------------------------------------- // If everything is cool, set the bitmaps into our presentation spaces. // -------------------------------------------------------------------------- else { hbmOld = GpiSetBitmap (hpsSource, hbmSource); if (hbmOld == HBM_ERROR) { errorid = WinGetLastError(hab); sprintf(szBuffer, "GpiSetBitmap failed setting hbmSource into hpsSource\nLast Error = %8.8x", errorid); DisplayMessages(NULLHANDLE, szBuffer, MSG_INFO); } hbmOld = GpiSetBitmap (hpsTarget, hbmTarget); if (hbmOld == HBM_ERROR) { errorid = WinGetLastError(hab); sprintf(szBuffer, "GpiSetBitmap failed setting hbmTarget into hpsTarget\nLast Error = %8.8x", errorid); DisplayMessages(NULLHANDLE, szBuffer, MSG_INFO); } aptl[0].x = 0; aptl[0].y = 0; aptl[1].x = bmp2.cx; aptl[1].y = bmp2.cy; aptl[2].x = 0; aptl[2].y = 0; // -------------------------------------------------------------------------- // Bit blit the contents of the source presentation space into our target // presentation space. This is how we copy the bitmap from the source to // the target. // -------------------------------------------------------------------------- bError = GpiBitBlt (hpsTarget, // Target presentation space handle hpsSource, // Source presentation space handle 3L, // Number of Points aptl, // Array of Points ROP_SRCCOPY, // Mixing function (source copy) BBO_IGNORE); // Options // -------------------------------------------------------------------------- // If we get an error copying from our source PS to our target PS // set the error flag to TRUE so that we can return GPI_ERROR back // to the caller. // -------------------------------------------------------------------------- if (bError == GPI_ERROR) { bError = TRUE; errorid = WinGetLastError(hab); sprintf(szBuffer, "Error on BitBlt is %8.8x", errorid); DisplayMessages(NULLHANDLE, szBuffer, MSG_INFO); } // -------------------------------------------------------------------------- // If we got a value back from GpiBitBlt reset our error flag since // bError would be TRUE. // -------------------------------------------------------------------------- else { bError = FALSE; } } // -------------------------------------------------------------------------- // Regardless of what happens, we will free all of our graphics engine // resources by destroying our presentation spaces and device context // handles. // -------------------------------------------------------------------------- // GpiDestroyPS (hpsSource); GpiDestroyPS (hpsTarget); DevCloseDC (hdcSource); DevCloseDC (hdcTarget); // -------------------------------------------------------------------------- // If we get an error trying to duplicate the bitmap, return GPI_ERROR. // -------------------------------------------------------------------------- if (bError) { return GPI_ERROR; } // -------------------------------------------------------------------------- // If everthing worked like a champ, return the bitmap handle. // -------------------------------------------------------------------------- else { return hbmTarget; } }