⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 initdlg.cpp

📁 客户端服务器源码
💻 CPP
字号:
// InitDlg.cpp : implementation file
//

#include "stdafx.h"
#include "clientmain.h"
#include "InitDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CInitDlg dialog


CInitDlg::CInitDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CInitDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CInitDlg)
	m_strDbName = _T("");
	m_strDbPsw = _T("");
	m_strDbUser = _T("");
	m_strComServer = _T("");
	m_strDbServer = _T("");
	//}}AFX_DATA_INIT
}


void CInitDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CInitDlg)
	DDX_Control(pDX, IDC_EDIT_DBSERVER, m_DbServer);
	DDX_Control(pDX, IDC_EDIT_COMSERVER, m_ComServer);
	DDX_Control(pDX, IDC_EDIT_DBUSER, m_DbUser);
	DDX_Control(pDX, IDC_EDIT_DBPSW, m_DbPsw);
	DDX_Control(pDX, IDC_EDIT_DBNAME, m_DbName);
	DDX_Control(pDX, IDC_BTN_OK, m_btnOK);
	DDX_Control(pDX, IDC_BTN_EXIT, m_btnExit);
	DDX_Text(pDX, IDC_EDIT_DBNAME, m_strDbName);
	DDX_Text(pDX, IDC_EDIT_DBPSW, m_strDbPsw);
	DDX_Text(pDX, IDC_EDIT_DBUSER, m_strDbUser);
	DDX_Text(pDX, IDC_EDIT_COMSERVER, m_strComServer);
	DDX_Text(pDX, IDC_EDIT_DBSERVER, m_strDbServer);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CInitDlg, CDialog)
	//{{AFX_MSG_MAP(CInitDlg)
	ON_BN_CLICKED(IDC_BTN_OK, OnBtnOk)
	ON_BN_CLICKED(IDC_BTN_EXIT, OnBtnExit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInitDlg message handlers

void CInitDlg::OnOK() 
{
	// TODO: Add extra validation here
	
	//CDialog::OnOK();
}

void CInitDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	//CDialog::OnCancel();
}

void CInitDlg::OnBtnOk() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	long lResult; // 操作注册表函数的返回值
	HKEY lKey;	// 定义一个键的句柄,用来存储被打开的键
	
	lResult = RegCreateKeyEx(MAINKEY, SUBKEY, 0, NULL, REG_OPTION_NON_VOLATILE, 
		KEY_WRITE, NULL, &lKey, NULL);
	if(ERROR_SUCCESS == lResult)
	{
		lResult = RegSetValueEx(lKey, "COM_Server", 0, REG_SZ, LPBYTE(LPCSTR(m_strComServer)),
			m_strComServer.GetLength()+1);	
		lResult = RegSetValueEx(lKey, "DB_Server", 0, REG_SZ, LPBYTE(LPCSTR(m_strDbServer)),
			m_strDbServer.GetLength()+1);	
		lResult = RegSetValueEx(lKey, "DB_Name", 0, REG_SZ, LPBYTE(LPCSTR(m_strDbName)),
			m_strDbName.GetLength()+1);
		lResult = RegSetValueEx(lKey, "DB_User", 0, REG_SZ, LPBYTE(LPCSTR(m_strDbUser)),
			m_strDbUser.GetLength()+1);
		lResult = RegSetValueEx(lKey, "DB_Psw", 0, REG_SZ, LPBYTE(LPCSTR(m_strDbPsw)),
			m_strDbPsw.GetLength()+1);
	}

	CDialog::OnOK();
}

void CInitDlg::OnBtnExit() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnCancel();
}

BOOL CInitDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	// 为对话框添加图标
	HICON  hIcon = AfxGetApp()->LoadIcon(IDI_INIT);
	ASSERT(hIcon != NULL);
	
	SetIcon(hIcon, TRUE);

	m_ComServer.SetFocus();

	return FALSE;    // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BOOL CInitDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message == WM_KEYDOWN)
	{
		if(pMsg->wParam == VK_RETURN)
		{
			//CEdit *pEdit=(CEdit*)GetDlgItem(IDC_EDIT_USERNAME);
			if(pMsg->hwnd == m_ComServer.GetSafeHwnd())
			{				
				m_DbServer.SetFocus();
				m_DbServer.SetSel(0, -1);
				return FALSE;
			}
			if(pMsg->hwnd == m_DbServer.GetSafeHwnd())
			{				
				m_DbName.SetFocus();
				m_DbName.SetSel(0, -1);
				return FALSE;
			}	
			if(pMsg->hwnd == m_DbName.GetSafeHwnd())
			{				
				m_DbUser.SetFocus();
				m_DbUser.SetSel(0, -1);
				return FALSE;
			}	
			if(pMsg->hwnd == m_DbUser.GetSafeHwnd())
			{				
				m_DbPsw.SetFocus();
				m_DbPsw.SetSel(0, -1);
				return FALSE;
			}	
			if(pMsg->hwnd == m_DbPsw.GetSafeHwnd())
			{				
				m_btnOK.SetFocus();
				return FALSE;
			}	
		}
	}

	return CDialog::PreTranslateMessage(pMsg);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -