/*
 * This file was generated automatically by ExtUtils::ParseXS version 3.44 from the
 * contents of GUI.xs. Do not edit this file, edit GUI.xs instead.
 *
 *    ANY CHANGES MADE HERE WILL BE LOST!
 *
 */

#line 1 "GUI.xs"
/*
###############################################################################
#
# Win32::GUI - Perl-Win32 Graphical User Interface Extension
#
# 29 Jan 1997 by Aldo Calpini <dada@perl.it>
#
# Version: 1.0 (12 Nov 2004)
#
# Copyright (c) 1997..2004 Aldo Calpini. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# $Id: GUI.xs,v 1.69 2011/07/16 14:51:03 acalpini Exp $
#
###############################################################################
 */

#include "GUI.h"
#ifdef __CYGWIN__
#include <cygwin/version.h>
#include <sys/cygwin.h>
#endif

    /*
    ###########################################################################
    # (@)PACKAGE:Win32::GUI
    ###########################################################################
     */

#line 41 "GUI.c"
#ifndef PERL_UNUSED_VAR
#  define PERL_UNUSED_VAR(var) if (0) var = var
#endif

#ifndef dVAR
#  define dVAR		dNOOP
#endif


/* This stuff is not part of the API! You have been warned. */
#ifndef PERL_VERSION_DECIMAL
#  define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
#endif
#ifndef PERL_DECIMAL_VERSION
#  define PERL_DECIMAL_VERSION \
	  PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
#endif
#ifndef PERL_VERSION_GE
#  define PERL_VERSION_GE(r,v,s) \
	  (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
#endif
#ifndef PERL_VERSION_LE
#  define PERL_VERSION_LE(r,v,s) \
	  (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
#endif

/* XS_INTERNAL is the explicit static-linkage variant of the default
 * XS macro.
 *
 * XS_EXTERNAL is the same as XS_INTERNAL except it does not include
 * "STATIC", ie. it exports XSUB symbols. You probably don't want that
 * for anything but the BOOT XSUB.
 *
 * See XSUB.h in core!
 */


/* TODO: This might be compatible further back than 5.10.0. */
#if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
#  undef XS_EXTERNAL
#  undef XS_INTERNAL
#  if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
#    define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
#    define XS_INTERNAL(name) STATIC XSPROTO(name)
#  endif
#  if defined(__SYMBIAN32__)
#    define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
#    define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
#  endif
#  ifndef XS_EXTERNAL
#    if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
#      define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
#      define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
#    else
#      ifdef __cplusplus
#        define XS_EXTERNAL(name) extern "C" XSPROTO(name)
#        define XS_INTERNAL(name) static XSPROTO(name)
#      else
#        define XS_EXTERNAL(name) XSPROTO(name)
#        define XS_INTERNAL(name) STATIC XSPROTO(name)
#      endif
#    endif
#  endif
#endif

/* perl >= 5.10.0 && perl <= 5.15.1 */


/* The XS_EXTERNAL macro is used for functions that must not be static
 * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
 * macro defined, the best we can do is assume XS is the same.
 * Dito for XS_INTERNAL.
 */
#ifndef XS_EXTERNAL
#  define XS_EXTERNAL(name) XS(name)
#endif
#ifndef XS_INTERNAL
#  define XS_INTERNAL(name) XS(name)
#endif

/* Now, finally, after all this mess, we want an ExtUtils::ParseXS
 * internal macro that we're free to redefine for varying linkage due
 * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
 * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
 */

#undef XS_EUPXS
#if defined(PERL_EUPXS_ALWAYS_EXPORT)
#  define XS_EUPXS(name) XS_EXTERNAL(name)
#else
   /* default to internal */
#  define XS_EUPXS(name) XS_INTERNAL(name)
#endif

#ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
#define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)

/* prototype to pass -Wmissing-prototypes */
STATIC void
S_croak_xs_usage(const CV *const cv, const char *const params);

STATIC void
S_croak_xs_usage(const CV *const cv, const char *const params)
{
    const GV *const gv = CvGV(cv);

    PERL_ARGS_ASSERT_CROAK_XS_USAGE;

    if (gv) {
        const char *const gvname = GvNAME(gv);
        const HV *const stash = GvSTASH(gv);
        const char *const hvname = stash ? HvNAME(stash) : NULL;

        if (hvname)
	    Perl_croak_nocontext("Usage: %s::%s(%s)", hvname, gvname, params);
        else
	    Perl_croak_nocontext("Usage: %s(%s)", gvname, params);
    } else {
        /* Pants. I don't think that it should be possible to get here. */
	Perl_croak_nocontext("Usage: CODE(0x%" UVxf ")(%s)", PTR2UV(cv), params);
    }
}
#undef  PERL_ARGS_ASSERT_CROAK_XS_USAGE

#define croak_xs_usage        S_croak_xs_usage

#endif

/* NOTE: the prototype of newXSproto() is different in versions of perls,
 * so we define a portable version of newXSproto()
 */
#ifdef newXS_flags
#define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
#else
#define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
#endif /* !defined(newXS_flags) */

#if PERL_VERSION_LE(5, 21, 5)
#  define newXS_deffile(a,b) Perl_newXS(aTHX_ a,b,file)
#else
#  define newXS_deffile(a,b) Perl_newXS_deffile(aTHX_ a,b)
#endif

#line 185 "GUI.c"

XS_EUPXS(XS_Win32__GUI__constant); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI__constant)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "name");
    {
	char *	name = (char *)SvPV_nolen(ST(0))
;
	DWORD	RETVAL;
	dXSTARG;
#line 41 "GUI.xs"
    if (strEQ(name, "WIN32__GUI__WINDOW"))
        RETVAL = WIN32__GUI__WINDOW;
    else if (strEQ(name, "WIN32__GUI__DIALOG"))
        RETVAL = WIN32__GUI__DIALOG;
    else if (strEQ(name, "WIN32__GUI__STATIC"))
        RETVAL = WIN32__GUI__STATIC;
    else if (strEQ(name, "WIN32__GUI__BUTTON"))
        RETVAL = WIN32__GUI__BUTTON;
    else if (strEQ(name, "WIN32__GUI__EDIT"))
        RETVAL = WIN32__GUI__EDIT;
    else if (strEQ(name, "WIN32__GUI__LISTBOX"))
        RETVAL = WIN32__GUI__LISTBOX;
    else if (strEQ(name, "WIN32__GUI__COMBOBOX"))
        RETVAL = WIN32__GUI__COMBOBOX;
    else if (strEQ(name, "WIN32__GUI__CHECKBOX"))
        RETVAL = WIN32__GUI__CHECKBOX;
    else if (strEQ(name, "WIN32__GUI__RADIOBUTTON"))
        RETVAL = WIN32__GUI__RADIOBUTTON;
    else if (strEQ(name, "WIN32__GUI__TOOLBAR"))
        RETVAL = WIN32__GUI__TOOLBAR;
    else if (strEQ(name, "WIN32__GUI__PROGRESS"))
        RETVAL = WIN32__GUI__PROGRESS;
    else if (strEQ(name, "WIN32__GUI__STATUS"))
        RETVAL = WIN32__GUI__STATUS;
    else if (strEQ(name, "WIN32__GUI__TAB"))
        RETVAL = WIN32__GUI__TAB;
    else if (strEQ(name, "WIN32__GUI__RICHEDIT"))
        RETVAL = WIN32__GUI__RICHEDIT;
    else if (strEQ(name, "WIN32__GUI__LISTVIEW"))
        RETVAL = WIN32__GUI__LISTVIEW;
    else if (strEQ(name, "WIN32__GUI__TREEVIEW"))
        RETVAL = WIN32__GUI__TREEVIEW;
    else if (strEQ(name, "WIN32__GUI__TRACKBAR"))
        RETVAL = WIN32__GUI__TRACKBAR;
    else if (strEQ(name, "WIN32__GUI__UPDOWN"))
        RETVAL = WIN32__GUI__UPDOWN;
    else if (strEQ(name, "WIN32__GUI__TOOLTIP"))
        RETVAL = WIN32__GUI__TOOLTIP;
    else if (strEQ(name, "WIN32__GUI__ANIMATION"))
        RETVAL = WIN32__GUI__ANIMATION;
    else if (strEQ(name, "WIN32__GUI__REBAR"))
        RETVAL = WIN32__GUI__REBAR;
    else if (strEQ(name, "WIN32__GUI__HEADER"))
        RETVAL = WIN32__GUI__HEADER;
    else if (strEQ(name, "WIN32__GUI__COMBOBOXEX"))
        RETVAL = WIN32__GUI__COMBOBOXEX;
    else if (strEQ(name, "WIN32__GUI__DTPICK"))
        RETVAL = WIN32__GUI__DTPICK;
    else if (strEQ(name, "WIN32__GUI__GRAPHIC"))
        RETVAL = WIN32__GUI__GRAPHIC;
    else if (strEQ(name, "WIN32__GUI__GROUPBOX"))
        RETVAL = WIN32__GUI__GROUPBOX;
    else if (strEQ(name, "WIN32__GUI__SPLITTER"))
        RETVAL = WIN32__GUI__SPLITTER;
    else if (strEQ(name, "WIN32__GUI__MDIFRAME"))
        RETVAL = WIN32__GUI__MDIFRAME;
    else if (strEQ(name, "WIN32__GUI__MDICLIENT"))
        RETVAL = WIN32__GUI__MDICLIENT;
    else if (strEQ(name, "WIN32__GUI__MDICHILD"))
        RETVAL = WIN32__GUI__MDICHILD;
    else if (strEQ(name, "WIN32__GUI__MONTHCAL"))
        RETVAL = WIN32__GUI__MONTHCAL;
    else
        RETVAL = 0xFFFFFFFF;
#line 263 "GUI.c"
	XSprePUSH;
	PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetAsyncKeyState); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetAsyncKeyState)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "key");
    {
	int	key = (int)SvIV(ST(0))
;
	LONG	RETVAL;
	dXSTARG;
#line 122 "GUI.xs"
    RETVAL = (GetAsyncKeyState(key) & 0x8000) >>15;
#line 284 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetKeyState); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetKeyState)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "key");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	int	key = (int)SvIV(ST(0))
;
#line 143 "GUI.xs"
    USHORT result;
#line 305 "GUI.c"
#line 145 "GUI.xs"
    result = (USHORT)GetKeyState(key);
    if(GIMME_V == G_ARRAY) {
        /* list context */
        EXTEND(SP, 2);
        XST_mIV(0, (UV) ((result & 0x8000) >> 15));
        XST_mIV(1, (UV) (result & 0x0001));
        XSRETURN(2);
    }
    else {
        /* scalar(and void) context */
        XSRETURN_IV((UV) ((result & 0x8000) >> 15));
    }
#line 319 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_GetKeyboardState); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetKeyboardState)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    {
#line 172 "GUI.xs"
     AV   *array;
     BYTE keys[256];
     int  i;
#line 337 "GUI.c"
	AV *	RETVAL;
#line 176 "GUI.xs"
     GetKeyboardState(keys);
     array = (AV*)sv_2mortal((SV*)newAV());
     for(i = 0; i <= 256; i++) {
       av_push(array, newSViv(keys[i] & 128));
     }
     RETVAL = array;
#line 346 "GUI.c"
	{
	    SV * RETVALSV;
	    RETVALSV = newRV((SV*)RETVAL);
	    RETVALSV = sv_2mortal(RETVALSV);
	    ST(0) = RETVALSV;
	}
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_LoadLibrary); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_LoadLibrary)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "name");
    {
	char *	name = (char *)SvPV_nolen(ST(0))
;
#line 199 "GUI.xs"
    char buffer[MAX_PATH+1];
    int i;
#line 370 "GUI.c"
	HINSTANCE	RETVAL;
	dXSTARG;
#line 202 "GUI.xs"
#ifdef __CYGWIN__
    /* Under Cygwin, convert paths to windows
     * paths. E.g. convert /usr/local... and /cygdrive/c/...
     */
#if CYGWIN_VERSION_API_MAJOR > 0 || CYGWIN_VERSION_API_MINOR >= 181
    i = cygwin_conv_path(CCP_POSIX_TO_WIN_A|CCP_RELATIVE,name,buffer,MAX_PATH+1);
    if (i < 0) XSRETURN_UNDEF;
#else
    /* old cygwin api */
    if(cygwin_conv_to_win32_path(name,buffer) != 0)
        XSRETURN_UNDEF;
#endif
#else
    /* LoadLibrary on Win98 (at least) doesn't like unix
     * path seperators, so normalise to windows path seperators
     */
    for(i=0; *name && (i<MAX_PATH); ++name,++i) {
        buffer[i] = (*name == '/' ? '\\' : *name);
    }
    if(*name) {
        /* XXX Path too long - although this appears to be what
         * LoadLibrary would return with such a path, it might be
         * better to find a more specific error code.  E.g.
         * ENAMETOOLONG?
         */
        SetLastError(ERROR_FILE_NOT_FOUND);
        errno = ENOENT;
        XSRETURN_UNDEF;
    }
    buffer[i] = 0;
#endif
    RETVAL = LoadLibrary(buffer);
    if(!RETVAL)
        XSRETURN_UNDEF;
#line 408 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_FreeLibrary); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_FreeLibrary)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "library");
    {
	HINSTANCE	library = INT2PTR(HINSTANCE,SvIV(ST(0)))
;
	bool	RETVAL;
#line 246 "GUI.xs"
    RETVAL = FreeLibrary(library);
#line 428 "GUI.c"
	ST(0) = boolSV(RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetEvent); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetEvent)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, name");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
	char *	name = (char *)SvPV_nolen(ST(1))
;
#line 260 "GUI.xs"
    SV** eventhandler;
    LPPERLWIN32GUI_USERDATA perlud;
#line 450 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 263 "GUI.xs"
    perlud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr((HWND) handle, GWLP_USERDATA);
    if(perlud == NULL || perlud->hvEvents == NULL) XSRETURN_UNDEF;
    eventhandler = hv_fetch(perlud->hvEvents,name,strlen(name),0);
    if(eventhandler != NULL) {
        SvREFCNT_inc(*eventhandler);
        XPUSHs(*eventhandler);
        XSRETURN(1);
    }
    XSRETURN_UNDEF;
#line 471 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_SetEvent); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetEvent)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "handle, name, event");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
	char *	name = (char *)SvPV_nolen(ST(1))
;
	SV*	event = ST(2)
;
#line 284 "GUI.xs"
    LPPERLWIN32GUI_USERDATA perlud;
    PERLWIN32GUI_CREATESTRUCT perlcs;
#line 495 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 287 "GUI.xs"
    ZeroMemory(&perlcs, sizeof(PERLWIN32GUI_CREATESTRUCT));
    perlud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr((HWND) handle, GWLP_USERDATA);
    if(perlud == NULL) XSRETURN_UNDEF;

    if ( perlud->hvEvents == NULL ) {
         perlud->hvEvents = newHV();
         perlud->dwEventMask = 0;
    }
    if(perlud->hvEvents == NULL) XSRETURN_UNDEF;

    perlcs.iClass = perlud->iClass;
    perlcs.hvEvents = perlud->hvEvents;
    perlcs.dwEventMask = perlud->dwEventMask;

    ParseNEMEvent(NOTXSCALL &perlcs, name, event);

    perlud->hvEvents = perlcs.hvEvents;
    perlud->dwEventMask = perlcs.dwEventMask;
    SwitchBit(perlud->dwPlStyle, PERLWIN32GUI_NEM, (perlud->dwEventMask != 0));

    XSRETURN_YES;
#line 528 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_LoadResource); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_LoadResource)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "filename");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	LPCSTR	filename = (LPCSTR)SvPV_nolen(ST(0))
;
#line 328 "GUI.xs"
    HINSTANCE myInstance;
    HRSRC resInfo;
    HGLOBAL resHandle;
    char * resData;
    DWORD resSize;

    myInstance = GetModuleHandle(NULL);
    if(myInstance == NULL) XSRETURN_UNDEF;

    resInfo = FindResource(myInstance,filename,RT_RCDATA);
    if(resInfo == NULL) XSRETURN_UNDEF;

    resSize = SizeofResource(myInstance,resInfo);
    resHandle = LoadResource(myInstance,resInfo);
    if(resHandle == NULL) XSRETURN_UNDEF;

    resData = (char *) LockResource(resHandle);
    if(resData != NULL) {
        // Whew, we have a pointer to our resource data.
        // We would free here, but according to MSDN we don't have to (?!)
        XPUSHs(newSVpvn(resData, resSize));
        XSRETURN(1);
    }
    XSRETURN_UNDEF;
#line 571 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_GetPerlWindow); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetPerlWindow)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 362 "GUI.xs"
    char OldPerlWindowTitle[1024];
    char NewPerlWindowTitle[1024];
    HWND hwndFound;
    HINSTANCE hinstanceFound;
    // this is an hack from M$'s Knowledge Base
    // to get the HWND of the console in which
    // Perl is running (and Hide() it :-).
    GetConsoleTitle(OldPerlWindowTitle, 1024);
    wsprintf(NewPerlWindowTitle,
             "PERL-%d-%d",
             GetTickCount(),
             GetCurrentProcessId());

    SetConsoleTitle(NewPerlWindowTitle);
    Sleep(40);
    hwndFound = FindWindow(NULL, NewPerlWindowTitle);

    // another hack to get the program's instance
#ifdef NT_BUILD_NUMBER
    hinstanceFound = GetModuleHandle("GUI.PLL");
#else
    hinstanceFound = GetModuleHandle("GUI.DLL");
#endif
    // hinstanceFound = (HINSTANCE) GetWindowLongPtr(hwndFound, GWL_HINSTANCE);
    // sv_hinstance = perl_get_sv("Win32::GUI::hinstance", TRUE);
    // sv_setiv(sv_hinstance, PTR2IV(hinstanceFound));
    SetConsoleTitle(OldPerlWindowTitle);
    if(GIMME == G_ARRAY) {
        EXTEND(SP, 2);
        XST_mIV(0, PTR2IV(hwndFound));
        XST_mIV(1, PTR2IV(hinstanceFound));
        XSRETURN(2);
    } else {
        XSRETURN_IV(PTR2IV(hwndFound));
    }
#line 623 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_RegisterClassEx); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_RegisterClassEx)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 405 "GUI.xs"
    WNDCLASSEX wcx;
    HINSTANCE hinstance;

    char * option;
    int i, next_i;

    WNDPROC DefClassProc = NULL;

    ZeroMemory(&wcx, sizeof(WNDCLASSEX));
    wcx.cbSize = sizeof(WNDCLASSEX);

    wcx.style = CS_HREDRAW | CS_VREDRAW; // TODO (default class style...)
    wcx.cbClsExtra = 0;
    wcx.cbWndExtra = 0;
    wcx.lpfnWndProc = WindowMsgLoop;
#ifdef NT_BUILD_NUMBER
    hinstance = GetModuleHandle("GUI.PLL");
#else
    hinstance = GetModuleHandle("GUI.DLL");
#endif
    wcx.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_DEFAULTICON));
    wcx.hIconSm = NULL;
    wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcx.lpszMenuName = NULL;

    for(i = 0; i < items; i++) {
        if(strcmp(SvPV_nolen(ST(i)), "-extends") == 0) {
            next_i = i + 1;
            if(!GetClassInfoEx((HINSTANCE) NULL, (LPCTSTR) SvPV_nolen(ST(next_i)), &wcx)) {
                W32G_WARN("Win32::GUI: Class '%s' not found!", SvPV_nolen(ST(next_i)));
                XSRETURN_NO;
            }
            DefClassProc = wcx.lpfnWndProc;
        }
    }

    next_i = -1;
    for(i = 0; i < items; i++) {
        if(next_i == -1) {
            option = SvPV_nolen(ST(i));
            if(strcmp(option, "-name") == 0) {
                next_i = i + 1;
                wcx.lpszClassName = (char *) SvPV_nolen(ST(next_i));
            } else if(strcmp(option, "-color") == 0) {
                next_i = i + 1;
                wcx.hbrBackground = (HBRUSH) SvCOLORREF(NOTXSCALL ST(next_i));
            } else if(strcmp(option, "-brush") == 0) {
                next_i = i + 1;
                wcx.hbrBackground = (HBRUSH) handle_From(NOTXSCALL ST(next_i));
            } else if(strcmp(option, "-visual") == 0) {
                next_i = i + 1;
                // -visual => 0 is obsolete
            } else if(strcmp(option, "-widget") == 0) {
                next_i = i + 1;
                if(strcmp(SvPV_nolen(ST(next_i)), "Container") == 0) {
                    wcx.lpfnWndProc = ContainerMsgLoop;
                } else if(strcmp(SvPV_nolen(ST(next_i)), "Graphic") == 0) {
                    wcx.lpfnWndProc = CustomMsgLoop;
                } else if(strcmp(SvPV_nolen(ST(next_i)), "Splitter") == 0) {
                    wcx.lpfnWndProc = CustomMsgLoop;
                    wcx.hCursor = LoadCursor(hinstance, MAKEINTRESOURCE(IDC_HSPLIT));
                } else if(strcmp(SvPV_nolen(ST(next_i)), "SplitterH") == 0) {
                    wcx.lpfnWndProc = CustomMsgLoop;
                    wcx.hCursor = LoadCursor(hinstance, MAKEINTRESOURCE(IDC_VSPLIT));
                } else if(strcmp(SvPV_nolen(ST(next_i)), "MDIFrame") == 0) {
                    wcx.lpfnWndProc = MDIFrameMsgLoop;
                } else if(strcmp(SvPV_nolen(ST(next_i)), "MDIChild") == 0) {
                    wcx.lpfnWndProc = MDIChildMsgLoop;
                } else {
                    wcx.lpfnWndProc = ControlMsgLoop;
                }
            } else if(strcmp(option, "-style") == 0) {
                next_i = i + 1;
                wcx.style = (UINT)SvIV(ST(next_i));
            } else if(strcmp(option, "-icon") == 0) {
                next_i = i + 1;
                wcx.hIcon = (HICON) handle_From(NOTXSCALL ST(next_i));
            } else if(strcmp(option, "-cursor") == 0) {
                next_i = i + 1;
                wcx.hCursor = (HCURSOR) handle_From(NOTXSCALL ST(next_i));
            } else if(strcmp(option, "-menu") == 0) {
                next_i = i + 1;
                wcx.lpszMenuName = (char *) SvPV_nolen(ST(next_i));
            }
        } else {
            next_i = -1;
        }
    }

    // Register the window class.
    if(RegisterClassEx(&wcx)) {

        if (DefClassProc != NULL && DefClassProc != wcx.lpfnWndProc)
            SetDefClassProc (NOTXSCALL wcx.lpszClassName, DefClassProc);

        XSRETURN_YES;
    // Try to reregister
    } else if ( UnregisterClass( wcx.lpszClassName, wcx.hInstance ) ) {
        if( RegisterClassEx(&wcx) ) {
            if (DefClassProc != NULL && DefClassProc != wcx.lpfnWndProc)
                SetDefClassProc (NOTXSCALL wcx.lpszClassName, DefClassProc);

            XSRETURN_YES;
        }
    }    
    XSRETURN_NO;
#line 746 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_CreateWindowEx); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_CreateWindowEx)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 518 "GUI.xs"
    HWND myhandle;
    int i, next_i;
    HWND  hParent;
    HMENU hMenu;
    HINSTANCE hInstance;
    LPVOID pPointer;
    DWORD dwStyle;
    DWORD dwExStyle;
    LPCTSTR szClassname;
    LPCTSTR szText;
    int nX, nY, nWidth, nHeight;
    char * option;

    hParent = NULL;
    hMenu = NULL;
    hInstance = NULL;
    pPointer = NULL;
    dwStyle = 0;
    dwExStyle = 0;
    szText = NULL;

    next_i = -1;
    for(i = 0; i < items; i++) {
        if(next_i == -1) {
            option = SvPV_nolen(ST(i));
            if(strcmp(option, "-exstyle") == 0) {
                next_i = i + 1;
                dwExStyle = (DWORD) SvIV(ST(next_i));
            }
            if(strcmp(option, "-class") == 0) {
                next_i = i + 1;
                szClassname = (LPCTSTR) SvPV_nolen(ST(next_i));
            }
            if(strcmp(option, "-text") == 0
            || strcmp(option, "-title") == 0) {
                next_i = i + 1;
                szText = (LPCTSTR) SvPV_nolen(ST(next_i));
            }
            if(strcmp(option, "-style") == 0) {
                next_i = i + 1;
                dwStyle = (DWORD) SvIV(ST(next_i));
            }

            if(strcmp(option, "-left") == 0) {
                next_i = i + 1;
                nX = (int) SvIV(ST(next_i));
            }
            if(strcmp(option, "-top") == 0) {
                next_i = i + 1;
                nY = (int) SvIV(ST(next_i));
            }
            if(strcmp(option, "-height") == 0) {
                next_i = i + 1;
                nHeight = (int) SvIV(ST(next_i));
            }
            if(strcmp(option, "-width") == 0) {
                next_i = i + 1;
                nWidth = (int) SvIV(ST(next_i));
            }
            if(strcmp(option, "-parent") == 0) {
                next_i = i + 1;
                hParent = (HWND) handle_From(NOTXSCALL ST(next_i));
            }
            if(strcmp(option, "-menu") == 0) {
                next_i = i + 1;
                hMenu = (HMENU) handle_From(NOTXSCALL ST(next_i));
            }
            if(strcmp(option, "-instance") == 0) {
                next_i = i + 1;
                hInstance = INT2PTR(HINSTANCE,SvIV(ST(next_i)));
            }
            if(strcmp(option, "-data") == 0) {
                next_i = i + 1;
                pPointer = (LPVOID) SvPV_nolen(ST(next_i));
            }

        } else {
            next_i = -1;
        }
    }
#ifdef PERLWIN32GUI_DEBUG
    printf("XS(CreateWindowEx): Done parsing parameters...\n");
    printf("XS(CreateWindowEx): dwExStyle = 0x%x\n", dwExStyle);
    printf("XS(CreateWindowEx): szClassname = %s\n", szClassname);
    printf("XS(CreateWindowEx): szText = %s\n", szText);
    printf("XS(CreateWindowEx): dwStyle = 0x%x\n", dwStyle);
    printf("XS(CreateWindowEx): nX = %d\n", nX);
    printf("XS(CreateWindowEx): nY = %d\n", nY);
    printf("XS(CreateWindowEx): nWidth = %d\n", nWidth);
    printf("XS(CreateWindowEx): nHeight = %d\n", nHeight);
    printf("XS(CreateWindowEx): hParent = 0x%x\n", hParent);
    printf("XS(CreateWindowEx): hMenu = 0x%x\n", hMenu);
    printf("XS(CreateWindowEx): hInstance = 0x%x\n", hInstance);
    printf("XS(CreateWindowEx): pPointer = 0x%x\n", pPointer);
