初学,很简单的程序
#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解决不了的说
#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解决不了的说
解决方案 »
- Winsock程序中出线的内存读写问题
- 如何使用结构体做函数参数并实现剪贴板功能,具体代码想如下那般?
- iocp udp 不能 WSARecvFrom 吗?10045不支持?
- 《Windows图形编程》中关于计算桢缓冲区RAM大小的问题。帮忙解答。
- 怎么让数据穿透代理+防火墙的这么网络架构?
- 请问涉及到“工具栏”编程的API函数有哪几个?
- 我使用mciSendString来播放AVI文件,请问我如何用代码知道以播放在什么位置了?
- 如何判断对方是否 http 代理服务器(proxy)?[ExitWindows求教]
- 我机器的内存常常会莫名其妙的达到很高的使用量,这是为什么?
- 子线程不能与主线程同步!! 急急急!!!!
- 这个问题好像挺简单的
- 我想获得注册表下某一子键下的全部内容,怎么做??
#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