MFC的问题,出现访问冲突
#include<afxwin.h>TCHARtitle[]=TEXT("MFC");classCMyWnd:publicCFrameWnd{private:char*S...
#include <afxwin.h>
TCHAR title[] = TEXT("MFC");
class CMyWnd:public CFrameWnd
{
private:
char *ShowText;
public:
afx_msg void OnPaint();
afx_msg void OnLButtonDown(UINT, CPoint);
DECLARE_MESSAGE_MAP();
};
BEGIN_MESSAGE_MAP(CMyWnd,CFrameWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
void CMyWnd::OnPaint()
{
CPaintDC dc(this);
dc.TextOut(20, 20, ShowText);
}
void CMyWnd::OnLButtonDown(UINT m, CPoint c)
{
ShowText = "Hello World";
InvalidateRect(NULL, TRUE);
}
class CMyApp:public CWinApp
{
public:
BOOL InitInstance();
};
BOOL CMyApp::InitInstance()
{
CMyWnd *pMainWnd = new CMyWnd;
pMainWnd->Create(0, title);
pMainWnd->ShowWindow(m_nCmdShow);
pMainWnd->UpdateWindow();
m_pMainWnd = pMainWnd;
return TRUE;
}
CMyApp MyApp;
能够compile,但是运行时出现
FirstMFC.exe 中的 0x758282ce 处有未经处理的异常: 0xC0000005: 读取位置 0xcdcdcdcd 时发生访问冲突
在别人的机子上能够运行
就是在dc.TextOut(20, 20, ShowText);这行跳出的 展开
TCHAR title[] = TEXT("MFC");
class CMyWnd:public CFrameWnd
{
private:
char *ShowText;
public:
afx_msg void OnPaint();
afx_msg void OnLButtonDown(UINT, CPoint);
DECLARE_MESSAGE_MAP();
};
BEGIN_MESSAGE_MAP(CMyWnd,CFrameWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
void CMyWnd::OnPaint()
{
CPaintDC dc(this);
dc.TextOut(20, 20, ShowText);
}
void CMyWnd::OnLButtonDown(UINT m, CPoint c)
{
ShowText = "Hello World";
InvalidateRect(NULL, TRUE);
}
class CMyApp:public CWinApp
{
public:
BOOL InitInstance();
};
BOOL CMyApp::InitInstance()
{
CMyWnd *pMainWnd = new CMyWnd;
pMainWnd->Create(0, title);
pMainWnd->ShowWindow(m_nCmdShow);
pMainWnd->UpdateWindow();
m_pMainWnd = pMainWnd;
return TRUE;
}
CMyApp MyApp;
能够compile,但是运行时出现
FirstMFC.exe 中的 0x758282ce 处有未经处理的异常: 0xC0000005: 读取位置 0xcdcdcdcd 时发生访问冲突
在别人的机子上能够运行
就是在dc.TextOut(20, 20, ShowText);这行跳出的 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询