Posted: December 23 2002 at 13:53 | IP Logged
|
|
|
Steve,
Well after a bit of research, it's not quite that easy to call a macro from straight VB script. I had thought that you could declare external API functions and use the SendMessage routines but VBScript does not have that provision. So...what I did was create a simple VB application that takes 3 command line arguments and then execute this VB application from within a VBScript. The application then sends a Windows message to PowerHome and triggers whatever macro I would like. Im assuming that you are trying to execute VBScript outside of the PowerHome environment. If you are executing VBScript from within the PowerHome environment then you would just use the ph.macro function.
Anyways, here is a link to the VB PowerHome message program. It takes three command line parameters and uses the PowerHome WM_USER Windows Message interface. This interface in PowerHome allows you to declare a trigger on WM_USER messages (1024) through WM_USER + 4 messages (1028). Using the WM_USER messages, you can pass whatever lparam and wparam values you like and then use those values within the PowerHome trigger however you like. The first parameter is the WM_USER message number (1 through 5 equating to 1024 through 1028). The second parameter is the wparam and is a long value. The third parameter is the lparam value and is also a long value. Separate the parameters with a space. You can download the program here: /otherdown/winmsg.exe
If you are interested in the code, its posted below:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wparam As Long, ByVal lparam As Long) As Long
Private Sub Form_Load() Dim msg, wparam, lparam, pos1, pos2 pos1 = InStr(1, Command, " ") msg = Mid(Command, 1, pos1 - 1) pos2 = InStr(pos1 + 1, Command, " ") wparam = Mid(Command, pos1 + 1, pos2 - pos1 - 1) lparam = Mid(Command, pos2 + 1) SendMessage FindWindow(vbNullString, " PowerHome "), msg + 1023, wparam, lparam End End Sub
To execute this program from within VBScript, just make the calls below:
dim Wshshell
set WshShell = CreateObject("WScript.Shell")
WshShell.Run ("winmsg.exe 1 100 200")
In the above code, I want to trigger within PowerHome on "Trigger 1" of the WM_USER trigger. Im passing in 100 as the wparam and 200 as the lparam. These values will be available within the PowerHome trigger in system variables [TEMP3] and [TEMP4] respectively. I can use these values to determine what action I would like the trigger to take.
Let me know if this helps or not.
Dave.
|