www.pudn.com > tongyongkongjianlei.rar > EditComboDlg.cpp


// EditComboDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "EditCombo.h" 
#include "EditComboDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CAboutDlg dialog used for App About 
 
class CAboutDlg : public CDialog 
{ 
public: 
	CAboutDlg(); 
 
// Dialog Data 
	//{{AFX_DATA(CAboutDlg) 
	enum { IDD = IDD_ABOUTBOX }; 
	//}}AFX_DATA 
 
	// ClassWizard generated virtual function overrides 
	//{{AFX_VIRTUAL(CAboutDlg) 
	protected: 
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support 
	//}}AFX_VIRTUAL 
 
// Implementation 
protected: 
	//{{AFX_MSG(CAboutDlg) 
	//}}AFX_MSG 
	DECLARE_MESSAGE_MAP() 
}; 
 
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) 
{ 
	//{{AFX_DATA_INIT(CAboutDlg) 
	//}}AFX_DATA_INIT 
} 
 
void CAboutDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CAboutDlg) 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) 
	//{{AFX_MSG_MAP(CAboutDlg) 
		// No message handlers 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CEditComboDlg dialog 
 
CEditComboDlg::CEditComboDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CEditComboDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CEditComboDlg) 
	m_info = _T(""); 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CEditComboDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CEditComboDlg) 
	DDX_Control(pDX, IDC_SCROLLBAR, m_scrollbar); 
	DDX_Control(pDX, IDC_SLIDER, m_slider); 
	DDX_Control(pDX, IDC_SPIN, m_spin); 
	DDX_Control(pDX, IDC_IPADDRESS, m_ip); 
	DDX_Control(pDX, IDC_COMBO, m_combo); 
	DDX_Text(pDX, IDC_EDIT, m_info); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CEditComboDlg, CDialog) 
	//{{AFX_MSG_MAP(CEditComboDlg) 
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_BN_CLICKED(IDC_DISPLAY, OnDisplay) 
	ON_BN_CLICKED(IDC_RESET, OnReset) 
	ON_BN_CLICKED(IDC_ADJUST, OnAdjust) 
	ON_BN_CLICKED(IDC_ORIGION, OnOrigion) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CEditComboDlg message handlers 
 
BOOL CEditComboDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// Add "About..." menu item to system menu. 
 
	// IDM_ABOUTBOX must be in the system command range. 
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); 
	ASSERT(IDM_ABOUTBOX < 0xF000); 
 
	CMenu* pSysMenu = GetSystemMenu(FALSE); 
	if (pSysMenu != NULL) 
	{ 
		CString strAboutMenu; 
		strAboutMenu.LoadString(IDS_ABOUTBOX); 
		if (!strAboutMenu.IsEmpty()) 
		{ 
			pSysMenu->AppendMenu(MF_SEPARATOR); 
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); 
		} 
	} 
 
	// Set the icon for this dialog.  The framework does this automatically 
	//  when the application's main window is not a dialog 
	SetIcon(m_hIcon, TRUE);			// Set big icon 
	SetIcon(m_hIcon, FALSE);		// Set small icon 
	 
	// TODO: Add extra initialization here 
	m_combo.AddString("MyComputer1(主机1)");//组合框中添加选项 
	m_combo.AddString("MyComputer2(主机2)"); 
	m_combo.AddString("MyComputer3(主机3)"); 
	m_combo.AddString("MyComputer4(主机4)"); 
	GetDlgItem(IDC_IPADDRESS)->EnableWindow(false);//IP地址输入无效 
	GetDlgItem(IDC_EDIT)->EnableWindow(false);//编辑框输入无效 
	GetDlgItem(IDC_RESET)->EnableWindow(false);//重置按钮无效 
	m_combo.SetCurSel(0);//设置组合框初始选项为选项1 
	m_spin.SetRange(0,20);//设置微调按钮调节范围 
	m_spin.SetPos(2);//设置微调按钮的初始值 
	//GetDlgItem(IDC_EDIT1)->EnableWindow(false);//滑块控件无效 
	 
	m_slider.SetRange(0,20,false);//设置滑块控件的范围 
	m_slider.SetPos(2);//设置滑块控件的初始值 
	m_slider.SetTicFreq(4);//设置刻度的频度 
	GetDlgItem(IDC_SLIDER)->EnableWindow(false);//滑块控件无效 
 
	m_scrollbar.SetScrollRange(0,20);//设置滚动条的范围 
	m_scrollbar.SetScrollPos(2);//设置滚动条的初始值 
 
	GetDlgItem(IDC_ORIGION)->EnableWindow(false);//初始状态按钮无效 
 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
void CEditComboDlg::OnSysCommand(UINT nID, LPARAM lParam) 
{ 
	if ((nID & 0xFFF0) == IDM_ABOUTBOX) 
	{ 
		CAboutDlg dlgAbout; 
		dlgAbout.DoModal(); 
	} 
	else 
	{ 
		CDialog::OnSysCommand(nID, lParam); 
	} 
} 
 
// If you add a minimize button to your dialog, you will need the code below 
//  to draw the icon.  For MFC applications using the document/view model, 
//  this is automatically done for you by the framework. 
 
void CEditComboDlg::OnPaint()  
{ 
	if (IsIconic()) 
	{ 
		CPaintDC dc(this); // device context for painting 
 
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); 
 
		// Center icon in client rectangle 
		int cxIcon = GetSystemMetrics(SM_CXICON); 
		int cyIcon = GetSystemMetrics(SM_CYICON); 
		CRect rect; 
		GetClientRect(&rect); 
		int x = (rect.Width() - cxIcon + 1) / 2; 
		int y = (rect.Height() - cyIcon + 1) / 2; 
 
		// Draw the icon 
		dc.DrawIcon(x, y, m_hIcon); 
	} 
	else 
	{ 
		CDialog::OnPaint(); 
	} 
} 
 
// The system calls this to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR CEditComboDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void CEditComboDlg::OnDisplay()  
{ 
	// TODO: Add your control notification handler code here 
	switch(m_combo.GetCurSel()) 
	{ 
	case 0://选择了选项1 
		m_ip.SetAddress(127,0,0,1);//设定IP值 
		m_info.Format("欢迎选择主机1,该主机的IP地址是127.0.0.1。"); 
		UpdateData(false);//显示编辑框文字 
		break; 
	case 1://选择了选项2 
		m_ip.SetAddress(127,0,0,2);//设定IP值 
		m_info.Format("欢迎选择主机2,该主机的IP地址是127.0.0.2。"); 
		UpdateData(false); 
		break; 
	case 2://选择了选项3 
		m_ip.SetAddress(127,0,0,3);//设定IP值 
		m_info.Format("欢迎选择主机3,该主机的IP地址是127.0.0.3。"); 
		UpdateData(false);//显示编辑框文字 
		break; 
	case 3://选择了选项4 
		m_ip.SetAddress(127,0,0,4);//设定IP值 
		m_info.Format("欢迎选择主机4,该主机的IP地址是127.0.0.4。"); 
		UpdateData(false);//显示编辑框文字 
		break; 
	} 
	GetDlgItem(IDC_RESET)->EnableWindow(true);//重置按钮生效 
	GetDlgItem(IDC_DISPLAY)->EnableWindow(false);//显示信息按钮无效 
	GetDlgItem(IDC_COMBO)->EnableWindow(false);//组合框无效 
	 
} 
 
void CEditComboDlg::OnReset()  
{ 
	// TODO: Add your control notification handler code here 
	m_ip.ClearAddress(); 
	m_info.Empty(); 
	UpdateData(false);//显示编辑框文字 
	m_combo.SetCurSel(0);//设置组合框初始选项为选项1 
	GetDlgItem(IDC_DISPLAY)->EnableWindow(true);//显示信息按钮生效 
	GetDlgItem(IDC_RESET)->EnableWindow(false);//重置按钮无效 
	GetDlgItem(IDC_COMBO)->EnableWindow(true);//组合框生效 
	 
} 
 
void CEditComboDlg::OnAdjust()  
{ 
	// TODO: Add your control notification handler code here 
	m_slider.SetPos(m_spin.GetPos());//设置滑块控件的值 
	m_scrollbar.SetScrollPos(m_spin.GetPos());//设置滚动条的值 
	GetDlgItem(IDC_EDIT1)->EnableWindow(false);//微调按钮无效 
	GetDlgItem(IDC_ADJUST)->EnableWindow(false);//确定调整按钮无效 
	GetDlgItem(IDC_ORIGION)->EnableWindow(true);//初始状态按钮生效 
 
	 
} 
 
void CEditComboDlg::OnOrigion()  
{ 
	// TODO: Add your control notification handler code here 
	GetDlgItem(IDC_ORIGION)->EnableWindow(false);//初始状态按钮无效 
	GetDlgItem(IDC_ADJUST)->EnableWindow(true);//确定调整按钮生效 
	m_spin.SetPos(2);//设置微调按钮的初始值 
	m_slider.SetPos(2);//设置滑块控件的初始值 
	m_scrollbar.SetScrollPos(2);//设置滚动条的初始值 
	GetDlgItem(IDC_EDIT1)->EnableWindow(true);//微调按钮生效 
 
	 
}