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

📄 mainsheet.cpp

📁 网络编程
💻 CPP
字号:
// MainSheet.cpp : implementation file
//

#include "stdafx.h"
#include "Chat Server.h"
#include "MainSheet.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();

	virtual BOOL PreTranslateMessage (MSG* pMsg);

// 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)
	virtual BOOL OnInitDialog();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

protected:
	CToolTipCtrl m_tooltip;
};

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()

BOOL CAboutDlg::PreTranslateMessage (MSG* pMsg)
{
	// Let the ToolTip process this message.
	m_tooltip.RelayEvent(pMsg);

	return CDialog::PreTranslateMessage(pMsg);
}

BOOL CAboutDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Create the ToolTip control.
	m_tooltip.Create (this);
	m_tooltip.Activate (TRUE);

	// TODO: Use one of the following forms to add controls:
	// m_tooltip.AddTool (GetDlgItem (IDC_<name>), <string-table-id>);
	// m_tooltip.AddTool (GetDlgItem (IDC_<name>), _T ("<text>"));

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainSheet

CMainSheet::CMainSheet()
: CPropertySheet (IDS_TITLE),m_logMessage("")
{
	// Add the property pages
	AddPage (&m_chatServer);
	AddPage (&m_log);

	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	m_imgTabBmps.Create (IDB_CHATSERVER, 10, 1, RGB (0x00, 0x00, 0xFF));
	for (int i = 1;i < 2;i++)
	{
		CBitmap bmp;
		bmp.LoadBitmap (IDB_CHATSERVER + i);
		m_imgTabBmps.Add (&bmp, RGB (0x00, 0x00, 0xFF));
	}
}

CMainSheet::~CMainSheet()
{
}


BEGIN_MESSAGE_MAP(CMainSheet, CPropertySheet)
	//{{AFX_MSG_MAP(CMainSheet)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(IDM_ABOUTBOX, OnAboutbox)
	ON_WM_SIZE()
	ON_REGISTERED_MESSAGE(WM_ICONNOTIFY, OnIconNotify)
	ON_COMMAND(ID_ICON_SHUTDOWN, OnIconShutdown)
	ON_COMMAND(ID_ICON_RESTORE, OnIconRestore)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CMainSheet message handlers

BOOL CMainSheet::OnInitDialog()
{

	CPropertySheet::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);
	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

	GetTabControl ()->SetImageList (&m_imgTabBmps);
	TC_ITEM tci = {TCIF_IMAGE};
	for (tci.iImage = 0;tci.iImage < 2;tci.iImage++)
		GetTabControl ()->SetItem (tci.iImage, &tci);

	// Create the ToolTip control.
	m_tooltip.Create (this);
	m_tooltip.Activate (TRUE);

	// TODO: Use one of the following forms to add controls:
	// m_tooltip.AddTool (GetDlgItem (IDC_<name>), <string-table-id>);
	// m_tooltip.AddTool (GetDlgItem (IDC_<name>), _T ("<text>"));

	//Link the CChatServer sheet with me.
	m_chatServer.SetOwner(this);
	m_log.SetOwner(this);

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

void CMainSheet::PostNcDestroy() 
{
	CPropertySheet::PostNcDestroy();

	delete this;
}

void CMainSheet::OnSysCommand(UINT nID, LPARAM lParam) 
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		switch (nID)
		{
		case SC_CLOSE:
			DestroyWindow ();
			break;
		default:
			CPropertySheet::OnSysCommand (nID, lParam);
			break;
		}
	}
}

