Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sancarn/159938bfccc686c6fa26a92917b247de to your computer and use it in GitHub Desktop.
Save sancarn/159938bfccc686c6fa26a92917b247de to your computer and use it in GitHub Desktop.
Toolbar customisation in ICM
# InfoWorks ICM - How to customise your toolbars
# InfoWorks ICM - How to customise your toolbars programatically
By now you should know that if I'm talking about it, it'd be because I've found a way to autoamte it!
module Toolbar
class Toolbar
BASE_ID = 59646 #first toolbar id created
def initialize(id)
@parts = []
end
def << (button)
if !isButton(button)
throw "Object provided is not a button."
end
@parts<<button
end
def push(button)
if !isButton(button)
throw "Object provided is not a button."
end
@parts<<button
end
#ToolBars State_109 data
def messages #Toolbar_ID_#{self.id} REG_BINARY
s = ""
@parts.each do |button|
s+=button.iMessage.to_icm_reg
end
s
end
def settings #Toolbar_ID_#{self.id}_ButtonsSettings REG_BINARY
s = 8.to_icm_reg
@parts.each do |button|
s+=button.data
end
s
end
def settings_size #Toolbar_ID_#{self.id}_ButtonsSettings_Size REG_DWORD
4
end
def positions #Toolbar_ID_#{self.id}_CustomButtonsPositions REG_BINARY
"00000000" #00 00 00 00
end
def positions_size #Toolbar_ID_#{self.id}_ButtonsSettings_Size REG_DWORD
4
end
private
def isButton(button)
button.class <= Button
end
end
class Button
attr_accessor :iMessage, :iIcon, :bShowText
attr_reader :sText
def sText=(s)
if s.length > 255
throw "Text cannot be greater than 255 chars long."
else
@sText = s
end
end
def sText_data
if sText!=""
sText.encode("utf-16")[1..-1].unpack("H*")[0]
else
""
end
end
def initialize(message=0,icon=0,text="", showtext=false)
puts message
@iMessage = message
@iIcon = icon
self.sText = text
@bShowText = showtext
end
def data()
#message + icon + "10" + show_text + "000000fffeff" + length of text + text in unicode
@iMessage.to_icm_reg + @iIcon.to_icm_reg + "10" + (@bShowText ? "01" : "00") + "000000fffeff" + @sText.length.to_s(16) + self.sText_data
end
end
end
class Numeric
def to_icm_reg
#convert ot padded hex:
hex = self.to_s(16).rjust(8,"0")
#reverse padded hex:
hex.scan(/../).reverse.join
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment