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

📄 conversation.cpp

📁 vc++6.0开发网络典型应用实例导航 1. 本光盘提供了本书中所有的实例源程序文件。 2. 附录文件夹下是Winsock 函数参考以及错误码列表
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	else if (Contact->IsBlocked())
	{
		ShowMessage("You cannot send messages to this contact because you have blocked him/her.");
		Disable();
	}
	else if (Contact->IsAway())
	{
		char buf[512];
		sprintf(buf, "This contact may not reply because he/she is away (%s).", Contact->GetAwayReason());
		ShowMessage(buf);
		Enable();
	}
	else if (GetApp()->View->Me.IsAway())
	{
		ShowMessage("You are currently set to 'Away'.");
		if (!Enabled) Enable();
	}
	else
	{
		if (HasMessage) HideMessage();
		if (!Enabled) Enable();
	}
}

void CConversation::SetBlocked(bool bBlocked)
{
	CHECK_WND(m_SendFile)
	CHECK_WND(m_Block)

	if (bBlocked)
	{
		CMenu *Menu = GetMenu(), *SubMenu;
		SubMenu = Menu->GetSubMenu(1);
		SubMenu->ModifyMenu(ID_IDRCONVERSATIONMENU_BLOCK, MF_BYCOMMAND | MF_STRING, ID_IDRCONVERSATIONMENU_BLOCK, "Unblock");
		m_SendFile.EnableWindow(FALSE);
		m_Block.SetIcons(m_iUnblock);
		m_Block.SetWindowText("Unblock");
		m_Block.Invalidate();
	}
	else
	{
		CMenu *Menu = GetMenu(), *SubMenu;
		SubMenu = Menu->GetSubMenu(1);
		SubMenu->ModifyMenu(ID_IDRCONVERSATIONMENU_BLOCK, MF_BYCOMMAND | MF_STRING, ID_IDRCONVERSATIONMENU_BLOCK, "Block");
		m_SendFile.EnableWindow(TRUE);
		m_Block.SetIcons(m_iBlock);
		m_Block.SetWindowText("Block");
		m_Block.Invalidate();
	}
}

void CConversation::SetNoSend(bool bNoSend)
{
	if (bNoSend)
	{
		CMenu *Menu = GetMenu(), *SubMenu;
		SubMenu = Menu->GetSubMenu(1);
		SubMenu->EnableMenuItem(ID_IDRCONVERSATIONMENU_SENDFILE, MF_GRAYED | MF_DISABLED);
		m_SendFile.EnableWindow(FALSE);
	}
	else
	{
		CMenu *Menu = GetMenu(), *SubMenu;
		SubMenu = Menu->GetSubMenu(1);
		SubMenu->EnableMenuItem(ID_IDRCONVERSATIONMENU_SENDFILE, MF_ENABLED);
		m_SendFile.EnableWindow(TRUE);
	}
}

void CConversation::OnSendfile() 
{
	GetApp()->View->StartFileTransfer(GetSafeHwnd(), Contact, true);
}


/////////////////////// File tansfer members ///////////////////////


BOOL CConversation::InitStatus(CFileSocketThread *pThread, CContact *pContact, bool bSending, char *szFileName)
{
	char buf[512], buf2[512];

	CHECK_WND_P0(this)
	CHECK_WND0(m_Cancel)
	CHECK_WND0(m_Progress)
	CHECK_WND0(m_FileStats)
	CHECK_WND0(m_Chat)
	CHECK_WND0(m_TransferStats)

	strcpy(FileName, szFileName);

	Thread = pThread;
	Sending = bSending;

	m_Progress.SetRange(0, 100);

	HideMessage();

	IsTransfering = true;
	
	RECT rect;
	GetClientRect(&rect);

	m_Cancel.ShowWindow(SW_SHOW);
	m_Cancel.MoveWindow(220, 28, 45, 16);

	m_Progress.ShowWindow(SW_SHOW);
	m_Progress.MoveWindow(10, 29, 200, 14);
	m_Progress.SetPos(0);
	m_Progress.SetTextColor(GetColor(COL_NORMALTEXT));
	m_FileStats.ShowWindow(SW_SHOW);
	m_TransferStats.ShowWindow(SW_SHOW);

	if (rect.bottom - 198 < 40)
	{
		SetSplitterPos(m_SplitterPos - (40 - (rect.bottom - 198)));
	}

	m_bgWnd.MoveWindow(6, 82, rect.right - 10, rect.bottom - 198);

	nopath(buf, szFileName);

	sprintf(buf2, "%s: %s", Sending ? "Sending" : "Receiving", buf);

	m_FileStats.SetWindowText(buf2);
	m_TransferStats.SetWindowText("");
	m_Cancel.SetWindowText("Cancel");

	GetWindowRect(&rect);

	if (rect.right - rect.left < 300)
	{
		MoveWindow(rect.left, rect.top, 300, rect.bottom - rect.top);
	}

	if (rect.bottom - rect.top < 289)
	{
		MoveWindow(rect.left, rect.top, rect.right - rect.left, 289);
		SetSplitterPos(0);
	}

	UpdateSizes();
	RedrawEssential();

	return 1;
}

