Windows API Control Implemented in mIRC.
/*
This snippet was designed to show the true power and application of $vba().
A registered copy of Microsoft Excel 2007 or 2010 is required for this example.
The identifier is provided as a local alias to ensure that it cannot
possibly affect anything else as a courtesy to the end user. In order to
properly make use of this code, one must have permissive settings with
regards to the VBA Project Model as well as having macros enabled. Microsoft
Office, to include other MSO applications besides Excel, offer this same
functionality.
The example shown here is /mouse:example. It is managed by a queue using
the system.collections.queue namespace to store user input and then builds a
function around that input. Now, as far as the surrounding code, it is
merely the declarative statements for the Windows API functions and the
encapsulating "function" and "end function" statements. No more, no less.
The example itself is a rather well defined one; being that it does not lack
in what one might call basic functions. The two commands, /build:queue and
/remove:queue are self-explanatory. $mouse:queue() is a handle on the COM
object used to input and retrieve events. Said identifier returns "true" or
"false" (1/0) if an item was successfully enqueued. It returns the first
item in the collection when the .dequeue property is supplied, and likewise
the amount of items when the .count property is given. $mouse:move() moves
the cursor to the defined x and y coordinates respectively.
I understand that there is the possibility for the end user to be "naive" as
far as the Windows API goes. (Not in a bad way ...) Therefore, I have taken
the liberty of including links to the two API functions utilized in this
snippet.
SetCursorPos: http://msdn.microsoft.com/en-us/library/ms648394%28VS.85%29.aspx
mouse_event : http://msdn.microsoft.com/en-us/library/ms646260%28VS.85%29.aspx
Any questions may be directed to me (Champagne on SwiftIRC) in the following
channels, by private message, or by email.
#mSL, #COM
msl_spm@live.com
Again, this is merely an example. The content of the function passed to $vba()
can be edited to suit the end user's need. Accessing the Windows API in mIRC
gives the application the power to perform many more tasks than would normally
be thought possible. Granted it relies on excel, but the extended power more
than makes up for this dependency.
*/
alias mouse:example {
build:queue
noop $mouse:queue($mouse:move(100,100)).enqueue
noop $mouse:queue($mouse:rightbutton:click).enqueue
var %function = $declaration(mouse_event) $declaration(SetCursorPos) function example() $crlf
while ($mouse:queue().count) {
%function = %function $mouse:queue().dequeue
}
%function = %function end function
noop $vba(%function,example)
remove:queue
}
alias -l mouse:move return SetCursorPos $1, $2 $crlf
alias -l mouse:leftbutton:click return mouse_event &H2& Or &H4&, 0, 0, 0, 0 $crlf
alias -l mouse:rightbutton:click return mouse_event &H8& Or &H10&, 0, 0, 0, 0 $crlf
alias -l build:queue if (!$com(mouse:queue)) .comopen mouse:queue system.collections.queue
alias -l mouse:queue {
if ($prop = enqueue) && ($com(mouse:queue)) return $null($com(mouse:queue,$prop,1,bstr,$1)) $iif(!$comerr,1,0)
if ($prop = dequeue || $prop = count) && ($com(mouse:queue)) return $null($com(mouse:queue,$prop,3)) $com(mouse:queue).result
}
alias -l remove:queue if ($com(mouse:queue)) .comclose mouse:queue
alias -l declaration {
if ($1 = mouse_event) {
return $&
Private Declare Sub mouse_event Lib "user32" ( $&
ByVal dwFlags As Long, $&
ByVal dx As Long, $&
ByVal dy As Long, $&
ByVal cButtons As Long, $&
ByVal dwExtraInfo As Long $&
) $crlf
}
elseif ($1 = SetCursorPos) {
return $&
Private Declare Function SetCursorPos Lib "user32" Alias "SetCursorPos" ( $&
ByVal x As Long, $&
ByVal y As Long $&
) As Long $crlf
}
else return $null
}
alias -l vba {
.comopen $obj(excel) excel.application
noop $handle($obj(excel),$1,$2)
var %evaluation = $com($obj(excel)).result
noop $com($obj(excel),activeworkbook,3,dispatch* $obj(sheets))
noop $com($obj(sheets),saved,5,boolean,true)
.timer 1 0 threads
return %evaluation
}
alias -l handle {
noop $com($1 ,$member(1),3,dispatch* $object(1)) $com($v1,$member(2),3,dispatch* $object(2))
noop $com($v1,$member(3),3,dispatch* $object(3)) $com($v1,$member(4),3,dispatch* $object(4))
noop $com($v1,$member(5),3,int,1,dispatch* $object(5)) $com($v1,$member(6),3,dispatch* $object(6))
noop $com($v1,$member(7),3,string,$2) $com($1 ,$member(8),3,string,$3 )
}
alias -l member {
var %collection = workbooks add vbproject vbcomponents add codemodule addfromstring run
return $gettok(%collection,$1,32)
}
alias -l obj return $+(vba:,$1)
alias -l object {
var %collection = $obj(add_workbook) $obj(vbproject) $obj(vbcomponents) $obj(add_module) $obj(codemodule) $obj(write_module)
if ($gettok(%collection,$1,32)) return $v1
}
alias -l threads {
var %i = $com(0)
while (0 < %i) { if ($left($com(%i),3) == vba) .comclose $com(%i) $com($com(%i),quit,1) | dec %i }
}