Event Handlers are great... but I am running into what looks like a bug or two when they fire while VBScript is executing.
Please try the following script... error shows up when run compiled or not.
Code: Select all
// COMPILE_OPTS|C:\event_handler_firing_during_VBScript_causes_error.exe||CONSOLE=0|INCLUDES=0| /NOSYSTRAY /HIDE
VBSTART
Dim IE
Sub CreateIE(IE_win_position_X,IE_win_position_Y)
Set IE = CreateObject("InternetExplorer.Application")
IE.visible = 0
'Window size and position
'IE.Left = 217
IE.Left = IE_win_position_X
'IE.Top = 0
IE.Top = IE_win_position_Y
IE.Height = 652
IE.Width = 722
'Comment out the line to leave enabled or set to 0 to Disable
'IE.MenuBar = 0
'IE.ToolBar = 0
IE.AddressBar = 0
'IE.StatusBar = 0
'IE.Resizable = 0
End Sub
Sub Navigate(URL)
IE.navigate URL
End Sub
Sub WaitBusy
do while IE.Busy
loop
End Sub
Sub DestroyIE
IE.Quit
Set IE = Nothing
End Sub
Sub MakeVisible
IE.visible = 1
End Sub
VBEND
Dialog>Dialog1
object Dialog1: TForm
Left = 251
Top = 97
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'Main Window'
ClientHeight = 223
ClientWidth = 439
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
Position = poScreenCenter
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
end
EndDialog>Dialog1
Let>APP_TITLE=MyApp
//initialize X and Y base co-ords of IE windows... this is where window 1 will open
//Let>IE_win_position_base_X=217
Let>IE_win_position_base_X=0
Let>IE_win_position_base_Y=0
//each subsequent IE CLR window will be offset by this ammount
Let>IE_win_position_offset=22
//This is the current positional "slot" that the IE CLR will position at.
//Valid values start at 1 and goes up to IE_win_position_max.
//We initialize at -1 because we'll increment before opening the window
//and we're multiplying the number by the offset value... window
Let>IE_win_position_number=-1
//this is the highest number of positions we'll position at
Let>IE_win_max_window_positions=10
AddTrayIcon>C:\MyIcon.ico,MyTrayIcon,MyApp
//Add System Tray icon Handlers
AddTrayHandler>MyTrayIcon,OnClick,Do_Show_Hide_Main_Window
AddTrayHandler>MyTrayIcon,OnDblClick,Do_Show_Hide_Main_Window
//Pressing ALT+F11 will run the "ACTION" Subroutine
OnEvent>KEY_DOWN,VK122,3,ACTION
SRT>ACTION
//calculate X and Y values for current IE CLR window positional slot
Let>IE_win_position_number=IE_win_position_number+1
If>IE_win_position_number=IE_win_max_window_positions
//reset if we're at the max, 0 is first slot
Let>IE_win_position_number=0
EndIf
Let>IE_win_position_X={%IE_win_position_base_X%+(%IE_win_position_number%*%IE_win_position_offset%)}
Let>IE_win_position_Y={%IE_win_position_base_Y%+(%IE_win_position_number%*%IE_win_position_offset%)}
Let>url=http://www.mjtnet.com/
//new method below using VBScript and must supply X and Y co-ords to open at
VBRun>CreateIE,IE_win_position_X,IE_win_position_Y
VBRun>Navigate,%url%
VBRun>MakeVisible
VBRun>WaitBusy
END>ACTION
SRT>Do_Show_Hide_Main_Window
//if Main Window is visible, set var main_window_visible = True
GetDialogProperty>Dialog1,,Visible,main_window_visible
If>main_window_visible=True
SetDialogProperty>Dialog1,,Visible,False
EndIf
If>main_window_visible=True,bypass_and_return
//if we make it here, Main Window was not visible... so make it visible
//...for some reason, I have to setfocus on a different window first...
SetFocus>Program Manager
SetDialogProperty>Dialog1,,Visible,True
//...and then I can setfocus on the Main Window
Wait>0.2
SetFocus>Main Window
Label>bypass_and_return
END>Do_Show_Hide_Main_Window
SRT>DoExit
Exit>0
END>DoExit
Show>Dialog1
//app spends most of its time in this loop... waiting for something to happen
Label>Loop
Wait>0.01
Goto>Loop
Code: Select all
AddTrayIcon>C:\MyIcon.ico,MyTrayIcon,MyApp
STEPS TO PRODUCE ERROR:
- Tap ALT+F11 and it will run the ACTION subroutine which uses VBScript calls to open an IE window.
- Immediately after the above step i.e. while the VBScript is still executing, click the systray icon and it will produce the following error...
Code: Select all
---------------------------
Information
---------------------------
Error initializing MSSCRIPT control.
---------------------------
OK
---------------------------
Code: Select all
---------------------------
Information
---------------------------
Line: 114 VBScript Runtimes Are Not Properly Installed
---------------------------
OK Abort
---------------------------
You must shut down MS itself, then fire it up again and only then will things reset and you can repeat the above results.
Please let me know if you (or anyone) can replicate this... thanks Marcus.
Take care