#endif
    if(myhandle = CreateWindowEx(dwExStyle,
                                 szClassname,
                                 szText,
                                 dwStyle,
                                 nX,
                                 nY,
                                 nWidth,
                                 nHeight,
                                 hParent,
                                 hMenu,
                                 hInstance,
                                 pPointer)) {
        XSRETURN_IV(PTR2IV(myhandle));
    } else {
        XSRETURN_NO;
    }
#line 874 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_Create); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Create)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 637 "GUI.xs"
    HWND myhandle;
    int first_i;
    PERLWIN32GUI_CREATESTRUCT perlcs;
    LPVOID pPointer;
    SV* self;
    SV** stored;
    SV* storing;
    SV** font;
    LPPERLWIN32GUI_USERDATA perlud;

    ZeroMemory(&perlcs, sizeof(PERLWIN32GUI_CREATESTRUCT));

    self = newSVsv(ST(0));
    sv_rvweaken(self);

    perlcs.cs.hInstance = GetModuleHandle(NULL);
    perlcs.hvSelf = (HV*) SvRV(self);
    perlcs.iClass = (int)SvIV(ST(1));
    perlcs.clrForeground = CLR_INVALID;
    perlcs.clrBackground = CLR_INVALID;
    perlcs.iMinWidth = -1;
    perlcs.iMaxWidth = -1;
    perlcs.iMinHeight = -1;
    perlcs.iMaxHeight = -1;    

    // #### fill the default parameters for classes
    OnPreCreate[perlcs.iClass](NOTXSCALL &perlcs);

    first_i = 2;
    if(SvROK(ST(2))) {
        perlcs.cs.hwndParent = (HWND) handle_From(NOTXSCALL ST(2));
        perlcs.hvParent = (HV*) SvRV(ST(2));
        first_i = 3;
    }

    // #### options parsing loop
    ParseWindowOptions(NOTXSCALL sp, mark, ax, items, first_i, &perlcs);

    // No event model set, then force default event model.
    if ( !(perlcs.dwPlStyle & PERLWIN32GUI_OEM) & !(perlcs.dwPlStyle & PERLWIN32GUI_NEM)) {
        SwitchBit(perlcs.dwPlStyle, PERLWIN32GUI_OEM, 1);
    }

    // #### post-processing default parameters
    switch(perlcs.iClass) {
    case WIN32__GUI__BUTTON:
        CalcControlSize(NOTXSCALL &perlcs, 16, 8);
        break;
    case WIN32__GUI__CHECKBOX:
    case WIN32__GUI__RADIOBUTTON:
        CalcControlSize(NOTXSCALL &perlcs, 24, 8);
        break;
    case WIN32__GUI__STATIC:
        CalcControlSize(NOTXSCALL &perlcs, 0, 0);
        break;
    }

    // #### default styles for all controls
    if(perlcs.iClass != WIN32__GUI__WINDOW && 
       perlcs.iClass != WIN32__GUI__DIALOG &&
       perlcs.iClass != WIN32__GUI__MDIFRAME &&
       perlcs.iClass != WIN32__GUI__MDICHILD &&
       perlcs.iClass != WIN32__GUI__TOOLTIP ) {
        SwitchBit(perlcs.cs.style, WS_CHILD, 1);
    }
#ifdef PERLWIN32GUI_STRONGDEBUG
    printf("XS(Create): Done parsing parameters...\n");
    printf("XS(Create): dwExStyle = 0x%x\n", perlcs.cs.dwExStyle);
    printf("XS(Create): szClassname = '%s'\n", perlcs.cs.lpszClass);
    printf("XS(Create): szName = '%s'\n", perlcs.cs.lpszName);
    printf("XS(Create): dwStyle = 0x%x\n", perlcs.cs.style);
    printf("XS(Create): nX = %d\n", perlcs.cs.x);
    printf("XS(Create): nY = %d\n", perlcs.cs.y);
    printf("XS(Create): nWidth = %d\n", perlcs.cs.cx);
    printf("XS(Create): nHeight = %d\n", perlcs.cs.cy);
    printf("XS(Create): hParent = 0x%x\n", perlcs.cs.hwndParent);
    printf("XS(Create): hMenu = 0x%x\n", perlcs.cs.hMenu);
    printf("XS(Create): hInstance = 0x%x\n", perlcs.cs.hInstance);
    printf("XS(Create): dwPlStyle = 0x%x\n", perlcs.dwPlStyle);
#endif

    // #### prepare the ground for the window
    Newz(0, perlud, 1, PERLWIN32GUI_USERDATA);
    perlud->dwSize = sizeof(PERLWIN32GUI_USERDATA);
    PERLUD_STORE;
    perlud->svSelf = self;
    if (NULL != perlcs.szWindowName) {
        strcpy( perlud->szWindowName, perlcs.szWindowName);
    } else {
        sprintf(perlud->szWindowName, "#%x", perlud);
        perlcs.szWindowName = perlud->szWindowName;
    }
    perlud->iClass = perlcs.iClass;
    perlud->hAcc = perlcs.hAcc;
    perlud->hCursor = perlcs.hCursor;
    perlud->dwPlStyle = perlcs.dwPlStyle;
    perlud->iMinWidth = perlcs.iMinWidth;
    perlud->iMaxWidth = perlcs.iMaxWidth;
    perlud->iMinHeight = perlcs.iMinHeight;
    perlud->iMaxHeight = perlcs.iMaxHeight;
    perlud->clrForeground = perlcs.clrForeground;
    perlud->clrBackground = perlcs.clrBackground;
    perlud->hBackgroundBrush = perlcs.hBackgroundBrush;
    perlud->bDeleteBackgroundBrush = perlcs.bDeleteBackgroundBrush;
    perlud->hvEvents = perlcs.hvEvents;
    perlud->dwEventMask = perlcs.dwEventMask;
    perlud->dwData = PTR2IV(perlcs.cs.lpCreateParams);
    pPointer = perlud;

    // #### the following can be vital for the window
    // #### because as soon as it is created the message
    // #### loop is activated and data needs to be there
    storing = newSViv((IV) perlcs.iClass);
    stored = hv_store_mg(NOTXSCALL perlcs.hvSelf, "-type", 5, storing, 0);  // TODO : used ?
    storing = newSVpv((char *)perlcs.szWindowName, 0);
    stored = hv_store_mg(NOTXSCALL perlcs.hvSelf, "-name", 5, storing, 0);

    // Specific MDI_CLIENT : Send CLIENTCREATESTRUCT as LPARAM
    if(perlcs.iClass == WIN32__GUI__MDICLIENT ) {
        pPointer = perlcs.cs.lpCreateParams;
    }

    // #### and finally, creation of the window
#ifdef PERLWIN32GUI_STRONGDEBUG
    printf("XS(Create): Done initialization of USERDATA struct...\n");
#endif
    if(myhandle = CreateWindowEx(
        perlcs.cs.dwExStyle,
        perlcs.cs.lpszClass,
        perlcs.cs.lpszName,
        perlcs.cs.style,
        perlcs.cs.x,
        perlcs.cs.y,
        perlcs.cs.cx,
        perlcs.cs.cy,
        perlcs.cs.hwndParent,
        perlcs.cs.hMenu,
        perlcs.cs.hInstance,
        pPointer
    )) {
        // #### ok, we can fill this object's hash
#ifdef PERLWIN32GUI_STRONGDEBUG
        printf("XS(Create): storing -handle...\n");
#endif
        storing = newSViv(PTR2IV(myhandle));
        stored = hv_store_mg(NOTXSCALL perlcs.hvSelf, "-handle", 7, storing, 0);
        // #### set the font for the control
#ifdef PERLWIN32GUI_STRONGDEBUG
        printf("XS(Create): storing -font...\n");
#endif
        if(perlcs.hFont != NULL) {
            storing = newSViv(PTR2IV(perlcs.hFont));
            stored = hv_store_mg(NOTXSCALL perlcs.hvSelf, "-font", 5, storing, 0);
            SendMessage(myhandle, WM_SETFONT, (WPARAM) perlcs.hFont, 0);
        } else if(perlcs.cs.hwndParent != NULL && perlcs.hvParent != NULL) {
            font = hv_fetch_mg(NOTXSCALL perlcs.hvParent, "-font", 5, FALSE);
            if(font != NULL && SvOK(*font)) {
                perlcs.hFont = (HFONT) handle_From(NOTXSCALL *font);
                SendMessage(myhandle, WM_SETFONT, (WPARAM) perlcs.hFont, 0);
            } else {
                perlcs.hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
                SendMessage(myhandle, WM_SETFONT, (WPARAM) perlcs.hFont, 0);
            }
        }
        if(NULL == perlcs.hAcc) {
#ifdef PERLWIN32GUI_STRONGDEBUG
            printf("XS(Create): storing -accel...\n");
#endif
            stored = hv_store_mg(NOTXSCALL perlcs.hvSelf, "-accel", 6, newSViv(0), 0);
        }

        // #### add (or create) the tooltip
        if(perlcs.szTip != NULL) {
            if(perlcs.hvParent != NULL) {
                if(perlcs.hTooltip == NULL) {
                    SV** t;
                    t = hv_fetch_mg(NOTXSCALL perlcs.hvParent, "-tooltip", 8, 0);
                    if(t != NULL && SvOK( *t )) {
                        perlcs.hTooltip = INT2PTR(HWND,SvIV(*t));
                    }
                }
                if(perlcs.hTooltip == NULL) {
#ifdef PERLWIN32GUI_STRONGDEBUG
                    printf("XS(Create): creating -tooltip...\n");
#endif
                    perlcs.hTooltip = CreateTooltip(NOTXSCALL perlcs.hvParent);
                }
            }
#ifdef PERLWIN32GUI_STRONGDEBUG
            printf("XS(Create): adding -tooltip...\n");
#endif
            TOOLINFO ti;
            ZeroMemory(&ti, sizeof(TOOLINFO));
            ti.cbSize = sizeof(TOOLINFO);
            ti.uFlags = TTF_IDISHWND | TTF_CENTERTIP | TTF_SUBCLASS;
            ti.hwnd = perlcs.cs.hwndParent;
            ti.uId = (WPARAM) myhandle;
            ti.lpszText = perlcs.szTip;
            SendMessage(perlcs.hTooltip, TTM_ADDTOOL, 0, (LPARAM) &ti);
        }

        // #### store the child in the parent hash
#ifdef PERLWIN32GUI_STRONGDEBUG
        printf("XS(Create): storing child into parent...\n");
#endif
        if(perlcs.hvParent != NULL && perlcs.szWindowName != NULL) {
            // storing = newSVsv(ST(0));
            // sv_rvweaken(storing);
            storing = SvREFCNT_inc (self);
            stored = hv_store_mg(NOTXSCALL perlcs.hvParent, perlcs.szWindowName, strlen(perlcs.szWindowName), storing, 0);
        }

        // #### other post-creation class-specific initializations...
#ifdef PERLWIN32GUI_STRONGDEBUG
        printf("XS(Create): post-creation phase...\n");
#endif
        OnPostCreate[perlcs.iClass](NOTXSCALL myhandle, &perlcs);

        // #### store a pointer to the Perl object in the window's USERDATA
#ifdef PERLWIN32GUI_STRONGDEBUG
        printf("XS(Create): storing GWLP_USERDATA...\n");
#endif

        // Specific MDI_CLIENT : SubClass Window
        // We need subclass after window creation for IDFirstChild work.
        if(perlcs.iClass == WIN32__GUI__MDICLIENT ) {
            perlud->dwPlStyle |= PERLWIN32GUI_CUSTOMCLASS;           
            perlud->WndProc = (WNDPROC) SetWindowLongPtr(myhandle, GWLP_WNDPROC, (LONG_PTR) MDIClientMsgLoop);
            SetWindowLongPtr(myhandle, GWLP_USERDATA, (LONG_PTR) perlud);
        }

        // Sub class all standard window control as child control (no WM_CREATE or WN_NCCREATE catch)
        if( !(perlud->dwPlStyle & PERLWIN32GUI_CUSTOMCLASS) ) {
            LPPERLWIN32GUI_USERDATA testud;
            testud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr(myhandle, GWLP_USERDATA);
            if (!ValidUserData(testud) ) {
                perlud->WndProc = (WNDPROC) SetWindowLongPtr(myhandle, GWLP_WNDPROC, (LONG_PTR) ControlMsgLoop);
                SetWindowLongPtr(myhandle, GWLP_USERDATA, (LONG_PTR) perlud);
            }
        }

        // #### (try to) figure out which MsgLoop procedure to use
        if (perlcs.hvParent != NULL) {
            LPPERLWIN32GUI_USERDATA parentud;
            parentud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr(perlcs.cs.hwndParent, GWLP_USERDATA);
            if( ValidUserData(parentud) ) {
                if(parentud->iClass != WIN32__GUI__WINDOW && 
                   parentud->iClass != WIN32__GUI__DIALOG &&
                   parentud->iClass != WIN32__GUI__MDIFRAME &&
                   parentud->iClass != WIN32__GUI__MDICLIENT &&
                   !(parentud->dwPlStyle & PERLWIN32GUI_CONTAINER)) {
                    SwitchBit(parentud->dwPlStyle, PERLWIN32GUI_CONTAINER, 1);
                }
            }
        }
#ifdef PERLWIN32GUI_STRONGDEBUG
        printf("XS(Create): DONE!\n");
#endif
        XSRETURN_IV(PTR2IV(myhandle));
    } else {
#ifdef PERLWIN32GUI_STRONGDEBUG
        printf("XS(Create): CreateWindowEx failed, returning undef\n");
#endif
        XSRETURN_NO;
    }
#line 1156 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_Change); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Change)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 909 "GUI.xs"
    HWND handle;
    PERLWIN32GUI_CREATESTRUCT perlcs;
    LPPERLWIN32GUI_USERDATA perlud;

    handle = (HWND) handle_From(NOTXSCALL ST(0));
    perlud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr(handle, GWLP_USERDATA);

    ZeroMemory(&perlcs, sizeof(PERLWIN32GUI_CREATESTRUCT));
    if( ! ValidUserData(perlud) ) {
        XSRETURN_UNDEF;
    }

    perlcs.hvSelf = (HV*) SvRV(perlud->svSelf);
    perlcs.cs.style = (LONG)GetWindowLongPtr(handle, GWL_STYLE);
    perlcs.cs.dwExStyle = (DWORD)GetWindowLongPtr(handle, GWL_EXSTYLE);
    if(perlcs.hvSelf != NULL) {
        // #### retrieve windows data
        perlcs.iClass = perlud->iClass;
        perlcs.hAcc = perlud->hAcc;
        perlcs.hCursor = perlud->hCursor;
        perlcs.dwPlStyle= perlud->dwPlStyle;
        perlcs.iMinWidth = perlud->iMinWidth;
        perlcs.iMaxWidth = perlud->iMaxWidth;
        perlcs.iMinHeight = perlud->iMinHeight;
        perlcs.iMaxHeight = perlud->iMaxHeight;
        perlcs.clrForeground = perlud->clrForeground;
        perlcs.clrBackground = perlud->clrBackground;
        perlcs.hBackgroundBrush = perlud->hBackgroundBrush;
        perlcs.bDeleteBackgroundBrush = perlud->bDeleteBackgroundBrush;
        perlcs.hvEvents    = perlud->hvEvents;
        perlcs.dwEventMask = perlud->dwEventMask;
#ifdef PERLWIN32GUI_STRONGDEBUG
        printf("XS(Change): BEFORE dwExStyle = 0x%x\n", perlcs.cs.dwExStyle);
        printf("XS(Change): BEFORE szClassname = %s\n", perlcs.cs.lpszClass);
        printf("XS(Change): BEFORE szName = %s\n", perlcs.cs.lpszName);
        printf("XS(Change): BEFORE dwStyle = 0x%x\n", perlcs.cs.style);
        printf("XS(Change): BEFORE nX = %d\n", perlcs.cs.x);
        printf("XS(Change): BEFORE nY = %d\n", perlcs.cs.y);
        printf("XS(Change): BEFORE nWidth = %d\n", perlcs.cs.cx);
        printf("XS(Change): BEFORE nHeight = %d\n", perlcs.cs.cy);
        printf("XS(Change): BEFORE hParent = 0x%x\n", perlcs.cs.hwndParent);
        printf("XS(Change): BEFORE hMenu = 0x%x\n", perlcs.cs.hMenu);
        printf("XS(Change): BEFORE hInstance = 0x%x\n", perlcs.cs.hInstance);
        printf("XS(Change): BEFORE clrForeground = 0x%x\n", perlcs.clrForeground);
        printf("XS(Change): BEFORE clrBackground = 0x%x\n", perlcs.clrBackground);
        printf("XS(Change): BEFORE hBackgroundBrush = 0x%x\n", perlcs.hBackgroundBrush);
        printf("XS(Change): BEFORE bDeleteBackgroundBrush = %d\n", perlcs.bDeleteBackgroundBrush);
#endif
        // #### parse new window options
        ParseWindowOptions(NOTXSCALL sp, mark, ax, items, 1, &perlcs);

        // #### default styles for all controls
        if(perlcs.iClass != WIN32__GUI__WINDOW && 
           perlcs.iClass != WIN32__GUI__DIALOG &&
           perlcs.iClass != WIN32__GUI__MDIFRAME &&
           perlcs.iClass != WIN32__GUI__MDICHILD) {
            SwitchBit(perlcs.cs.style, WS_CHILD, 1);
        }
#ifdef PERLWIN32GUI_STRONGDEBUG
        printf("XS(Change): AFTER dwExStyle = 0x%x\n", perlcs.cs.dwExStyle);
        printf("XS(Change): AFTER szClassname = %s\n", perlcs.cs.lpszClass);
        printf("XS(Change): AFTER szName = %s\n", perlcs.cs.lpszName);
        printf("XS(Change): AFTER dwStyle = 0x%x\n", perlcs.cs.style);
        printf("XS(Change): AFTER nX = %d\n", perlcs.cs.x);
        printf("XS(Change): AFTER nY = %d\n", perlcs.cs.y);
        printf("XS(Change): AFTER nWidth = %d\n", perlcs.cs.cx);
        printf("XS(Change): AFTER nHeight = %d\n", perlcs.cs.cy);
        printf("XS(Change): AFTER hParent = 0x%x\n", perlcs.cs.hwndParent);
        printf("XS(Change): AFTER hMenu = 0x%x\n", perlcs.cs.hMenu);
        printf("XS(Change): AFTER hInstance = 0x%x\n", perlcs.cs.hInstance);
        printf("XS(Change): AFTER clrForeground = 0x%x\n", perlcs.clrForeground);
        printf("XS(Change): AFTER clrBackground = 0x%x\n", perlcs.clrBackground);
        printf("XS(Change): AFTER hBackgroundBrush = 0x%x\n", perlcs.hBackgroundBrush);
        printf("XS(Change): AFTER bDeleteBackgroundBrush = %d\n", perlcs.bDeleteBackgroundBrush);
#endif
        // #### Perform changes
        if(NULL != perlcs.szWindowName) {
            strcpy(perlud->szWindowName, perlcs.szWindowName);
        }

        perlud->iClass = perlcs.iClass;
        perlud->hAcc = perlcs.hAcc;
        perlud->hCursor = perlcs.hCursor;
        perlud->dwPlStyle=  perlcs.dwPlStyle;
        perlud->iMinWidth = perlcs.iMinWidth;
        perlud->iMaxWidth = perlcs.iMaxWidth;
        perlud->iMinHeight = perlcs.iMinHeight;
        perlud->iMaxHeight = perlcs.iMaxHeight;
        perlud->clrForeground = perlcs.clrForeground;
        perlud->clrBackground = perlcs.clrBackground;
        perlud->hBackgroundBrush = perlcs.hBackgroundBrush;
        perlud->bDeleteBackgroundBrush = perlcs.bDeleteBackgroundBrush;
        perlud->hvEvents    = perlcs.hvEvents;
        perlud->dwEventMask = perlcs.dwEventMask;

        if(perlcs.cs.lpszName != NULL)
            SetWindowText(handle, perlcs.cs.lpszName);

        SetWindowLongPtr(handle, GWL_STYLE, perlcs.cs.style);
        SetWindowLongPtr(handle, GWL_EXSTYLE, perlcs.cs.dwExStyle);

        if(perlcs.cs.x != 0 || perlcs.cs.y != 0)
            SetWindowPos(handle, (HWND) NULL, perlcs.cs.x, perlcs.cs.y, 0, 0,
                                 SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOSIZE);
        if(perlcs.cs.cx != 0 || perlcs.cs.cy != 0)
            SetWindowPos(handle, (HWND) NULL, 0, 0, perlcs.cs.cx, perlcs.cs.cy,
                                 SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE);
        if(perlcs.cs.hMenu != NULL)
            SetMenu(handle, perlcs.cs.hMenu);

        if(perlcs.hFont != NULL) {
            hv_store_mg(NOTXSCALL perlcs.hvSelf, "-font", 5, newSViv(PTR2IV(perlcs.hFont)), 0);
            SendMessage(handle, WM_SETFONT, (WPARAM) perlcs.hFont, 0);
        }

        // ### Class Post creation
        OnPostCreate[perlcs.iClass](NOTXSCALL handle, &perlcs);

        /* TODO: change class ???
        if(perlcs.cs.iClass != NULL)
            SetWindowLong(handle, GWL_
        */

        XSRETURN_YES;
    } else {
        XSRETURN_NO;
    }
