알림 아이콘에 텍스트를 렌더링 (업데이트)하는 스크립트입니다.
"Get-NotifyIconText"기능을 원하는대로 사용자 정의하십시오. 당신이 [`NotifyIcon`]의 인스턴스의 사용 (http://msdn.microsoft.com/en-us/library/system.windows.forms을 할 수 있도록
#Requires -Version 3.0
function Get-NotifyIconText {
[DateTime]::Now.Second.ToString()
# ((Get-Counter '\\mypc\network interface(Intel[R] 82579V Gigabit Network Connection)\bytes total/sec').countersamples).cookedvalue*8/102400000*100
}
Add-Type -ReferencedAssemblies @("System.Windows.Forms"; "System.Drawing") -TypeDefinition @"
using System;
using System.Drawing;
using System.Windows.Forms;
public static class TextNotifyIcon
{
// it's difficult to call DestroyIcon() with powershell only...
[System.Runtime.InteropServices.DllImport("user32")]
private static extern bool DestroyIcon(IntPtr hIcon);
public static NotifyIcon CreateTrayIcon()
{
var notifyIcon = new NotifyIcon();
notifyIcon.Visible = true;
return notifyIcon;
}
public static void UpdateIcon(NotifyIcon notifyIcon, string text)
{
using (var b = new Bitmap(16, 16))
using (var g = Graphics.FromImage(b))
using (var font = new Font(FontFamily.GenericMonospace, 8))
{
g.DrawString(text, font, Brushes.Black, 0, 0);
var icon = b.GetHicon();
try
{
notifyIcon.Icon = Icon.FromHandle(icon);
} finally
{
DestroyIcon(icon);
}
}
}
}
"@
$icon = [TextNotifyIcon]::CreateTrayIcon()
while ($true) {
$text = Get-NotifyIconText
[TextNotifyIcon]::UpdateIcon($icon, $text)
[Threading.Thread]::Sleep(1000)
}
당신은 WinFroms GUI를 만들어야합니다 .notifyicon.aspx). 그런 다음 타이머를 사용하여 카운터의 새 값을 가져 와서 아이콘을 업데이트하십시오. – Richard
@ 리차드 .Net 프로그래밍에 정통하지 않습니다. 나는 [this] (http://www.codeproject.com/Articles/74/Adding-Icons-to-the-System-Tray)와 같은 것을 코드화하고 컴파일해야합니까? –
[이 블로그 게시물] (http://www.sapien.com/blog/2012/05/08/spotlight-on-the-notifyicon-control/)을보십시오. –