void SimpleCanvas::setBitmapSize(int sizeX, int sizeY) { HBITMAP newBM = CreateCompatibleBitmap(DC(), sizeX, sizeY); SetBitmapDimensionEx(newBM, sizeX, sizeY, 0); if (mOffScreenBM) { // Copy as much of the old contents as possible into the new bitmap HDC tempDC = CreateCompatibleDC(DC()); HGDIOBJ defaultBM = SelectObject(tempDC, newBM); // Perform the copy from old to new SIZE oldBMSize; GetBitmapDimensionEx(mOffScreenBM, &oldBMSize); BitBlt(tempDC, 0, 0, oldBMSize.cx, oldBMSize.cy, offScreenDC(), 0, 0, SRCCOPY); // Select clean up and select new bitmap SelectObject(tempDC, defaultBM); DeleteDC(tempDC); HGDIOBJ oldBM = SelectObject(offScreenDC(), newBM); assert(oldBM == mOffScreenBM); DeleteObject(mOffScreenBM); } else { SelectObject(offScreenDC(), newBM); } mOffScreenBM = newBM; }
static PetscErrorCode PetscDrawResizeWindow_Win32(PetscDraw draw,int w,int h) { PetscDraw_Win32 *windraw = (PetscDraw_Win32*)draw->data; RECT r; PetscFunctionBegin; GetWindowRect(windraw->hWnd,&r); MoveWindow(windraw->hWnd,r.left,r.top,(int)w,(int)h,TRUE); /* set all variable dealing with window dimensions */ windraw->node->bitheight = windraw->h = draw->h = h; windraw->node->bitwidth = windraw->w = draw->w = w; /* set up graphic buffers with the new size of window */ SetBitmapDimensionEx(windraw->node->BufferBit,w,h,NULL); if (windraw->node->DoubleBuffered) SetBitmapDimensionEx(windraw->node->DoubleBufferBit,w,h,NULL); windraw->haveresized = PETSC_TRUE; PetscFunctionReturn(0); }
void GDITest(void) { ENUMLOGFONTEXW enumlog; EXTLOGFONTW extlog; memset(& enumlog, 0, sizeof(enumlog)); memset(& extlog, 0, sizeof(extlog)); int j = sizeof(enumlog); int k = sizeof(extlog); for (int i=0; i<sizeof(FIXARRAY)/sizeof(long); i++) { char t[20]; long v = FIXARRAY[i]; if ( v >= 0) t[0] = '+'; else { t[0] = '-'; v = - v; } sprintf(t+1, "%d + %d/16\n", v/16, v%16); OutputDebugString(t); } HDC hDC = GetDC(NULL); HBITMAP bmp1 = CreateBitmap(100, 100, 1, 1, NULL); HBITMAP bmp2 = CreateBitmap(100, 100, 1, 4, NULL); HBITMAP bmp3 = CreateBitmap(100, 100, 1, 8, NULL); HBITMAP bmp4 = CreateBitmap(100, 100, 3, 8, NULL); HBITMAP bmp5 = CreateBitmap(100, 100, 1, 24, NULL); void * dibbits; HBITMAP bmp6 = CreateDIBSection(hDC, (BITMAPINFO *) & dib, DIB_RGB_COLORS, & dibbits, NULL, 0); BeginPath(hDC); MoveToEx(hDC, 100, 100, NULL); LineTo(hDC, 150, 150); PolyBezierTo(hDC, & Points[0], 3); CloseFigure(hDC); Ellipse(hDC, -100, -100, 100, 100); EndPath(hDC); POINT points[20]; BYTE types[20]; int n = GetPath(hDC, NULL, NULL, 0); n = GetPath(hDC, points, types, min(n, 20)); SetBitmapDimensionEx(bmp1, 10000, 10000, NULL); }
HBITMAP Explorerplusplus::CaptureTabScreenshot(int iTabId) { HDC hdc; HDC hdcSrc; HBITMAP hBitmap; HBITMAP hPrevBitmap; Gdiplus::Color color(0,0,0); RECT rcMain; RECT rcTab; HWND hTab = m_hListView[iTabId]; GetClientRect(m_hContainer,&rcMain); GetClientRect(hTab,&rcTab); /* Main window BitBlt. */ hdc = GetDC(m_hContainer); hdcSrc = CreateCompatibleDC(hdc); /* Any bitmap sent back to the operating system will need to be in 32-bit ARGB format. */ Gdiplus::Bitmap bi(GetRectWidth(&rcMain),GetRectHeight(&rcMain),PixelFormat32bppARGB); bi.GetHBITMAP(color,&hBitmap); /* BitBlt the main window into the bitmap. */ hPrevBitmap = (HBITMAP)SelectObject(hdcSrc,hBitmap); BitBlt(hdcSrc,0,0,GetRectWidth(&rcMain),GetRectHeight(&rcMain),hdc,0,0,SRCCOPY); /* Now BitBlt the tab onto the main window. */ HDC hdcTab; HDC hdcTabSrc; HBITMAP hbmTab; HBITMAP hbmTabPrev; BOOL bVisible; hdcTab = GetDC(hTab); hdcTabSrc = CreateCompatibleDC(hdcTab); hbmTab = CreateCompatibleBitmap(hdcTab,GetRectWidth(&rcTab),GetRectHeight(&rcTab)); hbmTabPrev = (HBITMAP)SelectObject(hdcTabSrc,hbmTab); bVisible = IsWindowVisible(hTab); if(!bVisible) { ShowWindow(hTab,SW_SHOW); } PrintWindow(hTab,hdcTabSrc,PW_CLIENTONLY); if(!bVisible) { ShowWindow(hTab,SW_HIDE); } MapWindowPoints(hTab,m_hContainer,(LPPOINT)&rcTab,2); BitBlt(hdcSrc,rcTab.left,rcTab.top,GetRectWidth(&rcTab),GetRectHeight(&rcTab),hdcTabSrc,0,0,SRCCOPY); SelectObject(hdcTabSrc,hbmTabPrev); DeleteObject(hbmTab); DeleteDC(hdcTabSrc); ReleaseDC(hTab,hdcTab); /* Shrink the bitmap. */ HDC hdcThumbnailSrc; HBITMAP hbmThumbnail; POINT pt; hdcThumbnailSrc = CreateCompatibleDC(hdc); /* Thumbnail bitmap. */ Gdiplus::Bitmap bmpThumbnail(GetRectWidth(&rcMain),GetRectHeight(&rcMain),PixelFormat32bppARGB); bmpThumbnail.GetHBITMAP(color,&hbmThumbnail); hPrevBitmap = (HBITMAP)SelectObject(hdcThumbnailSrc,hbmThumbnail); /* Finally, shrink the full-scale bitmap down into a thumbnail. */ SetStretchBltMode(hdcThumbnailSrc,HALFTONE); SetBrushOrgEx(hdcThumbnailSrc,0,0,&pt); BitBlt(hdcThumbnailSrc,0,0,GetRectWidth(&rcMain),GetRectHeight(&rcMain),hdcSrc,0,0,SRCCOPY); SetBitmapDimensionEx(hbmThumbnail,GetRectWidth(&rcMain),GetRectHeight(&rcMain),NULL); SelectObject(hdcThumbnailSrc,hPrevBitmap); DeleteDC(hdcThumbnailSrc); DeleteObject(hBitmap); SelectObject(hdcSrc,hPrevBitmap); DeleteDC(hdcSrc); ReleaseDC(m_hContainer,hdc); return hbmThumbnail; }
LRESULT CALLBACK Explorerplusplus::TabProxyWndProc(HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam,int iTabId) { switch(Msg) { case WM_ACTIVATE: /* Restore the main window if necessary, and switch to the actual tab. */ if(IsIconic(m_hContainer)) { ShowWindow(m_hContainer,SW_RESTORE); } OnSelectTab(iTabId,FALSE); return 0; break; case WM_SETFOCUS: SetFocus(m_hListView[iTabId]); break; case WM_SYSCOMMAND: switch(wParam) { case SC_CLOSE: break; default: SendMessage(m_hListView[iTabId],WM_SYSCOMMAND,wParam,lParam); break; } break; /* Generate a thumbnail of the current tab. Basic procedure: 1. Generate a full-scale bitmap of the main window. 2. Overlay a bitmap of the specified tab onto the main window bitmap. 3. Shrink the resulting bitmap down to the correct thumbnail size. A thumbnail will be dynamically generated, provided the main window is not currently minimized (as we won't be able to grap a screenshot of it). If the main window is minimized, we'll use a cached screenshot of the tab (taken before the main window was minimized). */ case WM_DWMSENDICONICTHUMBNAIL: { HDC hdc; HDC hdcSrc; HBITMAP hbmTab = NULL; HBITMAP hPrevBitmap; Gdiplus::Color color(0,0,0); HRESULT hr; int iBitmapWidth; int iBitmapHeight; int iWidth; int iHeight; int iMaxWidth; int iMaxHeight; iMaxWidth = HIWORD(lParam); iMaxHeight = LOWORD(lParam); /* If the main window is minimized, it won't be possible to generate a thumbnail for any of the tabs. In that case, use a static 'No Preview Available' bitmap. */ if(IsIconic(m_hContainer)) { hbmTab = (HBITMAP)LoadImage(GetModuleHandle(0),MAKEINTRESOURCE(IDB_NOPREVIEWAVAILABLE),IMAGE_BITMAP,0,0,0); SetBitmapDimensionEx(hbmTab,223,130,NULL); } else { hbmTab = CaptureTabScreenshot(iTabId); } SIZE sz; GetBitmapDimensionEx(hbmTab,&sz); iBitmapWidth = sz.cx; iBitmapHeight = sz.cy; /* Shrink the bitmap. */ HDC hdcThumbnailSrc; HBITMAP hbmThumbnail; POINT pt; hdc = GetDC(m_hContainer); hdcSrc = CreateCompatibleDC(hdc); SelectObject(hdcSrc,hbmTab); hdcThumbnailSrc = CreateCompatibleDC(hdc); /* If the current height of the main window is less than the width, we'll create a thumbnail of maximum width; else maximum height. */ if((iBitmapWidth / iMaxWidth) > (iBitmapHeight / iMaxHeight)) { iWidth = iMaxWidth; iHeight = iMaxWidth * iBitmapHeight / iBitmapWidth; } else { iHeight = iMaxHeight; iWidth = iMaxHeight * iBitmapWidth / iBitmapHeight; } /* Thumbnail bitmap. */ Gdiplus::Bitmap bmpThumbnail(iWidth,iHeight,PixelFormat32bppARGB); bmpThumbnail.GetHBITMAP(color,&hbmThumbnail); hPrevBitmap = (HBITMAP)SelectObject(hdcThumbnailSrc,hbmThumbnail); /* Finally, shrink the full-scale bitmap down into a thumbnail. */ SetStretchBltMode(hdcThumbnailSrc,HALFTONE); SetBrushOrgEx(hdcThumbnailSrc,0,0,&pt); StretchBlt(hdcThumbnailSrc,0,0,iWidth,iHeight,hdcSrc,0,0,iBitmapWidth,iBitmapHeight,SRCCOPY); SelectObject(hdcThumbnailSrc,hPrevBitmap); DeleteDC(hdcThumbnailSrc); HMODULE hDwmapi; DwmSetIconicThumbnailProc DwmSetIconicThumbnail; hDwmapi = LoadLibrary(_T("dwmapi.dll")); if(hDwmapi != NULL) { DwmSetIconicThumbnail = (DwmSetIconicThumbnailProc)GetProcAddress(hDwmapi,"DwmSetIconicThumbnail"); if(DwmSetIconicThumbnail != NULL) { hr = DwmSetIconicThumbnail(hwnd,hbmThumbnail,0); } } FreeLibrary(hDwmapi); /* Delete the thumbnail bitmap. */ DeleteObject(hbmTab); SelectObject(hdcSrc,hPrevBitmap); DeleteObject(hbmThumbnail); DeleteDC(hdcSrc); ReleaseDC(m_hContainer,hdc); return 0; } break; case WM_DWMSENDICONICLIVEPREVIEWBITMAP: { HMODULE hDwmapi; TabPreviewInfo_t tpi; DwmSetIconicLivePreviewBitmapProc DwmSetIconicLivePreviewBitmap; tpi.hbm = NULL; if(IsIconic(m_hContainer)) { /* TODO: Show an image here... */ } else { GetTabLivePreviewBitmap(iTabId,&tpi); } hDwmapi = LoadLibrary(_T("dwmapi.dll")); if(hDwmapi != NULL) { DwmSetIconicLivePreviewBitmap = (DwmSetIconicLivePreviewBitmapProc)GetProcAddress(hDwmapi,"DwmSetIconicLivePreviewBitmap"); if(DwmSetIconicLivePreviewBitmap != NULL) { DwmSetIconicLivePreviewBitmap(hwnd,tpi.hbm,&tpi.ptOrigin,0); } } FreeLibrary(hDwmapi); if(tpi.hbm != NULL) { DeleteObject(tpi.hbm); } return 0; } break; case WM_CLOSE: { TCITEM tcItem; int nTabs; int i = 0; nTabs = TabCtrl_GetItemCount(m_hTabCtrl); if(nTabs == 1) { /* If this is the last tab, we'll close the whole application. */ SendMessage(m_hContainer,WM_CLOSE,0,0); } else { for(i = 0;i < nTabs;i++) { tcItem.mask = TCIF_PARAM; TabCtrl_GetItem(m_hTabCtrl,i,&tcItem); if((int)tcItem.lParam == iTabId) { /* Close the tab... */ CloseTab(i); break; } } } } break; } return DefWindowProc(hwnd,Msg,wParam,lParam); }