Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Threading;
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- namespace Lab4
- {
- public partial class Lab_4 : Form
- {
- public static Lab_4 Instance { get; private set; }
- [DllImport("user32.dll", CharSet = CharSet.Auto)]
- private static extern IntPtr FindWindow(string className, string windowName);
- [DllImport("user32.dll", CharSet = CharSet.Auto)]
- private static extern int SendMessage(IntPtr hwnd, int wMessage, int wParam, int lParam);
- [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
- private static extern uint RegisterWindowMessage(string lpString);
- private uint messageId = RegisterWindowMessage("777");
- public Lab_4(){
- if (Instance == null)
- Instance = this;
- InitializeComponent();
- }
- protected override void WndProc(ref Message m) {
- if (m.Msg == messageId)
- chatHistory.AppendText(((char)m.WParam).ToString());
- base.WndProc(ref m);
- }
- private void SendButton_Click(object sender, EventArgs e)
- {
- if (!(string.IsNullOrEmpty(message.Text) ||
- string.IsNullOrEmpty(to.Text) ||
- string.IsNullOrEmpty(username.Text)))
- {
- string result = "Message from " + username.Text + " in " + DateTime.Now.ToShortTimeString() + ": " + message.Text + "\r\n";
- IntPtr windowToFind = FindWindow(null, to.Text);
- for (int i = 0; i < result.Length; i++)
- SendMessage(windowToFind, (int)messageId, result[i], 0);
- chatHistory.AppendText(result);
- message.Text = "";
- }
- }
- private void nameText_TextChanged(object sender, EventArgs e) {
- Text = Name = username.Text;
- }
- private void messageText_KeyPress(object sender, KeyPressEventArgs e){
- if (e.KeyChar == (char)Keys.Enter){
- send.PerformClick();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment