usetheforce2
11-21-2002, 09:47 PM
hello,
this code could be easially tailored to work with other common controls. But for this example i'm use the CStatic (for you vbr's "Label") control to display the image.
//====================================================================== ==========================
// programmer: usetheforce2
// date: november, 2002
// purpose: load image into a static control
// Important: If you copy paste this code make sure:
// 1. its a Win32 application type
// 2. press alt-f7 (project->settings) and choose the
// "Use MFC in a shared DLL" from the MFC drop down
//====================================================================== ==========================
#include<afxwin.h> // has all the code to do the dirty work
class bmpApp : public CWinApp
{
public:
virtual BOOL InitInstance(); // used to initialize the app (and main window)
};
bmpApp mainBmp; // declare main app object
class bmpWindow : public CFrameWnd
{
CStatic* m_sBmpImage; // private member static control
public:
bmpWindow();
};
BOOL bmpApp::InitInstance()
{
m_pMainWnd = new bmpWindow(); // assign our class window to the app main window
m_pMainWnd->ShowWindow(m_nCmdShow); // load window
m_pMainWnd->UpdateWindow(); // refresh window to ensure control are drawn properly
return TRUE; // return true to signify that the initiate completed properly
}
bmpWindow::bmpWindow()
{
// Create main window
Create(NULL,"Load Bitmap image!",WS_OVERLAPPEDWINDOW,CRect(200,200,545,300),this);
// Create static control
m_sBmpImage = new CStatic;
m_sBmpImage->Create("MAP:",WS_VISIBLE|WS_CHILD|SS_BITMAP, CRect(10,6,0,0),this);
// load bitmap into static control
// HBITMAP: accepts a handle to a bitmap created by the afxwin (loadimage()) function
// which returns a bitmap handle. the load image function has to be typecasted to return
// the HBITMAP handle type.
HBITMAP hnd;
hnd = (HBITMAP)LoadImage(0,"logo.bmp\0",IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_DEFAULTSIZE);
if(hnd == 0) // error trap
AfxMessageBox("Unable to create bitmap handle!");
else
m_sBmpImage->SetBitmap(hnd); // once a handle is obtained to a bitmap object
// we can use the SetBitmap() method
}
attached is the image used in the demo...
this code could be easially tailored to work with other common controls. But for this example i'm use the CStatic (for you vbr's "Label") control to display the image.
//====================================================================== ==========================
// programmer: usetheforce2
// date: november, 2002
// purpose: load image into a static control
// Important: If you copy paste this code make sure:
// 1. its a Win32 application type
// 2. press alt-f7 (project->settings) and choose the
// "Use MFC in a shared DLL" from the MFC drop down
//====================================================================== ==========================
#include<afxwin.h> // has all the code to do the dirty work
class bmpApp : public CWinApp
{
public:
virtual BOOL InitInstance(); // used to initialize the app (and main window)
};
bmpApp mainBmp; // declare main app object
class bmpWindow : public CFrameWnd
{
CStatic* m_sBmpImage; // private member static control
public:
bmpWindow();
};
BOOL bmpApp::InitInstance()
{
m_pMainWnd = new bmpWindow(); // assign our class window to the app main window
m_pMainWnd->ShowWindow(m_nCmdShow); // load window
m_pMainWnd->UpdateWindow(); // refresh window to ensure control are drawn properly
return TRUE; // return true to signify that the initiate completed properly
}
bmpWindow::bmpWindow()
{
// Create main window
Create(NULL,"Load Bitmap image!",WS_OVERLAPPEDWINDOW,CRect(200,200,545,300),this);
// Create static control
m_sBmpImage = new CStatic;
m_sBmpImage->Create("MAP:",WS_VISIBLE|WS_CHILD|SS_BITMAP, CRect(10,6,0,0),this);
// load bitmap into static control
// HBITMAP: accepts a handle to a bitmap created by the afxwin (loadimage()) function
// which returns a bitmap handle. the load image function has to be typecasted to return
// the HBITMAP handle type.
HBITMAP hnd;
hnd = (HBITMAP)LoadImage(0,"logo.bmp\0",IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_DEFAULTSIZE);
if(hnd == 0) // error trap
AfxMessageBox("Unable to create bitmap handle!");
else
m_sBmpImage->SetBitmap(hnd); // once a handle is obtained to a bitmap object
// we can use the SetBitmap() method
}
attached is the image used in the demo...