Help Drawing into a Dialog
Hello,
What I have done now is simple draw a BITMAP into a dialogue
windows(adding a variable ellipse), it works fine, it display and I
can change the position of the ellipse in the map but I can not erase
the previous drawing, I think it is something because the
CDialog::OnInitDialog() is is not a part of the Dlg class, isn't it? I
am not sure what is going on here. I think I should be able to reset
the map only calling the CDialog::OnInitDialog() routine. But it doest
not work.
Thank you for any help here,
Regards,
Here is the code on *Dlg.cpp
// BitMapInDIALOGDlg.cpp : implementation file
//
#include "stdafx.h"
#include "BitMapInDIALOG.h"
#include "BitMapInDIALOGDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBitMapInDIALOGDlg dialog
CBitMapInDIALOGDlg::CBitMapInDIALOGDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBitMapInDIALOGDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBitMapInDIALOGDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in
Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CBitMapInDIALOGDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBitMapInDIALOGDlg)
DDX_Control(pDX, IDC_PICTURE, m_Picture);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBitMapInDIALOGDlg, CDialog)
//{{AFX_MSG_MAP(CBitMapInDIALOGDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_SubmitBtn, OnSubmitBtn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBitMapInDIALOGDlg message handlers
BOOL CBitMapInDIALOGDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this
automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
BITMAP BM;
BITMAP BMCLE; //for clear map no markrs
Bmp1.LoadBitmap (IDB_BITMAP1);
Bmp1CLE.LoadBitmap (IDB_BITMAP2);//for clear map no markrs
Bmp1.GetObject (sizeof (BM), &BM);
Bmp1CLE.GetObject (sizeof (BMCLE), &BMCLE);//for clear map no markrs
m_BitmapWidth = BM.bmWidth;
m_BitmapWidthCLE = BM.bmWidth;//for clear map no markrs
m_BitmapHeight = BM.bmHeight;
m_BitmapHeightCLE = BM.bmHeight;//for clear map no markrs
/* CDC MemDC;
CDC MemDCCLE; //for clear map no markrs
//RECT ClientRect;
//RECT ClientRectCLE;//for clear map no markrs
// create memory device context object and select bitmap
// object into it:
MemDC.CreateCompatibleDC (NULL);
MemDCCLE.CreateCompatibleDC (NULL);//for clear map no markrs
MemDC.SelectObject (&Bmp1);
MemDCCLE.SelectObject (&Bmp1CLE); //for clear map no markrs
int x11 = xposition - 6;
int y11 = yposition - 6;
int x22 = xposition + 6;
int y22 = yposition + 6;
MemDC.Ellipse (x11, y11, x22, y22);*/
m_Picture.SetBitmap(Bmp1);
SetDlgItemText(IDC_EDIT1x,"194");
SetDlgItemText(IDC_EDIT2y,"250");
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code
below
// to draw the icon. For MFC applications using the document/view
model,
// this is automatically done for you by the framework.
int xposition = 194;
int yposition = 199;
void CBitMapInDIALOGDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
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;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
// CPaintDC dc(this); // device context for painting
// Bmp1.LoadBitmap(IDB_BITMAP1);
CDC MemDC;
CDC MemDCCLE; //for clear map no markrs
// RECT ClientRect;
// RECT ClientRectCLE;//for clear map no markrs
// create memory device context object and select bitmap
// object into it:
MemDC.CreateCompatibleDC (NULL);
MemDCCLE.CreateCompatibleDC (NULL);//for clear map no markrs
MemDC.SelectObject (&Bmp1);
MemDCCLE.SelectObject (&Bmp1CLE); //for clear map no markrs
int x11 = xposition - 6;
int y11 = yposition - 6;
int x22 = xposition + 6;
int y22 = yposition + 6;
MemDC.Ellipse (x11, y11, x22, y22);
MemDC.DeleteDC ();
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the
user drags
// the minimized window.
HCURSOR CBitMapInDIALOGDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CBitMapInDIALOGDlg::OnSubmitBtn()
{
// TODO: Add your control notification handler code here
// This works
/*
int xe = 3445;
char buffer[20];
_itoa(xe, buffer, 10 );
// TODO: Add your control notification handler code here
SetDlgItemText(IDC_EDIT1,buffer);
////////////////////////////////////////*/
//xposition = atoi(strXcoordi1);
//yposition = atoi(strYcoordi1);
//char buffer[20];
CString buffercharx;
CString bufferchary;
GetDlgItemText(IDC_EDIT1x,buffercharx);
GetDlgItemText(IDC_EDIT2y,bufferchary);
xposition = atoi(buffercharx);
yposition = atoi(bufferchary);
CDialog::OnInitDialog();
CBitMapInDIALOGDlg::OnPaint();
Invalidate();
}