简体   繁体   English

制作系统任务栏应用程序的有效方法

[英]Effective way to make a system tray application

This is my first post on Stack Overflow and I'm just wondering on the options of making a system tray application. 这是我关于Stack Overflow的第一篇文章,我只是想知道制作系统任务栏应用程序的选项。 The application would run primary from the system tray while still operating, and could be brought up into a window when clicked on. 该应用程序将在仍运行的同时从系统托盘运行,并且在单击时可以调入窗口。 It is also needed to have some support for global keystroke tracking, to bring up a window. 还需要对全局按键跟踪有一些支持,以打开一个窗口。

I'm curious on what options I have available to me, as I'm sure that there are many ways to do this. 我很想知道我可以使用哪些选项,因为我敢肯定有很多方法可以做到这一点。 I'm most familiar with with Java though I have some experience with C++. 尽管我对C ++有所了解,但我对Java最熟悉。 I'm willing to explore other languages if they have some definite perks to them, though it would be nice to work with what I know in a way. 我愿意探索其他语言,如果他们有一定的特权,尽管以某种方式使用我所知道的东西会很好。

Thank you 谢谢

Java 6 has new functionality which allows for the creation of applications which use the system tray. Java 6具有新功能,可以创建使用系统托盘的应用程序。

The New System Tray Functionality in Java SE 6 article goes into the details, and provides some sample code as well. Java SE 6中的新系统托盘功能”一文进行了详细介绍,并提供了一些示例代码。

The newly added SystemTray and TrayIcon classes of the java.awt package can be used to add icons to the system tray. java.awt包中新添加的SystemTrayTrayIcon类可用于将图标添加到系统托盘。 The icons can respond to mouse clicks and use pop up menus as well. 这些图标可以响应鼠标单击并使用弹出菜单。 However, this new functionality is a part of AWT, so it doesn't do a very good job integrating with Swing components. 但是,此新功能是AWT的一部分,因此在与Swing组件集成方面做得不好。

Here's an example of a little clock that shows up in the system tray which was made using the SystemTray and TrayIcon classes in Java 6: 这是一个用Java 6中的SystemTrayTrayIcon类制作的小时钟显示在系统托盘中的示例:

Java中的系统托盘时钟应用程序
(source: coobird.net ) (来源: coobird.net

Plain old Winforms would get my vote. 普通的Winforms将获得我的投票。

If you are familiar with Java you should have little difficulty using one of the managed languages to create a simple tray app with .NET. 如果您熟悉Java,则使用一种托管语言通过.NET创建简单的任务栏应用程序应该不会有什么困难。

Here is some advice on the correct way to create a tray app. 以下是有关创建托盘应用程序的正确方法的一些建议。

Be carefully with manged applications and Java here. 请在此处小心使用托管的应用程序和Java。 Tray applications run all the time. 纸盒应用程序始终运行。 So, if they are poorly written then they can use enough system resources to interfere with other things. 因此,如果编写不当,则可以使用足够的系统资源来干扰其他事物。

There is nothing wrong with manged code or Java in general, but it can be more difficult to keep managed or java apps frugal with memory, I/O and CPU time. 一般而言,托管代码或Java没什么问题,但要使托管或Java应用程序在内存,I / O和CPU时间方面保持节俭,可能会更加困难。

I'm saying this as a dev manger on the Windows perf team - we've seen lots and lots of very piggy tray applications. 我是作为Windows性能团队的一名开发人员来这么说的-我们已经看到很多很多非常简单的托盘应用程序。 Yes, some are even windows or MSFT applications. 是的,有些甚至是Windows或MSFT应用程序。

It may be a better approach to write a very small light weight tray app that launches a richer process when the user needs it. 编写非常轻巧的托盘应用程序可能是一种更好的方法,该应用程序在用户需要时启动更丰富的过程。 You can write your try app in simple C++ right on top of the low level Win32 APIs. 您可以在底层Win32 API之上,用简单的C ++编写try应用。 If you don't want to use the Win32 APIs directly, you can use the Windows Template Library . 如果您不想直接使用Win32 API,则可以使用Windows模板库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM