| Customize Help

Creating a MILweb client application with C/C++

The MILweb C/C++ API is suitable for writing a standalone MILweb client application executable. Unlike a MIL application, a MILweb client application can run on a Windows or Linux computer without MIL installed; it only requires the MILweb client application and MILweb library (DLL or DSO) file to be installed.

Typically, you should write your MILweb client application using JavaScript, unless C/C++ is specifically required (for example, if you are integrating MILweb client functionality into an existing C/C++ application). A MILweb client application written in JavaScript can be run in a web browser on a wide variety of platforms, without the need to install any files on the user's computer.

This section only discusses information specific to the MILweb C/C++ API. For general information about creating a MILweb client application, see the Fundamentals for creating your MILweb client application section earlier in this chapter. For details about the C/C++ versions of specific MILweb functions, see the C/C++ MILweb function reference section later in this chapter.

Writing a MILweb client application in C/C++

The C/C++ web client application uses milwebclient.dll (under Windows) or milwebclient.so (under Linux). These libraries provide functions to access objects, hook on updates, and send input data to the server. To access these libraries, you must include milweb.h in your project.

When deploying a C/C++ MILweb client application, milwebclient.dll or milwebclient.so must be added as a dependency and installed on the user's computer. Note that no MIL dependency is required.

C/C++ MILweb client applications are only supported on Windows and Linux platforms.

The Windows version of MIL only includes milwebclient.dll. The Linux version of MIL only includes milwebclient.so.

Presenting and interacting with MIL displays

The output of a MIL display is transmitted from your MILweb server application to your MILweb client application as a bitmap image, after all transformations (such as zooming) and annotations are applied. You must manually present the transmitted image in the client window of your application using your chosen GUI toolkit. To enable interactive control of the display, you must also manually capture user input and send it to the display using MilWeb::MdispMessage.

This only applies to C/C++. For JavaScript, presenting and interacting with a display are handled automatically.

Presenting a display

The exact steps to present a display in a client window depend upon the GUI toolkit that you are using in your MILweb client application. Specific C++ MIL examples are provided for Windows GDI (win32), Qt, and GTK.

Regardless of the GUI toolkit you use to present the display in a client window, your MILweb client application will need to inquire the host address, width, height, and pixel pitch of the transmitted image using MilWeb::MdispInquire. Typically, you should also hook a function to display updates using MilWeb::MobjHookFunction with M_UPDATE_WEB. You can then update the presented image within the hook-handler function whenever the content of the display changed in the MILweb server application (including if that change was initiated by a MILweb client application, for example MilWeb::MdispZoom.

Some GUI toolkits (such as Windows GDI and Qt) do not support the default RGBA32 color format of the transmitted image. You can specify that the local computer should automatically convert the transmitted image to the BGRA32 color format using MilWeb::MdispControl with M_WEB_PUBLISHED_FORMAT and M_BGR_32.

Note that, once enabled, you cannot disable this automatic conversion using MilWeb::MdispControl. To disable conversion, you must disconnect from the MILweb server application and reconnect. When you do this, the display is also assigned a new client-side MIL identifier.

Making a presented display interactive

To allow users of your MILweb client application to interactively control a display, you must manually pass their mouse and keyboard interactions to the display using MilWeb::MdispMessage (in addition to making the display interactive using MilWeb::MdispControl with M_INTERACTIVE). For example, if the user clicks the mouse button within the display, you can use MilWeb::MdispMessage with M_MOUSE_LEFT_BUTTON_DOWN to forward the interaction to the display.

In general, if you are using the Microsoft Win32 API, you can map Win32 mouse and keyboard input messages directly to settings for MilWeb::MdispMessage. For example, the following code snippet demonstrates a standard window processing callback function. Whenever the user moves the cursor within the window's client area, the callback function receives the WM_MOUSEMOVE notification and sends the updated cursor position to the display.

/* Forward user mouse input to a display using MILweb */
 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
       case WM_MOUSEMOVE:
          MilWeb::MdispMessage(displayIdentifier, M_MOUSE_MOVE, LOWORD(lParam), HIWORD(lParam), M_NULL, M_DEFAULT);
    return 0;

For each input event you want to forward to the display, you can include a separate case. If you are forwarding many types of events, you might find it useful to store a mapping between the Win32 and MIL constants, instead of writing a separate call to MilWeb::MdispMessage for each case.

The MilWeb::MdispMessage CombinationKeys parameter does not support the same set of keys that are provided as combination keys with some Win32 input messages.