VSTO Outlook:弹出窗口上的自定义通知

发布于 2025-02-10 06:38:31 字数 1577 浏览 3 评论 0 原文

我有一个VSTO Outlook加载项,我想在特定时间(例如5秒钟)弹出一个带有自定义文本消息的通知(浮动窗口),然后自动消失。我想从撰写窗口中显示此通知。我该如何实现?一些例子将高度赞赏。

更新:我希望通知窗口成为撰写窗口的孩子。

更新29.06.2022: 我已经完成了以下操作:

   Outlook.Inspector currentInspector = this.Window as Outlook.Inspector;
    IOleWindow ioleWnd = (IOleWindow)currentInspector;
    ioleWnd.GetWindow(out IntPtr phwnd);

    NativeWindow nativeWnd = new System.Windows.Forms.NativeWindow();
    nativeWnd.AssignHandle(phwnd);
    
    // frm is my notification window, borderless and without maximize, minimize and close buttons and without title bar.
    Form frm = new Form();
    frm.ControlBox = false;
    frm.FormBorderStyle = FormBorderStyle.None;


    NativeMethods.Rect rect = new NativeMethods.Rect();
    NativeMethods.GetWindowRect(phwnd, ref rect);


    frm.Left = rect.Right - 85;
    frm.Top = rect.Bottom - 55;
    frm.Width = 80;
    frm.Height = 50;
    frm.Location = new System.Drawing.Point(rect.Right - 85, rect.Bottom - 55);
    frm.BackColor = System.Drawing.Color.Red;

    TextBox txtBox = new TextBox();
    txtBox.BackColor = System.Drawing.Color.Red;
    txtBox.ForeColor = System.Drawing.Color.White;
    txtBox.Location = new System.Drawing.Point(5, 5);
    txtBox.Visible = true;
    txtBox.Text = "This is a notification message";

    frm.Controls.Add(txtBox);
    frm.Show(nativeWnd);

上面代码发生了什么:

  1. 通知窗口未位于右下方 撰写窗口的角。
  2. 如果我移动组合窗口,则通知窗口保持相同的位置,并且在我移动组合窗口时不会移动。
  3. 在Windows任务栏中,它显示为“通知窗口”是一个不同的过程/程序,而不是同一组合窗口的一部分,也许我需要做类似frm.Onterer =本机=本机的事情,但它不起作用。

有什么想法吗?

I have an VSTO Outlook Add-in and I would like to popup a notification (floating window) with a custom text message for a specific time (5 seconds for example) and then disappear automatically. I want to show this notification from within the compose window. How can I achieve this? some example will highly appreciated.

UPDATED: I would like the notification window to be a child of the compose window.

UPDATE 29.06.2022:
I have done the following:

   Outlook.Inspector currentInspector = this.Window as Outlook.Inspector;
    IOleWindow ioleWnd = (IOleWindow)currentInspector;
    ioleWnd.GetWindow(out IntPtr phwnd);

    NativeWindow nativeWnd = new System.Windows.Forms.NativeWindow();
    nativeWnd.AssignHandle(phwnd);
    
    // frm is my notification window, borderless and without maximize, minimize and close buttons and without title bar.
    Form frm = new Form();
    frm.ControlBox = false;
    frm.FormBorderStyle = FormBorderStyle.None;


    NativeMethods.Rect rect = new NativeMethods.Rect();
    NativeMethods.GetWindowRect(phwnd, ref rect);


    frm.Left = rect.Right - 85;
    frm.Top = rect.Bottom - 55;
    frm.Width = 80;
    frm.Height = 50;
    frm.Location = new System.Drawing.Point(rect.Right - 85, rect.Bottom - 55);
    frm.BackColor = System.Drawing.Color.Red;

    TextBox txtBox = new TextBox();
    txtBox.BackColor = System.Drawing.Color.Red;
    txtBox.ForeColor = System.Drawing.Color.White;
    txtBox.Location = new System.Drawing.Point(5, 5);
    txtBox.Visible = true;
    txtBox.Text = "This is a notification message";

    frm.Controls.Add(txtBox);
    frm.Show(nativeWnd);

What happens with above code is below:

  1. Notification window is not positioned on the bottom right hand
    corner of the compose window.
  2. If I move compose window, notification window keeps in the same position and it is not moving while I move the compose window.
  3. In windows task bar it appears as the notification window is a different process/program, not being part of the same compose window, maybe I need to do something like frm.Owner = nativeWnd but it is not working.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

唯憾梦倾城 2025-02-17 06:38:31

使用一个计时器,该计时器在主线程(UI)上启动 tick 事件,您可以在其中调用表单的 CLOSE 方法。 system.windows.forms.timer 的事件是通过消息循环从UI线程中提出的,当它收到 wm_timer 消息时。因此,您很高兴呼叫关闭方法。

请注意,可以运行计时器,并在表单外部或表单内部(内置的表单内)从您的代码上封闭表单。

Use a timer which fires the Tick event on the main thread (UI) where you can call the Close method of your form. The System.Windows.Forms.Timer's event is raised from the UI thread by the message loop when it receives a WM_TIMER message. So, you are good to calling the Close method.

Note, the timer can be run and the form is closed from your code outside of the form or inside the form (built-in to the form).

森末i 2025-02-17 06:38:31

您可以创建一个自定义的窗口表单,该表单在超时后自动关闭。

要使您的表格成为Outlook Inspector的孩子,请Q/code> Inspector 对象(例如 application.activeInspector )到 iolewindow 接口,调用 iolewindow.getWindow 获取 hwnd 。创建一个 System.windows.forms.nativewindow 类的实例,并调用 nativalwindow.assignhandle 。然后,您可以将本地窗口对象传递到 form.show form.showmodal antibalwindow object objock obsite iwin32window 接口)。

You can create a custom Windows form that closes itself automatically after a timeout.

To make your form a child of an Outlook inspector, Q/cast the Inspector object (e.g. from Application.ActiveInspector) to the IOleWindow interface, call IOleWindow.GetWindow to get the HWND. Create an instance of the System.Windows.Forms.NativeWindow class and call NativeWindow.AssignHandle. You can then pass the NativeWindow object to Form.Show or Form.ShowModal (NativeWindow object implements the IWin32Window interface).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文