Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's the code I use for loading images from disk.</p> <pre><code>// BMP, GIF, JPEG, PNG, TIFF, Exif, WMF, and EMF HBITMAP mLoadImg(WCHAR *szFilename) { HBITMAP result=NULL; Gdiplus::Bitmap* bitmap = new Gdiplus::Bitmap(szFilename,false); bitmap-&gt;GetHBITMAP(NULL, &amp;result); delete bitmap; return result; } </code></pre> <p><strong>Edit:</strong> Don't use GDI+ myself, other than for a few basic features. Whenever I use images, I generally want the smallest, fastest code possible - GDI does this job better imo.</p> <p>And here's the code ripped from a class that will display an image that has transparent pixels, complete with the class definition, so as to to (hopefully) avoid any ambiguity with class variables.</p> <pre><code>void CStaticImg::displayImage() { RECT myRect; BITMAP bm; HDC screenDC, memDC; HBITMAP oldBmp; BLENDFUNCTION bf; GetObject(mBmp, sizeof(bm), &amp;bm); bf.BlendOp = AC_SRC_OVER; bf.BlendFlags = 0; bf.SourceConstantAlpha = 0xff; bf.AlphaFormat = AC_SRC_ALPHA; screenDC = GetDC(mHwnd); GetClientRect(mHwnd, &amp;myRect); if (mBmp == NULL) FillRect(screenDC, &amp;myRect, WHITE_BRUSH); else { memDC = CreateCompatibleDC(screenDC); oldBmp = (HBITMAP)SelectObject(memDC, mBmp); AlphaBlend (screenDC, 0, 0, myRect.right,myRect.bottom, memDC, 0, 0, bm.bmWidth,bm.bmHeight, bf); SelectObject(memDC, oldBmp); DeleteDC(memDC); ReleaseDC(mHwnd, screenDC); } } class CStaticImg { public: CStaticImg(); ~CStaticImg(); void setImg(HBITMAP img); HBITMAP getImgCopy(); void attach(HWND tgt); void detach(); void setBkMode(bool transparent); protected: HWND mHwnd; HBITMAP mBmp; WNDPROC mOldWndProc; void displayImage(); virtual LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); bool isBkgTransparent; private: // virtual LRESULT onPaint(); LRESULT onCreate(); static CStaticImg *GetObjectFromWindow(HWND hWnd); static LRESULT CALLBACK stWinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload