// ctrl1.cpp #include #include "defs1.h" #include "ctrl1.h" CCtrlsWin::CCtrlsWin() { Create(NULL, "Controls Example 1", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CRect(0, 0, 400, 400), NULL, NULL); pCel = new CEdit; pFahr = new CEdit; pConvert = new CButton; pCel -> Create(ES_LEFT | WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(50, 20, 150, 40), this, IDC_INPUTC); pFahr -> Create(ES_LEFT | WS_CHILD | WS_VISIBLE |WS_BORDER, CRect(50, 60, 150, 80), this, IDC_INPUTF); pConvert -> Create("Convert", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, CRect(50, 100, 150, 130), this, IDC_CONVERT); } void CCtrlsWin::OnConvert() { int fahr, cel; cel = GetDlgItemInt(IDC_INPUTC); fahr = 9 * cel / 5 + 32; SetDlgItemInt(IDC_INPUTF, fahr); } BEGIN_MESSAGE_MAP(CCtrlsWin, CFrameWnd) ON_COMMAND(IDC_CONVERT, OnConvert) END_MESSAGE_MAP() class CCtrlsApp : public CWinApp { public: BOOL InitInstance() { m_pMainWnd = new CCtrlsWin; m_pMainWnd -> ShowWindow(m_nCmdShow); m_pMainWnd -> UpdateWindow(); return TRUE; } }; CCtrlsApp theApp;