document與view的問題
這是一個Document、View、Frame與App的綜合運用..
其實也是抄襲書本的練習...
只是讓我納悶的是..可以編譯與轉成執行檔,但是執行時卻無畫面出來
因此,想請教一下諸位,我的程式是哪裡寫錯了呢?
我的程式放在
http://home.pchome.com.tw/family/quota123/iiii.zip
語法部分如下,在此說聲謝謝!
# include<afxwin.h>
#include"resource.h"
#include<afxtempl.h>
class MyDocument : public CDocument
{
public:
CArray<CPoint, CPoint &>pArray;
void AddPoint(CPoint p)
{pArray.Add(p);}
CPoint GetPoint(int i)
{return pArray[i];}
int GetSize()
{return pArray.GetSize();}
DECLARE_DYNCREATE(MyDocument)
DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNCREATE(MyDocument,CDocument)
BEGIN_MESSAGE_MAP(MyDocument,CDocument)
END_MESSAGE_MAP()
class MyView : public CView
{
public:
void OnDraw(CDC * aDC)
{
MyDocument*doc=(MyDocument*)GetDocument();
int num=doc->GetSize();
int i;
for(i=0;i<num;++i)
{
CPoint point=doc->GetPoint(i);
aDC->SetPixel(point, RGB(255,0,0));
}
}
afx_msg void OnLButtonDown(UINT,CPoint point)
{SetCapture();}
afx_msg void OnMouseMove(UINT, CPoint point)
{
if(this==GetCapture())
{
CClientDC aDC(this);
aDC.SetPixel(point,RGB(255,0,0));
MyDocument *doc=(MyDocument*)GetDocument();
doc->AddPoint(point);
}
}
afx_msg void OnLButtonUp(UINT, CPoint point)
{ReleaseCapture();}
DECLARE_DYNCREATE(MyView)
DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNCREATE(MyView,CView)
BEGIN_MESSAGE_MAP(MyView,CView)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
class MyFrame:public CFrameWnd
{
public:
DECLARE_DYNCREATE(MyFrame)
DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNCREATE(MyFrame,CFrameWnd)
BEGIN_MESSAGE_MAP(MyFrame,CFrameWnd)
END_MESSAGE_MAP()
class MyApp:public CWinApp
{
public:
BOOL InitIntanse()
{
CDocument*doc;
CSingleDocTemplate* DocTemplate;
DocTemplate=new CSingleDocTemplate(
IDR_MENU1,
RUNTIME_CLASS(MyDocument),
RUNTIME_CLASS(MyFrame),
RUNTIME_CLASS(MyView));
AddDocTemplate(DocTemplate);
doc=DocTemplate->CreateNewDocument();
m_pMainWnd=DocTemplate->CreateNewFrame(doc,NULL);
DocTemplate->InitialUpdateFrame((CFrameWnd*)m_pMainWnd,doc);
m_pMainWnd->ShowWindow(SW_SHOW);
return true;
}
}a_app;
--
┌─────◆KKCITY◆─────┐▇─┐KKADSL→六星級優質連線服務
│ bbs.kkcity.com.tw │┴ └─▇ 馬上申請帶你上網環遊全世界!
└──《From:221.169.0.159 》──┘ KKADSL ┴ http://adsl.kkcity.com.tw
--
討論串 (同標題文章)
完整討論串 (本文為第 1 之 4 篇):
Programming 近期熱門文章
PTT數位生活區 即時熱門文章