STK X Tutorial - Visual Basic 6 In this exercise you will gain hands-on experience using STK X to embed STK functionality in a container application created with Visual Basic 6.0. CONTENTS CREATE THE PROJECT............................................................................................... 1 ADD THE STK X CONTROLS TO THE TOOLBOX.............................................................. 2 SEND COMMANDS TO STK X ...................................................................................... 5 ADD ZOOM IN/OUT TO THE MAP CONTROL .................................................................. 7 RESPOND TO EVENTS RAISED BY STK X...................................................................... 9 ADD MAP PICKING...................................................................................................11 SET STK X PROPERTIES ...........................................................................................13
Create the project 1) Start Microsoft Visual Basic 6. 2) A dialog box will open asking whether you want to create a new project. Select Standard EXE.
3) If Form1 now appears in the designer, skip to the next section. Otherwise proceed to the next step. 4) If a default form was not created automatically, click on the Add Form button in the toolbar to create a new one.
STK X Tutorial – Visual Basic 6.0 1 5) In the dialog box that appears, select Form. The form will be opened in design mode.
STK X Tutorial - Visual Basic 6 In this exercise you will gain hands-on experience using STK X to embed STK functionality in a container applicat ion created with Visual Basic 6.0. C ONTENTS CREATE THE PROJECT ............................................................................................... 1 ADD THE ST K X CONT ROLS TO THE TOOLBOX .............................................................. 2 SEND COMMANDS T O STK X ...................................................................................... 5 ADD ZOOM IN/OUT TO THE MAP CONTROL .................................................................. 7 RESPOND TO EVENTS RAI SED BY ST K X ...................................................................... 9 ADD MAP PI CKING ...................................................................................................11 SET ST K X P ROPERTIES ...........................................................................................13
Create the project 1) Start Microsoft Visual Basic 6. 2)Adialogbxowillopenaskingwhetheryouwanttocreaetanewproject.SelectStandard EXE .
3) If Form1 nowappeasrinthedesigner,skiptothenextsection.Otherwiseproceedto the next step. 4)Ifadefalutformwasnotcreatedautomaticlaly,clickonthe A dd Form button inthe toolbar to create a new one.
STK X Tutorial Vi sual Basic 6.0
1
5) In the dialog box that appears, s F e o l r e m ct. The form will be oepned in design mode.
Add the STK X controls to the Toolbox 1) Onthe View menu, clic T k oolbox to bring up the toolbox.
2)Right-clickinthetoolboxbagrcokund.Inthecontextmenu,c C li o ck m ponents…
STK X Tutorial Vi sual Basic 6.0
2
3)IntheComponents dialog, gothe Controls tab. Check AGI STK X 8 to load the AGI Map and Globe controls.
STK X Tutorial Vi sual Basic 6.0
3
4) Click OK to close th C e omponents dialog. 5) On the main menu, select Project->References. Scroll down and make sure AGI STK/Util 8 is selected.
6) The Map and Globe contro lnsowappearinth T e o olbox .
STK X Tutorial Vi sual Basic 6.0
4
Send commands to STK X 1)ReszieForm1 toacomfortabledimension.ClicktheMap Control and Globe Control in the Toolbox andplacethemonthefor . mResizeand move the controls to a visually pleasing orientation.
2) Click on the C ommandButton control in th T e oolbox to add a button to the form.
STK X Tutorial Vi sual Basic 6.0
5
3) In the Properties dialogforthenewbutton,changethe C aption property to “ New Scenario .
4)Double-clickonthenewbuttoninthedesigner.ThecoedforForm1.vb wi l be displayed. Modify th C e o mmand1_Click function as follows: _ Private Sub Command1 Click() AgUiAx2DCntrl1.Application.ExecuteCommand("New / Scenario Test")
STK X Tutorial Vi sual Basic 6.0
6
End Sub 5) Run the application. Click t N h e e w Scenario button. This may take a few minutes.
6)WiththemouseyouccaonntroltheGlobewindow.
Add Zoom In/Out to the Map control 1)AddtwomorebuttonstotheForm1 windowsform.Chagnethecaptionforthebuttons to Z oom In and Zoom Out .
STK X Tutorial Vi sual Basic 6.0
7
2)Double-clickontheZoom In buttontoswitchtothecodretfhoeClick evetnhandler. Modify the code like this: Private Sub Command2 Click() _ AgUiAx2DCntrl1.ZoomIn End Sub 3)Double-clickontheZoom Out button to switch to the code for C t l h i e ck eventhandler. Modify the code like this: _ Private Sub Command3 Click() AgUiAx2DCntrl1.ZoomOut End Sub 4)RuntheapplicationC.licktheNew Scenario bu t on.ClicktheZoom In button. Use themouse to definethe z o m areain the Map control. Youcan zoom outby clicking the Zoom Out button.
STK X Tutorial Vi sual Basic 6.0
8
Respond to events raised by STK X 1) Inthe Visual Basic 6 IDE, switch teo tchodeviewandenterthefollowingfunction:_ Private Sub AgUiAx2DCntrl1 DblClick() MsgBox ("2D Map double-clicked.") End Sub 2)Runtheapplication.Dobule-clickintheMapwindow.Themessageboxwillbedisplayed.
STK X Tutorial Vi sual Basic 6.0
9
3)Youcanusethesameapproachhootok up to the oGbl e control events. 4)YouarenowgoingtorespondtoSTKXapplicationevents.Usingtheclassandmethodnameselectorsatthetopoftehcodewindow,select(General) as the cla s and ( Declarations) for the method name.
STK X Tutorial Vi sual Basic 6.0
10
5)Addthelinebelowtothfeormcode.Thisaddst s h t e kxApp membervariabletoyourform.ThroughthisvariablecyaonuaccesstheSTKXapplicationobject.Private WithEvents stkxApp As AgSTKXApplication 6) You will now subscribe for notificationon the STK X application boject. Asthis objectisnoat control,theprocedeuirsalittlebitdifferent.UsetheclassnadmethodnameselectrostoselecttheForm classantdheLoad method.Addtheselinestotheform loader: Private Sub Form Load() _ Set stkxApp = AgUiAxVOCntrl1.Application End Sub 7)Now,addaneventhadnlertolitsenfornewscenarioevenst.Attheendofthecode,addthefollowingahndler:Private Sub stkxApp OnScenarioNew(ByVal path As String) _ MsgBox ("Scenario created: " & path) End Sub 8) Run the a p lication.lCicktheNew Scenario button. The me s ageboxwillbedisplayed as a result of the event.
Add map picking 1)GobacktotheDesignveiwinVisualBasic6byselectingForm1fromtehProjectpanel. Add a label to the form.
2) Under the Appearance subsection of teh Properties pag,eclearthelabelcaptionso that it comes up blank.