WinBuilder's Scripting "API"

The WinBuilder Scripting API (a.k.a. the "common" API) is a means to extend and add functionality to a WinBuilder project and to make application (and other) scripts more compatible across multiple projects. WinBuilder also provides a means to integrate these "macros" into the internal editor help system, and make them act and "feel" just like internal WinBuilder Commands

The current API project is still in a bit of "flux", however most commands have been around for some time and will continue to be supported in future versions.

A process to better manage the API is also under development.

How It works

The WinBuilder Scripting API is a set of macros, nothing more nothing less.

What makes it valuable is that the WinBuilder community has decided to use these same macro definitions across many projects. This allows individual scripts, especially for Applications, to be more easily used in different projects. If you know how to create a macro in a script, than you can easily figure out how the API is used. What makes this API process different than a script file containing ordinary macros is how it is "hooked into" the WinBuilder process.

Note: A WinBuilder projects does not need to use the API to be a valuable project. In fact, there are some projects that may not use ANY API, or may use the the API process to implement their own API definition.
It is also important to note that the API just defines the Macro names and interface conventions. Individual projects may need to use a different internal implementation of the API, and that is perfectly OK - as long as the API follows the syntax and functionality defined .

Hooking the API into your project

We will start by looking at what makes the API "turn on". If you look in script.project file you will see the following lines and Variables being defined. This first variable

//-- API File and Some Api project settings

tells WinBuilder what file contains the API, while this variable definition


is used to tell the Common APIi that we are project type 2 (Vista/Win7). This is used internally in the API to make decisions about which implementation should be used when a command is called. Here are the currently defined type values

The following line defines the name of the "section in common_api file that contains the actual definitions of the API commands. In other words, what section has the code to be run when you use any given macro (e.g. Add_shortcut etc.). We will look at that section of the Common API later.


There are some additional lines that should be added to the script.project file which help WinBuilder find and display items for the magic wand (i.e. WinBuilders internal help system). This is displayed in a pull-down menu, where the variable, as an example,


tells WinBuilder what to display for the top level API menu, and the variable


tells WinBuilder what the commands are in the API that have internal templates. (This would be all on one line inside the script file) In addition to defining the various variables, we need one last command to activate them at run time.


This command loads all commands in the common_api.script from the [ApiVar] section we mentioned above as GLOBAL variables. We will get into this a bit more later, but know that this needs to happen in order for scripts to use the Common API commands.

The Common_API.script file

Ok now on to Common_API.script. As mentioned above, we have defined several variables, and there is typically an [Api_Def] section in the script file. For example:


This section doesn't do anything! It is simply a reminder that you need to set these variables in your own script.project in order to use the Common API. Editing this section will not do anything!

On the other hand, the [!ApiVar] Section is very important. This is the section we defined with the line %APIVAR%=ApiVar back in script.project and loaded into memory with the command


This is the part where the commands actually get mapped to their functions. i.e. we create the macro definitions. For example:

----ETC ETC ETC---------

An easy way to think of it is that whenever WinBuilder sees the command _Calculate in any script it internally replaces the _Calculate with


which will execute the [_Calculate] section in %API% which we defined earlier in script.project as being %ProjectDir%\Build\Common_Api.script

Defining the menu entries (syntax templates) for the magic wand

The definitions are contained (as mentioned above) in the [API] Section. Note that line doesn't actually do anything - its just a reminder to developers that the next sections are menu definitions and not actually functions.

Following that line, you will see a bunch of sections all with names corresponding to the submenus we defined in the %APISUBDEF% variable in our project. this is where we actually define the commands to be displayed in the APIs magic wand menu. For example:

Full Syntax="//_Calculate,AutoIT Command(expression),ReturnVar(without %)"
Note="//Always use simple quote in expression ,use `#$c` in place of the comma" and use %ReturnVar% (with %) as result in your code . See AutoIT doc"
MsgBox="_Calculate,MsgBox(2#$c'Test Calculate'#$c'Choice:'#$c5),Choice"
InputBox="_Calculate,InputBox('Question'#$c 'Where were you born?'#$c 'Planet Earth'#$c ''#$c -1#$c -1#$c -1#$c -1),Answer"

Default Value="Add_URL,Favorites,<filename>,<webaddress>"
Full Syntax="Add_URL,[Favorites][Links]<TargetPath>,<filename>,<webaddress>,[UrlDll][None]<url icon address>,[None]<IconIndex>,[None]<HotKey>"
Sample Favorites="Add_Url,,Google.url,"
Sample Links="Add_Url,Links,Google.url,"
Sample Favorites SubF="Add_Url,Favorites\My Folder,Google.url,"
Sample AnyFolder="Add_Url,%target_win%,Google.url,"
Sample Icon Url.dll="Add_Url,,Google.url,,UrlDLL"
Sample Icon Ico="Add_Url,,Google.url,#$psystemroot#$p\system32\blabla.ico"

Full Syntax="//Add_Pin,Type,Order(0,1,2,..,8,9), path\)FileName,Title,Work Folder,Parameters,path\)IconFile#$cIconIndex,StartMode=(1,2,3)#$cHotKey,ToolTipText"
Default Value="Add_Pin,StartMenu,,%PE_Programs%\%ProgramFolder%\%ProgramExe%,%ProgramTitle%"
Sample File="Add_Pin,Taskbar,,#$pSystemRoot#$p\calc.exe"
Sample Lnk="Add_Pin,StartMenu,0,"$Desktop\My Computer.lnk""

When winbuilder builds the api menu it looks at %APISUBDEF% and makes the top level entries based on the contents of this variable. Next it looks for sections inside the API script file that have the matching name of the top level entries and fills the top level menus with the lines in each section.

The sections are layed out like so:

and that's the quick and dirty introduction to the common api. The rest of the code inside the script file are the functions that actually doing the work.

NOTE: WinBuilder does not scan the sections. It only displays the contents of the section referenced by the corresponding name defined in %APISUBDEF%