BOOL CMapDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//CEdit *edraw=(CEdit*)GetDlgItem(IDC_EDITDRAW);
//edraw->GetClientRect(&Grid);
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP1);
m_brBk.CreatePatternBrush(&bmp);
bmp.DeleteObject();
return TRUE;
}
void CMapDlg::OnDrawGrid()
{
//CEdit *edraw=(CEdit*)GetDlgItem(IDC_EDITDRAW);
//edraw->GetClientRect(&Grid); return;
}
HBRUSH CMapDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here // TODO: Return a different brush if the default is not desired
if (nCtlColor == CTLCOLOR_EDIT)
{
return m_brBk;
}
return hbr;
}void CMapDlg::OnPaint()
{
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
CEdit *edraw=(CEdit*)GetDlgItem(IDC_EDITDRAW);
CPaintDC dc(edraw);
edraw->GetClientRect(&Grid);
dc.MoveTo(0,0);
dc.LineTo(70,70);
}
void CSerialPortDlg::OnBnClickedComap()
{
// TODO: Add your control notification handler code here
CMapDlg* Dialog1;
Dialog1=new CMapDlg;
int x,y; if(Dialog1->DoModal()==IDOK)
{
//Dialog1->OnDrawGrid();
}
delete Dialog1;
}
如上是我实现的代码,CSerialPortDlg是我主对话框中的类,当我打开新对话框调用OnDrawGrid之后,添加代码就会弹出出现一个debug的对话框错误;这是什么原因呢?
第二个问题,也是主要问题,我的目的是想在弹出的新对话框的一个编辑框中贴位图,然后在其上画线和点(随时间可变),现在的问题是,位图我已经正确贴再编辑框中了,但是在onpaint中画线的时候,对话框变透明了,背景图片也没,程序也死掉了。就只有一条线,去掉位图的时候,直线就正常显示了,这是什么原因呢?我该怎么改?
{
CDialog::OnInitDialog();
//CEdit *edraw=(CEdit*)GetDlgItem(IDC_EDITDRAW);
//edraw->GetClientRect(&Grid);
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP1);
m_brBk.CreatePatternBrush(&bmp);
bmp.DeleteObject();
return TRUE;
}
void CMapDlg::OnDrawGrid()
{
//CEdit *edraw=(CEdit*)GetDlgItem(IDC_EDITDRAW);
//edraw->GetClientRect(&Grid); return;
}
HBRUSH CMapDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here // TODO: Return a different brush if the default is not desired
if (nCtlColor == CTLCOLOR_EDIT)
{
return m_brBk;
}
return hbr;
}void CMapDlg::OnPaint()
{
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
CEdit *edraw=(CEdit*)GetDlgItem(IDC_EDITDRAW);
CPaintDC dc(edraw);
edraw->GetClientRect(&Grid);
dc.MoveTo(0,0);
dc.LineTo(70,70);
}
void CSerialPortDlg::OnBnClickedComap()
{
// TODO: Add your control notification handler code here
CMapDlg* Dialog1;
Dialog1=new CMapDlg;
int x,y; if(Dialog1->DoModal()==IDOK)
{
//Dialog1->OnDrawGrid();
}
delete Dialog1;
}
如上是我实现的代码,CSerialPortDlg是我主对话框中的类,当我打开新对话框调用OnDrawGrid之后,添加代码就会弹出出现一个debug的对话框错误;这是什么原因呢?
第二个问题,也是主要问题,我的目的是想在弹出的新对话框的一个编辑框中贴位图,然后在其上画线和点(随时间可变),现在的问题是,位图我已经正确贴再编辑框中了,但是在onpaint中画线的时候,对话框变透明了,背景图片也没,程序也死掉了。就只有一条线,去掉位图的时候,直线就正常显示了,这是什么原因呢?我该怎么改?
{
//Dialog1->OnDrawGrid();
}当第一条执行后,对话框已经退出,就是说对话框已经不存在了,怎么能继续在上面画东西呢?2. 在OnPaint里面还是要调用CDialog::OnPaint(),因为这个函数负责绘制对话框的背景,所以必须先调用该函数再做自己的绘制任务
1. if(Dialog1->DoModal()==IDOK)
{
//Dialog1->OnDrawGrid();
}当第一条执行后,对话框已经退出,就是说对话框已经不存在了,怎么能继续在上面画东西呢?2. 在OnPaint里面还是要调用CDialog::OnPaint(),因为这个函数负责绘制对话框的背景,所以必须先调用该函数再做自己的绘制……
谢谢,第一个知道了。第二个问题还是存在,在位图上划线,图就没有了。该怎么改呢?
[
-----------------
重写CEdit类,OnPaint函数中贴图就好了~
class CMyEdit : public CEdit
{
}
具体该怎么操作哦?之前的代码可以直接加进去么?
大版指导下啊,新手
向导:
Inert Calss
CMyEdit
派生至 CEdit
把 原来的 m_Edit 的 类(CEdit) 改为 CMyEdit