WinBinder objects

Windows uses handles of type HWND to refer to most GUI objects. Since handles are 32-bit pointers that are unique to each window, it would be tempting to use them as PHP variables to refer to controls. However, this approach is not ideal for the following reasons:

Therefore the WinBinder Object (WBOBJ) structure is defined. All WinBinder windows and controls are of type WBOBJ. The structure contains the window handle (HWND) and more. Below is a copy of the WBOBJ definition in WB.H:

// WinBinder object (window, control, or menu), stored with SetWindowLong() / GWL_USERDATA

typedef struct _wbo {
    HWND hwnd;                          // Control or window handle
    UINT id;                            // Control identifier
    UINT uClass;                        // Object class
    int item;                           // Item index
    int subitem;                        // Subitem index
    DWORD style;                        // WinBinder style
    struct _wbo *parent;                // Parent window
    LPTSTR pszCallBackFn;               // Callback function
    LPARAM lparam;                      // User-defined parameter
    union {
        LONG lparams[8];                // General-purpose parameter array
        struct {
            RECT rcTitle;               // Title area
            AREA arMin;                 // Minimum window area
            AREA arMax;                 // Maximum window area
        };
    };
    HBITMAP pbuffer;                    // Screen buffer for windows
} WBOBJ, *PWBOBJ;

The WinBinder functions wb_create_control() and wb_create_window() effectively return a pointer to the window's WBOBJ structure as a long integer. This pointer is also stored (with Window API function SetWindowLong() and GWL_USERDATA) in every window. Therefore it always possible to obtain the HWND from a WBOBJ and vice-versa, for any given window or control.

The first LPARAM type field, lparam, carries the value of the param argument that is passed in functions wb_create_control() and wb_create_window(). The array of LPARAMs, lparams, is reserved for internal use and can be used to carry additional user information or additional 32-bit pointers. The latter are accessible only via the wb_peek() function.

Example: obtaining a window handle

// Declare constants for the WBOBJ structure

define("WBOBJ",               "Vhwnd/Vid/Vuclass/litem/lsubitem/Vstyle/Vparent/Vhandler/Vlparam/V8lparams/Vpbuffer");
define("WBOBJ_RAW",           "V3l2V13");
define("WBOBJ_SIZE",          72);

$wbobj = unpack(WBOBJ, wb_peek($window, WBOBJ_SIZE));
$hwnd = $wbobj["hwnd"];

echo "The handle for this window is $hwnd.";

See also

wb_create_control
wb_create_window