是深入浅出MFC书中 第六章 那个hello程序,知道的请帮忙。不知道的看下边,也请帮忙。
resource.h
#define IDM_ABOUT 100stdafx.h
#include <afxwin.h>stdafx.cpp
#include "stdafx.h"hello.hclass CMyWinApp : public CWinApp
{
public:
// virtual BOOL InitInstance();
//virtual BOOL OnIdle(LONG lCount); BOOL InitInstance();
};//--------------------------------------------------------------------
class CMyFrameWnd : public CFrameWnd
{
public:
CMyFrameWnd();
afx_msg void OnPaint();
afx_msg void OnAbout();
void IdleTimeHandler(LONG lCount); // we want it call by CMyWinApp::OnIdleprivate:
DECLARE_MESSAGE_MAP()
static VOID CALLBACK LineDDACallback(int,int,LPARAM);
};
//--------------------------------------------------------------------//hello.cpp#include "Stdafx.h"
#include "Hello4.h"
#include "resource.h"CMyWinApp theApp; BOOL CMyWinApp::InitInstance()
{
m_pMainWnd = new CMyFrameWnd();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}BOOL CMyWinApp::OnIdle(LONG lCount)
{
CMyFrameWnd* pWnd = (CMyFrameWnd*)m_pMainWnd;
pWnd->IdleTimeHandler(lCount); return TRUE;
}CMyFrameWnd::CMyFrameWnd()
{
Create(NULL, "Hello MFC", WS_OVERLAPPEDWINDOW, rectDefault,
NULL, "MainMenu");
}BEGIN_MESSAGE_MAP(CMyFrameWnd, CFrameWnd)
ON_COMMAND(IDM_ABOUT, OnAbout)
ON_WM_PAINT()
END_MESSAGE_MAP()void CMyFrameWnd::OnPaint()
{
CPaintDC dc(this);
CRect rect; GetClientRect(rect); dc.SetTextAlign(TA_BOTTOM | TA_CENTER); ::LineDDA(rect.right/2, 0, rect.right/2, rect.bottom/2,
(LINEDDAPROC) LineDDACallback, (LPARAM) (LPVOID) &dc);
}VOID CALLBACK CMyFrameWnd::LineDDACallback(int x, int y, LPARAM lpdc)
{
static char szText[] = "Hello, MFC"; ((CDC*)lpdc)->TextOut(x, y, szText, sizeof(szText)-1);
for(int i=1; i<50000; i++);
}void CMyFrameWnd::OnAbout()
{
CDialog about("AboutBox", this);
about.DoModal();
}
void CMyFrameWnd::IdleTimeHandler(LONG lCount)
{
CString str;
CRect rect(10,10,200,30);
CDC* pDC = new CClientDC(this); str.Format("%010d", lCount);
pDC->DrawText(str, &rect, DT_LEFT | DT_TOP);
}
Linking...
LINK : warning LNK4098: defaultlib "LIBCMT" conflicts with use of other libs; use /NODEFAULTLIB:library
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/HELLO.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.HELLO.exe - 2 error(s), 1 warning(s)
resource.h
#define IDM_ABOUT 100stdafx.h
#include <afxwin.h>stdafx.cpp
#include "stdafx.h"hello.hclass CMyWinApp : public CWinApp
{
public:
// virtual BOOL InitInstance();
//virtual BOOL OnIdle(LONG lCount); BOOL InitInstance();
};//--------------------------------------------------------------------
class CMyFrameWnd : public CFrameWnd
{
public:
CMyFrameWnd();
afx_msg void OnPaint();
afx_msg void OnAbout();
void IdleTimeHandler(LONG lCount); // we want it call by CMyWinApp::OnIdleprivate:
DECLARE_MESSAGE_MAP()
static VOID CALLBACK LineDDACallback(int,int,LPARAM);
};
//--------------------------------------------------------------------//hello.cpp#include "Stdafx.h"
#include "Hello4.h"
#include "resource.h"CMyWinApp theApp; BOOL CMyWinApp::InitInstance()
{
m_pMainWnd = new CMyFrameWnd();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}BOOL CMyWinApp::OnIdle(LONG lCount)
{
CMyFrameWnd* pWnd = (CMyFrameWnd*)m_pMainWnd;
pWnd->IdleTimeHandler(lCount); return TRUE;
}CMyFrameWnd::CMyFrameWnd()
{
Create(NULL, "Hello MFC", WS_OVERLAPPEDWINDOW, rectDefault,
NULL, "MainMenu");
}BEGIN_MESSAGE_MAP(CMyFrameWnd, CFrameWnd)
ON_COMMAND(IDM_ABOUT, OnAbout)
ON_WM_PAINT()
END_MESSAGE_MAP()void CMyFrameWnd::OnPaint()
{
CPaintDC dc(this);
CRect rect; GetClientRect(rect); dc.SetTextAlign(TA_BOTTOM | TA_CENTER); ::LineDDA(rect.right/2, 0, rect.right/2, rect.bottom/2,
(LINEDDAPROC) LineDDACallback, (LPARAM) (LPVOID) &dc);
}VOID CALLBACK CMyFrameWnd::LineDDACallback(int x, int y, LPARAM lpdc)
{
static char szText[] = "Hello, MFC"; ((CDC*)lpdc)->TextOut(x, y, szText, sizeof(szText)-1);
for(int i=1; i<50000; i++);
}void CMyFrameWnd::OnAbout()
{
CDialog about("AboutBox", this);
about.DoModal();
}
void CMyFrameWnd::IdleTimeHandler(LONG lCount)
{
CString str;
CRect rect(10,10,200,30);
CDC* pDC = new CClientDC(this); str.Format("%010d", lCount);
pDC->DrawText(str, &rect, DT_LEFT | DT_TOP);
}
Linking...
LINK : warning LNK4098: defaultlib "LIBCMT" conflicts with use of other libs; use /NODEFAULTLIB:library
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/HELLO.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.HELLO.exe - 2 error(s), 1 warning(s)
找到最下面的Project Options:
在其中找到/subsystem:console,
将其改为/subsystem:windows(记不大清了,如果原来是/subsystem:windows
就改为subsystem:console)
int main(){return 0;}
即可;
这就是穷对付呀;^_^
Alt+F7,打开工程的属性,进入Link页面(中文版的就是链接),
找到最下面的Project Options:
在其中找到/subsystem:console,
将其改为/subsystem:windows(记不大清了,如果原来是/subsystem:windows
就改为subsystem:console)出现这个问题:Compiling...
Command line warning D4002 : ignoring unknown option '/subsystem:windows'
StdAfx.cpp
LINK : fatal error LNK1561: entry point must be defined
Error executing cl.exe.HELLO.exe - 1 error(s), 1 warning(s)
[email protected]