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

📄 conversation.cpp

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

void CConversation::OnIdrconversationmenuBlock() 
{
	if (Contact->IsBlocked())
	::SendMessage(GetApp()->View->GetSafeHwnd(), WM_BLOCKTHISCONTACT, 0, (LPARAM) Contact); 	
	else
	{
		if (Contact->IsTransfering())
		{
			MessageBox("You cannot block a contact with a file transfer in progress", "Block contact", MB_OK|MB_ICONSTOP);
			return;
		}
		else
		::SendMessage(GetApp()->View->GetSafeHwnd(), WM_BLOCKTHISCONTACT, 1, (LPARAM) Contact); 	
	}
}

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

void CConversation::FileDropped(char *FileName, unsigned int Len)
{
	GetApp()->View->StartFileTransfer(GetSafeHwnd(), Contact, true, FileName);
}

HBRUSH CConversation::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	if (pWnd == this || pWnd == &m_Chat)
	return (HBRUSH) BrushWhite;

	else if (pWnd == &m_SendMsg)
	{
		if (Enabled) return (HBRUSH) BrushWhite;
		else return (HBRUSH) BrushDisabled;
	}
	else if (pWnd == &m_To || pWnd == &m_Splitter)
	return (HBRUSH) BrushNormal;

	else if (pWnd == &m_Message || pWnd == &m_Block || pWnd == &m_SendFile
		|| pWnd == &m_Cancel || pWnd == &m_FileStats || pWnd == &m_TransferStats)
	return (HBRUSH) BrushLight;

	return NULL;
}

void CConversation::OnIdrconversationmenuChangefont() 
{
	CHOOSEFONT cf;
	USERFONT uf;

	memcpy(&uf, &GetApp()->View->Me.uFont, sizeof(USERFONT));

	cf.lStructSize = sizeof(CHOOSEFONT);
	cf.hwndOwner = GetSafeHwnd();
	cf.iPointSize = uf.nPointSize;
	cf.lpLogFont = &uf.lfFont;
	cf.hInstance = AfxGetInstanceHandle();
	cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_BOTH;

	Font.DeleteObject();

	ChooseFont(&cf);

	Font.CreateFontIndirect(&uf.lfFont);

	uf.nPointSize = cf.iPointSize;

	memcpy(&GetApp()->View->Me.uFont, &uf, sizeof(USERFONT));

	GetApp()->View->SendMessage(WM_UPDATEMYFONT, 0, 0);

	m_SendMsg.SetFont(&Font);
}

void CConversation::OnActionsChooseadvancedcolor() 
{
	CHOOSECOLOR cc;
	static COLORREF acrCustClr[16];

	ZeroMemory(&cc, sizeof(CHOOSECOLOR));
	cc.lStructSize = sizeof(CHOOSECOLOR);
	cc.hwndOwner = GetSafeHwnd();
	cc.lpCustColors = (LPDWORD) acrCustClr;
	cc.rgbResult = GetApp()->View->Me.uFont.crColor;
	cc.Flags = CC_FULLOPEN | CC_RGBINIT;
 
	if (ChooseColor(&cc))
	{
		GetApp()->View->Me.uFont.crColor =  cc.rgbResult;
		GetApp()->View->SendMessage(WM_UPDATEMYFONT, 0, 0);
	}
}

void CConversation::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 
{
	if (IsTransfering) lpMMI->ptMinTrackSize.y = 289;
	else if (HasMessage) lpMMI->ptMinTrackSize.y = 253;
	else lpMMI->ptMinTrackSize.y = 237;
	if (IsTransfering) lpMMI->ptMinTrackSize.x = 300;
	else lpMMI->ptMinTrackSize.x = 185;

	CDialog::OnGetMinMaxInfo(lpMMI);
}

void CConversation::HostResolved(const char *NewHost)
{
	CHECK_WND_P(this)
	CHECK_WND(m_To)

	char buf[512];
	strcpy(Host, NewHost);
	sprintf(buf, "To: %s (%s) %s", Contact->GetTruncatedScreenName(32), Contact->GetHostName().Get(), NewHost);
	m_To.SetWindowText(buf);
}

void CConversation::ScreenNameChanged(const char *NewName)
{
	char buf[512];

	CHECK_WND_P(this)
	CHECK_WND(m_To)

	sprintf(buf, "Conversation: %s", NewName);
	SetWindowText(buf);
	sprintf(buf, "To: %s (%s) %s", Contact->GetTruncatedScreenName(32), Contact->GetHostName().Get(), Host);
	m_To.SetWindowText(buf);
}

