SendMessage Example

InstallShield 2022 ยป InstallScript Language Reference

Note:To call this function in a Basic MSI setup, you must first create a custom action for the entry-point function, execute the custom action in a sequence or as the result of a dialog's control event, and then build the release.

/*--------------------------------------------------------------*\

*

* InstallShield Example Script

*

* Demonstrates the FindWindow and SendMessage functions.

*

* This script launches Windows Notepad and then calls

* FindWindow to locate the Notepad window.  Next, it calls

* SendMessage to maximize the window;  after a three-second

* delay, it calls SendMessage again to minimize the

* window.   When the script ends, Windows NotePad remains

* open but minimized.  Note that the parameters passed to

* SendMessage are Windows system messages whose values

* are defined as constants in this script.

*

* Note: Before running this script, set the preprocessor

*       constant NOTEPAD so that it references the fully-

*       qualified name of the Windows Notepad executable.

*

\*--------------------------------------------------------------*/

 

#define NOTEPAD "C:\\Windows\\Notepad.exe"

 

// Include Ifx.h for built-in InstallScript function prototypes.

#include "Ifx.h"

 

export prototype ExFn_SendMessage(HWND);

 

function ExFn_SendMessage(hMSI)

    NUMBER nMsg, nwParam, nlParam;

    HWND nHwnd;

begin

 

    // Do not display the setup's background window.

    Disable (BACKGROUND);

 

    // Open the Windows Notepad.

    if (LaunchApp (NOTEPAD, "") < 0 ) then

        MessageBox ("Unable to launch Notepad.", SEVERE);

        abort;

    endif;

 

    // Wait three seconds so we can view the window before

    // it's maximized.

    Delay (3);

 

    // Retrieve the handle of the Notepad window.  The first

    // parameter is the window class.  A null string in the

    // second parameter specifies the topmost Notepad window.

    nHwnd = FindWindow ("NotePAD", "");

 

    if (nHwnd = NULL) then

        MessageBox ("Unable to find the Notepad window.", SEVERE);

    else

        // Send system command to maximize the window.

        SendMessage (nHwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);

 

        // Wait three seconds so we can view the window

        // before it's minimized.

        Delay (3);

 

        // Send system command to minimize the window.

        SendMessage (nHwnd, WM_SYSCOMMAND, SC_MINIMIZE, nlParam);

    endif;

 

end;