#line 1300 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_Dialog); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Dialog)
{
    dVAR; dXSARGS;
    if (items < 0 || items > 1)
       croak_xs_usage(cv,  "hwnd=NULL");
    {
	HWND	hwnd;
#line 1056 "GUI.xs"
    MSG msg;
    HWND phwnd;
    HWND thwnd;
    int stayhere;
    BOOL fIsDialog;
    BOOL fIsMDI;
    HACCEL acc;
    LPPERLWIN32GUI_USERDATA perlud;
    LPPERLWIN32GUI_USERDATA tperlud;
#line 1325 "GUI.c"
	WPARAM	RETVAL;
	dXSTARG;

	if (items < 1)
	    hwnd = NULL;
	else {
    if(SvROK(ST(0))) {
	SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
	if(out != NULL)
	    hwnd = INT2PTR(HWND,SvIV(*out));
	else
	    hwnd = NULL;
    } else
       hwnd = INT2PTR(HWND,SvIV(ST(0)))
;
	}
#line 1066 "GUI.xs"
    stayhere = 1;
    fIsDialog = FALSE;
    while (stayhere) {

        ENTER;
        SAVETMPS;

        stayhere = GetMessage(&msg, hwnd, 0, 0);

        if(msg.message == WM_EXITLOOP) {
            stayhere = 0;
            msg.wParam = (WPARAM) -1;
        } else if(stayhere == -1) {
            stayhere = 0;
            msg.wParam = (WPARAM) -2; // an error occurred...
        } else {
            // #### trace back to the window's parent
            phwnd = msg.hwnd;
            while((thwnd = GetParent(phwnd)) && IsChild(thwnd, phwnd) ) {
                phwnd = thwnd;
            }
            // #### now see if the parent window is a DialogBox
            fIsDialog = fIsMDI = FALSE;
            acc = NULL;
            perlud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr(phwnd, GWLP_USERDATA);
            if( ValidUserData(perlud) ) {
                fIsDialog = perlud->dwPlStyle & PERLWIN32GUI_DIALOGUI;
                fIsMDI    = perlud->dwPlStyle & (PERLWIN32GUI_MDIFRAME | PERLWIN32GUI_HAVECHILDWINDOW);
                acc = perlud->hAcc;
            }
            // ### If the parent window is a MDIFrame the active MDIChild 
            // ### can be THE DialogBox
            if(fIsMDI
                && (thwnd = (HWND)SendMessage(INT2PTR(HWND, perlud->dwData), WM_MDIGETACTIVE, (WPARAM) 0, (LPARAM) NULL))
                && (tperlud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr(thwnd, GWLP_USERDATA))
                && ValidUserData(tperlud))
            {
                fIsDialog = tperlud->dwPlStyle & PERLWIN32GUI_DIALOGUI;
            }
            else {
                thwnd = phwnd;
            }

            if( !( (fIsMDI && TranslateMDISysAccel(INT2PTR(HWND, perlud->dwData), &msg)) ||
                   (acc && TranslateAccelerator(phwnd, acc, &msg))              ||
                   (fIsDialog && IsDialogMessage(thwnd, &msg)) ) 
              ){
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }

        FREETMPS;
        LEAVE;
    }

    RETVAL = msg.wParam;
#line 1400 "GUI.c"
	XSprePUSH;
	PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_DoEvents); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_DoEvents)
{
    dVAR; dXSARGS;
    if (items < 0 || items > 4)
       croak_xs_usage(cv,  "hwnd=NULL, wMsgFilterMin=0, wMsgFilterMax=0, wRemoveMsg=PM_REMOVE");
    {
	HWND	hwnd;
	UINT	wMsgFilterMin;
	UINT	wMsgFilterMax;
	UINT	wRemoveMsg;
#line 1144 "GUI.xs"
    MSG msg;
    HWND phwnd;
    HWND thwnd;
    int stayhere;
    BOOL fIsDialog;
    BOOL fIsMDI;
    HACCEL acc;
    LPPERLWIN32GUI_USERDATA perlud;
    LPPERLWIN32GUI_USERDATA tperlud;
#line 1429 "GUI.c"
	WPARAM	RETVAL;
	dXSTARG;

	if (items < 1)
	    hwnd = NULL;
	else {
    if(SvROK(ST(0))) {
	SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
	if(out != NULL)
	    hwnd = INT2PTR(HWND,SvIV(*out));
	else
	    hwnd = NULL;
    } else
       hwnd = INT2PTR(HWND,SvIV(ST(0)))
;
	}

	if (items < 2)
	    wMsgFilterMin = 0;
	else {
	    wMsgFilterMin = (UINT)SvUV(ST(1))
;
	}

	if (items < 3)
	    wMsgFilterMax = 0;
	else {
	    wMsgFilterMax = (UINT)SvUV(ST(2))
;
	}

	if (items < 4)
	    wRemoveMsg = PM_REMOVE;
	else {
	    wRemoveMsg = (UINT)SvUV(ST(3))
;
	}
#line 1154 "GUI.xs"
    stayhere = 1;
    fIsDialog = FALSE;
    while(stayhere) {
        stayhere = PeekMessage(&msg, hwnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
#ifdef PERLWIN32GUI_STRONGDEBUG
        printf("XS(DoEvents): PeekMessage returned %d\n", stayhere);
#endif
        if (stayhere) {
            if(msg.message == WM_EXITLOOP) {
                stayhere = 0;
                msg.wParam = (WPARAM) -1;
            } else  {
                // #### trace back to the window's parent
                phwnd = msg.hwnd;
                while((thwnd = GetParent(phwnd)) && IsChild(thwnd, phwnd) ) {
                    phwnd = thwnd;
                }
                // #### now see if the parent window is a DialogBox
                fIsDialog = fIsMDI = FALSE;
                acc = NULL;
                perlud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr(phwnd, GWLP_USERDATA);
                if( ValidUserData(perlud) ) {
                    fIsDialog = perlud->dwPlStyle & PERLWIN32GUI_DIALOGUI;
                    fIsMDI    = perlud->dwPlStyle & (PERLWIN32GUI_MDIFRAME | PERLWIN32GUI_HAVECHILDWINDOW);
                    acc = perlud->hAcc;
                }
                // ### If the parent window is a MDIFrame the active MDIChild 
                // ### can be THE DialogBox
                if(fIsMDI
                    && (thwnd = (HWND)SendMessage(INT2PTR(HWND, perlud->dwData), WM_MDIGETACTIVE, (WPARAM) 0, (LPARAM) NULL))
                    && (tperlud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr(thwnd, GWLP_USERDATA))
                    && ValidUserData(tperlud))
                {
                    fIsDialog = tperlud->dwPlStyle & PERLWIN32GUI_DIALOGUI;
                }
                else {
                    thwnd = phwnd;
                }

                if( !( (fIsMDI && TranslateMDISysAccel(INT2PTR(HWND, perlud->dwData), &msg)) ||
                       (acc && TranslateAccelerator(phwnd, acc, &msg))              ||
                       (fIsDialog && IsDialogMessage(thwnd, &msg)) ) 
                  ){
                    TranslateMessage(&msg);
                    DispatchMessage(&msg);
                }
            }
        }
        else
            msg.wParam = (WPARAM) 0;
    }
    RETVAL = msg.wParam;
#line 1520 "GUI.c"
	XSprePUSH;
	PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_DoModal); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_DoModal)
{
    dVAR; dXSARGS;
    if (items < 1 || items > 2)
       croak_xs_usage(cv,  "handle, all=FALSE");
    {
	HWND	handle;
	BOOL	all;
#line 1231 "GUI.xs"
    LPPERLWIN32GUI_USERDATA perlud;
    MSG msg;
    int stayhere;
    HWND phwnd;
    HWND thwnd;
    BOOL fIsDialog;
    BOOL fIsMDI;
    HACCEL acc;
    HWND parent;
#line 1547 "GUI.c"
	WPARAM	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

	if (items < 2)
	    all = FALSE;
	else {
	    all = (BOOL)SvIV(ST(1))
;
	}
#line 1241 "GUI.xs"
    // Set ISMODAL flag
    perlud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr(handle, GWLP_USERDATA);
    if( !ValidUserData(perlud) || (perlud->dwPlStyle & PERLWIN32GUI_ISMODAL) )
        XSRETURN_NO;

    perlud->dwPlStyle |= PERLWIN32GUI_ISMODAL;

    // Find its owner window if any or use ActiveWindow
    parent = GetWindow(handle, GW_OWNER);
    if (parent == NULL) {
        parent = GetActiveWindow(); 
    }

    // Disable parent window or all top window
    if (all)
        EnumThreadWindows (GetWindowThreadProcessId(parent, NULL), (WNDENUMPROC) EnableWindowsProc, (LPARAM) FALSE);
    else
        EnableWindow (parent, FALSE);

    // Enable/Show Dialog
    EnableWindow (handle, TRUE);
    ShowWindow(handle, SW_SHOWNORMAL);
    SetActiveWindow(handle);

    // Go to message loop
    stayhere = 1;
    while (stayhere) {

        ENTER;
        SAVETMPS;

        stayhere = GetMessage(&msg, NULL, 0, 0);

        if(msg.message == WM_EXITLOOP || msg.message == WM_QUIT) {
            stayhere = 0;
            msg.wParam = (WPARAM) 0;  // Don't return -1 for a DoModal
        } else if(stayhere == -1) {
            stayhere = 0;
            msg.wParam = (WPARAM) -1; // an error occurred...
        } else {

            // #### trace back to the window's parent
            phwnd = msg.hwnd;
            while((thwnd = GetParent(phwnd)) && IsChild(thwnd, phwnd) ) {
                phwnd = thwnd;
            }
            // #### now see if the parent window is a DialogBox
            fIsDialog = fIsMDI = FALSE;
            acc = NULL;
            perlud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr(phwnd, GWLP_USERDATA);
            if( ValidUserData(perlud) ) {
                fIsDialog = perlud->dwPlStyle & PERLWIN32GUI_DIALOGUI;
                fIsMDI    = perlud->dwPlStyle & (PERLWIN32GUI_MDIFRAME | PERLWIN32GUI_HAVECHILDWINDOW);
                acc = perlud->hAcc;
            }

            if( !( (fIsMDI && TranslateMDISysAccel(INT2PTR(HWND, perlud->dwData), &msg)) ||
                   (acc && TranslateAccelerator(phwnd, acc, &msg))              ||
                   (fIsDialog && IsDialogMessage(phwnd, &msg)) ) 
              ){
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }

        FREETMPS;
        LEAVE;
    }

    // Enable parent or all active topwindow
    if (all)
        EnumThreadWindows (GetWindowThreadProcessId(parent, NULL), (WNDENUMPROC) EnableWindowsProc, (LPARAM) TRUE);
    else
        EnableWindow (parent, TRUE);

    // Hide DialogBox
    ShowWindow(handle, SW_HIDE);

    // Active parent
    SetActiveWindow(parent);
    // UnSet ISMODAL flag
    perlud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr(handle, GWLP_USERDATA);
    if( ValidUserData(perlud))
       perlud->dwPlStyle &= ~PERLWIN32GUI_ISMODAL;

    RETVAL = msg.wParam;
#line 1654 "GUI.c"
	XSprePUSH;
	PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_Scroll); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Scroll)
{
    dVAR; dXSARGS;
    if (items < 3 || items > 5)
       croak_xs_usage(cv,  "handle, scrollbar, operation, position = -1, thumbtrack_flag = 0");
    {
	HWND	handle;
	int	scrollbar = (int)SvIV(ST(1))
;
	int	operation = (int)SvIV(ST(2))
;
	int	position;
	BOOL	thumbtrack_flag;
#line 1364 "GUI.xs"
    SCROLLINFO si;
#line 1678 "GUI.c"
	int	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

	if (items < 4)
	    position = -1;
	else {
	    position = (int)SvIV(ST(3))
;
	}

	if (items < 5)
	    thumbtrack_flag = 0;
	else {
	    thumbtrack_flag = (BOOL)SvIV(ST(4))
;
	}
#line 1366 "GUI.xs"
    si.cbSize = sizeof(si);
    si.fMask = SIF_ALL;
    if(GetScrollInfo(handle,scrollbar,&si)) {
        si.fMask = SIF_POS;
        switch(operation) {
            case SB_THUMBTRACK:
                if(!thumbtrack_flag) {
                    /* No tracking */
                    break;
                }
                /* fall through */
            case SB_THUMBPOSITION:
                if(position == -1) {
                    si.nPos = si.nTrackPos;
                }
                else {
                    si.nPos = position;
                }
                break;
            case SB_LINEUP:
                si.nPos--;
                break;
            case SB_LINEDOWN:
                si.nPos++;
                break;
            case SB_PAGEUP:
                si.nPos -= si.nPage;
                break;
            case SB_PAGEDOWN:
                si.nPos += si.nPage;
                break;
            case SB_TOP:
                si.nPos = si.nMin;
                break;
            case SB_BOTTOM:
                si.nPos = si.nMax;
                break;
            default:
                XSRETURN_UNDEF;
                break;
        }
        RETVAL = SetScrollInfo(handle, scrollbar, &si, 1);
    }
    else {
        XSRETURN_UNDEF;
    }
#line 1752 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_ScrollRange); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_ScrollRange)
{
    dVAR; dXSARGS;
    if (items < 2)
       croak_xs_usage(cv,  "handle, scrollbar, ...");
    {
	HWND	handle;
	int	scrollbar = (int)SvIV(ST(1))
;
#line 1429 "GUI.xs"
    SCROLLINFO si;  // We use scrollinfo because SetScrollRange is deprecated.
#line 1772 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 1431 "GUI.xs"
    si.cbSize = sizeof(SCROLLINFO);
    si.fMask = SIF_RANGE;
    if(scrollbar > 1) XSRETURN_UNDEF;
    if(items > 2) {
        si.nMin = (int)SvIV(ST(2));
        si.nMax = (int)SvIV(ST(3));
        SetScrollInfo(handle, scrollbar, &si, 1);
    }
    if(GetScrollInfo(handle,scrollbar,&si)) {
        EXTEND(SP, 2);
        XST_mIV(0, si.nMin);
        XST_mIV(1, si.nMax);
        XSRETURN(2);
    }
    else {
        XSRETURN_UNDEF;
    }
#line 1801 "GUI.c"
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_ScrollPage); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_ScrollPage)
{
    dVAR; dXSARGS;
    if (items < 2)
       croak_xs_usage(cv,  "handle, scrollbar, ...");
    {
	HWND	handle;
	int	scrollbar = (int)SvIV(ST(1))
;
#line 1462 "GUI.xs"
    SCROLLINFO si;
#line 1819 "GUI.c"
	DWORD	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 1464 "GUI.xs"
    si.cbSize = sizeof(SCROLLINFO);
    if(scrollbar > 1) XSRETURN_UNDEF;
    si.fMask = SIF_PAGE;
    if(items > 2) {
        si.nPage = (UINT)SvIV(ST(2));
        SetScrollInfo(handle, scrollbar, &si, 1);
    }
    if(GetScrollInfo(handle,scrollbar,&si)) {
        RETVAL = si.nPage;
    }
#line 1843 "GUI.c"
	XSprePUSH;
	PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_ScrollPos); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_ScrollPos)
{
    dVAR; dXSARGS;
    if (items < 2)
       croak_xs_usage(cv,  "handle, scrollbar, ...");
    {
	HWND	handle;
	int	scrollbar = (int)SvIV(ST(1))
;
#line 1490 "GUI.xs"
    SCROLLINFO si;
#line 1863 "GUI.c"
	DWORD	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 1492 "GUI.xs"
    si.cbSize = sizeof(SCROLLINFO);
    if(scrollbar > 1) XSRETURN_UNDEF;
    if(items > 2) {
        si.fMask = SIF_POS;
        si.nPos = (int)SvIV(ST(2));
        SetScrollInfo(handle, scrollbar, &si, 1);
    }
    si.fMask = SIF_POS;
    if(GetScrollInfo(handle,scrollbar,&si)) {
        RETVAL = si.nPos;
    }
#line 1888 "GUI.c"
	XSprePUSH;
	PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_LoadCursorFromFile); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_LoadCursorFromFile)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "filename");
    {
	LPCTSTR	filename = (LPCTSTR)SvPV_nolen(ST(0))
;
	HCURSOR	RETVAL;
	dXSTARG;
#line 1513 "GUI.xs"
    RETVAL = LoadCursorFromFile(filename);
#line 1909 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_LoadCursor); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_LoadCursor)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "ID");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	long	ID = (long)SvIV(ST(0))
;
#line 1549 "GUI.xs"
    HCURSOR cursor;
#line 1930 "GUI.c"
#line 1551 "GUI.xs"
    cursor = LoadCursor(NULL, MAKEINTRESOURCE(ID));
    if (cursor== NULL) XSRETURN_UNDEF;
    XPUSHs(CreateObjectWithHandle(NOTXSCALL "Win32::GUI::Cursor", (HWND) cursor));
#line 1935 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_LoadString); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_LoadString)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "uID");
    {
	UINT	uID = (UINT)SvUV(ST(0))
;
#line 1563 "GUI.xs"
    char  lpBuffer[256];
    HINSTANCE moduleHandle;
#line 1954 "GUI.c"
	LPTSTR	RETVAL;
	dXSTARG;
#line 1566 "GUI.xs"
    moduleHandle = GetModuleHandle(NULL);
    if(LoadString(moduleHandle,uID,lpBuffer,256)) {
        RETVAL = (LPTSTR)  lpBuffer;
    } else {
        RETVAL = "";
    }
#line 1964 "GUI.c"
	sv_setpv(TARG, RETVAL);
	XSprePUSH;
	PUSHTARG;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_LoadImage); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_LoadImage)
{
    dVAR; dXSARGS;
    if (items < 1 || items > 5)
       croak_xs_usage(cv,  "filename, iType=IMAGE_BITMAP, iX=0, iY=0, iFlags=LR_DEFAULTCOLOR");
    {
	SV *	filename = ST(0)
;
	UINT	iType;
	int	iX;
	int	iY;
	UINT	iFlags;
#line 1590 "GUI.xs"
    HINSTANCE moduleHandle;
    HBITMAP bitmap = NULL;
    char buffer[MAX_PATH+1];
    char *name;
    int i;
#line 1992 "GUI.c"
	HBITMAP	RETVAL;
	dXSTARG;

	if (items < 2)
	    iType = IMAGE_BITMAP;
	else {
	    iType = (UINT)SvUV(ST(1))
;
	}

	if (items < 3)
	    iX = 0;
	else {
	    iX = (int)SvIV(ST(2))
;
	}

	if (items < 4)
	    iY = 0;
	else {
	    iY = (int)SvIV(ST(3))
;
	}

	if (items < 5)
	    iFlags = LR_DEFAULTCOLOR;
	else {
	    iFlags = (UINT)SvUV(ST(4))
;
	}
#line 1596 "GUI.xs"
    /* Try to find the resource in the current EXE */
    moduleHandle = GetModuleHandle(NULL);

    /* If filename looks like a string, attempt to load from current EXE: */
    if((bitmap ==NULL) && SvPOK(filename) && !(iFlags & LR_LOADFROMFILE)) {
        bitmap = (HBITMAP) LoadImage((HINSTANCE) moduleHandle,
                SvPV_nolen(filename), iType, iX, iY, iFlags);
    }

    /* If filename looks like a number, try it as a resource id from the current EXE */
    if((bitmap == NULL) && SvIOK(filename) && !(iFlags & LR_LOADFROMFILE)) {
        bitmap = (HBITMAP) LoadImage((HINSTANCE) moduleHandle,
                MAKEINTRESOURCE(SvIV(filename)), iType, iX, iY, iFlags);
    }

    /* Try to find the resource from GUI.dll */
    moduleHandle = GetModuleHandle("GUI.dll");

    /* If filename looks like a string, try it as a resource name from GUI.dll */
    if((bitmap == NULL) && SvPOK(filename) && !(iFlags & LR_LOADFROMFILE)) {
        bitmap = (HBITMAP) LoadImage((HINSTANCE) moduleHandle,
                SvPV_nolen(filename), iType, iX, iY, iFlags);
    }

    /* If filename looks like a number, try it as a resource id from GUI.dll */
    if((bitmap == NULL) && SvIOK(filename) && !(iFlags & LR_LOADFROMFILE)) {
        bitmap = (HBITMAP) LoadImage((HINSTANCE) moduleHandle,
                MAKEINTRESOURCE(SvIV(filename)), iType, iX, iY, iFlags);
    }

    /* Try to load from file or as an OEM resource */
    moduleHandle = NULL;

    /* if filename looks like a string, try it as a file name */
    if((bitmap == NULL) && SvPOK(filename)) {
        name = SvPV_nolen(filename);
#ifdef __CYGWIN__
        /* Under Cygwin, convert paths to windows
         * paths. E.g. convert /usr/local... and /cygdrive/c/...
         */
#if CYGWIN_VERSION_API_MAJOR > 0 || CYGWIN_VERSION_API_MINOR >= 181
    i = cygwin_conv_path(CCP_POSIX_TO_WIN_A|CCP_RELATIVE,name,buffer,MAX_PATH+1);
    if (i < 0) XSRETURN_UNDEF;
#else
    /* old cygwin api */
    if(cygwin_conv_to_win32_path(name,buffer) != 0)
        XSRETURN_UNDEF;
#endif
#else
        /* LoadImage on Win98 (at least) doesn't like unix
         * path seperators, so normalise to windows path seperators
         */
        for(i=0; *name && (i<MAX_PATH); ++name,++i) {
            buffer[i] = (*name == '/' ? '\\' : *name);
        }
        if(*name) {
            /* XXX Path too long - although this appears to be what
             * LoadImage would return with such a path, it might be
             * better to find a more specific error code.  E.g.
             * ENAMETOOLONG?
             */
            SetLastError(ERROR_FILE_NOT_FOUND);
            errno = ENOENT;
            XSRETURN_UNDEF;
        }
        buffer[i] = 0;
#endif
        bitmap = (HBITMAP) LoadImage((HINSTANCE) moduleHandle,
                buffer, iType, iX, iY, iFlags|LR_LOADFROMFILE);
    }

    /* If filename looks like a number, try it as an OEM resource id */
    if((bitmap == NULL) && SvIOK(filename) && !(iFlags & LR_LOADFROMFILE)) {
        bitmap = (HBITMAP) LoadImage((HINSTANCE) moduleHandle,
                MAKEINTRESOURCE(SvIV(filename)), iType, iX, iY, iFlags);
    }

    /* Finally, if it looks like a number, try it as a pre-defined resource */
    if((bitmap == NULL) && SvIOK(filename)) {
        if(iType == IMAGE_BITMAP) {
            bitmap = (HBITMAP)LoadBitmap(NULL, MAKEINTRESOURCE(SvIV(filename)));
        }
        else if (iType == IMAGE_ICON) {
            bitmap = (HBITMAP)LoadIcon(NULL, MAKEINTRESOURCE(SvIV(filename)));
        }
        else if (iType == IMAGE_CURSOR) {
            bitmap = (HBITMAP)LoadCursor(NULL, MAKEINTRESOURCE(SvIV(filename)));
        }
    }

    RETVAL = bitmap;
#line 2115 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_DestroyCursor); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_DestroyCursor)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "cursor");
    {
	HCURSOR	cursor;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            cursor = INT2PTR(HCURSOR,SvIV(*out));
        else
            cursor = NULL;
    } else
       cursor = INT2PTR(HCURSOR,SvIV(ST(0)))
;
#line 1696 "GUI.xs"
    RETVAL = DestroyCursor(cursor);
#line 2145 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_SetCursor); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetCursor)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "cursor");
    {
	HCURSOR	cursor;
	HCURSOR	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            cursor = INT2PTR(HCURSOR,SvIV(*out));
        else
            cursor = NULL;
    } else
       cursor = INT2PTR(HCURSOR,SvIV(ST(0)))
;
#line 1712 "GUI.xs"
    RETVAL = SetCursor(cursor);
#line 2175 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetCursor); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetCursor)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    {
	HCURSOR	RETVAL;
	dXSTARG;
#line 1722 "GUI.xs"
    RETVAL = GetCursor();
#line 2194 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_ChangeCursor); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_ChangeCursor)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, cursor");
    {
	HWND	handle;
	HCURSOR	cursor;
	HCURSOR	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

    if(SvROK(ST(1))) {
        SV** out=hv_fetch((HV*)SvRV(ST(1)), "-handle", 7, 0);
        if(out != NULL)
            cursor = INT2PTR(HCURSOR,SvIV(*out));
        else
            cursor = NULL;
    } else
       cursor = INT2PTR(HCURSOR,SvIV(ST(1)))
;
#line 1737 "GUI.xs"
    RETVAL = (HCURSOR) SetClassLongPtr(handle, GCLP_HCURSOR, (LONG_PTR) cursor);
#line 2235 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetCursorPos); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetCursorPos)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 1754 "GUI.xs"
    POINT point;
#line 2254 "GUI.c"
#line 1756 "GUI.xs"
    if(GetCursorPos(&point)) {
        EXTEND(SP, 2);
        XST_mIV(0, point.x);
        XST_mIV(1, point.y);
        XSRETURN(2);
    } else {
        XSRETURN_UNDEF;
    }
#line 2264 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_SetCursorPos); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetCursorPos)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "x, y");
    {
	int	x = (int)SvIV(ST(0))
;
	int	y = (int)SvIV(ST(1))
;
	BOOL	RETVAL;
	dXSTARG;
#line 1775 "GUI.xs"
    RETVAL = SetCursorPos(x, y);
#line 2286 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_ClipCursor); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_ClipCursor)
{
    dVAR; dXSARGS;
    if (items < 0 || items > 4)
       croak_xs_usage(cv,  "left=0, top=0, right=0, bottom=0");
    {
	LONG	left;
	LONG	top;
	LONG	right;
	LONG	bottom;
#line 1790 "GUI.xs"
    RECT r;
#line 2307 "GUI.c"
	BOOL	RETVAL;
	dXSTARG;

	if (items < 1)
	    left = 0;
	else {
	    left = (LONG)SvIV(ST(0))
;
	}

	if (items < 2)
	    top = 0;
	else {
	    top = (LONG)SvIV(ST(1))
;
	}

	if (items < 3)
	    right = 0;
	else {
	    right = (LONG)SvIV(ST(2))
;
	}

	if (items < 4)
	    bottom = 0;
	else {
	    bottom = (LONG)SvIV(ST(3))
;
	}
#line 1792 "GUI.xs"
    if(items == 0) {
        RETVAL = ClipCursor(NULL);
    } else {
        r.left = left;
        r.top = top;
        r.right = right;
        r.bottom = bottom;
        RETVAL = ClipCursor(&r);
    }
#line 2348 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_ChangeIcon); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_ChangeIcon)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, icon");
    {
	HWND	handle;
	HICON	icon;
	HICON	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

    if(SvROK(ST(1))) {
        SV** out=hv_fetch((HV*)SvRV(ST(1)), "-handle", 7, 0);
        if(out != NULL)
            icon = INT2PTR(HICON,SvIV(*out));
        else
            icon = NULL;
    } else
       icon = INT2PTR(HICON,SvIV(ST(1)))
;
#line 1813 "GUI.xs"
    SetClassLongPtr(handle, GCLP_HICONSM, (LONG_PTR) icon);
    RETVAL = (HICON) SetClassLongPtr(handle, GCLP_HICON, (LONG_PTR) icon);
#line 2390 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_ChangeSmallIcon); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_ChangeSmallIcon)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, icon");
    {
	HWND	handle;
	HICON	icon;
	HICON	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

    if(SvROK(ST(1))) {
        SV** out=hv_fetch((HV*)SvRV(ST(1)), "-handle", 7, 0);
        if(out != NULL)
            icon = INT2PTR(HICON,SvIV(*out));
        else
            icon = NULL;
    } else
       icon = INT2PTR(HICON,SvIV(ST(1)))
;
#line 1828 "GUI.xs"
    RETVAL = (HICON) SetClassLongPtr(handle, GCLP_HICONSM, (LONG_PTR) icon);
#line 2431 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_DestroyIcon); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_DestroyIcon)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "icon");
    {
	HICON	icon;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            icon = INT2PTR(HICON,SvIV(*out));
        else
            icon = NULL;
    } else
       icon = INT2PTR(HICON,SvIV(ST(0)))
;
#line 1838 "GUI.xs"
    RETVAL = DestroyIcon(icon);
#line 2461 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetClassName); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetClassName)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 1849 "GUI.xs"
    LPTSTR lpClassName;
    int nMaxCount;
#line 2482 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 1852 "GUI.xs"
    nMaxCount = 256;
    lpClassName = (LPTSTR) safemalloc(nMaxCount);
    if(GetClassName(handle, lpClassName, nMaxCount) > 0) {
        EXTEND(SP, 1);
        XST_mPV(0, lpClassName);
        safefree(lpClassName);
        XSRETURN(1);
    } else {
        safefree(lpClassName);
        XSRETURN_NO;
    }
#line 2505 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_GetParent); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetParent)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 1872 "GUI.xs"
  HWND parentHandle;
  SV* SvParent;
#line 2525 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 1875 "GUI.xs"
  parentHandle=GetParent(handle);
  if (parentHandle!=NULL) {
    SvParent = SV_SELF_FROM_WINDOW(parentHandle);
    if (SvParent != NULL && SvROK(SvParent)) {
      XPUSHs(SvParent);
    }
    else {
      XSRETURN_UNDEF;
    }
  } 
  else {
    XSRETURN_UNDEF;
  }
#line 2550 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_GetWindowObject); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetWindowObject)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 1898 "GUI.xs"
  SV* SvObject;
#line 2569 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 1900 "GUI.xs"
  if (IsWindow(handle)) {
    SvObject = SV_SELF_FROM_WINDOW(handle);
    if (SvObject != NULL && SvROK(SvObject)) {
      XPUSHs(SvObject);
    }
    else {
      XSRETURN_UNDEF;
    }
  } 
  else {
    XSRETURN_UNDEF;
  }
#line 2593 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI__UserData); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI__UserData)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
#line 1921 "GUI.xs"
    LPPERLWIN32GUI_USERDATA perlud;
#line 2610 "GUI.c"
	HV *	RETVAL;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 1923 "GUI.xs"
    perlud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr(handle, GWLP_USERDATA);
    if( ! ValidUserData(perlud) ) {
        XSRETURN_UNDEF;
    }

    if(perlud->userData == NULL)
        perlud->userData = (SV*)newHV();

    RETVAL = (HV*)perlud->userData;
#line 2632 "GUI.c"
	{
	    SV * RETVALSV;
	    RETVALSV = newRV((SV*)RETVAL);
	    RETVALSV = sv_2mortal(RETVALSV);
	    ST(0) = RETVALSV;
	}
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_FindWindow); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_FindWindow)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "classname, windowname");
    {
	LPCTSTR	classname = (LPCTSTR)SvPV_nolen(ST(0))
;
	LPCTSTR	windowname = (LPCTSTR)SvPV_nolen(ST(1))
;
	HWND	RETVAL;
	dXSTARG;
#line 1947 "GUI.xs"
    if(strlen(classname) == 0) classname = NULL;
    if(strlen(windowname) == 0) windowname = NULL;
    RETVAL = FindWindow(classname, windowname);
#line 2661 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetWindowLong); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetWindowLong)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, index");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
	int	index = (int)SvIV(ST(1))
;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 1963 "GUI.xs"
    XSRETURN_IV(PTR2IV(GetWindowLongPtr(handle, index)));
#line 2693 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_SetWindowLong); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetWindowLong)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "handle, index, value");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
	int	index = (int)SvIV(ST(1))
;
	LONG_PTR	value = INT2PTR(LONG_PTR,SvIV(ST(2)))
;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 1975 "GUI.xs"
    XSRETURN_IV(PTR2IV(SetWindowLongPtr(handle, index, value)));
#line 2726 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_SetWindowPos); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetWindowPos)
{
    dVAR; dXSARGS;
    if (items != 7)
       croak_xs_usage(cv,  "handle, insertafter, X, Y, cx, cy, flags");
    {
	HWND	handle;
	HWND	insertafter;
	int	X = (int)SvIV(ST(2))
;
	int	Y = (int)SvIV(ST(3))
;
	int	cx = (int)SvIV(ST(4))
;
	int	cy = (int)SvIV(ST(5))
;
	int	flags = (int)SvIV(ST(6))
;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

    if(SvROK(ST(1))) {
        SV** out=hv_fetch((HV*)SvRV(ST(1)), "-handle", 7, 0);
        if(out != NULL)
            insertafter = INT2PTR(HWND,SvIV(*out));
        else
            insertafter = NULL;
    } else
       insertafter = INT2PTR(HWND,SvIV(ST(1)))
;
#line 2015 "GUI.xs"
    RETVAL = SetWindowPos(handle, insertafter, X, Y, cx, cy, flags);
#line 2776 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetWindow); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetWindow)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, command");
    {
	HWND	handle;
	UINT	command = (UINT)SvUV(ST(1))
;
	HWND	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2040 "GUI.xs"
    RETVAL = GetWindow(handle, command);
#line 2808 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_Show); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Show)
{
    dVAR; dXSARGS;
    if (items < 1 || items > 2)
       croak_xs_usage(cv,  "handle, command=SW_SHOWNORMAL");
    {
	HWND	handle;
	int	command;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

	if (items < 2)
	    command = SW_SHOWNORMAL;
	else {
	    command = (int)SvIV(ST(1))
;
	}
#line 2072 "GUI.xs"
    RETVAL = ShowWindow(handle, command);
#line 2846 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI__Animate); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI__Animate)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "handle, time, flags");
    {
	HWND	handle;
	DWORD	time = (DWORD)SvUV(ST(1))
;
	DWORD	flags = (DWORD)SvUV(ST(2))
;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2087 "GUI.xs"
    RETVAL = AnimateWindow(handle, time, flags);
#line 2880 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_Hide); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Hide)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2099 "GUI.xs"
    RETVAL = ShowWindow(handle, SW_HIDE);
#line 2910 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_Maximize); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Maximize)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2111 "GUI.xs"
    RETVAL = ShowWindow(handle, SW_SHOWMAXIMIZED);
#line 2940 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_SetWindowRgn); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetWindowRgn)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 3)
       croak_xs_usage(cv,  "handle, region, flag=1");
    {
	HWND	handle;
	HRGN	region;
	BOOL	flag;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

    if(SvROK(ST(1))) {
        SV** out=hv_fetch((HV*)SvRV(ST(1)), "-handle", 7, 0);
        if(out != NULL)
            region = INT2PTR(HRGN,SvIV(*out));
        else
            region = NULL;
    } else
       region = INT2PTR(HRGN,SvIV(ST(1)))
;

	if (items < 3)
	    flag = 1;
	else {
	    flag = (BOOL)SvIV(ST(2))
;
	}
#line 2130 "GUI.xs"
    RETVAL = SetWindowRgn(handle, region, flag);
#line 2989 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_Update); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Update)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2144 "GUI.xs"
    RETVAL = UpdateWindow(handle);
#line 3019 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_Redraw); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Redraw)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "handle, ...");
    {
	HWND	handle;
#line 2158 "GUI.xs"
    RECT rect;
    LPRECT lpRect;
    UINT flags;
#line 3039 "GUI.c"
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2162 "GUI.xs"
    if(items != 2 && items != 6) {
        CROAK("Usage: Redraw(handle, flag);\n   or: Redraw(handle, left, top, right, bottom, flag);\n");
    }
    if(items == 2) {
        lpRect = (LPRECT) NULL;
        flags = (UINT) SvIV(ST(1));
    }
    else {
        rect.left = (LONG)SvIV(ST(1));
        rect.top = (LONG)SvIV(ST(2));
        rect.right = (LONG)SvIV(ST(3));
        rect.bottom = (LONG)SvIV(ST(4));
        flags = (UINT) SvIV(ST(5));
        lpRect = &rect;
    }
    RETVAL = RedrawWindow(handle,lpRect, (HRGN) NULL, flags);
#line 3069 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_LockWindowUpdate); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_LockWindowUpdate)
{
    dVAR; dXSARGS;
    if (items < 1 || items > 2)
       croak_xs_usage(cv,  "handle, flag=0");
    {
	HWND	handle;
	int	flag;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

	if (items < 2)
	    flag = 0;
	else {
	    flag = (int)SvIV(ST(1))
;
	}
#line 2198 "GUI.xs"
    RETVAL = LockWindowUpdate(flag == 0 ? handle : NULL);
#line 3107 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_InvalidateRect); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_InvalidateRect)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "handle, ...");
    {
	HWND	handle;
#line 2217 "GUI.xs"
    RECT rect;
    LPRECT lpRect;
    BOOL bErase;
#line 3127 "GUI.c"
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2221 "GUI.xs"
    if(items != 2 && items && items != 6) {
        CROAK("Usage: InvalidateRect(handle, flag);\n   or: InvalidateRect(handle, left, top, right, bottom, [flag]);\n");
    }
    if(items == 2) {
        lpRect = (LPRECT) NULL;
        bErase = (BOOL) SvIV(ST(1));
    } else {
        rect.left   = (LONG)SvIV(ST(1));
        rect.top    = (LONG)SvIV(ST(2));
        rect.right  = (LONG)SvIV(ST(3));
        rect.bottom = (LONG)SvIV(ST(4));
        if(items == 5)
            bErase      = TRUE;
        else
            bErase      = (BOOL) SvIV(ST(5));
        lpRect      = &rect;
    }
    RETVAL = InvalidateRect(handle, lpRect, bErase);
#line 3159 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_DestroyWindow); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_DestroyWindow)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2249 "GUI.xs"
    RETVAL = DestroyWindow(handle);
#line 3189 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetMessage); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetMessage)
{
    dVAR; dXSARGS;
    if (items < 1 || items > 3)
       croak_xs_usage(cv,  "handle, min=0, max=0");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
	UINT	min;
	UINT	max;
#line 2278 "GUI.xs"
    MSG msg;
    BOOL result;
#line 3212 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

	if (items < 2)
	    min = 0;
	else {
	    min = (UINT)SvUV(ST(1))
;
	}

	if (items < 3)
	    max = 0;
	else {
	    max = (UINT)SvUV(ST(2))
;
	}
#line 2281 "GUI.xs"
    result = GetMessage(&msg, handle, min, max);
    if(result == -1) {
        XSRETURN_UNDEF;
    } else {
        EXTEND(SP, 7);
        XST_mIV(0, result);
        XST_mIV(1, msg.message);
        XST_mIV(2, msg.wParam);
        XST_mIV(3, msg.lParam);
        XST_mIV(4, msg.time);
        XST_mIV(5, msg.pt.x);
        XST_mIV(6, msg.pt.y);
        XSRETURN(7);
    }
#line 3252 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_SendMessage); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SendMessage)
{
    dVAR; dXSARGS;
    if (items != 4)
       croak_xs_usage(cv,  "handle, msg, wparam, lparam");
    {
	HWND	handle;
	UINT	msg = (UINT)SvUV(ST(1))
;
	WPARAM	wparam = (WPARAM)SvUV(ST(2))
;
	LPARAM	lparam;
	LRESULT	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

    if(SvPOK(ST(3)))
      lparam = (LPARAM) SvPV_nolen(ST(3));
    else
      lparam = (LPARAM) SvIV(ST(3))
;
#line 2307 "GUI.xs"
    RETVAL = SendMessage(handle, msg, wparam, lparam);
#line 3292 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_PostMessage); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_PostMessage)
{
    dVAR; dXSARGS;
    if (items != 4)
       croak_xs_usage(cv,  "handle, msg, wparam, lparam");
    {
	HWND	handle;
	UINT	msg = (UINT)SvUV(ST(1))
;
	WPARAM	wparam = (WPARAM)SvUV(ST(2))
;
	LPARAM	lparam;
	LRESULT	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

    if(SvPOK(ST(3)))
      lparam = (LPARAM) SvPV_nolen(ST(3));
    else
      lparam = (LPARAM) SvIV(ST(3))
;
#line 2321 "GUI.xs"
    RETVAL = PostMessage(handle, msg, wparam, lparam);
#line 3333 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_WaitMessage); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_WaitMessage)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    {
	BOOL	RETVAL;
	dXSTARG;
#line 2334 "GUI.xs"
  RETVAL = WaitMessage();
#line 3352 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_SendMessageTimeout); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SendMessageTimeout)
{
    dVAR; dXSARGS;
    if (items < 5 || items > 6)
       croak_xs_usage(cv,  "handle, msg, wparam, lparam, flags=SMTO_NORMAL, timeout");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
	UINT	msg = (UINT)SvUV(ST(1))
;
	WPARAM	wparam = (WPARAM)SvUV(ST(2))
;
	LPARAM	lparam;
	UINT	flags;
	UINT	timeout = (UINT)SvUV(ST(5))
;
#line 2364 "GUI.xs"
    PDWORD result;
#line 3380 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

    if(SvPOK(ST(3)))
      lparam = (LPARAM) SvPV_nolen(ST(3));
    else
      lparam = (LPARAM) SvIV(ST(3))
;

	if (items < 5)
	    flags = SMTO_NORMAL;
	else {
	    flags = (UINT)SvUV(ST(4))
;
	}
#line 2366 "GUI.xs"
    if(SendMessageTimeout(handle, msg, wparam, lparam, flags, timeout, (PDWORD_PTR)&result) == 0) {
        XSRETURN_UNDEF;
    } else {
        XSRETURN_IV((IV)result);
    }
#line 3410 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_PostQuitMessage); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_PostQuitMessage)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 2380 "GUI.xs"
    int exitcode;
    if(items > 0)
        exitcode = (int)SvIV(ST(items-1));
    else
        exitcode = 0;
    PostQuitMessage(exitcode);
#line 3433 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_PeekMessage); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_PeekMessage)
{
    dVAR; dXSARGS;
    if (items < 1 || items > 4)
       croak_xs_usage(cv,  "handle, min=0, max=0, message=&PL_sv_undef");
    {
	HWND	handle;
	UINT	min;
	UINT	max;
	SV*	message;
#line 2412 "GUI.xs"
    MSG msg;
#line 3453 "GUI.c"
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

	if (items < 2)
	    min = 0;
	else {
	    min = (UINT)SvUV(ST(1))
;
	}

	if (items < 3)
	    max = 0;
	else {
	    max = (UINT)SvUV(ST(2))
;
	}

	if (items < 4)
	    message = &PL_sv_undef;
	else {
	    message = ST(3)
;
	}
#line 2414 "GUI.xs"
    ZeroMemory(&msg, sizeof(msg));
    RETVAL = PeekMessage(&msg, handle, min, max, PM_NOREMOVE);
    if(message != &PL_sv_undef) {
        if(SvROK(message) && SvTYPE(SvRV(message)) == SVt_PVAV) {
            av_clear((AV*) SvRV(message));
            av_push((AV*) SvRV(message), newSViv(PTR2IV(msg.hwnd)));
            av_push((AV*) SvRV(message), newSViv(msg.message));
            av_push((AV*) SvRV(message), newSViv(msg.wParam));
            av_push((AV*) SvRV(message), newSViv(msg.lParam));
            av_push((AV*) SvRV(message), newSViv(msg.time));
            av_push((AV*) SvRV(message), newSViv(msg.pt.x));
            av_push((AV*) SvRV(message), newSViv(msg.pt.y));
        } else {
            W32G_WARN("Win32::GUI: fourth parameter to PeekMessage is not an array reference");
        }
    }
#line 3504 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_Hook); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Hook)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "handle, msg, coderef");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
	I32	msg = (I32)SvIV(ST(1))
;
	SV*	coderef = ST(2)
;
#line 2488 "GUI.xs"
    LPPERLWIN32GUI_USERDATA perlud;
    SV** arrayref;
    AV* newarray;
    int i;
    SV** value;
#line 3532 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2494 "GUI.xs"
    if(msg < 0) { msg = 0 - msg; }; // Looks wrong but if hooks are used correctly this should be OK.
    if(SvOK(coderef) && SvROK(coderef) && SvTYPE(SvRV(coderef)) == SVt_PVCV) {
        // We have a code reference.
        perlud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr(handle, GWLP_USERDATA);
        if(perlud->avHooks == NULL) {
            perlud->avHooks = newAV();
        }

        // Check if array value for this message exists already:
        arrayref = av_fetch(perlud->avHooks, msg, 0);
        if(arrayref == NULL) {
            // No array reference for this msg yet, so make one and insert our
            // handler ref:
            newarray = newAV();
            av_push(newarray, coderef);
            SvREFCNT_inc(coderef);
            if(av_store(perlud->avHooks, msg, newRV_noinc((SV*) newarray)) == NULL) {
                SvREFCNT_dec((SV*) newarray);
                CROAK("AddHook failed to store new array reference.\n");
                XSRETURN_NO;
            }
        }
        else {
            // There IS an array reference already, so add the handler.
            // First, check the handler isn't already there:
            for(i = 0; i <= (int) av_len((AV*) SvRV(*arrayref)); i++) {
                value = av_fetch((AV*) SvRV(*arrayref), i,0);
                if(sv_eq(*value,coderef)) {
                    XSRETURN_NO;
                }
            }
            // Add the coderef:
            av_push((AV*) SvRV(*arrayref), coderef);
            SvREFCNT_inc(coderef);
        }
        XSRETURN_YES;
    }
    else {
        CROAK("Usage: Hook(message, coderef)\n");
        XSRETURN_NO;
    }
#line 3585 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_UnHook); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_UnHook)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 3)
       croak_xs_usage(cv,  "handle, msg, coderef = NULL");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
	I32	msg = (I32)SvIV(ST(1))
;
	SV*	coderef;
#line 2554 "GUI.xs"
    LPPERLWIN32GUI_USERDATA perlud;
    SV** arrayref;
    SV** removedvalue;
    int i;
    int count = 0;
#line 3611 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

	if (items < 3)
	    coderef = NULL;
	else {
	    coderef = ST(2)
;
	}
#line 2560 "GUI.xs"
    if(msg < 0) { msg = 0 - msg; };
    if(coderef != NULL && !(SvOK(coderef) && SvROK(coderef) && SvTYPE(SvRV(coderef)) == SVt_PVCV)) {
        CROAK("Usage: UnHook(message,[coderef]). What you gave as a coderef was not a code reference\n");
        XSRETURN_NO;
    }
    else {
    perlud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr(handle, GWLP_USERDATA);
        if(perlud->avHooks == NULL) {
            XSRETURN_NO;
        }
        else {
            arrayref = av_fetch(perlud->avHooks, msg, 0);
            if(arrayref == NULL) {
            XSRETURN_NO;
        }
            else {
                for(i = 0; i <= (int) av_len((AV*) SvRV(*arrayref)); i++) {
                    removedvalue = av_fetch((AV*) SvRV(*arrayref), i,0);
                    if(removedvalue != NULL && (coderef == NULL || sv_eq(*removedvalue,coderef)) ) {
                        /* SvREFCNT_dec(*removedvalue);
                        av_delete((AV*) SvRV(*arrayref), i, 0); */
                        av_delete((AV*) SvRV(*arrayref), i, G_DISCARD);
                        count++;
                    }
                }
                if(coderef == NULL || av_len((AV*) SvRV(*arrayref)) == -1) {
                    removedvalue = av_fetch(perlud->avHooks, msg, 0);
                    /* SvREFCNT_dec(*removedvalue);
                    av_delete(perlud->avHooks, msg, 0); */
                    av_delete(perlud->avHooks, msg, G_DISCARD);
                }
                XSRETURN_IV(count);
            }
        }
    }
#line 3665 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_Result); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Result)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, result");
    {
	HWND	handle;
	int	result = (int)SvIV(ST(1))
;
#line 2609 "GUI.xs"
    LPPERLWIN32GUI_USERDATA perlud;
#line 3684 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2611 "GUI.xs"
    perlud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr(handle, GWLP_USERDATA);
    if(ValidUserData(perlud)) {
        perlud->forceResult = (LRESULT) result;
        XSRETURN_YES;
    }
    else
        XSRETURN_NO;
#line 3703 "GUI.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Win32__GUI_SetFont); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetFont)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, font");
    {
	HWND	handle;
	HFONT	font;
	LRESULT	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

    if(SvROK(ST(1))) {
        SV** out=hv_fetch((HV*)SvRV(ST(1)), "-handle", 7, 0);
        if(out != NULL)
            font = INT2PTR(HFONT,SvIV(*out));
        else
            font = NULL;
    } else
       font = INT2PTR(HFONT,SvIV(ST(1)))
;
#line 2629 "GUI.xs"
    RETVAL = SendMessage(handle, WM_SETFONT, (WPARAM) font, 0);
#line 3742 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetFont); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetFont)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	LRESULT	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2645 "GUI.xs"
    RETVAL = SendMessage(handle, WM_GETFONT, 0, 0);
#line 3772 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_SetRedraw); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetRedraw)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, value");
    {
	HWND	handle;
	WPARAM	value = (WPARAM)SvUV(ST(1))
;
	LRESULT	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2661 "GUI.xs"
    RETVAL = SendMessage(handle, WM_SETREDRAW, value, 0);
#line 3804 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_SetIcon); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetIcon)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 3)
       croak_xs_usage(cv,  "handle, icon, type=ICON_SMALL");
    {
	HWND	handle;
	HICON	icon;
	WPARAM	type;
	LRESULT	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

    if(SvROK(ST(1))) {
        SV** out=hv_fetch((HV*)SvRV(ST(1)), "-handle", 7, 0);
        if(out != NULL)
            icon = INT2PTR(HICON,SvIV(*out));
        else
            icon = NULL;
    } else
       icon = INT2PTR(HICON,SvIV(ST(1)))
;

	if (items < 3)
	    type = ICON_SMALL;
	else {
	    type = (WPARAM)SvUV(ST(2))
;
	}
#line 2676 "GUI.xs"
    if (items > 2)
        RETVAL = SendMessage(handle, WM_SETICON, type, (LPARAM) icon);
    else {
        SendMessage(handle, WM_SETICON, ICON_SMALL, (LPARAM) icon);
        RETVAL = SendMessage(handle, WM_SETICON, ICON_BIG, (LPARAM) icon);
    }
#line 3858 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_Text); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Text)
{
    dVAR; dXSARGS;
    dXSI32;
    if (items < 1)
       croak_xs_usage(cv,  "handle, ...");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 2698 "GUI.xs"
    char *myBuffer;
    int myLength;
#line 3880 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2701 "GUI.xs"
    if(items > 2) {
        CROAK("Usage: Text(handle, [value]);\n");
    }
    if(items == 1) {
        myLength = GetWindowTextLength(handle)+1;
        if(myLength) {
            myBuffer = (char *) safemalloc(myLength);
            if(GetWindowText(handle, myBuffer, myLength)) {
                EXTEND(SP, 1);
                XST_mPV(0, myBuffer);
                safefree(myBuffer);
                XSRETURN(1);
            }
            safefree(myBuffer);
        }
        XSRETURN_NO;
    } else {
        XSRETURN_IV((IV) SetWindowText(handle, (LPCTSTR) SvPV_nolen(ST(1))));
    }
#line 3911 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_Move); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Move)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "handle, x, y");
    {
	HWND	handle;
	int	x = (int)SvIV(ST(1))
;
	int	y = (int)SvIV(ST(2))
;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2731 "GUI.xs"
    RETVAL = SetWindowPos(handle, (HWND) NULL, x, y, 0, 0,
                          SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOSIZE);
#line 3945 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_Resize); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Resize)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "handle, x, y");
    {
	HWND	handle;
	int	x = (int)SvIV(ST(1))
;
	int	y = (int)SvIV(ST(2))
;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2746 "GUI.xs"
    RETVAL = SetWindowPos(handle, (HWND) NULL, 0, 0, x, y,
                          SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE);
#line 3980 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetClientRect); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetClientRect)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 2762 "GUI.xs"
    RECT myRect;
#line 4000 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2764 "GUI.xs"
    if(GetClientRect(handle, &myRect)) {
        EXTEND(SP, 4);
        XST_mIV(0, myRect.left);
        XST_mIV(1, myRect.top);
        XST_mIV(2, myRect.right);
        XST_mIV(3, myRect.bottom);
        XSRETURN(4);
    } else {
        XSRETURN_UNDEF;
    }
#line 4022 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_GetAbsClientRect); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetAbsClientRect)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 2783 "GUI.xs"
    WINDOWINFO pwi;
#line 4041 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2785 "GUI.xs"
    pwi.cbSize = sizeof(WINDOWINFO);
    if(GetWindowInfo(handle, &pwi)) {
        EXTEND(SP, 4);
        XST_mIV(0, pwi.rcClient.left);
        XST_mIV(1, pwi.rcClient.top);
        XST_mIV(2, pwi.rcClient.right);
        XST_mIV(3, pwi.rcClient.bottom);
        XSRETURN(4);
    }
    else {
        XSRETURN_UNDEF;
    }
#line 4065 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_GetWindowRect); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetWindowRect)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 2806 "GUI.xs"
    RECT myRect;
#line 4084 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2808 "GUI.xs"
    if(GetWindowRect(handle, &myRect)) {
        EXTEND(SP, 4);
        XST_mIV(0, myRect.left);
        XST_mIV(1, myRect.top);
        XST_mIV(2, myRect.right);
        XST_mIV(3, myRect.bottom);
        XSRETURN(4);
    } else {
        XSRETURN_UNDEF;
    }
#line 4106 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_Width); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Width)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "handle, ...");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 2829 "GUI.xs"
    RECT myRect;
#line 4125 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2831 "GUI.xs"
    if(items > 2) {
        croak("Usage: Width(handle, [value]);\n");
    }

    if(!GetWindowRect(handle, &myRect)) XSRETURN_NO;

    if(items == 1) {
        EXTEND(SP, 1);
        XST_mIV(0, (myRect.right-myRect.left));
        XSRETURN(1);
    } else {
        if(SetWindowPos(handle, (HWND) NULL, 0, 0,
                        (int) SvIV(ST(1)),
                        (int) (myRect.bottom-myRect.top),
                        SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_DEFERERASE)) {
            XSRETURN_YES;
        } else {
            XSRETURN_NO;
        }
    }
#line 4157 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_Height); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Height)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "handle, ...");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 2862 "GUI.xs"
    RECT myRect;
#line 4176 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2864 "GUI.xs"
    if(items > 2) {
        croak("Usage: Height(handle, [value]);\n");
    }

    if(!GetWindowRect(handle, &myRect)) XSRETURN_NO;

    if(items == 1) {
        EXTEND(SP, 1);
        XST_mIV(0, (myRect.bottom-myRect.top));
        XSRETURN(1);
    } else {
        if(SetWindowPos(handle, (HWND) NULL, 0, 0,
                        (int) (myRect.right-myRect.left),
                        (int) SvIV(ST(1)),
                        SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_DEFERERASE)) {
            XSRETURN_YES;
        } else {
            XSRETURN_NO;
        }
    }
#line 4208 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_Left); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Left)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "handle, ...");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 2897 "GUI.xs"
    RECT myRect;
    HWND parent;
    POINT myPt;
#line 4229 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2901 "GUI.xs"
    if(items > 2) {
        croak("Usage: Left(handle, [value]);\n");
    }
    if(!GetWindowRect(handle, &myRect)) XSRETURN_NO;
    myPt.x = myRect.left;
    myPt.y = myRect.top;

    parent = GetParent(handle);
    if (parent && IsChild(parent, handle)) ScreenToClient(parent, &myPt);

    if(items == 1) {
        EXTEND(SP, 1);
        XST_mIV(0, myPt.x);
        XSRETURN(1);
    } else {
        if(SetWindowPos(
            handle, (HWND) NULL,
            (int) SvIV(ST(1)), (int) myPt.y,
            0, 0,
            SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_DEFERERASE
        )) {
            XSRETURN_YES;
        } else {
            XSRETURN_NO;
        }
    }
#line 4267 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_Top); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Top)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "handle, ...");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 2940 "GUI.xs"
    RECT myRect;
    HWND parent;
    POINT myPt;
#line 4288 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2944 "GUI.xs"
    if(items > 2) {
        croak("Usage: Top(handle, [value]);\n");
    }
    if(!GetWindowRect(handle, &myRect)) XSRETURN_NO;
    myPt.x = myRect.left;
    myPt.y = myRect.top;

    parent = GetParent(handle);
    if (parent && IsChild(parent, handle)) ScreenToClient(parent, &myPt);

    if(items == 1) {
        EXTEND(SP, 1);
        XST_mIV(0, myPt.y);
        XSRETURN(1);
    } else {
        if(SetWindowPos(
            handle, (HWND) NULL,
            (int) myPt.x, (int) SvIV(ST(1)),
            0, 0,
            SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_DEFERERASE
        )) {
            XSRETURN_YES;
        } else {
            XSRETURN_NO;
        }
    }
#line 4326 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_AbsLeft); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_AbsLeft)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "handle, ...");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 2981 "GUI.xs"
    RECT myRect;
    HWND parent;
#line 4346 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 2984 "GUI.xs"
    if(!GetWindowRect(handle, &myRect)) {
        XSRETURN_UNDEF;
    }

    /* Set */
    if(items > 1) {
        myRect.left = (LONG)SvIV(ST(1));

        /* If we're a child window convert to parent's client co-ordinates */
        if(parent = GetAncestor(handle, GA_PARENT)) {
            ScreenToClient(parent, (LPPOINT)&myRect);
        }

        if(SetWindowPos(handle, NULL, (int)myRect.left, (int)myRect.top,
                         0, 0, SWP_NOZORDER | SWP_NOSIZE)) {
            XSRETURN_YES;
        }
        else {
            XSRETURN_NO;
        }
    }

    /* Get */
    EXTEND(SP, 1);
    XST_mIV(0, myRect.left);
    XSRETURN(1);
#line 4384 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_AbsTop); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_AbsTop)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "handle, ...");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 3021 "GUI.xs"
    RECT myRect;
    HWND parent;
#line 4404 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3024 "GUI.xs"
    if(!GetWindowRect(handle, &myRect)) {
        XSRETURN_UNDEF;
    }

    /* Set */
    if(items > 1) {
        myRect.top = (LONG)SvIV(ST(1));

        /* If we're a child window convert to parent's client co-ordinates */
        if(parent = GetAncestor(handle, GA_PARENT)) {
            ScreenToClient(parent, (LPPOINT)&myRect);
        }

        if(SetWindowPos(handle, NULL, (int)myRect.left, (int)myRect.top,
                         0, 0, SWP_NOZORDER | SWP_NOSIZE)) {
            XSRETURN_YES;
        }
        else {
            XSRETURN_NO;
        }
    }

    /* Get */
    EXTEND(SP, 1);
    XST_mIV(0, myRect.top);
    XSRETURN(1);
#line 4442 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_ScreenToClient); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_ScreenToClient)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "handle, x, y");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
	int	x = (int)SvIV(ST(1))
;
	int	y = (int)SvIV(ST(2))
;
#line 3060 "GUI.xs"
    POINT myPt;
#line 4465 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3062 "GUI.xs"
    myPt.x = x;
    myPt.y = y;
    ScreenToClient(handle, &myPt);
    EXTEND(SP, 2);
    XST_mIV(0, myPt.x);
    XST_mIV(1, myPt.y);
    XSRETURN(2);
#line 4484 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_ClientToScreen); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_ClientToScreen)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "handle, x, y");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
	int	x = (int)SvIV(ST(1))
;
	int	y = (int)SvIV(ST(2))
;
#line 3080 "GUI.xs"
    POINT myPt;
#line 4507 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3082 "GUI.xs"
    myPt.x = x;
    myPt.y = y;
    ClientToScreen(handle, &myPt);
    EXTEND(SP, 2);
    XST_mIV(0, myPt.x);
    XST_mIV(1, myPt.y);
    XSRETURN(2);
#line 4526 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_ScaleWidth); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_ScaleWidth)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
#line 3097 "GUI.xs"
    RECT myRect;
#line 4543 "GUI.c"
	DWORD	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3099 "GUI.xs"
    if(GetClientRect(handle, &myRect)) {
        RETVAL = myRect.right;
    } else {
        RETVAL = 0;
    }
#line 4562 "GUI.c"
	XSprePUSH;
	PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_ScaleHeight); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_ScaleHeight)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
#line 3115 "GUI.xs"
    RECT myRect;
#line 4580 "GUI.c"
	DWORD	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3117 "GUI.xs"
    if(GetClientRect(handle, &myRect)) {
        RETVAL = myRect.bottom;
    } else {
        RETVAL = 0;
    }
#line 4599 "GUI.c"
	XSprePUSH;
	PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_BringWindowToTop); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_BringWindowToTop)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3136 "GUI.xs"
    RETVAL = BringWindowToTop(handle);
#line 4629 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_ArrangeIconicWindows); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_ArrangeIconicWindows)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	UINT	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3148 "GUI.xs"
    RETVAL = ArrangeIconicWindows(handle);
#line 4659 "GUI.c"
	XSprePUSH;
	PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetDesktopWindow); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetDesktopWindow)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    {
	HWND	RETVAL;
	dXSTARG;
#line 3159 "GUI.xs"
   RETVAL = GetDesktopWindow();
#line 4678 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetForegroundWindow); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetForegroundWindow)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    {
	HWND	RETVAL;
	dXSTARG;
#line 3170 "GUI.xs"
   RETVAL = GetForegroundWindow();
#line 4697 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_SetForegroundWindow); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetForegroundWindow)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3182 "GUI.xs"
    RETVAL = SetForegroundWindow(handle);
#line 4727 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_IsZoomed); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_IsZoomed)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3194 "GUI.xs"
    RETVAL = IsZoomed(handle);
#line 4757 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_IsIconic); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_IsIconic)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3206 "GUI.xs"
    RETVAL = IsIconic(handle);
#line 4787 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_IsWindow); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_IsWindow)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3218 "GUI.xs"
    RETVAL = IsWindow(handle);
#line 4817 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_IsVisible); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_IsVisible)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3230 "GUI.xs"
    RETVAL = IsWindowVisible(handle);
#line 4847 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_IsEnabled); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_IsEnabled)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3242 "GUI.xs"
    RETVAL = IsWindowEnabled(handle);
#line 4877 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_Enable); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Enable)
{
    dVAR; dXSARGS;
    if (items < 1 || items > 2)
       croak_xs_usage(cv,  "handle, flag=TRUE");
    {
	HWND	handle;
	BOOL	flag;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

	if (items < 2)
	    flag = TRUE;
	else {
	    flag = (BOOL)SvIV(ST(1))
;
	}
#line 3261 "GUI.xs"
    RETVAL = EnableWindow(handle, flag);
#line 4915 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_Disable); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Disable)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3277 "GUI.xs"
    RETVAL = EnableWindow(handle, FALSE);
#line 4945 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_OpenIcon); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_OpenIcon)
{
    dVAR; dXSARGS;
    dXSI32;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3292 "GUI.xs"
    RETVAL = OpenIcon(handle);
#line 4976 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_CloseWindow); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_CloseWindow)
{
    dVAR; dXSARGS;
    dXSI32;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3307 "GUI.xs"
    RETVAL = CloseWindow(handle);
#line 5007 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_WindowFromPoint); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_WindowFromPoint)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "x, y");
    {
	LONG	x = (LONG)SvIV(ST(0))
;
	LONG	y = (LONG)SvIV(ST(1))
;
#line 3320 "GUI.xs"
    POINT myPoint;
#line 5028 "GUI.c"
	HWND	RETVAL;
	dXSTARG;
#line 3322 "GUI.xs"
    myPoint.x = x;
    myPoint.y = y;
    RETVAL = WindowFromPoint(myPoint);
#line 5035 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetTopWindow); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetTopWindow)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	HWND	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3336 "GUI.xs"
    RETVAL = GetTopWindow(handle);
#line 5065 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetActiveWindow); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetActiveWindow)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    {
	HWND	RETVAL;
	dXSTARG;
#line 3347 "GUI.xs"
    RETVAL = GetActiveWindow();
#line 5084 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_SetActiveWindow); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetActiveWindow)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	HWND	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3359 "GUI.xs"
    RETVAL = SetActiveWindow(handle);
#line 5114 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetDlgItem); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetDlgItem)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, identifier");
    {
	HWND	handle;
	int	identifier = (int)SvIV(ST(1))
;
	HWND	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3371 "GUI.xs"
    RETVAL = GetDlgItem(handle, identifier);
#line 5146 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetFocus); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetFocus)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    {
	HWND	RETVAL;
	dXSTARG;
#line 3382 "GUI.xs"
    RETVAL = GetFocus();
#line 5165 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_SetFocus); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetFocus)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	HWND	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3394 "GUI.xs"
    RETVAL = SetFocus(handle);
#line 5195 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_SetCapture); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetCapture)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	HWND	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3406 "GUI.xs"
    RETVAL = SetCapture(handle);
#line 5225 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetCapture); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetCapture)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    {
	HWND	RETVAL;
	dXSTARG;
#line 3418 "GUI.xs"
    RETVAL = GetCapture();
#line 5244 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_ReleaseCapture); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_ReleaseCapture)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    {
	BOOL	RETVAL;
	dXSTARG;
#line 3428 "GUI.xs"
    RETVAL = ReleaseCapture();
#line 5263 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_ShellExecute); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_ShellExecute)
{
    dVAR; dXSARGS;
    if (items != 6)
       croak_xs_usage(cv,  "window, operation, file, parameters, directory, showcmd");
    {
	HWND	window;
	LPCTSTR	operation = (LPCTSTR)SvPV_nolen(ST(1))
;
	LPCTSTR	file = (LPCTSTR)SvPV_nolen(ST(2))
;
	LPCTSTR	parameters = (LPCTSTR)SvPV_nolen(ST(3))
;
	LPCTSTR	directory = (LPCTSTR)SvPV_nolen(ST(4))
;
	INT	showcmd = (INT)SvIV(ST(5))
;
#line 3522 "GUI.xs"
    char buffer[MAX_PATH+1];
    int i;
#line 5292 "GUI.c"
	IV	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            window = INT2PTR(HWND,SvIV(*out));
        else
            window = NULL;
    } else
       window = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3525 "GUI.xs"
#ifdef __CYGWIN__
    /* Under Cygwin, convert paths to windows
     * paths. E.g. convert /usr/local... and /cygdrive/c/...
     */
#if CYGWIN_VERSION_API_MAJOR > 0 || CYGWIN_VERSION_API_MINOR >= 181
    i = cygwin_conv_path(CCP_POSIX_TO_WIN_A|CCP_RELATIVE,file,buffer,MAX_PATH+1);
    if (i < 0) XSRETURN_UNDEF;
#else
    /* old cygwin api */
    if(cygwin_conv_to_win32_path(file,buffer) != 0)
        XSRETURN_UNDEF;
#endif
#else
        /* ShellExecute on Win98 (at least) doesn't like unix
         * path seperators, so normalise to windows path seperators
         */
        for(i=0; *name && (i<MAX_PATH); ++name,++i) {
            buffer[i] = (*name == '/' ? '\\' : *name);
        }
        if(*name) {
            /* XXX Path too long - although this appears to be what
             * LoadImage would return with such a path, it might be
             * better to find a more specific error code.  E.g.
             * ENAMETOOLONG?
             */
            SetLastError(ERROR_FILE_NOT_FOUND);
            errno = ENOENT;
            XSRETURN_UNDEF;
        }
        buffer[i] = 0;
#endif
    RETVAL = (IV) ShellExecute(window,operation,buffer,parameters,directory,showcmd);
#line 5338 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetWindowThreadProcessId); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetWindowThreadProcessId)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 3568 "GUI.xs"
    DWORD tid;
    DWORD pid;
#line 5359 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3571 "GUI.xs"
    tid = GetWindowThreadProcessId(handle, &pid);
    EXTEND(SP, 2);
    XST_mIV(0, tid);
    XST_mIV(1, pid);
    XSRETURN(2);
#line 5376 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_AttachThreadInput); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_AttachThreadInput)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 3)
       croak_xs_usage(cv,  "from, to, flag=TRUE");
    {
	DWORD	from = (DWORD)SvUV(ST(0))
;
	DWORD	to = (DWORD)SvUV(ST(1))
;
	BOOL	flag;
	BOOL	RETVAL;
	dXSTARG;

	if (items < 3)
	    flag = TRUE;
	else {
	    flag = (BOOL)SvIV(ST(2))
;
	}
#line 3598 "GUI.xs"
    RETVAL = AttachThreadInput(from, to, flag);
#line 5406 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetTextExtentPoint32); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetTextExtentPoint32)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 3)
       croak_xs_usage(cv,  "handle, string, font=NULL");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
	char *	string = (char *)SvPV_nolen(ST(1))
;
	HFONT	font;
#line 3614 "GUI.xs"
    STRLEN cbString;
    char *szString;
    HDC hdc;
    SIZE mySize;
#line 5432 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

	if (items < 3)
	    font = NULL;
	else {
    if(SvROK(ST(2))) {
	SV** out=hv_fetch((HV*)SvRV(ST(2)), "-handle", 7, 0);
	if(out != NULL)
	    font = INT2PTR(HFONT,SvIV(*out));
	else
	    font = NULL;
    } else
       font = INT2PTR(HFONT,SvIV(ST(2)))
;
	}
#line 3619 "GUI.xs"
    szString = SvPV(ST(1), cbString);
    hdc = GetDC(handle);
#ifdef PERLWIN32GUI_DEBUG
    printf("XS(GetTextExtentPoint32).font=0x%x\n", font);
    printf("XS(GetTextExtentPoint32).string='%s'\n", string);
#endif
    if(font) SelectObject(hdc, (HGDIOBJ) font);
    if(GetTextExtentPoint32(hdc, szString, (int)cbString, &mySize)) {
        EXTEND(SP, 2);
        XST_mIV(0, mySize.cx);
        XST_mIV(1, mySize.cy);
        ReleaseDC(handle, hdc);
        XSRETURN(2);
    } else {
        ReleaseDC(handle, hdc);
        XSRETURN_UNDEF;
    }
#line 5475 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_TrackPopupMenu); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_TrackPopupMenu)
{
    dVAR; dXSARGS;
    if (items < 2)
       croak_xs_usage(cv,  "handle, hmenu, ...");
    {
	HWND	handle;
	HMENU	hmenu;
#line 3706 "GUI.xs"
    int x = 0;
    int y = 0;
    UINT flags = TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON;
    LPTPMPARAMS lptpm = (LPTPMPARAMS) NULL;
    TPMPARAMS tpm;
    SV* coderef = (SV*) NULL;
    HHOOK hhook = NULL;
    LPPERLWIN32GUI_USERDATA perlud;
    AV* newarray;
    POINT pt;
#line 5502 "GUI.c"
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

    if(SvROK(ST(1))) {
        SV** out=hv_fetch((HV*)SvRV(ST(1)), "-handle", 7, 0);
        if(out != NULL)
            hmenu = INT2PTR(HMENU,SvIV(*out));
        else
            hmenu = NULL;
    } else
       hmenu = INT2PTR(HMENU,SvIV(ST(1)))
;
#line 3718 "GUI.xs"
    switch (items) {
      case 10: coderef              = ST(9);
      case  9: flags                = (UINT)SvIV(ST(8));
      case  8: tpm.rcExclude.bottom = (LONG)SvIV(ST(7));
               tpm.rcExclude.right  = (LONG)SvIV(ST(6));
               tpm.rcExclude.top    = (LONG)SvIV(ST(5));
               tpm.rcExclude.left   = (LONG)SvIV(ST(4));
               tpm.cbSize           = sizeof(TPMPARAMS);
               y                    = (int)SvIV(ST(3));
               x                    = (int)SvIV(ST(2));
           break;

      case  6: coderef              = ST(5);
      case  5: flags                = (UINT)SvIV(ST(4));
      case  4: y                    = (int)SvIV(ST(3));
               x                    = (int)SvIV(ST(2));
           break;

      case  2: if(GetCursorPos(&pt)) {
               y                  = pt.y;
               x                  = pt.x;
             }
          break;

      default:
        CROAK("Usage: TrackPopupMenu(handle, menu, [x, y, [left, top, right, bottom], [flag, [coderef]]])\n");
      break;
    }

    // if given a coderef, check that it actually is one
    if(coderef != NULL && !(SvOK(coderef) && SvROK(coderef) && SvTYPE(SvRV(coderef)) == SVt_PVCV)) {
      W32G_WARN("TrackPopupMenu argument 'coderef' must be a code reference - callback not applied");
      coderef = NULL;  // don't set up the hook
    }

    // if we have a coderef, then store it temporarily in the hooks array so that we can access
    // it in the callback, and if successful, register the callback hook handler
    if(coderef != NULL) {

      perlud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr(handle, GWLP_USERDATA);
      if(ValidUserData(perlud)) {
        if(perlud->avHooks == NULL) {
          perlud->avHooks = newAV();
        }

        // Check if there is already a handler for this message (there shouldn't be)
        if(av_fetch(perlud->avHooks, WM_TRACKPOPUP_MSGHOOK, 0) == NULL) {
          // No array reference for this msg yet, so make one and insert our
          // handler ref:
          newarray = newAV();
          av_push(newarray, coderef);
          SvREFCNT_inc(coderef);  // needed so that the ref count remains the same after we free
          if(av_store(perlud->avHooks, WM_TRACKPOPUP_MSGHOOK, newRV_noinc((SV*) newarray)) == NULL) {
            // Failed to store new array
            SvREFCNT_dec((SV*) newarray);
            W32G_WARN("TrackPopupMenu failed to store 'coderef' - callback not applied");
            coderef = NULL;  // don't set up the hook
          }
        }
        else {
          // there's an existing hook for the message value we've chosen to use.
          // this means someone called hook() with the message code 0xBFFF !!
          W32G_WARN("TrackPopupMenu found an existing 'coderef' - callback not applied");
          coderef = NULL;  // don't set up the hook
        }
      }
      else {
        coderef = NULL;  // don't set up the hook
      }

      // only set up the hook if we installed the callback
      if(coderef != NULL) {
        hhook = SetWindowsHookEx(WH_MSGFILTER, (HOOKPROC)WindowsHookMsgProc, (HINSTANCE)NULL, GetWindowThreadProcessId(handle, (LPDWORD)NULL));
      }
    }

    // Display the menu
    SetForegroundWindow(handle);
    RETVAL = TrackPopupMenuEx(hmenu, flags, x, y, handle, lptpm);
    SetForegroundWindow(handle);

    if(coderef != NULL) {
      if(hhook != NULL) {
        UnhookWindowsHookEx(hhook); // release the windows hook
      }
      // remove the temporary value stored in the hooks array
      av_delete(perlud->avHooks, WM_TRACKPOPUP_MSGHOOK, G_DISCARD);
    }
#line 5614 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_SetTimer); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetTimer)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "handle, id, elapse");
    {
	HWND	handle;
	UINT_PTR	id = INT2PTR(UINT_PTR,SvIV(ST(1)))
;
	UINT	elapse = (UINT)SvUV(ST(2))
;
	UINT_PTR	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3818 "GUI.xs"
    RETVAL = SetTimer(handle, id, elapse, NULL);
#line 5648 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_KillTimer); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_KillTimer)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, id");
    {
	HWND	handle;
	UINT_PTR	id = INT2PTR(UINT_PTR,SvIV(ST(1)))
;
	UINT	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3830 "GUI.xs"
    RETVAL = KillTimer(handle, id);
#line 5680 "GUI.c"
	XSprePUSH;
	PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetEffectiveClientRect); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetEffectiveClientRect)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "handle, ...");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 3843 "GUI.xs"
    LPINT controls;
    int i, c;
    RECT r;
#line 5702 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3847 "GUI.xs"
    c = 0;
    controls = (LPINT) safemalloc(sizeof(INT)*items*2);
    for(i=1;i<items;i++) {
        controls[c++] = 1;
        controls[c++] = (INT) SvIV(ST(i));
    }
    controls[c++] = 0;
    controls[c++] = 0;
    GetEffectiveClientRect(handle, &r, controls);
    EXTEND(SP, 4);
    XST_mIV(0, r.left);
    XST_mIV(1, r.top);
    XST_mIV(2, r.right);
    XST_mIV(3, r.bottom);
    XSRETURN(4);
#line 5729 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_DialogUI); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_DialogUI)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "handle, ...");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 3875 "GUI.xs"
    LPPERLWIN32GUI_USERDATA perlud;
#line 5748 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3877 "GUI.xs"
    if(items > 2) {
        CROAK("Usage: DialogUI(handle, [value]);\n");
    }

    perlud = (LPPERLWIN32GUI_USERDATA) GetWindowLongPtr(handle, GWLP_USERDATA);
    if( ! ValidUserData(perlud) ) {
        XSRETURN_UNDEF;
    } else {
        if(items == 1) {
            XSRETURN_IV( (IV) perlud->dwPlStyle & PERLWIN32GUI_DIALOGUI );
        } else {
            SwitchBit(perlud->dwPlStyle, PERLWIN32GUI_DIALOGUI, SvIV(ST(1)));
            XSRETURN_IV( (IV) perlud->dwPlStyle & PERLWIN32GUI_DIALOGUI );
        }
    }
#line 5775 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_TrackMouse); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_TrackMouse)
{
    dVAR; dXSARGS;
    if (items < 1 || items > 3)
       croak_xs_usage(cv,  "handle, timeout=HOVER_DEFAULT, events=TME_HOVER|TME_LEAVE");
    {
	HWND	handle;
	DWORD	timeout;
	DWORD	events;
#line 3915 "GUI.xs"
    TRACKMOUSEEVENT tme;
#line 5794 "GUI.c"
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

	if (items < 2)
	    timeout = HOVER_DEFAULT;
	else {
	    timeout = (DWORD)SvUV(ST(1))
;
	}

	if (items < 3)
	    events = TME_HOVER|TME_LEAVE;
	else {
	    events = (DWORD)SvUV(ST(2))
;
	}
#line 3917 "GUI.xs"
    tme.cbSize = sizeof(TRACKMOUSEEVENT);
    tme.hwndTrack = handle;
    tme.dwFlags = events;
    tme.dwHoverTime = timeout;
    RETVAL = _TrackMouseEvent( &tme );
#line 5827 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_UntrackMouse); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_UntrackMouse)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
#line 3935 "GUI.xs"
    TRACKMOUSEEVENT tme;
#line 5845 "GUI.c"
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3937 "GUI.xs"
    tme.cbSize = sizeof(TRACKMOUSEEVENT);
    tme.hwndTrack = handle;
    tme.dwFlags = TME_QUERY;
    tme.dwHoverTime = 0;
    if(_TrackMouseEvent( &tme )) {
        tme.dwFlags = tme.dwFlags | TME_CANCEL;
        RETVAL = _TrackMouseEvent( &tme );
    } else {
        RETVAL = FALSE;
    }
#line 5869 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_PlayEnhMetaFile); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_PlayEnhMetaFile)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, filename");
    {
	HWND	handle;
	LPCTSTR	filename = (LPCTSTR)SvPV_nolen(ST(1))
;
#line 3966 "GUI.xs"
    HV* self;
    HDC hdc;
    SV** tmp;
    HENHMETAFILE hmeta;
    RECT rect;
#line 5893 "GUI.c"
	int	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 3972 "GUI.xs"
    self = (HV*) SvRV(ST(0));
    tmp = hv_fetch_mg(NOTXSCALL self, "-DC", 3, 0);
    if(tmp == NULL) {
        RETVAL = -1;
    } else {
        hdc = INT2PTR(HDC,SvIV(*tmp));
        if(hmeta = GetEnhMetaFile(filename)) {
            GetClientRect(handle, &rect);
            RETVAL = PlayEnhMetaFile(hdc, hmeta, &rect);
            DeleteEnhMetaFile(hmeta);
        } else {
#ifdef PERLWIN32GUI_DEBUG
                printf("XS(PlayEnhMetaFile): GetEnhMetaFile failed, error = %d\n", GetLastError());
#endif
            RETVAL = 0;
        }
    }
#line 5924 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_PlayWinMetaFile); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_PlayWinMetaFile)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, filename");
    {
	HWND	handle;
	LPCTSTR	filename = (LPCTSTR)SvPV_nolen(ST(1))
;
#line 4001 "GUI.xs"
    HDC hdc;
    HMETAFILE hwinmeta;
    HENHMETAFILE hmeta;
    RECT rect;
    UINT size;
    LPVOID data;
#line 5949 "GUI.c"
	int	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 4008 "GUI.xs"
#ifdef PERLWIN32GUI_DEBUG
    printf("XS(PlayWinMetaFile): filename = '%s'\n", filename);
#endif
    SetLastError(0);
    hwinmeta = GetMetaFile(filename);
#ifdef PERLWIN32GUI_DEBUG
    printf("XS(PlayWinMetaFile): hwinmeta = 0x%x\n", hwinmeta);
    printf("XS(PlayWinMetaFile): GetLastError = %ld\n", GetLastError());
#endif
    size = GetMetaFileBitsEx(hwinmeta, 0, NULL);
#ifdef PERLWIN32GUI_DEBUG
    printf("XS(PlayWinMetaFile): size = %d\n", size);
#endif
    data = (LPVOID) safemalloc(size);
    GetMetaFileBitsEx(hwinmeta, size, data);
    hmeta = SetWinMetaFileBits(size, (CONST BYTE *) data, NULL, NULL);
#ifdef PERLWIN32GUI_DEBUG
    printf("XS(PlayWinMetaFile): hmeta = 0x%x\n", hmeta);
#endif
    hdc = GetDC(handle);
    GetClientRect(handle, &rect);
    SetLastError(0);
    RETVAL = PlayEnhMetaFile(hdc, hmeta, &rect);
#ifdef PERLWIN32GUI_DEBUG
    printf("XS(PlayWinMetaFile): GetLastError after PlayEnhMetaFile = %d\n", GetLastError());
#endif
    DeleteEnhMetaFile(hmeta);
    ReleaseDC(handle, hdc);
    safefree(data);
#line 5992 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_CreateEnhMetaFile); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_CreateEnhMetaFile)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 3)
       croak_xs_usage(cv,  "handle, filename, description=NULL");
    {
	HWND	handle;
	LPCTSTR	filename = (LPCTSTR)SvPV_nolen(ST(1))
;
	LPCTSTR	description;
#line 4050 "GUI.xs"
    HV* self;
    HDC hdc;
    SV** tmp;
    RECT rect;
    int iWidthMM, iHeightMM, iWidthPels, iHeightPels;
#line 6017 "GUI.c"
	HDC	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

	if (items < 3)
	    description = NULL;
	else {
	    description = (LPCTSTR)SvPV_nolen(ST(2))
;
	}
#line 4056 "GUI.xs"
    self = (HV*) SvRV(ST(0));
    tmp = hv_fetch_mg(NOTXSCALL self, "-DC", 3, 0);
    if(tmp == NULL) {
        RETVAL = 0;
    } else {
        hdc = INT2PTR(HDC,SvIV(*tmp));
        iWidthMM = GetDeviceCaps(hdc, HORZSIZE);
        iHeightMM = GetDeviceCaps(hdc, VERTSIZE);
        iWidthPels = GetDeviceCaps(hdc, HORZRES);
        iHeightPels = GetDeviceCaps(hdc, VERTRES);
        GetClientRect(handle, &rect);
        rect.left = (rect.left * iWidthMM * 100)/iWidthPels;
        rect.top = (rect.top * iHeightMM * 100)/iHeightPels;
        rect.right = (rect.right * iWidthMM * 100)/iWidthPels;
        rect.bottom = (rect.bottom * iHeightMM * 100)/iHeightPels;
        RETVAL = CreateEnhMetaFile(hdc, filename, &rect, description);
    }
#line 6055 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_CloseEnhMetaFile); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_CloseEnhMetaFile)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "hdc");
    {
	HDC	hdc;
	HENHMETAFILE	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            hdc = INT2PTR(HDC,SvIV(*out));
        else
            hdc = NULL;
    } else
       hdc = INT2PTR(HDC,SvIV(ST(0)))
;
#line 4084 "GUI.xs"
    RETVAL = CloseEnhMetaFile(hdc);
#line 6085 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_DeleteEnhMetaFile); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_DeleteEnhMetaFile)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "hmeta");
    {
	HENHMETAFILE	hmeta = INT2PTR(HENHMETAFILE,SvIV(ST(0)))
;
	BOOL	RETVAL;
	dXSTARG;
#line 4096 "GUI.xs"
    RETVAL = DeleteEnhMetaFile(hmeta);
#line 6106 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_TextOut); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_TextOut)
{
    dVAR; dXSARGS;
    if (items != 4)
       croak_xs_usage(cv,  "handle, x, y, text");
    {
	HWND	handle;
	int	x = (int)SvIV(ST(1))
;
	int	y = (int)SvIV(ST(2))
;
	char *	text = (char *)SvPV_nolen(ST(3))
;
#line 4193 "GUI.xs"
    HV* self;
    HDC hdc;
    SV** tmp;
    STRLEN textlen;
#line 6133 "GUI.c"
	long	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 4198 "GUI.xs"
    self = (HV*) SvRV(ST(0));
    tmp = hv_fetch_mg(NOTXSCALL self, "-DC", 3, 0);
    if(tmp == NULL) {
        RETVAL = -1;
    } else {
        hdc = INT2PTR(HDC,SvIV(*tmp));
        textlen = strlen(text);
        RETVAL = (long) TextOut(hdc, x, y, text, textlen);
    }
#line 6156 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_SetTextColor); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetTextColor)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, color");
    {
	HWND	handle;
	COLORREF    color = SvCOLORREF(NOTXSCALL ST(1))
;
#line 4215 "GUI.xs"
    HV* self;
    HDC hdc;
    SV** tmp;
#line 6178 "GUI.c"
	long	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 4219 "GUI.xs"
    self = (HV*) SvRV(ST(0));
    tmp = hv_fetch_mg(NOTXSCALL self, "-DC", 3, 0);
    if(tmp == NULL) {
        RETVAL = -1;
    } else {
        hdc = INT2PTR(HDC,SvIV(*tmp));
        RETVAL = SetTextColor(hdc, color);
    }
#line 6200 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetTextColor); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetTextColor)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
#line 4234 "GUI.xs"
    HV* self;
    HDC hdc;
    SV** tmp;
#line 6220 "GUI.c"
	long	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 4238 "GUI.xs"
    self = (HV*) SvRV(ST(0));
    tmp = hv_fetch_mg(NOTXSCALL self, "-DC", 3, 0);
    if(tmp == NULL) {
        RETVAL = -1;
    } else {
        hdc = INT2PTR(HDC,SvIV(*tmp));
        RETVAL = GetTextColor(hdc);
    }
#line 6242 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_SetBkMode); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetBkMode)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, mode");
    {
	HWND	handle;
	int	mode = (int)SvIV(ST(1))
;
#line 4254 "GUI.xs"
    HV* self;
    HDC hdc;
    SV** tmp;
#line 6264 "GUI.c"
	long	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 4258 "GUI.xs"
    self = (HV*) SvRV(ST(0));
    tmp = hv_fetch_mg(NOTXSCALL self, "-DC", 3, 0);
    if(tmp == NULL) {
        RETVAL = -1;
    } else {
        hdc = INT2PTR(HDC,SvIV(*tmp));
        RETVAL = (long) SetBkMode(hdc, mode);
    }
#line 6286 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetBkMode); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetBkMode)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
#line 4273 "GUI.xs"
    HV* self;
    HDC hdc;
    SV** tmp;
#line 6306 "GUI.c"
	int	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 4277 "GUI.xs"
    self = (HV*) SvRV(ST(0));
    tmp = hv_fetch_mg(NOTXSCALL self, "-DC", 3, 0);
    if(tmp == NULL) {
        RETVAL = -1;
    } else {
        hdc = INT2PTR(HDC,SvIV(*tmp));
        RETVAL = GetBkMode(hdc);
    }
#line 6328 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_MoveTo); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_MoveTo)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "handle, x, y");
    {
	HWND	handle;
	int	x = (int)SvIV(ST(1))
;
	int	y = (int)SvIV(ST(2))
;
#line 4294 "GUI.xs"
    HV* self;
    HDC hdc;
    SV** tmp;
#line 6352 "GUI.c"
	long	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 4298 "GUI.xs"
    self = (HV*) SvRV(ST(0));
    tmp = hv_fetch_mg(NOTXSCALL self, "-DC", 3, 0);
    if(tmp == NULL) {
        RETVAL = -1;
    } else {
        hdc = INT2PTR(HDC,SvIV(*tmp));
        RETVAL = MoveToEx(hdc, x, y, NULL);
    }
#line 6374 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_Circle); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_Circle)
{
    dVAR; dXSARGS;
    if (items < 4 || items > 5)
       croak_xs_usage(cv,  "handle, x, y, width, height=-1");
    {
	HWND	handle;
	int	x = (int)SvIV(ST(1))
;
	int	y = (int)SvIV(ST(2))
;
	int	width = (int)SvIV(ST(3))
;
	int	height;
#line 4317 "GUI.xs"
    HV* self;
    HDC hdc;
    SV** tmp;
#line 6401 "GUI.c"
	long	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

	if (items < 5)
	    height = -1;
	else {
	    height = (int)SvIV(ST(4))
;
	}
#line 4321 "GUI.xs"
    self = (HV*) SvRV(ST(0));
    tmp = hv_fetch_mg(NOTXSCALL self, "-DC", 3, 0);
    if(tmp == NULL) {
        RETVAL = -1;
    } else {
        hdc = INT2PTR(HDC,SvIV(*tmp));
        if(height == -1) {
            width *= 2;
            height = width;
        }
        RETVAL = (long) Arc(hdc, x, y, width-x, height-y, 0, 0, 0, 0);
    }
#line 6434 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_LineTo); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_LineTo)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "handle, x, y");
    {
	HWND	handle;
	int	x = (int)SvIV(ST(1))
;
	int	y = (int)SvIV(ST(2))
;
#line 4343 "GUI.xs"
    HV* self;
    HDC hdc;
    SV** tmp;
#line 6458 "GUI.c"
	long	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 4347 "GUI.xs"
    self = (HV*) SvRV(ST(0));
    tmp = hv_fetch_mg(NOTXSCALL self, "-DC", 3, 0);
    if(tmp == NULL) {
        RETVAL = -1;
    } else {
        hdc = INT2PTR(HDC,SvIV(*tmp));
        RETVAL = LineTo(hdc, x, y);
    }
#line 6480 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_BeginPaint); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_BeginPaint)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 4383 "GUI.xs"
    HV* self;
    HWND hwnd;
    HDC hdc;
    int i;
    PAINTSTRUCT ps;
    char tmprgb[16];
    self = (HV*) SvRV(ST(0));
    hwnd = INT2PTR(HWND,SvIV(*hv_fetch(self, "-handle", 7, 0)));
    if(hwnd) {
        if(hdc = BeginPaint(hwnd, &ps)) {
            hv_store(self, "-DC", 3, newSViv(PTR2IV(hdc)), 0);
            hv_store(self, "-ps.hdc", 7, newSViv(PTR2IV(ps.hdc)), 0);
            hv_store(self, "-ps.fErase", 10, newSViv((IV) ps.fErase), 0);
            hv_store(self, "-ps.rcPaint.left", 16, newSViv((IV) ps.rcPaint.left), 0);
            hv_store(self, "-ps.rcPaint.top", 15, newSViv((IV) ps.rcPaint.top), 0);
            hv_store(self, "-ps.rcPaint.right", 17, newSViv((IV) ps.rcPaint.right), 0);
            hv_store(self, "-ps.rcPaint.bottom", 18, newSViv((IV) ps.rcPaint.bottom), 0);
            hv_store(self, "-ps.fRestore", 12, newSViv((IV) ps.fRestore), 0);
            hv_store(self, "-ps.fIncUpdate", 14, newSViv((IV) ps.fIncUpdate), 0);
            for(i=0;i<=31;i++) {
                sprintf(tmprgb, "-ps.rgbReserved%02d", i);
                hv_store(self, tmprgb, 17, newSViv((IV) ps.rgbReserved[i]), 0);
            }
            XSRETURN_YES;
        } else {
            XSRETURN_NO;
        }
    } else {
        XSRETURN_NO;
    }
#line 6528 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_EndPaint); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_EndPaint)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 4417 "GUI.xs"
    HV* self;
    HWND hwnd;
    SV** tmp;
    int i;
    PAINTSTRUCT ps;
    char tmprgb[16];
    BOOL result;

    self = (HV*) SvRV(ST(0));
    if(self) {
        tmp = hv_fetch(self, "-handle", 7, 0);
        if(tmp == NULL) XSRETURN_NO;
        hwnd = INT2PTR(HWND,SvIV(*tmp));
        tmp = hv_fetch(self, "-ps.hdc", 7, 0);
        if(tmp == NULL) XSRETURN_NO;
        ps.hdc = INT2PTR(HDC,SvIV(*tmp));
        tmp = hv_fetch(self, "-ps.fErase", 10, 0);
        if(tmp == NULL) XSRETURN_NO;
        ps.fErase = (BOOL) SvIV(*tmp);
        tmp = hv_fetch(self, "-ps.rcPaint.left", 16, 0);
        if(tmp == NULL) XSRETURN_NO;
        ps.rcPaint.left = (LONG) SvIV(*tmp);
        tmp = hv_fetch(self, "-ps.rcPaint.top", 15, 0);
        if(tmp == NULL) XSRETURN_NO;
        ps.rcPaint.top = (LONG) SvIV(*tmp);
        tmp = hv_fetch(self, "-ps.rcPaint.right", 17, 0);
        if(tmp == NULL) XSRETURN_NO;
        ps.rcPaint.right = (LONG) SvIV(*tmp);
        tmp = hv_fetch(self, "-ps.rcPaint.bottom", 18, 0);
        if(tmp == NULL) XSRETURN_NO;
        ps.rcPaint.bottom = (LONG) SvIV(*tmp);
        tmp = hv_fetch(self, "-ps.fRestore", 12, 0);
        if(tmp == NULL) XSRETURN_NO;
        ps.fRestore = (BOOL) SvIV(*tmp);
        tmp = hv_fetch(self, "-ps.fIncUpdate", 14, 0);
        if(tmp == NULL) XSRETURN_NO;
        ps.fIncUpdate = (BOOL) SvIV(*tmp);
        for(i=0;i<=31;i++) {
            sprintf(tmprgb, "-ps.rgbReserved%02d", i);
            tmp = hv_fetch(self, tmprgb, 17, 0);
            if(tmp == NULL) XSRETURN_NO;
            ps.rgbReserved[i] = (BYTE) SvIV(*tmp);
        }
        result = EndPaint(hwnd, &ps);
        hv_delete(self, "-DC", 3, 0);
        hv_delete(self, "-ps.hdc", 7, 0);
        hv_delete(self, "-ps.fErase", 10, 0);
        hv_delete(self, "-ps.rcPaint.left", 16, 0);
        hv_delete(self, "-ps.rcPaint.top", 15, 0);
        hv_delete(self, "-ps.rcPaint.right", 17, 0);
        hv_delete(self, "-ps.rcPaint.bottom", 18, 0);
        hv_delete(self, "-ps.fRestore", 12, 0);
        hv_delete(self, "-ps.fIncUpdate", 14, 0);
        for(i=0;i<=31;i++) {
            sprintf(tmprgb, "-ps.rgbReserved%02d", i);
            hv_delete(self, tmprgb, 17, 0);
        }
        XSRETURN_IV((IV) result);
    } else {
        XSRETURN_NO;
    }
#line 6606 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_SaveBMP); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SaveBMP)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	HWND	handle;
#line 4487 "GUI.xs"
    HDC hdc;
    HDC hdc2;
    RECT cr;
    HANDLE hf;
    BITMAP bmp;
    HBITMAP hbmp;
    PBITMAPINFO pbmi;
    PBITMAPINFOHEADER pbih;
    BITMAPFILEHEADER hdr;
    WORD cClrBits;
    LONG width, height;
    LPBYTE lpBits;
    BYTE *hp;
    DWORD cb;
    DWORD dwTmp;
    DWORD dwTotal;
    DWORD MAXWRITE;
#line 6641 "GUI.c"

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 4505 "GUI.xs"
    hdc = GetDC(handle);
    GetClientRect(handle, &cr);
    width = cr.right - cr.left;
    height = cr.bottom - cr.top;
    MAXWRITE = 2048;

    hdc2 = CreateCompatibleDC(hdc);
    hbmp = CreateCompatibleBitmap(hdc, width, height);
    SelectObject(hdc2, hbmp);
    BitBlt(hdc2, 0, 0, width, height, hdc, 0, 0, SRCCOPY);
    if (!GetObject(hbmp, sizeof(BITMAP), (LPSTR)&bmp)) {
        XSRETURN_NO;
    }

    cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel);
    if (cClrBits == 1)       cClrBits = 1;
    else if (cClrBits <= 4)  cClrBits = 4;
    else if (cClrBits <= 8)  cClrBits = 8;
    else if (cClrBits <= 16) cClrBits = 16;
    else if (cClrBits <= 24) cClrBits = 24;
    else                     cClrBits = 32;

    if (cClrBits != 24)
        pbmi = (PBITMAPINFO) LocalAlloc(LPTR, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * (2^cClrBits));
    else
        pbmi = (PBITMAPINFO) LocalAlloc(LPTR, sizeof(BITMAPINFOHEADER));

    pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    pbmi->bmiHeader.biWidth = bmp.bmWidth;
    pbmi->bmiHeader.biHeight = bmp.bmHeight;
    pbmi->bmiHeader.biPlanes = bmp.bmPlanes;
    pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel;
    if (cClrBits < 24) pbmi->bmiHeader.biClrUsed = 2^cClrBits;
    pbmi->bmiHeader.biCompression = BI_RGB;
    pbmi->bmiHeader.biSizeImage = (pbmi->bmiHeader.biWidth + 7) /8
                                  * pbmi->bmiHeader.biHeight
                                  * cClrBits;
    pbmi->bmiHeader.biClrImportant = 0;

    pbih = (PBITMAPINFOHEADER) pbmi;

    lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);

    if (!GetDIBits(hdc2, hbmp, 0, (WORD) pbih->biHeight, lpBits, pbmi, DIB_RGB_COLORS)) {
        XSRETURN_NO;
    }

    hf = CreateFile("SaveBMP.bmp",
                    GENERIC_READ | GENERIC_WRITE,
                    (DWORD) 0,
                    (LPSECURITY_ATTRIBUTES) NULL,
                    CREATE_ALWAYS,
                    FILE_ATTRIBUTE_NORMAL,
                    (HANDLE) NULL);
    if(hf == INVALID_HANDLE_VALUE) {
        XSRETURN_NO;
    }
    hdr.bfType = 0x4d42;        // #### 0x42 = "B" 0x4d = "M"

    // #### Compute the size of the entire file
    hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) +
                 pbih->biSize + pbih->biClrUsed
                 * sizeof(RGBQUAD) + pbih->biSizeImage);
    hdr.bfReserved1 = 0;
    hdr.bfReserved2 = 0;

    // #### Compute the offset to the array of color indices
    hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) +
                    pbih->biSize + pbih->biClrUsed
                    * sizeof (RGBQUAD);
    // #### Copy the BITMAPFILEHEADER into the .BMP file
    if (!WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER),
       (LPDWORD) &dwTmp, (LPOVERLAPPED) NULL)) {
       XSRETURN_NO;
    }
    // #### Copy the BITMAPINFOHEADER and RGBQUAD array into the file
    if (!WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER)
                  + pbih->biClrUsed * sizeof (RGBQUAD),
                  (LPDWORD) &dwTmp, (LPOVERLAPPED) NULL)) {
        XSRETURN_NO;
    }
    // #### Copy the array of color indices into the .BMP file
    dwTotal = cb = pbih->biSizeImage;     hp = lpBits;
    while (cb > MAXWRITE)  {
        if (!WriteFile(hf, (LPSTR) hp, MAXWRITE,
                          (LPDWORD) &dwTmp, (LPOVERLAPPED) NULL)) {
            XSRETURN_NO;
        }
        cb -= MAXWRITE;
        hp += MAXWRITE;
    }
    if (!WriteFile(hf, (LPSTR) hp, (int) cb,
        (LPDWORD) &dwTmp, (LPOVERLAPPED) NULL)) {
        XSRETURN_NO;
    }
    if (!CloseHandle(hf)) {
        XSRETURN_NO;
    }

    // #### Free memory
    GlobalFree((HGLOBAL)lpBits);
    DeleteDC(hdc2);
    ReleaseDC(handle, hdc);
    DeleteObject(hbmp);
    XSRETURN_YES;
#line 6758 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_GetFontName); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetFontName)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
#line 4620 "GUI.xs"
    HDC hdc;
    char facename[256];
#line 6776 "GUI.c"
	LPTSTR	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 4623 "GUI.xs"
    hdc = GetDC(handle);
    if(GetTextFace(hdc, 256, facename)) {
        RETVAL = (LPTSTR) facename;
    } else {
        RETVAL = "";
    }
    ReleaseDC(handle, hdc);
#line 6797 "GUI.c"
	sv_setpv(TARG, RETVAL);
	XSprePUSH;
	PUSHTARG;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_EnumMyWindows); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_EnumMyWindows)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 4655 "GUI.xs"
    AV* ary;
    int i;
#line 6818 "GUI.c"
#line 4658 "GUI.xs"
    ary = newAV();
    EnumWindows( (WNDENUMPROC) EnumMyWindowsProc, (LPARAM) ary);
    for(i=0; i<av_len(ary)+1; i++) {
        //printf("XS(EnumMyWindows): ary[%d] = %ld\n", i, SvIV(*(av_fetch(ary, i, 0))));
        XST_mIV(i, SvIV(*(av_fetch(ary, i, 0))));
    }
    SvREFCNT_dec((SV*)ary);
    XSRETURN(i);
#line 6828 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_GetSystemMetrics); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetSystemMetrics)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "index");
    {
	int	index = (int)SvIV(ST(0))
;
	int	RETVAL;
	dXSTARG;
#line 4676 "GUI.xs"
    RETVAL = GetSystemMetrics(index);
#line 6848 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_MessageBox); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_MessageBox)
{
    dVAR; dXSARGS;
    if (items < 1 || items > 4)
       croak_xs_usage(cv,  "handle=NULL, text, caption=NULL, type=MB_ICONEXCLAMATION|MB_OK");
    {
	HWND	handle;
	LPCTSTR	text = (LPCTSTR)SvPV_nolen(ST(1))
;
	LPCTSTR	caption;
	UINT	type;
	int	RETVAL;
	dXSTARG;

	if (items < 1)
	    handle = NULL;
	else {
    if(SvROK(ST(0))) {
	SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
	if(out != NULL)
	    handle = INT2PTR(HWND,SvIV(*out));
	else
	    handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
	}

	if (items < 3)
	    caption = NULL;
	else {
	    caption = (LPCTSTR)SvPV_nolen(ST(2))
;
	}

	if (items < 4)
	    type = MB_ICONEXCLAMATION|MB_OK;
	else {
	    type = (UINT)SvUV(ST(3))
;
	}
#line 4760 "GUI.xs"
    RETVAL = MessageBox(handle, text, caption, type);
#line 6900 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_MessageBeep); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_MessageBeep)
{
    dVAR; dXSARGS;
    if (items < 0 || items > 1)
       croak_xs_usage(cv,  "type=MB_OK");
    {
	UINT	type;
	BOOL	RETVAL;
	dXSTARG;

	if (items < 1)
	    type = MB_OK;
	else {
	    type = (UINT)SvUV(ST(0))
;
	}
#line 4780 "GUI.xs"
    RETVAL = MessageBeep(type);
#line 6927 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetOpenFileName); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetOpenFileName)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 4856 "GUI.xs"
    OPENFILENAME ofn;
    BOOL retval;
    int i, next_i;
    unsigned int fnlen = MAX_PATH;
    char *fname_in = NULL;
    char *fname;
    char *option;
    char *filter;

    ZeroMemory(&ofn, sizeof(OPENFILENAME));
    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = NULL;
    ofn.lpstrFilter = NULL;
    ofn.lpstrCustomFilter = NULL;
    ofn.nFilterIndex = 0;
    ofn.lpstrFileTitle = NULL;
    ofn.lpstrInitialDir = NULL;
    ofn.lpstrTitle = NULL;
    ofn.lpstrDefExt = NULL;
    ofn.lpTemplateName = NULL;
    ofn.Flags = OFN_HIDEREADONLY | OFN_EXPLORER;

    next_i = -1;
    for(i = 0; i < items; i++) {
        if(next_i == -1) {
            option = SvPV_nolen(ST(i));
            if(strcmp(option, "-owner") == 0) {
                next_i = i + 1;
                ofn.hwndOwner = (HWND) handle_From(NOTXSCALL ST(next_i));
            } else if(strcmp(option, "-title") == 0) {
                next_i = i + 1;
                ofn.lpstrTitle = SvPV_nolen(ST(next_i));
            } else if(strcmp(option, "-directory") == 0) {
                next_i = i + 1;
                ofn.lpstrInitialDir = SvPV_nolen(ST(next_i));
            } else if(strcmp(option, "-defaultextension") == 0
                  ||  strcmp(option, "-defaultextention") == 0 ) {
                next_i = i + 1;
                ofn.lpstrDefExt = SvPV_nolen(ST(next_i));
            } else if(strcmp(option, "-file") == 0) {
                next_i = i + 1;
                fname_in = SvPV_nolen(ST(next_i));
            } else if(strcmp(option, "-filter") == 0) {
                next_i = i + 1;
                if(SvROK(ST(next_i)) && SvTYPE(SvRV(ST(next_i))) == SVt_PVAV) {
                    AV* filters;
                    SV** t;
                    int i, filterlen = 0;
                    char *fpointer;
                    filters = (AV*)SvRV(ST(next_i));
                    for(i=0; i<=av_len(filters); i++) {
                        t = av_fetch(filters, i, 0);
                        if(t != NULL) {
                            filterlen += SvCUR(*t) + 1;
                        }
                    }
                    filterlen += 2;
                    filter = (char *) safemalloc(filterlen);
                    fpointer = filter;
                    for(i=0; i<=av_len(filters); i++) {
                        t = av_fetch(filters, i, 0);
                        if(t != NULL) {
                            strcpy(fpointer, SvPV_nolen(*t));
                            fpointer += SvCUR(*t);
                            *fpointer++ = 0;
                        }
                    }
                    *fpointer = 0;
                    ofn.lpstrFilter = (LPCTSTR) filter;
                } else {
                    W32G_WARN("Win32::GUI: argument to -filter is not an array reference!");
                }
            } else if(strcmp(option, "-defaultfilter") == 0 ) {
                next_i = i + 1;
                ofn.nFilterIndex = (DWORD)SvIV(ST(next_i)) + 1;
            } else if(strcmp(option, "-flags") == 0) {
                next_i = i + 1;
                ofn.Flags = (DWORD)SvIV(ST(next_i));
            } else BitmaskOption( "-multisel", ofn.Flags, OFN_ALLOWMULTISELECT )
                if(fnlen < 4000 * (unsigned)SvIV(ST(next_i))) {
                  fnlen = 4000 * (unsigned)SvIV(ST(next_i));
                }
            } else BitmaskOption( "-createprompt", ofn.Flags, OFN_CREATEPROMPT )
            } else BitmaskOption( "-explorer", ofn.Flags, OFN_EXPLORER )
            } else BitmaskOption( "-extensiondifferent", ofn.Flags, OFN_EXTENSIONDIFFERENT )
            } else BitmaskOption( "-filemustexist", ofn.Flags, OFN_FILEMUSTEXIST )
            } else BitmaskOption( "-hidereadonly", ofn.Flags, OFN_HIDEREADONLY )
            } else BitmaskOption( "-nochangedir", ofn.Flags, OFN_NOCHANGEDIR )
            } else BitmaskOption( "-nodeferencelinks", ofn.Flags, OFN_NODEREFERENCELINKS )
            } else BitmaskOption( "-nonetwork", ofn.Flags, OFN_NONETWORKBUTTON )
            } else BitmaskOption( "-noreadonlyreturn", ofn.Flags, OFN_NOREADONLYRETURN )
            } else BitmaskOption( "-pathmustexist", ofn.Flags, OFN_PATHMUSTEXIST )
            } else BitmaskOption( "-readonly", ofn.Flags, OFN_READONLY )
            }
        } else {
            next_i = -1;
        }
    }


    fname = (char *) safemalloc(fnlen);
    fname[0] = 0;
    if(fname_in  &&  fnlen > strlen(fname_in)) {
      strcpy(fname, fname_in);
    }
    ofn.lpstrFile = fname;
    ofn.nMaxFile = fnlen;

    retval = GetOpenFileName(&ofn);

    if(ofn.lpstrFilter != NULL) safefree((void *)filter);

    if(retval) {
      if (ofn.Flags & OFN_ALLOWMULTISELECT) {
         i = 0;
         char * ptr = (char *) ofn.lpstrFile;

         // Count files
         while (*ptr) {
           i ++;
           ptr += strlen(ptr) + 1;
         }

         if ( !(ofn.Flags & OFN_HIDEREADONLY) )
            i++;

         EXTEND(SP, i);

         i = 0;
         ptr = (char *) ofn.lpstrFile;
         while (*ptr) {
            XST_mPV(i, ptr);
            i ++;
            ptr += strlen(ptr) + 1;
         }

         if ( !(ofn.Flags & OFN_HIDEREADONLY) ) {
            XST_mIV( i, (ofn.Flags & OFN_READONLY) );
            i ++;
         }

         safefree((void *)fname);
         XSRETURN(i);
      }
      else {
        if ((ofn.Flags & OFN_HIDEREADONLY) || GIMME_V == G_SCALAR) {
            EXTEND(SP, 1);
            XST_mPV( 0, ofn.lpstrFile);
            safefree((void *)fname);
            XSRETURN(1);
        }
        else {
            EXTEND(SP, 2);
            XST_mPV( 0, ofn.lpstrFile);
            XST_mIV( 1, (ofn.Flags & OFN_READONLY) );
            safefree((void *)fname);
            XSRETURN(2);
        }
      }
    } else {
        safefree((void *)fname);
        XSRETURN_UNDEF;
    }
#line 7108 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_GetSaveFileName); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetSaveFileName)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 5084 "GUI.xs"
    OPENFILENAME ofn;
    BOOL retval;
    int i, next_i;
    char filename[MAX_PATH];
    char *option;
    char *filter;

    ZeroMemory(&ofn, sizeof(OPENFILENAME));
    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = NULL;
    ofn.lpstrFilter = NULL;
    ofn.lpstrCustomFilter = NULL;
    ofn.nFilterIndex = 0;
    ofn.lpstrFileTitle = NULL;
    ofn.lpstrInitialDir = NULL;
    ofn.lpstrTitle = NULL;
    ofn.lpstrDefExt = NULL;
    ofn.lpTemplateName = NULL;
    ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_EXPLORER;
    filename[0] = 0;
    ofn.lpstrFile = filename;
    ofn.nMaxFile = MAX_PATH;

    next_i = -1;
    for(i = 0; i < items; i++) {
        if(next_i == -1) {
            option = SvPV_nolen(ST(i));
            if(strcmp(option, "-owner") == 0) {
                next_i = i + 1;
                ofn.hwndOwner = (HWND) handle_From(NOTXSCALL ST(next_i));
            } else if(strcmp(option, "-title") == 0) {
                next_i = i + 1;
                ofn.lpstrTitle = SvPV_nolen(ST(next_i));
            } else if(strcmp(option, "-directory") == 0) {
                next_i = i + 1;
                ofn.lpstrInitialDir = SvPV_nolen(ST(next_i));
            } else if(strcmp(option, "-defaultextension") == 0
                  ||  strcmp(option, "-defaultextention") == 0 ) {
                next_i = i + 1;
                ofn.lpstrDefExt = SvPV_nolen(ST(next_i));
            } else if(strcmp(option, "-file") == 0) {
                next_i = i + 1;
                strcpy(filename, SvPV_nolen(ST(next_i)));
            } else if(strcmp(option, "-filter") == 0) {
                next_i = i + 1;
                if(SvROK(ST(next_i)) && SvTYPE(SvRV(ST(next_i))) == SVt_PVAV) {
                    AV* filters;
                    SV** t;
                    int i, filterlen = 0;
                    char *fpointer;
                    filters = (AV*)SvRV(ST(next_i));
                    for(i=0; i<=av_len(filters); i++) {
                        t = av_fetch(filters, i, 0);
                        if(t != NULL) {
                            filterlen += SvCUR(*t) + 1;
                        }
                    }
                    filterlen += 2;
                    filter = (char *) safemalloc(filterlen);
                    fpointer = filter;
                    for(i=0; i<=av_len(filters); i++) {
                        t = av_fetch(filters, i, 0);
                        if(t != NULL) {
                            strcpy(fpointer, SvPV_nolen(*t));
                            fpointer += SvCUR(*t);
                            *fpointer++ = 0;
                        }
                    }
                    *fpointer = 0;
                    ofn.lpstrFilter = (LPCTSTR) filter;
                } else {
                    W32G_WARN("Win32::GUI: argument to -filter is not an array reference!");
                }
            } else if(strcmp(option, "-defaultfilter") == 0 ) {
                next_i = i + 1;
                ofn.nFilterIndex = (DWORD)SvIV(ST(next_i)) + 1;
            } else if(strcmp(option, "-flags") == 0) {
                next_i = i + 1;
                ofn.Flags = (DWORD)SvIV(ST(next_i));
            } else BitmaskOption( "-createprompt", ofn.Flags, OFN_CREATEPROMPT )
            } else BitmaskOption( "-explorer", ofn.Flags, OFN_EXPLORER )
            } else BitmaskOption( "-extensiondifferent", ofn.Flags, OFN_EXTENSIONDIFFERENT )
            } else BitmaskOption( "-filemustexist", ofn.Flags, OFN_FILEMUSTEXIST )
            } else BitmaskOption( "-nochangedir", ofn.Flags, OFN_NOCHANGEDIR )
            } else BitmaskOption( "-nodeferencelinks", ofn.Flags, OFN_NODEREFERENCELINKS )
            } else BitmaskOption( "-nonetwork", ofn.Flags, OFN_NONETWORKBUTTON )
            } else BitmaskOption( "-noreadonlyreturn", ofn.Flags, OFN_NOREADONLYRETURN )
            } else BitmaskOption( "-pathmustexist", ofn.Flags, OFN_PATHMUSTEXIST )
            } else BitmaskOption( "-overwriteprompt", ofn.Flags, OFN_OVERWRITEPROMPT )
            } else BitmaskOption( "-overdriveprompt", ofn.Flags, OFN_OVERWRITEPROMPT ) // deprecated, but retained for compatibility
            }
        } else {
            next_i = -1;
        }
    }
    retval = GetSaveFileName(&ofn);
    if(retval) {
        EXTEND(SP, 1);
        XST_mPV( 0, ofn.lpstrFile);
        if(ofn.lpstrFilter != NULL) safefree((void *)filter);
        XSRETURN(1);
    } else {
        if(ofn.lpstrFilter != NULL) safefree((void *)filter);
        XSRETURN_UNDEF;
    }
#line 7230 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_BrowseForFolder); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_BrowseForFolder)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 5335 "GUI.xs"
    BROWSEINFO bi;
    LPITEMIDLIST retval;
    LPITEMIDLIST pidl;
    LPSHELLFOLDER pDesktopFolder;
    OLECHAR olePath[MAX_PATH];
    ULONG chEaten;
    HRESULT hr;
    int i, next_i;
    char folder[MAX_PATH];
    char *option;
    ZeroMemory(&bi, sizeof(BROWSEINFO));
    bi.pszDisplayName = folder;
    next_i = -1;
    for(i = 0; i < items; i++) {
        if(next_i == -1) {
            option = SvPV_nolen(ST(i));
            if(strcmp(option, "-owner") == 0) {
                next_i = i + 1;
                bi.hwndOwner = (HWND) handle_From(NOTXSCALL ST(next_i));
            } else if(strcmp(option, "-title") == 0) {
                next_i = i + 1;
                bi.lpszTitle = SvPV_nolen(ST(next_i));
            } else BitmaskOption("-computeronly", bi.ulFlags, BIF_BROWSEFORCOMPUTER)
            } else BitmaskOption("-domainonly", bi.ulFlags, BIF_DONTGOBELOWDOMAIN)
            } else BitmaskOption("-driveonly", bi.ulFlags, BIF_RETURNFSANCESTORS)
            } else BitmaskOption("-editbox", bi.ulFlags, BIF_EDITBOX)
            } else BitmaskOption("-folderonly", bi.ulFlags, BIF_RETURNONLYFSDIRS)
            } else BitmaskOption("-includefiles", bi.ulFlags, BIF_BROWSEINCLUDEFILES)
            } else BitmaskOption("-printeronly", bi.ulFlags, BIF_BROWSEFORPRINTER)
            } else BitmaskOption("-newui", bi.ulFlags, BIF_NEWDIALOGSTYLE)
#ifdef BIF_NONEWFOLDERBUTTON
            /* not defined on old cygwin */
            } else BitmaskOption("-nonewfolder", bi.ulFlags, BIF_NONEWFOLDERBUTTON)
#endif
            } else if(strcmp(option, "-directory") == 0) {
                next_i = i + 1;
                bi.lParam = (LPARAM) SvPV_nolen(ST(next_i));
                bi.lpfn = BrowseForFolderProc;
            } else if(strcmp(option, "-root") == 0) {
                next_i = i + 1;
                if(SvIOK(ST(next_i))) {
                    bi.pidlRoot = INT2PTR(LPCITEMIDLIST,SvIV(ST(next_i)));
                } else {
                    SHGetDesktopFolder(&pDesktopFolder);
                    MultiByteToWideChar(
                        CP_ACP,
                        MB_PRECOMPOSED,
                        SvPV_nolen(ST(next_i)), -1,
                        olePath, MAX_PATH
                    );
                    hr = pDesktopFolder->ParseDisplayName(
                    // hr = IShellFolder::ParseDisplayName(
                        NULL,
                        NULL,
                        olePath,
                        &chEaten,
                        &pidl,
                        NULL
                    );
                    if(FAILED(hr)) {
                        W32G_WARN("Win32::GUI::BrowseForFolder: can't get ITEMIDLIST for -root!");
                        pDesktopFolder->Release();
                        XSRETURN_UNDEF;
                    } else {
                        bi.pidlRoot = pidl;
                        pDesktopFolder->Release();
                    }
                }
            }
        } else {
            next_i = -1;
        }
    }
    retval = SHBrowseForFolder(&bi);
    if(retval != NULL) {
        if(SHGetPathFromIDList(retval, folder)) {
            EXTEND(SP, 1);
            XST_mPV( 0, folder);
            XSRETURN(1);
        } else {
            XSRETURN_UNDEF;
        }
    } else {
        XSRETURN_UNDEF;
    }
#line 7332 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_ChooseColor); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_ChooseColor)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 5432 "GUI.xs"
    CHOOSECOLOR cc;
    COLORREF lpCustColors[16];
    BOOL retval;
    int i, next_i;
    char * option;

    ZeroMemory(&cc, sizeof(CHOOSECOLOR));
    cc.lStructSize = sizeof(CHOOSECOLOR);
    cc.hwndOwner = NULL;
    cc.lpCustColors = lpCustColors;
    cc.lpTemplateName = NULL;
    cc.Flags = 0;
    cc.rgbResult = 0;

    next_i = -1;
    for(i = 0; i < items; i++) {
        if(next_i == -1) {
            option = SvPV_nolen(ST(i));
            if(strcmp(option, "-owner") == 0) {
                next_i = i + 1;
                cc.hwndOwner = (HWND) handle_From(NOTXSCALL ST(next_i));
            } else if(strcmp(option, "-color") == 0) {
                next_i = i + 1;
                cc.rgbResult = (COLORREF) SvCOLORREF(NOTXSCALL ST(next_i));
                cc.Flags = cc.Flags | CC_RGBINIT;
            }
        } else {
            next_i = -1;
        }
    }

    retval = ChooseColor(&cc);

    if(retval) {
        EXTEND(SP, 1);
        XST_mIV(0, cc.rgbResult);
        XSRETURN(1);
    } else {
        XSRETURN_UNDEF;
    }
#line 7389 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_ChooseFont); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_ChooseFont)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 5506 "GUI.xs"
    CHOOSEFONT cf;
    static LOGFONT lf;
    BOOL retval;
    int i, next_i;
    char *option;

    ZeroMemory(&cf, sizeof(CHOOSEFONT));
    cf.lStructSize = sizeof(CHOOSEFONT);
    cf.hwndOwner = NULL;
    cf.lpLogFont = &lf;
    cf.lpTemplateName = NULL;
    cf.Flags = CF_SCREENFONTS;

    next_i = -1;
    for(i = 0; i < items; i++) {
        if(next_i == -1) {
            option = SvPV_nolen(ST(i));
            if(strcmp(option, "-owner") == 0) {
                next_i = i + 1;
                cf.hwndOwner = (HWND) handle_From(NOTXSCALL ST(next_i));
            }
            if(strcmp(option, "-pointsize") == 0) {
                next_i = i + 1;
                cf.iPointSize = (INT)SvIV(ST(next_i));
            }
            if(strcmp(option, "-height") == 0) {
                HDC hDisplay;
                hDisplay = CreateDC("DISPLAY", NULL, NULL, NULL);
                next_i = i + 1;
                lf.lfHeight = -MulDiv((int)SvIV(ST(next_i)), GetDeviceCaps(hDisplay, LOGPIXELSY), 72);
                DeleteDC(hDisplay);
                SwitchBit(cf.Flags, CF_INITTOLOGFONTSTRUCT, 1);

            }
            if(strcmp(option, "-width") == 0) {
                next_i = i + 1;
                lf.lfWidth = (LONG)SvIV(ST(next_i));
                SwitchBit(cf.Flags, CF_INITTOLOGFONTSTRUCT, 1);
            }
            if(strcmp(option, "-escapement") == 0) {
                next_i = i + 1;
                lf.lfEscapement = (LONG)SvIV(ST(next_i));
                SwitchBit(cf.Flags, CF_INITTOLOGFONTSTRUCT, 1);
            }
            if(strcmp(option, "-orientation") == 0) {
                next_i = i + 1;
                lf.lfOrientation = (LONG)SvIV(ST(next_i));
                SwitchBit(cf.Flags, CF_INITTOLOGFONTSTRUCT, 1);
            }
            if(strcmp(option, "-weight") == 0) {
                next_i = i + 1;
                lf.lfWeight = (int) SvIV(ST(next_i));
                SwitchBit(cf.Flags, CF_INITTOLOGFONTSTRUCT, 1);
            }
            if(strcmp(option, "-bold") == 0) {
                next_i = i + 1;
                if(SvIV(ST(next_i)) != 0) lf.lfWeight = 700;
                SwitchBit(cf.Flags, CF_INITTOLOGFONTSTRUCT, 1);
            }
            if(strcmp(option, "-italic") == 0) {
                next_i = i + 1;
                lf.lfItalic = (BYTE) SvIV(ST(next_i));
                SwitchBit(cf.Flags, CF_INITTOLOGFONTSTRUCT, 1);
            }
            if(strcmp(option, "-underline") == 0) {
                next_i = i + 1;
                lf.lfUnderline = (BYTE) SvIV(ST(next_i));
                SwitchBit(cf.Flags, CF_INITTOLOGFONTSTRUCT, 1);
            }
            if(strcmp(option, "-strikeout") == 0) {
                next_i = i + 1;
                lf.lfStrikeOut = (BYTE) SvIV(ST(next_i));
                SwitchBit(cf.Flags, CF_INITTOLOGFONTSTRUCT, 1);
            }
            if(strcmp(option, "-charset") == 0) {
                next_i = i + 1;
                lf.lfCharSet = (BYTE) SvIV(ST(next_i));
                SwitchBit(cf.Flags, CF_INITTOLOGFONTSTRUCT, 1);
            }
            if(strcmp(option, "-outputprecision") == 0) {
                next_i = i + 1;
                lf.lfOutPrecision = (BYTE) SvIV(ST(next_i));
                SwitchBit(cf.Flags, CF_INITTOLOGFONTSTRUCT, 1);
            }
            if(strcmp(option, "-clipprecision") == 0) {
                next_i = i + 1;
                lf.lfClipPrecision = (BYTE) SvIV(ST(next_i));
                SwitchBit(cf.Flags, CF_INITTOLOGFONTSTRUCT, 1);
            }
            if(strcmp(option, "-quality") == 0) {
                next_i = i + 1;
                lf.lfQuality = (BYTE) SvIV(ST(next_i));
                SwitchBit(cf.Flags, CF_INITTOLOGFONTSTRUCT, 1);
            }
            if(strcmp(option, "-family") == 0) {
                next_i = i + 1;
                lf.lfPitchAndFamily = (BYTE) SvIV(ST(next_i));
                SwitchBit(cf.Flags, CF_INITTOLOGFONTSTRUCT, 1);
            }
            if(strcmp(option, "-name") == 0
            || strcmp(option, "-face") == 0) {
                next_i = i + 1;
                strncpy(lf.lfFaceName, SvPV_nolen(ST(next_i)), 32);
                SwitchBit(cf.Flags, CF_INITTOLOGFONTSTRUCT, 1);
            }
            if(strcmp(option, "-color") == 0) {
                next_i = i + 1;
                cf.rgbColors = (DWORD) SvCOLORREF(NOTXSCALL ST(next_i));
                SwitchBit(cf.Flags, CF_EFFECTS, 1);
            }
            if(strcmp(option, "-ttonly") == 0) {
                next_i = i + 1;
                SwitchBit(cf.Flags, CF_TTONLY, SvIV(ST(next_i)));
            }
            if(strcmp(option, "-fixedonly") == 0) {
                next_i = i + 1;
                SwitchBit(cf.Flags, CF_FIXEDPITCHONLY, SvIV(ST(next_i)));
            }
            if(strcmp(option, "-effects") == 0) {
                next_i = i + 1;
                SwitchBit(cf.Flags, CF_EFFECTS, SvIV(ST(next_i)));
            }
            if(strcmp(option, "-script") == 0) {
                next_i = i + 1;
                if(SvIV(ST(next_i)) == 0) {
                    SwitchBit(cf.Flags, CF_NOSCRIPTSEL, 1);
                } else {
                    SwitchBit(cf.Flags, CF_NOSCRIPTSEL, 0);
                }
            }
            if(strcmp(option, "-minsize") == 0) {
                next_i = i + 1;
                cf.nSizeMin = (INT)SvIV(ST(next_i));
                SwitchBit(cf.Flags, CF_LIMITSIZE, 1);
            }
            if(strcmp(option, "-maxsize") == 0) {
                next_i = i + 1;
                cf.nSizeMax = (INT)SvIV(ST(next_i));
                SwitchBit(cf.Flags, CF_LIMITSIZE, 1);
            }


        } else {
            next_i = -1;
        }
    }
    retval = ChooseFont(&cf);
    if(retval) {

        HDC hDisplay;
        hDisplay = CreateDC("DISPLAY", NULL, NULL, NULL);
        lf.lfHeight = -MulDiv(lf.lfHeight, 72, GetDeviceCaps(hDisplay, LOGPIXELSY));
        DeleteDC(hDisplay);

        EXTEND(SP, 18);
        XST_mPV( 0, "-name");
        XST_mPV( 1, lf.lfFaceName);
        XST_mPV( 2, "-height");
        XST_mIV( 3, lf.lfHeight);
        XST_mPV( 4, "-width");
        XST_mIV( 5, lf.lfWidth);
        XST_mPV( 6, "-weight");
        XST_mIV( 7, lf.lfWeight);
        XST_mPV( 8, "-pointsize");
        XST_mIV( 9, cf.iPointSize);
        XST_mPV(10, "-italic");
        XST_mIV(11, lf.lfItalic);
        XST_mPV(12, "-underline");
        XST_mIV(13, lf.lfUnderline);
        XST_mPV(14, "-strikeout");
        XST_mIV(15, lf.lfStrikeOut);
        XST_mPV(16, "-color");
        XST_mIV(17, cf.rgbColors);
        // XST_mPV(18, "-style");
        // XST_mPV(19, cf.lpszStyle);
        // XSRETURN(20);
        XSRETURN(18);
    } else
        XSRETURN_UNDEF;
#line 7585 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI_CommDlgExtendedError); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_CommDlgExtendedError)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    {
	DWORD	RETVAL;
	dXSTARG;
#line 5693 "GUI.xs"
    RETVAL = CommDlgExtendedError();
#line 7603 "GUI.c"
	XSprePUSH;
	PUSHu((UV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_SelectObject); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SelectObject)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, hgdiobj");
    {
	HDC	handle;
	HGDIOBJ	hgdiobj;
	HGDIOBJ	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HDC,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HDC,SvIV(ST(0)))
;

    if(SvROK(ST(1))) {
        SV** out=hv_fetch((HV*)SvRV(ST(1)), "-handle", 7, 0);
        if(out != NULL)
            hgdiobj = INT2PTR(HGDIOBJ,SvIV(*out));
        else
            hgdiobj = NULL;
    } else
       hgdiobj = INT2PTR(HGDIOBJ,SvIV(ST(1)))
;
#line 5703 "GUI.xs"
    RETVAL = SelectObject(handle, hgdiobj);
#line 7644 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_DeleteObject); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_DeleteObject)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "hgdiobj");
    {
	HGDIOBJ	hgdiobj;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            hgdiobj = INT2PTR(HGDIOBJ,SvIV(*out));
        else
            hgdiobj = NULL;
    } else
       hgdiobj = INT2PTR(HGDIOBJ,SvIV(ST(0)))
;
#line 5711 "GUI.xs"
    RETVAL = DeleteObject(hgdiobj);
#line 7674 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetStockObject); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetStockObject)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "object");
    {
	int	object = (int)SvIV(ST(0))
;
	HGDIOBJ	RETVAL;
	dXSTARG;
#line 5754 "GUI.xs"
    RETVAL = GetStockObject(object);
#line 7695 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_CreateAcceleratorTable); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_CreateAcceleratorTable)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    {
#line 5767 "GUI.xs"
    LPACCEL acc;
    int a, c, i;
#line 7713 "GUI.c"
	HACCEL	RETVAL;
	dXSTARG;
#line 5770 "GUI.xs"
    a = items/3;
    acc = (LPACCEL) safemalloc(a * sizeof(ACCEL));
    c = 0;
    for(i=0; i<items; i+=3) {
        acc[c].cmd   = (WORD) SvIV(ST(i));
        acc[c].key   = (WORD) SvIV(ST(i+1));
        acc[c].fVirt = (BYTE) SvIV(ST(i+2));
        c++;
    }
    RETVAL = CreateAcceleratorTable(acc, a);
#line 7727 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_DestroyAcceleratorTable); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_DestroyAcceleratorTable)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HACCEL	handle = INT2PTR(HACCEL,SvIV(ST(0)))
;
	BOOL	RETVAL;
	dXSTARG;
#line 5790 "GUI.xs"
    RETVAL = DestroyAcceleratorTable(handle);
#line 7748 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_CreateMenu); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_CreateMenu)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    {
	HMENU	RETVAL;
	dXSTARG;
#line 5805 "GUI.xs"
    RETVAL = CreateMenu();
#line 7767 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_CreatePopupMenu); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_CreatePopupMenu)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    {
	HMENU	RETVAL;
	dXSTARG;
#line 5815 "GUI.xs"
    RETVAL = CreatePopupMenu();
#line 7786 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_SetMenu); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_SetMenu)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "handle, menu");
    {
	HWND	handle;
	HMENU	menu;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;

    if(SvROK(ST(1))) {
        SV** out=hv_fetch((HV*)SvRV(ST(1)), "-handle", 7, 0);
        if(out != NULL)
            menu = INT2PTR(HMENU,SvIV(*out));
        else
            menu = NULL;
    } else
       menu = INT2PTR(HMENU,SvIV(ST(1)))
;
#line 5828 "GUI.xs"
    RETVAL = SetMenu(handle, menu);
#line 7827 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetMenu); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetMenu)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	HMENU	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 5840 "GUI.xs"
    RETVAL = GetMenu(handle);
#line 7857 "GUI.c"
	XSprePUSH;
	PUSHi(PTR2IV(RETVAL));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_DrawMenuBar); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_DrawMenuBar)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HWND	handle;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HWND,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HWND,SvIV(ST(0)))
;
#line 5852 "GUI.xs"
    RETVAL = DrawMenuBar(handle);
#line 7887 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_DestroyMenu); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_DestroyMenu)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "hmenu");
    {
	HMENU	hmenu;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            hmenu = INT2PTR(HMENU,SvIV(*out));
        else
            hmenu = NULL;
    } else
       hmenu = INT2PTR(HMENU,SvIV(ST(0)))
;
#line 5863 "GUI.xs"
    RETVAL = DestroyMenu(hmenu);
#line 7917 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI_GetDllVersion); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI_GetDllVersion)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "filename");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	LPTSTR	filename = (LPTSTR)SvPV_nolen(ST(0))
;
#line 5878 "GUI.xs"
    HINSTANCE hinstDll;
    DWORD major = 0xFFFFFFFF;
    DWORD minor = 0xFFFFFFFF;
    DWORD build = 0xFFFFFFFF;
#line 7941 "GUI.c"
#line 5883 "GUI.xs"
    hinstDll = LoadLibrary(filename);

    if(hinstDll) {
        DLLGETVERSIONPROC pDllGetVersion;
        pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hinstDll,"DllGetVersion");

        if(pDllGetVersion) {
            DLLVERSIONINFO dvi;
            HRESULT hr;

            ZeroMemory(&dvi, sizeof(dvi));
            dvi.cbSize = sizeof(dvi);

            hr = (*pDllGetVersion)(&dvi);

            if(SUCCEEDED(hr)) {
                major = dvi.dwMajorVersion;
                minor = dvi.dwMinorVersion;
                build = dvi.dwBuildNumber;
            }
        }

        FreeLibrary(hinstDll);
    }

    if(major == 0xFFFFFFFF) {
        DWORD size;
        DWORD handle;
        char *data;

        size = GetFileVersionInfoSize(filename, &handle);
        if(size) {
            New(0, data, size, char);
            if(data) {
                if(GetFileVersionInfo(filename, handle, size, data)) {
                    VS_FIXEDFILEINFO *info;
                    UINT len;
                    if(VerQueryValue(data, "\\", (void**)&info, &len)) {
                        major = (info->dwFileVersionMS>>16);
                        minor = (info->dwFileVersionMS&0xffff);
                        build = (info->dwFileVersionLS>>16);
		    }
		}

                Safefree(data);
	    }
	}
    }

    if(major == 0xFFFFFFFF) {
	    XSRETURN_UNDEF;
    }

    if (GIMME_V == G_ARRAY) {
        EXTEND(SP, 3);
        XST_mIV(0, major);
        XST_mIV(1, minor);
        XST_mIV(2, build);
	items = 3;
    }
    else {
       char version[50];
       sprintf(version, "%d.%d.%d", major, minor, build);
       XST_mPV(0, version);
       items = 1;
    }
    XSRETURN(items);
#line 8010 "GUI.c"
	PUTBACK;
	return;
    }
}

#pragma message( "*** PACKAGE Win32::GUI::Menu..." )

XS_EUPXS(XS_Win32__GUI__Menu_RemoveMenu); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI__Menu_RemoveMenu)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 3)
       croak_xs_usage(cv,  "menu, position, flags=MF_BYPOSITION");
    {
	HMENU	menu;
	UINT	position = (UINT)SvUV(ST(1))
;
	UINT	flags;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            menu = INT2PTR(HMENU,SvIV(*out));
        else
            menu = NULL;
    } else
       menu = INT2PTR(HMENU,SvIV(ST(0)))
;

	if (items < 3)
	    flags = MF_BYPOSITION;
	else {
	    flags = (UINT)SvUV(ST(2))
;
	}
#line 5980 "GUI.xs"
    RETVAL = RemoveMenu(menu, position, flags);
#line 8050 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Win32__GUI__Menu_DESTROY); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI__Menu_DESTROY)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "handle");
    {
	HMENU	handle;
	BOOL	RETVAL;
	dXSTARG;

    if(SvROK(ST(0))) {
        SV** out=hv_fetch((HV*)SvRV(ST(0)), "-handle", 7, 0);
        if(out != NULL)
            handle = INT2PTR(HMENU,SvIV(*out));
        else
            handle = NULL;
    } else
       handle = INT2PTR(HMENU,SvIV(ST(0)))
;
#line 5990 "GUI.xs"
    RETVAL = DestroyMenu(handle);
#line 8080 "GUI.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}

#pragma message( "*** PACKAGE Win32::GUI::MenuButton..." )

XS_EUPXS(XS_Win32__GUI__MenuButton_InsertMenuItem); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI__MenuButton_InsertMenuItem)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 6008 "GUI.xs"
    MENUITEMINFO mii;
    LPPERLWIN32GUI_MENUITEMDATA perlmid;
    UINT myItem;
    BOOL RETVAL;
#line 8103 "GUI.c"
#line 6013 "GUI.xs"
    ZeroMemory(&mii, sizeof(MENUITEMINFO));
    mii.cbSize = sizeof(MENUITEMINFO);
    myItem = 0;
    Newz(0, perlmid, 1, PERLWIN32GUI_MENUITEMDATA);
    perlmid->dwSize = sizeof(PERLWIN32GUI_MENUITEMDATA);
    perlmid->svCode = newSVsv(&PL_sv_undef);
    ParseMenuItemOptions(NOTXSCALL sp, mark, ax, items, 1, &mii, perlmid, &myItem);
    mii.hbmpChecked = NULL;
    mii.hbmpUnchecked = NULL;
#ifdef PERLWIN32GUI_STRONGDEBUG
    printf("XS(InsertMenuItem) doing InsertMenuItem (HMENU=0x%x)...\n", handle_From(NOTXSCALL ST(0)));
#endif
    RETVAL = InsertMenuItem(
        (HMENU) handle_From(NOTXSCALL ST(0)),
        myItem,
        FALSE,
        &mii
    );
#ifdef PERLWIN32GUI_STRONGDEBUG
    printf("XS(InsertMenuItem) done InsertMenuItem (RETVAL=%d)\n", RETVAL);
#endif
    XSRETURN_IV(RETVAL);
#line 8127 "GUI.c"
	PUTBACK;
	return;
    }
}

#pragma message( "*** PACKAGE Win32::GUI::MenuItem..." )

XS_EUPXS(XS_Win32__GUI__MenuItem_Change); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI__MenuItem_Change)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 6051 "GUI.xs"
    MENUITEMINFO myMII;
    LPPERLWIN32GUI_MENUITEMDATA perlmid;
    UINT myItem;
    HMENU hMenu;
    SV** parentmenu;
    char tmpmenutext[1024];
    if(SvROK(ST(0))) {
        parentmenu = hv_fetch((HV*)SvRV((ST(0))), "-menu", 5, 0);
        if(parentmenu != NULL) {
            hMenu = INT2PTR(HMENU,SvIV(*parentmenu));
            myItem = (UINT)SvIV(*(hv_fetch((HV*)SvRV(ST(0)), "-id", 3, 0)));
        } else {
            hMenu = (HMENU) handle_From(NOTXSCALL ST(0));
        }
    }
#ifdef PERLWIN32GUI_DEBUG
        printf("XS(MenuItem::Change): hMenu=0x%x, myItem=%d\n", hMenu, myItem);
#endif
    ZeroMemory(&myMII, sizeof(MENUITEMINFO));
    myMII.cbSize = sizeof(MENUITEMINFO);
    myMII.fMask = MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE | MIIM_DATA;
    myMII.dwTypeData = tmpmenutext;
    myMII.cch = 1024;
    if(GetMenuItemInfo(hMenu, myItem, FALSE, &myMII)) {
        perlmid = (LPPERLWIN32GUI_MENUITEMDATA) myMII.dwItemData;
        myMII.fMask = 0;
        ParseMenuItemOptions(NOTXSCALL sp, mark, ax, items, 1, &myMII, perlmid, &myItem);
        myMII.hbmpChecked = NULL;
        myMII.hbmpUnchecked = NULL;
        XSRETURN_IV(
            SetMenuItemInfo(hMenu, myItem, FALSE, &myMII)
        );
    } else
        XSRETURN_UNDEF;
#line 8179 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI__MenuItem_Checked); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI__MenuItem_Checked)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 6093 "GUI.xs"
    MENUITEMINFO myMII;
    int i;
    UINT myItem;
    HMENU hMenu;
    SV** parentmenu;

    if(SvROK(ST(0))) {
        parentmenu = hv_fetch((HV*)SvRV((ST(0))), "-menu", 5, 0);
        if(parentmenu != NULL) {
            hMenu = INT2PTR(HMENU,SvIV(*parentmenu));
            myItem = (UINT)SvIV(*(hv_fetch((HV*)SvRV(ST(0)), "-id", 3, 0)));
            i = 1;
        } else {
            hMenu = (HMENU) handle_From(NOTXSCALL ST(0));
            myItem = (UINT)SvIV(ST(1));
            i = 2;
        }
    }
    ZeroMemory(&myMII, sizeof(MENUITEMINFO));
    myMII.cbSize = sizeof(MENUITEMINFO);
    myMII.fMask = MIIM_STATE;
    if(GetMenuItemInfo(hMenu, myItem, FALSE, &myMII)) {
        if(items > i) {
            myMII.fMask = MIIM_STATE;
            SwitchBit(myMII.fState, MFS_CHECKED, SvIV(ST(i)));
            XSRETURN_IV(
                SetMenuItemInfo(hMenu, myItem, FALSE, &myMII)
            );
        } else {
            XSRETURN_IV((myMII.fState & MFS_CHECKED) ? 1 : 0);
        }
    } else {
        XSRETURN_UNDEF;
    }
#line 8230 "GUI.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Win32__GUI__MenuItem_Enabled); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Win32__GUI__MenuItem_Enabled)
{
    dVAR; dXSARGS;
    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 6140 "GUI.xs"
    MENUITEMINFO myMII;
    int i, x;
    UINT myItem;
    HMENU hMenu;
    SV** parentmenu;

    if(SvROK(ST(0))) {
        parentmenu = hv_fetch((HV*)SvRV((ST(0))), "-menu", 5, 0);
        if(parentmenu != NULL) {
            hMenu = INT2PTR(HMENU,SvIV(*parentmenu));
            myItem = (UINT)SvIV(*(hv_fetch((HV*)SvRV(ST(0)), "-id", 3, 0)));
            i = 1;
        } else {
            hMenu = (HMENU) handle_From(NOTXSCALL ST(0));
            myItem = (UINT)SvIV(ST(1));
            i = 2;
        }
    }
    ZeroMemory(&myMII, sizeof(MENUITEMINFO));
    myMII.cbSize = sizeof(MENUITEMINFO);
    myMII.fMask = MIIM_STATE;
    if(GetMenuItemInfo(hMenu, myItem, FALSE, &myMII)) {
        if(items > i) {
            myMII.fMask = MIIM_STATE;
            x = (SvIV(ST(i))) ? 0 : 1;
            SwitchBit(myMII.fState, MFS_DISABLED, x);
            XSRETURN_IV(
                SetMenuItemInfo(hMenu, myItem, FALSE, &myMII)
            );
        } else {
            XSRETURN_IV((myMII.fState & MFS_DISABLED) ? 0 : 1);
        }
    } else {
        XSRETURN_UNDEF;
    }
#line 8282 "GUI.c"
	PUTBACK;
	return;
    }
}

#ifdef __cplusplus
extern "C"
#endif
XS_EXTERNAL(boot_Win32__GUI); /* prototype to pass -Wmissing-prototypes */
XS_EXTERNAL(boot_Win32__GUI)
{
#if PERL_VERSION_LE(5, 21, 5)
    dVAR; dXSARGS;
#else
    dVAR; dXSBOOTARGSXSAPIVERCHK;
#endif
#if PERL_VERSION_LE(5, 8, 999) /* PERL_VERSION_LT is 5.33+ */
    char* file = __FILE__;
#else
    const char* file = __FILE__;
#endif

    PERL_UNUSED_VAR(file);

    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
#if PERL_VERSION_LE(5, 21, 5)
    XS_VERSION_BOOTCHECK;
#  ifdef XS_APIVERSION_BOOTCHECK
    XS_APIVERSION_BOOTCHECK;
#  endif
#endif

        newXS_deffile("Win32::GUI::_constant", XS_Win32__GUI__constant);
        newXS_deffile("Win32::GUI::GetAsyncKeyState", XS_Win32__GUI_GetAsyncKeyState);
        newXS_deffile("Win32::GUI::GetKeyState", XS_Win32__GUI_GetKeyState);
        newXS_deffile("Win32::GUI::GetKeyboardState", XS_Win32__GUI_GetKeyboardState);
        newXS_deffile("Win32::GUI::LoadLibrary", XS_Win32__GUI_LoadLibrary);
        newXS_deffile("Win32::GUI::FreeLibrary", XS_Win32__GUI_FreeLibrary);
        newXS_deffile("Win32::GUI::GetEvent", XS_Win32__GUI_GetEvent);
        newXS_deffile("Win32::GUI::SetEvent", XS_Win32__GUI_SetEvent);
        newXS_deffile("Win32::GUI::LoadResource", XS_Win32__GUI_LoadResource);
        newXS_deffile("Win32::GUI::GetPerlWindow", XS_Win32__GUI_GetPerlWindow);
        newXS_deffile("Win32::GUI::RegisterClassEx", XS_Win32__GUI_RegisterClassEx);
        newXS_deffile("Win32::GUI::CreateWindowEx", XS_Win32__GUI_CreateWindowEx);
        newXS_deffile("Win32::GUI::Create", XS_Win32__GUI_Create);
        newXS_deffile("Win32::GUI::Change", XS_Win32__GUI_Change);
        newXS_deffile("Win32::GUI::Dialog", XS_Win32__GUI_Dialog);
        newXS_deffile("Win32::GUI::DoEvents", XS_Win32__GUI_DoEvents);
        newXS_deffile("Win32::GUI::DoModal", XS_Win32__GUI_DoModal);
        newXS_deffile("Win32::GUI::Scroll", XS_Win32__GUI_Scroll);
        newXS_deffile("Win32::GUI::ScrollRange", XS_Win32__GUI_ScrollRange);
        newXS_deffile("Win32::GUI::ScrollPage", XS_Win32__GUI_ScrollPage);
        newXS_deffile("Win32::GUI::ScrollPos", XS_Win32__GUI_ScrollPos);
        newXS_deffile("Win32::GUI::LoadCursorFromFile", XS_Win32__GUI_LoadCursorFromFile);
        newXS_deffile("Win32::GUI::LoadCursor", XS_Win32__GUI_LoadCursor);
        newXS_deffile("Win32::GUI::LoadString", XS_Win32__GUI_LoadString);
        newXS_deffile("Win32::GUI::LoadImage", XS_Win32__GUI_LoadImage);
        newXS_deffile("Win32::GUI::DestroyCursor", XS_Win32__GUI_DestroyCursor);
        newXS_deffile("Win32::GUI::SetCursor", XS_Win32__GUI_SetCursor);
        newXS_deffile("Win32::GUI::GetCursor", XS_Win32__GUI_GetCursor);
        newXS_deffile("Win32::GUI::ChangeCursor", XS_Win32__GUI_ChangeCursor);
        newXS_deffile("Win32::GUI::GetCursorPos", XS_Win32__GUI_GetCursorPos);
        newXS_deffile("Win32::GUI::SetCursorPos", XS_Win32__GUI_SetCursorPos);
        newXS_deffile("Win32::GUI::ClipCursor", XS_Win32__GUI_ClipCursor);
        newXS_deffile("Win32::GUI::ChangeIcon", XS_Win32__GUI_ChangeIcon);
        newXS_deffile("Win32::GUI::ChangeSmallIcon", XS_Win32__GUI_ChangeSmallIcon);
        newXS_deffile("Win32::GUI::DestroyIcon", XS_Win32__GUI_DestroyIcon);
        newXS_deffile("Win32::GUI::GetClassName", XS_Win32__GUI_GetClassName);
        newXS_deffile("Win32::GUI::GetParent", XS_Win32__GUI_GetParent);
        newXS_deffile("Win32::GUI::GetWindowObject", XS_Win32__GUI_GetWindowObject);
        newXS_deffile("Win32::GUI::_UserData", XS_Win32__GUI__UserData);
        newXS_deffile("Win32::GUI::FindWindow", XS_Win32__GUI_FindWindow);
        newXS_deffile("Win32::GUI::GetWindowLong", XS_Win32__GUI_GetWindowLong);
        newXS_deffile("Win32::GUI::SetWindowLong", XS_Win32__GUI_SetWindowLong);
        newXS_deffile("Win32::GUI::SetWindowPos", XS_Win32__GUI_SetWindowPos);
        newXS_deffile("Win32::GUI::GetWindow", XS_Win32__GUI_GetWindow);
        newXS_deffile("Win32::GUI::Show", XS_Win32__GUI_Show);
        newXS_deffile("Win32::GUI::_Animate", XS_Win32__GUI__Animate);
        newXS_deffile("Win32::GUI::Hide", XS_Win32__GUI_Hide);
        newXS_deffile("Win32::GUI::Maximize", XS_Win32__GUI_Maximize);
        newXS_deffile("Win32::GUI::SetWindowRgn", XS_Win32__GUI_SetWindowRgn);
        newXS_deffile("Win32::GUI::Update", XS_Win32__GUI_Update);
        newXS_deffile("Win32::GUI::Redraw", XS_Win32__GUI_Redraw);
        newXS_deffile("Win32::GUI::LockWindowUpdate", XS_Win32__GUI_LockWindowUpdate);
        newXS_deffile("Win32::GUI::InvalidateRect", XS_Win32__GUI_InvalidateRect);
        newXS_deffile("Win32::GUI::DestroyWindow", XS_Win32__GUI_DestroyWindow);
        newXS_deffile("Win32::GUI::GetMessage", XS_Win32__GUI_GetMessage);
        newXS_deffile("Win32::GUI::SendMessage", XS_Win32__GUI_SendMessage);
        newXS_deffile("Win32::GUI::PostMessage", XS_Win32__GUI_PostMessage);
        newXS_deffile("Win32::GUI::WaitMessage", XS_Win32__GUI_WaitMessage);
        newXS_deffile("Win32::GUI::SendMessageTimeout", XS_Win32__GUI_SendMessageTimeout);
        newXS_deffile("Win32::GUI::PostQuitMessage", XS_Win32__GUI_PostQuitMessage);
        newXS_deffile("Win32::GUI::PeekMessage", XS_Win32__GUI_PeekMessage);
        newXS_deffile("Win32::GUI::Hook", XS_Win32__GUI_Hook);
        newXS_deffile("Win32::GUI::UnHook", XS_Win32__GUI_UnHook);
        newXS_deffile("Win32::GUI::Result", XS_Win32__GUI_Result);
        newXS_deffile("Win32::GUI::SetFont", XS_Win32__GUI_SetFont);
        newXS_deffile("Win32::GUI::GetFont", XS_Win32__GUI_GetFont);
        newXS_deffile("Win32::GUI::SetRedraw", XS_Win32__GUI_SetRedraw);
        newXS_deffile("Win32::GUI::SetIcon", XS_Win32__GUI_SetIcon);
        cv = newXS_deffile("Win32::GUI::Caption", XS_Win32__GUI_Text);
        XSANY.any_i32 = 1;
        cv = newXS_deffile("Win32::GUI::Text", XS_Win32__GUI_Text);
        XSANY.any_i32 = 0;
        newXS_deffile("Win32::GUI::Move", XS_Win32__GUI_Move);
        newXS_deffile("Win32::GUI::Resize", XS_Win32__GUI_Resize);
        newXS_deffile("Win32::GUI::GetClientRect", XS_Win32__GUI_GetClientRect);
        newXS_deffile("Win32::GUI::GetAbsClientRect", XS_Win32__GUI_GetAbsClientRect);
        newXS_deffile("Win32::GUI::GetWindowRect", XS_Win32__GUI_GetWindowRect);
        newXS_deffile("Win32::GUI::Width", XS_Win32__GUI_Width);
        newXS_deffile("Win32::GUI::Height", XS_Win32__GUI_Height);
        newXS_deffile("Win32::GUI::Left", XS_Win32__GUI_Left);
        newXS_deffile("Win32::GUI::Top", XS_Win32__GUI_Top);
        newXS_deffile("Win32::GUI::AbsLeft", XS_Win32__GUI_AbsLeft);
        newXS_deffile("Win32::GUI::AbsTop", XS_Win32__GUI_AbsTop);
        newXS_deffile("Win32::GUI::ScreenToClient", XS_Win32__GUI_ScreenToClient);
        newXS_deffile("Win32::GUI::ClientToScreen", XS_Win32__GUI_ClientToScreen);
        newXS_deffile("Win32::GUI::ScaleWidth", XS_Win32__GUI_ScaleWidth);
        newXS_deffile("Win32::GUI::ScaleHeight", XS_Win32__GUI_ScaleHeight);
        newXS_deffile("Win32::GUI::BringWindowToTop", XS_Win32__GUI_BringWindowToTop);
        newXS_deffile("Win32::GUI::ArrangeIconicWindows", XS_Win32__GUI_ArrangeIconicWindows);
        newXS_deffile("Win32::GUI::GetDesktopWindow", XS_Win32__GUI_GetDesktopWindow);
        newXS_deffile("Win32::GUI::GetForegroundWindow", XS_Win32__GUI_GetForegroundWindow);
        newXS_deffile("Win32::GUI::SetForegroundWindow", XS_Win32__GUI_SetForegroundWindow);
        newXS_deffile("Win32::GUI::IsZoomed", XS_Win32__GUI_IsZoomed);
        newXS_deffile("Win32::GUI::IsIconic", XS_Win32__GUI_IsIconic);
        newXS_deffile("Win32::GUI::IsWindow", XS_Win32__GUI_IsWindow);
        newXS_deffile("Win32::GUI::IsVisible", XS_Win32__GUI_IsVisible);
        newXS_deffile("Win32::GUI::IsEnabled", XS_Win32__GUI_IsEnabled);
        newXS_deffile("Win32::GUI::Enable", XS_Win32__GUI_Enable);
        newXS_deffile("Win32::GUI::Disable", XS_Win32__GUI_Disable);
        cv = newXS_deffile("Win32::GUI::OpenIcon", XS_Win32__GUI_OpenIcon);
        XSANY.any_i32 = 0;
        cv = newXS_deffile("Win32::GUI::Restore", XS_Win32__GUI_OpenIcon);
        XSANY.any_i32 = 1;
        cv = newXS_deffile("Win32::GUI::CloseWindow", XS_Win32__GUI_CloseWindow);
        XSANY.any_i32 = 0;
        cv = newXS_deffile("Win32::GUI::Minimize", XS_Win32__GUI_CloseWindow);
        XSANY.any_i32 = 1;
        newXS_deffile("Win32::GUI::WindowFromPoint", XS_Win32__GUI_WindowFromPoint);
        newXS_deffile("Win32::GUI::GetTopWindow", XS_Win32__GUI_GetTopWindow);
        newXS_deffile("Win32::GUI::GetActiveWindow", XS_Win32__GUI_GetActiveWindow);
        newXS_deffile("Win32::GUI::SetActiveWindow", XS_Win32__GUI_SetActiveWindow);
        newXS_deffile("Win32::GUI::GetDlgItem", XS_Win32__GUI_GetDlgItem);
        newXS_deffile("Win32::GUI::GetFocus", XS_Win32__GUI_GetFocus);
        newXS_deffile("Win32::GUI::SetFocus", XS_Win32__GUI_SetFocus);
        newXS_deffile("Win32::GUI::SetCapture", XS_Win32__GUI_SetCapture);
        newXS_deffile("Win32::GUI::GetCapture", XS_Win32__GUI_GetCapture);
        newXS_deffile("Win32::GUI::ReleaseCapture", XS_Win32__GUI_ReleaseCapture);
        newXS_deffile("Win32::GUI::ShellExecute", XS_Win32__GUI_ShellExecute);
        newXS_deffile("Win32::GUI::GetWindowThreadProcessId", XS_Win32__GUI_GetWindowThreadProcessId);
        newXS_deffile("Win32::GUI::AttachThreadInput", XS_Win32__GUI_AttachThreadInput);
        newXS_deffile("Win32::GUI::GetTextExtentPoint32", XS_Win32__GUI_GetTextExtentPoint32);
        newXS_deffile("Win32::GUI::TrackPopupMenu", XS_Win32__GUI_TrackPopupMenu);
        newXS_deffile("Win32::GUI::SetTimer", XS_Win32__GUI_SetTimer);
        newXS_deffile("Win32::GUI::KillTimer", XS_Win32__GUI_KillTimer);
        newXS_deffile("Win32::GUI::GetEffectiveClientRect", XS_Win32__GUI_GetEffectiveClientRect);
        newXS_deffile("Win32::GUI::DialogUI", XS_Win32__GUI_DialogUI);
        newXS_deffile("Win32::GUI::TrackMouse", XS_Win32__GUI_TrackMouse);
        newXS_deffile("Win32::GUI::UntrackMouse", XS_Win32__GUI_UntrackMouse);
        newXS_deffile("Win32::GUI::PlayEnhMetaFile", XS_Win32__GUI_PlayEnhMetaFile);
        newXS_deffile("Win32::GUI::PlayWinMetaFile", XS_Win32__GUI_PlayWinMetaFile);
        newXS_deffile("Win32::GUI::CreateEnhMetaFile", XS_Win32__GUI_CreateEnhMetaFile);
        newXS_deffile("Win32::GUI::CloseEnhMetaFile", XS_Win32__GUI_CloseEnhMetaFile);
        newXS_deffile("Win32::GUI::DeleteEnhMetaFile", XS_Win32__GUI_DeleteEnhMetaFile);
        newXS_deffile("Win32::GUI::TextOut", XS_Win32__GUI_TextOut);
        newXS_deffile("Win32::GUI::SetTextColor", XS_Win32__GUI_SetTextColor);
        newXS_deffile("Win32::GUI::GetTextColor", XS_Win32__GUI_GetTextColor);
        newXS_deffile("Win32::GUI::SetBkMode", XS_Win32__GUI_SetBkMode);
        newXS_deffile("Win32::GUI::GetBkMode", XS_Win32__GUI_GetBkMode);
        newXS_deffile("Win32::GUI::MoveTo", XS_Win32__GUI_MoveTo);
        newXS_deffile("Win32::GUI::Circle", XS_Win32__GUI_Circle);
        newXS_deffile("Win32::GUI::LineTo", XS_Win32__GUI_LineTo);
        newXS_deffile("Win32::GUI::BeginPaint", XS_Win32__GUI_BeginPaint);
        newXS_deffile("Win32::GUI::EndPaint", XS_Win32__GUI_EndPaint);
        newXS_deffile("Win32::GUI::SaveBMP", XS_Win32__GUI_SaveBMP);
        newXS_deffile("Win32::GUI::GetFontName", XS_Win32__GUI_GetFontName);
        newXS_deffile("Win32::GUI::EnumMyWindows", XS_Win32__GUI_EnumMyWindows);
        newXS_deffile("Win32::GUI::GetSystemMetrics", XS_Win32__GUI_GetSystemMetrics);
        newXS_deffile("Win32::GUI::MessageBox", XS_Win32__GUI_MessageBox);
        newXS_deffile("Win32::GUI::MessageBeep", XS_Win32__GUI_MessageBeep);
        newXS_deffile("Win32::GUI::GetOpenFileName", XS_Win32__GUI_GetOpenFileName);
        newXS_deffile("Win32::GUI::GetSaveFileName", XS_Win32__GUI_GetSaveFileName);
        newXS_deffile("Win32::GUI::BrowseForFolder", XS_Win32__GUI_BrowseForFolder);
        newXS_deffile("Win32::GUI::ChooseColor", XS_Win32__GUI_ChooseColor);
        newXS_deffile("Win32::GUI::ChooseFont", XS_Win32__GUI_ChooseFont);
        newXS_deffile("Win32::GUI::CommDlgExtendedError", XS_Win32__GUI_CommDlgExtendedError);
        newXS_deffile("Win32::GUI::SelectObject", XS_Win32__GUI_SelectObject);
        newXS_deffile("Win32::GUI::DeleteObject", XS_Win32__GUI_DeleteObject);
        newXS_deffile("Win32::GUI::GetStockObject", XS_Win32__GUI_GetStockObject);
        newXS_deffile("Win32::GUI::CreateAcceleratorTable", XS_Win32__GUI_CreateAcceleratorTable);
        newXS_deffile("Win32::GUI::DestroyAcceleratorTable", XS_Win32__GUI_DestroyAcceleratorTable);
        newXS_deffile("Win32::GUI::CreateMenu", XS_Win32__GUI_CreateMenu);
        newXS_deffile("Win32::GUI::CreatePopupMenu", XS_Win32__GUI_CreatePopupMenu);
        newXS_deffile("Win32::GUI::SetMenu", XS_Win32__GUI_SetMenu);
        newXS_deffile("Win32::GUI::GetMenu", XS_Win32__GUI_GetMenu);
        newXS_deffile("Win32::GUI::DrawMenuBar", XS_Win32__GUI_DrawMenuBar);
        newXS_deffile("Win32::GUI::DestroyMenu", XS_Win32__GUI_DestroyMenu);
        newXS_deffile("Win32::GUI::GetDllVersion", XS_Win32__GUI_GetDllVersion);
        newXS_deffile("Win32::GUI::Menu::RemoveMenu", XS_Win32__GUI__Menu_RemoveMenu);
        newXS_deffile("Win32::GUI::Menu::DESTROY", XS_Win32__GUI__Menu_DESTROY);
        newXS_deffile("Win32::GUI::MenuButton::InsertMenuItem", XS_Win32__GUI__MenuButton_InsertMenuItem);
        newXS_deffile("Win32::GUI::MenuItem::Change", XS_Win32__GUI__MenuItem_Change);
        newXS_deffile("Win32::GUI::MenuItem::Checked", XS_Win32__GUI__MenuItem_Checked);
        newXS_deffile("Win32::GUI::MenuItem::Enabled", XS_Win32__GUI__MenuItem_Enabled);

    /* Initialisation Section */

#line 6179 "GUI.xs"
    {
        INITCOMMONCONTROLSEX icce;
        icce.dwSize = sizeof(INITCOMMONCONTROLSEX);
        icce.dwICC = ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES
                   | ICC_LISTVIEW_CLASSES | ICC_PROGRESS_CLASS
                   | ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES
                   | ICC_UPDOWN_CLASS | ICC_USEREX_CLASSES
                   | ICC_DATE_CLASSES;
        if(!InitCommonControlsEx(&icce)) {
            warn("Win32::GUI: Unable to init common controls!\n");
        }
    }

#line 8506 "GUI.c"

    /* End of Initialisation Section */

#if PERL_VERSION_LE(5, 21, 5)
#  if PERL_VERSION_GE(5, 9, 0)
    if (PL_unitcheckav)
        call_list(PL_scopestack_ix, PL_unitcheckav);
#  endif
    XSRETURN_YES;
#else
    Perl_xs_boot_epilog(aTHX_ ax);
#endif
}

