小的在vc++6.0环境下,新建了一个win32 application的项目,然后在此项目上新建一个cpp文件,
代码如下且setting菜单里已经设置为uses mfc in shared dll, 但还是出现65个错误,请大伙帮我看看,好吗?
#include <afxwin.h>
#include <strstrea.h>#define IDC_BUTTON 103
#define MIN_RANGE 0
#define MAX_RANGE 100
#define IDC_CS1 101
#define IDC_CS2 102
#define IDC_SB1 100
class CApp::public CWinApp
{public:
virtual BOOL InitInstance();};
CApp App;
class CWindow::public CFrameWnd
{
CScrollBar *sb1;
CStatic *cs1;
CStatic *cs2;
CButton *bt;public:
CWindow();
afx_msg void OnHScroll (UINT nSBCode,UINT nPos,
CScrollBar *pScrollBar);
afx_msg void HandleButton(); DECLARE_MESSAGE_MAP ()
};
BEGIN_MESSAGE_MAP(CWindow,CFrameWnd)
ON_WM_HSCROLL()
ON_BN_CLICKED (IDC_BUTTON,HandleButton)
END_MESSAGE_MAP
CWindow::CWindow()
{
Create (NULL,"c2f",OVERLAPPEDWINDOW,CRect(0,0,208,208)); cs1 = new CStatic();
cs1->Create("Fahrenheit = 32",WS_CHILD | WS_VISIBLE | WS_BORDER,
CRect(0,0,200,50),this,IDC_CS1); cs2 = new CStatic();
cs2->Create("Cels = 0",WS_CHILD | WS_VISIBLE | WS_BORDER,
CRect(0,51,200,100),this,IDC_CS2); sb1 = new CScroll();
sb1->Create (WS_CHILD | WS_VISIBLE | SBS_HORZ,CRect(0,101,200,130),
this,IDC_SB1); button = new CButton();
button->Create("Quit",WS_CHILD | WS_VISIBLE | WS_BORDER,CRect(0,131,200,180),
this,IDC_BUTTON);}
void CWindow::OnHScroll(UINT nSBCode,UINT nPos,CScrollBar *pScrollBar)
{
int pos;
pos = pScrollBar->GetScrollPos(); switch(nSBCode)
{
case SB_LINEUP:
pos - = 1;
break;
case SB_LINEDOWN:
pos + = 1;
break;
case SB_PAGEUP:
pos - = 10;
break;
case SB_PAGEDOWN:
pos + = 10;
break;
case SB_TOP:
pos = MIN_RANGE;
break;
case SB_BOTTOM:
pos = MAX_RANGE;
break;
case SB_THUMBPOSITION:
pos = nPos;
break;
default:
return;
} if pos < MIN_RANGE
pos = MIN_RANGE;
else if pos > MAX_RANGE
pos = MAX_RANGE;
sb1->SetScrollPos(pos,TRUE); char s[100];
ostrstream ostr(s,100);
ostr<<"Fahrenheit = "<<pos<<ends;
SetDlgItemText (IDC_CS1,s);
ostr.seekp(ios::beg);
ostr<<"cels = "<<(pos - 32) * 5 / 9 <<ends;
SetDlagItemText(IDC_CS2,s);
}
void CWindow::HandleButton()
{
DestroyWindow();
}
BOOL CApp::InitInstance()
{
m_pMainWnd = new CWindow();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow(); return TRUE:
}
代码如下且setting菜单里已经设置为uses mfc in shared dll, 但还是出现65个错误,请大伙帮我看看,好吗?
#include <afxwin.h>
#include <strstrea.h>#define IDC_BUTTON 103
#define MIN_RANGE 0
#define MAX_RANGE 100
#define IDC_CS1 101
#define IDC_CS2 102
#define IDC_SB1 100
class CApp::public CWinApp
{public:
virtual BOOL InitInstance();};
CApp App;
class CWindow::public CFrameWnd
{
CScrollBar *sb1;
CStatic *cs1;
CStatic *cs2;
CButton *bt;public:
CWindow();
afx_msg void OnHScroll (UINT nSBCode,UINT nPos,
CScrollBar *pScrollBar);
afx_msg void HandleButton(); DECLARE_MESSAGE_MAP ()
};
BEGIN_MESSAGE_MAP(CWindow,CFrameWnd)
ON_WM_HSCROLL()
ON_BN_CLICKED (IDC_BUTTON,HandleButton)
END_MESSAGE_MAP
CWindow::CWindow()
{
Create (NULL,"c2f",OVERLAPPEDWINDOW,CRect(0,0,208,208)); cs1 = new CStatic();
cs1->Create("Fahrenheit = 32",WS_CHILD | WS_VISIBLE | WS_BORDER,
CRect(0,0,200,50),this,IDC_CS1); cs2 = new CStatic();
cs2->Create("Cels = 0",WS_CHILD | WS_VISIBLE | WS_BORDER,
CRect(0,51,200,100),this,IDC_CS2); sb1 = new CScroll();
sb1->Create (WS_CHILD | WS_VISIBLE | SBS_HORZ,CRect(0,101,200,130),
this,IDC_SB1); button = new CButton();
button->Create("Quit",WS_CHILD | WS_VISIBLE | WS_BORDER,CRect(0,131,200,180),
this,IDC_BUTTON);}
void CWindow::OnHScroll(UINT nSBCode,UINT nPos,CScrollBar *pScrollBar)
{
int pos;
pos = pScrollBar->GetScrollPos(); switch(nSBCode)
{
case SB_LINEUP:
pos - = 1;
break;
case SB_LINEDOWN:
pos + = 1;
break;
case SB_PAGEUP:
pos - = 10;
break;
case SB_PAGEDOWN:
pos + = 10;
break;
case SB_TOP:
pos = MIN_RANGE;
break;
case SB_BOTTOM:
pos = MAX_RANGE;
break;
case SB_THUMBPOSITION:
pos = nPos;
break;
default:
return;
} if pos < MIN_RANGE
pos = MIN_RANGE;
else if pos > MAX_RANGE
pos = MAX_RANGE;
sb1->SetScrollPos(pos,TRUE); char s[100];
ostrstream ostr(s,100);
ostr<<"Fahrenheit = "<<pos<<ends;
SetDlgItemText (IDC_CS1,s);
ostr.seekp(ios::beg);
ostr<<"cels = "<<(pos - 32) * 5 / 9 <<ends;
SetDlagItemText(IDC_CS2,s);
}
void CWindow::HandleButton()
{
DestroyWindow();
}
BOOL CApp::InitInstance()
{
m_pMainWnd = new CWindow();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow(); return TRUE:
}
谁贴上这段代码试试
1. #include <strstrea.h> ==> #include <strstream>; using namespace std;
使用C++标准头文件吧。2. class CApp::public CWinApp ==> class CApp : public CWinApp
一个冒号,不是两个。基本C++语法都不懂了?3. END_MESSAGE_MAP ==> END_MESSAGE_MAP()4. OVERLAPPEDWINDOW ==> WS_OVERLAPPEDWINDOW5. pos - = 1; ==> pos -= 1;
+= -= *= /= 等运算符中间不能有空格。这也是基础语法。6. if pos < MIN_RANGE ==> if (pos < MIN_RANGE)
if 条件后要加括号7. return TRUE: ==> return TRUE;
分号,不是冒号你的程序基本没错,只是语法错误太多,祝你早日成功。
你的态度让我感动。