void CConversation::SetPercent(int nPercent)
{
	char buf[512], buf2[512];

	CHECK_WND_P(this)
	CHECK_WND(m_Progress)

	m_Progress.SetPos(nPercent);
	if (nPercent > 50) 
		m_Progress.SetTextColor(RGB(255, 255, 255));
	nopath(buf2, FileName);
	sprintf(buf, "Conversation: %s (%s %d%% of %s)", Contact->GetScreenName(), Sending ? "Sent" : "Received", nPercent, buf2);
	SetWindowText(buf);
}

void CConversation::SetStats(unsigned long Total, unsigned long Transfered)
{
	char buf[512], buf3[64], buf4[64];

	CHECK_WND_P(this)
	CHECK_WND(m_TransferStats)

	strcpy(buf3, FormatBytes(Total));
	strcpy(buf4, FormatBytes(Contact->Transfer->FileLen));
	sprintf(buf, "Transfer rate: %s/s %s: %s of %s", FormatBytes(Transfered), 
		Sending ? "Sent" : "Received", buf3, buf4);
	m_TransferStats.SetWindowText(buf);
}

void CConversation::SetStatus(const char *Text)
{
	char buf[512];

	CHECK_WND_P(this)
	CHECK_WND(m_FileStats)

	strcpy(buf, "Status: ");
	strcat(buf, Text);
	m_FileStats.SetWindowText(buf);
}

void CConversation::Remove()
{
	char buf[512];

	CHECK_WND_P(this)
	CHECK_WND(m_Cancel)
	CHECK_WND(m_Progress)
	CHECK_WND(m_FileStats)
	CHECK_WND(m_TransferStats)

	IsTransfering = false;
	RECT rect;
	GetClientRect(&rect);
	SendMessage(WM_PAINT, 0, 0);
	m_TransferStats.ShowWindow(SW_HIDE);
	m_FileStats.ShowWindow(SW_HIDE);
	m_Progress.ShowWindow(SW_HIDE);
	m_Cancel.ShowWindow(SW_HIDE);
	SendMessage(WM_PAINT, 0, 0);
	UpdateWindow();
	SetTimer(1, 1, 0);
	sprintf(buf, "Conversation: %s", Contact->GetScreenName());
	SetWindowText(buf);
	UpdateSizes();
	RedrawEssential();
}

void CConversation::Ended()
{
	CHECK_WND(m_Cancel)
	CHECK_WND_P(this)

	m_Cancel.SetWindowText("Close");
	m_TransferStats.SetWindowText("");
	m_Cancel.Invalidate();
}

void CConversation::OnTransferCancel() 
{
	Remove();
	if (Thread)
	Thread->Kill();	
}

///////////////////////////////////////////////////////////////////////

void CConversation::OnOK() 
{	

}

void CConversation::OnCancel() 
{

}

void CConversation::UpdateSizes()
{
	RECT clientRect;

	CHECK_WND(m_Chat)
	CHECK_WND(m_SendButton)
	CHECK_WND(m_To)
	CHECK_WND(m_SendFile)
	CHECK_WND(m_Message)
	CHECK_WND(m_TransferStats)
	CHECK_WND(m_FileStats)
	CHECK_WND(m_SendMsg)

	GetClientRect(&clientRect);

	RECT rect;

	if (HasMessage)
	{
		m_bgWnd.MoveWindow(6, 46, clientRect.right - 10, (clientRect.bottom - 162) - m_SplitterPos);
	}
	else if (IsTransfering)
	{
		m_bgWnd.MoveWindow(6, 82, clientRect.right - 10, (clientRect.bottom - 198) - m_SplitterPos);
	}
	else
	{
		m_bgWnd.MoveWindow(6, 30, clientRect.right - 10, (clientRect.bottom  - 146) - m_SplitterPos);
	}

	if (IsTransfering)
	{
		m_FileStats.MoveWindow(10, 46, clientRect.right - 20, 14);
		m_TransferStats.MoveWindow(10, 64, clientRect.right - 20, 14);
	}

	m_Chat.GetClientRect(&rect);
	if (rect.bottom < 40)
	{
		if (clientRect.bottom > 0)
		SetSplitterPos(m_SplitterPos - (40 - rect.bottom));
	}

	m_SendMsg.MoveWindow(6, (clientRect.bottom - 78) - m_SplitterPos, clientRect.right - 73, 54 + m_SplitterPos);
	m_SendButton.MoveWindow(clientRect.right - 60, (clientRect.bottom - 72) - m_SplitterPos, 52, 45);
	m_To.MoveWindow(6, 4, clientRect.right - 6, 18);
	m_Message.MoveWindow(10, 28, clientRect.right - 20, 18);
	m_Block.MoveWindow(clientRect.right - 84, (clientRect.bottom - 116) - m_SplitterPos, 80, 34);
	m_SendFile.MoveWindow(clientRect.right - 169, (clientRect.bottom - 116) - m_SplitterPos, 85, 34);
	m_Splitter.MoveWindow(4, (clientRect.bottom - 82) - m_SplitterPos, clientRect.right - 8, 4);
	RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);

	m_Block.Invalidate();
	m_SendFile.Invalidate();
}

