Trying to show a notification using a Ruby ball

I'm trying to make a small class in ruby, allowing me to make an icon in the system tray and use notification balloons. But I'm having problems using structures with Win32API calls.

http://www.ruby-forum.com/topic/18102
Shell_NotifyIcon Function
NOTIFYICONDATA Struct

Here is the code that I have, all it does is add an icon to the system tray:

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 
+4
source share
1 answer

Give up visualuruby and its demo / sample files. They easily got me balloons.

0
source

Source: https://habr.com/ru/post/1299407/


All Articles