📄 windialog.cs
字号:
/*
<Aicaca Community Messenger Client>
Copyright (c) Aicaca.com, All rights reserved.
Writer : Byung-ku, Cho (Aicaca)
E-mail : aicaca@hanmail.net
Personal Homepage URL : http://www.aicaca.com
Last Updated Date : Feb. 27th, 2002
Programming Language : C#
Editor & Compiler : VisualStudio.NET
*/
using System;
using System.IO;
using System.Threading;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
namespace TalkClient
{
public class WinDialog : System.Windows.Forms.Form
{
private WinCom WC = new WinCom();
private WinClient xWinClient;
private WinMsg xWinMsg;
private Socket DialogSocket = null;
private TextWriter SocketWriter = null;
private string localID;
private string clientID;
private string threadID;
private string remoteID;
private string msgBuffer;
private bool directMode;
private System.Timers.Timer barTimer = new System.Timers.Timer();
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Button fileButton;
private System.Windows.Forms.TextBox toTextBox;
private System.Windows.Forms.Label toLabel;
private System.Windows.Forms.Button msgButton;
private System.Windows.Forms.TextBox writeTextBox;
private System.Windows.Forms.TextBox showTextBox;
private System.Windows.Forms.GroupBox bottomGroupBox;
public WinDialog(WinClient tWinClient, string tLocalID, string tClientID)
{
xWinClient = tWinClient;
localID = tLocalID;
clientID = tClientID;
}
public WinDialog(WinClient tWinClient, Socket tDialogSocket, string tLocalID, string tClientID, string tMsgBuffer)
{
xWinClient = tWinClient;
this.SetSocket(tDialogSocket, false);
localID = tLocalID;
clientID = tClientID;
msgBuffer = tMsgBuffer;
}
public WinDialog(WinClient tWinClient, string tLocalID, string tClientID, string tMsgBuffer)
{
xWinClient = tWinClient;
localID = tLocalID;
clientID = tClientID;
msgBuffer = tMsgBuffer;
}
public void WinThread_Connect()
{
this.Initialize();
this.ShowDialog();
}
public void WinThread_Accept()
{
this.Initialize();
this.StartWinMsg_Accept();
this.OnILOVEAICACAMSG(msgBuffer);
this.ShowDialog();
}
public void WinThread_RoundMsg()
{
this.Initialize();
this.OnILOVEAICACAMSG(msgBuffer);
this.ShowDialog();
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.writeTextBox = new System.Windows.Forms.TextBox();
this.toTextBox = new System.Windows.Forms.TextBox();
this.toLabel = new System.Windows.Forms.Label();
this.showTextBox = new System.Windows.Forms.TextBox();
this.msgButton = new System.Windows.Forms.Button();
this.fileButton = new System.Windows.Forms.Button();
this.bottomGroupBox = new System.Windows.Forms.GroupBox();
this.bottomGroupBox.SuspendLayout();
this.SuspendLayout();
//
// writeTextBox
//
this.writeTextBox.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.writeTextBox.Location = new System.Drawing.Point(8, 48);
this.writeTextBox.MaxLength = 1000;
this.writeTextBox.Multiline = true;
this.writeTextBox.Name = "writeTextBox";
this.writeTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.writeTextBox.Size = new System.Drawing.Size(288, 56);
this.writeTextBox.TabIndex = 1;
this.writeTextBox.Text = "";
//
// toTextBox
//
this.toTextBox.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
this.toTextBox.Location = new System.Drawing.Point(72, 16);
this.toTextBox.Name = "toTextBox";
this.toTextBox.ReadOnly = true;
this.toTextBox.Size = new System.Drawing.Size(224, 21);
this.toTextBox.TabIndex = 0;
this.toTextBox.Text = "";
//
// toLabel
//
this.toLabel.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
this.toLabel.Location = new System.Drawing.Point(8, 24);
this.toLabel.Name = "toLabel";
this.toLabel.Size = new System.Drawing.Size(56, 16);
this.toLabel.TabIndex = 0;
this.toLabel.Text = "Client ID";
this.toLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// showTextBox
//
this.showTextBox.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.showTextBox.MaxLength = 10000000;
this.showTextBox.Multiline = true;
this.showTextBox.Name = "showTextBox";
this.showTextBox.ReadOnly = true;
this.showTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.showTextBox.Size = new System.Drawing.Size(376, 224);
this.showTextBox.TabIndex = 0;
this.showTextBox.Text = "";
//
// msgButton
//
this.msgButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
this.msgButton.Location = new System.Drawing.Point(304, 48);
this.msgButton.Name = "msgButton";
this.msgButton.Size = new System.Drawing.Size(64, 56);
this.msgButton.TabIndex = 2;
this.msgButton.Text = "Send";
this.msgButton.Click += new System.EventHandler(this.msgButton_Click);
//
// fileButton
//
this.fileButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
this.fileButton.Location = new System.Drawing.Point(304, 16);
this.fileButton.Name = "fileButton";
this.fileButton.Size = new System.Drawing.Size(64, 24);
this.fileButton.TabIndex = 3;
this.fileButton.Text = "File";
this.fileButton.Click += new System.EventHandler(this.fileButton_Click);
//
// bottomGroupBox
//
this.bottomGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.bottomGroupBox.Controls.AddRange(new System.Windows.Forms.Control[] {
this.writeTextBox,
this.fileButton,
this.msgButton,
this.toTextBox,
this.toLabel});
this.bottomGroupBox.Location = new System.Drawing.Point(0, 224);
this.bottomGroupBox.Name = "bottomGroupBox";
this.bottomGroupBox.Size = new System.Drawing.Size(376, 112);
this.bottomGroupBox.TabIndex = 0;
this.bottomGroupBox.TabStop = false;
//
// WinDialog
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(376, 341);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.showTextBox,
this.bottomGroupBox});
this.Name = "WinDialog";
this.Text = "Aicaca WinDialog";
this.GotFocus += new System.EventHandler(this.OnSizeChanged);
this.Closed += new System.EventHandler(this.OnClosed);
this.Activated += new System.EventHandler(this.OnActivated);
this.bottomGroupBox.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void OnActivated(object sender, System.EventArgs e)
{
this.writeTextBox.Focus();
}
private void OnClosed(object sender, System.EventArgs e)
{
if (xWinMsg != null) xWinMsg.CloseThis();
xWinClient.RemoveThread(threadID);
}
private void msgButton_Click (object sender, System.EventArgs e)
{
this.StartMsg();
this.writeTextBox.Text = "";
}
private void fileButton_Click (object sender, System.EventArgs e)
{
string fileThreadSort = "WinSend";
string fileThreadName = WC.GetXML(clientID, "cn");
string fileThreadIP = WC.GetXML(clientID, "ci");
string fileThreadPort = WC.GetXML(clientID, "cp");
string fileThreadID = WC.MakeThreadID(fileThreadSort, fileThreadName, fileThreadIP, fileThreadPort);
if (!xWinClient.CheckThread(fileThreadID))
{
this.StartWinSend();
}
}
private void OnTimer(object sender, System.Timers.ElapsedEventArgs e)
{
FlashWindow(this.Handle.ToInt32(), 1);
}
private void OnSizeChanged(object sender, System.EventArgs e)
{
if (this.barTimer.Enabled == true) this.barTimer.Enabled = false;
}
[DllImport("user32")]
private static extern void FlashWindow(int xHandle, int xInvert);
private void Initialize()
{
this.StartWinMode();
string threadSort = "WinDialog";
string threadName = WC.GetXML(clientID, "cn");
string threadIP = WC.GetXML(clientID, "ci");
string threadPort = WC.GetXML(clientID, "cp");
threadID = WC.MakeThreadID(threadSort, threadName, threadIP, threadPort);
string remoteSort = "WinDialog";
string remoteName = WC.GetXML(localID, "ln");
string remoteIP = WC.GetXML(localID, "li");
string remotePort = WC.GetXML(localID, "lp");
remoteID = WC.MakeRemoteID(remoteSort, remoteName, remoteIP, remotePort);
xWinClient.AddThread(threadID, this);
InitializeComponent();
this.toTextBox.Text = WC.GetXML(clientID, "cn") + ":" + WC.GetXML(clientID, "ci") + ":" + WC.GetXML(clientID, "cp");
}
private void AddComingText(string str)
{
str = WC.ReplaceStr(str, "&Line;", "\n");
if (this.showTextBox.Text.Length == 0)
{
this.showTextBox.Text = str + "\r\n";
}
else
{
this.showTextBox.AppendText(str + "\r\n");
}
this.writeTextBox.Focus();
}
private void StartMsg()
{
string sendStr = WC.MakeXML("ms", "ILOVEAICACAMSG") + threadID + remoteID + "<body>" + this.writeTextBox.Text;
if (DialogSocket != null && DialogSocket.Connected)
{
this.SendMsg(sendStr);
}
else if (directMode == true)
{
this.StartWinMsg_Connect(sendStr);
}
else
{
xWinClient.SendRootMsg(sendStr);
}
this.AddComingText(">> " + this.writeTextBox.Text + "\r\n");
}
private void StartWinMode()
{
WinMode xWinMode = new WinMode(this, clientID);
Thread ModeThread = new Thread(new ThreadStart(xWinMode.WinThread_Dialog));
ModeThread.Start();
}
private void StartWinMsg_Connect(string sendStr)
{
xWinMsg = new WinMsg(xWinClient, this, localID, clientID, sendStr);
Thread MsgThread = new Thread(new ThreadStart(xWinMsg.ClientProc));
MsgThread.Start();
}
private void StartWinMsg_Accept()
{
xWinMsg = new WinMsg(xWinClient, this, DialogSocket);
Thread MsgThread = new Thread(new ThreadStart(xWinMsg.ServerProc));
MsgThread.Start();
}
private void StartWinSend()
{
WinSend xWinSend = new WinSend(xWinClient, localID, clientID);
Thread FileThread = new Thread(new ThreadStart(xWinSend.WinThread_Connect));
FileThread.Start();
}
public void SetSocket(Socket sk, bool threadMode)
{
lock(this)
{
if (sk != null && sk.Connected)
{
DialogSocket = sk;
NetworkStream stream = new NetworkStream(DialogSocket);
SocketWriter = new StreamWriter(stream);
if (threadMode == true) this.StartWinMsg_Accept();
}
}
}
public void SendMsg(string str)
{
str = WC.ReplaceStr(str, "\n", "&Line;") + "\n";
SocketWriter.Write(str);
SocketWriter.Flush();
}
public void OnILOVEAICACAMSG(string str)
{
lock(this)
{
str = WC.GetNextXML(str, "body");
this.AddComingText("<< " + str + "\r\n");
if (this.WindowState == System.Windows.Forms.FormWindowState.Minimized)
{
if (this.barTimer.Enabled == false)
{
this.barTimer.Elapsed += new System.Timers.ElapsedEventHandler(this.OnTimer);
this.barTimer.Interval = 1000;
this.barTimer.Enabled = true;
}
}
else
{
this.TopMost = true;
this.TopMost = false;
}
}
}
public void OnILOVEAICACAERR(string str)
{
lock(this)
{
MessageBox.Show(this, WC.GetXML(str, "er"));
this.Close();
}
}
public Socket pDialogSocket
{
set
{
this.SetSocket(value, false);
}
}
public bool pDirectMode
{
set
{
this.directMode = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -