从C#托盘应用程序中显示消息框 [英] Show message box from C# tray application on top of all

查看:57
本文介绍了从C#托盘应用程序中显示消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我用C#开发了一个RESTful Windows托盘应用程序。我从javascript通过ajax调用http:// localhost:8888 / ....访问此应用程序的公共函数。



在托盘应用程序中,我引用了一个vb6 dll。



现在我的查询...

在应用程序的执行过程中,vb dll会显示一个消息框。由于我从Web浏览器调用该进程,因此浏览器后面会显示消息框。因此,用户必须按alt + tab才能看到消息,这需要花费大量时间。



我希望此消息框显示在所有消息之上应用程序始终。



托盘应用程序和vb6 dll中没有表单元素。



请帮我解决这个问题。



问候



我的尝试:



我尝试使用以下代码但没有用



private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);

private const UInt32 SWP_NOSIZE = 0x0001;

private const UInt32 SWP_NOMOVE = 0x0002;

private const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;



[DllImport(user32.dll)]

[返回:MarshalAs(UnmanagedType.Bool)]

public static extern bool SetWindowPos(IntPtr hWnd,IntPtr hWndInsertAfter,int X,int Y,int cx,int cy,uint uFlags);

Hi,

I have developed a RESTful windows tray application in C#. I access the public functions of this application from javascript via ajax call to http://localhost:8888/....

In the tray application i have referenced to a vb6 dll.

Now my query...
During the application's execution process, the vb dll shows a message box. Since I am calling the process from web browser, the message box appears behind the browser. Hence, The user has to press alt+tab to see the message, which is costing lot of time.

I want this message box to show up on top of all application all the time.

There is no form element in the tray application and vb6 dll.

Please help me to solve this issue.

Regards

What I have tried:

I have tried using the following code but no use

private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
private const UInt32 SWP_NOSIZE = 0x0001;
private const UInt32 SWP_NOMOVE = 0x0002;
private const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

推荐答案

嗯。如果这是一个真正的MessageBox - 你的VB代码暗示它是 - 那么问题比你想象的更糟糕:用户根本不会看到这个框。

VB代码在服务器,而不是客户端,因此MessageBox将显示在服务器上,即使他移动浏览器,客户端也不会看到它。唯一可能成为您的Web主机管理员的人!

它显示您描述的行为的原因是因为在开发过程中,您的服务器和客户端是相同的硬件,即同一台PC。因为它们是同一台PC上的独立应用程序(IIS和浏览器是完全独立的),所以MessageBox出现在IIS而不是浏览器上。

如果您希望用户看到消息,则需要使用javascript警报或类似信息,而不是消息框。
Um. If this is a real MessageBox - and your VB code would imply it is - then the problem is worse than you thought: The user won't see the box at all.
VB code is executed on the Server, not the Client, so the MessageBox will display on the Server, and the Client won't see it, even if he moves his browser. The only person who might will be your web host administrator!
The reason it shows the behaviour you describe is because in development, your Server and Client are the same hardware, the same PC. And because they are separate apps on the same PC (IIS and the browser are totally separate) the MessageBox appears "over" IIS not the browser.
If you want the user to see a message, you need to use a javascript Alert or similar, not a message box at all.


您不必使用MessageBox调用进行任何控制。您必须创建自己的表单来显示消息。这样,您就可以更好地控制窗口的显示方式。
You don't have to kind of control you want using a MessageBox call. You have to create you're own form for displaying messages. That way, you've got far more control over how the window is displayed.


这篇关于从C#托盘应用程序中显示消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