public void CreateMessage(string subject, string attachmentPath)
 {
     try
     {
         var handle      = IntPtr.Zero;
         var processList = Process.GetProcesses();
         foreach (var process in processList.Where(x => x.ProcessName.ToLower().Contains("outlook")).Where(process => process.MainWindowHandle.ToInt32() != 0))
         {
             handle = process.MainWindowHandle;
             break;
         }
         Utilities.ActivateForm(handle, true, false);
         var mi = (MailItem)_outlookObject.CreateItem(OlItemType.olMailItem);
         mi.Attachments.Add(attachmentPath, OlAttachmentType.olByValue, 1, Path.GetFileNameWithoutExtension(attachmentPath));
         mi.Subject = subject;
         mi.Display(false);
         var count = 100000;
         handle = IntPtr.Zero;
         while (handle == IntPtr.Zero && count > 0)
         {
             handle = WinAPIHelper.FindWindow(string.Empty, subject + "- Message (HTML)");
             count--;
             System.Windows.Forms.Application.DoEvents();
         }
         if (handle != IntPtr.Zero)
         {
             Utilities.ActivateForm(handle, true, false);
         }
     }
     catch (Exception e)
     {
         PopupMessageHelper.Instance.ShowWarning(e.Message);
     }
 }
Example #2
0
        public void WriteTextBox()
        {
            string txt = "Hello Hook!";
            //获得窗体句柄
            IntPtr winHwnd = WinAPIHelper.FindWindow("WindowsForms10.Window.8.app.0.378734a", "MyWindow");
            //获得窗体上TextBox句柄
            IntPtr txtHwnd = WinAPIHelper.FindWindowEx(winHwnd, IntPtr.Zero, "WindowsForms10.EDIT.app.0.378734a", "");

            //向TextBox中写入内容
            WinAPIHelper.BringWindowToTop(winHwnd);
            IntPtr result  = WinAPIHelper.SendMessage(txtHwnd, 0x000C, (IntPtr)txt.Length, txt);
            IntPtr result1 = WinAPIHelper.SendMessage(txtHwnd, 0x000C, (IntPtr)0, txt);
        }