CPP FILE
***********
#include "stdafx.h"
#include "Bitmap1.h"
#include "Bitmap1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CBitmap1Dlg::CBitmap1Dlg(CWnd* pParent )
: CDialog(CBitmap1Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CBitmap1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CBitmap1Dlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_ERASEBKGND()
ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
BOOL CBitmap1Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); SetIcon(m_hIcon, FALSE);
m_picture.Create(NULL, WS_CHILD|WS_VISIBLE|BS_BITMAP,CRect(10,10,400,50), this, IDC_PICTURE);
hBitmap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1));
m_picture.SetBitmap(hBitmap);
return TRUE; }
void CBitmap1Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<wparam>(dc.GetSafeHdc()), 0);
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
hBitmap = MakeBitMapTransparent(hBitmap);
m_picture.SetBitmap(hBitmap);
}
}
HCURSOR CBitmap1Dlg::OnQueryDragIcon()
{
return static_cast<hcursor>(m_hIcon);
}
BOOL CBitmap1Dlg::OnEraseBkgnd(CDC* pDC)
{
CRect r;
GetClientRect(&r);
CBrush br(RGB(0,100,0));
pDC->SelectObject(br);
pDC->FillRect(r,&br);
return TRUE;
}
HBRUSH CBitmap1Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
CBrush br(RGB(0,255,0));
return (HBRUSH)br;
}</hcursor></wparam>
*************************
*.h file
*********
#pragma once
#include "afxwin.h"
#include "afxext.h"
class CBitmap1Dlg : public CDialog
{
public:
CBitmap1Dlg(CWnd* pParent = NULL); HBITMAP hBitmap;
enum { IDD = IDD_BITMAP1_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
HICON m_hIcon;
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg BOOL OnEraseBkgnd(CDC*);
afx_msg HBRUSH OnCtlColor(CDC* , CWnd* , UINT );
DECLARE_MESSAGE_MAP()
public:
CBitmapButton m_picture;
};
This is the solution
The
afx_msg BOOL OnEraseBkgnd(CDC*);
afx_msg HBRUSH OnCtlColor(CDC* , CWnd* , UINT );
These two function will change the background
Thanks