LRESULT CConversation::ReceivedMessage(WPARAM wParam, LPARAM lParam)
{
	CHECK_WND_P0(this)
	CHECK_WND0(m_Chat)

	char *Message = (char *)lParam;


	m_Chat.AppendWindowTextF(&ufFontNormal, 0, "%s says:\r\n", wParam ? 
		GetApp()->View->Me.GetScreenName() : Contact->GetScreenName()); 

	m_Chat.AppendWindowTextF(wParam ? &GetApp()->View->Me.uFont : &Contact->uFont, 200, "%s\r\n", Message);

	PluginsMessageReceived(Contact, Message);

	delete [] Message;

	if (!wParam)
		FlashWindow(TRUE);

	return 0L;
}

LRESULT CConversation::OnTypeNotify(WPARAM wParam, LPARAM lParam)
{
	char buf[512];

	CHECK_WND_P0(this)
	CHECK_WND0(m_statusBar)

	if (wParam)
	{
		sprintf(buf, "%s is typing a message", Contact->GetTruncatedScreenName(32));
		m_statusBar.SetWindowText(buf);
	}
	else
		m_statusBar.SetWindowText("");
	return 0L;
}

void CConversation::OnClose() 
{
	if (IsTransfering)
	if (Thread)
	if (!Thread->Finished)
	{
		MessageBox("You cannot close this window with a transfer in progress", "Close window", MB_OK|MB_ICONSTOP);
		return;
	}

	WINDOWPLACEMENT windowPlacement;
	GetWindowPlacement(&windowPlacement);
	if (windowPlacement.showCmd != SW_SHOWMINIMIZED)
	AfxGetApp()->WriteProfileBinary("Settings", "WindowPosChat", (BYTE*)&windowPlacement, sizeof(WINDOWPLACEMENT));		
	AfxGetApp()->WriteProfileInt("Settings", "SplitterPos", m_SplitterPos);
	EndDialog(IDOK);
}

void CConversation::ShowMessage(const char *Text)
{
	if (IsTransfering) return;

	CHECK_WND(m_Message)
	CHECK_WND(m_Chat)

	HasMessage = true;
	m_Message.SetWindowText(Text);
	m_Message.ShowWindow(SW_SHOW);

	RECT rect;
	GetWindowRect(&rect);
	if (rect.bottom - rect.top < 253)
	{
		MoveWindow(rect.left, rect.top, rect.right - rect.left, 253);
		SetSplitterPos(0);
	}

	UpdateSizes();
	RedrawEssential();
}

void CConversation::HideMessage()
{
	if (IsTransfering) return;

	CHECK_WND(m_Message)
	CHECK_WND(m_Chat)

	HasMessage = false;
	m_Message.SetWindowText("");
	m_Message.ShowWindow(SW_HIDE);
	UpdateSizes();
	RedrawEssential();
}

void CConversation::Disable()
{
	CHECK_WND(m_SendMsg)
	CHECK_WND(m_SendButton)

	Enabled = false;
	m_SendMsg.Enable(false);
	m_SendButton.SetCornerColor(GetColor(COL_DISABLED));
	m_SendButton.EnableWindow(FALSE);
	SendMessage(WM_PAINT, 0, 0);
	SetNoSend(true);
	SetTimer(2, 1, 0);
	RedrawEssential();
}

void CConversation::Enable()
{
	CHECK_WND(m_SendMsg)
	CHECK_WND(m_SendButton)

	Enabled = true;
	m_SendMsg.Enable(true);
	m_SendButton.SetCornerColor(RGB(255, 255, 255));
	SendMessage(WM_PAINT, 0, 0);
	SetNoSend(false);
	OnChangeSendmsg();
	RedrawEssential();
}

void CConversation::SplitterMoved(int pos)
{
	RECT rect;
	RECT clientRect;
	RECT chatRect;
	POINT cur, point;
	int NewPos = 0;

	GetClientRect(&clientRect);
	GetCursorPos(&cur);
	GetWindowRect(&rect);

	m_bgWnd.GetClientRect(&chatRect);

	point.x = cur.x - rect.right;
	point.y = cur.y - rect.top;
	
	NewPos = point.y - (clientRect.bottom - 82);
	NewPos = -NewPos + 48;

	if (NewPos >= 0 && chatRect.bottom > 40)
	SetSplitterPos(NewPos);
	
	else if (NewPos < m_SplitterPos && NewPos >= 0)
	SetSplitterPos(NewPos);
	
	else if (NewPos < 0)
	{
		if (!m_SplitterPos) return;
		SetSplitterPos(0);
	}
}

void CConversation::SetSplitterPos(int pos)
{
	RECT clientRect;
	RECT rectUpdate;
	GetClientRect(&clientRect);

	m_SplitterPos = pos;
	
	UpdateSizes();

	rectUpdate.left = 0;
	rectUpdate.right = clientRect.right;
	rectUpdate.top = 40;
	rectUpdate.bottom = clientRect.bottom - 30;

	RedrawWindow(&rectUpdate);
}

