我在CMYDlg类中写了一个绘图函数:
CButton btn;
void CMYDlg::DrawButton()
{
btn.Create(_T(""),WS_CHILD|WS_VISIBLE, CRect(10, 10, 16, 16), this, 10);
}然后在类外声明了该类的指针:
CMYDlg *mydlg = NULL;为什么在全局函数:
void fun()
{
mydlg->DrawButton();
}
的时候程序会崩溃?
CButton btn;
void CMYDlg::DrawButton()
{
btn.Create(_T(""),WS_CHILD|WS_VISIBLE, CRect(10, 10, 16, 16), this, 10);
}然后在类外声明了该类的指针:
CMYDlg *mydlg = NULL;为什么在全局函数:
void fun()
{
mydlg->DrawButton();
}
的时候程序会崩溃?
void fun()
{
CMyDlg *pMydlg = new CMyDlg;
pMydlg->Create(NULL,IDD_MYDLG)//IDD_MYDLG为对话框类的模板
pMydlg->DrawButton();
}
2,还必须调用mydlg->create,创建对话框
CMYView* myView = NULL;void DispGrid(bool bEnable)
{
myView->GrawButton();
}其中:
class CMYView : public CViewvoid CMYView::GrawButton()
{
btn.Create(_T(""),WS_CHILD|WS_VISIBLE, CRect(111, 134, 123+16, 145+16), this, 10);
}
运行正常?