// If you add a minimize button to your property sheet, 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 CMainSheet::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
	{
		CPropertySheet::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.

HCURSOR CMainSheet::OnQueryDragIcon() 
{
	return (HCURSOR (m_hIcon));
}

BOOL CMainSheet::OnCommand(WPARAM wParam, LPARAM lParam) 
{
	if (HIWORD (wParam) == BN_CLICKED)
	{
		switch (LOWORD (wParam))
		{
		case IDOK:
			PressButton (PSBTN_OK);
			DestroyWindow ();
			return (TRUE);
		case 0x3021:	// Apply
			PressButton (PSBTN_APPLYNOW);
			return (TRUE);
		case IDCANCEL:
			PressButton (PSBTN_CANCEL);
			DestroyWindow ();
			return (TRUE);
		case IDHELP:
			PressButton (PSBTN_HELP);
			return (TRUE);
		}
	}
	return CPropertySheet::OnCommand(wParam, lParam);
}

void CMainSheet::OnAboutbox() 
{
	CAboutDlg dlgAbout;
	dlgAbout.DoModal();
}

void CMainSheet::OnSize(UINT nType, int cx, int cy) 
{
	CPropertySheet::OnSize(nType, cx, cy);

	NOTIFYICONDATA nid = {sizeof (nid), GetSafeHwnd (), 100, NIF_ICON|NIF_MESSAGE|NIF_TIP, WM_ICONNOTIFY, m_hIcon};
	CString niTip;
	niTip.LoadString (IDS_TITLE);
	strcpy (nid.szTip, niTip);
	switch (nType)
	{
	case SIZE_MINIMIZED:
		ShowWindow (SW_HIDE);
		Shell_NotifyIcon (NIM_ADD, &nid);
		AfxGetApp ()->WriteProfileInt (_T ("StartUp"), _T ("StartOnTaskBar"), TRUE);
		break;
	case SIZE_RESTORED:
		Shell_NotifyIcon (NIM_DELETE, &nid);
		AfxGetApp ()->WriteProfileInt (_T ("StartUp"), _T ("StartOnTaskBar"), FALSE);
		static BOOL bFirst = TRUE;
		if (bFirst && GetTabControl () != NULL)
		{
			bFirst = FALSE;

			CWnd *pTab = GetTabControl ();
			CRect rTab;
			pTab->GetWindowRect (rTab);

			SetWindowPos (NULL, rTab.left - 9, rTab.top - 29, rTab.Width () + 18, rTab.Height () + 35, SWP_NOACTIVATE|SWP_NOZORDER);
		}
		break;
	}
}

LRESULT CMainSheet::OnIconNotify(WPARAM wParam, LPARAM lParam)
{
	if (wParam == 100)
	{
		switch (lParam)
		{
		case WM_LBUTTONDBLCLK:
			PostMessage (WM_COMMAND, ID_ICON_RESTORE);
			break;
		case WM_RBUTTONDOWN:
			{
				CMenu menu;
				menu.LoadMenu (IDR_MAINFRAME);
				CPoint pt;
				::GetCursorPos (&pt);
				menu.GetSubMenu (0)->TrackPopupMenu (TPM_RIGHTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y, this);
			}
			break;
		}
	}
	return (0);
}

void CMainSheet::OnIconShutdown() 
{
	NOTIFYICONDATA nid = {sizeof (nid), GetSafeHwnd (), 100, NIF_ICON|NIF_MESSAGE|NIF_TIP, WM_ICONNOTIFY, m_hIcon};
	CString niTip;
	niTip.LoadString (IDS_TITLE);
	strcpy (nid.szTip, niTip);
	Shell_NotifyIcon (NIM_DELETE, &nid);
	DestroyWindow ();
}

void CMainSheet::OnIconRestore() 
{
	ShowWindow (SW_RESTORE);
}


BOOL CMainSheet::PreTranslateMessage(MSG* pMsg)
{
	// Let the ToolTip process this message.
	m_tooltip.RelayEvent (pMsg);

	return CPropertySheet::PreTranslateMessage (pMsg);
}



CString CMainSheet::GetLogMessage()
{
	return m_logMessage;
}

void CMainSheet::SetLogMessage(CString &msg)
{
	m_logMessage += msg;
	m_logMessage +="\r\n";
}

⌨️ 快捷键说明

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