void CConversation::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	RECT rect;
	GetClientRect(&rect);

	dc.FillSolidRect(0, 0, rect.right, 4, GetColor(COL_LINEFRAMES)); //top
	dc.FillSolidRect(0, 4, 6, 18, GetColor(COL_LINEFRAMES)); //padding before IP static
	dc.FillSolidRect(0, 28, 4, rect.bottom - 56, GetColor(COL_LINEFRAMES)); //left side
	dc.FillSolidRect(rect.right - 4, 28, 4, rect.bottom - 56, GetColor(COL_LINEFRAMES));//right side
	dc.FillSolidRect(10, rect.bottom - 22, rect.right - 20, 4, GetColor(COL_LINEFRAMES));//bottom

	dc.FillSolidRect(4, (rect.bottom - 116) - m_SplitterPos, rect.right - 8, 34, GetColor(COL_LIGHTITEMS)); //light blue bar

	if (HasMessage)
	{
		dc.FillSolidRect(10, 22, rect.right - 20, 6, GetColor(COL_LIGHTITEMS));
		dc.FillSolidRect(4, 28, 6, 18, GetColor(COL_LIGHTITEMS));
		dc.FillSolidRect(rect.right - 10, 28, 6, 18, GetColor(COL_LIGHTITEMS));
	}

	if (IsTransfering)
	{
		dc.FillSolidRect(10, 22, rect.right - 20, 6, GetColor(COL_LIGHTITEMS));
		dc.FillSolidRect(4, 28, rect.right - 8, 54, GetColor(COL_LIGHTITEMS));
		m_Progress.Invalidate();
	}

	if (!Enabled)
	{
		dc.FillSolidRect(rect.right - 8, rect.bottom - 78 - m_SplitterPos, 4, 50 + m_SplitterPos, GetColor(COL_DISABLED));
		dc.FillSolidRect(rect.right - 67, rect.bottom - 78 - m_SplitterPos, 59, 6, GetColor(COL_DISABLED));
		dc.FillSolidRect(rect.right - 60, rect.bottom - 27 - m_SplitterPos, 52, 5 + m_SplitterPos, GetColor(COL_DISABLED));
		dc.FillSolidRect(4, rect.bottom - 78 - m_SplitterPos, 6, 50 + m_SplitterPos, GetColor(COL_DISABLED));
		dc.FillSolidRect(10, rect.bottom - 78 - m_SplitterPos, rect.right - 69, 56 + m_SplitterPos, GetColor(COL_DISABLED));
	}

	DrawCorner(&dc, 0, 18, GetColor(COL_LINEFRAMES), 1, HasMessage || IsTransfering, GetColor(COL_LIGHTITEMS));
	DrawCorner(&dc, rect.right - 10, 18, GetColor(COL_LINEFRAMES), 2, HasMessage || IsTransfering, GetColor(COL_LIGHTITEMS));
	DrawCorner(&dc, 0, rect.bottom - 28, GetColor(COL_LINEFRAMES), 3, !Enabled, GetColor(COL_DISABLED));
	DrawCorner(&dc, rect.right - 10, rect.bottom - 28, GetColor(COL_LINEFRAMES), 4, !Enabled, GetColor(COL_DISABLED));
}

void CConversation::OnFileClose() 
{
	SendMessage(WM_CLOSE, 0, 0);	
}

void CConversation::OnBlock() 
{
	if (Contact->IsBlocked())
	{
		::SendMessage(GetApp()->View->GetSafeHwnd(), WM_BLOCKTHISCONTACT, 0, (LPARAM) Contact); 	
	}
	else
	{
		if (Contact->IsTransfering())
		{
			MessageBox("You cannot block a contact with a file transfer in progress", "Block contact", MB_OK|MB_ICONSTOP);
			return;
		}
		else
		::SendMessage(GetApp()->View->GetSafeHwnd(), WM_BLOCKTHISCONTACT, 1, (LPARAM) Contact); 
	}
}

void CConversation::UpdateWindow()
{
	CHECK_WND_P(this)

	if (Contact->IsBlocked())
	{
		SetBlocked(true);
	}
	else
	{
		SetBlocked(false);
	}

	if (Contact->IsOffline())
	{
		ShowMessage("You cannot send messages to this contact because he/she is offline.");
		Disable();
	}
	else if (GetApp()->View->Me.IsOffline())
	{
		ShowMessage("You cannot send messages because you are set to 'Appear Offline'.");
		Disable();
	}

⌨️ 快捷键说明

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