I try through olectl.h- why it does not work. Here is the code.

static TCHAR szWindowClass[] = _T("winClass"); static TCHAR szTitle[] = _T("Pattern"); HINSTANCE hInst; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCSTR)IDI_ICON1); wcex.hCursor = LoadCursor(hInstance, (LPCSTR)IDC_CURSOR6); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wcex.lpszMenuName = NULL; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(hInstance, (LPCSTR)IDI_ICON1); if (!RegisterClassEx(&wcex)) { MessageBox(NULL,_T("Call to RegisterClassEx failed!"),_T("Win32 Guided Tour"),NULL); return 1; } hInst = hInstance; // Store instance handle in our global variable HWND hWnd = CreateWindow(szWindowClass,szTitle,WS_OVERLAPPEDWINDOW|WS_VISIBLE,CW_USEDEFAULT, CW_USEDEFAULT,800, 300,NULL,NULL, hInstance,NULL); if (!hWnd) { MessageBox(NULL,_T("Call to CreateWindow failed!"),_T("Win32 Guided Tour"), NULL); return 1; } /*ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd);*/ MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hDC; switch (message) { case WM_DESTROY: PostQuitMessage(0); break; /*case WM_PAINT: { PAINTSTRUCT ps; hDC = BeginPaint(hWnd, &ps); BITMAP bm; HDC hdcMem; HBITMAP back = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP3)); hdcMem = CreateCompatibleDC(hDC); SelectObject(hdcMem, back); GetObject(back, sizeof(BITMAP), (LPVOID)&bm); RECT r; GetClientRect(hWnd, &r); if (!bm.bmWidth || !bm.bmHeight) return 0; int w = r.right - r.left, h = r.bottom - r.top, bw = bm.bmWidth, bh = bm.bmHeight; StretchBlt(hDC, r.left, r.top, r.right, r.bottom, hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); EndPaint(hWnd, &ps); }*/ default: return DefWindowProc(hWnd, message, wParam, lParam); break; } return 0; } HRESULT Load(LPCTSTR szFile) { CComPtr <IStream> Stream; // Load the file to a memory stream HRESULT hr = FileToStream(szFile, &Stream); if (SUCCEEDED(hr)) { // Decode the picture hr = ::OleLoadPicture( Stream, // [in] Pointer to the stream that contains picture's data 0, // [in] Number of bytes read from the stream (0 == entire) true, // [in] Loose original format if true IID_IPicture, // [in] Requested interface (void**)&m_pPicture // [out] IPictire object on success ); } return hr; } HRESULT DrawImg(HDC hdc, const RECT& rcBounds) { if (m_pPicture) { // Get the width and the height of the picture long hmWidth = 0, hmHeight = 0; m_pPicture->get_Width(&hmWidth); m_pPicture->get_Height(&hmHeight); // Convert himetric to pixels int nWidth = MulDiv(hmWidth, ::GetDeviceCaps(hdc, LOGPIXELSX), HIMETRIC_INCH); int nHeight = MulDiv(hmHeight, ::GetDeviceCaps(hdc, LOGPIXELSY), HIMETRIC_INCH); // Display the picture using IPicture::Render return m_pPicture->Render( hdc, // [in] Handle of device context on which to render the image rcBounds.left, // [in] Horizontal position of image in hdc rcBounds.top, // [in] Vertical position of image in hdc rcBounds.right - rcBounds.left, // [in] Horizontal dimension of destination rectangle rcBounds.bottom - rcBounds.top, // [in] Vertical dimension of destination rectangle 0, // [in] Horizontal offset in source picture hmHeight, // [in] Vertical offset in source picture hmWidth, // [in] Amount to copy horizontally in source picture -hmHeight, // [in] Amount to copy vertically in source picture &rcBounds // [in, optional] Pointer to position of destination for a metafile hdc ); } return E_UNEXPECTED; } ` 
  • one
    OleLoadPicture supports only bmp, ico and wmf files. It would be better to use WIC . - VTT
  • one
    Use OleCreateFromFile, for example, like here.stackoverflow.com/questions/556781 ... It supports jpg and png additionally. - nick_n_a
  • For the same link - you can find how to use GDI +. - nick_n_a

0