This code is extremely useful if you want to display images. It loads *.bmp *.jpg *.png and *.gif files from disk or from resources included in your program. The
control has scrollbar support and a build in context menu for easy usage which can be disabled.
Using the code
The following example assumes that you want the picture box to be in the client area of the main view.
#include <span class="code-string">"PictureBox.h"
LRESULT CMainFrame::OnCreate(UINT , WPARAM ,
LPARAM , BOOL& )
m_hwndClient = m_PictureBox.Create(m_hWnd, rcDefault, NULL,
The create function of the
works just like the create function of any
derived class. By default the control will position the bitmap in the center of the view, and it will use the build in context menu.
bool LoadBitmapFromFile(LPCTSTR pszFileName);
bool LoadBitmapFromID(HINSTANCE hInstance, UINT uiIDResource)
void SetBitmap(HBITMAP hBitmap, bool bOwner = true)
void CenterPicture(bool bCenter)
void StretchPicture(bool bStretch)
void UseMenu(bool bUseMenu)
Points of Interest
I wrote this code because WTL did not have any classes that could display *.jpg, *.png, *.gif or had scrollbar support.
For additional information, questions and bug report, visit my website: http://www.Trilobyte-Solutions.nl, or contact me at firstname.lastname@example.org.