function save_phpcode($filename)
{
    global $wb;
    // Set project variables
    foreach ($wb->project_array as $var) {
        ${$var} = $wb->form[$wb->currentform]->{$var};
        if (!$var) {
            $var = constant("DEFAULT_" . strtoupper($var));
        }
    }
    // Set up some useful variables
    $form = $wb->form[$wb->currentform];
    $valueid = $wb->form[$wb->currentform]->startval;
    $ctrlid = $wb->form[$wb->currentform]->startctrlval;
    $ncontrols = $form->numcontrols;
    $tabnumber = 0;
    // Empty table of IDs
    make_unique_id(null);
    // Start PHP code
    if ($filename) {
        $phpcode = "<?php\r\n\r\n" . PHP_HEADER;
    } else {
        $phpcode = "";
    }
    //--------------------- Code to generate identifiers for all controls
    $phpcode .= "// Control identifiers\r\n\r\n";
    $invalid = array();
    $defined = array();
    // Loop for all controls
    for ($nctrl = 0; $nctrl < $ncontrols; $nctrl++) {
        $ct = $wb->form[$wb->currentform]->ct[$nctrl];
        $define_this = false;
        if (!$ct->id) {
            // Null ID
        } else {
            if (preg_match("/^-?[0-9]+\$/", $ct->id)) {
                // Numeric ID
            } else {
                if (preg_match('/^[a-z][a-z0-9_]*$/i', $ct->id)) {
                    if (in_array($ct->id, $wb->presetids)) {
                        continue;
                    }
                    // Valid string identifier
                    if (!in_array($ct->id, $defined)) {
                        $defined[] = $ct->id;
                        if (preg_match("/^" . $wb->form[$wb->currentform]->prefix . "[a-z]+([0-9]+)\$/i", $ct->id, $matches)) {
                            $valueid = $matches[1];
                        } else {
                            $valueid++;
                        }
                        $define_this = true;
                    }
                } else {
                    // Invalid ID: fix it
                    $inv = $ct->id;
                    $wb->form[$wb->currentform]->ct[$nctrl]->id = make_valid_id($ct->id, 'MAKEID_');
                    if (!in_array($ct->id, $defined)) {
                        $defined[] = $ct->id;
                        $ct = $wb->form[$wb->currentform]->ct[$nctrl];
                        $valueid++;
                        $valueid = make_unique_id($valueid);
                        $invalid[] = "{$inv} (changed to {$ct->id})";
                        $define_this = true;
                    }
                }
            }
        }
        // Create a define() call
        if ($define_this) {
            $valueid = make_unique_id($valueid);
            $phpcode .= "if(!defined('{$ct->id}')) define('{$ct->id}', {$valueid});\r\n";
        }
    }
    // Create code to generate the form (optional)
    if (!$wb->form[$wb->currentform]->istabpage) {
        $phpcode .= "\r\n// Create window\r\n\r\n";
        $phpcode .= "{$formvar} = wb_create_window({$parent}, " . ($form->cclass == "TabPage" ? "AppWindow" : $form->cclass) . ', ' . ($wb->form[$wb->currentform]->localize && $filename ? make_valid_id(str_replace('.prj', '', basename($filename))) : "'{$form->caption}'") . ", WBC_CENTER, WBC_CENTER, {$form->width}, {$form->height}, " . sprintf("0x%08X", $form->style) . ", {$form->value});\r\n";
    } else {
        $tabnumber = $wb->form[$wb->currentform]->tabnumber;
    }
    //--------------------- Code to generate the controls
    $phpcode .= "\r\n// Insert controls\r\n\r\n";
    $last_tab = null;
    for ($i = 0; $i < $ncontrols; $i++) {
        $ct = $wb->form[$wb->currentform]->ct[$i];
        $cid = !$ct->id ? '0' : $ct->id;
        $ctrlparent = $formvar;
        $ctrlcode = '';
        $xoff = 0;
        $yoff = 0;
        //--------------------- Adds optional code for tabs
        if ($wb->form[$wb->currentform]->insertontabs) {
            // If a control is over a tab control, force its parent to be the tab
            static $xtaboffset = 0;
            static $ytaboffset = 0;
            if ($ct->cclass == 'TabControl') {
                $ctrlcode = '$tab = ';
                $ctrlparent = $formvar;
                $tabctrl = $ct;
                $xtaboffset = $tabctrl->left;
                $ytaboffset = $tabctrl->top + 22;
                // Height of a tab, should be read from API
            } else {
                $ctrlcode = '';
                // Is the control inside the tab?
                if (isset($tabctrl) && ($ct->left >= $tabctrl->left && $ct->left <= $tabctrl->left + $tabctrl->width && $ct->top >= $tabctrl->top && $ct->top <= $tabctrl->top + $tabctrl->height)) {
                    $ctrlparent = '$tab';
                    $xoff = $xtaboffset;
                    $yoff = $ytaboffset;
                } else {
                    $ctrlparent = $formvar;
                    $xoff = 0;
                    $yoff = 0;
                }
            }
        }
        //--------------------- Adds optional code (before control creation)
        if ($wb->form[$wb->currentform]->filllists) {
            switch ($ct->cclass) {
                case 'ComboBox':
                case 'ListBox':
                    $ctrlcode .= '$ctrl = ';
                    break;
            }
        }
        if ($wb->form[$wb->currentform]->fillheaders) {
            switch ($ct->cclass) {
                case 'ListView':
                case 'ImageButton':
                    $ctrlcode .= '$ctrl = ';
                    break;
            }
        }
        if ($wb->form[$wb->currentform]->imagenames) {
            switch ($ct->cclass) {
                case 'ImageButton':
                    $ctrlcode .= '$ctrl = ';
                    break;
            }
        }
        if ($wb->form[$wb->currentform]->applyvalues) {
            switch ($ct->cclass) {
                case 'ScrollBar':
                case 'Slider':
                case 'Gauge':
                    $ctrlcode .= '$ctrl = ';
                    break;
            }
        }
        //---------------------  Add variable name (if any)
        $var = $wb->form[$wb->currentform]->ctrlvar;
        if ($var) {
            if ($var[0] != '$') {
                $var = '$' . $var;
            }
            $ctrlcode .= sprintf($var, $ctrlid) . ' = ';
            $ctrlid++;
        }
        //---------------------  Add code to create control
        $phpcode .= $ctrlcode . "wb_create_control({$ctrlparent}, {$ct->cclass}, " . ($wb->form[$wb->currentform]->localize && $filename && $ct->caption ? make_valid_id($ct->caption) : "'{$ct->caption}'") . ", " . ($ct->left - $xoff) . ", " . ($ct->top - $yoff) . ", {$ct->width}, {$ct->height}, {$cid}, " . sprintf("0x%08X", $ct->style) . ", {$ct->value}, {$tabnumber});\r\n";
        //--------------------- Adds optional code (after control creation)
        switch ($ct->cclass) {
            case 'ImageButton':
                if ($wb->form[$wb->currentform]->imagenames) {
                    if (substr($ct->caption, -4) == '.bmp' && file_exists($ct->caption)) {
                        $imgfile = "'{$ct->caption}'";
                    } else {
                        $imgfile = "'resources\\symb_imagebutton.bmp'";
                    }
                    $phpcode .= "\$img = wb_load_image({$imgfile});\n" . "  wb_set_image(\$ctrl, \$img, NOCOLOR, 0, {$ct->value});\n" . "  wb_destroy_image(\$img);";
                }
                break;
            case 'ListView':
                if ($wb->form[$wb->currentform]->fillheaders) {
                    $phpcode .= "wb_set_text(\$ctrl, '{$ct->caption}');\n";
                }
                break;
            case 'ComboBox':
            case 'ListBox':
                if ($wb->form[$wb->currentform]->filllists) {
                    $phpcode .= "wb_set_text(\$ctrl, explode(',', '{$ct->caption}'));\n";
                }
                break;
            case 'ScrollBar':
            case 'Slider':
            case 'Gauge':
                if ($wb->form[$wb->currentform]->applyvalues) {
                    $phpcode .= "wb_set_value(\$ctrl, {$ct->value});\n";
                }
                break;
        }
    }
    // end control loop
    if (!$filename) {
        $phpcode = str_replace('$this->', '$', $phpcode);
    }
    // Prevents errors in PHP 5 -- Stefano
    $phpcode .= "\r\n// End controls\r\n";
    // Let the user know that invalid IDs were corrected
    if (!empty($invalid)) {
        update_control_data();
        // Update ID field on main screen if necessary
        wb_message_box($wb->mainwin, "The following invalid IDs were automatically corrected:\n\n" . implode("\n", $invalid), APPNAME, WBC_INFO);
    }
    //--------------------- Add ending PHP code and save file
    if ($filename) {
        $phpcode .= "\r\n?>";
        $filename = str_replace(".prj", ".form.php", $filename);
        file_put_contents($filename, $phpcode);
        // Generate localization file
        if ($wb->form[$wb->currentform]->localize) {
            $phpcode = "<?php\r\n\r\n" . PHP_HEADER;
            $phpcode .= "// Identifiers for localization\r\n\r\n";
            // Generate line for dialog box title
            if (!$wb->form[$wb->currentform]->istabpage) {
                $id = make_valid_id(str_replace('.form.php', '', basename($filename)));
                echo "******" . "{$id}\n";
                $phpcode .= "define('{$id}'," . str_repeat(' ', 26 - strlen($id)) . "'{$form->caption}');\n\n";
            }
            // Create a define() call for each localization identifier
            for ($i = 0; $i < $ncontrols; $i++) {
                $ct = $wb->form[$wb->currentform]->ct[$i];
                $cid = !$ct->id ? '0' : $ct->id;
                if ($ct->caption) {
                    $id = make_valid_id($ct->caption);
                    if (strlen($id) < 26) {
                        $phpcode .= "define('{$id}'," . str_repeat(' ', 26 - strlen($id)) . "'{$ct->caption}');\n";
                    } else {
                        $phpcode .= "define('{$id}', '{$ct->caption}');\n";
                    }
                }
            }
            $phpcode .= "\r\n?>";
            $filename = str_replace(".form", ".lang", $filename);
            file_put_contents($filename, $phpcode);
        }
    } else {
        return $phpcode;
    }
}
function process_form($window, $id, $ctrl, $lparam1 = 0, $lparam2 = 0)
{
    global $wb;
    static $controls = array();
    static $isMoving = false;
    static $xcuroff = 0;
    static $ycuroff = 0;
    static $ctrl_lastpos = null;
    switch ($id) {
        case IDDEFAULT:
            if ($lparam1 & WBC_RESIZE) {
                // Form was resized
                $size = wb_get_size($wb->formwin);
                $wb->form[$wb->currentform]->width = $size[0];
                $wb->form[$wb->currentform]->height = $size[1];
                update_control_data();
            } elseif ($lparam1 & WBC_REDRAW) {
                // Redraw screen
                // Draw the form background and grid
                $buffer = $lparam2;
                $dim = wb_get_size($window, true);
                $winwidth = $dim[0];
                $winheight = $dim[1];
                draw_background($buffer, $winwidth, $winheight);
                // Draw all controls from the current form
                for ($i = 0; $i < $wb->form[$wb->currentform]->numcontrols; $i++) {
                    $ct = $wb->form[$wb->currentform]->ct[$i];
                    if ($ct) {
                        draw_control($buffer, $ct);
                    }
                }
                // Draw a "ghost"
                if ($ctrl_lastpos && $wb->ghost) {
                    draw_ghost($buffer, $ctrl_lastpos);
                }
                // Is there a control selected?
                if ($wb->form[$wb->currentform]->nselcontrol >= 0) {
                    $ct = $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol];
                    if (!$isMoving) {
                        draw_handles($buffer, "", $ct->left, $ct->top, $ct->width, $ct->height);
                    }
                } else {
                    break;
                }
            } elseif ($lparam1 & WBC_MOUSEUP) {
                // A button was released
                $ctrl_lastpos = null;
                $isMoving = false;
                $wb->mouseop = false;
                $xcuroff = 0;
                $ycuroff = 0;
                wb_refresh($window, true);
                SetMyCursor(IDC_ARROW);
                $wb->mousecpos = NOWHERE;
            } elseif ($lparam1 & WBC_LBUTTON) {
                // Left button is held down
                $wb->mouseop = true;
                $xleft = $lparam2 & 0xffff;
                $ytop = ($lparam2 & 4294901760.0) >> 16;
                // Left mouse button was pressed
                if ($lparam1 & WBC_MOUSEDOWN) {
                    // Can't change the current control while resizing or moving a control
                    if ($wb->mousecpos == NOWHERE || $wb->mousecpos == INCONTROL) {
                        // If mouse cursor is clicked inside a control, select a new one.
                        // Search in reverse order because we need the topmost control
                        $wb->form[$wb->currentform]->nselcontrol = -1;
                        // Start with no control selected
                        $form = $wb->form[$wb->currentform];
                        // Auxiliary variable
                        // This loop finds and selects a new control as current
                        for ($i = $form->numcontrols - 1; $i >= 0; $i--) {
                            $cttest = $form->ct[$i];
                            if ($xleft >= $cttest->left && $xleft <= $cttest->left + $cttest->width && $ytop >= $cttest->top && $ytop <= $cttest->top + $cttest->height) {
                                $ctrl_lastpos = $form->ct[$i];
                                $wb->form[$wb->currentform]->nselcontrol = $i;
                                break;
                            }
                        }
                        // No control selected
                        update_control_data();
                    }
                }
                // $ct (an auxiliary variable) is set to the currently selected control
                if ($wb->form[$wb->currentform]->nselcontrol >= 0) {
                    $ct = $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol];
                }
                // **** Below: resizes aren't considering cursor offset
                if ($wb->mousecpos == INCONTROL) {
                    // Moving control
                    $x = $lparam2 & 0xffff;
                    $y = ($lparam2 & 4294901760.0) >> 16;
                    if (!$isMoving) {
                        $isMoving = true;
                        $xcuroff = $x - $ct->left;
                        $ycuroff = $y - $ct->top;
                    }
                    SetMyCursor(IDC_CROSS);
                    // Is grid active?
                    $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->left = $wb->grid ? (int) (max(4, $x - $xcuroff) / 5) * 5 : $x - $xcuroff;
                    $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->top = $wb->grid ? (int) (max(4, $y - $ycuroff) / 5) * 5 : $y - $ycuroff;
                    update_control_data();
                    wb_refresh($window, true);
                } elseif ($wb->mousecpos == INNHANDLE) {
                    // Resizing control (North)
                    $y = ($lparam2 & 4294901760.0) >> 16;
                    // Is grid active?
                    $y1 = $wb->grid ? (int) (max(4, $y - 0) / 5) * 5 : $y;
                    SetMyCursor(IDC_SIZENS);
                    $bottom = $ct->top + $ct->height;
                    $newtop = $y1 + HANDLE_YOFFSET_5;
                    $newheight = $bottom - $newtop;
                    if ($newheight > 0) {
                        $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->top = $newtop;
                        $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->height = $newheight;
                    }
                    update_control_data();
                    wb_refresh($window, true);
                } elseif ($wb->mousecpos == INEHANDLE) {
                    // Resizing control (East)
                    $x = $lparam2 & 0xffff;
                    // Is grid active?
                    $x1 = $wb->grid ? (int) (max(4, $x - 0) / 5) * 5 : $x;
                    SetMyCursor(IDC_SIZEWE);
                    $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->width = max(1, $x1 - $ct->left);
                    update_control_data();
                    wb_refresh($window, true);
                } elseif ($wb->mousecpos == INWHANDLE) {
                    // Resizing control (West)
                    $x = $lparam2 & 0xffff;
                    // Is grid active?
                    $x1 = $wb->grid ? (int) (max(4, $x - 0) / 5) * 5 : $x;
                    SetMyCursor(IDC_SIZEWE);
                    $right = $ct->left + $ct->width;
                    $newleft = $x1 + HANDLE_XOFFSET_5;
                    $newwidth = $right - $newleft;
                    if ($newwidth > 0) {
                        $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->left = $newleft;
                        $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->width = $newwidth;
                    }
                    update_control_data();
                    wb_refresh($window, true);
                } elseif ($wb->mousecpos == INSHANDLE) {
                    // Resizing control (South)
                    $y = ($lparam2 & 4294901760.0) >> 16;
                    // Is grid active?
                    $y1 = $wb->grid ? (int) (max(4, $y - 0) / 5) * 5 : $y;
                    SetMyCursor(IDC_SIZENS);
                    $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->height = max(1, $y1 - $ct->top);
                    update_control_data();
                    wb_refresh($window, true);
                } elseif ($wb->mousecpos == INNEHANDLE) {
                    // Resizing control (Northeast)
                    $x = $lparam2 & 0xffff;
                    $y = ($lparam2 & 4294901760.0) >> 16;
                    // Is grid active?
                    $x1 = $wb->grid ? (int) (max(4, $x - 0) / 5) * 5 : $x;
                    $y1 = $wb->grid ? (int) (max(4, $y - 0) / 5) * 5 : $y;
                    SetMyCursor(IDC_SIZENESW);
                    $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->width = max(1, $x1 - $ct->left);
                    $bottom = $ct->top + $ct->height;
                    $newtop = $y1 + HANDLE_YOFFSET_5;
                    $newheight = $bottom - $newtop;
                    if ($newheight > 0) {
                        $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->top = $newtop;
                        $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->height = $newheight;
                    }
                    update_control_data();
                    wb_refresh($window, true);
                } elseif ($wb->mousecpos == INSEHANDLE) {
                    // Resizing control (Southeast)
                    $x = $lparam2 & 0xffff;
                    $y = ($lparam2 & 4294901760.0) >> 16;
                    // Is grid active?
                    $x1 = $wb->grid ? (int) (max(4, $x - 0) / 5) * 5 : $x;
                    $y1 = $wb->grid ? (int) (max(4, $y - 0) / 5) * 5 : $y;
                    SetMyCursor(IDC_SIZENWSE);
                    $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->width = max(1, $x1 - $ct->left);
                    $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->height = max(1, $y1 - $ct->top);
                    update_control_data();
                    wb_refresh($window, true);
                } elseif ($wb->mousecpos == INNWHANDLE) {
                    // Resizing control (Northwest)
                    $x = $lparam2 & 0xffff;
                    $y = ($lparam2 & 4294901760.0) >> 16;
                    // Is grid active?
                    $x1 = $wb->grid ? (int) (max(4, $x - 0) / 5) * 5 : $x;
                    $y1 = $wb->grid ? (int) (max(4, $y - 0) / 5) * 5 : $y;
                    SetMyCursor(IDC_SIZENWSE);
                    $right = $ct->left + $ct->width;
                    $newleft = $x1 + HANDLE_XOFFSET_5;
                    $newwidth = $right - $newleft;
                    if ($newwidth > 0) {
                        $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->left = $newleft;
                        $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->width = $newwidth;
                    }
                    $bottom = $ct->top + $ct->height;
                    $newtop = $y1 + HANDLE_YOFFSET_5;
                    $newheight = $bottom - $newtop;
                    if ($newheight > 0) {
                        $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->top = $newtop;
                        $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->height = $newheight;
                    }
                    update_control_data();
                    wb_refresh($window, true);
                } elseif ($wb->mousecpos == INSWHANDLE) {
                    // Resizing control (Southwest)
                    $x = $lparam2 & 0xffff;
                    $y = ($lparam2 & 4294901760.0) >> 16;
                    // Is grid active?
                    $x1 = $wb->grid ? (int) (max(4, $x - 0) / 5) * 5 : $x;
                    $y1 = $wb->grid ? (int) (max(4, $y - 0) / 5) * 5 : $y;
                    SetMyCursor(IDC_SIZENESW);
                    $right = $ct->left + $ct->width;
                    $newleft = $x1 + HANDLE_XOFFSET_5;
                    $newwidth = $right - $newleft;
                    if ($newwidth > 0) {
                        $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->left = $newleft;
                        $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->width = $newwidth;
                    }
                    $wb->form[$wb->currentform]->ct[$wb->form[$wb->currentform]->nselcontrol]->height = max(1, $y1 - $ct->top);
                    update_control_data();
                    wb_refresh($window, true);
                }
            } elseif (!($lparam1 & (WBC_LBUTTON | WBC_RBUTTON))) {
                // No button pressed
                $xleft = $lparam2 & 0xffff;
                $ytop = ($lparam2 & 4294901760.0) >> 16;
                $form = $wb->form[$wb->currentform];
                // Auxiliary variable
                if ($form->nselcontrol < 0) {
                    $wb->mousecpos = NOWHERE;
                    break;
                }
                $ct = $wb->form[$wb->currentform]->ct[$form->nselcontrol];
                // Aux variable
                //-------------- Mouse position tests
                // Is mouse cursor inside the control area?
                if ($xleft >= $ct->left && $xleft <= $ct->left + $ct->width && $ytop >= $ct->top && $ytop <= $ct->top + $ct->height) {
                    SetMyCursor(IDC_HAND);
                    $wb->mousecpos = INCONTROL;
                    break;
                    // Test for North handle
                } else {
                    if ($xleft >= $ct->left + ($ct->width - HANDLE_WIDTH) / 2 && $xleft <= $ct->left + ($ct->width + HANDLE_WIDTH) / 2 && $ytop >= $ct->top - HANDLE_YOFFSET && $ytop <= $ct->top - HANDLE_YOFFSET + HANDLE_HEIGHT) {
                        SetMyCursor(IDC_SIZENS);
                        $wb->mousecpos = INNHANDLE;
                        break;
                        // Test for East handle
                    } else {
                        if ($xleft >= $ct->left + $ct->width + HANDLE_XOFFSET - HANDLE_WIDTH && $xleft <= $ct->left + $ct->width + HANDLE_XOFFSET && $ytop >= $ct->top + ($ct->height - HANDLE_HEIGHT) / 2 && $ytop <= $ct->top + ($ct->height + HANDLE_HEIGHT) / 2) {
                            SetMyCursor(IDC_SIZEWE);
                            $wb->mousecpos = INEHANDLE;
                            break;
                            // Test for West handle
                        } else {
                            if ($xleft >= $ct->left - HANDLE_XOFFSET && $xleft <= $ct->left - HANDLE_XOFFSET + HANDLE_WIDTH && $ytop >= $ct->top + ($ct->height - HANDLE_HEIGHT) / 2 && $ytop <= $ct->top + ($ct->height + HANDLE_HEIGHT) / 2) {
                                SetMyCursor(IDC_SIZEWE);
                                $wb->mousecpos = INWHANDLE;
                                break;
                                // Test for South handle
                            } else {
                                if ($xleft >= $ct->left + ($ct->width - HANDLE_WIDTH) / 2 && $xleft <= $ct->left + ($ct->width + HANDLE_WIDTH) / 2 && $ytop >= $ct->top + $ct->height + HANDLE_YOFFSET - HANDLE_HEIGHT && $ytop <= $ct->top + $ct->height + HANDLE_YOFFSET) {
                                    SetMyCursor(IDC_SIZENS);
                                    $wb->mousecpos = INSHANDLE;
                                    break;
                                    // Test for Northeast handle
                                } else {
                                    if ($xleft >= $ct->left + $ct->width + HANDLE_XOFFSET - HANDLE_WIDTH && $xleft <= $ct->left + $ct->width + HANDLE_XOFFSET && $ytop >= $ct->top - HANDLE_YOFFSET && $ytop <= $ct->top - HANDLE_YOFFSET + HANDLE_HEIGHT) {
                                        SetMyCursor(IDC_SIZENESW);
                                        $wb->mousecpos = INNEHANDLE;
                                        break;
                                        // Test for Shoutheast handle
                                    } else {
                                        if ($xleft >= $ct->left + $ct->width + HANDLE_XOFFSET - HANDLE_WIDTH && $xleft <= $ct->left + $ct->width + HANDLE_XOFFSET && $ytop >= $ct->top + $ct->height + HANDLE_YOFFSET - HANDLE_HEIGHT && $ytop <= $ct->top + $ct->height + HANDLE_YOFFSET) {
                                            SetMyCursor(IDC_SIZENWSE);
                                            $wb->mousecpos = INSEHANDLE;
                                            break;
                                            // Test for Northwest handle
                                        } else {
                                            if ($xleft >= $ct->left - HANDLE_XOFFSET && $xleft <= $ct->left - HANDLE_XOFFSET + HANDLE_WIDTH && $ytop >= $ct->top - HANDLE_YOFFSET && $ytop <= $ct->top - HANDLE_YOFFSET + HANDLE_HEIGHT) {
                                                SetMyCursor(IDC_SIZENWSE);
                                                $wb->mousecpos = INNWHANDLE;
                                                break;
                                                // Test for Shouthwest handle
                                            } else {
                                                if ($xleft >= $ct->left - HANDLE_XOFFSET && $xleft <= $ct->left - HANDLE_XOFFSET + HANDLE_WIDTH && $ytop >= $ct->top + $ct->height + HANDLE_YOFFSET - HANDLE_HEIGHT && $ytop <= $ct->top + $ct->height + HANDLE_YOFFSET) {
                                                    SetMyCursor(IDC_SIZENESW);
                                                    $wb->mousecpos = INSWHANDLE;
                                                    break;
                                                } else {
                                                    $wb->mousecpos = NOWHERE;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            break;
        case IDCLOSE:
            end_drawing_functions();
            wb_destroy_window($window);
            break;
    }
}