初学,很简单的程序
#include"draw.h"BEGIN_MESSAGE_MAP(CMainWnd,CFrameWnd)
ON_WM_TIMER()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
END_MESSAGE_MAP()
CMainWnd::CMainWnd()
{
bTimerInit=FALSE;
SeedRand();
}
COLORREF CMainWnd::Mycolor(int x,int y)
{
long red,blue,green;
int cx,cy;
CRect rc;
GetClientRect(&rc);
cx=rc.Width(); cy=rc.Height();
red=y*255/cy;
blue=((cy-y)*255/cy+x*255/cx)/2;
green=((cy-y)*255/cy+(cx-x)*255/cx)/2;
return RGB(red+MapRand(2),green+MapRand(2),blue+MapRand(2));
}
UINT CMainWnd::MapRand(UINT nMax)
{
int nRand =rand();
float fMap=(float)nMax/RAND_MAX;
float fRetVal=(float)nRand*fMap+0.5F;
return (UINT)fRetVal;
}
void CMainWnd::OnTimer(UINT IDEvent)
{
CClientDC dc(this);
DoPixels(&dc);
}
void CMainWnd::OnLButtonDown(UINT nFlags,CPoint point)
{
if(bTimerInit)
{
bTimerInit=FALSE;
KillTimer(10);
}
else
{
bTimerInit=TRUE;
SetTimer(10,50,NULL);
ptRectLT.x=270;
ptRectLT.y=190;
nWidth=100;
nWidthIncrement=20;
}
}
void CMainWnd::OnRButtonDown(UINT nFlags,CPoint point)
{
Invalidate();
}
void CMainWnd::DoPixels(CClientDC *pDC)
{
CRect rc;
GetClientRect(&rc);
for(int i=0;i<500;i++)
{
int cx=MapRand(rc.Width());
int cy=MapRand(rc.Height());
pDC->SetPixel(cx,cy,Mycolor(cx,cy));
}
int nPrev=pDC->SetBkMode(TRANSPARENT);
CString str="Points as Pixels:";
pDC->TextOut(5,5,str);
pDC->SetBkMode(nPrev);
}BOOL CMyApp::InitInstance()
{
CMainWnd *pFrame=new CMainWnd;
pFrame->Create(0,"绘图教程",WS_POPUPWINDOW|WS_DLGFRAME,CRect(0,0,800,600));
this->m_pMainWnd=pFrame;
pFrame->ShowWindow(m_nCmdShow);
pFrame->UpdateWindow();
return TRUE;
}CMyApp theApp;错误代码 
这些错误是什么呀?如何解决?
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/draw.exe : fatal error LNK1120: 1 unresolved externals
照着msdn解决不了的说 

解决方案 »

  1.   

    需要添加某个.lib库,仔细看看是哪个吧,这里看不出来呀
      

  2.   

    头文件:
    #include<afxwin.h>
    #include<afxext.h>
    #define SeedRand() srand((UINT)::GetTickCount())class CMyApp:public CWinApp
    {
    public:
    virtual BOOL InitInstance();
    };
    class CMainWnd:public CFrameWnd
    {
    protected:
    int m_nCurscreen;
    CPoint ptRectLT;
    int nWidth;
    int nWidthIncrement;
    BOOL bTimerInit;
    COLORREF Mycolor(int x,int y);
    UINT MapRand(UINT nMax);
    void DoPixels(CClientDC *pDC);
    public:
    CMainWnd();
    afx_msg void OnTimer(UINT nIDEvent);
    afx_msg void OnLButtonDown(UINT nFlags,CPoint point);
    afx_msg void OnRButtonDown(UINT nFlags,CPoint point);
    DECLARE_MESSAGE_MAP();
    };
    都在这里了,msdn:
    RESOLUTION
    Remove _ATL_MIN_CRT from the list of preprocessor defines to allow CRT startup code to be included. 
    On the Project menu, click Settings. In the Settings For: drop-down list, choose Multiple Configurations. (没找到:()In the "Select project configuration(s) to modify" dialog box that appears, select the check boxes for all Release versions, and then click OK. (project没有这个菜单吧?)Click the C/C++ tab in the Project Settings dialog box, and then choose the General category. Remove _ATL_MIN_CRT from the Preprocessor definitions edit box. Alternatively, you can remove calls to the CRT functions within the generated CServiceModule::LogEvent function. 
    STATUS
      

  3.   

    让你生成REALEASE版本,不要生成DEBUG版本。