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

📄 mainoptions.cpp

📁 vc++6.0开发网络典型应用实例导航 1. 本光盘提供了本书中所有的实例源程序文件。 2. 附录文件夹下是Winsock 函数参考以及错误码列表
💻 CPP
字号:
// MainOptions.cpp : implementation file
//

#include "stdafx.h"
#include "Netmsg.h"
#include "MainOptions.h"
#include "ContactView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMainOptions property page

IMPLEMENT_DYNCREATE(CMainOptions, CPropertyPage)

CMainOptions::CMainOptions(CContactView *view, int* pingtime, int* reconnecttime, 
				   int *showips, int *usepopup, int *useemoticons, char *secwarning)
				   : CPropertyPage(CMainOptions::IDD)
{
	//{{AFX_DATA_INIT(CMainOptions)
	m_ShowIps = FALSE;
	m_Usepopup = FALSE;
	m_Emoticons = FALSE;
	//}}AFX_DATA_INIT
	View = view;
	PingTime = pingtime;
	ReconnectTime = reconnecttime;
	ShowIps = showips;
	UsePopup = usepopup;
	UseEmoticons = useemoticons;
	SecurityWarning = secwarning;

}

CMainOptions::~CMainOptions()
{
}

void CMainOptions::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMainOptions)
	DDX_Check(pDX, IDC_SHOWIPS, m_ShowIps);
	DDX_Check(pDX, IDC_USEPOPUP, m_Usepopup);
	DDX_Check(pDX, IDC_EMOTICONS, m_Emoticons);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMainOptions, CPropertyPage)
	//{{AFX_MSG_MAP(CMainOptions)
	ON_EN_CHANGE(IDC_SCREENNAME, OnChangeScreenname)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMainOptions message handlers

BOOL CMainOptions::OnApply() 
{
	char buf[512];

	GetDlgItem(IDC_SCREENNAME)->GetWindowText(buf, sizeof(buf));

	if (!stricmp(buf, ""))
	{
		MessageBox("Please enter a screen name", "Error", MB_OK|MB_ICONSTOP);
		return FALSE;
	}

 	if (strlen(buf) > 64)
	{
		sprintf(buf, "The screen name you have entered is too long, please keep it below 64 charactors, you had %d charactors. please remove %d charactors",
			strlen(buf), strlen(buf) - 64);
		MessageBox(buf, "Error", MB_OK|MB_ICONSTOP);
		return FALSE;
	}

	GetApp()->View->ChangeMyName(buf);

	return CPropertyPage::OnApply();
}

void CMainOptions::OnOK() 
{
	char buf[512];
	char szPing[64], szReconnect[64];
	GetDlgItem(IDC_SCREENNAME)->GetWindowText(buf, sizeof(buf));
	GetDlgItem(IDC_PINGTIME)->GetWindowText(szPing, sizeof(szPing));
	GetDlgItem(IDC_RECONNECT)->GetWindowText(szReconnect, sizeof(szReconnect));
	GetDlgItem(IDC_STARTUP)->GetWindowText(SecurityWarning, 502);
	UpdateData();
	if (atoi(szPing) < 1 || atoi(szReconnect) < 1)
	{
		MessageBox("Delay times must be greater than one (1) second.", "Error", MB_OK|MB_ICONSTOP);
		return;
	}

	*PingTime = atoi(szPing) * 1000;
	*ReconnectTime = atoi(szReconnect) * 1000;
	
	if (!stricmp(buf, ""))
	{
		MessageBox("Please enter a screen name", "Error", MB_OK|MB_ICONSTOP);
		return;
	}

 	if (strlen(buf) > 64)
	{
		sprintf(buf, "The screen name you have entered is too long, please keep it below 64 charactors, you had %d charactors. please remove %d charactors",
			strlen(buf), strlen(buf) - 64);
		MessageBox(buf, "Error", MB_OK|MB_ICONSTOP);
		return;
	}
	*ShowIps = m_ShowIps;
	*UsePopup = m_Usepopup;
	*UseEmoticons = m_Emoticons;
	GetApp()->View->ChangeMyName(buf);

	CPropertyPage::OnOK();
}


BOOL CMainOptions::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	CButton *bShowIps = (CButton *)GetDlgItem(IDC_SHOWIPS);
	CButton *bUsePopup = (CButton *)GetDlgItem(IDC_USEPOPUP);
	CButton *bUseEmoticons = (CButton *)GetDlgItem(IDC_EMOTICONS);

	CEdit *eStartup = (CEdit *)GetDlgItem(IDC_STARTUP);

	eStartup->LimitText(500);

	char szPing[64], szReconnect[64];

	itoa(*PingTime / 1000, szPing, 10);
	itoa(*ReconnectTime / 1000, szReconnect, 10);

	GetDlgItem(IDC_PINGTIME)->SetWindowText(szPing);
	GetDlgItem(IDC_RECONNECT)->SetWindowText(szReconnect);
	GetDlgItem(IDC_SCREENNAME)->SetWindowText(View->Me.GetScreenName());

	if (SecurityWarning)
		GetDlgItem(IDC_STARTUP)->SetWindowText(SecurityWarning);

	bUsePopup->SetCheck(*UsePopup);
	bShowIps->SetCheck(*ShowIps);
	bUseEmoticons->SetCheck(*UseEmoticons);

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

void CMainOptions::OnChangeScreenname() 
{
	SetModified();	
}

⌨️ 快捷键说明

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