4
我想在ruby中做一個小班,允許我製作一個系統托盤圖標並使用通知氣球。但我在使用Win32API調用結構時遇到問題。試圖用紅寶石顯示一個氣球通知
http://www.ruby-forum.com/topic/18102
Shell_NotifyIcon Function
NOTIFYICONDATA Struct
繼承人現在我的代碼,它是所有的圖標添加到系統托盤:
require 'Win32API'
NIF_MESSAGE = 1
NIF_ICON = 2
NIF_TIP = 4
NIF_STATE = 8
NIF_INFO = 10
NIM_ADD = 0
NIM_MODIFY = 1
NIM_DELETE = 2
NIS_HIDDEN = 1
NIS_SHAREDICON = 2
class NotifyIconData < Struct.new(:cbsize, :hwnd, :uid, :uflags, :ucallbackmessage, :hicon)#, :sztip, :dwstate, :dwstatemask, :szinfo, :utimeout, :uversion, :szinfotitle, :dwinfoflags, :guiditem, :hballoonicon)
def pack
values.pack('LLIIIL')
end
# def self.unpack(s)
# new(*s.unpack('LLIIIL'))
# end
end
#===---
ExtractIcon = Win32API.new('shell32', 'ExtractIcon', 'LPI', 'L')
Shell_NotifyIcon = Win32API.new('shell32', 'Shell_NotifyIconA', 'LP', 'I')
hicoY = ExtractIcon.call(0, 'C:\WINDOWS\SYSTEM32\INETCPL.CPL', 21) # Green tick
hicoN = ExtractIcon.call(0, 'C:\WINDOWS\SYSTEM32\INETCPL.CPL', 22) # Red minus
#===---
tiptxt = "hai"
nid = NotifyIconData.new
nid.cbsize = Marshal.dump(NotifyIconData).size#6*4+64
nid.hwnd = 0
nid.uid = 'ruby'.hash
nid.uflags = NIF_INFO
nid.ucallbackmessage = 0
nid.hicon = hicoY
ret = Shell_NotifyIcon.call(NIM_ADD, nid.pack << tiptxt << "\0"*(64 - tiptxt.size))
p 'Err: NIM_ADD' if ret == 0
sleep(3) # <----<<
# pnid = [6*4+64, 0, 'ruby'.hash, NIF_ICON | NIF_TIP, 0, hicoN].pack('LLIIIL') << tiptxt << "\0"*(64 - tiptxt.size)
# ret = Shell_NotifyIcon.call(NIM_MODIFY, pnid)
# p 'Err: NIM_MODIFY' if ret == 0
# sleep(6) # <----<<
nid.uflags = 0
ret = Shell_NotifyIcon.call(NIM_DELETE, nid.pack << "\0")
p 'Err: NIM_DELETE' if ret == 0
當你去安裝需要swin的vruby時,你會看到'找到swin(2004.03.14),但是用於平臺i386-mswin32',所以我猜測沒有64位? – 2014-06-10 18:51:10
自64位窗口紅寶石相對較新... – rogerdpack 2014-06-11 05:13:08