Introduction
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 "PictureBox.h"
class CMainFrame:
{
public:
WTL::CPictureBox m_PictureBox;
};
LRESULT CMainFrame::OnCreate(UINT , WPARAM ,
LPARAM , BOOL& )
{
m_hwndClient = m_PictureBox.Create(m_hWnd, rcDefault, NULL,
WS_VISIBLE|WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, WS_EX_CLIENTEDGE);
}
The create function of the
CPictureBox
works just like the create function of any
CWindowImpl
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.
The CPictureBox
functions
bool LoadBitmapFromFile(LPCTSTR pszFileName);
bool LoadBitmapFromID(HINSTANCE hInstance, UINT uiIDResource)
void SetBitmap(HBITMAP hBitmap, bool bOwner = true)
HBITMAP GetBitmap()
HBITMAP GetSaveBitmap()const
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.
Additional Information
For additional information, questions and bug report, visit my website: http://www.Trilobyte-Solutions.nl, or contact me at bertwillems@trilobyte-solutions.nl.