#include<afxwin.h>
#include<strstrea.h>
const int IDC_SB1= 100;
const int IDC_CS1= 101;
const int IDC_CS2= 102;
const int IDC_BUTTON= 103;
const int MIN_RANGE=0;
const int MAX_RANGE=100;
class CApp:public CWinApp
{
public:
virtual BOOL InitInstance();
};
CApp app;
class CWindow:public CFrameWnd
{
CScrollBar *sb1;
CStatic *cs1;
CStatic *cs2;
CButton *button;
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,"cfa",WS_OVERLAPPEDWINDOW,
CRect(0,0,208,208));
cs1=new CStatic();
cs1->Create("farhenheit=32",WS_CHILD|WS_VISIBLE|WS_BORDER,
CRect(0,0,200,50),
this,
IDC_CS1);
cs2=new CStatic();
cs2->Create("celsius=0",WS_CHILD|WS_VISIBLE|WS_BORDER,
CRect(0,51,200,100),
this,
IDC_CS2);
sb1=new CScrollBar();
sb1->Create(WS_CHILD|WS_VISIBLE|SBS_HORZ,
CRect(0,101,200,130),
this,
IDC_SB1);
sb1->SetScrollRange(MIN_RANGE,MAX_RANGE,TRUE);
sb1->SetScrollPos(32);
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_LINELEFT:
pos-=1;
break;
case SB_LINERIGHT:
pos+=1;
break;
case SB_PAGELEFT:
pos-=10;
break;
case SB_PAGERIGHT:
pos+=10;
break;
case SB_LEFT:
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<<"celisius="<<(pos-32)*5/9<<ends;
SetDlgItemText(IDC_CS2,s);
void CWindowA:handleButton()
{
DestroyWindow();
}
BOOL CApp::InitInstance()
{
m_pMainWnd= new CWindow();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return true;
}
--------------------Configuration: 6 - Win32 Debug--------------------
Compiling...
6.cpp
F:\Debug\6.cpp(102) : error C2601: handleButton : local function definitions are illegal
F:\Debug\6.cpp(106) : error C2601: InitInstance : local function definitions are illegal
F:\Debug\6.cpp(112) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
6.exe - 3 error(s), 0 warning(s)
SetDlgItemText(IDC_CS2,s);
}//加上这个
void CWindowA:handleButton()