Module: Snarl::SnarlAPI
Overview
This is the lowlevel API implemenation using DL and a few handy constants from the snarl api and the Win32 API Note that I have jump through some hoops to get the array of characters to work corretly – if you know a better way please send me ([email protected]) a note.
Defined Under Namespace
Classes: CopyDataStruct, SnarlStruct, SnarlStructEx
Constant Summary collapse
- CreateWindow =
extern “HWND CreateWindowEx(DWORD, LPCSTR, LPCSTR, DWORD, int, int, HWND, HMENU, HINSTANCE, LPVOID)”
Win32API.new("user32", "CreateWindowExA", ['L', 'p', 'p', 'l', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'p'], 'L')
- DestroyWindow =
Win32API.new("user32", "DestroyWindow", ['L'], 'L')
- HWND_MESSAGE =
WIN32API
0x84
- WM_USER =
0x400
- SNARL_GLOBAL_MSG =
Global Event Ids
"SnarlGlobalEvent"
- SNARL_LAUNCHED =
1
- SNARL_QUIT =
2
- SNARL_ASK_APPLET_VER =
introduced in V36
3
- SNARL_SHOW_APP_UP =
introduced in V37
4
- SNARL_NOTIFICATION_CLICKED =
Message Event Ids
32
- SNARL_NOTIFICATION_TIMED_OUT =
33
- SNARL_NOTIFICATION_ACK =
34
- SNARL_NOTIFICATION_CANCLED =
yes that’s right.
SNARL_NOTIFICATION_CLICKED
- SNARL_SHOW =
Snarl Commands
1
- SNARL_HIDE =
2
- SNARL_UPDATE =
3
- SNARL_IS_VISIBLE =
4
- SNARL_GET_VERSION =
5
- SNARL_REGISTER_CONFIG_WINDOW =
6
- SNARL_REVOKE_CONFIG_WINDOW =
7
- SNARL_REGISTER_ALERT =
8
- SNARL_REVOKE_ALERT =
9
- SNARL_REGISTER_CONFIG_WINDOW_2 =
10
- SNARL_GET_VERSION_EX =
11
- SNARL_SET_TIMEOUT =
12
- SNARL_EX_SHOW =
32
- SNARL_TEXT_LENGTH =
1024
- WM_COPYDATA =
0x4a
- BASE =
[:cmd, :int, :id, :long, :timeout, :long, :data2, :long, :title, [:char, SNARL_TEXT_LENGTH], :text, [:char, SNARL_TEXT_LENGTH], :icon, [:char, SNARL_TEXT_LENGTH] ]
Class Method Summary collapse
-
.send(ss) ⇒ Object
Send the structure off to snarl, the routine will return (if everything goes well) the result of SendMessage which has an overloaded meaning based upon the cmd being sent.
-
.to_cha(str) ⇒ Object
character array hoop jumping, we take the passed string and convert it into an array of integers, padded out to the correct length to_cha –> to character array I do this as it seems necessary to fit the DL API, if there is a better way please let me know.
Class Method Details
.send(ss) ⇒ Object
Send the structure off to snarl, the routine will return (if everything goes well) the result of SendMessage which has an overloaded meaning based upon the cmd being sent
149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/snarl.rb', line 149 def self.send(ss) if isWindow(hwnd = findWindow(nil, 'Snarl')) cd = CopyDataStruct.new cd.dwData = 2 cd.cbData = ss.size cd.lpData = ss.to_ptr [:pointer, :uint, :long, :long] got = sendMessage(hwnd, WM_COPYDATA, 0, cd.to_ptr) _dbg unless got got end end |
.to_cha(str) ⇒ Object
character array hoop jumping, we take the passed string and convert it into an array of integers, padded out to the correct length to_cha –> to character array I do this as it seems necessary to fit the DL API, if there is a better way please let me know
140 141 142 143 144 |
# File 'lib/snarl.rb', line 140 def self.to_cha(str) raise 'bad' result = str.split(/(.)/).map { |ch| ch[0] }.compact result + Array.new(SNARL_TEXT_LENGTH - result.size, 0) end |