HRESULT FirstTry::CreateDeviceResources() { HRESULT hr = S_OK; if (!m_pRenderTarget) { RECT rc; GetClientRect(m_hwnd, &rc); D2D1_SIZE_U size = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top); // Create a Direct2D render target. hr = m_pD2DFactory->CreateHwndRenderTarget( D2D1::RenderTargetProperties(), D2D1::HwndRenderTargetProperties(m_hwnd, size), &m_pRenderTarget); if (SUCCEEDED(hr)) { // Create a gray brush. hr = m_pRenderTarget->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::LightSlateGray), &m_pLightSlateGrayBrush); } if (SUCCEEDED(hr)) { // Create a blue brush. hr = m_pRenderTarget->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::CornflowerBlue), &m_pCornflowerBlueBrush); } // Create a bitmap from an application resource. if (SUCCEEDED(hr)) { hr = LoadResourceBitmap( m_pRenderTarget, m_pWICFactory, L"SAMPLEIMAGE", L"IMAGE", 0, 0, &m_pBitmap); } // Create a bitmap by loading it from a file. if (SUCCEEDED(hr)) { hr = LoadBitmapFromFile( m_pRenderTarget, m_pWICFactory, L".\\sampleImage.jpg", 0, 0, &m_pBitmap1); } } return hr; }
bool CCheckGridCell::LoadCheckBitmap() { if (m_hBitmapCheck != 0) { return true; } HINSTANCE hInst = AfxGetInstanceHandle(); m_hBitmapCheck = LoadResourceBitmap(hInst, MAKEINTRESOURCE(m_nBitmapResourceId)); if (m_hBitmapCheck == 0) { return false; } HANDLE hBitmap = m_hBitmapCheck; LPSTR lpDIB = (LPSTR)GlobalLock(hBitmap); DWORD dwColors = GetNumDIBColorEntries((LPBITMAPINFO)lpDIB); for (DWORD i = 0; i < dwColors; i++) { RGBQUAD* pColor = &((LPBITMAPINFO)lpDIB)->bmiColors[i]; COLORREF rgbOld = RGB(pColor->rgbRed, pColor->rgbGreen, pColor->rgbBlue); COLORREF rgbNew = GetColorValue(rgbOld); // replace color if (rgbOld != rgbNew) { pColor->rgbGreen = GetGValue(rgbNew); pColor->rgbBlue = GetBValue(rgbNew); pColor->rgbRed = GetRValue(rgbNew); } } GlobalUnlock(hBitmap); return true; }
BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/) { // check whether device supports palettes CClientDC dc(AfxGetMainWnd()); if ((dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE) != 0) m_bSupportPalette = TRUE; else m_bSupportPalette = FALSE; // load from resources according to palette support presence if (m_bSupportPalette) { HBITMAP hBitmap; HPALETTE hPalette; hBitmap = LoadResourceBitmap(NULL, (LPCTSTR)MAKELONG((WORD)VDBA_GetSplashScreen_Bitmap_id(), 0), hPalette); if (hBitmap == NULL) return FALSE; if (hPalette == NULL) { // No palette: try to load as a DDB if (!m_bitmap.LoadBitmap(VDBA_GetSplashScreen_Bitmap_id())) return FALSE; } else { m_bHasPalette = TRUE; m_bitmap.Attach(hBitmap); m_palette.Attach(hPalette); } } else { // load as a DDB if (!m_bitmap.LoadBitmap(VDBA_GetSplashScreen_Bitmap_id())) return FALSE; } // Get bitmap width/height, for window create BITMAP bm; m_bitmap.GetBitmap(&bm); // Create "Verdana 8" font for the copyright information. LOGFONT lf; // Used to create the CFont. memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure. lf.lfHeight = -9; // Request a 8-pixel-high font strcpy(lf.lfFaceName, "Verdana"); // with face name "Verdana". m_font.CreateFontIndirect(&lf); // Create the font. BOOL bSuccess; bSuccess = CreateEx(0, AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)), NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL); return bSuccess; }
BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/) { UINT image = IDB_SPLASH; if (!m_bitmap.LoadBitmap(image)) return FALSE; BITMAP bm; m_bitmap.GetBitmap(&bm); BOOL rc=CreateEx(0, AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)), NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL); m_hBitmap = LoadResourceBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(image)); m_pBitmap = CBitmap::FromHandle(m_hBitmap); return rc; }
VOID CCustomBitmap::PaintDCByResource(CDC* pDC, INT nResourceID) { HBITMAP hBitmap; HPALETTE hPalette; ASSERT_VALID(pDC); // Load bitmap handle from resource hBitmap = LoadResourceBitmap(nResourceID, &hPalette); ASSERT(hBitmap); ASSERT(hPalette); // Paint the DC PaintDCByHBitmap(pDC, hBitmap, FALSE); }
void Draw256Bitmap(HINSTANCE hInst, HDC hdc, UINT uiBmpID, short xStart, short yStart, int width, int height) { HBITMAP hBitmap,hOldBitmap; HPALETTE hPalette; HDC hMemDC; BITMAP bm; hBitmap = LoadResourceBitmap(hInst, MAKEINTRESOURCE(uiBmpID), &hPalette); GetObject(hBitmap, sizeof(BITMAP), &bm); hMemDC = CreateCompatibleDC(hdc); SelectPalette(hdc,hPalette,FALSE); RealizePalette(hdc); SelectPalette(hMemDC,hPalette,FALSE); RealizePalette(hMemDC); hOldBitmap = (HBITMAP)SelectObject(hMemDC,hBitmap); ::StretchBlt(hdc, xStart, yStart, width, height, hMemDC, xStart, yStart, bm.bmWidth, bm.bmHeight, SRCCOPY); DeleteObject( hPalette ); DeleteObject( hBitmap ); DeleteDC( hMemDC ); }
void Draw256Bitmap(HINSTANCE hInst, HDC hdc, UINT uiBmpID, const RECT& rcClient) { HBITMAP hBitmap,hOldBitmap; HPALETTE hPalette; HDC hMemDC; BITMAP bm; hBitmap = LoadResourceBitmap(hInst, MAKEINTRESOURCE(uiBmpID), &hPalette); GetObject(hBitmap, sizeof(BITMAP), &bm); hMemDC = CreateCompatibleDC(hdc); SelectPalette(hdc,hPalette,FALSE); RealizePalette(hdc); SelectPalette(hMemDC,hPalette,FALSE); RealizePalette(hMemDC); hOldBitmap = (HBITMAP)SelectObject(hMemDC,hBitmap); StretchBlt(hdc,rcClient.left,rcClient.top,rcClient.right-rcClient.left,rcClient.bottom-rcClient.top,hMemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY); DeleteObject( hPalette ); DeleteObject( hBitmap ); DeleteDC( hMemDC ); }
// Create device resources HRESULT DemoApp::CreateDeviceResources() { HRESULT hr = S_OK; if (!m_pRenderTarget) { RECT rc; GetClientRect(m_hwnd, &rc); D2D1_SIZE_U size = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top); // Create a Direct2D render target hr = m_pD2DFactory->CreateHwndRenderTarget( D2D1::RenderTargetProperties(), D2D1::HwndRenderTargetProperties(m_hwnd, size), &m_pRenderTarget); if (SUCCEEDED(hr)) { // Create a black brush hr = m_pRenderTarget->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::Black), &m_pBlackBrush); } if (SUCCEEDED(hr)) { ID2D1GradientStopCollection *pGradientStops = NULL; static const D2D1_GRADIENT_STOP stops[]= { {0.f,{0.f,1.f,1.f,0.25f}}, {1.f,{0.f,0.f,1.f,1.f}} }; hr = m_pRenderTarget->CreateGradientStopCollection( stops, ARRAYSIZE(stops), &pGradientStops); if (SUCCEEDED(hr)) { hr = m_pRenderTarget->CreateLinearGradientBrush( D2D1::LinearGradientBrushProperties( D2D1::Point2F(100, 0), D2D1::Point2F(100, 200)), D2D1::BrushProperties(), pGradientStops, &m_pLinearGradientBrush); pGradientStops->Release(); } } // Create a bitmap from an application resource hr = LoadResourceBitmap( m_pRenderTarget, m_pWICFactory, L"SampleImage", L"Image", 100, 0, &m_pBitmap); if (SUCCEEDED(hr)) { // Create a bitmap by loading it from a file hr = LoadBitmapFromFile( m_pRenderTarget, m_pWICFactory, L".\\sampleImage.jpg", 100, 0, &m_pAnotherBitmap); } if (SUCCEEDED(hr)) hr = CreateGridPatternBrush(m_pRenderTarget, &m_pGridPatternBitmapBrush); } return hr; }
HRESULT MetroWindow::CreateDeviceResources() { HRESULT hr = S_OK; if (!m_pRenderTarget) { RECT rc; ::GetClientRect(m_hWnd, &rc); D2D1_SIZE_U size = D2D1::SizeU( rc.right - rc.left, rc.bottom - rc.top ); hr = m_pDirect2dFactory->CreateHwndRenderTarget( D2D1::RenderTargetProperties(), D2D1::HwndRenderTargetProperties(m_hWnd, size), &m_pRenderTarget ); if (SUCCEEDED(hr)){ hr = CoCreateInstance( CLSID_WICImagingFactory1, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, reinterpret_cast<void **>(&m_pWICFactory) ); } if (SUCCEEDED(hr)) { hr = LoadResourceBitmap(m_pRenderTarget, m_pWICFactory, MAKEINTRESOURCE(IDP_TITLE_IMAGE), L"PNG", 0, 0, &m_pBitmap); } if (SUCCEEDED(hr)) { hr = LoadResourceBitmap(m_pRenderTarget, m_pWICFactory, MAKEINTRESOURCE(IDP_BACKGROUND_IMAGE), L"PNG", 0, 0, &m_pBitmapBkg); } if (SUCCEEDED(hr)) { hr = m_pRenderTarget->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::Silver), &m_pMinButtonActiveBrush ); } if (SUCCEEDED(hr)) { hr = m_pRenderTarget->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::Firebrick), &m_pCloseButtonClickBrush ); } if (SUCCEEDED(hr)) { hr = m_pRenderTarget->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::MediumBlue), &m_EdgeViewBrush ); } if (SUCCEEDED(hr)) { hr = m_pRenderTarget->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::White), &m_pLightWhiteBrush ); } if (SUCCEEDED(hr)) { hr = m_pRenderTarget->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::Gold), &m_pMetroButtonNsBrush ); } if (SUCCEEDED(hr)) { hr = m_pRenderTarget->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::Yellow), &m_pMetroButtonLsBrush ); } if (SUCCEEDED(hr)) { hr = m_pRenderTarget->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::Black), &m_pControlTextBrush ); } } return hr; }