i wirte a text chat program. in PM mode i have problem .
for first time when one of the client try to send pm to other one everything is fine and it work well. but next time if the same client try to send second line in second client machin the PM form open agine (as long as the first client send pm second one get more open page of PM )
i will put code here plz if anyone can help .
Expand|Select|Wrap|Line Numbers
- #region PM
- [DllImport("user32.dll", SetLastError = true)]
- internal static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- [DllImport("user32.dll", SetLastError = true)]
- internal static extern long GetClassName(IntPtr hwnd, [Out] StringBuilder lpString, int nMaxCount);
- public static IntPtr isExist(string title)
- {
- IntPtr hwnd = FindWindow(FormClassName.ToString(), title);
- return hwnd;
- }
- private static PM getPM(IntPtr hwnd)
- {
- PM x = (PM)FromChildHandle(hwnd);
- return x;
- }
- public void OpenPmDel(string all)
- {
- Invoke(new Classes.DLLClient.RecievePm(OpenPm), all);
- }
- public void OpenPm(string All)
- {
- string[] info = All.Split('#');
- string Sender = info[0];
- string Reciever = info[1];
- string Size = info[2];
- string Bold = info[3];
- string Italic = info[4];
- string color = info[5];
- string Text = info;
- Color clrPm = Color.FromName(color);
- GetHtml a = new GetHtml();
- string pm = a.PM(Sender, Text, Size, clrPm, bool.Parse(Italic), bool.Parse(Bold));
- pm = a.GetSmily(pm);
- string path = Application.StartupPath + "\\Data\\" + Sender + ".html";
- if (File.Exists(path) == false)
- {
- FileStream WritePm = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
- StreamWriter WP = new StreamWriter(WritePm);
- WP.WriteLine("<body onLoad=\"window.scroll(0,100000)\">");
- WP.Close();
- }
- File.AppendAllText(path, pm);
- IntPtr myPM = isExist(Sender);
- if (myPM.ToInt64() > 0)
- {
- PM Opened = getPM(myPM);
- Opened.Ready();
- }
- else
- {
- PM p = new PM();
- p.Reciver = Sender;
- p.Text = Sender;
- GFX.NotifyWindow.NotifyWindow n;
- n = new GFX.NotifyWindow.NotifyWindow("Private message", "Private message az " + Sender);
- n.SetDimensions(200, 100);
- n.Notify();
- p.Show();
- }
- }
- #endregion