Globals

AutoPlay Media Studio comes with some built-in global functions to make certain runtime tasks simpler.

Note: These optional functions are automatically called by your application. You do not call them in your script, only define them.

General Project Functions

General project functions are called by the application whenever something project-wide happens. These functions allow the developer to control how certain aspects of the published application behave.

g_OnSystemTrayMenu (number X, number Y)

Called whenever the user right-clicks on your application's system tray icon. Typically, you would use Application.ShowPopupMenu in this function to create a right-click popup menu from the system tray.

X:

The X coordinate, in pixels, in relation to the top left corner of the user's screen.

Y:

The Y coordinate, in pixels, in relation to the top left corner of the user's screen.

Returns:

Nothing.

Example:

function g_OnSystemTrayMenu(X, Y)
   tblMenu = {};
   tblMenu[1] ={};
   tblMenu[1].Text = "&New Menu";
   tblMenu[1].ID = 100;
   tblMenu[1].Checked = false;
   tblMenu[1].Enabled = true;
   tblMenu[1].SubMenu = {};
   tblMenu[1].SubMenu[1] = {};
   tblMenu[1].SubMenu[1].Text = "&SubItem 1";
   tblMenu[1].SubMenu[1].ID = 101;
   tblMenu[1].SubMenu[1].Checked = false;
   tblMenu[1].SubMenu[1].Enabled = true;
   tblMenu[1].SubMenu[2] = {};
   tblMenu[1].SubMenu[2].Text = "S&ubItem 2";
   tblMenu[1].SubMenu[2].ID = 102;
   tblMenu[1].SubMenu[2].Checked = false;
   tblMenu[1].SubMenu[2].Enabled = true;

   result = Application.ShowPopupMenu(X, Y, tblMenu, TPM_RIGHTALIGN, TPM_BOTTOMALIGN, true, false);
   
   if(result ~= -1)then
       Dialog.Message("Menu Item Selected",result);
   end
end

QueryAllowProjectClose ( )

Called whenever the project is 'told' to close. Using this function, you can control how the user can close the application, such as confirming with the user that they intended to close the application.

Returns:

True if the application should close, false if it should not close.

Example:

function QueryAllowProjectClose()
    result= Dialog.Message("Application Exit", "Are you sure that you want to quit?", MB_YESNO, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
    --if they choose yes
    if result == IDYES then
        --allow the app to close
        return true;
    else
        --cancel close
        return false;
    end
end

g_OnGetMinMaxInfo ( )

Called whenever the application is resized at runtime. Using this function, you can set the minimum and maximum application window size for your project. If 'Resizable' is not checked in your application's Project Settings, this function is ignored.

Note: If this function is not defined then window size during a resize will not be restricted.

Note: The Min. height and Min. width settings on the Appearance tab of the Project Settings dialog can also be used to set a minimum page height and width, however this function will override those values.

Returns:

A table indexed by the following keys:

KEY

TYPE

DESCRIPTION

MinX

number

The minimum window width in pixels. Note that there is an absolute minimum size allowed by Windows if you have a title bar displayed.

MinY

number

The minimum window height in pixels. Note that there is an absolute minimum size allowed by Windows if you have a title bar displayed.

MaxX

number

The maximum window width in pixels.

MaxY

number

The maximum window height in pixels.

Tip: Do not set any of the values above which you do not want to restrict. For example, if you only want to set a minimum height but not restrict sizing in any other way then only define the MinY value.

Example:

-- Restrict the window size to 200x100 minimum
-- and 800x600 maximum:
function g_OnGetMinMaxInfo()
    tbReturn = {};
    tbReturn.MinX = 200;
    tbReturn.MinY = 100;
    tbReturn.MaxX = 800;
    tbReturn.MaxY = 600;

    return tbReturn;
end

Dialog Functions

Dialog functions are called by the application whenever dialogs are used. These functions allow the developer to control how certain aspects of the dialog behave.

QueryAllowDialogClose (string DialogName )

Called whenever the dialog is 'told' to close. Using this function, you can control how the user can close the dialog, such as confirming with the user that they intended to close the dialog. This function will be called before the dialog's On Close event.

DialogName

A string containing the name of the dialog you want this function to be used on.

Returns:

True to allow the dialog to close, false to not close it.

Example:

function QueryAllowDialogClose(strDialogName)
    result= Dialog.Message("Close Dialog", "Are you sure that you want to close the dialog?", MB_YESNO, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
    --if they choose yes
    if result == IDYES then
        --allow the dialog to close
        return true;
    else
        --cancel close
        return false;
    end
end

Menu Bar Functions

Menu Bar functions are called by the application at runtime to allow the developer to dynamically enable/disable and check/uncheck menu items. By default these functions are not defined (and therefore will do nothing). These functions will only perform tasks if they are defined by the developer at design time.

boolean g_OnUpdateMenuEnabled (number CommandID, table ItemInfo)

Accepts both a Command ID and a table of item information from the AutoPlay runtime. Should return true if the current item should be enabled, and false if the current item should be disabled.

CommandID:

The ID of the currently selected menu item.

ItemInfo:

A table of information about the currently selected item, indexed by the following keys:

KEY

TYPE

DESCRIPTION

ID

number

The numeric ID of the menu item.

Text

string

The text of the menu item. Note that a separator item's Text is set to "---".

IconID

number

The 0-based icon index from the Image List specified on the Menu Bar for the menu item.

Enabled

boolean

Whether the menu item is enabled.

Checked

boolean

Whether the menu item is checked.

SubTable

table

A numerically indexed table of menu item tables if child elements exist, or nil if no child elements exist.

Returns:

True if the current item should be enabled, false if the current item should not be enabled.

Example:

function g_OnUpdateMenuEnabled(CommandID,tblInfo)
    -- Disable command 2000
    if (CommandID == 2000) then
        return false;
    else
        return true;
    end
end

boolean g_OnUpdateMenuCheck (number CommandID, table ItemInfo)

Accepts both a Command ID and a table of item information from the AutoPlay runtime. Should return true if the current item should be checked, and false if the current item should not be checked.

CommandID

The ID of the currently selected menu item.

ItemInfo

A table of information about the currently selected item, indexed by the following keys:

KEY

TYPE

DESCRIPTION

ID

number

The numeric ID of the menu item.

Text

string

The text of the menu item. Note that a separator item's Text is set to "---".

IconID

number

The 0-based icon index from the Image List specified on the Menu Bar for the menu item.

Enabled

boolean

Whether the menu item is enabled.

Checked

boolean

Whether the menu item is checked.

SubTable

table

A numerically indexed table of menu item tables if child elements exist, or nil if no child elements exist.

Returns:

True if the current item should be checked, false if the current item should not be checked.

Example:

function g_OnUpdateMenuCheck(CommandID,tblInfo)
    -- Uncheck command 2000
    if (CommandID == 2000) then
        return false;
    else
        return true;
    end
end