void CConversation::ColorUpdate()
{
	m_Message.SetColors(GetColor(COL_NORMALTEXT), GetColor(COL_LIGHTITEMS));
	m_Progress.SetBkColor(GetColor(COL_LIGHTITEMS));
	m_To.SetColors(GetColor(COL_NOTIFYTEXT), GetColor(COL_LINEFRAMES));
	m_Progress.SetTextColor(GetColor(COL_NORMALTEXT));
	m_TransferStats.SetColors(GetColor(COL_NORMALTEXT), GetColor(COL_LIGHTITEMS));
	m_FileStats.SetColors(GetColor(COL_NORMALTEXT), GetColor(COL_LIGHTITEMS));

	BrushNormal.DeleteObject();
	BrushLight.DeleteObject();
	BrushDisabled.DeleteObject();

	BrushNormal.CreateSolidBrush(GetColor(COL_LINEFRAMES));
	BrushLight.CreateSolidBrush(GetColor(COL_LIGHTITEMS));
	BrushDisabled.CreateSolidBrush(GetColor(COL_DISABLED));

	RedrawWindow();
}

void CConversation::RedrawEssential()
{
	CRect rect;
	CRect rcUpdate;
	GetClientRect(rect);
	rcUpdate.SetRect(0, 18, rect.right, rect.bottom - 18);
	RedrawWindow(&rcUpdate);
}

void CConversation::PrepareHtmlHelp()
{
	POSITION pos;
	char szTempPath[1024];
	char szFilePath[1024];
	char cwd[1024];

	CList<EMOTICON *, EMOTICON *> &Emoticons = GetApp()->View->Emoticons;
	FILE *f;

	::GetTempPath(sizeof(szTempPath), szTempPath);
	getcwd(cwd, sizeof(cwd));
	sprintf(szFilePath, "%spre%u.htm", szTempPath, GetVersion());
	f = fopen(szFilePath, "w");
	if (!f)
	{
		MessageBox("There was an error while attempting to write out the help file", "Error", MB_ICONSTOP|MB_OK);
		return;
	}
	fprintf(f,

	"<html>\r\n"
	"<head>\r\n"
	"<title>Network Messenger Emoticons Help</title>\r\n"
	"</head>\r\n"
	"<body>\r\n"
	"<font face=\"verdana, arial, helvetica\" size=\"2\">\r\n"
	"Below is a list of emoticons currently loaded into Network Messenger.<br>\r\n"
	"Type the text in the 'Text' Column and it will be replaced with the associated emoticon.<br><br>\r\n"
	"Emoticons can be added/removed in emoticons.ini.<br><br>\r\n"
	"</font>\r\n"
	"<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" align=\"left\">\r\n"
	"<tr>\r\n"
	"<td><p align=\"center\"><font face=\"verdana, arial, helvetica\" size=\"2\">&nbsp;Text&nbsp;</font></p></td>\r\n"
	"<td><p align=\"center\"><font face=\"verdana, arial, helvetica\" size=\"2\">&nbsp;Emoticon&nbsp;</font></p></td>\r\n"
	"</tr>\r\n"

	);

	pos = Emoticons.GetHeadPosition();
	while (pos)
	{
		EMOTICON *Emoticon = Emoticons.GetNext(pos);
		fprintf(f, 

		"<tr>\r\n"
		"<td><p align=\"center\"><font face=\"verdana, arial, helvetica\" size=\"2\">%s</font></p></td>\r\n"
		"<td><p align=\"center\"><img src=\"file:///%s\\%s\"></p></td>\r\n"
		"</tr>\r\n",

		Emoticon->szActivationText, cwd, Emoticon->szFileName);
	}
	fprintf(f, 

	"</table>\r\n"
	"</body>\r\n"
	"</html>\r\n"
	);

	fclose(f);
	ShellExecute(GetSafeHwnd(), "OPEN", szFilePath, NULL, NULL, SW_SHOW);
}

void CConversation::OnHelpEmoticonshelp() 
{
	PrepareHtmlHelp();	
}

⌨️ 快捷键说明

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