Sfoglia il codice sorgente

win32maxguiex NG, initial import.

woollybah 9 anni fa
parent
commit
c0962da020

+ 644 - 0
win32maxguiex.mod/common.bmx

@@ -0,0 +1,644 @@
+Strict
+
+Import pub.win32
+
+Import "-lcomdlg32"
+Import "-lole32"
+Import "-loleaut32"
+Import "-luuid"
+Import "-lmsimg32"
+Import "-lshell32"
+Import "-lcomctl32"
+Import "-luxtheme"
+
+'Import "commctrl.h"
+
+Import "*.h"
+Import "mshtmlview.cpp"
+Import "glue.cpp"
+
+
+Extern
+
+	Function bmx_win32maxgui_choosecolor_new:Byte Ptr(parent:Byte Ptr, rgb:Int, customColors:Int Ptr, flags:Int)
+	Function bmx_win32maxgui_choosecolor_ChooseColor:Int(handle:Byte Ptr)
+	Function bmx_win32maxgui_choosecolor_free(handle:Byte Ptr)
+	Function bmx_win32maxgui_choosecolor_rgbResult:Int(handle:Byte Ptr)
+	
+	Function SystemParametersInfoW:Int(uiAction:UInt, uiParam:UInt, pvParam:Byte Ptr, fWinIni:Uint) "win32"
+	Function SetLayeredWindowAttributes:Int(hwnd:Byte Ptr,crKey:Int,bAlpha:Byte,dwFlags:Int) "win32"
+	Function OpenThemeData:Byte Ptr( hwnd:Byte Ptr, lpszClassString:Short Ptr ) "win32"
+	Function CloseThemeData( hTheme:Byte Ptr ) "win32"
+	Function SetWindowTheme:Byte Ptr( pHwnd:Byte Ptr, pThemeStr:Short Ptr, pList:Short Ptr ) "win32"
+	Function IsThemeBackgroundPartiallyTransparent( hTheme:Byte Ptr, iPartId%, iStateId% ) "win32"
+	Function DrawThemeParentBackground:Byte Ptr(hwnd:Byte Ptr,hDC:Byte Ptr,pRect:Int Ptr) "win32"
+	Function DrawThemeBackground:Byte Ptr( hTheme:Byte Ptr, hdc:Byte Ptr, iPartID%, iStateID%, pRect:Int Ptr, pClipRect:Int Ptr) "win32"
+	Function GetThemeBackgroundContentRect:Byte Ptr( hTheme:Byte Ptr, hdc:Byte Ptr, iPartId%, iStateId%, pBoundingRect:Int Ptr, pContentRect:Int Ptr ) "win32"
+
+	Function msHtmlCreate:Byte Ptr( owner:Object,wndclass$w,hwnd:Byte Ptr,flags )
+	Function msHtmlGo( handle:Byte Ptr,url$w )
+	Function msHtmlRun( handle:Byte Ptr,script$w )
+	Function msHtmlSetShape( handle:Byte Ptr,x,y,w,h )
+	Function msHtmlSetVisible( handle:Byte Ptr,visible )
+	Function msHtmlSetEnabled( handle:Byte Ptr,enabled )
+	Function msHtmlActivate(handle:Byte Ptr,cmd)
+	Function msHtmlStatus(handle:Byte Ptr)
+	Function msHtmlHwnd:Byte Ptr(handle:Byte Ptr)
+	Function msHtmlBrowser:Byte Ptr(handle:Byte Ptr)
+	Function mstmlDocument:Byte Ptr(handle:Byte Ptr)
+
+End Extern
+
+' Custom Window Messages
+
+Const WM_MAXGUILISTREFRESH% = WM_APP + $100
+
+'Error Codes
+	
+Const S_OK:Int = 0
+
+Const E_OUTOFMEMORY=$8007000E
+Const E_INVALIDARG=$80070057
+Const E_ACCESSDENIED=$80070005
+
+' WM_SIZE message wParam values
+
+Const SIZE_RESTORED=0
+Const SIZE_MINIMIZED=1
+Const SIZE_MAXIMIZED=2
+Const SIZE_MAXSHOW=3
+Const SIZE_MAXHIDE=4
+
+'Tool-tips
+
+Const TTS_ALWAYSTIP% = $1
+Const TTS_NOPREFIX% = $2
+Const TTS_NOANIMATE% = $10
+Const TTS_NOFADE% = $20
+Const TTS_BALLOON% = $40
+
+Const LPSTR_TEXTCALLBACK% = -1
+'Const TTM_ADDTOOLW% = (WM_USER + 50)
+
+'WM_MENUCHAR Return Constants
+
+Const MNC_IGNORE% = 0
+Const MNC_CLOSE% = 1
+Const MNC_EXECUTE% = 2
+Const MNC_SELECT% = 3
+
+'MK Constants
+
+Const MK_CONTROL% = $8
+Const MK_LBUTTON% = $1
+Const MK_MBUTTON% = $10
+Const MK_RBUTTON% = $2
+Const MK_SHIFT% = $4
+Const MK_XBUTTON1% = $20
+Const MK_XBUTTON2% = $40
+
+
+Const SPI_GETWORKAREA:Int = 48
+Const SPI_GETNONCLIENTMETRICS:Int = 41
+
+'Button Image
+Const BCM_FIRST = $1600
+Const BCM_SETIMAGELIST% = BCM_FIRST+2
+
+Const BUTTON_IMAGELIST_ALIGN_LEFT%		= 0
+Const BUTTON_IMAGELIST_ALIGN_RIGHT%	= 1
+Const BUTTON_IMAGELIST_ALIGN_TOP%		= 2
+Const BUTTON_IMAGELIST_ALIGN_BOTTOM%	= 3
+Const BUTTON_IMAGELIST_ALIGN_CENTER%	= 4
+
+'ComboBox cue-banners
+Const CBM_FIRST = $1700
+Const CB_SETCUEBANNER = CBM_FIRST + 3
+
+'Progress bar colors
+'Const PBM_SETBARCOLOR=WM_USER+9
+Const PBM_SETBKCOLOR=CCM_FIRST+1
+
+'SetBkMode() consts, etc.
+Const LWA_COLORKEY=1
+Const LWA_ALPHA=2
+Const LWA_BOTH=3
+Const TRANSPARENT=1
+Const OPAQUE = 2
+
+'RedrawWindow() flags
+Const RDW_FRAME = $500
+Const RDW_UPDATENOW = $100
+Const RDW_INVALIDATE = $1
+Const RDW_NOCHILDREN = $40
+Const RDW_ALLCHILDREN = $80
+Const RDW_ERASE = $4
+Const RDW_ERASENOW = $200
+
+'ScrollBar constants
+Const OBJID_HSCROLL = $FFFFFFFA
+Const OBJID_VSCROLL = $FFFFFFFB
+Const OBJID_CLIENT = $FFFFFFFC
+
+Const EM_GETSCROLLPOS = WM_USER + 221
+Const EM_SETSCROLLPOS = WM_USER + 222
+Const EM_SETZOOM = WM_USER + 225
+
+'GetDCEx Constants
+Const DCX_WINDOW = $1
+Const DCX_CACHE = $2
+Const DCX_NORESETATTRS = $4
+Const DCX_CLIPCHILDREN = $8
+Const DCX_CLIPSIBLINGS = $10
+Const DCX_PARENTCLIP = $20
+Const DCX_EXCLUDERGN = $40
+Const DCX_INTERSECTRGN = $80
+Const DCX_EXCLUDEUPDATE = $100
+Const DCX_INTERSECTUPDATE = $200
+Const DCX_LOCKWINDOWUPDATE = $400
+Const DCX_VALIDATE = $200000
+
+Const WM_THEMECHANGED = $31A
+
+'Icon Stuff
+
+'Const LR_DEFAULTSIZE = $40
+
+'Type ICONINFO
+'Field fIcon
+'Field xHotspot
+'Field yHotspot
+'Field hbmMask
+'Field hbmColor
+'EndType
+
+'Treeview Consts
+
+Const TVM_FIRST = $1100
+Const TVS_EX_DOUBLEBUFFER = $4
+Const TVS_EX_FADEINOUTEXPANDOS = $40
+Const TVM_SETEXTENDEDSTYLE = TVM_FIRST + 44
+
+Const TTN_GETDISPINFOW = -530
+
+'System State Contstants
+
+Const STATE_SYSTEM_UNAVAILABLE = $00000001
+Const STATE_SYSTEM_SELECTED = $00000002
+Const STATE_SYSTEM_FOCUSED = $00000004
+Const STATE_SYSTEM_PRESSED = $00000008
+Const STATE_SYSTEM_CHECKED = $00000010
+Const STATE_SYSTEM_MIXED = $00000020
+Const STATE_SYSTEM_READONLY = $00000040
+Const STATE_SYSTEM_HOTTRACKED = $00000080
+Const STATE_SYSTEM_DEFAULT = $00000100
+Const STATE_SYSTEM_EXPANDED = $00000200
+Const STATE_SYSTEM_COLLAPSED = $00000400
+Const STATE_SYSTEM_BUSY = $00000800
+Const STATE_SYSTEM_FLOATING = $00001000
+Const STATE_SYSTEM_MARQUEED = $00002000
+Const STATE_SYSTEM_ANIMATED = $00004000
+Const STATE_SYSTEM_INVISIBLE = $00008000
+Const STATE_SYSTEM_OFFSCREEN = $00010000
+Const STATE_SYSTEM_SIZEABLE = $00020000
+Const STATE_SYSTEM_MOVEABLE = $00040000
+Const STATE_SYSTEM_SELFVOICING = $00080000
+Const STATE_SYSTEM_FOCUSABLE = $00100000
+Const STATE_SYSTEM_SELECTABLE = $00200000
+Const STATE_SYSTEM_LINKED = $00400000
+Const STATE_SYSTEM_TRAVERSED = $00800000
+Const STATE_SYSTEM_MULTISELECTABLE = $01000000
+Const STATE_SYSTEM_EXTSELECTABLE = $02000000
+Const STATE_SYSTEM_ALERT_LOW = $04000000
+Const STATE_SYSTEM_ALERT_MEDIUM = $08000000
+Const STATE_SYSTEM_ALERT_HIGH = $10000000
+Const STATE_SYSTEM_VALID = $1FFFFFFF
+
+
+'System Metrics
+
+Const SM_CXSCREEN = 0
+Const SM_CYSCREEN = 1
+Const SM_CXVSCROLL = 2
+Const SM_CYHSCROLL = 3
+Const SM_CYCAPTION = 4
+Const SM_CXBORDER = 5
+Const SM_CYBORDER = 6
+Const SM_CXDLGFRAME = 7
+Const SM_CYDLGFRAME = 8
+Const SM_CYVTHUMB = 9
+Const SM_CXHTHUMB = 10
+Const SM_CXICON = 11
+Const SM_CYICON = 12
+Const SM_CXCURSOR = 13
+Const SM_CYCURSOR = 14
+Const SM_CYMENU = 15
+Const SM_CXFULLSCREEN = 16
+Const SM_CYFULLSCREEN = 17
+Const SM_CYKANJIWINDOW = 18
+Const SM_MOUSEPRESENT = 19
+Const SM_CYVSCROLL = 20
+Const SM_CXHSCROLL = 21
+Const SM_DEBUG = 22
+Const SM_SWAPBUTTON = 23
+Const SM_RESERVED1 = 24
+Const SM_RESERVED2 = 25
+Const SM_RESERVED3 = 26
+Const SM_RESERVED4 = 27
+Const SM_CXMIN = 28
+Const SM_CYMIN = 29
+Const SM_CXSIZE = 30
+Const SM_CYSIZE = 31
+Const SM_CXFRAME = 32
+Const SM_CYFRAME = 33
+Const SM_CXMINTRACK = 34
+Const SM_CYMINTRACK = 35
+Const SM_CXDOUBLECLK = 36
+Const SM_CYDOUBLECLK = 37
+Const SM_CXICONSPACING = 38
+Const SM_CYICONSPACING = 39
+Const SM_MENUDROPALIGNMENT = 40
+Const SM_PENWINDOWS = 41
+Const SM_DBCSENABLED = 42
+Const SM_CMOUSEBUTTONS = 43
+Const SM_CXFIXEDFRAME = SM_CXDLGFRAME
+Const SM_CYFIXEDFRAME = SM_CYDLGFRAME
+Const SM_CXSIZEFRAME = SM_CXFRAME
+Const SM_CYSIZEFRAME = SM_CYFRAME
+Const SM_SECURE = 44
+Const SM_CXEDGE = 45
+Const SM_CYEDGE = 46
+Const SM_CXMINSPACING = 47
+Const SM_CYMINSPACING = 48
+Const SM_CXSMICON = 49
+Const SM_CYSMICON = 50
+Const SM_CYSMCAPTION = 51
+Const SM_CXSMSIZE = 52
+Const SM_CYSMSIZE = 53
+Const SM_CXMENUSIZE = 54
+Const SM_CYMENUSIZE = 55
+Const SM_ARRANGE = 56
+Const SM_CXMINIMIZED = 57
+Const SM_CYMINIMIZED = 58
+Const SM_CXMAXTRACK = 59
+Const SM_CYMAXTRACK = 60
+Const SM_CXMAXIMIZED = 61
+Const SM_CYMAXIMIZED = 62
+Const SM_NETWORK = 63
+Const SM_CLEANBOOT = 67
+Const SM_CXDRAG = 68
+Const SM_CYDRAG = 69
+Const SM_SHOWSOUNDS = 70
+Const SM_CXMENUCHECK = 71
+Const SM_CYMENUCHECK = 72
+Const SM_SLOWMACHINE = 73
+Const SM_MIDEASTENABLED = 74
+Const SM_MOUSEWHEELPRESENT = 75
+Const SM_XVIRTUALSCREEN = 76
+Const SM_YVIRTUALSCREEN = 77
+Const SM_CXVIRTUALSCREEN = 78
+Const SM_CYVIRTUALSCREEN = 79
+Const SM_CMONITORS = 80
+Const SM_SAMEDISPLAYFORMAT = 81
+Const SM_CMETRICS = 83
+
+
+
+'External functions
+Extern "Win32"
+	
+'		Function GetCharABCWidthsW(dc,firstcharcode,lastcharcode,widths:Int Ptr Ptr)
+	Function GetCharABCWidthsW(dc:Byte Ptr,firstcharcode:UInt,lastcharcode:UInt,widths:Int Ptr)
+
+	Function GetCharWidth32W(hdc:Byte Ptr,first:Uint,last:UInt,widths:Int Ptr)
+	
+	'BRL.System
+	'Function _TrackMouseEvent( trackmouseeventstrunct:Byte Ptr )
+	
+	'Imagelists and pixmap conversion
+	'Function ImageList_Add(himl:Byte Ptr,hbmImage:Byte Ptr,crMask)
+	'Function ImageList_Destroy( hImageList:Byte Ptr )
+	'Function ImageList_GetImageCount( hImageList:Byte Ptr )
+	Function CreateDIBSection(hdc:Byte Ptr,bminfo:Byte Ptr,iUsage,bits:Byte Ptr Ptr,hSection,dwOffset)
+	Function AlphaBlend_(hdc:Byte Ptr,dx,dy,dw,dh,hdc2:Byte Ptr,src,sry,srcw,srch,rop)="AlphaBlendArgs"
+	Function SendMessageSetImageList(hwnd:Byte Ptr, _buttonImageList:Byte Ptr Ptr, _imageAlign:Int)
+	
+	'WM_CTLCOLORXXXX handling
+	Function SetBkMode( hdc:Byte Ptr, mode)
+	Function SetBkColor( hdc:Byte Ptr, crColor )
+	Function GetAncestor_:Byte Ptr( hwnd:Byte Ptr, gaFlags ) = "GetAncestor"
+	Function SetTextColor_( hdc:Byte Ptr, crColor ) = "SetTextColor"
+	
+	'Drawing Contexts
+	Function GetObjectW( hgdiobj:Byte Ptr, cbBuffer, lpvObject:Byte Ptr )
+	Function SaveDC( hdc:Byte Ptr )
+	Function RestoreDC( hdc:Byte Ptr, savestate )
+	Function CreatePatternBrush:Byte Ptr( bitmap:Byte Ptr )
+	Function GetDCEx:Byte Ptr( hwnd:Byte Ptr, hRgn:Byte Ptr, flags )
+	Function ReleaseDC( hwnd:Byte Ptr, hdc:Byte Ptr )
+	Function GetDCOrgEx( hdc:Byte Ptr, point:Int Ptr )
+	Function GetWindowOrgEx( hdc:Byte Ptr, point:Int Ptr )
+	Function GetWindowExtEx( hdc:Byte Ptr, size:Int Ptr )
+
+	'Drawing
+	Function DrawTextW( hdc:Byte Ptr, lpString$w, nCount, lpRect:Int Ptr, uFormat )
+	Function DrawFocusRect( hdc:Byte Ptr, lprc:Int Ptr )
+	Function DrawFrameControl( hdc:Byte Ptr, lprc:Int Ptr, uType%, uState% )
+	Function ExtTextOutW( hdc:Byte Ptr, x, y, fuOptions, lpRc:Int Ptr, lpString$w, cbCount, lpDx:Int Ptr )
+	
+	'Resizing
+	Function BeginDeferWindowPos:Byte Ptr( nCount )
+	Function EndDeferWindowPos( hdwpStruct:Byte Ptr )
+	Function DeferWindowPos:Byte Ptr( hWinPosInfo:Byte Ptr, hWnd:Byte Ptr, hWndInsertAfter:Byte Ptr, x, y, cx, cy, uFlags)
+	
+	'Position and regions
+	Function IsRectEmpty( rect:Int Ptr )
+	Function GetClipBox( hdc:Byte Ptr, rect:Int Ptr)
+	Function GetUpdateRect( hwnd:Byte Ptr, rect:Int Ptr, pErase )
+	Function ScreenToClient( hwnd:Byte Ptr, rect:Int Ptr )
+	Function RedrawWindow(hwnd:Byte Ptr, lprcUpdate:Int Ptr, hrgnUpdate:Int Ptr, flags )
+	Function FrameRect( hdc:Byte Ptr, rect:Int Ptr, hBrush:Byte Ptr )
+	Function InflateRect( rect:Int Ptr, dx, dy )
+	Function OffsetRect( rect:Int Ptr, dx, dy )
+	Function IntersectRect( lprcDest:Int Ptr, lprcSrc1:Int Ptr, lprcSrc2:Int Ptr )
+	Function CopyRect( dest:Int Ptr, src:Int Ptr )
+	Function GDISetRect( rect:Int Ptr, xLeft, yTop, xRight, yBottom ) = "SetRect"
+	
+	'Menu Stuff
+	Function GetMenu_:Byte Ptr( hwnd:Byte Ptr ) = "GetMenu"
+	Function SetMenuItemBitmaps( hMenu:Byte Ptr, uPosition, uFlags, hBitmapUnchecked:Byte Ptr, hBitmapChecked:Byte Ptr )
+	Function SetMenuInfo( hMenu:Byte Ptr, lpcMenuInfo:Byte Ptr )
+	Function GetSysColor( hColor )
+	
+	'Scroll-bar fixes
+	Function GetSystemMetrics( metric )
+	Function GetScrollBarInfo( hwnd:Byte Ptr, idObject, pScrollBarInfo:Int Ptr )
+	
+	'Gadget text retrieval
+	Function GetWindowTextLengthW( hwnd:Byte Ptr )
+	Function GetWindowTextW( hwnd:Byte Ptr, lpString:Short Ptr, nMaxCount)
+	
+	'Missing misc. system functions
+	Function GetCursor:Byte Ptr()
+	Function GetClassNameW%( pHwnd:Byte Ptr, pTextOut:Short Ptr, pTextLength% )
+	Function GetLastError()
+	Function FreeLibrary( hLibrary:Byte Ptr )
+	
+	'Printing functions for text-area GadgetPrint()
+	Function PrintDlg( printDialogStruct:Byte Ptr ) = "PrintDlgW"
+	Function StartDocW( hdc:Byte Ptr, pDocStruct:Byte Ptr )
+	Function EndDoc( hdc:Byte Ptr )
+	Function AbortDoc( hdc:Byte Ptr )
+	Function StartPage( hdc:Byte Ptr )
+	Function EndPage( hdc:Byte Ptr )
+	Function SetMapMode( hdc:Byte Ptr, pMode )
+	Function PrintWindow( hwnd:Byte Ptr, hdc:Byte Ptr, flags )
+
+	'Icons
+	Function CreateIconIndirect:Byte Ptr(IconInf:Byte Ptr)
+	Function CopyImage:Byte Ptr(hImage:Byte Ptr , uType , xDesired , yDesired , flags)
+	Function DestroyIcon(hIcon:Byte Ptr)
+
+EndExtern
+
+
+Extern
+	Function bmx_win32_DLLVERSIONINFO2_new:Byte Ptr()
+	Function bmx_win32_DLLVERSIONINFO2_free(handle:Byte Ptr)
+	Function bmx_win32_DLLVERSIONINFO2_dwMajorVersion:Int(handle:Byte Ptr)
+	Function bmx_win32_DLLVERSIONINFO2_dwMinorVersion:Int(handle:Byte Ptr)
+	Function bmx_win32_DLLVERSIONINFO2_dwBuildNumber:Int(handle:Byte Ptr)
+End Extern
+
+Type DLLVERSIONINFO2
+	Field infoPtr:Byte Ptr
+
+	Method New()
+		infoPtr = bmx_win32_DLLVERSIONINFO2_new()
+	End Method
+	
+	Method Delete()
+		Free()
+	End Method
+	
+	Method Free()
+		If infoPtr Then
+			bmx_win32_DLLVERSIONINFO2_free(infoPtr)
+			infoPtr = Null
+		End If
+	End Method
+
+	Method dwMajorVersion:Int()
+		Return bmx_win32_DLLVERSIONINFO2_dwMajorVersion(infoPtr)
+	End Method
+	
+	Method dwMinorVersion:Int()
+		Return bmx_win32_DLLVERSIONINFO2_dwMinorVersion(infoPtr)
+	End Method
+	
+	Method dwBuildNumber:Int()
+		Return bmx_win32_DLLVERSIONINFO2_dwBuildNumber(infoPtr)
+	End Method
+
+'	Field cbSize = SizeOf(Self), dwMajorVersion, dwMinorVersion, dwBuildNo, dwPlatformID
+'	Field dwFlags, ulVersion:Long
+EndType
+
+Extern
+	Function bmx_win32_DRAWITEMSTRUCT_new:Byte Ptr()
+	Function bmx_win32_DRAWITEMSTRUCT_free(handle:Byte Ptr)
+	Function bmx_win32_DRAWITEMSTRUCT_CtlType:Uint(handle:Byte Ptr)
+	Function bmx_win32_DRAWITEMSTRUCT_CtlID:Uint(handle:Byte Ptr)
+	Function bmx_win32_DRAWITEMSTRUCT_itemID:Uint(handle:Byte Ptr)
+	Function bmx_win32_DRAWITEMSTRUCT_itemAction:Uint(handle:Byte Ptr)
+	Function bmx_win32_DRAWITEMSTRUCT_hwndItem:Byte Ptr(handle:Byte Ptr)
+	Function bmx_win32_DRAWITEMSTRUCT_hDC:Byte Ptr(handle:Byte Ptr)
+	Function bmx_win32_DRAWITEMSTRUCT_rcItem:Int Ptr(handle:Byte Ptr)
+	Function bmx_win32_DRAWITEMSTRUCT_itemState:UInt(handle:Byte Ptr)
+	Function bmx_win32_DRAWITEMSTRUCT_itemData:Byte Ptr(handle:Byte Ptr)
+End Extern
+'DrawItemStruct
+Type DRAWITEMSTRUCT
+	Field itemPtr:Byte Ptr
+
+	Field _owner:Int = True
+
+	Method New()
+		itemPtr = bmx_win32_DRAWITEMSTRUCT_new()
+	End Method
+	
+	Function _create:DRAWITEMSTRUCT(handle:Byte Ptr)
+		Local this:DRAWITEMSTRUCT = New DRAWITEMSTRUCT
+		this.Free()
+		this._owner = False
+		this.itemPtr = handle
+		Return this
+	End Function
+
+	Method Delete()
+		Free()
+	End Method
+	
+	Method Free()
+		If _owner And itemPtr Then
+			bmx_win32_DRAWITEMSTRUCT_free(itemPtr)
+		End If
+		itemPtr = Null
+	End Method
+
+	Method CtlType:UInt()
+		Return bmx_win32_DRAWITEMSTRUCT_CtlType(itemPtr)
+	End Method
+	
+	Method CtlID:UInt()
+		Return bmx_win32_DRAWITEMSTRUCT_CtlID(itemPtr)
+	End Method
+	
+	Method itemID:UInt()
+		Return bmx_win32_DRAWITEMSTRUCT_itemID(itemPtr)
+	End Method
+	
+	Method itemAction:UInt()
+		Return bmx_win32_DRAWITEMSTRUCT_itemAction(itemPtr)
+	End Method
+	
+	Method hwndItem:Byte Ptr()
+		Return bmx_win32_DRAWITEMSTRUCT_hwndItem(itemPtr)
+	End Method
+	
+	Method hDC:Byte Ptr()
+		Return bmx_win32_DRAWITEMSTRUCT_hDC(itemPtr)
+	End Method
+	
+	Method rcItem:Int Ptr()
+		Return bmx_win32_DRAWITEMSTRUCT_rcItem(itemPtr)
+	End Method
+	
+	Method itemState:UInt()
+		Return bmx_win32_DRAWITEMSTRUCT_itemState(itemPtr)
+	End Method
+	
+	Method itemData:Byte Ptr()
+		Return bmx_win32_DRAWITEMSTRUCT_itemData(itemPtr)
+	End Method
+	
+'	Field CtlType, CtlID, ItemID, ItemAction, ItemState
+'	Field hwndItem, hDC, rcItem_Left, rcItem_Top, rcItem_Right, rcItem_Bottom, itemData
+EndType
+
+'WM_DRAWITEM States
+Const ODS_SELECTED = $1
+Const ODS_GRAYED = $2
+Const ODS_DISABLED = $4
+Const ODS_CHECKED = $8
+Const ODS_FOCUS = $10
+Const ODS_HOTLIGHT = $40
+Const ODS_INACTIVE = $80
+Const ODS_NOACCEL = $100
+Const ODS_NOFOCUSRECT = $200
+
+'DrawThemeBackground Button States
+Const BP_PUSHBUTTON = 1
+Const PBS_NORMAL = 1
+Const PBS_HOT = 2
+Const PBS_PRESSED = 3
+Const PBS_DISABLED = 4
+Const PBS_DEFAULTED = 5
+
+'DrawFrameControl Constants
+Const DFC_BUTTON = $4
+Const DFCS_BUTTONPUSH = $10
+Const DFCS_INACTIVE = $100
+Const DFCS_PUSHED = $200
+Const DFCS_CHECKED = $400
+Const DFCS_TRANSPARENT = $800
+Const DFCS_HOT = $1000
+Const DFCS_ADJUSTRECT = $2000
+Const DFCS_FLAT = $4000
+Const DFCS_MONO = $8000
+
+'DrawText Constants
+Const DT_BOTTOM= $8
+Const DT_CALCRECT= $400
+Const DT_CENTER= $1
+Const DT_EDITCONTROL= $2000
+Const DT_END_ELLIPSIS= $8000
+Const DT_EXPANDTABS = $40
+Const DT_EXTERNALLEADING = $200
+Const DT_HIDEPREFIX = $100000
+Const DT_INTERNAL = $1000
+Const DT_LEFT = $0
+Const DT_MODIFYSTRING = $10000
+Const DT_NOCLIP = $100
+Const DT_NOFULLWIDTHCHARBREAK = $80000
+Const DT_NOPREFIX = $800
+Const DT_NOT_SPECIFIC = $50000
+Const DT_PATH_ELLIPSIS = $4000
+Const DT_PREFIXONLY = $200000
+Const DT_RIGHT = $2
+Const DT_RTLREADING = $20000
+Const DT_SINGLELINE = $20
+Const DT_TABSTOP = $80
+Const DT_TOP = $0
+Const DT_VCENTER = $4
+Const DT_WORD_ELLIPSIS = $40000
+Const DT_WORDBREAK = $10
+
+'TextArea Gadget Printing
+Const MM_TEXT = 1
+
+Extern
+	Function bmx_win32_NONCLIENTMETRICSW_new:Byte Ptr()
+	Function bmx_win32_NONCLIENTMETRICSW_free(handle:Byte Ptr)
+	Function bmx_win32_NONCLIENTMETRICSW_lfMessageFont:Byte Ptr(handle:Byte Ptr)
+End Extern
+Type NONCLIENTMETRICSW
+	Field metricsPtr:Byte Ptr
+	
+	Method New()
+		metricsPtr = bmx_win32_NONCLIENTMETRICSW_new()
+	End Method
+
+	Method Delete()
+		Free()
+	End Method
+	
+	Method Free()
+		If metricsPtr Then
+			bmx_win32_NONCLIENTMETRICSW_free(metricsPtr)
+			metricsPtr = Null
+		End If
+	End Method
+
+	Method lfMessageFont:LOGFONTW()
+		Return LOGFONTW._create(bmx_win32_NONCLIENTMETRICSW_lfMessageFont(metricsPtr))
+	End Method
+	
+End Type
+
+Extern
+	Function bmx_win32_MOUSEHOOKSTRUCT_x:Int(handle:Byte Ptr)
+	Function bmx_win32_MOUSEHOOKSTRUCT_y:Int(handle:Byte Ptr)
+	Function bmx_win32_MOUSEHOOKSTRUCT_hwnd:Byte Ptr(handle:Byte Ptr)
+	Function bmx_win32_MOUSEHOOKSTRUCT_wHitTestCode:UInt(handle:Byte Ptr)
+End Extern
+Type MOUSEHOOKSTRUCT
+	Field hookPtr:Byte Ptr
+
+	Method x:Int()
+		Return bmx_win32_MOUSEHOOKSTRUCT_x(hookPtr)
+	End Method
+	
+	Method y:Int()
+		Return bmx_win32_MOUSEHOOKSTRUCT_y(hookPtr)
+	End Method
+	
+	Method hwnd:Byte Ptr()
+		Return bmx_win32_MOUSEHOOKSTRUCT_hwnd(hookPtr)
+	End Method
+	
+	Method wHitTestCode:UInt()
+		Return bmx_win32_MOUSEHOOKSTRUCT_wHitTestCode(hookPtr)
+	End Method
+	
+End Type

+ 61 - 0
win32maxguiex.mod/common.x

@@ -0,0 +1,61 @@
+WINBOOL __stdcall  SystemParametersInfoW(UINT ,UINT ,PVOID ,UINT )!
+WINBOOL __stdcall SetLayeredWindowAttributes(HWND ,COLORREF ,BYTE ,DWORD )!
+
+WINBOOL __stdcall GetCharABCWidthsW(HDC ,UINT ,UINT ,LPABC )!
+WINBOOL __stdcall GetCharWidth32W(HDC ,UINT ,UINT ,LPINT )!
+HBITMAP __stdcall CreateDIBSection(HDC ,CONST BITMAPINFO *,UINT ,VOID **,HANDLE ,DWORD )!
+int __stdcall SetBkMode(HDC ,int )!
+COLORREF __stdcall SetBkColor(HDC ,COLORREF )!
+HWND __stdcall GetAncestor(HWND ,UINT )!
+COLORREF __stdcall SetTextColor(HDC ,COLORREF )!
+int __stdcall GetObjectW(HANDLE ,int ,LPVOID )!
+int __stdcall SaveDC(HDC )!
+WINBOOL __stdcall RestoreDC(HDC ,int )!
+HBRUSH __stdcall CreatePatternBrush(HBITMAP )!
+HDC __stdcall GetDCEx(HWND ,HRGN ,DWORD )!
+int __stdcall ReleaseDC(HWND ,HDC )!
+WINBOOL __stdcall GetDCOrgEx(HDC ,LPPOINT )!
+WINBOOL __stdcall GetWindowOrgEx(HDC ,LPPOINT )!
+WINBOOL __stdcall GetWindowExtEx(HDC ,LPSIZE )!
+int __stdcall DrawTextW(HDC ,LPCWSTR ,int ,LPRECT ,UINT )!
+WINBOOL __stdcall DrawFocusRect(HDC ,CONST RECT *)!
+WINBOOL __stdcall DrawFrameControl(HDC,LPRECT,UINT,UINT)!
+WINBOOL __stdcall ExtTextOutW(HDC ,int ,int ,UINT ,CONST RECT *,LPCWSTR ,UINT ,CONST INT *)!
+HDWP __stdcall BeginDeferWindowPos(int )!
+WINBOOL __stdcall EndDeferWindowPos(HDWP )!
+HDWP __stdcall DeferWindowPos(HDWP ,HWND ,HWND ,int ,int ,int ,int ,UINT )!
+WINBOOL __stdcall IsRectEmpty(CONST RECT *)!
+int __stdcall GetClipBox(HDC ,LPRECT )!
+WINBOOL __stdcall GetUpdateRect(HWND ,LPRECT ,WINBOOL )!
+WINBOOL __stdcall ScreenToClient(HWND ,LPPOINT )!
+WINBOOL __stdcall RedrawWindow(HWND ,CONST RECT *,HRGN ,UINT )!
+int __stdcall FrameRect(HDC ,CONST RECT *,HBRUSH )!
+WINBOOL __stdcall InflateRect(LPRECT ,int ,int )!
+WINBOOL __stdcall OffsetRect(LPRECT ,int ,int )!
+WINBOOL __stdcall IntersectRect(LPRECT ,CONST RECT *,CONST RECT *)!
+WINBOOL __stdcall CopyRect(LPRECT ,CONST RECT *)!
+WINBOOL __stdcall SetRect(LPRECT ,int ,int ,int ,int )!
+HMENU __stdcall GetMenu(HWND )!
+WINBOOL __stdcall SetMenuItemBitmaps(HMENU ,UINT ,UINT ,HBITMAP ,HBITMAP )!
+WINBOOL __stdcall SetMenuInfo(HMENU,LPCMENUINFO)!
+DWORD __stdcall GetSysColor(int )!
+int __stdcall GetSystemMetrics(int )!
+WINBOOL __stdcall GetScrollBarInfo(HWND ,LONG ,PSCROLLBARINFO )!
+int __stdcall GetWindowTextLengthW(HWND )!
+int __stdcall GetWindowTextW(HWND ,LPWSTR ,int )!
+HCURSOR __stdcall GetCursor()!
+int __stdcall GetClassNameW(HWND ,LPWSTR ,int )!
+DWORD __stdcall GetLastError ()!
+WINBOOL __stdcall FreeLibrary (HMODULE )!
+WINBOOL __stdcall PrintDlgW(LPPRINTDLGW)!
+int __stdcall StartDocW(HDC ,CONST DOCINFOW *)!
+int __stdcall EndDoc(HDC )!
+int __stdcall AbortDoc(HDC )!
+int __stdcall StartPage(HDC )!
+int __stdcall EndPage(HDC )!
+int __stdcall SetMapMode(HDC ,int )!
+WINBOOL __stdcall PrintWindow(HWND ,HDC ,UINT )!
+HICON __stdcall CreateIconIndirect(PICONINFO )!
+HANDLE __stdcall CopyImage(HANDLE ,UINT ,int ,int ,UINT )!
+WINBOOL __stdcall DestroyIcon(HICON )!
+

+ 179 - 0
win32maxguiex.mod/glue.cpp

@@ -0,0 +1,179 @@
+#include "windows.h"
+#include <stdio.h>
+#include <shlwapi.h>
+
+extern "C" {
+
+	CHOOSECOLORW * bmx_win32maxgui_choosecolor_new(HWND parent, int rgb, int * customColors, int flags);
+	int bmx_win32maxgui_choosecolor_ChooseColor(CHOOSECOLORW * cc);
+	void bmx_win32maxgui_choosecolor_free(CHOOSECOLORW * cc);
+	int bmx_win32maxgui_choosecolor_rgbResult(CHOOSECOLORW * cc);
+
+	DLLVERSIONINFO2 * bmx_win32_DLLVERSIONINFO2_new();
+	void bmx_win32_DLLVERSIONINFO2_free(DLLVERSIONINFO2 * info);
+	int bmx_win32_DLLVERSIONINFO2_dwMajorVersion(DLLVERSIONINFO2 * info);
+	int bmx_win32_DLLVERSIONINFO2_dwMinorVersion(DLLVERSIONINFO2 * info);
+	int bmx_win32_DLLVERSIONINFO2_dwBuildNumber(DLLVERSIONINFO2 * info);
+
+	DRAWITEMSTRUCT * bmx_win32_DRAWITEMSTRUCT_new();
+	void bmx_win32_DRAWITEMSTRUCT_free(DRAWITEMSTRUCT * item);
+	UINT bmx_win32_DRAWITEMSTRUCT_CtlType(DRAWITEMSTRUCT * item);
+	UINT bmx_win32_DRAWITEMSTRUCT_CtlID(DRAWITEMSTRUCT * item);
+	UINT bmx_win32_DRAWITEMSTRUCT_itemID(DRAWITEMSTRUCT * item);
+	UINT bmx_win32_DRAWITEMSTRUCT_itemAction(DRAWITEMSTRUCT * item);
+	HWND bmx_win32_DRAWITEMSTRUCT_hwndItem(DRAWITEMSTRUCT * item);
+	HDC bmx_win32_DRAWITEMSTRUCT_hDC(DRAWITEMSTRUCT * item);
+	RECT* bmx_win32_DRAWITEMSTRUCT_rcItem(DRAWITEMSTRUCT * item);
+	UINT bmx_win32_DRAWITEMSTRUCT_itemState(DRAWITEMSTRUCT * item);
+	ULONG_PTR bmx_win32_DRAWITEMSTRUCT_itemData(DRAWITEMSTRUCT * item);
+
+	BOOL AlphaBlendArgs(HDC hdcDest, int xoriginDest, int yoriginDest, int wDest, int hDest, HDC hdcSrc, int xoriginSrc,
+		int yoriginSrc, int wSrc, int hSrc, int blend);
+
+	NONCLIENTMETRICSW * bmx_win32_NONCLIENTMETRICSW_new();
+	void bmx_win32_NONCLIENTMETRICSW_free(NONCLIENTMETRICSW * metrics);
+	LOGFONTW * bmx_win32_NONCLIENTMETRICSW_lfMessageFont(NONCLIENTMETRICSW * metrics);
+
+	int bmx_win32_MOUSEHOOKSTRUCT_x(MOUSEHOOKSTRUCT * hook);
+	int bmx_win32_MOUSEHOOKSTRUCT_y(MOUSEHOOKSTRUCT * hook);
+	HWND bmx_win32_MOUSEHOOKSTRUCT_hwnd(MOUSEHOOKSTRUCT * hook);
+	UINT bmx_win32_MOUSEHOOKSTRUCT_wHitTestCode(MOUSEHOOKSTRUCT * hook);
+}
+
+BOOL AlphaBlendArgs(HDC hdcDest, int xoriginDest, int yoriginDest, int wDest, int hDest, HDC hdcSrc, int xoriginSrc,
+		int yoriginSrc, int wSrc, int hSrc, int blend) {
+
+	BLENDFUNCTION ftn = {(blend & 0xff000000) >> 24, (blend & 0xff0000) >> 16, (blend & 0xff00) >> 8, blend & 0xff};
+	
+	return AlphaBlend(hdcDest, xoriginDest, yoriginDest, wDest, hDest, hdcSrc, xoriginSrc,
+		yoriginSrc, wSrc, hSrc, ftn);
+}
+
+// ********************************************************
+
+
+CHOOSECOLORW * bmx_win32maxgui_choosecolor_new(HWND parent, int rgb, int * customColors, int flags) {
+	CHOOSECOLORW * cc = (CHOOSECOLORW *)malloc(sizeof(CHOOSECOLORW));
+	cc->lStructSize = sizeof(CHOOSECOLORW);
+	cc->hwndOwner = parent;
+	cc->rgbResult = rgb;
+	cc->lpCustColors = (COLORREF*)customColors;
+	cc->Flags = flags;
+	
+	return cc;
+}
+
+int bmx_win32maxgui_choosecolor_ChooseColor(CHOOSECOLORW * cc) {
+	return ChooseColorW(cc);
+}
+
+void bmx_win32maxgui_choosecolor_free(CHOOSECOLORW * cc) {
+	free(cc);
+}
+
+int bmx_win32maxgui_choosecolor_rgbResult(CHOOSECOLORW * cc) {
+	return cc->rgbResult;
+}
+
+// ********************************************************
+
+DLLVERSIONINFO2 * bmx_win32_DLLVERSIONINFO2_new() {
+	DLLVERSIONINFO2 * info = (DLLVERSIONINFO2 *)calloc(1,sizeof(DLLVERSIONINFO2));
+	info->info1.cbSize = sizeof(DLLVERSIONINFO2);
+	return info;
+}
+
+void bmx_win32_DLLVERSIONINFO2_free(DLLVERSIONINFO2 * info) {
+	free(info);
+}
+
+int bmx_win32_DLLVERSIONINFO2_dwMajorVersion(DLLVERSIONINFO2 * info) {
+	return info->info1.dwMajorVersion;
+}
+
+int bmx_win32_DLLVERSIONINFO2_dwMinorVersion(DLLVERSIONINFO2 * info) {
+	return info->info1.dwMinorVersion;
+}
+
+int bmx_win32_DLLVERSIONINFO2_dwBuildNumber(DLLVERSIONINFO2 * info) {
+	return info->info1.dwBuildNumber;
+}
+
+// ********************************************************
+
+DRAWITEMSTRUCT * bmx_win32_DRAWITEMSTRUCT_new() {
+	return (DRAWITEMSTRUCT*)malloc(sizeof(DRAWITEMSTRUCT));
+}
+
+void bmx_win32_DRAWITEMSTRUCT_free(DRAWITEMSTRUCT * item) {
+	free(item);
+}
+
+UINT bmx_win32_DRAWITEMSTRUCT_CtlType(DRAWITEMSTRUCT * item) {
+	return item->CtlType;
+}
+
+UINT bmx_win32_DRAWITEMSTRUCT_CtlID(DRAWITEMSTRUCT * item) {
+	return item->CtlID;
+}
+
+UINT bmx_win32_DRAWITEMSTRUCT_itemID(DRAWITEMSTRUCT * item) {
+	return item->itemID;
+}
+
+UINT bmx_win32_DRAWITEMSTRUCT_itemAction(DRAWITEMSTRUCT * item) {
+	return item->itemAction;
+}
+
+HWND bmx_win32_DRAWITEMSTRUCT_hwndItem(DRAWITEMSTRUCT * item) {
+	return item->hwndItem;
+}
+
+HDC bmx_win32_DRAWITEMSTRUCT_hDC(DRAWITEMSTRUCT * item) {
+	return item->hDC;
+}
+
+RECT* bmx_win32_DRAWITEMSTRUCT_rcItem(DRAWITEMSTRUCT * item) {
+	return &item->rcItem;
+}
+
+UINT bmx_win32_DRAWITEMSTRUCT_itemState(DRAWITEMSTRUCT * item) {
+	return item->itemState;
+}
+
+ULONG_PTR bmx_win32_DRAWITEMSTRUCT_itemData(DRAWITEMSTRUCT * item) {
+	return item->itemData;
+}
+
+// ********************************************************
+
+NONCLIENTMETRICSW * bmx_win32_NONCLIENTMETRICSW_new() {
+	return (NONCLIENTMETRICSW *)calloc(1, sizeof(NONCLIENTMETRICSW));
+}
+
+void bmx_win32_NONCLIENTMETRICSW_free(NONCLIENTMETRICSW * metrics) {
+	free(metrics);
+}
+
+LOGFONTW * bmx_win32_NONCLIENTMETRICSW_lfMessageFont(NONCLIENTMETRICSW * metrics) {
+	return &metrics->lfMessageFont;
+}
+
+// ********************************************************
+
+int bmx_win32_MOUSEHOOKSTRUCT_x(MOUSEHOOKSTRUCT * hook) {
+	return hook->pt.x;
+}
+
+int bmx_win32_MOUSEHOOKSTRUCT_y(MOUSEHOOKSTRUCT * hook) {
+	return hook->pt.y;
+}
+
+HWND bmx_win32_MOUSEHOOKSTRUCT_hwnd(MOUSEHOOKSTRUCT * hook) {
+	return hook->hwnd;
+}
+
+UINT bmx_win32_MOUSEHOOKSTRUCT_wHitTestCode(MOUSEHOOKSTRUCT * hook) {
+	return hook->wHitTestCode;
+}
+

+ 1409 - 0
win32maxguiex.mod/mshtmhst.h

@@ -0,0 +1,1409 @@
+
+#pragma warning( disable: 4049 )  /* more than 64k source lines */
+
+/* this ALWAYS GENERATED file contains the definitions for the interfaces */
+
+
+ /* File created by MIDL compiler version 6.00.0347 */
+/* Compiler settings for mshtmhst.idl:
+    Oicf, W1, Zp8, env=Win32 (32b run)
+    protocol : dce , ms_ext, c_ext
+    error checks: allocation ref bounds_check enum stub_data 
+    VC __declspec() decoration level: 
+         __declspec(uuid()), __declspec(selectany), __declspec(novtable)
+         DECLSPEC_UUID(), MIDL_INTERFACE()
+*/
+//@@MIDL_FILE_HEADING(  )
+
+
+/* verify that the <rpcndr.h> version is high enough to compile this file*/
+#ifndef __REQUIRED_RPCNDR_H_VERSION__
+#define __REQUIRED_RPCNDR_H_VERSION__ 440
+#endif
+
+#include "rpc.h"
+#include "rpcndr.h"
+
+#ifndef __RPCNDR_H_VERSION__
+#error this stub requires an updated version of <rpcndr.h>
+#endif // __RPCNDR_H_VERSION__
+
+#ifndef COM_NO_WINDOWS_H
+#include "windows.h"
+#include "ole2.h"
+#endif /*COM_NO_WINDOWS_H*/
+
+#ifndef __mshtmhst_h__
+#define __mshtmhst_h__
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+#pragma once
+#endif
+
+/* Forward Declarations */ 
+
+#ifndef __IHostDialogHelper_FWD_DEFINED__
+#define __IHostDialogHelper_FWD_DEFINED__
+typedef interface IHostDialogHelper IHostDialogHelper;
+#endif 	/* __IHostDialogHelper_FWD_DEFINED__ */
+
+
+#ifndef __HostDialogHelper_FWD_DEFINED__
+#define __HostDialogHelper_FWD_DEFINED__
+
+#ifdef __cplusplus
+typedef class HostDialogHelper HostDialogHelper;
+#else
+typedef struct HostDialogHelper HostDialogHelper;
+#endif /* __cplusplus */
+
+#endif 	/* __HostDialogHelper_FWD_DEFINED__ */
+
+
+#ifndef __IDocHostUIHandler_FWD_DEFINED__
+#define __IDocHostUIHandler_FWD_DEFINED__
+typedef interface IDocHostUIHandler IDocHostUIHandler;
+#endif 	/* __IDocHostUIHandler_FWD_DEFINED__ */
+
+
+#ifndef __IDocHostUIHandler2_FWD_DEFINED__
+#define __IDocHostUIHandler2_FWD_DEFINED__
+typedef interface IDocHostUIHandler2 IDocHostUIHandler2;
+#endif 	/* __IDocHostUIHandler2_FWD_DEFINED__ */
+
+
+#ifndef __ICustomDoc_FWD_DEFINED__
+#define __ICustomDoc_FWD_DEFINED__
+typedef interface ICustomDoc ICustomDoc;
+#endif 	/* __ICustomDoc_FWD_DEFINED__ */
+
+
+#ifndef __IDocHostShowUI_FWD_DEFINED__
+#define __IDocHostShowUI_FWD_DEFINED__
+typedef interface IDocHostShowUI IDocHostShowUI;
+#endif 	/* __IDocHostShowUI_FWD_DEFINED__ */
+
+
+#ifndef __IClassFactoryEx_FWD_DEFINED__
+#define __IClassFactoryEx_FWD_DEFINED__
+typedef interface IClassFactoryEx IClassFactoryEx;
+#endif 	/* __IClassFactoryEx_FWD_DEFINED__ */
+
+
+/* header files for imported files */
+#include "ocidl.h"
+#include "docobj.h"
+
+#ifdef __cplusplus
+extern "C"{
+#endif 
+
+//void * __RPC_USER MIDL_user_allocate(size_t);
+void __RPC_USER MIDL_user_free( void * ); 
+
+/* interface __MIDL_itf_mshtmhst_0000 */
+/* [local] */ 
+
+//=--------------------------------------------------------------------------=
+// mshtmhst.h
+//=--------------------------------------------------------------------------=
+// (C) Copyright 1995-1998 Microsoft Corporation.  All Rights Reserved.
+//
+// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+// PARTICULAR PURPOSE.
+//=--------------------------------------------------------------------------=
+
+#pragma comment(lib,"uuid.lib")
+
+//--------------------------------------------------------------------------
+// MSTHML Advanced Host Interfaces.
+
+#ifndef MSHTMHST_H
+#define MSHTMHST_H
+#define CONTEXT_MENU_DEFAULT        0
+#define CONTEXT_MENU_IMAGE          1
+#define CONTEXT_MENU_CONTROL        2
+#define CONTEXT_MENU_TABLE          3
+// in browse mode
+#define CONTEXT_MENU_TEXTSELECT     4
+#define CONTEXT_MENU_ANCHOR         5
+#define CONTEXT_MENU_UNKNOWN        6
+//;begin_internal
+// These 2 are mapped to IMAGE for the public
+#define CONTEXT_MENU_IMGDYNSRC      7
+#define CONTEXT_MENU_IMGART         8
+#define CONTEXT_MENU_DEBUG          9
+//;end_internal
+#define CONTEXT_MENU_VSCROLL        10
+#define CONTEXT_MENU_HSCROLL        11
+#define MENUEXT_SHOWDIALOG           0x1
+#define DOCHOSTUIFLAG_BROWSER       DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE 
+#define HTMLDLG_NOUI                     0x10
+#define HTMLDLG_MODAL                    0x20
+#define HTMLDLG_MODELESS                 0x40
+#define HTMLDLG_PRINT_TEMPLATE           0x80
+#define HTMLDLG_VERIFY                   0x100
+#define PRINT_DONTBOTHERUSER             0x01
+#define PRINT_WAITFORCOMPLETION          0x02
+EXTERN_C const GUID CGID_MSHTML;
+#define CMDSETID_Forms3 CGID_MSHTML
+#define SZ_HTML_CLIENTSITE_OBJECTPARAM L"{d4db6850-5385-11d0-89e9-00a0c90a90ac}"
+#ifndef __IHTMLWindow2_FWD_DEFINED__
+#define __IHTMLWindow2_FWD_DEFINED__
+typedef interface IHTMLWindow2 IHTMLWindow2;
+#endif
+typedef HRESULT STDAPICALLTYPE SHOWHTMLDIALOGFN (HWND hwndParent, IMoniker *pmk, VARIANT *pvarArgIn, WCHAR* pchOptions, VARIANT *pvArgOut);
+typedef HRESULT STDAPICALLTYPE SHOWHTMLDIALOGEXFN (HWND hwndParent, IMoniker *pmk, DWORD dwDialogFlags, VARIANT *pvarArgIn, WCHAR* pchOptions, VARIANT *pvArgOut);
+typedef HRESULT STDAPICALLTYPE SHOWMODELESSHTMLDIALOGFN (HWND hwndParent, IMoniker *pmk, VARIANT *pvarArgIn, VARIANT* pvarOptions, IHTMLWindow2 ** ppWindow);
+//;begin_internal
+STDAPI ShowHTMLDialog(                   
+    HWND        hwndParent,              
+    IMoniker *  pMk,                     
+    VARIANT *   pvarArgIn,               
+    WCHAR *     pchOptions,              
+    VARIANT *   pvarArgOut               
+    );                                   
+STDAPI ShowHTMLDialogEx(                 
+    HWND        hwndParent,              
+    IMoniker *  pMk,                     
+    DWORD       dwDialogFlags,           
+    VARIANT *   pvarArgIn,               
+    WCHAR *     pchOptions,              
+    VARIANT *   pvarArgOut               
+    );                                   
+STDAPI ShowModelessHTMLDialog(           
+    HWND        hwndParent,              
+    IMoniker *  pMk,                     
+    VARIANT *   pvarArgIn,               
+    VARIANT *   pvarOptions,             
+    IHTMLWindow2 ** ppWindow);           
+//;end_internal
+//;begin_internal
+STDAPI RunHTMLApplication(               
+    HINSTANCE hinst,                     
+    HINSTANCE hPrevInst,                 
+    LPSTR szCmdLine,                     
+    int nCmdShow                         
+    );                                   
+//;end_internal
+//;begin_internal
+STDAPI CreateHTMLPropertyPage(           
+    IMoniker *          pmk,             
+    IPropertyPage **    ppPP             
+    );                                   
+//;end_internal
+
+
+extern RPC_IF_HANDLE __MIDL_itf_mshtmhst_0000_v0_0_c_ifspec;
+extern RPC_IF_HANDLE __MIDL_itf_mshtmhst_0000_v0_0_s_ifspec;
+
+#ifndef __IHostDialogHelper_INTERFACE_DEFINED__
+#define __IHostDialogHelper_INTERFACE_DEFINED__
+
+/* interface IHostDialogHelper */
+/* [local][unique][uuid][object] */ 
+
+
+EXTERN_C const IID IID_IHostDialogHelper;
+
+#if defined(__cplusplus) && !defined(CINTERFACE)
+    
+    MIDL_INTERFACE("53DEC138-A51E-11d2-861E-00C04FA35C89")
+    IHostDialogHelper : public IUnknown
+    {
+    public:
+        virtual HRESULT STDMETHODCALLTYPE ShowHTMLDialog( 
+            HWND hwndParent,
+            IMoniker *pMk,
+            VARIANT *pvarArgIn,
+            WCHAR *pchOptions,
+            VARIANT *pvarArgOut,
+            IUnknown *punkHost) = 0;
+        
+    };
+    
+#else 	/* C style interface */
+
+    typedef struct IHostDialogHelperVtbl
+    {
+        BEGIN_INTERFACE
+        
+        HRESULT ( STDMETHODCALLTYPE *QueryInterface )( 
+            IHostDialogHelper * This,
+            /* [in] */ REFIID riid,
+            /* [iid_is][out] */ void **ppvObject);
+        
+        ULONG ( STDMETHODCALLTYPE *AddRef )( 
+            IHostDialogHelper * This);
+        
+        ULONG ( STDMETHODCALLTYPE *Release )( 
+            IHostDialogHelper * This);
+        
+        HRESULT ( STDMETHODCALLTYPE *ShowHTMLDialog )( 
+            IHostDialogHelper * This,
+            HWND hwndParent,
+            IMoniker *pMk,
+            VARIANT *pvarArgIn,
+            WCHAR *pchOptions,
+            VARIANT *pvarArgOut,
+            IUnknown *punkHost);
+        
+        END_INTERFACE
+    } IHostDialogHelperVtbl;
+
+    interface IHostDialogHelper
+    {
+        CONST_VTBL struct IHostDialogHelperVtbl *lpVtbl;
+    };
+
+    
+
+#ifdef COBJMACROS
+
+
+#define IHostDialogHelper_QueryInterface(This,riid,ppvObject)	\
+    (This)->lpVtbl -> QueryInterface(This,riid,ppvObject)
+
+#define IHostDialogHelper_AddRef(This)	\
+    (This)->lpVtbl -> AddRef(This)
+
+#define IHostDialogHelper_Release(This)	\
+    (This)->lpVtbl -> Release(This)
+
+
+#define IHostDialogHelper_ShowHTMLDialog(This,hwndParent,pMk,pvarArgIn,pchOptions,pvarArgOut,punkHost)	\
+    (This)->lpVtbl -> ShowHTMLDialog(This,hwndParent,pMk,pvarArgIn,pchOptions,pvarArgOut,punkHost)
+
+#endif /* COBJMACROS */
+
+
+#endif 	/* C style interface */
+
+
+
+HRESULT STDMETHODCALLTYPE IHostDialogHelper_ShowHTMLDialog_Proxy( 
+    IHostDialogHelper * This,
+    HWND hwndParent,
+    IMoniker *pMk,
+    VARIANT *pvarArgIn,
+    WCHAR *pchOptions,
+    VARIANT *pvarArgOut,
+    IUnknown *punkHost);
+
+
+void __RPC_STUB IHostDialogHelper_ShowHTMLDialog_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+
+#endif 	/* __IHostDialogHelper_INTERFACE_DEFINED__ */
+
+
+/* interface __MIDL_itf_mshtmhst_0267 */
+/* [local] */ 
+
+EXTERN_C const GUID CLSID_HostDialogHelper;
+//;begin_internal
+typedef 
+enum tagDOCHOSTUITYPE
+    {	DOCHOSTUITYPE_BROWSE	= 0,
+	DOCHOSTUITYPE_AUTHOR	= 1
+    } 	DOCHOSTUITYPE;
+
+//;end_internal
+typedef 
+enum tagDOCHOSTUIDBLCLK
+    {	DOCHOSTUIDBLCLK_DEFAULT	= 0,
+	DOCHOSTUIDBLCLK_SHOWPROPERTIES	= 1,
+	DOCHOSTUIDBLCLK_SHOWCODE	= 2
+    } 	DOCHOSTUIDBLCLK;
+
+typedef 
+enum tagDOCHOSTUIFLAG
+    {	DOCHOSTUIFLAG_DIALOG	= 0x1,
+	DOCHOSTUIFLAG_DISABLE_HELP_MENU	= 0x2,
+	DOCHOSTUIFLAG_NO3DBORDER	= 0x4,
+	DOCHOSTUIFLAG_SCROLL_NO	= 0x8,
+	DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE	= 0x10,
+	DOCHOSTUIFLAG_OPENNEWWIN	= 0x20,
+	DOCHOSTUIFLAG_DISABLE_OFFSCREEN	= 0x40,
+	DOCHOSTUIFLAG_FLAT_SCROLLBAR	= 0x80,
+	DOCHOSTUIFLAG_DIV_BLOCKDEFAULT	= 0x100,
+	DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY	= 0x200,
+	DOCHOSTUIFLAG_OVERRIDEBEHAVIORFACTORY	= 0x400,
+	DOCHOSTUIFLAG_CODEPAGELINKEDFONTS	= 0x800,
+	DOCHOSTUIFLAG_URL_ENCODING_DISABLE_UTF8	= 0x1000,
+	DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8	= 0x2000,
+	DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE	= 0x4000,
+	DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION	= 0x10000,
+	DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION	= 0x20000,
+	DOCHOSTUIFLAG_THEME	= 0x40000,
+	DOCHOSTUIFLAG_NOTHEME	= 0x80000,
+	DOCHOSTUIFLAG_NOPICS	= 0x100000,
+	DOCHOSTUIFLAG_NO3DOUTERBORDER	= 0x200000,
+	DOCHOSTUIFLAG_DISABLE_EDIT_NS_FIXUP	= 0x400000
+    } 	DOCHOSTUIFLAG;
+
+#define DOCHOSTUIATOM_ENABLE_HIRES	_T("TridentEnableHiRes")
+
+
+extern RPC_IF_HANDLE __MIDL_itf_mshtmhst_0267_v0_0_c_ifspec;
+extern RPC_IF_HANDLE __MIDL_itf_mshtmhst_0267_v0_0_s_ifspec;
+
+#ifndef __IDocHostUIHandler_INTERFACE_DEFINED__
+#define __IDocHostUIHandler_INTERFACE_DEFINED__
+
+/* interface IDocHostUIHandler */
+/* [local][unique][uuid][object] */ 
+
+typedef struct _DOCHOSTUIINFO
+    {
+    ULONG cbSize;
+    DWORD dwFlags;
+    DWORD dwDoubleClick;
+    OLECHAR *pchHostCss;
+    OLECHAR *pchHostNS;
+    } 	DOCHOSTUIINFO;
+
+
+EXTERN_C const IID IID_IDocHostUIHandler;
+
+#if defined(__cplusplus) && !defined(CINTERFACE)
+    
+    MIDL_INTERFACE("bd3f23c0-d43e-11cf-893b-00aa00bdce1a")
+    IDocHostUIHandler : public IUnknown
+    {
+    public:
+        virtual HRESULT STDMETHODCALLTYPE ShowContextMenu( 
+            /* [in] */ DWORD dwID,
+            /* [in] */ POINT *ppt,
+            /* [in] */ IUnknown *pcmdtReserved,
+            /* [in] */ IDispatch *pdispReserved) = 0;
+        
+        virtual HRESULT STDMETHODCALLTYPE GetHostInfo( 
+            /* [out][in] */ DOCHOSTUIINFO *pInfo) = 0;
+        
+        virtual HRESULT STDMETHODCALLTYPE ShowUI( 
+            /* [in] */ DWORD dwID,
+            /* [in] */ IOleInPlaceActiveObject *pActiveObject,
+            /* [in] */ IOleCommandTarget *pCommandTarget,
+            /* [in] */ IOleInPlaceFrame *pFrame,
+            /* [in] */ IOleInPlaceUIWindow *pDoc) = 0;
+        
+        virtual HRESULT STDMETHODCALLTYPE HideUI( void) = 0;
+        
+        virtual HRESULT STDMETHODCALLTYPE UpdateUI( void) = 0;
+        
+        virtual HRESULT STDMETHODCALLTYPE EnableModeless( 
+            /* [in] */ BOOL fEnable) = 0;
+        
+        virtual HRESULT STDMETHODCALLTYPE OnDocWindowActivate( 
+            /* [in] */ BOOL fActivate) = 0;
+        
+        virtual HRESULT STDMETHODCALLTYPE OnFrameWindowActivate( 
+            /* [in] */ BOOL fActivate) = 0;
+        
+        virtual HRESULT STDMETHODCALLTYPE ResizeBorder( 
+            /* [in] */ LPCRECT prcBorder,
+            /* [in] */ IOleInPlaceUIWindow *pUIWindow,
+            /* [in] */ BOOL fRameWindow) = 0;
+        
+        virtual HRESULT STDMETHODCALLTYPE TranslateAccelerator( 
+            /* [in] */ LPMSG lpMsg,
+            /* [in] */ const GUID *pguidCmdGroup,
+            /* [in] */ DWORD nCmdID) = 0;
+        
+        virtual HRESULT STDMETHODCALLTYPE GetOptionKeyPath( 
+            /* [out] */ LPOLESTR *pchKey,
+            /* [in] */ DWORD dw) = 0;
+        
+        virtual HRESULT STDMETHODCALLTYPE GetDropTarget( 
+            /* [in] */ IDropTarget *pDropTarget,
+            /* [out] */ IDropTarget **ppDropTarget) = 0;
+        
+        virtual HRESULT STDMETHODCALLTYPE GetExternal( 
+            /* [out] */ IDispatch **ppDispatch) = 0;
+        
+        virtual HRESULT STDMETHODCALLTYPE TranslateUrl( 
+            /* [in] */ DWORD dwTranslate,
+            /* [in] */ OLECHAR *pchURLIn,
+            /* [out] */ OLECHAR **ppchURLOut) = 0;
+        
+        virtual HRESULT STDMETHODCALLTYPE FilterDataObject( 
+            /* [in] */ IDataObject *pDO,
+            /* [out] */ IDataObject **ppDORet) = 0;
+        
+    };
+    
+#else 	/* C style interface */
+
+    typedef struct IDocHostUIHandlerVtbl
+    {
+        BEGIN_INTERFACE
+        
+        HRESULT ( STDMETHODCALLTYPE *QueryInterface )( 
+            IDocHostUIHandler * This,
+            /* [in] */ REFIID riid,
+            /* [iid_is][out] */ void **ppvObject);
+        
+        ULONG ( STDMETHODCALLTYPE *AddRef )( 
+            IDocHostUIHandler * This);
+        
+        ULONG ( STDMETHODCALLTYPE *Release )( 
+            IDocHostUIHandler * This);
+        
+        HRESULT ( STDMETHODCALLTYPE *ShowContextMenu )( 
+            IDocHostUIHandler * This,
+            /* [in] */ DWORD dwID,
+            /* [in] */ POINT *ppt,
+            /* [in] */ IUnknown *pcmdtReserved,
+            /* [in] */ IDispatch *pdispReserved);
+        
+        HRESULT ( STDMETHODCALLTYPE *GetHostInfo )( 
+            IDocHostUIHandler * This,
+            /* [out][in] */ DOCHOSTUIINFO *pInfo);
+        
+        HRESULT ( STDMETHODCALLTYPE *ShowUI )( 
+            IDocHostUIHandler * This,
+            /* [in] */ DWORD dwID,
+            /* [in] */ IOleInPlaceActiveObject *pActiveObject,
+            /* [in] */ IOleCommandTarget *pCommandTarget,
+            /* [in] */ IOleInPlaceFrame *pFrame,
+            /* [in] */ IOleInPlaceUIWindow *pDoc);
+        
+        HRESULT ( STDMETHODCALLTYPE *HideUI )( 
+            IDocHostUIHandler * This);
+        
+        HRESULT ( STDMETHODCALLTYPE *UpdateUI )( 
+            IDocHostUIHandler * This);
+        
+        HRESULT ( STDMETHODCALLTYPE *EnableModeless )( 
+            IDocHostUIHandler * This,
+            /* [in] */ BOOL fEnable);
+        
+        HRESULT ( STDMETHODCALLTYPE *OnDocWindowActivate )( 
+            IDocHostUIHandler * This,
+            /* [in] */ BOOL fActivate);
+        
+        HRESULT ( STDMETHODCALLTYPE *OnFrameWindowActivate )( 
+            IDocHostUIHandler * This,
+            /* [in] */ BOOL fActivate);
+        
+        HRESULT ( STDMETHODCALLTYPE *ResizeBorder )( 
+            IDocHostUIHandler * This,
+            /* [in] */ LPCRECT prcBorder,
+            /* [in] */ IOleInPlaceUIWindow *pUIWindow,
+            /* [in] */ BOOL fRameWindow);
+        
+        HRESULT ( STDMETHODCALLTYPE *TranslateAccelerator )( 
+            IDocHostUIHandler * This,
+            /* [in] */ LPMSG lpMsg,
+            /* [in] */ const GUID *pguidCmdGroup,
+            /* [in] */ DWORD nCmdID);
+        
+        HRESULT ( STDMETHODCALLTYPE *GetOptionKeyPath )( 
+            IDocHostUIHandler * This,
+            /* [out] */ LPOLESTR *pchKey,
+            /* [in] */ DWORD dw);
+        
+        HRESULT ( STDMETHODCALLTYPE *GetDropTarget )( 
+            IDocHostUIHandler * This,
+            /* [in] */ IDropTarget *pDropTarget,
+            /* [out] */ IDropTarget **ppDropTarget);
+        
+        HRESULT ( STDMETHODCALLTYPE *GetExternal )( 
+            IDocHostUIHandler * This,
+            /* [out] */ IDispatch **ppDispatch);
+        
+        HRESULT ( STDMETHODCALLTYPE *TranslateUrl )( 
+            IDocHostUIHandler * This,
+            /* [in] */ DWORD dwTranslate,
+            /* [in] */ OLECHAR *pchURLIn,
+            /* [out] */ OLECHAR **ppchURLOut);
+        
+        HRESULT ( STDMETHODCALLTYPE *FilterDataObject )( 
+            IDocHostUIHandler * This,
+            /* [in] */ IDataObject *pDO,
+            /* [out] */ IDataObject **ppDORet);
+        
+        END_INTERFACE
+    } IDocHostUIHandlerVtbl;
+
+    interface IDocHostUIHandler
+    {
+        CONST_VTBL struct IDocHostUIHandlerVtbl *lpVtbl;
+    };
+
+    
+
+#ifdef COBJMACROS
+
+
+#define IDocHostUIHandler_QueryInterface(This,riid,ppvObject)	\
+    (This)->lpVtbl -> QueryInterface(This,riid,ppvObject)
+
+#define IDocHostUIHandler_AddRef(This)	\
+    (This)->lpVtbl -> AddRef(This)
+
+#define IDocHostUIHandler_Release(This)	\
+    (This)->lpVtbl -> Release(This)
+
+
+#define IDocHostUIHandler_ShowContextMenu(This,dwID,ppt,pcmdtReserved,pdispReserved)	\
+    (This)->lpVtbl -> ShowContextMenu(This,dwID,ppt,pcmdtReserved,pdispReserved)
+
+#define IDocHostUIHandler_GetHostInfo(This,pInfo)	\
+    (This)->lpVtbl -> GetHostInfo(This,pInfo)
+
+#define IDocHostUIHandler_ShowUI(This,dwID,pActiveObject,pCommandTarget,pFrame,pDoc)	\
+    (This)->lpVtbl -> ShowUI(This,dwID,pActiveObject,pCommandTarget,pFrame,pDoc)
+
+#define IDocHostUIHandler_HideUI(This)	\
+    (This)->lpVtbl -> HideUI(This)
+
+#define IDocHostUIHandler_UpdateUI(This)	\
+    (This)->lpVtbl -> UpdateUI(This)
+
+#define IDocHostUIHandler_EnableModeless(This,fEnable)	\
+    (This)->lpVtbl -> EnableModeless(This,fEnable)
+
+#define IDocHostUIHandler_OnDocWindowActivate(This,fActivate)	\
+    (This)->lpVtbl -> OnDocWindowActivate(This,fActivate)
+
+#define IDocHostUIHandler_OnFrameWindowActivate(This,fActivate)	\
+    (This)->lpVtbl -> OnFrameWindowActivate(This,fActivate)
+
+#define IDocHostUIHandler_ResizeBorder(This,prcBorder,pUIWindow,fRameWindow)	\
+    (This)->lpVtbl -> ResizeBorder(This,prcBorder,pUIWindow,fRameWindow)
+
+#define IDocHostUIHandler_TranslateAccelerator(This,lpMsg,pguidCmdGroup,nCmdID)	\
+    (This)->lpVtbl -> TranslateAccelerator(This,lpMsg,pguidCmdGroup,nCmdID)
+
+#define IDocHostUIHandler_GetOptionKeyPath(This,pchKey,dw)	\
+    (This)->lpVtbl -> GetOptionKeyPath(This,pchKey,dw)
+
+#define IDocHostUIHandler_GetDropTarget(This,pDropTarget,ppDropTarget)	\
+    (This)->lpVtbl -> GetDropTarget(This,pDropTarget,ppDropTarget)
+
+#define IDocHostUIHandler_GetExternal(This,ppDispatch)	\
+    (This)->lpVtbl -> GetExternal(This,ppDispatch)
+
+#define IDocHostUIHandler_TranslateUrl(This,dwTranslate,pchURLIn,ppchURLOut)	\
+    (This)->lpVtbl -> TranslateUrl(This,dwTranslate,pchURLIn,ppchURLOut)
+
+#define IDocHostUIHandler_FilterDataObject(This,pDO,ppDORet)	\
+    (This)->lpVtbl -> FilterDataObject(This,pDO,ppDORet)
+
+#endif /* COBJMACROS */
+
+
+#endif 	/* C style interface */
+
+
+
+HRESULT STDMETHODCALLTYPE IDocHostUIHandler_ShowContextMenu_Proxy( 
+    IDocHostUIHandler * This,
+    /* [in] */ DWORD dwID,
+    /* [in] */ POINT *ppt,
+    /* [in] */ IUnknown *pcmdtReserved,
+    /* [in] */ IDispatch *pdispReserved);
+
+
+void __RPC_STUB IDocHostUIHandler_ShowContextMenu_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+HRESULT STDMETHODCALLTYPE IDocHostUIHandler_GetHostInfo_Proxy( 
+    IDocHostUIHandler * This,
+    /* [out][in] */ DOCHOSTUIINFO *pInfo);
+
+
+void __RPC_STUB IDocHostUIHandler_GetHostInfo_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+HRESULT STDMETHODCALLTYPE IDocHostUIHandler_ShowUI_Proxy( 
+    IDocHostUIHandler * This,
+    /* [in] */ DWORD dwID,
+    /* [in] */ IOleInPlaceActiveObject *pActiveObject,
+    /* [in] */ IOleCommandTarget *pCommandTarget,
+    /* [in] */ IOleInPlaceFrame *pFrame,
+    /* [in] */ IOleInPlaceUIWindow *pDoc);
+
+
+void __RPC_STUB IDocHostUIHandler_ShowUI_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+HRESULT STDMETHODCALLTYPE IDocHostUIHandler_HideUI_Proxy( 
+    IDocHostUIHandler * This);
+
+
+void __RPC_STUB IDocHostUIHandler_HideUI_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+HRESULT STDMETHODCALLTYPE IDocHostUIHandler_UpdateUI_Proxy( 
+    IDocHostUIHandler * This);
+
+
+void __RPC_STUB IDocHostUIHandler_UpdateUI_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+HRESULT STDMETHODCALLTYPE IDocHostUIHandler_EnableModeless_Proxy( 
+    IDocHostUIHandler * This,
+    /* [in] */ BOOL fEnable);
+
+
+void __RPC_STUB IDocHostUIHandler_EnableModeless_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+HRESULT STDMETHODCALLTYPE IDocHostUIHandler_OnDocWindowActivate_Proxy( 
+    IDocHostUIHandler * This,
+    /* [in] */ BOOL fActivate);
+
+
+void __RPC_STUB IDocHostUIHandler_OnDocWindowActivate_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+HRESULT STDMETHODCALLTYPE IDocHostUIHandler_OnFrameWindowActivate_Proxy( 
+    IDocHostUIHandler * This,
+    /* [in] */ BOOL fActivate);
+
+
+void __RPC_STUB IDocHostUIHandler_OnFrameWindowActivate_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+HRESULT STDMETHODCALLTYPE IDocHostUIHandler_ResizeBorder_Proxy( 
+    IDocHostUIHandler * This,
+    /* [in] */ LPCRECT prcBorder,
+    /* [in] */ IOleInPlaceUIWindow *pUIWindow,
+    /* [in] */ BOOL fRameWindow);
+
+
+void __RPC_STUB IDocHostUIHandler_ResizeBorder_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+HRESULT STDMETHODCALLTYPE IDocHostUIHandler_TranslateAccelerator_Proxy( 
+    IDocHostUIHandler * This,
+    /* [in] */ LPMSG lpMsg,
+    /* [in] */ const GUID *pguidCmdGroup,
+    /* [in] */ DWORD nCmdID);
+
+
+void __RPC_STUB IDocHostUIHandler_TranslateAccelerator_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+HRESULT STDMETHODCALLTYPE IDocHostUIHandler_GetOptionKeyPath_Proxy( 
+    IDocHostUIHandler * This,
+    /* [out] */ LPOLESTR *pchKey,
+    /* [in] */ DWORD dw);
+
+
+void __RPC_STUB IDocHostUIHandler_GetOptionKeyPath_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+HRESULT STDMETHODCALLTYPE IDocHostUIHandler_GetDropTarget_Proxy( 
+    IDocHostUIHandler * This,
+    /* [in] */ IDropTarget *pDropTarget,
+    /* [out] */ IDropTarget **ppDropTarget);
+
+
+void __RPC_STUB IDocHostUIHandler_GetDropTarget_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+HRESULT STDMETHODCALLTYPE IDocHostUIHandler_GetExternal_Proxy( 
+    IDocHostUIHandler * This,
+    /* [out] */ IDispatch **ppDispatch);
+
+
+void __RPC_STUB IDocHostUIHandler_GetExternal_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+HRESULT STDMETHODCALLTYPE IDocHostUIHandler_TranslateUrl_Proxy( 
+    IDocHostUIHandler * This,
+    /* [in] */ DWORD dwTranslate,
+    /* [in] */ OLECHAR *pchURLIn,
+    /* [out] */ OLECHAR **ppchURLOut);
+
+
+void __RPC_STUB IDocHostUIHandler_TranslateUrl_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+HRESULT STDMETHODCALLTYPE IDocHostUIHandler_FilterDataObject_Proxy( 
+    IDocHostUIHandler * This,
+    /* [in] */ IDataObject *pDO,
+    /* [out] */ IDataObject **ppDORet);
+
+
+void __RPC_STUB IDocHostUIHandler_FilterDataObject_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+
+#endif 	/* __IDocHostUIHandler_INTERFACE_DEFINED__ */
+
+
+#ifndef __IDocHostUIHandler2_INTERFACE_DEFINED__
+#define __IDocHostUIHandler2_INTERFACE_DEFINED__
+
+/* interface IDocHostUIHandler2 */
+/* [local][unique][uuid][object] */ 
+
+
+EXTERN_C const IID IID_IDocHostUIHandler2;
+
+#if defined(__cplusplus) && !defined(CINTERFACE)
+    
+    MIDL_INTERFACE("3050f6d0-98b5-11cf-bb82-00aa00bdce0b")
+    IDocHostUIHandler2 : public IDocHostUIHandler
+    {
+    public:
+        virtual HRESULT STDMETHODCALLTYPE GetOverrideKeyPath( 
+            /* [out] */ LPOLESTR *pchKey,
+            /* [in] */ DWORD dw) = 0;
+        
+    };
+    
+#else 	/* C style interface */
+
+    typedef struct IDocHostUIHandler2Vtbl
+    {
+        BEGIN_INTERFACE
+        
+        HRESULT ( STDMETHODCALLTYPE *QueryInterface )( 
+            IDocHostUIHandler2 * This,
+            /* [in] */ REFIID riid,
+            /* [iid_is][out] */ void **ppvObject);
+        
+        ULONG ( STDMETHODCALLTYPE *AddRef )( 
+            IDocHostUIHandler2 * This);
+        
+        ULONG ( STDMETHODCALLTYPE *Release )( 
+            IDocHostUIHandler2 * This);
+        
+        HRESULT ( STDMETHODCALLTYPE *ShowContextMenu )( 
+            IDocHostUIHandler2 * This,
+            /* [in] */ DWORD dwID,
+            /* [in] */ POINT *ppt,
+            /* [in] */ IUnknown *pcmdtReserved,
+            /* [in] */ IDispatch *pdispReserved);
+        
+        HRESULT ( STDMETHODCALLTYPE *GetHostInfo )( 
+            IDocHostUIHandler2 * This,
+            /* [out][in] */ DOCHOSTUIINFO *pInfo);
+        
+        HRESULT ( STDMETHODCALLTYPE *ShowUI )( 
+            IDocHostUIHandler2 * This,
+            /* [in] */ DWORD dwID,
+            /* [in] */ IOleInPlaceActiveObject *pActiveObject,
+            /* [in] */ IOleCommandTarget *pCommandTarget,
+            /* [in] */ IOleInPlaceFrame *pFrame,
+            /* [in] */ IOleInPlaceUIWindow *pDoc);
+        
+        HRESULT ( STDMETHODCALLTYPE *HideUI )( 
+            IDocHostUIHandler2 * This);
+        
+        HRESULT ( STDMETHODCALLTYPE *UpdateUI )( 
+            IDocHostUIHandler2 * This);
+        
+        HRESULT ( STDMETHODCALLTYPE *EnableModeless )( 
+            IDocHostUIHandler2 * This,
+            /* [in] */ BOOL fEnable);
+        
+        HRESULT ( STDMETHODCALLTYPE *OnDocWindowActivate )( 
+            IDocHostUIHandler2 * This,
+            /* [in] */ BOOL fActivate);
+        
+        HRESULT ( STDMETHODCALLTYPE *OnFrameWindowActivate )( 
+            IDocHostUIHandler2 * This,
+            /* [in] */ BOOL fActivate);
+        
+        HRESULT ( STDMETHODCALLTYPE *ResizeBorder )( 
+            IDocHostUIHandler2 * This,
+            /* [in] */ LPCRECT prcBorder,
+            /* [in] */ IOleInPlaceUIWindow *pUIWindow,
+            /* [in] */ BOOL fRameWindow);
+        
+        HRESULT ( STDMETHODCALLTYPE *TranslateAccelerator )( 
+            IDocHostUIHandler2 * This,
+            /* [in] */ LPMSG lpMsg,
+            /* [in] */ const GUID *pguidCmdGroup,
+            /* [in] */ DWORD nCmdID);
+        
+        HRESULT ( STDMETHODCALLTYPE *GetOptionKeyPath )( 
+            IDocHostUIHandler2 * This,
+            /* [out] */ LPOLESTR *pchKey,
+            /* [in] */ DWORD dw);
+        
+        HRESULT ( STDMETHODCALLTYPE *GetDropTarget )( 
+            IDocHostUIHandler2 * This,
+            /* [in] */ IDropTarget *pDropTarget,
+            /* [out] */ IDropTarget **ppDropTarget);
+        
+        HRESULT ( STDMETHODCALLTYPE *GetExternal )( 
+            IDocHostUIHandler2 * This,
+            /* [out] */ IDispatch **ppDispatch);
+        
+        HRESULT ( STDMETHODCALLTYPE *TranslateUrl )( 
+            IDocHostUIHandler2 * This,
+            /* [in] */ DWORD dwTranslate,
+            /* [in] */ OLECHAR *pchURLIn,
+            /* [out] */ OLECHAR **ppchURLOut);
+        
+        HRESULT ( STDMETHODCALLTYPE *FilterDataObject )( 
+            IDocHostUIHandler2 * This,
+            /* [in] */ IDataObject *pDO,
+            /* [out] */ IDataObject **ppDORet);
+        
+        HRESULT ( STDMETHODCALLTYPE *GetOverrideKeyPath )( 
+            IDocHostUIHandler2 * This,
+            /* [out] */ LPOLESTR *pchKey,
+            /* [in] */ DWORD dw);
+        
+        END_INTERFACE
+    } IDocHostUIHandler2Vtbl;
+
+    interface IDocHostUIHandler2
+    {
+        CONST_VTBL struct IDocHostUIHandler2Vtbl *lpVtbl;
+    };
+
+    
+
+#ifdef COBJMACROS
+
+
+#define IDocHostUIHandler2_QueryInterface(This,riid,ppvObject)	\
+    (This)->lpVtbl -> QueryInterface(This,riid,ppvObject)
+
+#define IDocHostUIHandler2_AddRef(This)	\
+    (This)->lpVtbl -> AddRef(This)
+
+#define IDocHostUIHandler2_Release(This)	\
+    (This)->lpVtbl -> Release(This)
+
+
+#define IDocHostUIHandler2_ShowContextMenu(This,dwID,ppt,pcmdtReserved,pdispReserved)	\
+    (This)->lpVtbl -> ShowContextMenu(This,dwID,ppt,pcmdtReserved,pdispReserved)
+
+#define IDocHostUIHandler2_GetHostInfo(This,pInfo)	\
+    (This)->lpVtbl -> GetHostInfo(This,pInfo)
+
+#define IDocHostUIHandler2_ShowUI(This,dwID,pActiveObject,pCommandTarget,pFrame,pDoc)	\
+    (This)->lpVtbl -> ShowUI(This,dwID,pActiveObject,pCommandTarget,pFrame,pDoc)
+
+#define IDocHostUIHandler2_HideUI(This)	\
+    (This)->lpVtbl -> HideUI(This)
+
+#define IDocHostUIHandler2_UpdateUI(This)	\
+    (This)->lpVtbl -> UpdateUI(This)
+
+#define IDocHostUIHandler2_EnableModeless(This,fEnable)	\
+    (This)->lpVtbl -> EnableModeless(This,fEnable)
+
+#define IDocHostUIHandler2_OnDocWindowActivate(This,fActivate)	\
+    (This)->lpVtbl -> OnDocWindowActivate(This,fActivate)
+
+#define IDocHostUIHandler2_OnFrameWindowActivate(This,fActivate)	\
+    (This)->lpVtbl -> OnFrameWindowActivate(This,fActivate)
+
+#define IDocHostUIHandler2_ResizeBorder(This,prcBorder,pUIWindow,fRameWindow)	\
+    (This)->lpVtbl -> ResizeBorder(This,prcBorder,pUIWindow,fRameWindow)
+
+#define IDocHostUIHandler2_TranslateAccelerator(This,lpMsg,pguidCmdGroup,nCmdID)	\
+    (This)->lpVtbl -> TranslateAccelerator(This,lpMsg,pguidCmdGroup,nCmdID)
+
+#define IDocHostUIHandler2_GetOptionKeyPath(This,pchKey,dw)	\
+    (This)->lpVtbl -> GetOptionKeyPath(This,pchKey,dw)
+
+#define IDocHostUIHandler2_GetDropTarget(This,pDropTarget,ppDropTarget)	\
+    (This)->lpVtbl -> GetDropTarget(This,pDropTarget,ppDropTarget)
+
+#define IDocHostUIHandler2_GetExternal(This,ppDispatch)	\
+    (This)->lpVtbl -> GetExternal(This,ppDispatch)
+
+#define IDocHostUIHandler2_TranslateUrl(This,dwTranslate,pchURLIn,ppchURLOut)	\
+    (This)->lpVtbl -> TranslateUrl(This,dwTranslate,pchURLIn,ppchURLOut)
+
+#define IDocHostUIHandler2_FilterDataObject(This,pDO,ppDORet)	\
+    (This)->lpVtbl -> FilterDataObject(This,pDO,ppDORet)
+
+
+#define IDocHostUIHandler2_GetOverrideKeyPath(This,pchKey,dw)	\
+    (This)->lpVtbl -> GetOverrideKeyPath(This,pchKey,dw)
+
+#endif /* COBJMACROS */
+
+
+#endif 	/* C style interface */
+
+
+
+HRESULT STDMETHODCALLTYPE IDocHostUIHandler2_GetOverrideKeyPath_Proxy( 
+    IDocHostUIHandler2 * This,
+    /* [out] */ LPOLESTR *pchKey,
+    /* [in] */ DWORD dw);
+
+
+void __RPC_STUB IDocHostUIHandler2_GetOverrideKeyPath_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+
+#endif 	/* __IDocHostUIHandler2_INTERFACE_DEFINED__ */
+
+
+/* interface __MIDL_itf_mshtmhst_0269 */
+/* [local] */ 
+
+DEFINE_GUID(CGID_DocHostCommandHandler,0xf38bc242,0xb950,0x11d1,0x89,0x18,0x00,0xc0,0x4f,0xc2,0xc8,0x36);
+
+
+extern RPC_IF_HANDLE __MIDL_itf_mshtmhst_0269_v0_0_c_ifspec;
+extern RPC_IF_HANDLE __MIDL_itf_mshtmhst_0269_v0_0_s_ifspec;
+
+#ifndef __ICustomDoc_INTERFACE_DEFINED__
+#define __ICustomDoc_INTERFACE_DEFINED__
+
+/* interface ICustomDoc */
+/* [local][unique][uuid][object] */ 
+
+
+EXTERN_C const IID IID_ICustomDoc;
+
+#if defined(__cplusplus) && !defined(CINTERFACE)
+    
+    MIDL_INTERFACE("3050f3f0-98b5-11cf-bb82-00aa00bdce0b")
+    ICustomDoc : public IUnknown
+    {
+    public:
+        virtual HRESULT STDMETHODCALLTYPE SetUIHandler( 
+            /* [in] */ IDocHostUIHandler *pUIHandler) = 0;
+        
+    };
+    
+#else 	/* C style interface */
+
+    typedef struct ICustomDocVtbl
+    {
+        BEGIN_INTERFACE
+        
+        HRESULT ( STDMETHODCALLTYPE *QueryInterface )( 
+            ICustomDoc * This,
+            /* [in] */ REFIID riid,
+            /* [iid_is][out] */ void **ppvObject);
+        
+        ULONG ( STDMETHODCALLTYPE *AddRef )( 
+            ICustomDoc * This);
+        
+        ULONG ( STDMETHODCALLTYPE *Release )( 
+            ICustomDoc * This);
+        
+        HRESULT ( STDMETHODCALLTYPE *SetUIHandler )( 
+            ICustomDoc * This,
+            /* [in] */ IDocHostUIHandler *pUIHandler);
+        
+        END_INTERFACE
+    } ICustomDocVtbl;
+
+    interface ICustomDoc
+    {
+        CONST_VTBL struct ICustomDocVtbl *lpVtbl;
+    };
+
+    
+
+#ifdef COBJMACROS
+
+
+#define ICustomDoc_QueryInterface(This,riid,ppvObject)	\
+    (This)->lpVtbl -> QueryInterface(This,riid,ppvObject)
+
+#define ICustomDoc_AddRef(This)	\
+    (This)->lpVtbl -> AddRef(This)
+
+#define ICustomDoc_Release(This)	\
+    (This)->lpVtbl -> Release(This)
+
+
+#define ICustomDoc_SetUIHandler(This,pUIHandler)	\
+    (This)->lpVtbl -> SetUIHandler(This,pUIHandler)
+
+#endif /* COBJMACROS */
+
+
+#endif 	/* C style interface */
+
+
+
+HRESULT STDMETHODCALLTYPE ICustomDoc_SetUIHandler_Proxy( 
+    ICustomDoc * This,
+    /* [in] */ IDocHostUIHandler *pUIHandler);
+
+
+void __RPC_STUB ICustomDoc_SetUIHandler_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+
+#endif 	/* __ICustomDoc_INTERFACE_DEFINED__ */
+
+
+#ifndef __IDocHostShowUI_INTERFACE_DEFINED__
+#define __IDocHostShowUI_INTERFACE_DEFINED__
+
+/* interface IDocHostShowUI */
+/* [local][unique][uuid][object] */ 
+
+
+EXTERN_C const IID IID_IDocHostShowUI;
+
+#if defined(__cplusplus) && !defined(CINTERFACE)
+    
+    MIDL_INTERFACE("c4d244b0-d43e-11cf-893b-00aa00bdce1a")
+    IDocHostShowUI : public IUnknown
+    {
+    public:
+        virtual HRESULT STDMETHODCALLTYPE ShowMessage( 
+            /* [in] */ HWND hwnd,
+            /* [in] */ LPOLESTR lpstrText,
+            /* [in] */ LPOLESTR lpstrCaption,
+            /* [in] */ DWORD dwType,
+            /* [in] */ LPOLESTR lpstrHelpFile,
+            /* [in] */ DWORD dwHelpContext,
+            /* [out] */ LRESULT *plResult) = 0;
+        
+        virtual HRESULT STDMETHODCALLTYPE ShowHelp( 
+            /* [in] */ HWND hwnd,
+            /* [in] */ LPOLESTR pszHelpFile,
+            /* [in] */ UINT uCommand,
+            /* [in] */ DWORD dwData,
+            /* [in] */ POINT ptMouse,
+            /* [out] */ IDispatch *pDispatchObjectHit) = 0;
+        
+    };
+    
+#else 	/* C style interface */
+
+    typedef struct IDocHostShowUIVtbl
+    {
+        BEGIN_INTERFACE
+        
+        HRESULT ( STDMETHODCALLTYPE *QueryInterface )( 
+            IDocHostShowUI * This,
+            /* [in] */ REFIID riid,
+            /* [iid_is][out] */ void **ppvObject);
+        
+        ULONG ( STDMETHODCALLTYPE *AddRef )( 
+            IDocHostShowUI * This);
+        
+        ULONG ( STDMETHODCALLTYPE *Release )( 
+            IDocHostShowUI * This);
+        
+        HRESULT ( STDMETHODCALLTYPE *ShowMessage )( 
+            IDocHostShowUI * This,
+            /* [in] */ HWND hwnd,
+            /* [in] */ LPOLESTR lpstrText,
+            /* [in] */ LPOLESTR lpstrCaption,
+            /* [in] */ DWORD dwType,
+            /* [in] */ LPOLESTR lpstrHelpFile,
+            /* [in] */ DWORD dwHelpContext,
+            /* [out] */ LRESULT *plResult);
+        
+        HRESULT ( STDMETHODCALLTYPE *ShowHelp )( 
+            IDocHostShowUI * This,
+            /* [in] */ HWND hwnd,
+            /* [in] */ LPOLESTR pszHelpFile,
+            /* [in] */ UINT uCommand,
+            /* [in] */ DWORD dwData,
+            /* [in] */ POINT ptMouse,
+            /* [out] */ IDispatch *pDispatchObjectHit);
+        
+        END_INTERFACE
+    } IDocHostShowUIVtbl;
+
+    interface IDocHostShowUI
+    {
+        CONST_VTBL struct IDocHostShowUIVtbl *lpVtbl;
+    };
+
+    
+
+#ifdef COBJMACROS
+
+
+#define IDocHostShowUI_QueryInterface(This,riid,ppvObject)	\
+    (This)->lpVtbl -> QueryInterface(This,riid,ppvObject)
+
+#define IDocHostShowUI_AddRef(This)	\
+    (This)->lpVtbl -> AddRef(This)
+
+#define IDocHostShowUI_Release(This)	\
+    (This)->lpVtbl -> Release(This)
+
+
+#define IDocHostShowUI_ShowMessage(This,hwnd,lpstrText,lpstrCaption,dwType,lpstrHelpFile,dwHelpContext,plResult)	\
+    (This)->lpVtbl -> ShowMessage(This,hwnd,lpstrText,lpstrCaption,dwType,lpstrHelpFile,dwHelpContext,plResult)
+
+#define IDocHostShowUI_ShowHelp(This,hwnd,pszHelpFile,uCommand,dwData,ptMouse,pDispatchObjectHit)	\
+    (This)->lpVtbl -> ShowHelp(This,hwnd,pszHelpFile,uCommand,dwData,ptMouse,pDispatchObjectHit)
+
+#endif /* COBJMACROS */
+
+
+#endif 	/* C style interface */
+
+
+
+HRESULT STDMETHODCALLTYPE IDocHostShowUI_ShowMessage_Proxy( 
+    IDocHostShowUI * This,
+    /* [in] */ HWND hwnd,
+    /* [in] */ LPOLESTR lpstrText,
+    /* [in] */ LPOLESTR lpstrCaption,
+    /* [in] */ DWORD dwType,
+    /* [in] */ LPOLESTR lpstrHelpFile,
+    /* [in] */ DWORD dwHelpContext,
+    /* [out] */ LRESULT *plResult);
+
+
+void __RPC_STUB IDocHostShowUI_ShowMessage_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+HRESULT STDMETHODCALLTYPE IDocHostShowUI_ShowHelp_Proxy( 
+    IDocHostShowUI * This,
+    /* [in] */ HWND hwnd,
+    /* [in] */ LPOLESTR pszHelpFile,
+    /* [in] */ UINT uCommand,
+    /* [in] */ DWORD dwData,
+    /* [in] */ POINT ptMouse,
+    /* [out] */ IDispatch *pDispatchObjectHit);
+
+
+void __RPC_STUB IDocHostShowUI_ShowHelp_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+
+#endif 	/* __IDocHostShowUI_INTERFACE_DEFINED__ */
+
+
+/* interface __MIDL_itf_mshtmhst_0271 */
+/* [local] */ 
+
+#define IClassFactory3      IClassFactoryEx
+#define IID_IClassFactory3  IID_IClassFactoryEx
+
+
+extern RPC_IF_HANDLE __MIDL_itf_mshtmhst_0271_v0_0_c_ifspec;
+extern RPC_IF_HANDLE __MIDL_itf_mshtmhst_0271_v0_0_s_ifspec;
+
+#ifndef __IClassFactoryEx_INTERFACE_DEFINED__
+#define __IClassFactoryEx_INTERFACE_DEFINED__
+
+/* interface IClassFactoryEx */
+/* [local][unique][uuid][object] */ 
+
+
+EXTERN_C const IID IID_IClassFactoryEx;
+
+#if defined(__cplusplus) && !defined(CINTERFACE)
+    
+    MIDL_INTERFACE("342D1EA0-AE25-11D1-89C5-006008C3FBFC")
+    IClassFactoryEx : public IClassFactory
+    {
+    public:
+        virtual HRESULT STDMETHODCALLTYPE CreateInstanceWithContext( 
+            IUnknown *punkContext,
+            IUnknown *punkOuter,
+            REFIID riid,
+            /* [out] */ void **ppv) = 0;
+        
+    };
+    
+#else 	/* C style interface */
+
+    typedef struct IClassFactoryExVtbl
+    {
+        BEGIN_INTERFACE
+        
+        HRESULT ( STDMETHODCALLTYPE *QueryInterface )( 
+            IClassFactoryEx * This,
+            /* [in] */ REFIID riid,
+            /* [iid_is][out] */ void **ppvObject);
+        
+        ULONG ( STDMETHODCALLTYPE *AddRef )( 
+            IClassFactoryEx * This);
+        
+        ULONG ( STDMETHODCALLTYPE *Release )( 
+            IClassFactoryEx * This);
+        
+        /* [local] */ HRESULT ( STDMETHODCALLTYPE *CreateInstance )( 
+            IClassFactoryEx * This,
+            /* [unique][in] */ IUnknown *pUnkOuter,
+            /* [in] */ REFIID riid,
+            /* [iid_is][out] */ void **ppvObject);
+        
+        /* [local] */ HRESULT ( STDMETHODCALLTYPE *LockServer )( 
+            IClassFactoryEx * This,
+            /* [in] */ BOOL fLock);
+        
+        HRESULT ( STDMETHODCALLTYPE *CreateInstanceWithContext )( 
+            IClassFactoryEx * This,
+            IUnknown *punkContext,
+            IUnknown *punkOuter,
+            REFIID riid,
+            /* [out] */ void **ppv);
+        
+        END_INTERFACE
+    } IClassFactoryExVtbl;
+
+    interface IClassFactoryEx
+    {
+        CONST_VTBL struct IClassFactoryExVtbl *lpVtbl;
+    };
+
+    
+
+#ifdef COBJMACROS
+
+
+#define IClassFactoryEx_QueryInterface(This,riid,ppvObject)	\
+    (This)->lpVtbl -> QueryInterface(This,riid,ppvObject)
+
+#define IClassFactoryEx_AddRef(This)	\
+    (This)->lpVtbl -> AddRef(This)
+
+#define IClassFactoryEx_Release(This)	\
+    (This)->lpVtbl -> Release(This)
+
+
+#define IClassFactoryEx_CreateInstance(This,pUnkOuter,riid,ppvObject)	\
+    (This)->lpVtbl -> CreateInstance(This,pUnkOuter,riid,ppvObject)
+
+#define IClassFactoryEx_LockServer(This,fLock)	\
+    (This)->lpVtbl -> LockServer(This,fLock)
+
+
+#define IClassFactoryEx_CreateInstanceWithContext(This,punkContext,punkOuter,riid,ppv)	\
+    (This)->lpVtbl -> CreateInstanceWithContext(This,punkContext,punkOuter,riid,ppv)
+
+#endif /* COBJMACROS */
+
+
+#endif 	/* C style interface */
+
+
+
+HRESULT STDMETHODCALLTYPE IClassFactoryEx_CreateInstanceWithContext_Proxy( 
+    IClassFactoryEx * This,
+    IUnknown *punkContext,
+    IUnknown *punkOuter,
+    REFIID riid,
+    /* [out] */ void **ppv);
+
+
+void __RPC_STUB IClassFactoryEx_CreateInstanceWithContext_Stub(
+    IRpcStubBuffer *This,
+    IRpcChannelBuffer *_pRpcChannelBuffer,
+    PRPC_MESSAGE _pRpcMessage,
+    DWORD *_pdwStubPhase);
+
+
+
+#endif 	/* __IClassFactoryEx_INTERFACE_DEFINED__ */
+
+
+/* interface __MIDL_itf_mshtmhst_0272 */
+/* [local] */ 
+
+#endif
+
+
+extern RPC_IF_HANDLE __MIDL_itf_mshtmhst_0272_v0_0_c_ifspec;
+extern RPC_IF_HANDLE __MIDL_itf_mshtmhst_0272_v0_0_s_ifspec;
+
+/* Additional Prototypes for ALL interfaces */
+
+/* end of Additional Prototypes */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+

+ 1101 - 0
win32maxguiex.mod/mshtmlview.cpp

@@ -0,0 +1,1101 @@
+
+#include <w32api.h>
+#include <windows.h>
+#include <mshtml.h>
+#include <exdisp.h>
+#include <mshtmhst.h>
+
+#include "mshtmlview.h"
+
+// fix emit!!!
+
+// blitzmax / mingw compilations stuff...
+
+#include <brl.mod/blitz.mod/blitz.h>
+#include <maxgui.mod/maxgui.mod/maxgui.h>
+
+#define NOCONTEXTMENU 1
+#define NONAVIGATE 2
+
+BBString *bbStringFromVariant2(VARIANT *v){
+	unsigned short *w;
+	int n;
+	if (v->vt!=VT_BSTR)  return 0;
+	w=(unsigned short*)v->bstrVal;
+	n=0;
+	while (w[n++]) {}
+	return bbStringFromShorts(w,n-1);
+}
+
+
+#define OLERENDER_DRAW 1
+
+#define TODO {printf("htmlview TODO error line:%d\n",__LINE__);fflush(stdout);brl_blitz_NullObjectError();return 0;}
+
+typedef IDispatch * DWebBrowserEventsPtr;
+const IID IID_IDocHostUIHandler2={0xbd3f23c0,0xd43e,0x11cf,{0x89,0x3b,0x00,0xaa,0x00,0xbd,0xce,0x1a}};
+const IID IID_DWebBrowserEvents2={0x34A715A0,0x6587,0x11D0,{0x92,0x4A,0x00,0x20,0xAF,0xC7,0xAC,0x4D}};
+//const IID IID_IHTMLDocument={0x626FC520,0xA41E,0x11cf,{0xA7,0x31,0x00,0xa0,0xc9,0x08,0x26,0x37}};
+
+#define DISPID_BEFORENAVIGATE2      250   // hyperlink clicked on
+#define DISPID_NEWWINDOW2           251
+#define DISPID_NAVIGATECOMPLETE2    252   // UIActivate new document
+#define DISPID_DOCUMENTCOMPLETE	    259
+
+//#ifdef MINGW322
+
+typedef interface IHTMLFiltersCollection *LPHTMLFILTERSCOLLECTION;
+typedef interface IHTMLLinkElement *LPHTMLLINKELEMENT;
+typedef interface IHTMLImgElement *LPHTMLIMGELEMENT;
+typedef interface IHTMLImageElementFactory *LPHTMLIMAGEELEMENTFACTORY;
+typedef interface IHTMLEventObj *LPHTMLEVENTOBJ;
+typedef interface IHTMLScreen *LPHTMLSCREEN;
+typedef interface IHTMLOptionElementFactory *LPHTMLOPTIONELEMENTFACTORY;
+typedef interface IOmHistory *LPOMHISTORY;
+typedef interface IOmNavigator *LPOMNAVIGATOR;
+ 
+#if __W32API_MAJOR_VERSION<3
+ 
+EXTERN_C const IID IID_IHTMLFramesCollection2;
+EXTERN_C const IID IID_IHTMLWindow2;
+
+#undef INTERFACE
+#define INTERFACE IHTMLFramesCollection2
+DECLARE_INTERFACE_(IHTMLFramesCollection2,IDispatch)
+{
+	STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE;
+	STDMETHOD_(ULONG,AddRef)(THIS) PURE;
+	STDMETHOD_(ULONG,Release)(THIS) PURE;
+	STDMETHOD(GetTypeInfoCount)(THIS_ UINT*) PURE;
+	STDMETHOD(GetTypeInfo)(THIS_ UINT,LCID,LPTYPEINFO*) PURE;
+	STDMETHOD(GetIDsOfNames)(THIS_ REFIID,LPOLESTR*,UINT,LCID,DISPID*) PURE;
+	STDMETHOD(Invoke)(THIS_ DISPID,REFIID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,UINT*) PURE;
+    STDMETHOD(item)(THIS_ VARIANT*,VARIANT*) PURE;
+    STDMETHOD(get_length)(THIS_ long*) PURE;
+};
+
+#undef INTERFACE
+#define INTERFACE IHTMLWindow2
+DECLARE_INTERFACE_(IHTMLWindow2,IHTMLFramesCollection2)
+{
+	STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE;
+	STDMETHOD_(ULONG,AddRef)(THIS) PURE;
+	STDMETHOD_(ULONG,Release)(THIS) PURE;
+	STDMETHOD(GetTypeInfoCount)(THIS_ UINT*) PURE;
+	STDMETHOD(GetTypeInfo)(THIS_ UINT,LCID,LPTYPEINFO*) PURE;
+	STDMETHOD(GetIDsOfNames)(THIS_ REFIID,LPOLESTR*,UINT,LCID,DISPID*) PURE;
+	STDMETHOD(Invoke)(THIS_ DISPID,REFIID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,UINT*) PURE;
+    STDMETHOD(item)(THIS_ VARIANT*,VARIANT*) PURE;
+    STDMETHOD(get_length)(THIS_ long*) PURE;
+
+    STDMETHOD(get_frames)(THIS_ IHTMLFramesCollection2**) PURE;
+    STDMETHOD(put_defaultStatus)(THIS_ BSTR) PURE;
+    STDMETHOD(get_defaultStatus)(THIS_ BSTR*) PURE;
+    STDMETHOD(put_status)(THIS_ BSTR) PURE;
+    STDMETHOD(get_status)(THIS_ BSTR*) PURE;
+    STDMETHOD(setTimeout)(THIS_ BSTR,long,VARIANT*,long*) PURE;
+    STDMETHOD(clearTimeout)(THIS_ long) PURE;
+    STDMETHOD(alert)(THIS_ BSTR) PURE;
+    STDMETHOD(confirm)(THIS_ BSTR,VARIANT_BOOL*) PURE;
+    STDMETHOD(prompt)(THIS_ BSTR,BSTR,VARIANT*) PURE;
+    STDMETHOD(get_Image)(THIS_ LPHTMLIMAGEELEMENTFACTORY*) PURE;
+    STDMETHOD(get_location)(THIS_ LPHTMLLOCATION*) PURE;
+    STDMETHOD(get_history)(THIS_ LPOMHISTORY*) PURE;
+    STDMETHOD(close)(THIS) PURE;
+    STDMETHOD(put_opener)(THIS_ VARIANT) PURE;
+    STDMETHOD(get_opener)(THIS_ VARIANT*) PURE;
+    STDMETHOD(get_navigator)(THIS_ LPOMNAVIGATOR*) PURE;
+    STDMETHOD(put_name)(THIS_ BSTR) PURE;
+    STDMETHOD(get_name)(THIS_ BSTR*) PURE;
+    STDMETHOD(get_parent)(THIS_ LPHTMLWINDOW2*) PURE;
+    STDMETHOD(open)(THIS_ BSTR,BSTR,BSTR,VARIANT_BOOL,LPHTMLWINDOW2*) PURE;
+    STDMETHOD(get_self)(THIS_ LPHTMLWINDOW2*) PURE;
+    STDMETHOD(get_top)(THIS_ LPHTMLWINDOW2*) PURE;
+    STDMETHOD(get_window)(THIS_ LPHTMLWINDOW2*) PURE;
+    STDMETHOD(navigate)(THIS_ BSTR) PURE;
+    STDMETHOD(put_onfocus)(THIS_ VARIANT) PURE;
+    STDMETHOD(get_onfocus)(THIS_ VARIANT*) PURE;
+    STDMETHOD(put_onblur)(THIS_ VARIANT) PURE;
+    STDMETHOD(get_onblur)(THIS_ VARIANT*) PURE;
+    STDMETHOD(put_onload)(THIS_ VARIANT) PURE;
+    STDMETHOD(get_onload)(THIS_ VARIANT*) PURE;
+    STDMETHOD(put_onbeforeunload)(THIS_ VARIANT) PURE;
+    STDMETHOD(get_onbeforeunload)(THIS_ VARIANT*) PURE;
+    STDMETHOD(put_onunload)(THIS_ VARIANT) PURE;
+    STDMETHOD(get_onunload)(THIS_ VARIANT*) PURE;
+    STDMETHOD(put_onhelp)(THIS_ VARIANT) PURE;
+    STDMETHOD(get_onhelp)(THIS_ VARIANT*) PURE;
+    STDMETHOD(put_onerror)(THIS_ VARIANT) PURE;
+    STDMETHOD(get_onerror)(THIS_ VARIANT*) PURE;
+    STDMETHOD(put_onresize)(THIS_ VARIANT) PURE;
+    STDMETHOD(get_onresize)(THIS_ VARIANT*) PURE;
+    STDMETHOD(put_onscroll)(THIS_ VARIANT) PURE;
+    STDMETHOD(get_onscroll)(THIS_ VARIANT*) PURE;
+    STDMETHOD(get_document)(THIS_ IHTMLDocument2**) PURE;
+    STDMETHOD(get_event)(THIS_ LPHTMLEVENTOBJ*) PURE;
+    STDMETHOD(get__newEnum)(THIS_ IUnknown**) PURE;
+    STDMETHOD(showModalDialog)(THIS_ BSTR,VARIANT*,VARIANT*,VARIANT*) PURE;
+    STDMETHOD(showHelp)(THIS_ BSTR,VARIANT,BSTR) PURE;
+    STDMETHOD(get_screen)(THIS_ LPHTMLSCREEN*) PURE;
+    STDMETHOD(get_Option)(THIS_ LPHTMLOPTIONELEMENTFACTORY*) PURE;
+    STDMETHOD(focus)(THIS) PURE;
+    STDMETHOD(get_closed)(THIS_ VARIANT_BOOL*) PURE;
+    STDMETHOD(blur)(THIS) PURE;
+    STDMETHOD(scroll)(THIS_ long,long) PURE;
+    STDMETHOD(get_clientInformation)(THIS_ LPOMNAVIGATOR*) PURE;
+    STDMETHOD(setInterval)(THIS_ BSTR,long,VARIANT*,long*) PURE;
+    STDMETHOD(clearInterval)(THIS_ long) PURE;
+    STDMETHOD(put_offscreenBuffering)(THIS_ VARIANT) PURE;
+    STDMETHOD(get_offscreenBuffering)(THIS_ VARIANT*) PURE;
+    STDMETHOD(execScript)(THIS_ BSTR,BSTR,VARIANT*) PURE;
+    STDMETHOD(toString)(THIS_ BSTR*) PURE;
+    STDMETHOD(scrollBy)(THIS_ long,long) PURE;
+    STDMETHOD(scrollTo)(THIS_ long,long) PURE;
+    STDMETHOD(moveTo)(THIS_ long,long) PURE;
+    STDMETHOD(moveBy)(THIS_ long,long) PURE;
+    STDMETHOD(resizeTo)(THIS_ long,long) PURE;
+    STDMETHOD(resizeBy)(THIS_ long,long) PURE;
+    STDMETHOD(get_external)(THIS_ IDispatch**) PURE;
+};
+
+#endif
+
+//#endif	//additional mingw 3.2 includes
+
+
+struct CNullStorage2 : public IStorage{
+	// IUnknown
+	STDMETHODIMP QueryInterface(REFIID riid,void ** ppvObject);
+	STDMETHODIMP_(ULONG) AddRef(void);
+	STDMETHODIMP_(ULONG) Release(void);
+	// IStorage
+	STDMETHODIMP CreateStream(const WCHAR * pwcsName,DWORD grfMode,DWORD reserved1,DWORD reserved2,IStream ** ppstm);
+	STDMETHODIMP OpenStream(const WCHAR * pwcsName,void * reserved1,DWORD grfMode,DWORD reserved2,IStream ** ppstm);
+	STDMETHODIMP CreateStorage(const WCHAR * pwcsName,DWORD grfMode,DWORD reserved1,DWORD reserved2,IStorage ** ppstg);
+	STDMETHODIMP OpenStorage(const WCHAR * pwcsName,IStorage * pstgPriority,DWORD grfMode,SNB snbExclude,DWORD reserved,IStorage ** ppstg);
+	STDMETHODIMP CopyTo(DWORD ciidExclude,IID const * rgiidExclude,SNB snbExclude,IStorage * pstgDest);
+	STDMETHODIMP MoveElementTo(const OLECHAR * pwcsName,IStorage * pstgDest,const OLECHAR* pwcsNewName,DWORD grfFlags);
+	STDMETHODIMP Commit(DWORD grfCommitFlags);
+	STDMETHODIMP Revert(void);
+	STDMETHODIMP EnumElements(DWORD reserved1,void * reserved2,DWORD reserved3,IEnumSTATSTG ** ppenum);
+	STDMETHODIMP DestroyElement(const OLECHAR * pwcsName);
+	STDMETHODIMP RenameElement(const WCHAR * pwcsOldName,const WCHAR * pwcsNewName);
+	STDMETHODIMP SetElementTimes(const WCHAR * pwcsName,FILETIME const * pctime,FILETIME const * patime,FILETIME const * pmtime);
+	STDMETHODIMP SetClass(REFCLSID clsid);
+	STDMETHODIMP SetStateBits(DWORD grfStateBits,DWORD grfMask);
+	STDMETHODIMP Stat(STATSTG * pstatstg,DWORD grfStatFlag);
+};
+
+struct CMyFrame2 : public IOleInPlaceFrame{
+
+	// IUnknown
+	STDMETHODIMP QueryInterface(REFIID riid,void ** ppvObject);
+	STDMETHODIMP_(ULONG) AddRef(void);
+	STDMETHODIMP_(ULONG) Release(void);
+	// IOleWindow
+	STDMETHODIMP GetWindow(HWND FAR* lphwnd);
+	STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode);
+	// IOleInPlaceUIWindow
+	STDMETHODIMP GetBorder(LPRECT lprectBorder);
+	STDMETHODIMP RequestBorderSpace(LPCBORDERWIDTHS pborderwidths);
+	STDMETHODIMP SetBorderSpace(LPCBORDERWIDTHS pborderwidths);
+	STDMETHODIMP SetActiveObject(IOleInPlaceActiveObject *pActiveObject,LPCOLESTR pszObjName);
+	// IOleInPlaceFrame
+	STDMETHODIMP InsertMenus(HMENU hmenuShared,LPOLEMENUGROUPWIDTHS lpMenuWidths);
+	STDMETHODIMP SetMenu(HMENU hmenuShared,HOLEMENU holemenu,HWND hwndActiveObject);
+	STDMETHODIMP RemoveMenus(HMENU hmenuShared);
+	STDMETHODIMP SetStatusText(LPCOLESTR pszStatusText);
+	STDMETHODIMP EnableModeless(BOOL fEnable);
+	STDMETHODIMP TranslateAccelerator(  LPMSG lpmsg,WORD wID);
+
+	struct HTMLView *rep;
+};
+
+struct CMySite2 : public IOleClientSite,public IOleInPlaceSite,public IDocHostUIHandler
+{
+	// IUnknown
+	STDMETHODIMP QueryInterface(REFIID riid,void ** ppvObject);
+	STDMETHODIMP_(ULONG) AddRef(void);
+	STDMETHODIMP_(ULONG) Release(void);
+	// IOleClientSite
+	STDMETHODIMP SaveObject();
+	STDMETHODIMP GetMoniker(DWORD dwAssign,DWORD dwWhichMoniker,IMoniker ** ppmk);
+	STDMETHODIMP GetContainer(LPOLECONTAINER FAR* ppContainer);
+	STDMETHODIMP ShowObject();
+	STDMETHODIMP OnShowWindow(BOOL fShow);
+	STDMETHODIMP RequestNewObjectLayout();
+	// IOleWindow
+	STDMETHODIMP GetWindow(HWND FAR* lphwnd);
+	STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode);
+	// IOleInPlaceSite methods
+	STDMETHODIMP CanInPlaceActivate();
+	STDMETHODIMP OnInPlaceActivate();
+	STDMETHODIMP OnUIActivate();
+	STDMETHODIMP GetWindowContext(LPOLEINPLACEFRAME FAR* lplpFrame,LPOLEINPLACEUIWINDOW FAR* lplpDoc,LPRECT lprcPosRect,LPRECT lprcClipRect,LPOLEINPLACEFRAMEINFO lpFrameInfo);
+	STDMETHODIMP Scroll(SIZE scrollExtent);
+	STDMETHODIMP OnUIDeactivate(BOOL fUndoable);
+	STDMETHODIMP OnInPlaceDeactivate();
+	STDMETHODIMP DiscardUndoState();
+	STDMETHODIMP DeactivateAndUndo();
+	STDMETHODIMP OnPosRectChange(LPCRECT lprcPosRect);
+	// idochost methods
+	STDMETHODIMP ShowContextMenu( DWORD dwID,POINT __RPC_FAR *ppt,IUnknown __RPC_FAR *pcmdtReserved,IDispatch __RPC_FAR *pdispReserved) ;
+	STDMETHODIMP GetHostInfo( DOCHOSTUIINFO __RPC_FAR *pInfo);
+	STDMETHODIMP ShowUI( DWORD dwID,IOleInPlaceActiveObject __RPC_FAR *pActiveObject,IOleCommandTarget __RPC_FAR *pCommandTarget,IOleInPlaceFrame __RPC_FAR *pFrame,IOleInPlaceUIWindow __RPC_FAR *pDoc);
+	STDMETHODIMP HideUI( void);
+	STDMETHODIMP UpdateUI( void);
+	STDMETHODIMP OnDocWindowActivate(  BOOL fActivate);
+	STDMETHODIMP OnFrameWindowActivate(  BOOL fActivate);
+	STDMETHODIMP ResizeBorder( LPCRECT prcBorder,IOleInPlaceUIWindow __RPC_FAR *pUIWindow,BOOL fRameWindow);
+	STDMETHODIMP TranslateAccelerator( LPMSG lpMsg,const GUID __RPC_FAR *pguidCmdGroup,DWORD nCmdID);
+	STDMETHODIMP GetOptionKeyPath( LPOLESTR __RPC_FAR *pchKey,DWORD dw);
+	STDMETHODIMP GetDropTarget( IDropTarget __RPC_FAR *pDropTarget,IDropTarget __RPC_FAR *__RPC_FAR *ppDropTarget);
+	STDMETHODIMP GetExternal(  IDispatch __RPC_FAR *__RPC_FAR *ppDispatch);
+	STDMETHODIMP TranslateUrl(DWORD dwTranslate,OLECHAR __RPC_FAR *pchURLIn,OLECHAR __RPC_FAR *__RPC_FAR *ppchURLOut);
+	STDMETHODIMP EnableModeless(  BOOL fEnable);
+	STDMETHODIMP FilterDataObject( IDataObject __RPC_FAR *pDO,IDataObject __RPC_FAR *__RPC_FAR *ppDORet);
+	
+	struct HTMLView *rep;
+};
+
+struct CMyContainer : public IOleContainer{
+	// IUnknown
+	STDMETHODIMP QueryInterface(REFIID riid,void ** ppvObject);
+	STDMETHODIMP_(ULONG) AddRef(void);
+	STDMETHODIMP_(ULONG) Release(void);
+	// IParseDisplayName
+	STDMETHODIMP ParseDisplayName(IBindCtx *pbc,LPOLESTR pszDisplayName,ULONG *pchEaten,IMoniker **ppmkOut);
+	// IOleContainer
+	STDMETHODIMP EnumObjects(DWORD grfFlags,IEnumUnknown **ppenum);
+	STDMETHODIMP LockContainer(BOOL fLock);
+};
+
+struct _bstr_t
+{
+	struct Data_t
+	{
+        wchar_t*        m_wstr;
+        mutable char*   m_str;
+        unsigned long   m_RefCount;
+		Data_t(BSTR bstr, bool fCopy) : m_str(NULL), m_RefCount(1)			//throw(_com_error)
+		{
+			if (fCopy && bstr != NULL)
+			{
+				m_wstr = ::SysAllocStringByteLen(reinterpret_cast<char*>(bstr),::SysStringByteLen(bstr));
+//				if (m_wstr == NULL) {_com_issue_error(E_OUTOFMEMORY);}
+			}
+			else
+			{
+				m_wstr = bstr;
+			}
+		}
+		Data_t(const wchar_t* s):m_str(NULL), m_RefCount(1)
+		{
+			m_wstr = ::SysAllocString(s);
+//			if (m_wstr == NULL && s != NULL) {_com_issue_error(E_OUTOFMEMORY);}
+		}
+		unsigned long AddRef() throw()
+		{
+			InterlockedIncrement(reinterpret_cast<long*>(&m_RefCount));
+			return m_RefCount;
+		}
+		unsigned long Release() throw()
+		{
+			if (!InterlockedDecrement(reinterpret_cast<long*>(&m_RefCount))) {delete this;return 0;}
+			return m_RefCount;
+		}
+		unsigned long RefCount() const throw()
+		{
+			return m_RefCount;
+		}
+		wchar_t* GetWString()
+		{
+			return m_wstr;
+		}
+	};
+	Data_t* m_Data;
+
+	_bstr_t(BSTR bstr, bool fCopy):m_Data(new Data_t(bstr, fCopy))
+	{
+//		if (m_Data == NULL) {_com_issue_error(E_OUTOFMEMORY);}
+	}
+
+	_bstr_t(const wchar_t* s):m_Data(new Data_t(s))
+	{
+//		if (m_Data == NULL) {_com_issue_error(E_OUTOFMEMORY);}
+	}
+
+	BBString	*bbString()
+	{
+		unsigned short *w;
+		int		n;
+		w=(unsigned short*)m_Data->m_wstr;n=0;while (w[n++]) {}
+		return bbStringFromShorts(w,n-1);
+	}
+};
+
+struct DWebBrowserEventsImpl2 : public DWebBrowserEvents2	//DWebBrowserEvents
+{
+// IUnknown methods
+    STDMETHOD(QueryInterface)(REFIID riid, LPVOID* ppv);
+    STDMETHOD_(ULONG, AddRef)();
+    STDMETHOD_(ULONG, Release)();
+// IDispatch methods
+	STDMETHOD(GetTypeInfoCount)(UINT* pctinfo);
+	STDMETHOD(GetTypeInfo)(UINT iTInfo,LCID lcid,ITypeInfo** ppTInfo);
+	STDMETHOD(GetIDsOfNames)(REFIID riid,LPOLESTR* rgszNames,UINT cNames,LCID lcid,DISPID* rgDispId);	
+	STDMETHOD(Invoke)(DISPID dispIdMember,
+            REFIID riid,
+            LCID lcid,
+            WORD wFlags,
+            DISPPARAMS __RPC_FAR *pDispParams,
+            VARIANT __RPC_FAR *pVarResult,
+            EXCEPINFO __RPC_FAR *pExcepInfo,
+            UINT __RPC_FAR *puArgErr);
+// events
+    HRESULT BeforeNavigate (
+        _bstr_t URL,
+        long Flags,
+        _bstr_t TargetFrameName,
+        VARIANT * PostData,
+        _bstr_t Headers,
+		VARIANT_BOOL * Cancel );
+
+	HRESULT NavigateComplete ( _bstr_t URL ) {return S_OK;}
+    HRESULT StatusTextChange ( _bstr_t Text );
+    void ProgressChange (
+        long Progress,
+        long ProgressMax );
+    void DownloadComplete();
+    void CommandStateChange (
+        long Command,
+        VARIANT_BOOL Enable );
+    void DownloadBegin ();
+    HRESULT NewWindow (
+        _bstr_t URL,
+        long Flags,
+        _bstr_t TargetFrameName,
+        VARIANT * PostData,
+        _bstr_t Headers,
+        VARIANT_BOOL * Processed );
+    HRESULT TitleChange ( _bstr_t Text );
+    HRESULT FrameBeforeNavigate (
+        _bstr_t URL,
+        long Flags,
+        _bstr_t TargetFrameName,
+        VARIANT * PostData,
+        _bstr_t Headers,
+		VARIANT_BOOL * Cancel );
+    HRESULT FrameNavigateComplete (
+        _bstr_t URL );
+    HRESULT FrameNewWindow (
+        _bstr_t URL,
+        long Flags,
+        _bstr_t TargetFrameName,
+        VARIANT * PostData,
+        _bstr_t Headers,
+        VARIANT_BOOL * Processed );
+    HRESULT Quit (
+        VARIANT_BOOL * Cancel );
+    HRESULT WindowMove ( );
+    HRESULT WindowResize ( );
+    HRESULT WindowActivate ( );
+    HRESULT PropertyChange (
+        _bstr_t Property );
+
+	void StatusTextChange(OLECHAR*) {}
+	void TitleChange(OLECHAR*) {}
+	void PropertyChange(OLECHAR*) {}
+	void BeforeNavigate2(IDispatch*, VARIANT*, VARIANT*, VARIANT*, VARIANT*, VARIANT*, VARIANT_BOOL*);
+	void NewWindow2(IDispatch**, VARIANT_BOOL*);	// {}
+	void NavigateComplete(IDispatch*, VARIANT*) ;
+	void DocumentComplete(IDispatch*, VARIANT*) ;//{}
+	void OnQuit() {}
+	void OnVisible(short int) {}
+	void OnToolBar(short int) {}
+	void OnMenuBar(short int) {}
+	void OnStatusBar(short int) {}
+	void OnFullScreen(short int) {}
+	void OnTheaterMode(short int) {}
+	void WindowSetResizable(short int) {}
+	void WindowSetLeft(long int) {}
+	void WindowSetTop(long int) {}
+	void WindowSetWidth(long int) {}
+	void WindowSetHeight(long int) {}
+	void WindowClosing(short int, VARIANT_BOOL*) {}
+	void ClientToHostWindow(long int*, long int*) {}
+	void SetSecureLockIcon(long int) {}
+	void FileDownload(VARIANT_BOOL*) {}
+
+	HTMLView *rep;
+};
+
+
+
+struct HTMLView{
+
+	HWND hwnd;
+	BBObject *owner;
+
+	CMySite2 site;
+	CMyFrame2 frame;
+	CNullStorage2 storage;
+	DWebBrowserEventsImpl2 eventsink;
+
+	IOleObject *oleObject;
+	IWebBrowser2* iBrowser;
+	IOleInPlaceObject *inPlaceObject;
+	IConnectionPointContainer *iConnection;
+	IConnectionPoint *iConnectionPoint;
+	IOleCommandTarget *iTarget;	
+	
+	BSTR current;
+	
+	DWORD	dwCookie;
+
+	int		viewstyle;
+	int		navcount;	//used with style&NOUSERNAV to route user navigation to event queue
+	int		loading;		//state returned by getstatus()
+	
+	HTMLView( BBObject *gadget, wchar_t *wndclass,HWND parent,int style ){
+
+		owner=gadget;
+		current=0;
+
+		viewstyle=style;
+		navcount=0;
+		loading=0;
+
+		int xstyle=WS_EX_CONTROLPARENT;
+		int wstyle=WS_CHILD|WS_TABSTOP|WS_CLIPSIBLINGS|WS_VISIBLE;
+	
+		hwnd=CreateWindowExW( xstyle,wndclass,0,wstyle,0,0,200,200,parent,0,GetModuleHandle(0),0 );
+		
+		site.rep=this;
+		eventsink.rep=this;
+		frame.rep=this;
+
+		int res=OleCreate( CLSID_WebBrowser,IID_IOleObject,OLERENDER_DRAW,0,&site,&storage,(void**)&oleObject );
+
+		OleSetContainedObject( oleObject,TRUE);
+		
+		oleObject->SetHostNames(L"Web Host",L"Web View");
+		oleObject->QueryInterface(IID_IWebBrowser2,(void**)&iBrowser);
+		oleObject->QueryInterface(IID_IOleInPlaceObject,(void**)&inPlaceObject );
+		oleObject->QueryInterface(IID_IConnectionPointContainer,(void**)&iConnection);
+		oleObject->QueryInterface(IID_IOleCommandTarget,(void**)&iTarget );
+
+		iConnection->FindConnectionPoint(DIID_DWebBrowserEvents2, &iConnectionPoint);
+		iConnectionPoint->Advise((LPUNKNOWN)&eventsink, &dwCookie);
+
+		RECT rect;
+		::GetClientRect( hwnd,&rect );
+		oleObject->DoVerb(OLEIVERB_SHOW,NULL,&site,-1,hwnd,&rect);
+
+		oleObject->DoVerb(OLEIVERB_UIACTIVATE,NULL,&site,0,hwnd,&rect);	//INPLACE
+		
+		go( L"about:blank" );
+	}
+
+	~HTMLView(){
+		if (current) SysFreeString(current);
+		inPlaceObject->Release();
+		iBrowser->Release();
+		oleObject->Close(OLECLOSE_NOSAVE);
+		oleObject->Release();
+	}
+
+	void setcurrenturl(VARIANT *url)
+	{
+		if (current) SysFreeString(current);
+		current=0;
+		if (url->vt==VT_BSTR){
+			current=SysAllocString(url->bstrVal);			
+		}
+	}
+	
+	void setshape(int x,int y,int w,int h){
+		RECT rect;
+		rect.left=0;rect.right=w;rect.top=0;rect.bottom=h;
+		MoveWindow(hwnd,x,y,w,h,TRUE);
+		inPlaceObject->SetObjectRects( &rect,&rect );	
+	}
+
+	void go( const wchar_t *url ){
+		BSTR bstr=SysAllocString(url);
+		VARIANT flags={VT_INT};
+		navcount=1;
+		loading=1;
+		iBrowser->Navigate( bstr,&flags,0,0,0 );
+		SysFreeString(bstr);
+	}
+
+
+#define IDM_COPY                    15
+#define IDM_CUT                     16
+#define IDM_PASTE                   26
+
+	int activate(int cmd){
+		
+		OLECMDF tmpOutput;
+		
+		switch (cmd)
+		{
+		case ACTIVATE_CUT:
+			iBrowser->QueryStatusWB(OLECMDID_CUT,&tmpOutput);
+			if(tmpOutput&OLECMDF_ENABLED) return iBrowser->ExecWB(OLECMDID_CUT,OLECMDEXECOPT_DONTPROMPTUSER,0,0);
+			break;
+		case ACTIVATE_COPY:
+			iBrowser->QueryStatusWB(OLECMDID_COPY,&tmpOutput);
+			if(tmpOutput&OLECMDF_ENABLED) return iBrowser->ExecWB(OLECMDID_COPY,OLECMDEXECOPT_DONTPROMPTUSER,0,0);
+			break;
+		case ACTIVATE_PASTE:
+			iBrowser->QueryStatusWB(OLECMDID_PASTE,&tmpOutput);
+			if(tmpOutput&OLECMDF_ENABLED) return iBrowser->ExecWB(OLECMDID_PASTE,OLECMDEXECOPT_DONTPROMPTUSER,0,0);
+			break;
+		case ACTIVATE_PRINT:
+			return iBrowser->ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_PROMPTUSER,0,0);
+		case ACTIVATE_BACK:
+			navcount=1;
+			iBrowser->GoBack();
+			return 0;
+		case ACTIVATE_FORWARD:
+			navcount=1;
+			iBrowser->GoForward();
+			return 0;
+		}
+		return 0;
+	}
+
+	void run( const wchar_t *script )
+	{
+		IDispatch		*disp;
+		BSTR			bstr;
+		IHTMLDocument2	*doc;
+		IHTMLWindow2	*win;
+		HRESULT			res;
+		VARIANT			result;
+		
+//		bstr=SysAllocStringLen((OLECHAR*)script->buf,scripturl->length);
+		bstr=SysAllocString(script);//(OLECHAR*)script->buf,scripturl->length);
+	
+		res=iBrowser->get_Document(&disp);
+		if (res==S_OK)
+		{
+			res=disp->QueryInterface(IID_IHTMLDocument2,(void**)&doc);
+			res=doc->get_parentWindow(&win);
+			result.vt=VT_EMPTY;
+			res=win->execScript(bstr,0,&result);
+		}
+		SysFreeString(bstr);
+	}
+	
+	int status(){
+		READYSTATE	state;
+		iBrowser->get_ReadyState(&state);
+		return (state!=READYSTATE_COMPLETE);
+	}
+};
+	
+
+
+
+STDMETHODIMP CNullStorage2::QueryInterface(REFIID riid,void ** ppvObject){
+	TODO
+}
+STDMETHODIMP_(ULONG) CNullStorage2::AddRef(void){
+	return 1;
+}
+STDMETHODIMP_(ULONG) CNullStorage2::Release(void){
+	return 1;
+}
+STDMETHODIMP CNullStorage2::CreateStream(const WCHAR * pwcsName,DWORD grfMode,DWORD reserved1,DWORD reserved2,IStream ** ppstm){
+	TODO
+}
+STDMETHODIMP CNullStorage2::OpenStream(const WCHAR * pwcsName,void * reserved1,DWORD grfMode,DWORD reserved2,IStream ** ppstm){
+	TODO
+}
+STDMETHODIMP CNullStorage2::CreateStorage(const WCHAR * pwcsName,DWORD grfMode,DWORD reserved1,DWORD reserved2,IStorage ** ppstg){
+	TODO
+}
+STDMETHODIMP CNullStorage2::OpenStorage(const WCHAR * pwcsName,IStorage * pstgPriority,DWORD grfMode,SNB snbExclude,DWORD reserved,IStorage ** ppstg){
+	TODO
+}
+STDMETHODIMP CNullStorage2::CopyTo(DWORD ciidExclude,IID const * rgiidExclude,SNB snbExclude,IStorage * pstgDest){
+	TODO
+}
+STDMETHODIMP CNullStorage2::MoveElementTo(const OLECHAR * pwcsName,IStorage * pstgDest,const OLECHAR* pwcsNewName,DWORD grfFlags){
+	TODO
+}
+STDMETHODIMP CNullStorage2::Commit(DWORD grfCommitFlags){
+	TODO
+}
+STDMETHODIMP CNullStorage2::Revert(void){
+	TODO
+}
+STDMETHODIMP CNullStorage2::EnumElements(DWORD reserved1,void * reserved2,DWORD reserved3,IEnumSTATSTG ** ppenum){
+	TODO
+}
+STDMETHODIMP CNullStorage2::DestroyElement(const OLECHAR * pwcsName){
+	TODO
+}
+STDMETHODIMP CNullStorage2::RenameElement(const WCHAR * pwcsOldName,const WCHAR * pwcsNewName){
+	TODO
+}
+STDMETHODIMP CNullStorage2::SetElementTimes(const WCHAR * pwcsName,FILETIME const * pctime,FILETIME const * patime,FILETIME const * pmtime){
+	TODO
+}
+STDMETHODIMP CNullStorage2::SetClass(REFCLSID clsid){
+	return S_OK;
+}
+STDMETHODIMP CNullStorage2::SetStateBits(DWORD grfStateBits,DWORD grfMask){
+	TODO
+}
+STDMETHODIMP CNullStorage2::Stat(STATSTG * pstatstg,DWORD grfStatFlag){
+	TODO
+}
+
+STDMETHODIMP CMySite2::QueryInterface(REFIID riid,void ** ppvObject){
+	if( riid == IID_IUnknown || riid == IID_IOleClientSite ){
+		*ppvObject = (IOleClientSite*)this;
+	}else if(riid == IID_IOleInPlaceSite){
+		*ppvObject = (IOleInPlaceSite*)this;
+	}else if(riid == IID_IDocHostUIHandler2){
+		*ppvObject = (IDocHostUIHandler*)this;
+	}else{
+		*ppvObject = NULL;
+		return E_NOINTERFACE;
+	}
+	return S_OK;
+}
+STDMETHODIMP_(ULONG) CMySite2::AddRef(void){
+	return 1;
+}
+STDMETHODIMP_(ULONG) CMySite2::Release(void){
+	return 1;
+}
+STDMETHODIMP CMySite2::SaveObject(){
+	TODO
+}
+STDMETHODIMP CMySite2::GetMoniker(DWORD dwAssign,DWORD dwWhichMoniker,IMoniker ** ppmk){
+	TODO
+}
+STDMETHODIMP CMySite2::GetContainer(LPOLECONTAINER FAR* ppContainer){
+	*ppContainer = NULL;
+	return E_NOINTERFACE;
+}
+STDMETHODIMP CMySite2::ShowObject(){
+	return NOERROR;
+}
+STDMETHODIMP CMySite2::OnShowWindow(BOOL fShow){
+	TODO
+}
+STDMETHODIMP CMySite2::RequestNewObjectLayout(){
+	TODO
+}
+STDMETHODIMP CMySite2::GetWindow(HWND FAR* lphwnd){
+	*lphwnd=rep->hwnd;
+	return S_OK;
+}
+STDMETHODIMP CMySite2::ContextSensitiveHelp(BOOL fEnterMode){
+	TODO
+}
+STDMETHODIMP CMySite2::CanInPlaceActivate(){
+	return S_OK;
+}
+STDMETHODIMP CMySite2::OnInPlaceActivate(){
+	return S_OK;
+}
+STDMETHODIMP CMySite2::OnUIActivate(){
+	return S_OK;
+}
+STDMETHODIMP CMySite2::GetWindowContext(
+	LPOLEINPLACEFRAME FAR* ppFrame,
+	LPOLEINPLACEUIWINDOW FAR* ppDoc,
+	LPRECT prcPosRect,
+	LPRECT prcClipRect,
+	LPOLEINPLACEFRAMEINFO lpFrameInfo){
+	*ppFrame=&rep->frame;
+	*ppDoc = NULL;
+	GetClientRect(rep->hwnd,prcPosRect);
+	GetClientRect(rep->hwnd,prcClipRect);
+	lpFrameInfo->cb=sizeof(OLEINPLACEFRAMEINFO);
+	lpFrameInfo->fMDIApp=FALSE;
+	lpFrameInfo->hwndFrame=rep->hwnd;
+	lpFrameInfo->haccel=NULL;
+	lpFrameInfo->cAccelEntries=0;
+	return S_OK;
+}
+STDMETHODIMP CMySite2::Scroll(SIZE scrollExtent){
+	TODO
+}
+STDMETHODIMP CMySite2::OnUIDeactivate(BOOL fUndoable){
+	return S_OK;
+}
+STDMETHODIMP CMySite2::OnInPlaceDeactivate(){
+	return S_OK;
+}
+STDMETHODIMP CMySite2::DiscardUndoState(){
+	TODO
+}
+STDMETHODIMP CMySite2::DeactivateAndUndo(){
+	TODO
+}
+STDMETHODIMP CMySite2::OnPosRectChange( const RECT *rect ){
+	TODO
+}
+STDMETHODIMP CMySite2::EnableModeless(  BOOL fEnable) {return S_OK;}	//[in]
+
+STDMETHODIMP CMySite2::ShowContextMenu( 
+    /* [in] */ DWORD dwID,
+    /* [in] */ POINT __RPC_FAR *ppt,
+    /* [in] */ IUnknown __RPC_FAR *pcmdtReserved,
+    /* [in] */ IDispatch __RPC_FAR *pdispReserved) 
+{
+	if (rep->viewstyle&NOCONTEXTMENU) return S_OK;
+	return S_FALSE;
+}
+
+STDMETHODIMP CMySite2::ShowUI( 
+    /* [in] */ DWORD dwID,
+    /* [in] */ IOleInPlaceActiveObject __RPC_FAR *pActiveObject,
+    /* [in] */ IOleCommandTarget __RPC_FAR *pCommandTarget,
+    /* [in] */ IOleInPlaceFrame __RPC_FAR *pFrame,
+    /* [in] */ IOleInPlaceUIWindow __RPC_FAR *pDoc)
+{
+//	pCommandTarget->Exec(0,IDM_DISABLEMODELESS,OLECMDEXECOPT_DODEFAULT,0,0);
+//	if (rep->style&SHOWUI) return S_FALSE;
+	return S_OK;
+}
+
+STDMETHODIMP CMySite2::HideUI( void)
+{
+	return S_OK;
+}
+STDMETHODIMP CMySite2::UpdateUI( void) 
+{
+	return S_OK;
+}
+
+STDMETHODIMP CMySite2::OnDocWindowActivate( /* [in] */ BOOL fActivate) {return S_OK;}
+STDMETHODIMP CMySite2::OnFrameWindowActivate( /* [in] */ BOOL fActivate){return S_OK;}
+
+STDMETHODIMP CMySite2::ResizeBorder( 
+    /* [in] */ LPCRECT prcBorder,
+    /* [in] */ IOleInPlaceUIWindow __RPC_FAR *pUIWindow,
+    /* [in] */ BOOL fRameWindow) {return S_OK;}
+
+STDMETHODIMP CMySite2::TranslateAccelerator( 	//simon was here
+    /* [in] */ LPMSG lpMsg,
+    /* [in] */ const GUID __RPC_FAR *pguidCmdGroup,
+    /* [in] */ DWORD nCmdID) 
+{
+//	printf("CMySite2::TranslateAccelerator\n");fflush(stdout);
+	if (lpMsg && lpMsg->message == WM_KEYDOWN){// && pMsg->wParam == VK_TAB) {
+		return S_FALSE;
+	}	return E_NOTIMPL;
+}
+
+STDMETHODIMP CMySite2::GetOptionKeyPath( 
+    /* [out] */ LPOLESTR __RPC_FAR *pchKey,
+    /* [in] */ DWORD dw) {return E_NOTIMPL;}
+
+STDMETHODIMP CMySite2::GetDropTarget( 
+    /* [in] */ IDropTarget __RPC_FAR *pDropTarget,
+    /* [out] */ IDropTarget __RPC_FAR *__RPC_FAR *ppDropTarget) {return E_NOTIMPL;}
+
+STDMETHODIMP CMySite2::GetExternal( /* [out] */ IDispatch __RPC_FAR *__RPC_FAR *ppDispatch) {return -1;}
+
+STDMETHODIMP CMySite2::TranslateUrl(
+    /* [in] */ DWORD dwTranslate,
+    /* [in] */ OLECHAR __RPC_FAR *pchURLIn,
+    /* [out] */ OLECHAR __RPC_FAR *__RPC_FAR *ppchURLOut)
+{
+	return S_FALSE;
+//	ppchURLOut=0;
+//	return S_OK;
+}
+
+STDMETHODIMP CMySite2::GetHostInfo( 
+    /* [out][in] */ DOCHOSTUIINFO __RPC_FAR *pInfo)
+{
+//	static DOCHOSTUIINFO	pi;
+//	pi.cbSize=sizeof(pi);
+//	pi.dwFlags|=DOCHOSTUIFLAG_SCROLL_NO;
+//	pi.dwDoubleClick=0;
+//	pInfo=&pi;
+//	pinfo.dwFlags|=DOCHOSTUIFLAG_SCROLL_NO;
+//	return S_OK;
+	return E_NOTIMPL;
+}
+
+STDMETHODIMP CMySite2::FilterDataObject( 
+    /* [in] */ IDataObject __RPC_FAR *pDO,
+    /* [out] */ IDataObject __RPC_FAR *__RPC_FAR *ppDORet) {return S_FALSE;}
+
+
+STDMETHODIMP CMyFrame2::QueryInterface(REFIID riid,void ** ppvObject){
+	TODO
+}
+STDMETHODIMP_(ULONG) CMyFrame2::AddRef(void){
+	return 1;
+}
+STDMETHODIMP_(ULONG) CMyFrame2::Release(void){
+	return 1;
+}
+STDMETHODIMP CMyFrame2::GetWindow(HWND FAR* lphwnd){
+	*lphwnd=rep->hwnd;
+	return S_OK;
+}
+STDMETHODIMP CMyFrame2::ContextSensitiveHelp(BOOL fEnterMode){
+	TODO
+}
+STDMETHODIMP CMyFrame2::GetBorder(LPRECT lprectBorder){
+	TODO
+}
+STDMETHODIMP CMyFrame2::RequestBorderSpace(LPCBORDERWIDTHS pborderwidths){
+	TODO
+}
+STDMETHODIMP CMyFrame2::SetBorderSpace(LPCBORDERWIDTHS pborderwidths){
+	TODO
+}
+STDMETHODIMP CMyFrame2::SetActiveObject(IOleInPlaceActiveObject *pActiveObject,LPCOLESTR pszObjName){
+	return S_OK;
+}
+STDMETHODIMP CMyFrame2::InsertMenus(HMENU hmenuShared,LPOLEMENUGROUPWIDTHS lpMenuWidths){
+	TODO
+}
+STDMETHODIMP CMyFrame2::SetMenu(HMENU hmenuShared,HOLEMENU holemenu,HWND hwndActiveObject){
+	return S_OK;
+}
+STDMETHODIMP CMyFrame2::RemoveMenus(HMENU hmenuShared){
+	TODO
+}
+STDMETHODIMP CMyFrame2::SetStatusText(LPCOLESTR pszStatusText){
+	return S_OK;
+}
+STDMETHODIMP CMyFrame2::EnableModeless(BOOL fEnable){
+	return S_OK;
+}
+STDMETHODIMP CMyFrame2::TranslateAccelerator(LPMSG lpmsg,WORD wID){
+	TODO
+}
+
+
+
+ULONG __stdcall DWebBrowserEventsImpl2::AddRef() { return 1;}
+ULONG __stdcall DWebBrowserEventsImpl2::Release() { return 0;}
+
+HRESULT __stdcall DWebBrowserEventsImpl2::QueryInterface(REFIID riid, LPVOID* ppv)
+{
+	*ppv = NULL;
+
+	if (IID_IUnknown == riid || IID_DWebBrowserEvents2 == riid)	//__uuidof(DWebBrowserEventsPtr) == riid)	//was PTR
+	{
+		*ppv = (LPUNKNOWN)(DWebBrowserEventsPtr*)this;
+		AddRef();
+		return NOERROR;
+	}
+	else if (IID_IOleClientSite == riid)
+	{
+		*ppv = (IOleClientSite*)this;
+		AddRef();
+		return NOERROR;
+	}
+	else if (IID_IDispatch == riid)
+	{
+		*ppv = (IDispatch*)this;
+		AddRef();
+		return NOERROR;
+	}
+	else
+	{
+		return E_NOTIMPL;
+	}
+}
+
+//	void BeforeNavigate2(IDispatch*, VARIANT*, VARIANT*, VARIANT*, VARIANT*, VARIANT*, VARIANT_BOOL*);
+
+
+HRESULT __stdcall DWebBrowserEventsImpl2::Invoke(DISPID dispIdMember,
+            REFIID riid,
+            LCID lcid,
+            WORD wFlags,
+            DISPPARAMS __RPC_FAR *pDispParams,
+            VARIANT __RPC_FAR *pVarResult,
+            EXCEPINFO __RPC_FAR *pExcepInfo,
+            UINT __RPC_FAR *puArgErr)
+{
+	switch (dispIdMember)
+	{
+	case DISPID_BEFORENAVIGATE2:		
+		BeforeNavigate2(
+			pDispParams->rgvarg[6].pdispVal,
+			pDispParams->rgvarg[5].pvarVal,
+			pDispParams->rgvarg[4].pvarVal,
+			pDispParams->rgvarg[3].pvarVal,
+			pDispParams->rgvarg[2].pvarVal,
+			pDispParams->rgvarg[1].pvarVal,
+			pDispParams->rgvarg[0].pboolVal);
+		break;
+	case DISPID_NEWWINDOW2:
+		NewWindow2(
+			pDispParams->rgvarg[1].ppdispVal,
+			pDispParams->rgvarg[0].pboolVal);		//IDispatch**, VARIANT_BOOL*
+		break;
+	case DISPID_NAVIGATECOMPLETE2:
+		NavigateComplete(pDispParams->rgvarg[1].pdispVal,pDispParams->rgvarg[0].pvarVal);
+		break;
+	case DISPID_DOCUMENTCOMPLETE:
+		DocumentComplete(pDispParams->rgvarg[1].pdispVal,pDispParams->rgvarg[0].pvarVal);
+		break;
+	}
+	return NOERROR;
+}
+
+// IDispatch methods
+HRESULT __stdcall DWebBrowserEventsImpl2::GetTypeInfoCount(UINT* pctinfo)
+{ 
+	return E_NOTIMPL; 
+}
+
+HRESULT __stdcall DWebBrowserEventsImpl2::GetTypeInfo(UINT iTInfo,
+            LCID lcid,
+            ITypeInfo** ppTInfo)
+{ 
+	return E_NOTIMPL; 
+}
+
+HRESULT __stdcall DWebBrowserEventsImpl2::GetIDsOfNames(REFIID riid,
+            LPOLESTR* rgszNames,
+            UINT cNames,
+            LCID lcid,
+            DISPID* rgDispId)
+{ 
+	return E_NOTIMPL; 
+}
+
+// Methods:
+
+void DWebBrowserEventsImpl2::NewWindow2(IDispatch**pdisp, VARIANT_BOOL*Cancel)
+{
+//	*pdisp=rep->iBrowser;
+	*Cancel=VARIANT_TRUE;// was FALSE;
+}
+
+void DWebBrowserEventsImpl2::BeforeNavigate2(IDispatch*, VARIANT*URL, VARIANT*, VARIANT*TARGET, VARIANT*, VARIANT*, VARIANT_BOOL*Cancel)
+{
+	BBString	*url;
+	*Cancel=VARIANT_FALSE;
+	if (TARGET->bstrVal) {
+		return;
+	}
+	if ((rep->viewstyle&NONAVIGATE) && (rep->navcount==0)){
+		*Cancel=VARIANT_TRUE;
+		url=bbStringFromVariant2(URL);
+		bbSystemEmitEvent( BBEVENT_GADGETACTION,rep->owner,0,0,0,0,(BBObject*)url );
+	}else{
+		rep->navcount=0;
+	}
+}
+
+void DWebBrowserEventsImpl2::NavigateComplete ( IDispatch* pDisp,VARIANT*URL )
+{
+//	printf("Navigate Complete!\n");fflush(stdout);
+//		rep->setcurrenturl(URL);
+//		rep->loading=0;
+//	rep->owner->emit( BBEVENT_GADGETDONE );
+//		bbSystemEmitEvent( BBEVENT_GADGETDONE,rep->owner,0,0,0,0,BBNULL );
+}
+
+void DWebBrowserEventsImpl2::DocumentComplete ( IDispatch* pDisp,VARIANT*URL )
+{
+//	printf("Document Complete!\n");fflush(stdout);
+	rep->setcurrenturl(URL);
+	rep->loading=0;
+//	rep->owner->emit( BBEVENT_GADGETDONE );
+	bbSystemEmitEvent( BBEVENT_GADGETDONE,rep->owner,0,0,0,0,BBNULL );
+}
+
+HRESULT DWebBrowserEventsImpl2::StatusTextChange ( _bstr_t Text ) { return S_OK; }
+
+void DWebBrowserEventsImpl2::ProgressChange (long Progress,long ProgressMax )  {}
+void DWebBrowserEventsImpl2::DownloadComplete()  {}
+void DWebBrowserEventsImpl2::CommandStateChange (long Command,VARIANT_BOOL Enable ) {}
+void DWebBrowserEventsImpl2::DownloadBegin () {}
+
+HRESULT DWebBrowserEventsImpl2::NewWindow (
+    _bstr_t URL,
+    long Flags,
+    _bstr_t TargetFrameName,
+    VARIANT * PostData,
+    _bstr_t Headers,
+    VARIANT_BOOL * Processed ) { return S_OK; }
+HRESULT DWebBrowserEventsImpl2::TitleChange ( _bstr_t Text ) { return S_OK; }
+HRESULT DWebBrowserEventsImpl2::FrameBeforeNavigate (
+    _bstr_t URL,
+    long Flags,
+    _bstr_t TargetFrameName,
+    VARIANT * PostData,
+    _bstr_t Headers,
+    VARIANT_BOOL * Cancel ) { return S_OK; }
+HRESULT DWebBrowserEventsImpl2::FrameNavigateComplete (
+    _bstr_t URL ) { return S_OK; }
+HRESULT DWebBrowserEventsImpl2::FrameNewWindow (
+    _bstr_t URL,
+    long Flags,
+    _bstr_t TargetFrameName,
+    VARIANT * PostData,
+    _bstr_t Headers,
+    VARIANT_BOOL * Processed ) { return S_OK; }
+HRESULT DWebBrowserEventsImpl2::Quit (
+    VARIANT_BOOL * Cancel ) { return S_OK; }
+HRESULT DWebBrowserEventsImpl2::WindowMove ( ) { return S_OK; }
+HRESULT DWebBrowserEventsImpl2::WindowResize ( ) { return S_OK; }
+HRESULT DWebBrowserEventsImpl2::WindowActivate ( ) { return S_OK; }
+HRESULT DWebBrowserEventsImpl2::PropertyChange (
+    _bstr_t Property ) { return S_OK; }
+
+
+// C style public interface
+	
+HTMLView * msHtmlCreate( BBObject *gadget,wchar_t *wndclass,HWND hwnd,int flags ){
+	HTMLView *view;
+	view=new HTMLView(gadget,wndclass, hwnd,flags);
+	return view;
+}
+
+void msHtmlGo( HTMLView * view,wchar_t *url ){
+	view->go(url);
+}
+
+void msHtmlRun( HTMLView * view,wchar_t *script ){
+	view->run(script);
+}
+
+void msHtmlSetShape( HTMLView * view,int x,int y,int w,int h ){
+	view->setshape(x,y,w,h);
+}
+
+void msHtmlSetVisible( HTMLView * view,int visible ){
+}
+
+void msHtmlSetEnabled( HTMLView * view,int enabled ){
+}
+
+int msHtmlActivate(HTMLView * view,int cmd){
+	return view->activate(cmd);
+}
+
+int msHtmlStatus(HTMLView * view){
+	return view->status();
+}
+
+HWND msHtmlHwnd( HTMLView * view){
+	return view->hwnd;
+}
+	
+void *msHtmlBrowser( HTMLView * view){
+	return view->iBrowser;
+}
+

+ 27 - 0
win32maxguiex.mod/mshtmlview.h

@@ -0,0 +1,27 @@
+
+#ifndef MSHTMLVIEW_H
+#define MSHTMLVIEW_H
+
+#include "brl.mod/blitz.mod/blitz.h"
+
+struct HTMLView;
+
+extern "C"{
+
+HTMLView * msHtmlCreate( BBObject *gadget,wchar_t *wndclass,HWND hwnd,int flags );
+
+void msHtmlGo( HTMLView * view,wchar_t *url );
+void msHtmlRun( HTMLView * view,wchar_t *script );
+
+void msHtmlSetShape( HTMLView * view,int x,int y,int w,int h );
+void msHtmlSetVisible( HTMLView * view,int visible );
+void msHtmlSetEnabled( HTMLView * view,int enabled );
+
+int msHtmlActivate(HTMLView * view,int cmd);
+int msHtmlStatus(HTMLView * view);
+HWND msHtmlHwnd( HTMLView * view);
+void *msHtmlBrowser( HTMLView * view);
+
+};
+
+#endif

+ 601 - 0
win32maxguiex.mod/tom.bmx

@@ -0,0 +1,601 @@
+' tom.bmx
+
+Import pub.win32
+
+Strict
+
+Import "tom.cpp"
+
+Const TOMTRUE = -1
+Const TOMFALSE = 0
+Const TOMNONE = 0
+Const TOMSINGLE = 1
+Const TOMWORDS = 2
+Const TOMDOUBLE = 3
+Const TOMDOTTED = 4
+
+Type IRichEditOLE Extends IUnknown
+	
+	Method GetClientSite()
+	End Method
+
+	Method GetObjectCount()
+	End Method
+
+	Method GetLinkCount()
+	End Method
+
+	Method GetObject()
+	End Method
+
+	Method InsertObject()
+	End Method
+
+	Method ConvertObject()
+	End Method
+
+	Method ActivateAs()
+	End Method
+
+	Method SetHostNames()
+	End Method
+
+	Method SetLinkAvailable()
+	End Method
+
+	Method SetDvaspect()
+	End Method
+
+	Method HandsOffStorage()
+	End Method
+
+	Method SaveCompleted()
+	End Method
+
+	Method InPlaceDeactivate()
+	End Method
+
+	Method ContextSensitiveHelp()
+	End Method
+
+	Method GetClipboardData()
+	End Method
+
+	Method ImportDataObject()
+	End Method
+
+End Type
+
+Extern
+	Function bmx_tom_ITextDocument_Range:Int(handle:Byte Ptr, p0:Int, p1:Int, irangePtr:Byte Ptr Ptr)
+	Function bmx_tom_ITextDocument_SetDefaultTabStop:Int(handle:Byte Ptr, Value:Float)
+	Function bmx_tom_ITextDocument_Freeze:Int(handle:Byte Ptr, count:Int Ptr)
+	Function bmx_tom_ITextDocument_Unfreeze:Int(handle:Byte Ptr, count:Int Ptr)
+End Extern
+Type ITextDocument Extends IDispatch
+	Method GetName()
+	End Method
+
+	Method GetSlection()
+	End Method
+
+	Method GetStoryCount( storycount:Int Var)
+	End Method
+
+	Method GetStoryRanges()
+	End Method
+
+	Method GetSaved()
+	End Method
+
+	Method SetSaved()
+	End Method
+
+	Method GetDefaultTabStop(Value# Var)
+	End Method
+
+	Method SetDefaultTabStop(Value:Float)
+		Return bmx_tom_ITextDocument_SetDefaultTabStop(unknownPtr, Value)
+	End Method
+
+	Method NewDocument()
+	End Method
+
+	Method Open()
+	End Method
+
+	Method Save()
+	End Method
+
+	Method Freeze(count Var)
+		Return bmx_tom_ITextDocument_Freeze(unknownPtr, Varptr count)
+	End Method
+
+	Method Unfreeze(count Var)
+		Return bmx_tom_ITextDocument_Unfreeze(unknownPtr, Varptr count)
+	End Method
+
+	Method BeginEditCollection()
+	End Method
+
+	Method EndEditCollection()
+	End Method
+
+	Method Undo()
+	End Method
+
+	Method Redo()
+	End Method
+
+	Method Range(p0,p1,irange:ITextRange Var)
+		If Not irange Then
+			irange = New ITextRange
+		End If
+		Return bmx_tom_ITextDocument_Range(unknownPtr, p0, p1, Varptr irange.unknownPtr)
+	End Method
+
+	Method RangeFromPoint(x,y,irange:ITextRange Var)
+	End Method
+
+End Type
+
+Extern
+	Function bmx_tom_ITextRange_GetFont:Int(handle:Byte Ptr, ifontPtr:Byte Ptr Ptr)
+	Function bmx_tom_ITextRange_SetText:Int(handle:Byte Ptr, bstr:Short Ptr)
+	Function bmx_tom_ITextRange_GetText:Int(handle:Byte Ptr, bstr:Short Ptr Ptr)
+End Extern
+Type ITextRange Extends IDispatch
+	Method GetText(bstr:Short Ptr Ptr)
+		Return bmx_tom_ITextRange_GetText(unknownPtr, bstr)
+	End Method
+	
+	Method SetText(bstr:Short Ptr)
+		Return bmx_tom_ITextRange_SetText(unknownPtr, bstr)
+	End Method
+	
+	Method GetChar()
+	End Method
+	
+	Method SetChar()
+	End Method
+	
+	Method GetDuplicate(irange:ITextRange Var)
+	End Method
+	
+	Method GetFormattedText()
+	End Method
+	
+	Method SetFormattedText()
+	End Method
+	
+	Method GetStart()
+	End Method
+	
+	Method SetStart()
+	End Method
+	
+	Method GetEnd()
+	End Method
+	
+	Method SetEnd()
+	End Method
+	
+	Method GetFont(ifont:ITextFont Var)
+		If Not ifont Then
+			ifont = New ITextFont
+		End If
+		Return bmx_tom_ITextRange_GetFont(unknownPtr, Varptr ifont.unknownPtr)
+	End Method
+	
+	Method SetFont(ifont:ITextFont)
+	End Method
+	
+'	Method GetPara(para:ITextPara Var)
+'	End Method
+	
+'	Method SetPara(para:ITextPara)
+'	End Method
+	
+	Method GetStoryLength( length:Int Var )
+	End Method
+	
+	Method GetStoryType( storytype:Int Var)
+	End Method
+	
+	Method Collapse()
+	End Method
+	
+	Method Expand()
+	End Method
+	
+	Method GetIndex()
+	End Method
+	
+	Method SetIndex()
+	End Method
+	
+	Method SetRange(cp1,cp2)
+	End Method
+	
+	Method InRange()
+	End Method
+	
+	Method InStory()
+	End Method
+	
+	Method IsEqual()
+	End Method
+	
+	Method Select_()
+	End Method
+	
+	Method StartOf()
+	End Method
+	
+	Method EndOf()
+	End Method
+	
+	Method Move()
+	End Method
+	
+	Method MoveStart()
+	End Method
+	
+	Method MoveEnd()
+	End Method
+	
+	Method MoveWhile()
+	End Method
+	
+	Method MoveStartWhile()
+	End Method
+	
+	Method MoveEndWhile()
+	End Method
+	
+	Method MoveUntil()
+	End Method
+	
+	Method MoveStartUntil()
+	End Method
+	
+	Method MoveEndUntil()
+	End Method
+	
+	Method FindText()
+	End Method
+	
+	Method FindTextStart()
+	End Method
+	
+	Method FindTextEnd()
+	End Method
+	
+	Method Delete_()
+	End Method
+	
+	Method Cut()
+	End Method
+	
+	Method Copy()
+	End Method
+	
+	Method Paste()
+	End Method
+	
+	Method CanPaste()
+	End Method
+	
+	Method CanEdit(bool Var)
+	End Method
+	
+	Method ChangeCase()
+	End Method
+	
+	Method GetPoint()
+	End Method
+	
+	Method SetPoint()
+	End Method
+	
+	Method ScrollIntoView()
+	End Method
+	
+	Method GetEmbeddedObject()
+	End Method
+	
+EndType
+
+Extern
+	Function bmx_tom_ITextFont_SetForeColor:Int(handle:Byte Ptr, Value:Int)
+	Function bmx_tom_ITextFont_SetBold:Int(handle:Byte Ptr, Value:Int)
+	Function bmx_tom_ITextFont_SetItalic:Int(handle:Byte Ptr, Value:Int)
+	Function bmx_tom_ITextFont_SetStrikeThrough:Int(handle:Byte Ptr, Value:Int)
+	Function bmx_tom_ITextFont_SetUnderline:Int(handle:Byte Ptr, Value:Int)
+End Extern
+Type ITextFont Extends IDispatch
+	Method GetDuplicate(ifont:ITextFont Var)
+	End Method
+	
+	Method SetDuplicate()
+	End Method
+	
+	Method CanChange()
+	End Method
+	
+	Method IsEqual() 
+	End Method
+	
+	Method Reset()
+	End Method
+	
+	Method GetStyle(Value:Int Ptr)
+	End Method
+	
+	Method SetStyle(Value)
+	End Method
+	
+	Method GetAllCaps(Value:Int Ptr)
+	End Method
+	
+	Method SetAllCaps(Value)
+	End Method
+	
+	Method GetAnimation(Value:Int Ptr)
+	End Method
+	
+	Method SetAnimation(Value)
+	End Method
+	
+	Method GetBackColor(Value:Int Ptr)
+	End Method
+	
+	Method SetBackColor(Value)
+	End Method
+	
+	Method GetBold(Value:Int Ptr)
+	End Method
+	
+	Method SetBold(Value)
+		Return bmx_tom_ITextFont_SetBold(unknownPtr, Value)
+	End Method
+	
+	Method GetEmboss(Value:Int Ptr)
+	End Method
+	
+	Method SetEmboss(Value)
+	End Method
+	
+	Method GetForeColor(Value:Int Ptr)
+	End Method
+	
+	Method SetForeColor(Value)
+		Return bmx_tom_ITextFont_SetForeColor(unknownPtr, Value)
+	End Method
+	
+	Method GetHidden(Value:Int Ptr)
+	End Method
+	
+	Method SetHidden(Value)
+	End Method
+	
+	Method GetEngrave(Value:Int Ptr)
+	End Method
+	
+	Method SetEngrave(Value)
+	End Method
+	
+	Method GetItalic(Value:Int Ptr)
+	End Method
+	
+	Method SetItalic(Value)
+		Return bmx_tom_ITextFont_SetItalic(unknownPtr, Value)
+	End Method
+	
+	Method GetKerning(Value:Int Ptr)
+	End Method
+	
+	Method SetKerning(Value)
+	End Method
+	
+	Method GetLanguageID()
+	End Method
+	
+	Method SetLanguageID() 
+	End Method
+	
+	Method GetName()
+	End Method
+	
+	Method SetName()
+	End Method
+	
+	Method GetOutline(Value:Int Ptr)
+	End Method
+	
+	Method SetOutline(Value)
+	End Method
+	
+	Method GetPosition(Value:Int Ptr)
+	End Method
+	
+	Method SetPosition(Value)
+	End Method
+	
+	Method GetProtected(Value:Int Ptr)
+	End Method
+	
+	Method SetProtected(Value)
+	End Method
+	
+	Method GetShadow(Value:Int Ptr)
+	End Method
+	
+	Method SetShadow(Value)
+	End Method
+	
+	Method GetSize(Value:Int Ptr)
+	End Method
+	
+	Method SetSize(Value)
+	End Method
+	
+	Method GetSmallCaps(Value:Int Ptr)
+	End Method
+	
+	Method SetSmallCaps(Value)
+	End Method
+	
+	Method GetSpacing(Value:Int Ptr)
+	End Method
+	
+	Method SetSpacing(Value)
+	End Method
+	
+	Method GetStrikeThrough(Value:Int Ptr)
+	End Method
+	
+	Method SetStrikeThrough(Value)
+		Return bmx_tom_ITextFont_SetStrikeThrough(unknownPtr, Value)
+	End Method
+	
+	Method GetSubscript(Value:Int Ptr)
+	End Method
+	
+	Method SetSubscript(Value)
+	End Method
+	
+	Method GetSuperscript(Value:Int Ptr)
+	End Method
+	
+	Method SetSuperscript(Value) 
+	End Method
+	
+	Method GetUnderline(Value:Int Ptr)
+	End Method
+	
+	Method SetUnderline(Value)
+		Return bmx_tom_ITextFont_SetUnderline(unknownPtr, Value)
+	End Method
+	
+	Method GetWeight(Value:Int Ptr)
+	End Method
+	
+	Method SetWeight(Value)
+	End Method
+	
+End Type
+
+Const ITextDocument_UUID$="{8CC497C0-A1DF-11ce-8098-00AA0047BE5D}"
+Rem
+Type ITextFont Extends IDispatch
+	Method GetDuplicate(ifont:ITextFont Var)
+	Method SetDuplicate()
+	Method CanChange()
+	Method IsEqual() 
+	Method Reset()
+	Method GetStyle(Value:Int Ptr)
+	Method SetStyle(Value)
+	Method GetAllCaps(Value:Int Ptr)
+	Method SetAllCaps(Value)
+	Method GetAnimation(Value:Int Ptr)
+	Method SetAnimation(Value)
+	Method GetBackColor(Value:Int Ptr)
+	Method SetBackColor(Value)
+	Method GetBold(Value:Int Ptr)
+	Method SetBold(Value)
+	Method GetEmboss(Value:Int Ptr)
+	Method SetEmboss(Value)
+	Method GetForeColor(Value:Int Ptr)
+	Method SetForeColor(Value)
+	Method GetHidden(Value:Int Ptr)
+	Method SetHidden(Value)
+	Method GetEngrave(Value:Int Ptr)
+	Method SetEngrave(Value)
+	Method GetItalic(Value:Int Ptr)
+	Method SetItalic(Value)
+	Method GetKerning(Value:Int Ptr)
+	Method SetKerning(Value)
+	Method GetLanguageID()
+	Method SetLanguageID() 
+	Method GetName()
+	Method SetName()
+	Method GetOutline(Value:Int Ptr)
+	Method SetOutline(Value)
+	Method GetPosition(Value:Int Ptr)
+	Method SetPosition(Value)
+	Method GetProtected(Value:Int Ptr)
+	Method SetProtected(Value)
+	Method GetShadow(Value:Int Ptr)
+	Method SetShadow(Value)
+	Method GetSize(Value:Int Ptr)
+	Method SetSize(Value)
+	Method GetSmallCaps(Value:Int Ptr)
+	Method SetSmallCaps(Value)
+	Method GetSpacing(Value:Int Ptr)
+	Method SetSpacing(Value)
+	Method GetStrikeThrough(Value:Int Ptr)
+	Method SetStrikeThrough(Value)
+	Method GetSubscript(Value:Int Ptr)
+	Method SetSubscript(Value)
+	Method GetSuperscript(Value:Int Ptr)
+	Method SetSuperscript(Value) 
+	Method GetUnderline(Value:Int Ptr)
+	Method SetUnderline(Value)
+	Method GetWeight(Value:Int Ptr)
+	Method SetWeight(Value)
+End Type
+
+Const ITextPara_UUID$="{8CC497C4-A1DF-11ce-8098-00AA0047BE5D}"
+
+Type ITextPara Extends IDispatch
+	Method GetDuplicate(ipara:ITextPara Var)
+	Method SetDuplicate()
+	Method CanChange()
+	Method IsEqual(para)
+	Method Reset(value)
+	Method GetStyle() 
+	Method SetStyle(value)
+	Method GetAlignment()
+	Method SetAlignment(value)
+	Method GetHyphenation()
+	Method SetHyphenation(value)
+	Method GetFirstLineIndent()
+	Method GetKeepTogether()
+	Method SetKeepTogether(value)
+	Method GetKeepWithNext()
+	Method SetKeepWithNext(value)
+	Method GetLeftIndent#()
+	Method GetLineSpacing#()
+	Method GetLineSpacingRule()
+	Method GetListAlignment()
+	Method SetListAlignment( value)
+	Method GetListLevelIndex()
+	Method SetListLevelIndex(value)
+	Method GetListStart()
+	Method SetListStart(value)
+	Method GetListTab#()
+	Method SetListTab(value#)
+	Method GetListType()
+	Method SetListType(value)
+	Method GetNoLineNumber()
+	Method SetNoLineNumber(value)
+	Method GetPageBreakBefore()
+	Method SetPageBreakBefore(value)
+	Method GetRightIndent#()
+	Method SetRightIndent(value#)
+	Method SetIndents(startindent#,leftindent#,rightindent#)
+	Method SetLineSpacing( rule,spacing# )
+	Method GetSpaceAfter()
+	Method SetSpaceAfter(value#)
+	Method GetSpaceBefore#()
+	Method SetSpaceBefore(value#)
+	Method GetWidowControl()
+	Method SetWidowControl(value)
+	Method GetTabCount( )
+	Method AddTab( pos#,align,leader )
+	Method ClearAllTabs()
+	Method DeleteTab(pos#)
+	Method GetTab(tab,pos,align,leader)	
+End Type
+End Rem

+ 83 - 0
win32maxguiex.mod/tom.cpp

@@ -0,0 +1,83 @@
+#include "windows.h"
+#include <stdio.h>
+#include <tom.h>
+
+extern "C" {
+
+	int bmx_tom_ITextDocument_Range(ITextDocument * doc, int p0, int p1, ITextRange ** range);
+	int bmx_tom_ITextDocument_SetDefaultTabStop(ITextDocument * doc, float Value);
+	int bmx_tom_ITextDocument_Freeze(ITextDocument * doc, int * count);
+	int bmx_tom_ITextDocument_Unfreeze(ITextDocument * doc, int * count);
+
+	int bmx_tom_ITextRange_GetFont(ITextRange * range, ITextFont ** font);
+	int bmx_tom_ITextRange_SetText(ITextRange * range, BSTR bstr);
+	int bmx_tom_ITextRange_GetText(ITextRange * range, BSTR * bstr);
+	
+	int bmx_tom_ITextFont_SetForeColor(ITextFont * font, int Value);
+	int bmx_tom_ITextFont_SetBold(ITextFont * font, int Value);
+	int bmx_tom_ITextFont_SetItalic(ITextFont * font, int Value);
+	int bmx_tom_ITextFont_SetStrikeThrough(ITextFont * font, int Value);
+	int bmx_tom_ITextFont_SetUnderline(ITextFont * font, int Value);
+}
+
+
+// ********************************************************
+
+int bmx_tom_ITextDocument_Range(ITextDocument * doc, int p0, int p1, ITextRange ** range) {
+	return doc->Range(p0, p1, range);
+}
+
+int bmx_tom_ITextDocument_SetDefaultTabStop(ITextDocument * doc, float Value) {
+	return doc->SetDefaultTabStop(Value);
+}
+
+int bmx_tom_ITextDocument_Freeze(ITextDocument * doc, int * count) {
+	long c;
+	int res = doc->Freeze(&c);
+	*count = c;
+	return res;
+}
+
+int bmx_tom_ITextDocument_Unfreeze(ITextDocument * doc, int * count) {
+	long c;
+	int res = doc->Unfreeze(&c);
+	*count = c;
+	return res;
+}
+
+// ********************************************************
+
+int bmx_tom_ITextRange_GetFont(ITextRange * range, ITextFont ** font) {
+	return range->GetFont(font);
+}
+
+int bmx_tom_ITextRange_SetText(ITextRange * range, BSTR bstr) {
+	return range->SetText(bstr);
+}
+
+int bmx_tom_ITextRange_GetText(ITextRange * range, BSTR * bstr) {
+	return range->GetText(bstr);
+}
+
+// ********************************************************
+
+int bmx_tom_ITextFont_SetForeColor(ITextFont * font, int Value) {
+	return font->SetForeColor(Value);
+}
+
+int bmx_tom_ITextFont_SetBold(ITextFont * font, int Value) {
+	return font->SetBold(Value);
+}
+
+int bmx_tom_ITextFont_SetItalic(ITextFont * font, int Value) {
+	return font->SetItalic(Value);
+}
+
+int bmx_tom_ITextFont_SetStrikeThrough(ITextFont * font, int Value) {
+	return font->SetStrikeThrough(Value);
+}
+
+int bmx_tom_ITextFont_SetUnderline(ITextFont * font, int Value) {
+	return font->SetUnderline(Value);
+}
+

+ 5173 - 0
win32maxguiex.mod/win32maxguiex.bmx

@@ -0,0 +1,5173 @@
+Strict
+
+Rem
+bbdoc: MaxGUI Drivers/Win32MaxGUIEx
+End Rem
+Module MaxGUI.Win32MaxGUIEx
+
+ModuleInfo "Version: 0.80"
+ModuleInfo "Author: Simon Armstrong, Seb Hollington, Bruce A Henderson"
+ModuleInfo "License: zlib/libpng"
+
+ModuleInfo "History: 0.80"
+ModuleInfo "History: Rebuilt to support Windows 64-bit."
+
+?Win32
+
+ModuleInfo "CC_OPTS: -include ~qwindows.h~q -include ~qcommctrl.h~q"
+
+Import MaxGUI.MaxGUI
+Import brl.systemdefault
+Import brl.retro
+Import "tom.bmx"
+Import "common.bmx"
+
+
+maxgui_driver = New TWindowsGUIDriver
+
+Type TWindowsGUIDriver Extends TMaxGUIDriver
+	
+	Global GadgetMap:TPtrMap
+	Global GDIDesktop:TWindowsDesktop
+	Global GDIFont:TWindowsFont
+	Global ClassAtom
+	Global ClassAtom2
+	Global KBMessageHook:Byte Ptr,MouseMessageHook:Byte Ptr
+
+	Global windowtheme:Short Ptr
+	Global _cursor, _commoncontrolversion[]
+	Global _explorerstyle = False
+	Global _activeWindow:TWindowsWindow = Null
+
+	Global _customcolors[] = 	[$FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, ..
+						 $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF, $FFFFFF ]
+
+	Global _hwndTooltips:Byte Ptr
+
+	Global intDontReleaseCapture% = False	'See WM_CAPTURECHANGED
+
+	Method New()
+
+		'Initialize libraries
+		OleInitialize(Null)
+		Local icc:TINITCOMMONCONTROLSEX = New TINITCOMMONCONTROLSEX
+		'icc.dwSize = SizeOf(icc)
+		icc.SetdwICC(ICC_WIN95_CLASSES|ICC_USEREX_CLASSES)'|ICC_COOL_CLASSES'|ICC_DATE_CLASSES
+		InitCommonControlsEx icc.controlPtr
+		
+		'Initialize Global Variables
+		GDIFont=TWindowsFont.DefaultFont()
+		GadgetMap=New TPtrMap
+		GDIDesktop=New TWindowsDesktop
+		
+		'Set-up Message Hooks
+		KBMessageHook=SetWindowsHookExW(WH_KEYBOARD,KeyboardProc,GetModuleHandleW(Null),GetCurrentThreadId())
+		MouseMessageHook=SetWindowsHookExW(WH_MOUSE,MouseProc,GetModuleHandleW(Null),GetCurrentThreadId())
+		
+		'Gadget Tooltips
+		_hwndTooltips = CreateWindowExW( 0,"tooltips_class32","",WS_POPUP|TTS_ALWAYSTIP,0,0,0,0,GDIDesktop._hwnd,0,GetModuleHandleW(Null),Null )
+		SendMessageW( _hwndTooltips, TTM_SETMAXTIPWIDTH, 0, 300 )
+		SetWindowPos( _hwndTooltips, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE )
+		
+	EndMethod
+	
+	Method Delete()
+		DestroyWindow( _hwndTooltips );_hwndTooltips = 0
+		UnhookWindowsHookEx MouseMessageHook
+		UnhookWindowsHookEx KBMessageHook
+	EndMethod
+	
+	Method UserName$()
+		Return getenv_("username")
+	End Method
+	
+	Method ComputerName$()
+		Return getenv_("userdomain")
+	End Method
+	
+	Method CreateGadget:TGadget(class,Text$,x,y,w,h,group:TGadget,style)
+		
+		Select class
+			Case GADGET_WINDOW
+				If Not group group=GDIDesktop
+		End Select
+		
+		Local gadget:TGadget = GadgetInstanceFromClass(class,group,style,Text)
+		
+		Select class
+			Case GADGET_DESKTOP, GADGET_MENUITEM, GADGET_NODE
+				Return gadget
+		End Select
+		
+		If LocalizationMode() & LOCALIZATION_OVERRIDE Then
+			LocalizeGadget(gadget,Text,"")
+		Else
+			gadget.SetText(Text)
+		EndIf
+		
+		If group Then gadget._SetParent group
+		If class <> GADGET_TOOLBAR Then gadget.SetShape(x,y,w,h)
+		
+		'v0.51: Gadgets are now only shown when they have been sized, and the text set.
+		If TWindowsGadget(gadget) Then
+			If Not TWindowsWindow(gadget)
+				gadget.SetFont(GDIFont)
+				If TWindowsGadget(group) Then
+					TWindowsGadget(gadget)._forceDisable = Not( TWindowsGadget(group)._enabled And Not TWindowsGadget(group)._forceDisable )
+					gadget.SetEnabled(Not (gadget.State()&STATE_DISABLED))
+				EndIf
+				gadget.SetShow(True)
+			ElseIf Not (style & WINDOW_HIDDEN) Then
+				gadget.SetShow(True)
+			EndIf
+		EndIf
+		
+		If TWindowsGadget(gadget) Then TWindowsGadget(gadget).Sensitize()
+		
+		Return gadget
+	EndMethod
+
+	Method GadgetInstanceFromClass:TGadget(class, group:TGadget, style = 0, Text$ = "")
+		
+		Local gadget:TGadget
+		
+		Select class
+			Case GADGET_DESKTOP
+				gadget=GDIDesktop
+			Case GADGET_MENUITEM
+				gadget=New TWindowsMenu.Create(group,style,Text)
+			Case GADGET_WINDOW
+				gadget=New TWindowsWindow.Create(group,style)
+			Case GADGET_BUTTON
+				gadget=New TWindowsButton.Create(group,style)
+			Case GADGET_TEXTFIELD
+				gadget=New TWindowsTextField.Create(group,style,Text)
+			Case GADGET_TEXTAREA
+				gadget=New TWindowsTextArea.Create(group,style)
+			Case GADGET_COMBOBOX
+				gadget=New TWindowsComboBox.Create(group,style,Text)
+			Case GADGET_LISTBOX
+				gadget=New TWindowsListBox.Create(group,style)
+			Case GADGET_TOOLBAR
+				gadget=New TWindowsToolBar.Create(group,style,Text)
+			Case GADGET_TABBER
+				gadget=New TWindowsTabber.Create(group,style)
+			Case GADGET_NODE	
+				gadget=New TWindowsTreeNode.Create(group,style,Text)
+			Case GADGET_TREEVIEW
+				gadget=New TWindowsTreeView.Create(group,style)
+			Case GADGET_LABEL
+				gadget=New TWindowsLabel.Create(group,style)
+			Case GADGET_SLIDER
+				gadget=New TWindowsSlider.Create(group,style)
+			Case GADGET_PROGBAR
+				gadget=New TWindowsProgressBar.Create(group,style)
+			Case GADGET_PANEL
+				gadget=New TWindowsPanel.Create(group,style)
+			Case GADGET_CANVAS
+				gadget=New TWindowsPanel.Create(group,style|PANEL_CANVAS|PANEL_ACTIVE)
+			Case GADGET_HTMLVIEW
+				gadget=New TWindowsHTMLView.Create(group,style)
+		End Select
+		
+		Return gadget
+		
+	EndMethod
+
+	Method ActiveGadget:TGadget()
+		Local tmpHwnd:Byte Ptr = GetFocus(), tmpGadget:TGadget
+		While tmpHwnd
+		 	tmpGadget = GadgetFromHwnd( tmpHwnd )
+			If tmpGadget Then Exit
+			tmpHwnd = GetParent_(tmpHwnd)
+		Wend
+		Return tmpGadget
+	EndMethod
+
+	Method RequestColor(red,green,blue)
+		Local cc:TChooseColor = New TChooseColor.Create(GetActiveHwnd(), (red)|(green Shl 8)|(blue Shl 16), _customcolors)
+		Local hwnd:Byte Ptr = GetFocus()
+		Local n:Int = cc.ChooseColor()
+		SetFocus(hwnd)
+		If Not n Return 0	
+		Local rgbResult:Int = cc.rgbResult()
+		n = ((rgbResult Shr 16)&$ff) | (rgbResult&$ff00) | ((rgbResult Shl 16)&$ff0000)
+		Return n|$ff000000
+	EndMethod
+
+	Method LookupColor( colorindex:Int, red:Byte Var, green:Byte Var, blue:Byte Var )
+		
+		Select colorindex
+			Case GUICOLOR_WINDOWBG
+				colorindex = COLOR_BTNFACE
+			Case GUICOLOR_GADGETBG
+				colorindex = COLOR_WINDOW
+			Case GUICOLOR_GADGETFG
+				colorindex = COLOR_WINDOWTEXT
+			Case GUICOLOR_LINKFG
+				colorindex = COLOR_HOTLIGHT
+			Case GUICOLOR_SELECTIONBG
+				colorindex = COLOR_HIGHLIGHT
+			Default
+				Return Super.LookupColor( colorindex, red, green, blue )
+		EndSelect
+		
+		Local tmpColor:Int = GetSysColor( colorindex )
+		red = tmpColor & $FF
+		green = (tmpColor Shr 8) & $FF
+		blue = (tmpColor Shr 16) & $FF
+		
+		Return True
+		
+	EndMethod
+
+	Method LoadFont:TGuiFont(name$,size,flags)
+		Return New TWindowsFont.Load(name,Double(size),flags)
+	EndMethod
+	
+	Method LoadFontWithDouble:TGuiFont(name$,size:Double,flags)
+		Return New TWindowsFont.Load(name,size,flags)
+	EndMethod
+	
+	Method LibraryFont:TGuiFont( pFontType% = GUIFONT_SYSTEM, pFontSize:Double = 0, pFontStyle% = FONT_NORMAL )
+		If pFontType = GUIFONT_SYSTEM Then Return TWindowsFont.DefaultFont( pFontSize, pFontStyle ) Else Return Super.LibraryFont( pFontType, pFontSize, pFontStyle )
+	EndMethod
+	
+	Method RequestFont:TGuiFont(font:TGuiFont)
+		Return TWindowsFont.Request(font)
+	EndMethod
+		
+	Method SetPointer(shape)
+		'Global winptrs[]=[0,32512,32513,32514,32515,32516,32642,32643,32644,32645,32646,32648,32649,32650,32651]
+		'If shape<1 Or shape>14 Then _cursor = LoadCursorW( 0,Short Ptr( IDC_ARROW ) ) Else _cursor=LoadCursorW(0,Short Ptr(winptrs[shape]))
+		'SetCursor(_cursor)
+		'If TWindowsTextArea._oldCursor Then TWindowsTextArea._oldCursor = _cursor
+		'If shape = 0 Then _cursor = 0
+	EndMethod
+
+	Method LoadIconStrip:TIconStrip(source:Object)		
+		Return TWindowsIconStrip.Create(source)
+	EndMethod
+	
+	
+	'Low-level Win32 interface
+
+	Function RegisterHwnd(hwnd:Byte Ptr,gadget:TWindowsGadget)
+		GadgetMap.Insert hwnd,gadget		
+	EndFunction
+	
+	Function RemoveHwnd(hwnd:Byte Ptr)
+		GadgetMap.Remove hwnd
+	EndFunction
+	
+	Function GadgetFromHwnd:TWindowsGadget(hwnd:Byte Ptr) nodebug
+		Return TWindowsGadget(GadgetMap.ValueForKey(hwnd))
+	EndFunction
+	
+	Function ClassWndProc:Byte Ptr(hwnd:Byte Ptr,msg:Uint,wp:Byte Ptr,lp:Byte Ptr) "win32"
+		Local owner:TWindowsGadget
+		Local res
+		Local nmhdrPtr:Byte Ptr
+		
+		'?Debug And Win32
+		'Print TWindowsDebug.ReverseLookupMsg(msg) + ", hwnd: " + hwnd + ", wp: " + wp + ", lp: " + lp
+		'?Win32
+		
+		Select msg
+			
+			Case WM_MENUCHAR
+				
+				If HotKeyEventFromWp(Long(wp) & $FF) Then
+					Return (MNC_CLOSE Shl 16)
+				Else
+					Return (MNC_IGNORE Shl 16)
+				EndIf
+			
+			Case WM_SIZE
+				
+				owner = GadgetFromHwnd(hwnd)
+				If owner And Not TWindowsWindow(owner) Then
+					If hwnd = owner.Query(QUERY_HWND) Then owner.RethinkClient()
+					If hwnd = owner.Query(QUERY_HWND_CLIENT) Then owner.LayoutKids()
+				EndIf
+			
+			Case WM_CTLCOLORSTATIC, WM_CTLCOLOREDIT, WM_CTLCOLORBTN
+				
+				owner=GadgetFromHwnd(lp)
+				
+				Select True
+					
+					Case TWindowsLabel(owner) <> Null
+					
+						SetBkMode(wp, TRANSPARENT)
+						If owner.FgColor() > -1 Then SetTextColor_(wp, owner.FgColor())
+						Return owner.CreateControlBrush( owner._hwnd, wp )
+				
+					Case TWindowsPanel(owner) <> Null
+						
+						If TWindowsPanel(owner)._type = TWindowsPanel.PANELGROUP Then
+							
+							SetBkMode(wp, TRANSPARENT)
+							If owner.FgColor() > -1 Then SetTextColor_(wp, owner.FgColor())
+							Return owner.CreateControlBrush( lp, wp )
+							
+						EndIf
+						
+					Case TWindowsTextField(owner) <> Null, TWindowsComboBox(owner) <> Null
+						
+						If owner.FgColor() > -1 Then SetTextColor_(wp, owner.FgColor())
+						If owner.BgBrush() Then SetBkColor(wp, owner.BgColor());Return owner.BgBrush()
+						
+					Case TWindowsButton(owner) <> Null, TWindowsSlider(owner) <> Null
+						
+						SetBkMode(wp, TRANSPARENT)
+						If owner.FgColor() > -1 Then SetTextColor_(wp, owner.FgColor())
+						Return owner.CreateControlBrush( owner._hwnd, wp )
+					
+				EndSelect
+				
+				owner = Null
+				
+			Case WM_COMMAND,WM_HSCROLL,WM_VSCROLL
+				If lp Then
+					owner=GadgetFromHwnd(lp)
+					'Fix for tab control's up/down arrow.
+					If Not owner Then owner = GadgetFromHwnd(GetParent_(lp))
+				Else
+					owner=GadgetFromHwnd(hwnd)		'Fixed for menu events
+				EndIf
+
+				If Not owner Then owner = GadgetFromHwnd(hwnd)
+
+				If owner Then
+					res=owner.OnCommand(msg,ULong(wp))
+					If Not res And owner._proc And owner._hwnd = hwnd Return CallWindowProcW(owner._proc,hwnd,msg,wp,lp)
+					Return res
+				Else
+					Return DefWindowProcW( hwnd,msg,wp,lp )
+				EndIf
+				
+			Case WM_NOTIFY
+				'Gadget tooltips
+				nmhdrPtr=lp
+				owner=GadgetFromHwnd(bmx_win32_NMHDR_hwndFrom(nmhdrPtr))		
+				If owner Then
+					Select bmx_win32_NMHDR_code(nmhdrPtr)
+						Case TTN_GETDISPINFOW
+							If owner._wstrTooltip Then bmx_win32_NMTTDISPINFOW_SetlpszText(nmhdrPtr, owner._wstrTooltip)
+					EndSelect
+					Return owner.OnNotify(wp,lp)
+				EndIf
+				
+			Case WM_SETCURSOR
+			
+				If _cursor Then
+					SetCursor(_cursor)
+					Return 1
+				EndIf
+				
+			Case WM_ACTIVATEAPP, WM_ACTIVATE
+			
+				SystemEmitOSEvent(hwnd,msg,wp,lp,Null)
+			
+			Case WM_DRAWITEM
+				
+				Local tmpDrawItemStruct:DRAWITEMSTRUCT = DRAWITEMSTRUCT._create(lp)
+				'MemCopy tmpDrawItemStruct, Byte Ptr lp, SizeOf(tmpDrawItemStruct)
+				
+				owner = GadgetFromHwnd(tmpDrawItemStruct.hwndItem())
+				If owner And owner.OnDrawItem( tmpDrawItemStruct ) Then Return True
+				
+				owner = Null
+			
+			'Allow BRL.System to handle mouse/key events on sensitive gadgets.
+				
+			Case WM_CAPTURECHANGED
+				
+				'For preventing problem where controls which called SetCapture() internally
+				'had their capture prematurely released by the ReleaseCapture() call in BRL.System.
+				intDontReleaseCapture = False
+				'If SetCapture() is called again after BRL.System's call (when the new
+				'capture hwnd [lp] = old hwnd [hwnd]) then we dont want to call ReleaseCapture() in BRL.System
+				'when WM_MOUSEBUTTONUP is received by the system hook TWindowsGUIDriver.MouseProc().
+				If (lp = hwnd) And (Not intEmitOSEvent) Then intDontReleaseCapture = True
+			
+			Default
+				
+				'Added preliminary check to avoid searching for a gadget in GadgetMap un-necessarily.
+				If (msg = WM_MOUSEWHEEL) Or (msg = WM_MOUSELEAVE) Or (msg>=WM_KEYFIRST And msg<=WM_KEYLAST) Then
+					owner=GadgetFromHwnd(hwnd)
+					If owner Then
+						Select msg
+							Case WM_MOUSELEAVE, WM_MOUSEWHEEL
+								If (owner.sensitivity&SENSITIZE_MOUSE) Then SystemEmitOSEvent hwnd,msg,wp,lp,owner
+							Case WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, WM_SYSKEYUP, WM_CHAR, WM_SYSCHAR
+								If (owner.sensitivity&SENSITIZE_KEYS) And Not GadgetDisabled(owner) Then
+									SystemEmitOSEvent hwnd,msg,wp,lp,owner
+								EndIf
+								If (msg<>WM_CHAR And msg<>WM_SYSCHAR) And HotKeyEventFromWp(Long(wp)) Then Return 1
+						EndSelect
+					EndIf
+				EndIf
+			
+		EndSelect
+		
+		If Not owner Then owner=GadgetFromHwnd(hwnd)
+		If owner Return owner.WndProc(hwnd,msg,wp,lp)
+		
+		Return DefWindowProcW( hwnd,msg,wp,lp )
+
+	EndFunction
+
+	Function KeyboardProc:Byte Ptr( code, wparam:Byte Ptr, lparam:Byte Ptr ) "win32" nodebug
+		Local ev:TEvent, hwnd:Byte Ptr, tmpClassName:Short[16], mods:Int, key:Int = Int(wparam)
+		If code>=0 Then
+			'Removed: http://www.blitzbasic.com/Community/posts.php?topic=72737
+'			Rem
+			If wparam = $D Then	'$D: VK_RETURN
+				hwnd = GetFocus()
+				If hwnd And GetClassNameW(hwnd,tmpClassName,tmpClassName.length) And String.FromWString(tmpClassName).ToUpper() = "EDIT" Then
+					SetFocus(GetParent_(hwnd))
+				EndIf
+			EndIf
+'			EndRem
+
+			ev = HotkeyEventFromWp(wparam)
+			If ev
+				'Hot-key events shouldn't be emitted if the source gadget is disabled
+				If Not(TGadget(ev.source) And GadgetDisabled(TGadget(ev.source))) Then
+					If Not (UInt(lparam) & $80000000) Then
+						EmitEvent ev
+						If ev.mods Then Return 1	'Key press events never reach active panels etc. if we return 1
+					EndIf
+				EndIf
+			EndIf		
+		EndIf
+		Return CallNextHookEx( KBMessageHook,code,wparam,lparam )
+	EndFunction
+
+	Function HotkeyEventFromWp:TEvent(wparam:Byte Ptr)
+		Local key = Int(wparam), mods = KeyMods()
+		Select wparam
+			Case VK_SHIFT, $A0, $A1
+				If (wparam=VK_SHIFT) Then key = KEY_LSHIFT
+				mods:&~MODIFIER_SHIFT
+			Case VK_CONTROL, $A2, $A3
+				If (wparam=VK_CONTROL) Then key = KEY_LCONTROL
+				mods:&~MODIFIER_CONTROL
+			Case VK_MENU, $A4, $A5
+				If (wparam=VK_MENU) Then key = KEY_LALT
+				mods:&~MODIFIER_ALT
+			Case VK_LWIN, VK_RWIN
+				mods:&~MODIFIER_SYSTEM
+		EndSelect
+		Return HotKeyEvent( key,mods,GetForegroundWindow() )
+	EndFunction
+
+	Global intButtonStates%[3]
+	
+	Function MouseProc:Byte Ptr( code,wparam:Byte Ptr,lparam:Byte Ptr ) "win32" nodebug
+
+		If code>=0 And Int(wparam) >= WM_MOUSEFIRST And Int(wparam) <= WM_MOUSELAST Then 'Not needed as MouseProc only receives mouse messages!!!
+
+			Global mh:MOUSEHOOKSTRUCT = New MOUSEHOOKSTRUCT
+			mh.hookPtr = lparam
+			Local wp, lp, data
+			Local hwnd:Byte Ptr = mh.hwnd(), msg% = Int(wparam), owner:TWindowsGadget
+			Local point:Int[] = [mh.x(), mh.y()]
+			
+			Select msg
+				Case WM_LBUTTONDOWN, WM_LBUTTONDBLCLK
+					data = MOUSE_LEFT
+					msg = WM_LBUTTONDOWN
+					intButtonStates[MOUSE_LEFT] = True
+				Case WM_LBUTTONUP
+					data = MOUSE_LEFT
+					intButtonStates[MOUSE_LEFT] = False
+				Case WM_RBUTTONDOWN, WM_RBUTTONDBLCLK
+					data = MOUSE_RIGHT
+					msg = WM_RBUTTONDOWN
+					intButtonStates[MOUSE_RIGHT] = True
+				Case WM_RBUTTONUP
+					data = MOUSE_RIGHT
+					intButtonStates[MOUSE_RIGHT] = False
+				Case WM_MBUTTONDOWN, WM_MBUTTONDBLCLK
+					data = MOUSE_MIDDLE
+					msg = WM_MBUTTONDOWN
+					intButtonStates[MOUSE_MIDDLE] = True
+				Case WM_MBUTTONUP
+					data = MOUSE_MIDDLE
+					intButtonStates[MOUSE_MIDDLE] = False
+			EndSelect
+			
+			owner = GadgetFromHwnd(hwnd)
+			If owner And ScreenToClient( hwnd, point ) Then
+				
+				If data And (Not intButtonStates[data]) And TGadget.dragGadget[data-1] Then
+					PostGuiEvent EVENT_GADGETDROP, owner, data, KeyMods(), point[0], point[1], TGadget.dragGadget[data-1]
+					TGadget.dragGadget[data-1] = Null
+				EndIf
+				
+				If (owner.sensitivity&SENSITIZE_MOUSE) Then
+					
+					'Fake wp parameter to pass onto bbSystemEmitOSEvent
+					If intButtonStates[MOUSE_LEFT] Then wp:|MK_LBUTTON
+					If intButtonStates[MOUSE_MIDDLE] Then wp:|MK_MBUTTON
+					If intButtonStates[MOUSE_RIGHT] Then wp:|MK_RBUTTON
+					If GetKeyState(VK_SHIFT)&$8000 Then wp:|MK_SHIFT
+					If GetKeyState(VK_CONTROL)&$8000 Then wp:|MK_CONTROL
+					
+					lp = (Short(point[1]) Shl 16) | Short(point[0])
+					'Sort and determine whether to emit the event
+					Select msg
+						Case WM_MOUSEMOVE
+							If (owner._oldcursorlp<>lp) Then
+								owner._oldcursorlp=lp
+								SystemEmitOSEvent hwnd,msg,wp,lp,owner
+							EndIf
+						Case WM_LBUTTONUP, WM_RBUTTONUP, WM_MBUTTONUP
+							If intDontReleaseCapture Then
+								PostGuiEvent EVENT_MOUSEUP, owner, data
+							Else
+								SystemEmitOSEvent hwnd,msg,wp,lp,owner
+							EndIf
+						Case WM_LBUTTONDOWN, WM_RBUTTONDOWN, WM_MBUTTONDOWN
+							SystemEmitOSEvent hwnd,msg,wp,lp,owner
+					EndSelect
+					
+				EndIf
+			EndIf
+		EndIf
+		Return CallNextHookEx( MouseMessageHook,code,wparam,lparam )
+	EndFunction
+	
+	Global intEmitOSEvent
+	
+	Function SystemEmitOSEvent( hwnd:Byte Ptr, msg:Uint, wp:Byte Ptr, lp:Byte Ptr, owner:TGadget )
+		intEmitOSEvent:+1
+		If owner Then
+			While owner.source
+				owner = owner.source
+			Wend
+		EndIf
+		Local tmpResult% = bbSystemEmitOSEvent( hwnd, msg, wp, lp, owner )
+		intEmitOSEvent:-1
+		Return tmpResult
+	EndFunction
+
+	Function CheckCommonControlVersion()	'Returns True if supports alpha/themes etc. or False if not.
+		If Not _commoncontrolversion Then
+			Local libComCtl:Byte Ptr = LoadLibraryW("comctl32.dll")
+			Local GetCommonControlVersion( pDllVersionInfo:Byte Ptr ) "win32" = GetProcAddress(libComCtl, "DllGetVersion")
+			If GetCommonControlVersion Then
+				Local tmpDllVersion:DLLVERSIONINFO2 = New DLLVERSIONINFO2
+				GetCommonControlVersion( tmpDllVersion.infoPtr )
+				_commoncontrolversion = [tmpDllVersion.dwMajorVersion(),tmpDllVersion.dwMinorVersion(),tmpDLLVersion.dwBuildNumber()]
+			EndIf
+			GetCommonControlVersion = Null
+			FreeLibrary( libComCtl )
+		EndIf
+		If _commoncontrolversion And _commoncontrolversion[0] >= 6 Then
+			If (_commoncontrolversion[0] > 6) Or (_commoncontrolversion[1] > 0) Then Return 2 Else Return 1
+		EndIf
+	EndFunction
+	
+	Function GetThemeHandle:Byte Ptr(hwnd:Byte Ptr, pClass$ = "WINDOW")
+		If CheckCommonControlVersion() Then Return OpenThemeData(hwnd, pClass)
+	EndFunction
+
+	Function CloseThemeHandle(hTheme:Byte Ptr)
+		Return CloseThemeData(hTheme)
+	EndFunction
+	
+	Function CreateExplorerStyleGadgets( pDisable = False )
+		_explorerstyle = (pDisable <> True)
+	EndFunction
+	
+
+	Function GetActiveHwnd:Byte Ptr()
+		If _activeWindow Then Return _activeWindow._hwnd Else Return GetActiveWindow()
+	EndFunction
+
+
+	Function ClassName$()
+		Global _name$
+		Global _wc:WNDCLASSW
+		Global _icon:Byte Ptr
+		
+		If Not _name
+			_name="BLITZMAX_WINDOW_CLASS"
+			_icon=LoadIconW(GetModuleHandleW(Null),Short Ptr(101))
+			_wc=New WNDCLASSW
+			_wc.Setstyle(CS_OWNDC|CS_HREDRAW|CS_VREDRAW)
+			_wc.SetlpfnWndProc(ClassWndProc)
+			_wc.SethInstance(GetModuleHandleW(Null))
+			_wc.SethIcon(_icon)
+			_wc.SethCursor(LoadCursorW( 0,Short Ptr( IDC_ARROW ) ))
+			_wc.SethbrBackground(COLOR_BTNSHADOW)
+			'_wc.lpszMenuName=Null
+			Local n:Short Ptr = _name.ToWString()
+			_wc.SetlpszClassName(n)
+			_wc.SetcbWndExtra(DLGWINDOWEXTRA)
+			ClassAtom=RegisterClassW(_wc.classPtr)
+			MemFree(n)
+		EndIf
+		Return _name
+	EndFunction
+
+	Function DialogClassName$()
+		Global _dname$
+		Global _dc:WNDCLASSW
+		
+		If Not _dname
+			_dname="BLITZMAX_DIALOG_CLASS"
+			_dc=New WNDCLASSW
+			_dc.Setstyle(CS_OWNDC|CS_HREDRAW|CS_VREDRAW)
+			_dc.SetlpfnWndProc(ClassWndProc)
+			_dc.SethInstance(GetModuleHandleW(Null))
+			_dc.SethCursor(LoadCursorW( 0,Short Ptr( IDC_ARROW ) ))
+			_dc.SethbrBackground(COLOR_BTNSHADOW)
+			'_dc.lpszMenuName=Null
+			Local n:Short Ptr = _dname.ToWString()
+			_dc.SetlpszClassName(_dname.ToWString())
+			_dc.SetcbWndExtra(DLGWINDOWEXTRA)
+			ClassAtom2=RegisterClassW(_dc.classPtr)
+			MemFree(n)
+		EndIf
+		Return _dname
+	EndFunction
+
+End Type
+
+
+
+Type TChooseColor
+
+	Field colorPtr:Byte Ptr
+
+	Method Create:TChooseColor(parent:Byte Ptr, rgb:Int, customColors:Int Ptr, flags:Int = CC_RGBINIT|CC_FULLOPEN|CC_ANYCOLOR)
+		colorPtr = bmx_win32maxgui_choosecolor_new(parent, rgb, customColors, flags)
+		Return Self
+	End Method
+	
+	Method ChooseColor:Int()
+		Return bmx_win32maxgui_choosecolor_ChooseColor(colorPtr)
+	End Method
+	
+	Method rgbResult:Int()
+		Return bmx_win32maxgui_choosecolor_rgbResult(colorPtr)
+	End Method
+	
+	Method Delete()
+		If colorPtr Then
+			bmx_win32maxgui_choosecolor_free(colorPtr)
+			colorPtr = Null
+		End If
+	End Method
+	
+End Type
+
+
+
+
+Type TWindowsIconStrip Extends TIconStrip
+	
+	Field	_blanks[]
+	Field	_imagelist:Byte Ptr
+
+	Function DetectNotBlank(pixmap:TPixmap,xx,n)
+		Local c = pixmap.ReadPixel(xx,0), y
+		For Local x=0 Until n
+			For y=0 Until n
+				If pixmap.ReadPixel(xx+x,y)<>c Return True
+			Next
+		Next
+	EndFunction
+	
+	Method IsBlankIcon(n)
+		Return _blanks[n]
+	EndMethod
+	
+	Function RemoveMask(pixmap:TPixmap)
+		If pixmap.format<>( PF_RGBA8888 ) And pixmap.format<>( PF_BGRA8888 ) Return
+		Local w = pixmap.width, h = pixmap.height, y, c
+		For Local x=0 Until w
+			For y=0 Until h
+				c=pixmap.ReadPixel(x,y) 			
+				If c>=0 pixmap.WritePixel x,y,-1
+			Next
+		Next
+	EndFunction
+	
+	Function BuildImageList:Byte Ptr(pixmap:TPixmap)
+		Local bitmap:Byte Ptr,imagelist:Byte Ptr,sz,mask:Byte Ptr
+		sz=pixmap.height
+		If TWindowsGUIDriver.CheckCommonControlVersion() And (Pixmap.format=PF_RGBA8888 Or pixmap.format=PF_BGRA8888)
+			imagelist=ImageList_Create(sz,sz,ILC_COLOR32,0,1)
+			If imagelist
+				bitmap=TWindowsGraphic.BitmapFromPixmap(pixmap, True)
+				ImageList_Add(imagelist,bitmap,0)
+			EndIf
+		EndIf
+		If imagelist=0
+			bitmap=TWindowsGraphic.BitmapFromPixmap(pixmap, False)
+			mask=TWindowsGraphic.BitmapMaskFromPixmap(pixmap)
+			imagelist=ImageList_Create(sz,sz,ILC_COLOR24|ILC_MASK,0,1)
+			ImageList_Add(imagelist,bitmap,mask)
+			DeleteObject(mask)
+		EndIf
+		DeleteObject(bitmap)
+		Return imagelist
+	EndFunction
+
+	Function Create:TWindowsIconStrip(source:Object)
+		Local	icons:TWindowsIconStrip
+		Local	imagelist:Byte Ptr
+		Local	n,i,sz
+		Local	blanks[]
+		
+		'Get a 24-bit pixmap from source				
+		Local pix:TPixmap = TPixmap(source)
+		If Not pix pix = LoadPixmap(source)
+		If Not pix Return
+Print "image ok"
+		'Detect blank icons in the set		
+		sz=pix.height;If sz n=pix.width/sz
+		If n=0 Return	
+		blanks=New Int[n]
+		For i=0 Until n
+			blanks[i]=Not DetectNotBlank(pix,i*sz,sz)
+		Next
+		
+		'Build a Win32 Image-List
+		imagelist=BuildImageList(pix)		
+		icons = New TWindowsIconStrip
+		icons.pixmap = pix
+		icons.count=n
+		icons._blanks=blanks
+		icons._imagelist=imagelist
+				
+		Return icons
+	EndFunction	
+	
+	Function CreateBlank:TWindowsIconStrip()
+		Return Create(CreatePixmap(1,1,PF_BGR888))
+	EndFunction
+	
+	Method Delete()
+		If _imagelist Then
+			ImageList_Destroy(_imagelist)
+			_imagelist = 0
+		EndIf
+	EndMethod
+	
+EndType
+
+Type TWindowsFont Extends TGuiFont
+	
+	Method Load:TWindowsFont(_name$,_size:Double,_style)
+		
+		If handle Then
+			DeleteObject handle
+			handle = 0
+		End If
+		
+		Local cfweight = FW_NORMAL
+		Local cfsize = -LogicalUnitsFromSize( _size )
+		
+		If _style & FONT_BOLD cfweight=FW_BOLD
+		handle = CreateFontW( cfsize, 0,0,0,cfweight,..
+			(_style & FONT_ITALIC) ,..
+			(_style & FONT_UNDERLINE),..
+			(_style & FONT_STRIKETHROUGH),..
+			DEFAULT_CHARSET,..
+			OUT_DEFAULT_PRECIS,..
+			CLIP_DEFAULT_PRECIS,..
+			ANTIALIASED_QUALITY,..
+			DEFAULT_PITCH|FF_DONTCARE,..
+			_name.toWString())
+		
+		'Now lets test to see whether the right font was found
+		
+		name = NameFromHandle(handle)
+		
+		'If the font returned has a different name to that requested, let's try the symbol character set
+		
+		If name.ToLower() <> _name.ToLower() Then
+			Local tmpSymbolHandle:Byte Ptr = CreateFontW( cfsize, 0,0,0,cfweight,..
+							(_style & FONT_ITALIC) ,..
+							(_style & FONT_UNDERLINE),..
+							(_style & FONT_STRIKETHROUGH),..
+							SYMBOL_CHARSET,..
+							OUT_DEFAULT_PRECIS,..
+							CLIP_DEFAULT_PRECIS,..
+							ANTIALIASED_QUALITY,..
+							DEFAULT_PITCH|FF_DONTCARE,..
+							_name.toWString())
+			
+			Local strSymbolName:String = NameFromHandle(tmpSymbolHandle)
+			
+			'If we now have a match, delete the first font returned and use the new symbol one.
+			
+			If strSymbolName.ToLower() = _name.ToLower() Then
+				DeleteObject handle
+				handle = tmpSymbolHandle
+				name = strSymbolName
+			Else
+				DeleteObject tmpSymbolHandle
+			EndIf
+			
+		EndIf
+			
+		size=_size
+		style=_style
+		
+		Return Self
+		
+	EndMethod
+	
+	Method LoadFromLogFont:TWindowsFont( pLogFont:LOGFONTW, pStyle% = 0, pSize:Double = 0:Double )
+		
+		If pLogFont.lfWeight()>=FW_BOLD Then pStyle:| FONT_BOLD
+		If pLogFont.lfItalic() Then pStyle:| FONT_ITALIC
+		If pLogFont.lfUnderline() Then pStyle:| FONT_UNDERLINE
+		If pLogFont.lfStrikeOut() Then pStyle:| FONT_STRIKETHROUGH
+		
+		style = pStyle
+		
+		If Not pSize Then pSize = SizeFromLogFont( pLogFont )
+		
+		size = pSize
+		
+		SetLogFontProperties( pLogFont, pStyle, pSize )
+		
+		name = String.FromWString( pLogFont.lfFaceName() )
+		
+		If handle Then DeleteObject handle
+		handle = CreateFontIndirectW( pLogFont )
+		
+		Return Self
+		
+	EndMethod
+	
+	Method LoadFromHandle:TWindowsFont(hfont:Byte Ptr)
+		
+		Local tmpLogFont:LOGFONTW = New LOGFONTW
+		GetObjectW( hfont, SizeOf(LOGFONTW), tmpLogFont )
+		Return LoadFromLogFont( tmpLogFont )
+		
+	EndMethod
+	
+	Method CharWidth( charcode )
+		Local hdc:Byte Ptr=GetDC(0)	
+		Local tfont:Byte Ptr=SelectObject( hdc,handle )
+		
+		Local width=8,widths[3]
+		
+		If GetCharABCWidthsW( hdc,charcode,charcode,widths )
+			width=widths[0]+widths[1]+widths[2]
+		Else If GetCharWidth32W( hdc,charcode,charcode,widths )
+			width=widths[0]
+		EndIf
+		
+		SelectObject hdc,tfont
+		ReleaseDC 0,hdc
+		
+		Return width
+	EndMethod
+	
+	Method GetMaxCharWidth()	
+		Local hdc:Byte Ptr=GetDC(0)
+		Local tfont:Byte Ptr=SelectObject(hdc,handle)
+		Local tm:TEXTMETRICW=New TEXTMETRICW
+		GetTextMetricsW hdc,tm.metricPtr
+		SelectObject(hdc,tfont)
+		ReleaseDC(0,hdc)		
+		Return tm.tmAveCharWidth()
+	EndMethod
+	
+	Method Delete()
+		If handle Then DeleteObject handle
+	EndMethod
+	
+	Function Request:TWindowsFont(font:TGuiFont)
+		
+		Local lf:LOGFONTW = New LOGFONTW
+		Local cf:CHOOSEFONTW = New CHOOSEFONTW
+		
+		'cf.lStructSize=SizeOf(cf)
+		cf.SethwndOwner(TWindowsGUIDriver.GetActiveHwnd())
+		cf.SetlpLogFont(lf.fontPtr)
+		cf.SetFlags(CF_BOTH)
+		
+		If font
+			Local p:Short Ptr = lf.lfFaceName()
+			For Local i = 0 Until Min(font.name.length, 31)
+				p[i]=font.name[i]
+			Next
+			SetLogFontProperties( lf, font.style, font.size )			
+			cf.SetFlags(cf.Flags()|CF_INITTOLOGFONTSTRUCT)
+		EndIf
+		
+		Local hwnd:Byte Ptr = GetFocus()
+		Local n = ChooseFontW_(cf)
+		SetFocus(hwnd)
+		If Not n Return
+		
+		Local style
+		If cf.nFontType()&BOLD_FONTTYPE style:|FONT_BOLD
+		If cf.nFontType()&ITALIC_FONTTYPE style:|FONT_ITALIC
+		Return New TWindowsFont.LoadFromLogFont( lf, style, cf.iPointSize()/Double(10) )
+		
+	EndFunction
+
+	Function DefaultFont:TWindowsFont( pFontSize:Double = 0, pFontStyle% = FONT_NORMAL )
+
+		'Attempts to get hold of the Windows themed font (typically Tahoma on XP, Segeo UI on Vista)
+		Local tmpNonClientMetrics:NONCLIENTMETRICSW = New NONCLIENTMETRICSW
+		
+		If SystemParametersInfoW( SPI_GETNONCLIENTMETRICS, 0, tmpNonClientMetrics.metricsPtr, 0 ) Then
+			Return New TWindowsFont.LoadFromLogFont( tmpNonClientMetrics.lfMessageFont(), pFontStyle, pFontSize )
+		EndIf
+		
+		'If these functions, for whatever reason, fail, then the default GUI font is used (typically MS Sans Serif).
+		'Note: A font size of '8' has has been hard-coded in as no reliable substitute can be found, however this may cause
+		'text to appear too small in some languages/lacalizations.
+		If pFontSize <= 0 Then pFontSize = 8
+		Return New TWindowsFont.Load( "MS Shell Dlg", pFontSize, pFontStyle )
+
+	EndFunction
+
+	Function NameFromHandle:String( pFntHandle:Byte Ptr )
+		
+		Local hdc:Byte Ptr = GetDC(0), buffer:Short[512]
+		Local tfont:Byte Ptr = SelectObject(hdc,pFntHandle)
+		
+		If Not GetTextFaceW(hdc,buffer.length,buffer) buffer[0] = 0
+		
+		SelectObject(hdc, tfont)
+		ReleaseDC(0,hdc)
+		
+		Return String.FromWString(buffer)
+		
+	EndFunction
+	
+	Function LogicalUnitsFromSize( pSize:Double )
+		
+		Local tmpDC:Byte Ptr = GetDC(0)
+		Local tmpSize:Int = (pSize * GetDeviceCaps(tmpDC,LOGPIXELSY))/72 + 0.5
+		ReleaseDC( 0, tmpDC )
+		Return tmpSize
+		
+	EndFunction
+	
+	Function SizeFromLogFont:Double( pLogFont:LOGFONTW )
+		
+		Local tmpDC:Byte Ptr = GetDC(0)
+		Local tmpSize:Double = (Abs(pLogFont.lfHeight()) * Double(72.0) )/GetDeviceCaps(tmpDC,LOGPIXELSY)
+		ReleaseDC( 0, tmpDC )
+		Return tmpSize
+		
+	EndFunction
+	
+	Function SetLogFontProperties( pLogFont:LOGFONTW, pFlags%, pSize:Double = 0:Double )
+		
+		If pFlags&FONT_BOLD Then pLogFont.SetlfWeight(FW_BOLD) Else pLogFont.SetlfWeight(FW_NORMAL)
+		If pFlags&FONT_ITALIC Then pLogFont.SetlfItalic(True) Else pLogFont.SetlfItalic(False)
+		If pFlags&FONT_UNDERLINE Then pLogFont.SetlfUnderline(True) Else pLogFont.SetlfUnderline(False)
+		If pFlags&FONT_STRIKETHROUGH Then pLogFont.SetlfStrikeOut(True) Else pLogFont.SetlfStrikeOut(False)
+		
+		If pSize > 0 Then pLogFont.SetlfHeight(-LogicalUnitsFromSize( pSize ))
+		
+	EndFunction
+	
+EndType
+
+
+Type TWindowsGadget Extends TGadget
+
+	'Flag that determines whether gadgets should redraw when they are resized (see Rethink()).
+	Global _resizeRedraw = True
+	
+	'Generic Unicode Strings to prevent memory-leak
+	Global _wstrEmpty:Short Ptr = "".ToWString()
+	Global _wstrSpace:Short Ptr = " ".ToWString()
+	Global _wstrExplorer:Short Ptr = "Explorer".ToWString()
+
+	'Important gadget fields that store OS control handles etc..
+	
+	Field _class, _hwnd:Byte Ptr, _hwndclient:Byte Ptr, _tooltips:Byte Ptr
+	Field _proc(hwnd:Byte Ptr,msg:UInt,wp:Byte Ptr,lp:Byte Ptr) "win32"
+	Field _hotkey:THotKey
+	Field _oldcursorlp:Byte Ptr	'Should track events
+	
+	Field _sensitive% = False	'Determines whether gadgets should generate events.
+						'Not to be confused with the sensitivity field of TGadget
+						'which specifies which type of events are fired.
+
+	'Aesthetics
+	Field _bgbrush:Byte Ptr, _fgcolor = -1, _bgcolor = -1	'Background colour
+	Field _hbrush:Byte Ptr, _hbitmap:Byte Ptr					'Background colour
+	Field _bitmap:Byte Ptr							'Background bitmap
+	Field _iconBitmap:Byte Ptr							'Icon bitmap
+	Field _hTheme:Byte Ptr							'Open handle to XP Theme API (for use in button's WM_DRAWITEM etc.)
+	Field _font:TWindowsFont					'Font (needs to be stored, otherwise it may be collected by GC)
+	Field _wstrTooltip:Short Ptr, _toolAdded = False
+	Field _clientX:Int, _clientY:Int, _enabled:Int = True, _forcedisable:Int = False
+
+
+	Method Create:TWindowsGadget(group:TGadget, style, Text$="")	 Abstract
+	
+	Method SetColor(red,green,blue)
+		If _bgbrush Then DeleteObject _bgbrush
+		_bgcolor = (blue Shl 16) | (green Shl 8) | red
+		_bgbrush=CreateSolidBrush(_bgcolor)
+		RedrawGadget(Self)
+	EndMethod
+
+	Method RemoveColor()
+		If _bgbrush Then DeleteObject _bgbrush
+		_bgbrush=0
+		RedrawGadget(Self)
+	EndMethod
+	
+	Method FgColor()
+		Return _fgcolor
+	EndMethod
+	
+	Method BgColor()
+		Return _bgcolor
+	EndMethod
+	
+	Method BgBrush:Byte Ptr()
+		Return _bgbrush
+	EndMethod
+
+	Method SetTextColor(r,g,b)
+		_fgcolor = (b Shl 16) | (g Shl 8) | r
+		RedrawGadget(Self)
+	EndMethod
+
+	Method Query:Byte Ptr(queryid)
+		Select queryid
+			Case QUERY_HWND
+				Return _hwnd
+			Case QUERY_HWND_CLIENT
+				If _hwndclient Return _hwndclient
+				Return _hwnd
+		End Select				
+	EndMethod
+
+	Method Register(class,hwnd:Byte Ptr,hwndclient:Byte Ptr=0,tips=False)
+		_class=class
+		_hwnd=hwnd
+		_hwndclient=hwndclient
+		TWindowsGUIDriver.RegisterHwnd(_hwnd,Self)		
+		If _hwndclient TWindowsGUIDriver.RegisterHwnd(_hwndclient,Self)		
+		Local atom=GetClassLongW(hwnd,GCW_ATOM)
+		If atom<>TWindowsGUIDriver.ClassAtom And atom<>TWindowsGUIDriver.ClassAtom2 And Not _proc
+			_proc=Byte Ptr(SetWindowLongPtrW(hwnd,GWL_WNDPROC,TWindowsGUIDriver.ClassWndProc))
+		EndIf
+		If tips Then SetupToolTips()	
+	EndMethod	
+
+	Method SetupToolTips()
+		If _tooltips Then
+			DestroyWindow _tooltips;TWindowsGUIDriver.RemoveHwnd(_tooltips);_tooltips = 0
+		End If
+		_tooltips = CreateWindowExW( 0,"tooltips_class32","",TTS_ALWAYSTIP,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,_hwnd,0,GetModuleHandleW(Null),Null )
+		SendMessageW _tooltips,TTM_SETMAXTIPWIDTH,0,300
+		TWindowsGUIDriver.RegisterHwnd( _tooltips, Self )
+	EndMethod
+	
+	Method isTabbable()
+		Local style:Int = GetWindowLongW(_hwnd,GWL_STYLE)&(WS_TABSTOP|WS_CHILD)
+		Return (style=(WS_TABSTOP|WS_CHILD))
+	EndMethod
+	
+	Method isControl()
+		Return (GetWindowLongW(_hwnd,GWL_STYLE)&(WS_CHILD)=WS_CHILD)
+	EndMethod
+
+	Method Activate(cmd)
+		Select cmd
+			Case ACTIVATE_FOCUS
+				If isTabbable()
+					DefDlgProcW GetParent_(_hwnd),WM_NEXTDLGCTL,_hwnd,1
+					Return 1
+				EndIf
+				If SetFocus(_hwnd) Then
+					Return True
+				End If
+			Case ACTIVATE_BACK
+				Return SendMessageW(_hwnd,WM_NEXTDLGCTL,1,0)
+			Case ACTIVATE_FORWARD
+				Return SendMessageW(_hwnd,WM_NEXTDLGCTL,0,0)
+			Case ACTIVATE_REDRAW
+				RefreshLook()
+				Return RedrawWindow( _hwnd, Null, Null, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN )
+		End Select
+	EndMethod
+	
+	Method Rethink()
+		QueueResize(_hwnd,xpos,ypos,width,height)
+	EndMethod	
+	
+	Method RethinkClient(forceRedraw:Int = False)
+	EndMethod
+	
+	Method SetArea(x,y,w,h)
+		SetRect(x,y,w,h)
+		Rethink()
+	EndMethod
+
+	Method LayoutKids()
+		
+		StartResize()
+		
+		'Implemented hack to speed-up drawing considerably...
+		Local tmpOldState = TWindowsGadget._resizeredraw
+		TWindowsGadget._resizeredraw = False
+		
+		'Child windows are laid-out like normal...
+		Super.LayoutKids()
+		
+		'Reposition all child gadgets together.
+		EndResize()
+		
+		'If this control is the first parent who started the resizing, then redraw parent and all controls now.
+		If tmpOldState Then
+			If (Not kids.IsEmpty()) Then Activate(ACTIVATE_REDRAW)
+			TWindowsGadget._resizeredraw = True
+		EndIf
+		
+	EndMethod
+	
+	Method ClientWidth()
+		Local Rect[] = [xpos,ypos,xpos+width,ypos+height]
+		SendMessageW Query(QUERY_HWND), WM_NCCALCSIZE, False, Rect
+		Return Rect[2]-Rect[0]-_clientX
+	EndMethod
+
+	Method ClientHeight()
+		Local Rect[] = [xpos,ypos,xpos+width,ypos+height]
+		SendMessageW Query(QUERY_HWND), WM_NCCALCSIZE, False, Rect
+		Return Rect[3]-Rect[1]-_clientY
+	EndMethod
+	
+	Method SetText(Text$)
+		Desensitize()
+		SetWindowTextW _hwnd, Text
+		Sensitize()
+	EndMethod	
+	
+	Method GetText$()
+		Local strText:Short[GetWindowTextLengthW(_hwnd)+1]		'Must include NULL terminator.
+		GetWindowTextW _hwnd, strText, strText.length
+		Return String.FromWString( strText )
+	EndMethod
+	
+	Method SetFont(font:TGuiFont)
+		If TWindowsFont(font) Then _font = TWindowsFont(font) Else _font = TWindowsGUIDriver.GDIFont
+		SendMessageW _hwnd,WM_SETFONT,font.handle,1
+	EndMethod
+	
+	Method SetShow(show)
+		If show
+			ShowWindow _hwnd,SW_SHOW
+		Else
+			'Requester fix - ShowWindow activates the last activated window when an active window is hidden, so if
+			'a file requester/child gadget was the last window to be activated, then the program will lose focus as it is
+			'trying to activate a non-existent window.
+			If parent And HasDescendant(ActiveGadget()) Then ActivateGadget(parent)
+			ShowWindow _hwnd,SW_HIDE
+		EndIf
+	EndMethod
+	
+	Method SetEnabled(enable)
+		_enabled = enable
+		enable = enable And Not _forceDisable
+		If Not((EnableWindow(_hwnd,enable)<>0) ~ enable) Then
+			For Local tmpGadget:TWindowsGadget = EachIn kids
+				tmpGadget._forceDisable = Not enable
+				If tmpGadget.isControl() Then tmpGadget.SetEnabled(tmpGadget._enabled)
+			Next
+		EndIf
+	EndMethod
+	
+	Method SetTooltip( pTooltip$ )
+
+		If _wstrTooltip Then
+			MemFree _wstrTooltip
+			_wstrTooltip = Null
+		End If
+		
+		Local tmpToolInfo:TOOLINFOW = New TOOLINFOW
+		'tmpToolInfo.cbSize = SizeOf(tmpToolInfo)
+		tmpToolInfo.Sethwnd(GetParent_(_hwnd))
+		tmpToolInfo.Sethinst(GetModuleHandleW(Null))
+		tmpToolInfo.SetuID(_hwnd)
+		
+		If pTooltip Then
+			_wstrTooltip = pTooltip.Replace("~r","").Replace("~n","~r~n").ToWString()
+			
+			tmpToolInfo.SetuFlags(TTF_IDISHWND|TTF_TRANSPARENT|TTF_SUBCLASS)
+			tmpToolInfo.SetlpszText(_wstrTooltip)
+			
+			If Not _toolAdded Then
+				_toolAdded = SendMessageW(TWindowsGUIDriver._hwndTooltips, TTM_ADDTOOLW, 0, tmpToolInfo.infoPtr)
+			Else
+				SendMessageW(TWindowsGUIDriver._hwndTooltips, TTM_UPDATETIPTEXTW, 0, tmpToolInfo.infoPtr)
+			EndIf
+		ElseIf _tooladded Then
+			SendMessageW(TWindowsGUIDriver._hwndTooltips, TTM_DELTOOLW, 0, tmpToolInfo.infoPtr )
+			_toolAdded = 0
+		EndIf
+		
+	EndMethod
+	
+	Method GetTooltip$()
+		If _wstrTooltip Then Return String.FromWString(_wstrTooltip)
+	EndMethod
+	
+	Method State()
+		Local t, style = GetWindowLongW(_hwnd, GWL_STYLE)
+		If Not (style&WS_VISIBLE) Then t:|STATE_HIDDEN
+		If Not _enabled Then t:|STATE_DISABLED
+		Return t
+	EndMethod
+
+	Method Free()
+		If _tooltips Then DestroyWindow _tooltips;_tooltips=0
+		SetTooltip("")	'Free any tooltip memory allocations
+		If _hwnd Then DestroyWindow _hwnd;TWindowsGUIDriver.RemoveHwnd(_hwnd);_hwnd=0
+		If _hwndclient Then TWindowsGUIDriver.RemoveHwnd(_hwndclient);_hwndclient=0
+		FlushBrushes(False)
+		If _hotKey Then RemoveHotKey(_hotKey);_hotKey = Null
+		If _iconBitmap Then DeleteObject(_iconBitmap);_iconBitmap = 0
+		If _bitmap Then DeleteObject(_bitmap);_bitmap = 0
+		If _bgbrush Then DeleteObject(_bgbrush);_bgbrush = 0
+		If _htheme Then TWindowsGUIDriver.CloseThemeHandle(_hTheme);_hTheme = 0
+		_font = Null
+		_SetParent Null
+	EndMethod	
+	
+	Method OnNotify(wp:Byte Ptr,lp:Byte Ptr)
+	EndMethod
+	
+	Method WndProc:Byte Ptr(hwnd:Byte Ptr,msg:Uint,wp:Byte Ptr,lp:Byte Ptr)
+		Select msg
+			Case WM_WINDOWPOSCHANGING
+				FlushBrushes()
+		EndSelect
+		If _proc And _hwnd = hwnd Then
+			Return CallWindowProcW(_proc,hwnd,msg,wp,lp)	 'fixed auto scrollbars
+		EndIf
+		Return DefWindowProcW( hwnd,msg,wp,lp )
+	EndMethod
+	
+	Method OnCommand(msg,wp:ULong)
+	EndMethod
+	
+	Method OnDrawItem( pDrawItemStruct:DRAWITEMSTRUCT )
+	EndMethod
+	
+	Method SetHotKey(key,modifier)
+		Local ev:TEvent = CreateEvent( EVENT_GADGETACTION,Self )
+		If _hotKey Then
+			RemoveHotKey(_hotKey)
+			_hotKey = Null
+		End If
+		If key Then _hotkey=SetHotKeyEvent(key,modifier,ev,FindGadgetWindowHwnd(Self))
+	EndMethod
+	
+	'Slow back-up code for mimicking transparency for PANEL_GROUPs and when
+	'DrawThemeParentBackground() is not available (i.e. on Windows 9x/2000).
+	Method CreateControlBrush:Byte Ptr( hWndControl:Byte Ptr, hdc:Byte Ptr = Null )
+		
+		Local xOffset, yOffset
+		Local hwndWindow:Byte Ptr = GetParent_(hwndControl)
+		Local rectWindow[4], rectControl[4], rectClient[4]
+		
+		If _hbrush Then Return _hbrush
+		
+		If BgBrush() Then
+			If hdc Then SetBkColor(hdc, BgColor())
+			Return BgBrush()
+		EndIf
+		
+		Local tmpDC:Byte Ptr = GetDC( hwndWindow )
+		
+		'Fix required to offset background when controls are drawn with WS_EX_CLIENTEDGE (e.g. panel with PANEL_SUNKEN/PANEL_RAISED set)
+		If GetWindowLongW(hwndWindow,GWL_EXSTYLE)&(WS_EX_CLIENTEDGE|WS_EX_WINDOWEDGE) Then
+			xOffset = -GetSystemMetrics(SM_CXEDGE)
+			yOffset = -GetSystemMetrics(SM_CYEDGE)
+		EndIf
+		
+		GetClientRect( hwndControl, rectClient )
+		GetWindowRect( hwndWindow, rectWindow )
+		GetWindowRect( hwndControl, rectControl )
+		
+		Local x = rectControl[0]-rectWindow[0]
+		Local y = rectControl[1]-rectWindow[1]
+		Local w = rectControl[2]-rectControl[0]
+		Local h = rectControl[3]-rectControl[1]
+		
+		Local dcBitmap:Byte Ptr = CreateCompatibleDC( tmpDC )
+		Local bkgndBitmap:Byte Ptr = CreateCompatibleBitmap( tmpDC, rectWindow[2]-rectWindow[0], rectWindow[3]-rectWindow[1] )
+		SelectObject( dcBitmap, bkgndBitmap )
+		
+		'InvalidateRect( hwndWindow, Null, False )
+		SendMessageW hwndWindow, WM_ERASEBKGND, dcBitmap, 0
+		
+		Local bkgndClientBitmap:Byte Ptr = CreateCompatibleBitmap( tmpDC, w, h )
+		Local dcClientBitmap:Byte Ptr = CreateCompatibleDC( tmpDC )
+		SelectObject( dcClientBitmap, bkgndClientBitmap )
+		
+		BitBlt( dcClientBitmap, 0,0 , w, h, dcBitmap, x+xOffset, y+yOffset, ROP_SRCCOPY )
+		
+		DeleteObject( bkgndBitmap )
+		DeleteDC( dcBitmap )
+		DeleteDC( dcClientBitmap )
+		
+		_hbrush = CreatePatternBrush( bkgndClientBitmap )
+		_hbitmap = bkgndClientBitmap
+		
+		ReleaseDC( hwndWindow, tmpDC )
+		
+		Return _hbrush
+		
+	EndMethod
+
+	'Clears the parent background brushes.
+	Method FlushBrushes(pRecurse:Int = True)
+		Local tmpChanges:Int = 0
+		If _hbrush Then
+			DeleteObject( _hbrush )
+			_hbrush = 0
+			tmpChanges:|True
+		EndIf
+		If _hBitmap Then
+			DeleteObject( _hBitmap )
+			_hBitmap = 0
+			tmpChanges:|True
+		EndIf
+		Return tmpChanges
+	EndMethod
+
+	'Method that returns a brush for drawing backgrounds.
+	Method DrawBackground:Byte Ptr( hdc:Byte Ptr, hwnd:Byte Ptr )
+		
+		If BgBrush() Then SetBkColor(hdc, BgColor());Return BgBrush()
+		
+		Return DrawParentBackground( hdc, hwnd )
+
+	EndMethod
+	
+	'Another method which mimics transparency on Windows Controls.
+	Function DrawParentBackground:Byte Ptr( hdc:Byte Ptr, hwndControl:Byte Ptr, pForceHack = False )
+
+		Local rectWindow[4], rectControl[4], rectClient[4]
+		Local hwndWindow:Byte Ptr = GetParent_(hwndControl)
+
+		GetClientRect( hwndControl, rectClient )
+		GetClientRect( hwndWindow, rectWindow )
+		GetWindowRect( hwndControl, rectControl )
+		
+		'Ensures that the the drawing context is returned in exactly the same state that it was passed.
+		Local tmpSaveState = SaveDC( hdc )
+		
+		If Not pForceHack Then
+			
+			DrawThemeParentBackground(hwndControl,hdc,rectClient)
+			
+		Else 'Again, slow back-up code in case DrawThemeParentBackground() is not available.
+			
+			Local tmpDC:Byte Ptr
+			Local xOffset, yOffset
+			
+			'Fix required to offset background when controls are drawn with WS_EX_CLIENTEDGE (e.g. panel with PANEL_BORDER set)
+			If GetWindowLongW(hwndWindow,GWL_EXSTYLE)&WS_EX_CLIENTEDGE Then
+				xOffset = -GetSystemMetrics(SM_CXEDGE)
+				yOffset = -GetSystemMetrics(SM_CYEDGE)
+			EndIf
+			
+			tmpDC = GetDC( hwndWindow )
+			
+			ScreenToClient( hwndWindow, rectControl )
+			ScreenToClient( hwndWindow, Int Ptr (rectControl)+2 )
+			
+			Local x = rectControl[0]+rectClient[0]
+			Local y = rectControl[1]+rectClient[1]
+			Local w = rectClient[2]-rectClient[0]
+			Local h = rectClient[3]-rectClient[1]
+			
+			Local bkgndBitmap:Byte Ptr = CreateCompatibleBitmap( tmpDC, rectWindow[2]-rectWindow[0], rectWindow[3]-rectWindow[1] )
+			Local dcBitmap:Byte Ptr = CreateCompatibleDC( tmpDC )
+			SelectObject( dcBitmap, bkgndBitmap )
+			
+			InvalidateRect( hwndWindow, Null, False )
+			SendMessageW hwndWindow, WM_ERASEBKGND, dcBitmap, 0
+			
+			BitBlt( hdc, 0,0 , w, h, dcBitmap, x+xOffset, y+yOffset, ROP_SRCCOPY )
+			
+			DeleteObject( bkgndBitmap )
+			DeleteDC( dcBitmap )
+			ReleaseDC( hwndWindow, tmpDC )
+			
+		EndIf
+		
+		'Ensures that the the drawing context is returned in exactly the same state that it was passed.
+		RestoreDC( hdc, tmpSaveState )
+		
+		Return GetStockObject( NULL_BRUSH )
+		
+	EndFunction
+
+	Method Sensitize()
+		_sensitive = True
+	EndMethod
+	
+	Method DeSensitize()
+		_sensitive = False
+	EndMethod
+	
+	Method PostGuiEvent( pID%, pData%=0, pMods%=0, pX%=0, pY%=0, pExtra:Object = Null)
+		
+		Select True
+			Case TWindowsListBox(Self) <> Null, TWindowsTabber(Self) <> Null, TWindowsToolbar(Self) <> Null, TWindowsCombobox(Self) <> Null
+				If pData>-1 Then
+					If (ItemFlags(pData) & GADGETITEM_TOGGLE) Then SelectItem(pData,2)
+				EndIf
+		End Select
+		
+		If _sensitive Then MaxGUI.MaxGUI.PostGuiEvent( pID, Self, pData, pMods, pX, pY, pExtra )
+		
+	EndMethod
+	
+	'Resize Methods
+	
+	Field hdwpStruct:Byte Ptr
+	
+	Method StartResize()
+		If Not hdwpStruct Then
+			Local tmpCount = kids.Count()
+			If tmpCount Then hdwpStruct = BeginDeferWindowPos( tmpCount )
+		EndIf
+	EndMethod
+	
+	Method QueueResize( hwnd:Byte Ptr, xpos, ypos, width, height )
+		If parent And GetParent_(hwnd) = parent.Query(QUERY_HWND_CLIENT) And TWindowsGadget(parent).hdwpStruct Then
+			Local tmpFlags = SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE' | SWP_NOCOPYBITS
+			If Not _resizeRedraw Then tmpFlags:| SWP_NOREDRAW
+			TWindowsGadget(parent).hdwpStruct = DeferWindowPos( TWindowsGadget(parent).hdwpStruct, hwnd, Null, xpos, ypos, width, height, tmpFlags )
+		Else
+			MoveWindow( hwnd, xpos, ypos, width, height, _resizeRedraw )
+			HasResized()
+		EndIf
+	EndMethod
+	
+	Method EndResize()
+		If hdwpStruct Then
+			EndDeferWindowPos( hdwpStruct );hdwpStruct = 0
+			For Local tmpGadget:TWindowsGadget = EachIn kids
+				Sensitize()
+				tmpGadget.HasResized()
+			Next
+		EndIf
+	EndMethod
+
+	'Required for resizing columns in listboxes (has to be done outside WM_SIZE)
+	Method HasResized()
+	EndMethod
+	
+	'Required to ensure problematic controls are updated when parent aesthetics are changed:
+	Method RefreshLook()
+		FlushBrushes(False)
+		For Local tmpGadget:TWindowsGadget = EachIn kids
+			tmpGadget.RefreshLook()
+		Next
+	EndMethod
+
+End Type
+
+Type TWindowsDesktop Extends TWindowsGadget
+
+	Method New()
+		Local Rect[4]
+		Local hwnd:Byte Ptr = GetDesktopWindow()
+		Register(GADGET_DESKTOP,hwnd,0,False)
+		GetClientRect hwnd,Rect
+		SetShape 0,0,Rect[2]-Rect[0],Rect[3]-Rect[1]
+	EndMethod
+	
+	Method Create:TWindowsGadget(group:TGadget,style,Text$="")
+		Return Self
+	EndMethod
+	
+	Method SetTooltip( pTooltip$ )
+		'Shouldn't have tool-tips.
+	EndMethod
+	
+	Method Free()
+		'Can't be free'd.
+	EndMethod
+	
+	Method Class()
+		Return GADGET_DESKTOP
+	EndMethod
+	
+	Method ClientHeight()
+		Local Rect[4]
+		If Super.ClientHeight() = height And SystemParametersInfoW( SPI_GETWORKAREA, 0, Rect, 0 ) 
+			Return Rect[3]-Rect[1]
+		Else
+			Return Super.ClientHeight()
+		EndIf
+	EndMethod
+	
+	Method ClientWidth()
+		Local Rect[4]
+		If Super.ClientWidth() = width And SystemParametersInfoW( SPI_GETWORKAREA, 0, Rect, 0 ) 
+			Return Rect[2]-Rect[0]
+		Else
+			Return Super.ClientWidth()
+		EndIf
+	EndMethod
+	
+EndType
+
+Type TWindowsWindow Extends TWindowsGadget
+
+	Field	_wstyle, _xstyle
+	Field	_minwidth,_minheight,_maxwidth = -1,_maxheight = -1
+	Field	_menu:TWindowsMenu
+	Field	_hmenu:Byte Ptr
+	Field	_status:Byte Ptr
+
+	Method Create:TWindowsGadget(group:TGadget,style,Text$="")
+		Local	hwnd:Byte Ptr, parent:Byte Ptr, client:Byte Ptr
+		Local classname$ = TWindowsGUIDriver.ClassName()
+		
+		Self.style = style
+		_wstyle=WS_CLIPSIBLINGS|WS_CLIPCHILDREN
+		If group Then parent = group.Query(QUERY_HWND)
+		
+		If (style&WINDOW_TITLEBAR)
+			_wstyle:|WS_OVERLAPPED|WS_SYSMENU
+			If style&WINDOW_RESIZABLE _wstyle:|WS_MINIMIZEBOX|WS_MAXIMIZEBOX
+			If group <> TWindowsGUIDriver.GDIDesktop And Not (style&WINDOW_TOOL) Then
+				classname$ = TWindowsGUIDriver.DialogClassName()
+				_xstyle:|WS_EX_DLGMODALFRAME
+			EndIf
+		Else
+			_wstyle:|WS_POPUP		
+		EndIf
+		
+		If style&WINDOW_RESIZABLE Then _wstyle:|WS_SIZEBOX	
+		If style&WINDOW_MENU Then 
+			_hmenu=CreateMenu_()
+			AppendMenuW( _hmenu,MF_STRING,Null,_wstrEmpty )
+		End If
+		If style&WINDOW_TOOL Then _xstyle:|WS_EX_TOOLWINDOW
+		
+		' Note: No WINDOW_HIDDEN case as gadgets are always created hidden to hide initial resize flicker.
+		' TWindowsGUIDriver.CreateGadget() will later show window if WINDOW_HIDDEN is not specified.
+		
+		hwnd=CreateWindowExW(_xstyle,classname,"",_wstyle,0,0,0,0,parent,_hmenu,GetModuleHandleW(Null),Null)
+		
+		If style&WINDOW_STATUS
+			_status=CreateWindowExW(0,"msctls_statusbar32","",WS_CHILD|WS_VISIBLE,0,0,0,0,hwnd,0,GetModuleHandleW(Null),Null)
+			SetWindowPos( _status, HWND_TOPMOST,0,0,0,0,SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOSIZE)
+		EndIf
+		
+		client=CreateWindowExW(0,TWindowsGUIDriver.ClassName(),"",WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,0,0,0,0,hwnd,0,GetModuleHandleW(Null),Null)
+		
+		Register GADGET_WINDOW,hwnd,client,False
+
+		If style&WINDOW_ACCEPTFILES Then DragAcceptFiles _hwnd,True
+		_wstyle = GetWindowLongW( hwnd, GWL_STYLE )
+			
+		Return Self
+	EndMethod
+
+	Method SetAlpha( alpha# )
+		Local tmpStyle% = GetWindowLongW(_hwnd, GWL_EXSTYLE)
+		If alpha = 1.0 Then
+			SetLayeredWindowAttributes( _hwnd, 0, Byte(alpha*255), LWA_ALPHA)
+			If (tmpStyle & WS_EX_LAYERED) Then SetWindowLongW(_hwnd, GWL_EXSTYLE, tmpStyle&~WS_EX_LAYERED)
+		Else
+			If Not (tmpStyle & WS_EX_LAYERED) Then SetWindowLongW(_hwnd, GWL_EXSTYLE, tmpStyle|WS_EX_LAYERED)
+			SetLayeredWindowAttributes( _hwnd, 0, Byte(alpha*255), LWA_ALPHA)
+		EndIf
+		RedrawGadget(Self)
+	EndMethod
+	
+	Method Rethink()
+		Local dimensions[] = [xpos,ypos,width,height]
+		ConvertToContainerDimensions( dimensions[0], dimensions[1], dimensions[2], dimensions[3] )
+		MoveWindow _hwnd, dimensions[0], dimensions[1], dimensions[2], dimensions[3], True
+		RethinkClient(True)
+	EndMethod	
+	
+	Method RethinkClient(forceRedraw:Int = False)
+		If _hwndClient Then
+			MoveWindow _hwndClient, _clientx,_clienty,ClientWidth(),ClientHeight(),forceRedraw
+		EndIf
+		LayoutKids()
+	EndMethod
+	
+	
+	Method ClientWidth()
+		If (style & WINDOW_CLIENTCOORDS) Then Return width
+		Local Rect:Int[4]
+		GetClientRect _hwnd, Rect
+		Return Max(Rect[2]-Rect[0]-_clientX,0)
+	EndMethod
+	
+	Method ClientHeight()
+		If (style & WINDOW_CLIENTCOORDS) Then Return height
+		Local h:Int = height, Rect:Int[] = [0,0,width,height]
+		Local menu:Int = _hMenu <> Null
+		AdjustWindowRectEx(Rect,GetWindowLongW(_hwnd, GWL_STYLE),menu,GetWindowLongW(_hwnd, GWL_EXSTYLE))
+		h:-(Rect[3]-Rect[1]+_clientY-height)
+		If _status Then GetWindowRect _status,Rect;h:-(Rect[3]-Rect[1])
+		Return Max(h,0)
+	End Method
+
+	Method Class()
+		Return GADGET_WINDOW
+	EndMethod
+	
+	Method State()
+		Local t = Super.State()
+		If IsIconic(_hwnd) t:|STATE_MINIMIZED
+		If IsZoomed(_hwnd) t:|STATE_MAXIMIZED
+		Return t
+	EndMethod
+
+	Method SetEnabled(enable)
+		_enabled = enable
+		EnableWindow(_hwnd,enable)
+	EndMethod
+
+	Method SetMinimumSize(w,h)
+		'Set minimum size for current window style
+		_minwidth=w;_minheight=h
+		'Get window style
+		Local tmpWStyle% = GetWindowLongW( _hwnd, GWL_STYLE )
+		'Update size border
+		If (_maxwidth = _minwidth And _maxheight = _minheight) Then tmpWStyle:&~WS_SIZEBOX ElseIf (style&WINDOW_RESIZABLE) Then tmpWStyle:|WS_SIZEBOX
+		'Set new window style if necessary
+		If tmpWStyle <> GetWindowLongW( _hwnd, GWL_STYLE ) Then
+			SetWindowLongW( _hwnd, GWL_STYLE, tmpWStyle )
+			Rethink()
+			SetWindowPos( _hwnd, Null, 0, 0, 0, 0, SWP_DRAWFRAME|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOSIZE )
+		EndIf
+	EndMethod
+	
+	Method SetMaximumSize(w,h)
+		'Set maximum size for current window style
+		_maxwidth=w;_maxheight=h
+		'Get window style
+		Local tmpWStyle% = GetWindowLongW( _hwnd, GWL_STYLE )&~WS_MAXIMIZEBOX
+		'Update size border
+		If (_maxwidth = _minwidth And _maxheight = _minheight) Then tmpWStyle:&~WS_SIZEBOX ElseIf (style&WINDOW_RESIZABLE) Then tmpWStyle:|WS_SIZEBOX
+		'Set new window style if necessary
+		If tmpWStyle <> GetWindowLongW( _hwnd, GWL_STYLE ) Then
+			SetWindowLongW( _hwnd, GWL_STYLE, tmpWStyle )
+			Rethink()
+			SetWindowPos( _hwnd, Null, 0, 0, 0, 0, SWP_DRAWFRAME|SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOSIZE )
+		EndIf
+	EndMethod
+	
+	Method GetMenu:TGadget()
+		If Not _menu Then
+			_menu = New TWindowsMenu.Create(Null,0,"")
+			_menu._setParent Self
+		EndIf
+		Return _menu
+	EndMethod
+
+	Method UpdateMenu()
+	
+		Local hmenu:Byte Ptr, oldMenu:Byte Ptr
+		If _menu
+			_menu.FreeKids
+			_menu.Open
+			hmenu=_menu._hmenu
+		EndIf
+		
+		oldMenu = GetMenu_( _hwnd )
+		SetMenu _hwnd,hmenu
+		DrawMenuBar _hwnd
+		DestroyMenu oldMenu
+		
+	EndMethod
+	
+	Field _statustext$
+	
+	Method GetStatusText$()
+		If _status
+			Return _statustext
+		EndIf
+	EndMethod
+	
+	Method SetStatusText(Text$)
+		If _status
+			_statustext = Text
+			If (style&WINDOW_RESIZABLE) Then Text:+"     "	'Cludge for size handle obfuscation
+			Local tmpWString:Short Ptr = Text.ToWString()
+			SendMessageW _status,WM_SETTEXT,0,Int(tmpWString)
+			MemFree tmpWString
+		EndIf
+	EndMethod
+	
+	Field popupextra:Object
+		
+	Method PopupMenu(menu:TGadget,extra:Object)
+		Local pt[2], wmenu:TWindowsMenu = TWindowsMenu(menu), tmpLink:TLink
+		If wmenu
+			
+			GetCursorPos_ pt
+			popupextra = extra
+			wmenu.Open(True)
+			
+			Local hmenu:Int = TrackPopupMenu( wmenu._hmenu,TPM_LEFTALIGN|TPM_TOPALIGN|TPM_RETURNCMD|TPM_NONOTIFY,pt[0],pt[1],0,_hwnd,0 )
+			If hmenu Then HandleMenuEvent( WM_COMMAND, hmenu )
+			
+			wmenu.Close()
+			popupextra = Null
+			
+		EndIf
+	EndMethod
+
+	Function EnumChildProc(hwnd:Byte Ptr,lp:Byte Ptr) "win32"
+		Local winfo:WINDOWINFO = New WINDOWINFO
+		'winfo.cbSize=SizeOf winfo
+		GetWindowInfo hwnd,winfo.infoPtr
+		If winfo.dwStyle()&WS_TABSTOP
+			_firsttab=hwnd
+		Else
+			EnumChildWindows hwnd,EnumChildProc,0
+		EndIf		
+		If _firsttab Return 0
+		Return 1
+	EndFunction
+
+	Global _firsttab:Byte Ptr
+
+	Method Activate(cmd)
+		Select cmd
+			Case ACTIVATE_FOCUS
+				_firsttab=0
+				EnumChildWindows _hwnd,EnumChildProc,0
+				If Not _firsttab _firsttab=_hwnd
+				SetFocus _firsttab
+			Case ACTIVATE_MINIMIZE
+				ShowWindow _hwnd,SW_MINIMIZE
+			Case ACTIVATE_MAXIMIZE
+				ShowWindow _hwnd,SW_MAXIMIZE
+			Case ACTIVATE_RESTORE
+				ShowWindow _hwnd,SW_RESTORE
+			Case ACTIVATE_REDRAW
+				RefreshLook()
+				Return RedrawWindow( _hwnd, Null, Null, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN )
+		End Select
+	EndMethod
+	
+	Method OnCommand(msg,wp:ULong)
+		If wp>100 Then HandleMenuEvent(msg,wp)
+	EndMethod
+	
+	Method HandleMenuEvent( msg, wp:ULong )
+		
+		Local tmpMenuSource:TWindowsMenu = TWindowsMenu.GetMenuFromKey(wp), tmpMenuID
+		If tmpMenuSource Then tmpMenuID = tmpMenuSource._tag
+		
+		Local tmpPopupExtra:Object = popupextra
+		popupextra = Null
+		
+		MaxGUI.MaxGUI.PostGuiEvent EVENT_MENUACTION,tmpMenuSource,tmpMenuID,0,0,0,tmpPopupExtra
+		
+	EndMethod
+	
+	Method WndProc:Byte Ptr(hwnd:Byte Ptr,msg:UInt,wp:Byte Ptr,lp:Byte Ptr)
+		Local x,y,w,h
+		Local move,size
+		Local Rect[4]
+		Local winrect[4]
+		
+		Select msg
+		
+			Case WM_ERASEBKGND
+				If BgBrush() Then
+					Local Rect[4]
+					If Not GetUpdateRect( hwnd, Rect, False ) Then GetClipBox( wp, Rect )
+					FillRect( wp, Rect, BgBrush() )
+					Return 1
+				EndIf
+			
+			Case WM_SIZE
+				
+				If (hwnd = _hwnd) And (wp <> SIZE_MINIMIZED) Then
+				
+					If _status Then SendMessageW _status,WM_SIZE,0,0
+					
+					If (style & WINDOW_CLIENTCOORDS) Then
+						GetClientRect _hwnd,Rect
+						w=Rect[2]
+						h=Rect[3]
+						AdjustWindowRectEx(Rect,GetWindowLongW(_hwnd, GWL_STYLE),_hmenu,GetWindowLongW(_hwnd, GWL_EXSTYLE))
+						x=-Rect[0]
+						y=-Rect[1]
+						GetWindowRect _hwnd,Rect
+						x:+Rect[0]
+						y:+Rect[1]
+						If _status Then
+							GetWindowRect _status,Rect
+							h:-(Rect[3]-Rect[1])
+						EndIf
+						x:+_clientX;y:+_clientY
+						w:-_clientX;h:-_clientY
+					Else
+						GetWindowRect(_hwnd,Rect)
+						x=Rect[0];y=Rect[1]
+						w=Rect[2]-Rect[0]
+						h=Rect[3]-Rect[1]	
+					EndIf	
+					
+					If x<>xpos Or y<>ypos Then move = True
+					If w<>width Or h<>height Then size = True
+					
+					SetRect x,y,w,h
+					
+					If size Then RethinkClient()
+					
+					If move PostGuiEvent EVENT_WINDOWMOVE,0,0,x,y
+					If size PostGuiEvent EVENT_WINDOWSIZE,0,0,w,h
+					
+				EndIf
+				
+			Case WM_MOVE
+				If (hwnd = _hwnd) And Not (IsZoomed(hwnd) Or IsIconic(hwnd)) Then
+					
+					If (style & WINDOW_CLIENTCOORDS) Then
+						GetClientRect _hwnd,Rect
+						w=Rect[2]
+						h=Rect[3]
+						AdjustWindowRectEx(Rect,GetWindowLongW(_hwnd, GWL_STYLE),_hmenu,GetWindowLongW(_hwnd, GWL_EXSTYLE))
+						x=-Rect[0]
+						y=-Rect[1]
+						GetWindowRect _hwnd,Rect
+						x:+Rect[0]+_clientX
+						y:+Rect[1]+_clientY
+					Else
+						GetWindowRect(_hwnd,Rect)
+						x=Rect[0];y=Rect[1]
+						w=Rect[2]-Rect[0]
+						h=Rect[3]-Rect[1]			
+					EndIf	
+					
+					If x<>xpos Or y<>ypos Then
+						SetRect x,y,width,height
+						PostGuiEvent EVENT_WINDOWMOVE,0,0,x,y
+					EndIf
+					
+				EndIf
+				
+			Case WM_GETMINMAXINFO
+				If hwnd = _hwnd And lp Then
+' FIXME
+					Local minmax:Int Ptr = Int Ptr(lp), tmpZero% = 0
+					
+					minmax[6]=_minwidth
+					minmax[7]=_minheight
+					ConvertToContainerDimensions(tmpZero,tmpZero,minmax[6],minmax[7])
+					
+					If (_maxwidth >= _minwidth) And (_maxheight >= _minheight) Then
+						minmax[8]=_maxwidth
+						minmax[9]=_maxheight
+						ConvertToContainerDimensions(tmpZero,tmpZero,minmax[8],minmax[9])
+					EndIf
+					
+				EndIf
+				
+			Case WM_ACTIVATE
+				If (wp = WA_ACTIVE) Or (wp = WA_CLICKACTIVE) Then
+					TWindowsGUIDriver._ActiveWindow = Self
+					PostGuiEvent EVENT_WINDOWACTIVATE
+				EndIf
+				
+			Case WM_COMMAND
+				If wp>100 Then HandleMenuEvent(msg,ULong(wp))
+
+			Case WM_CLOSE
+				PostGuiEvent EVENT_WINDOWCLOSE
+				Return 1
+				
+			Case WM_DROPFILES
+				Local hdrop:Byte Ptr,pt[2],path$
+				Local pbuffer:Short[MAX_PATH]
+				Local i,n,l
+				DragQueryPoint wp,pt
+				n=DragQueryFileW(wp,$ffffffff,Null,0);
+				For i=0 Until n
+					l=DragQueryFileW(wp,i,pbuffer,MAX_PATH)
+					path=String.FromShorts(pbuffer,l)
+					PostGuiEvent EVENT_WINDOWACCEPT,0,0,pt[0],pt[1],path
+				Next
+				DragFinish wp
+ 
+		End Select
+		
+		Return Super.WndProc(hwnd,msg,wp,lp)
+		
+	EndMethod
+	
+	Method DoLayout()
+		'Don't do anything!
+	EndMethod
+	
+	Method SetTooltip( pTooltip$ )
+		'Windows shouldn't have tool-tips!
+	EndMethod
+	
+	Method SetSensitivity(flags)
+		'Problems with resizing/moving sensitive windows.
+		Super.SetSensitivity(flags&~SENSITIZE_MOUSE)
+		'Easy to create an active panel in client area as a work around.
+	EndMethod
+	
+	Method SetPixmap(pPixmap:TPixmap, pFlags)
+		If Not (pFlags & GADGETPIXMAP_ICON) Then Return False
+		If _iconBitmap Then
+			DestroyIcon(_iconBitmap)
+			_iconBitmap = 0
+		End If
+		If pPixmap Then _iconBitmap = TWindowsGraphic.IconFromPixmap32( pPixmap )
+		SendMessageW (_hwnd, WM_SETICON, 0, _iconBitmap)
+		SendMessageW (_hwnd, WM_SETICON, 1, _iconBitmap)
+		Return True
+	EndMethod
+	
+	' Needed otherwise SetEnabled() locks if modal child window is opened and parent is disabled.
+	Method isControl()
+		Return False
+	EndMethod
+
+	Method ConvertToContainerDimensions%( pX Var, pY Var, pW Var , pH Var )
+		
+		If Not (style & WINDOW_CLIENTCOORDS) Then Return 0
+		
+		Local Rect[4], menu_:Byte Ptr = GetMenu_(_hwnd), menu
+		
+		If menu_ Then menu = True
+		If _status Then 
+			GetWindowRect _status,Rect
+			pH:+(Rect[3]-Rect[1])
+		End If
+		pW:+_clientX;pH:+_clientY;pX:-_clientX;pY:-_clientY
+		
+		Rect = [pX,pY,pX+pW,pY+pH]
+		AdjustWindowRectEx Rect,GetWindowLongW(_hwnd, GWL_STYLE),menu,GetWindowLongW(_hwnd, GWL_EXSTYLE)
+		
+		pX = Rect[0];pY = Rect[1];pW = Rect[2]-Rect[0];pH = Rect[3]-Rect[1]
+		
+		Return 1
+		
+	EndMethod
+
+	Method FlushBrushes(pRecurse:Int = True)
+		Super.FlushBrushes()
+		If Not pRecurse Then Return
+		For Local tmpGadget:TWindowsGadget = EachIn kids
+			tmpGadget.FlushBrushes()
+		Next
+	EndMethod
+
+End Type
+
+Type TButtonImageList
+	Field buttonImageListPtr:Byte Ptr
+	Field hasImageList:Int
+	
+	Method New()
+		buttonImageListPtr = bmx_win32_BUTTON_IMAGELIST_new()
+	End Method
+	
+	Method Delete()
+		If buttonImageListPtr Then
+			If hasImageList Then
+				
+			End If
+			bmx_win32_BUTTON_IMAGELIST_free(buttonImageListPtr)
+			buttonImageListPtr = Null
+		End If
+	End Method
+	
+	Method Sethiml(himl:Byte Ptr)
+		bmx_win32_BUTTON_IMAGELIST_Sethiml(buttonImageListPtr, himl)
+		hasImageList = True
+	End Method
+	
+	Method SetuAlign(uAlign:UInt)
+		bmx_win32_BUTTON_IMAGELIST_SetuAlign(buttonImageListPtr, uAlign)
+	End Method
+	
+	Method himl:Byte Ptr()
+		Return bmx_win32_BUTTON_IMAGELIST_himl(buttonImageListPtr)
+	End Method
+	
+	Method Destroyhiml()
+		ImageList_Destroy(himl())
+		hasImageList = False
+	End Method
+	
+End Type
+
+Type TWindowsButton Extends TWindowsGadget
+
+	'Field _buttonImageList[] = [-1,0,0,0,0,0]
+	Field _buttonImageList:TButtonImageList = New TButtonImageList
+	Field _strButtonText$, _mouseoverbutton
+	
+	Method Create:TWindowsGadget(group:TGadget,style,Text$="")
+		Local	xstyle,wstyle,hotkey
+		Local	hwnd:Byte Ptr,parent:Byte Ptr
+		Self.style = style
+		wstyle=WS_CHILD|WS_TABSTOP|WS_CLIPSIBLINGS|BS_MULTILINE		
+		Select style&7
+			Case 0
+				wstyle:|BS_PUSHBUTTON
+				style = BUTTON_PUSH
+			Case BUTTON_CHECKBOX
+				wstyle:|BS_3STATE
+				If (style&BUTTON_PUSH) Then wstyle:|BS_PUSHLIKE
+			Case BUTTON_RADIO
+				wstyle:|BS_AUTORADIOBUTTON
+				If (style&BUTTON_PUSH) Then wstyle:|BS_PUSHLIKE
+			Case BUTTON_OK
+				wstyle:|BS_DEFPUSHBUTTON
+				hotkey=IDOK
+			Case BUTTON_CANCEL
+				wstyle:|BS_PUSHBUTTON
+				hotkey=IDCANCEL
+		End Select
+		parent=group.query(QUERY_HWND_CLIENT)
+		hwnd=CreateWindowExW(xstyle,"BUTTON","",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)				
+		Register GADGET_BUTTON,hwnd
+		Return Self		
+	EndMethod
+	
+	Method SetTextColor(r,g,b)
+		If Not (style&7) Then
+			SetWindowLongW(_hwnd,GWL_STYLE,GetWindowLongW(_hwnd,GWL_STYLE)|BS_OWNERDRAW)
+			If Not _hTheme Then _hTheme = TWindowsGUIDriver.GetThemeHandle( _hwnd, "Button" )
+		ElseIf Not (style&BUTTON_PUSH) And ((style&7=BUTTON_CHECKBOX) Or (style&7=BUTTON_RADIO))
+			SetWindowTheme(_hwnd,_wstrSpace,_wstrSpace)
+		EndIf
+		Super.SetTextColor(r,g,b)
+	EndMethod
+
+	Method SetColor(r,g,b)
+		If Not (style&7) Then
+			SetWindowLongW(_hwnd,GWL_STYLE,GetWindowLongW(_hwnd,GWL_STYLE)|BS_OWNERDRAW)
+			If Not _hTheme Then _hTheme = TWindowsGUIDriver.GetThemeHandle( _hwnd, "Button" )
+		EndIf
+		Super.SetColor(r,g,b)
+	EndMethod
+
+	Method RemoveColor()
+		If Not (style&7) Then
+			SetWindowLongW(_hwnd,GWL_STYLE,GetWindowLongW(_hwnd,GWL_STYLE)&~BS_OWNERDRAW)
+			_hTheme=0
+		EndIf
+		Super.RemoveColor()
+	EndMethod
+	
+	Method State()
+		Local t=Super.State()
+		Select SendMessageW( _hwnd,BM_GETCHECK,0,0 )
+			Case BST_CHECKED;t:|STATE_SELECTED
+			Case BST_INDETERMINATE;t:|STATE_INDETERMINATE
+		EndSelect
+		Return t
+	EndMethod
+
+	Method SetSelected(bool)
+		Local state = BST_UNCHECKED
+		If bool Then
+			If (style&7 = BUTTON_CHECKBOX) And (bool = CHECK_INDETERMINATE) Then
+				state = BST_INDETERMINATE
+			Else
+				state = BST_CHECKED
+			EndIf
+		EndIf
+		SendMessageW _hwnd,BM_SETCHECK,state,0
+	EndMethod
+	
+	Method WndProc:Byte Ptr(hwnd:Byte Ptr,msg:UInt,wp:Byte Ptr,lp:Byte Ptr)
+		Select msg
+			Case WM_THEMECHANGED
+				If _hTheme Then
+					TWindowsGUIDriver.CloseThemeHandle(_hTheme)
+					_hTheme = TWindowsGUIDriver.GetThemeHandle(_hwnd,"BUTTON")
+				EndIf
+			Case WM_LBUTTONDBLCLK
+				PostMessageW(_hwnd, WM_LBUTTONDOWN, wp, lp)
+			Case WM_MOUSEMOVE
+				If Not _mouseoverbutton Then
+					_mouseoverbutton = True
+					InvalidateRect(_hwnd,Null,False)
+' FIXME
+					Local tmpTrackMouseEvent:Int[] = [ 16, $2, hwnd, 0 ]	'TME_LEAVE: $2
+					_TrackMouseEvent( tmpTrackMouseEvent )
+				EndIf
+			Case WM_MOUSELEAVE
+				If _mouseoverbutton Then
+					_mouseoverbutton = False
+					InvalidateRect(_hwnd,Null,False)
+				EndIf
+			Case WM_ERASEBKGND
+				Return 1
+		EndSelect
+		
+		Return Super.WndProc(hwnd,msg,wp,lp)
+		
+	EndMethod
+	
+	Method OnDrawItem(pDrawItemStruct:DRAWITEMSTRUCT)
+		
+		Local tmpDc:Byte Ptr = pDrawItemStruct.hDc(), txtWidth%, txtHeight%
+		Local tmpDcState = SaveDC(tmpDC)
+		
+		' button state
+		Local tmpIsPressed = (pDrawItemStruct.ItemState() & ODS_SELECTED)
+		Local tmpIsFocused  = (pDrawItemStruct.ItemState() & ODS_FOCUS)
+		Local tmpIsDisabled = (pDrawItemStruct.ItemState() & ODS_DISABLED)
+		Local tmpDrawFocusRect = Not (pDrawItemStruct.ItemState() & ODS_NOFOCUSRECT)
+		
+		Local itemRect:Int Ptr = pDrawItemStruct.rcItem(), txtRect:Int[4], clientRect:Int[4]
+		
+		Local tmpBgMode = SetBkMode(tmpDc, TRANSPARENT)
+		
+		' Prepare draw... paint button background
+		
+		If _hTheme Then
+			
+			Local tmpState = PBS_NORMAL
+			If tmpIsDisabled Then
+				tmpState = PBS_DISABLED
+			ElseIf tmpIsPressed Then
+				tmpState = PBS_PRESSED
+			ElseIf _mouseoverbutton Then
+				tmpState = PBS_HOT
+			ElseIf tmpIsFocused Then
+				tmpState = PBS_DEFAULTED
+			EndIf
+			
+			If IsThemeBackgroundPartiallyTransparent(_hTheme, BP_PUSHBUTTON, tmpState) Then
+				DrawThemeParentBackground( _hwnd, tmpDc, itemRect )
+			EndIf
+			DrawThemeBackground(_hTheme, tmpDc, BP_PUSHBUTTON, tmpState, itemRect, Null)
+			GetThemeBackgroundContentRect(_hTheme, tmpDc, BP_PUSHBUTTON, tmpState, itemRect, clientRect)
+			
+		Else
+			
+			clientRect = [itemRect[0], itemRect[1], itemRect[2], itemRect[3]]
+			InflateRect(clientRect, -GetSystemMetrics(SM_CXEDGE), -GetSystemMetrics(SM_CYEDGE))
+			
+			If tmpIsFocused Then
+				
+				Local tmpBr:Byte Ptr = CreateSolidBrush($000000)
+				FrameRect(tmpDc, itemRect , tmpBr)
+				InflateRect(itemRect, -1, -1)
+				DeleteObject(tmpBr)
+				
+			EndIf
+			
+			Local crColor
+			If BgColor() < 0 Then crColor = GetSysColor(COLOR_BTNFACE) Else crColor = BgColor()
+			
+			Local brBackground:Byte Ptr = CreateSolidBrush(crColor)
+			
+			FillRect(tmpDc, itemRect, brBackground)
+			
+			DeleteObject(brBackground)
+			
+			' Draw pressed button
+			If tmpIsPressed
+				
+				Local brBtnShadow:Byte Ptr = CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW))
+				FrameRect(tmpDc, itemRect, brBtnShadow)
+				DeleteObject(brBtnShadow)
+				
+				OffsetRect( clientRect, 1, 1 )
+				
+			Else ' ...Else draw non pressed button
+				
+				Local tmpUState = DFCS_BUTTONPUSH
+				If _mouseoverbutton Then tmpUState :| DFCS_HOT
+				If tmpIsPressed Then tmpUState :| DFCS_PUSHED
+				
+				DrawFrameControl(tmpDc, itemRect, DFC_BUTTON, tmpUState)
+				
+			EndIf
+			
+		EndIf
+		
+		If BgColor() > -1 Then
+			Local brBackground:Byte Ptr = CreateSolidBrush(BgColor())
+			FillRect(tmpDc, clientRect, brBackground)
+			DeleteObject(brBackground)
+		EndIf
+		
+		txtRect = clientRect[..]
+		
+		clientRect[RECT_RIGHT]:-clientRect[RECT_LEFT]
+		clientRect[RECT_BOTTOM]:-clientRect[RECT_TOP]
+		
+		' Read the button's title
+		Local tmpText$ = Super.GetText()
+		
+		' Draw the icon
+		'DrawTheIcon(GetDlgItem(hDlg, IDC_OWNERDRAW_BTN), &dc, bHasTitle, &lpDIS.rcItem, &captionRect, bIsPressed, bIsDisabled)
+		
+		' Write the button title (if any)
+		If tmpText Then
+			
+			Local tmpFlags = DT_CENTER|DT_WORDBREAK
+			
+			DrawTextW( tmpDc, tmpText, -1, txtRect, DT_CALCRECT|tmpFlags )
+			
+			txtWidth = txtRect[RECT_RIGHT]-txtRect[RECT_LEFT]
+			txtHeight = txtRect[RECT_BOTTOM]-txtRect[RECT_TOP]
+			
+			txtRect[RECT_LEFT] = clientRect[RECT_LEFT] + (clientRect[RECT_RIGHT] - txtWidth)/2
+			txtRect[RECT_TOP] = clientRect[RECT_TOP] + (clientRect[RECT_BOTTOM] - txtHeight)/2
+			txtRect[RECT_RIGHT] = txtRect[RECT_LEFT] + txtWidth
+			txtRect[RECT_BOTTOM] = txtRect[RECT_TOP] + txtHeight
+			
+			Local tmpTextColor
+			If tmpIsDisabled Then
+				tmpTextColor = GetSysColor(COLOR_GRAYTEXT)
+			Else
+				If FgColor() < 0 Then tmpTextColor = GetSysColor(COLOR_BTNTEXT) Else tmpTextColor = FgColor()
+			EndIf
+			tmpTextColor = SetTextColor_(tmpDc,tmpTextColor)
+			
+			DrawTextW( tmpDc, tmpText, -1, txtRect, tmpFlags )
+			
+			SetTextColor_(tmpDc,tmpTextColor)
+			
+		EndIf
+		
+		RestoreDC(tmpDc,tmpDcState)
+		
+		' Draw the focus rect
+		If tmpIsFocused And tmpDrawFocusRect Then
+			Local focusRect:Int[4]
+			CopyRect(focusRect, itemRect)
+			InflateRect(focusRect, -3, -3)
+			SetMapMode(tmpDc, MM_TEXT)
+			DrawFocusRect(tmpDc, focusRect)
+		EndIf
+		
+		Return True
+	EndMethod
+	
+	Method OnCommand(msg,wp:ULong)
+
+		Select wp Shr 16
+			Case BN_CLICKED
+				Select (style&7)
+					Case BUTTON_CHECKBOX
+						Select State()&STATE_INDETERMINATE
+							Case 0, STATE_INDETERMINATE
+								SetSelected(True)
+							Case STATE_SELECTED
+								SetSelected(False)
+						EndSelect
+				EndSelect
+				
+				PostGuiEvent EVENT_GADGETACTION,ButtonState(Self)
+				
+				'Fix so that tooltips reappear on Windows XP
+				Local tmpTooltip$ = GetTooltip()
+				If tmpTooltip Then SetTooltip("");SetTooltip(tmpTooltip)
+				
+		EndSelect
+	EndMethod							
+	
+	Method SetPixmap(pixmap:TPixmap,pFlags)
+
+		Local tmpWindowStyle = GetWindowLongW(_hwnd,GWL_STYLE)
+		
+		If (pFlags & GADGETPIXMAP_ICON) And (((style&BUTTON_PUSH)=BUTTON_PUSH) Or (style = BUTTON_CANCEL)) Then
+			
+			'To remove an image from a button, a handle-list of -1 should be passed.
+			If _buttonImageList.hasImageList Then _buttonImageList.Destroyhiml()
+			If pixmap Then _buttonImageList.Sethiml(BuildImageList( pixmap ))
+			
+			If (pFlags & GADGETPIXMAP_NOTEXT) Then
+				_buttonImageList.SetuAlign(BUTTON_IMAGELIST_ALIGN_CENTER)
+			Else
+				_buttonImageList.SetuAlign(BUTTON_IMAGELIST_ALIGN_LEFT)
+			EndIf
+			
+			'If running Windows XP/Vista, let's use BCM_SETIMAGELIST
+
+			If Not SendMessageW (_hwnd, BCM_SETIMAGELIST, 0, _buttonImageList.buttonImageListPtr) Then
+			'Otherwise, if this fails we should use BM_SETIMAGE.
+				
+				If _buttonImageList.hasImageList Then _buttonImageList.Destroyhiml()
+				
+				If _iconBitmap Then DeleteObject(_iconBitmap);_iconBitmap = 0
+				If pixmap Then _iconBitmap = TWindowsGraphic.BitmapFromPixmap( pixmap, True )
+				
+				SendMessageW (_hwnd, BM_SETIMAGE, IMAGE_BITMAP, _iconBitmap)
+				
+			EndIf
+			
+			'Show the text if there isn't a pixmap or if we haven't specified GADGETPIXMAP_NOTEXT.
+			If (Not pixmap) Or Not(pFlags & GADGETPIXMAP_NOTEXT) Then
+				tmpWindowStyle:&(~BS_BITMAP)
+				
+				'Text isn't hidden on XP image buttons regardless of whether BS_BITMAP is set
+				'so we have to hack this in - they must have fixed it on Vista though as it works fine there.
+				
+				Super.SetText( GetText() )
+			Else
+				tmpWindowStyle:|BS_BITMAP
+				
+				'Text isn't hidden on XP image buttons regardless of whether BS_BITMAP is set
+				'so we have to hack this in - they must have fixed it on Vista though as it works fine there.
+				
+				Super.SetText( "" )
+			EndIf
+			
+			SetWindowLongW _hwnd,GWL_STYLE,tmpWindowStyle
+			
+			InvalidateRect _hwnd, Null, False
+			
+			Return True
+			
+		EndIf
+		
+	EndMethod
+	
+	Method SetText(pText$)
+		Local oldText$ = _strButtonText
+		_strButtonText = pText
+		If (Not _buttonImageList.hasImageList  And Not _iconBitmap) Or (oldText = Super.GetText()) Then Super.SetText(pText)
+	EndMethod
+	
+	Method GetText$()
+		Return _strButtonText
+	EndMethod
+	
+	Method Free()
+		If _buttonImageList.hasImageList Then _buttonImageList.Destroyhiml()
+		If _iconBitmap Then DestroyIcon( _iconBitmap );_iconBitmap = 0
+		_buttonImageList = Null
+		Super.Free()
+	EndMethod
+	
+	Function BuildImageList:Byte Ptr(pixmap:TPixmap)
+		Local bitmap:Byte Ptr,imagelist:Byte Ptr,mask:Byte Ptr
+		If TWindowsGUIDriver.CheckCommonControlVersion() And (Pixmap.format=PF_RGBA8888 Or pixmap.format=PF_BGRA8888)
+			imagelist=ImageList_Create(pixmap.width,pixmap.height,ILC_COLOR32,0,1)
+			If imagelist
+				bitmap=TWindowsGraphic.BitmapFromPixmap(pixmap, True)
+				ImageList_Add(imagelist,bitmap,0)
+			EndIf
+		EndIf
+		If imagelist=0
+			bitmap=TWindowsGraphic.BitmapFromPixmap(pixmap, False)
+			mask=TWindowsGraphic.BitmapMaskFromPixmap(pixmap)
+			imagelist=ImageList_Create(pixmap.width,pixmap.height,ILC_COLOR24|ILC_MASK,0,1)
+			ImageList_Add(imagelist,bitmap,mask)
+			DeleteObject(mask)
+		EndIf
+		DeleteObject(bitmap)
+		Return imagelist
+	EndFunction
+	
+	Method Class()
+		Return GADGET_BUTTON
+	EndMethod
+
+End Type
+
+Type TWindowsMenu Extends TGadget
+	Field	_hmenu:Byte Ptr
+	Field	_pmenu:Byte Ptr
+	Field	_item
+	Field	_state
+	Field	_tag
+	Field	_hotkeycode
+	Field	_modifier
+	Field	_shortcut$
+	Field	_hotkey:THotKey
+	Field	_key = SetNewKey()
+	Field _iconBitmap:Byte Ptr
+	
+	Global iteminfo:MENUITEMINFOW
+	
+	Global keymap:TIntMap=New TIntMap 'key,gadget
+	Global keycount=100
+	
+	Method SetNewKey%()
+		keycount:+1
+		keymap.Insert( keycount, Self )
+		Return keycount
+	EndMethod
+	
+	Function GetMenuFromKey:TWindowsMenu(pKey%)
+		Return TWindowsMenu(keymap.ValueForKey(pKey))
+	EndFunction
+	
+	Method SetText(pText$)
+		name = pText
+	EndMethod
+	
+	Method GetText$()
+		Return name
+	EndMethod
+	
+	Method Free()
+		Close
+		_setparent Null
+		keymap.Remove(_key)
+		If _iconBitmap Then DeleteObject(_iconBitmap)
+	EndMethod
+	
+	Method DoLayout()
+		'Don't do anything!
+	EndMethod
+	
+	Method State()
+		Return _state
+	EndMethod
+	
+	Method SetEnabled(enable)
+		If enable
+			If _pmenu EnableMenuItem(_pmenu,_item,MF_BYPOSITION|MF_ENABLED)
+			_state:&~STATE_DISABLED
+		Else
+			If _pmenu EnableMenuItem(_pmenu,_item,MF_BYPOSITION|MF_GRAYED)
+			_state:|STATE_DISABLED
+		EndIf
+	EndMethod
+
+	Method SetSelected(bool)
+		If bool
+			If _pmenu CheckMenuItem(_pmenu,_item,MF_BYPOSITION|MF_CHECKED)
+			_state:|STATE_SELECTED
+		Else
+			If _pmenu CheckMenuItem(_pmenu,_item,MF_BYPOSITION|MF_UNCHECKED)
+			_state:&~STATE_SELECTED
+		EndIf
+	EndMethod
+	
+	Method SetHotKey(keycode,modifier)
+		_hotkeycode=keycode
+		_modifier=modifier
+		
+		Local	pre$, suf$, m$
+		
+		If LocalizationMode()&LOCALIZATION_ON Then
+			pre="{{"
+			suf="}}"
+		EndIf
+		
+		If keycode>=KEY_0 And keycode<=KEY_9
+			m$=Chr(keycode)
+		ElseIf keycode>=KEY_A And keycode<=KEY_Z
+			m$=Chr(keycode)
+		ElseIf keycode>=KEY_F1 And keycode<=KEY_F12
+			m$="F"+(keycode+1-KEY_F1)
+		ElseIf keycode>=KEY_NUM0 And keycode<=KEY_NUM9
+			m$="Num "+(keycode+1-KEY_NUM0)
+		Else
+			Select keycode
+				Case KEY_BACKSPACE;m = pre+"Backspace"+suf
+				Case KEY_TAB;m = pre+"Tab"+suf
+				Case KEY_ESCAPE;m = pre+"Esc"+suf
+				Case KEY_SPACE;m = pre+"Space"+suf
+				Case KEY_ENTER;m = pre+"Enter"+suf
+				Case KEY_PAGEUP;m = pre+"PageUp"+suf
+				Case KEY_PAGEDOWN;m = pre+"PageDown"+suf
+				Case KEY_END;m = pre+"End"+suf
+				Case KEY_HOME;m = pre+"Home"+suf
+				Case KEY_LEFT;m = pre+"Left"+suf
+				Case KEY_RIGHT;m = pre+"Right"+suf
+				Case KEY_UP;m = pre+"Up"+suf
+				Case KEY_DOWN;m = pre+"Down"+suf
+				Case KEY_INSERT;m = pre+"Insert"+suf
+				Case KEY_DELETE;m = pre+"Delete"+suf
+				Case KEY_TILDE;m = "~~"
+				Case KEY_MINUS;m = "-"
+				Case KEY_EQUALS;m = "="
+				Case KEY_OPENBRACKET;m = "["
+				Case KEY_CLOSEBRACKET;m = "]"
+				Case KEY_BACKSLASH;m = "\"
+				Case KEY_SEMICOLON;m = ";"
+				Case KEY_QUOTES;m = "'"
+				Case KEY_COMMA;m = ","
+				Case KEY_PERIOD;m = "."
+				Case KEY_SLASH;m = "/"
+				Case KEY_NUMMULTIPLY;m = "Num *"
+				Case KEY_NUMADD;m = "Num +"
+				Case KEY_NUMSUBTRACT;m = "Num -"
+				Case KEY_NUMDECIMAL;m = "Num ."
+				Case KEY_NUMDIVIDE;m = "Num /"
+			EndSelect
+		EndIf
+		
+		If m
+			If modifier&MODIFIER_SHIFT m$=pre+"Shift"+suf+"+"+m$
+			If modifier&MODIFIER_CONTROL m$=pre+"Ctrl"+suf+"+"+m$
+			If modifier&MODIFIER_ALT m$=pre+"Alt"+suf+"+"+m$
+			m="~t"+m
+		EndIf
+		_shortcut$=LocalizeString(m)
+		
+		If Not iteminfo
+			iteminfo=New MENUITEMINFOW
+			'iteminfo.cbSize=SizeOf(iteminfo)
+		EndIf
+		iteminfo.SetfMask(MIIM_TYPE)
+		iteminfo.SetdwTypeData((name+_shortcut).toWString())
+		SetMenuItemInfoW _pmenu,_item,True,iteminfo.infoPtr
+		
+		MemFree iteminfo.dwTypeData()
+		
+		Local ev:TEvent=CreateEvent( EVENT_MENUACTION, Self,_tag )
+		If _hotKey Then
+			RemoveHotKey(_hotKey)
+			_hotKey = Null
+		End If
+		If keycode Then _hotkey=SetHotKeyEvent(keycode,modifier,ev,FindGadgetWindowHwnd(Self))
+	EndMethod
+				
+	Method Create:TWindowsMenu(group:TGadget,tag,Text$="")
+		If Not iteminfo Then
+			iteminfo=New MENUITEMINFOW
+			'iteminfo.cbSize=SizeOf(iteminfo)
+		EndIf
+		name=Text
+		_tag=tag
+		Local window:TWindowsWindow = TWindowsWindow(group)
+		If window group=window.GetMenu()
+		_SetParent(group)
+		If (LocalizationMode()&LOCALIZATION_OVERRIDE) Then
+			LocalizeGadget(Self, name, "")
+		EndIf
+		Return Self	
+	EndMethod
+	
+	Method Open(popup=False)
+	
+		Local dad:TWindowsMenu	= TWindowsMenu(parent)				
+		
+		If dad
+			_pmenu=dad._hmenu
+			If Not _pmenu Throw "Parent doesn't have a handle - the desktop heap may have run out of memory!"
+			_item=GetMenuItemCount(_pmenu)
+			If name
+				Local tmpWString:Short Ptr = (LocalizeString(name)+_shortcut).ToWString()
+				AppendMenuW _pmenu,MF_STRING,_key,tmpWString
+				MemFree tmpWString
+			Else
+				AppendMenuW _pmenu,MF_SEPARATOR,_key,Null
+			EndIf
+			If kids.count()
+				_hmenu=CreateMenu_()
+				Local tmpMenuInfo:MENUINFO = New MENUINFO
+				
+				tmpMenuInfo.SetfMask(MIM_APPLYTOSUBMENUS|MIM_STYLE)
+				tmpMenuInfo.SetdwStyle(MNS_CHECKORBMP|MNS_MODELESS)
+				SetMenuInfo(_hmenu, tmpMenuInfo.infoPtr)
+				
+				iteminfo.SetfMask(MIIM_SUBMENU)
+				iteminfo.SethSubMenu(_hmenu)
+				SetMenuItemInfoW _pmenu,_item,True,iteminfo.infoPtr
+			EndIf
+			
+			If _state&STATE_DISABLED SetEnabled(False)
+			If _state&STATE_SELECTED SetSelected(True)
+			
+			If _iconBitmap Then SetMenuItemBitmaps(_pMenu,_key,MF_BYCOMMAND,_iconBitmap,Null)
+		Else
+			If popup
+				_hmenu=CreatePopupMenu()
+			Else
+				If kids _hmenu=CreateMenu_()
+			EndIf
+		EndIf
+		
+		For Local kid:TWindowsMenu = EachIn kids
+			kid.Open
+		Next
+		
+	EndMethod
+
+	Method FreeKids()
+		For Local kid:TWindowsMenu = EachIn kids
+			kid.Close
+		Next
+	EndMethod
+	
+	Method Close()
+		FreeKids()
+		If _hmenu
+			DestroyMenu _hmenu
+			_hmenu=0
+		EndIf
+	EndMethod
+	
+	Method SetPixmap(pixmap:TPixmap,pFlags)
+		If Not (pFlags & GADGETPIXMAP_ICON) Then Return
+		If _iconBitmap Then DeleteObject(_iconBitmap);_iconBitmap = 0
+		If pixmap Then
+			pixmap = PixmapWindow(pixmap,0,0,Min(GetSystemMetrics(SM_CXMENUCHECK),PixmapWidth(pixmap)),Min(GetSystemMetrics(SM_CYMENUCHECK),PixmapHeight(pixmap)))
+			If TWindowsGUIDriver.CheckCommonControlVersion() >= 2 Then
+				_iconBitmap = TWindowsGraphic.PreMultipliedBitmapFromPixmap32( pixmap )
+			Else
+				Local tmpRGB = GetSysColor(COLOR_MENU)
+				_iconBitmap = TWindowsGraphic.BitmapWithBackgroundFromPixmap32( pixmap, tmpRGB&$FF, (tmpRGB Shr 8) & $FF, (tmpRGB Shr 16) & $FF )
+			EndIf
+		EndIf
+		
+	EndMethod
+	
+	Method SetTooltip( pTooltip$ )
+		'Menus shouldn't have tool-tips.
+	EndMethod
+	
+	Method Class()
+		Return GADGET_MENUITEM
+	EndMethod
+
+End Type
+
+Type TWindowsListBox Extends TWindowsGadget
+
+	Field _icons:TWindowsIconStrip
+	Field _selected = -1
+
+	Method Create:TWindowsGadget(group:TGadget,style,Text$="")		
+		Local	xstyle,wstyle,hotkey
+		Local	hwnd:Byte Ptr,parent:Byte Ptr
+
+		Self.style = style
+		
+		xstyle=WS_EX_CLIENTEDGE
+		wstyle=WS_CHILD|WS_TABSTOP|LVS_REPORT|LVS_NOCOLUMNHEADER|LVS_SHOWSELALWAYS|LVS_SHAREIMAGELISTS			
+		wstyle:|WS_CLIPSIBLINGS
+		
+		If (style&LISTBOX_MULTISELECT<>LISTBOX_MULTISELECT) Then wstyle:|LVS_SINGLESEL
+		
+		parent=group.query(QUERY_HWND_CLIENT)
+		hwnd=CreateWindowExW(xstyle,"SysListView32","",wstyle,0,0,20,20,parent,hotkey,GetModuleHandleW(Null),Null)
+
+		Local column:LVCOLUMNW = New LVCOLUMNW
+		SendMessageW hwnd,LVM_INSERTCOLUMNW,0,column.colPtr
+
+		SendMessageW hwnd,LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT|LVS_EX_INFOTIP,LVS_EX_FULLROWSELECT|LVS_EX_INFOTIP
+
+		If TWindowsGUIDriver.CheckCommonControlVersion() Then SendMessageW hwnd,LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_DOUBLEBUFFER,LVS_EX_DOUBLEBUFFER
+
+		Register GADGET_LISTBOX,hwnd,0,False	'Set to True for normal Tooltips
+		
+		If TWindowsGUIDriver._explorerstyle Then UseExplorerTheme()
+
+		Return Self
+	EndMethod
+	
+	Method SetColor(r,g,b)
+		SendMessageW _hwnd,LVM_SETBKCOLOR ,0,(b Shl 16)|(g Shl 8)|r
+		SendMessageW _hwnd,LVM_SETTEXTBKCOLOR ,0,(b Shl 16)|(g Shl 8)|r
+	EndMethod
+
+	Method RemoveColor()
+		SendMessageW _hwnd,LVM_SETBKCOLOR ,1,0
+		SendMessageW _hwnd,LVM_SETTEXTBKCOLOR ,1,0
+	EndMethod
+
+	Method SetTextColor(r,g,b)
+		SendMessageW _hwnd,LVM_SETTEXTCOLOR,0,(b Shl 16)|(g Shl 8)|r
+	EndMethod
+	
+	'Hack: When image lists are removed from listviews, the items don't
+	'reposition themselves automatically. Hack involves first setting a tiny
+	'blank image-list to update item size, before attempting to remove it.
+	Method SetIconStrip(iconstrip:TIconStrip)
+		Local imagelist:Byte Ptr
+		If Not iconstrip Then
+			_icons = TWindowsIconStrip.CreateBlank()
+		Else
+			_icons = TWindowsIconStrip(iconstrip)
+		EndIf
+		If _icons Then imagelist = _icons._imagelist
+
+		SendMessageW _hwnd,LVM_SETIMAGELIST,LVSIL_SMALL,imagelist
+		If Not iconstrip Then
+			SendMessageW _hwnd,LVM_SETIMAGELIST,LVSIL_SMALL,0
+			_icons = Null
+		EndIf
+	EndMethod
+
+	Method ClearListItems()
+		_selected=-1
+		DeSensitize()
+		SendMessageW _hwnd,LVM_DELETEALLITEMS,0,0
+		If Not IsSingleSelect() Then SelectionChanged()
+		Sensitize()
+	EndMethod
+
+	Method InsertListItem(index,Text$,tip$,icon,tag:Object)
+		Local it:LVITEMW = New LVITEMW
+		it.Setmask(LVIF_TEXT|LVIF_DI_SETITEM)
+		it.SetiItem(index)
+		it.SetpszText(Text.toWString())
+
+		'If icon>=0 Then
+			it.Setmask(it.mask()|LVIF_IMAGE)
+			it.SetiImage(icon)
+		'EndIf
+
+		Desensitize()
+		SendMessageW _hwnd,LVM_INSERTITEMW,0,it.itemPtr
+		SendMessageW _hwnd,LVM_SETCOLUMNWIDTH,0,-2
+		If Not IsSingleSelect() Then SelectionChanged()
+		Sensitize()
+		MemFree it.pszText()
+		
+	EndMethod
+	
+	Method SetListItem(index,Text$,tip$,icon,tag:Object)
+		Local tmpReselect
+		If ListItemState(index) & STATE_SELECTED Then tmpReselect = True
+		RemoveListItem index
+		InsertListItem index,Text,tip,icon,tag
+		If tmpReselect Then SetItemState(index,STATE_SELECTED)
+	EndMethod
+	
+	Method RemoveListItem(index)
+		Desensitize()
+		If ListItemState(index) & STATE_SELECTED Then _selected = -1
+		SendMessageW _hwnd,LVM_DELETEITEM,index,0
+		SendMessageW _hwnd,LVM_SETCOLUMNWIDTH,0,-2
+		If Not IsSingleSelect() Then SelectionChanged()
+		Sensitize()
+	EndMethod
+	
+	Method SetListItemState(index,state)
+		Local it:LVITEMW = New LVITEMW
+		it.Setmask(LVIF_STATE)
+		it.SetiItem(index)
+		If state&STATE_SELECTED
+			it.Setstate(LVIS_SELECTED)
+			If IsSingleSelect() Then _selected=index
+		ElseIf _selected=index
+			_selected=-1
+		EndIf
+		it.SetstateMask(LVIS_SELECTED)
+		Desensitize()
+		SendMessageW _hwnd,LVM_SETITEMSTATE,index,it.itemPtr
+		If it.state() Then SendMessageW _hwnd,LVM_ENSUREVISIBLE,index,False
+		If Not IsSingleSelect() Then SelectionChanged()
+		Sensitize()
+	EndMethod
+	
+	Method ListItemState(index)
+		Local state = SendMessageW(_hwnd,LVM_GETITEMSTATE,index,LVIS_SELECTED)
+		If state&LVIS_SELECTED Return STATE_SELECTED
+	EndMethod
+	
+	Method SetTooltip( pTooltip$ )
+		'ToolTips should be set on an item-by-item basis instead.
+	EndMethod
+	
+	Method WndProc:Byte Ptr(hwnd:Byte Ptr,msg:UInt,wp:Byte Ptr,lp:Byte Ptr)
+		Select msg
+			Case WM_MAXGUILISTREFRESH
+				Local index
+				
+				If IsSingleSelect() Then
+					index=SendMessageW(_hwnd,LVM_GETNEXTITEM,-1,LVNI_SELECTED)
+				Else
+					index = SelectionChanged()
+				EndIf
+				If index <> _selected Then
+					If IsSingleSelect() Then _selected = index
+					Local item:TGadgetItem = New TGadgetItem
+					If index>=0 And index<items.length item=items[index]
+					PostGuiEvent EVENT_GADGETSELECT,index,0,0,0,item.extra
+				EndIf
+				
+			'If we are using XP Common Controls or higher, then the listbox will be double-buffered
+			'and so we don't need to clear the background (performance tweak).
+			Case WM_ERASEBKGND
+				If TWindowsGUIDriver.CheckCommonControlVersion() Then Return 1
+		EndSelect
+		Return Super.WndProc(hwnd,msg,wp,lp)
+	EndMethod
+	
+	Method OnNotify(wp:Byte Ptr,lp:Byte Ptr)
+		Local nmhdrPtr:Byte Ptr = lp
+		Local index, code = bmx_win32_NMHDR_code(nmhdrPtr)
+		Select code
+		
+			Case LVN_GETINFOTIPW
+				Local tmpItemIndex = bmx_win32_NMLVGETINFOTIPW_iItem(nmhdrPtr)
+				Local tmpMaxCharCount = bmx_win32_NMLVGETINFOTIPW_cchTextMax(nmhdrPtr)-1
+				Local tmpTipOutput:Short Ptr = bmx_win32_NMLVGETINFOTIPW_pszText(nmhdrPtr)
+				
+				If tmpItemIndex < items.length Then
+					
+					Local tmpTipString$ = items[tmpItemIndex].tip
+					If (items[tmpItemIndex].flags&GADGETITEM_LOCALIZED) Then tmpTipString = LocalizeString(tmpTipString)
+					
+					tmpTipString = tmpTipString[..Min(tmpTipString.length,tmpMaxCharCount)]
+					
+					Local tmpBufferMem:Short Ptr = tmpTipString.ToWString()
+					MemCopy tmpTipOutput, tmpBufferMem, (tmpTipString.length+1) * 2
+					MemFree tmpBufferMem
+					
+				EndIf
+
+			Case LVN_ITEMCHANGED
+				'We need to postpone processing until after *all* item states have been updated by the OS.
+				If Not(bmx_win32_NMLISTVIEW_uChanged(nmhdrPtr)&LVIF_STATE) Then Return
+				PostMessageW( _hwnd, WM_MAXGUILISTREFRESH, 0, 0 )
+			Case NM_DBLCLK
+				index=bmx_win32_NMITEMACTIVATE_iItem(nmhdrPtr)
+				Local item:TGadgetItem
+				If index>=0 And index<items.length
+					item=items[index]
+					PostGuiEvent EVENT_GADGETACTION,index,0,0,0,item.extra
+				EndIf
+			Case NM_CLICK
+				index=bmx_win32_NMITEMACTIVATE_iItem(nmhdrPtr)
+				If index=-1 And _selected<>-1
+					_selected=-1
+					PostGuiEvent EVENT_GADGETSELECT,-1
+				EndIf
+			Case NM_RCLICK
+				index=bmx_win32_NMITEMACTIVATE_iItem(nmhdrPtr)
+				Local item:TGadgetItem
+				If index>=0 And index<items.length
+					item=items[index]
+					PostGuiEvent EVENT_GADGETMENU,index,0,0,0,item.extra
+				EndIf
+			'Return true to tell the OS not to send individual LVN_DELETEITEM notifications for each and every item when clearing list.
+			Case LVN_DELETEALLITEMS
+				Return True
+		End Select
+	EndMethod
+	
+	Method IsSingleSelect()
+		Return (style&LISTBOX_MULTISELECT<>LISTBOX_MULTISELECT)
+	EndMethod
+	
+	Method Class()
+		Return GADGET_LISTBOX
+	EndMethod
+	
+	Method HasResized()
+		SendMessageW _hwnd,LVM_SETCOLUMNWIDTH,0,-2
+	EndMethod
+	
+	Method UseExplorerTheme()
+		If TWindowsGUIDriver.CheckCommonControlVersion() Then SetWindowTheme( _hwnd, _wstrExplorer, Null )
+	EndMethod
+	
+EndType
+
+Type TWindowsTabber Extends TWindowsGadget
+
+	Field _icons:TWindowsIconStrip
+	Field _tabcount
+	Field _blank:Short Ptr
+	Field _selected = -1
+	Field _tipbuffer:Short Ptr
+	Field _hittest:TCHITTESTINFO
+
+	Method Create:TWindowsGadget(group:TGadget,style,Text$="")		
+		Local	xstyle,wstyle,hotkey
+		Local	hwnd:Byte Ptr,parent:Byte Ptr,client:Byte Ptr
+		Self.style = style
+		xstyle=WS_EX_CONTROLPARENT
+		wstyle=WS_CHILD|TCS_HOTTRACK|WS_TABSTOP|TCS_FOCUSNEVER|WS_CLIPCHILDREN|WS_CLIPSIBLINGS		
+		parent=group.query(QUERY_HWND_CLIENT)
+		hwnd=CreateWindowExW(xstyle,"SysTabControl32","",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
+		client=CreateWindowExW(xstyle,TWindowsGUIDriver.ClassName(),"",WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,0,0,0,0,hwnd,0,GetModuleHandleW(Null),Null )
+		SendMessageW hwnd,TCM_INSERTITEMW,0,_wstrSpace
+		Register GADGET_TABBER,hwnd,client,True
+		SendMessageW _hwnd,TCM_SETTOOLTIPS,_tooltips,0
+		Return Self		
+	EndMethod
+	
+	Method SetIconStrip(iconstrip:TIconStrip)
+		Local imagelist:Byte Ptr
+		_icons=TWindowsIconStrip(iconstrip)
+		If _icons Then imagelist = _icons._imagelist
+		SendMessageW _hwnd,TCM_SETIMAGELIST,0,imagelist
+		RethinkClient()
+	EndMethod
+	
+	Method ClientWidth()
+		Local Rect[] = [0,0,width,height]
+		SendMessageW _hwnd,TCM_ADJUSTRECT,False,Rect
+		If Rect[2]>Rect[0] Then Return Rect[2]-Rect[0]
+	EndMethod
+
+	Method ClientHeight()
+		Local Rect[] = [0,0,width,height]
+		SendMessageW _hwnd,TCM_ADJUSTRECT,False,Rect
+		If Rect[3]>Rect[1] Then Return Rect[3]-Rect[1]
+	EndMethod
+
+	Method ClearListItems()
+		_tabcount=0
+		_selected=-1
+		Desensitize()
+		SendMessageW _hwnd,TCM_DELETEALLITEMS, 0, 0
+		Sensitize()
+		RethinkClient()
+	EndMethod
+
+	Method InsertListItem(index,Text$,tip$,icon,tag:Object)
+		If _tabcount=0 SendMessageW _hwnd,TCM_DELETEALLITEMS,0,0
+		Local t:TCITEMW=New TCITEMW		
+		t.Setmask(TCIF_TEXT|TCIF_IMAGE)
+		t.SetpszText(Text.toWString())
+		t.SetiImage(icon)
+		Desensitize()
+		SendMessageW _hwnd,TCM_INSERTITEMW,index,t.itemPtr
+		Sensitize()
+		MemFree t.pszText()
+		_tabcount:+1
+		RethinkClient()
+	EndMethod
+	
+	Method SetListItem(index,Text$,tip$,icon,tag:Object)
+		Local t:TCITEMW=New TCITEMW		
+		t.Setmask(TCIF_TEXT|TCIF_IMAGE)
+		t.SetpszText(Text.toWString())
+		t.SetiImage(icon)
+		Desensitize()
+		SendMessageW _hwnd,TCM_SETITEMW,index,t.itemPtr
+		Sensitize()
+		MemFree t.pszText()
+		RethinkClient()
+	EndMethod
+	
+	Method RemoveListItem(index)
+		Desensitize()
+		SendMessageW _hwnd,TCM_DELETEITEM,index,0
+		_tabcount:-1
+		_selected=SendMessageW(_hwnd,TCM_GETCURSEL,0,0)
+		If _tabcount=0 SendMessageW _hwnd,TCM_INSERTITEMW,0,Int(_blank)
+		Sensitize()
+		RethinkClient()
+	EndMethod
+
+	Method SetListItemState(index,state)
+		Desensitize()
+		If state&STATE_SELECTED
+			_selected=index
+			SendMessageW _hwnd,TCM_SETCURSEL,index,0
+		ElseIf _selected=index
+			_selected=-1
+		EndIf
+		Sensitize()
+	EndMethod
+	
+	Method ListItemState(index)
+		Local state,Current
+		Current=-1
+		If _tabcount Current=SendMessageW(_hwnd,TCM_GETCURSEL,0,0)
+		If Current=index state:|STATE_SELECTED
+		Return state
+	EndMethod
+
+	Method OnNotify(wp:Byte Ptr,lp:Byte Ptr)
+		Local nmhdrPtr:Byte Ptr	'hwnd,id,code
+		Local index
+		nmhdrPtr=lp
+		Select bmx_win32_NMHDR_code(nmhdrPtr)
+		
+			Case TTN_GETDISPINFOW
+				
+				'Local hittest:TCHITTESTINFO = New TCHITTESTINFO
+				If Not _hittest Then
+					_hittest = New TCHITTESTINFO
+				End If
+				
+				Local Rect[4]
+				
+				GetCursorPos_( _hittest.pt() );GetWindowRect( _hwnd, Rect )
+				'TCHITTESTINFO = [TCHITTESTINFO[0]-Rect[0],TCHITTESTINFO[1]-Rect[1],0]
+				_hittest.Setx(_hittest.x() - Rect[0])
+				_hittest.Sety(_hittest.y() - Rect[1])
+				_hittest.Setflags(0)
+				
+				Local tmpItem = SendMessageW( _hwnd, TCM_HITTEST, 0, _hittest.infoPtr)
+				
+				If (tmpItem > -1) And (tmpItem < items.length) Then
+					Local tmpTooltip$ = items[tmpItem].tip
+					If (items[tmpItem].flags&GADGETITEM_LOCALIZED) Then tmpTooltip = LocalizeString(tmpTooltip)
+					SetTipBuffer( tmpTooltip )
+					If tmpTooltip Then bmx_win32_NMTTDISPINFOW_SetlpszText(nmhdrPtr, _tipbuffer)
+				EndIf
+
+			Case TCN_SELCHANGE
+				If _tabcount
+					index=SendMessageW(_hwnd,TCM_GETCURSEL,0,0)
+					If index<>_selected
+						Local extra:Object
+						If index>=0 And index<items.length
+							extra=items[index].extra
+						Else
+							index=-1
+						EndIf
+						_selected=index
+						
+						PostGuiEvent EVENT_GADGETACTION,index,0,0,0,extra
+					EndIf
+				EndIf
+				
+			Case NM_RCLICK
+				
+				If Not _hittest Then
+					_hittest = New TCHITTESTINFO
+				End If
+				Local Rect[4], extra:Object
+				
+				GetCursorPos_( _hittest.pt() );GetWindowRect( _hwnd, Rect )
+				_hittest.Setx(_hittest.x() - Rect[0])
+				_hittest.Sety(_hittest.y() - Rect[1])
+				_hittest.Setflags(0)
+'				TCHITTESTINFO = [TCHITTESTINFO[0]-Rect[0],TCHITTESTINFO[1]-Rect[1],0]
+				
+				Local index = SendMessageW( _hwnd, TCM_HITTEST, 0, _hittest.infoPtr)
+				If (index < 0) Or (index >= items.length) Then
+					index = -1
+				Else
+					extra = items[index].extra
+				End If
+				
+				PostGuiEvent EVENT_GADGETMENU,index,0,_hittest.x(),_hittest.y(),extra
+				
+		EndSelect
+	EndMethod
+	
+	Method WndProc:Byte Ptr(hwnd:Byte Ptr,msg:UInt,wp:Byte Ptr,lp:Byte Ptr)
+		Select msg
+			Case WM_ERASEBKGND
+				Select hwnd
+					Case _hwndclient
+						DrawParentBackground(wp,hwnd)
+						Return 1
+				EndSelect
+		End Select
+		Return Super.WndProc(hwnd,msg,wp,lp)
+	EndMethod
+	
+	Method RethinkClient(forceRedraw:Int = False)
+		Local Rect[] = [0,0,width,height]
+		SendMessageW _hwnd,TCM_ADJUSTRECT,False, Int Byte Ptr(Rect)
+		MoveWindow _hwndclient,Rect[RECT_LEFT],Rect[RECT_TOP],Rect[RECT_RIGHT]-Rect[RECT_LEFT],Rect[RECT_BOTTOM]-Rect[RECT_TOP],forceRedraw
+	EndMethod
+	
+	Method SetTipBuffer( pTip$ )
+		If _tipbuffer Then MemFree _tipbuffer
+		If pTip Then
+			_tipbuffer = pTip.ToWString()
+		Else
+			_tipbuffer = Null
+		End If
+	EndMethod
+	
+	Method SetTooltip( pTooltip$ )
+		'ToolTips should be set on an item-by-item basis instead.
+	EndMethod
+	
+	Method Class()
+		Return GADGET_TABBER
+	EndMethod
+	
+EndType
+
+Type TWindowsToolbar Extends TWindowsGadget
+	Field _icons:TWindowsIconStrip
+
+	Method Create:TWindowsGadget(group:TGadget,style,Text$="")	
+		Local	xstyle,wstyle,hotkey
+		Local	hwnd:Byte Ptr,parent:Byte Ptr
+		Self.style = style
+		xstyle=TBSTYLE_EX_DOUBLEBUFFER|TBSTYLE_EX_HIDECLIPPEDBUTTONS
+		wstyle=TBSTYLE_FLAT|WS_CHILD|WS_CLIPSIBLINGS|TBSTYLE_TRANSPARENT
+		Self.parent = group
+		parent=Self.parent.query(QUERY_HWND)
+		hwnd=CreateWindowExW(xstyle,"ToolbarWindow32","",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
+		DragAcceptFiles(hwnd,False)	'For some reason, toolbars may accept files by default!
+		Register GADGET_TOOLBAR,hwnd,0,True
+		SendMessageW _hwnd,TB_SETTOOLTIPS,_tooltips,0
+		Rethink()
+		Return Self
+	EndMethod
+	
+	Method SetIconStrip(iconstrip:TIconStrip)	
+		_icons=TWindowsIconStrip(iconstrip)
+		SendMessageW _hwnd,TB_SETIMAGELIST,0,_icons._imagelist	
+		SendMessageW _hwnd,TB_AUTOSIZE,0,0
+		Rethink
+	EndMethod
+	
+	Method SetShow(truefalse)
+		Super.SetShow(truefalse)
+		UpdateWindowClient()
+	EndMethod
+	
+	Method Free()
+		SetShow(False)
+		Super.Free()
+	EndMethod
+	
+	Method Rethink()
+		
+		Local tmpRect[4]
+		GetWindowRect _hwnd,tmpRect
+		SetRect(0,0,parent.ClientWidth(),(tmpRect[3]-tmpRect[1]))
+		QueueResize _hwnd,xpos,ypos,width,height
+		UpdateWindowClient()
+		
+	EndMethod
+	
+	Method UpdateWindowClient()
+		Local tmpHeight:Int = height
+		If (State()&STATE_HIDDEN) Then tmpHeight = 0
+		If TWindowsGadget(parent)._clientY <> tmpHeight Then
+			TWindowsGadget(parent)._clientY = tmpHeight
+			parent.Rethink()
+			TWindowsGadget(parent).RethinkClient()
+			parent.LayoutKids()
+		EndIf
+	EndMethod
+	
+	Method DoLayout()
+		Rethink()
+	EndMethod
+	
+	Method SetTooltip( pTooltip$ )
+		'ToolTips should be set on an item-by-item basis instead.
+	EndMethod
+	
+	Method ClearListItems()
+		While SendMessageW(_hwnd,TB_BUTTONCOUNT,0,0)
+			RemoveListItem(0)
+		Wend
+	EndMethod
+
+	Method InsertListItem(index,Text$,tip$,icon,tag:Object)
+		Local but:TBBUTTON = New TBBUTTON
+		but.SetfsState(TBSTATE_ENABLED)
+		If icon = -2 Or (icon>-1 And _icons.IsBlankIcon(icon))
+			but.SetidCommand(0)
+			but.SetfsStyle(TBSTYLE_SEP)
+		Else
+			but.SetiBitmap(icon)
+			but.SetidCommand(index+1)
+			but.SetfsStyle(TBSTYLE_BUTTON)
+		EndIf
+		Desensitize()
+		SendMessageW _hwnd,TB_INSERTBUTTON,index,but.buttonPtr
+		Sensitize()
+		If tip
+			Local ti:TOOLINFOW=New TOOLINFOW
+			'ti.cbSize=SizeOf(ti)
+			ti.SetuFlags(TTF_SUBCLASS)
+			ti.Sethwnd(_hwnd)
+			ti.SetlpszText(tip.towstring())
+			ti.SetuId(index+1)
+			SendMessageW _hwnd,TB_GETITEMRECT,index,ti.rect()
+			SendMessageW _tooltips,TTM_ADDTOOLW,0,ti.infoPtr
+			MemFree ti.lpszText()
+		EndIf
+	EndMethod
+
+	Method SetListItem(index,Text$,tip$,icon,tag:Object)
+		Local tmpState:Int = ListItemState(index)
+		RemoveListItem index
+		InsertListItem index,Text,tip,icon,tag
+		SetListItemState(index,tmpState)
+	EndMethod
+	
+	Method RemoveListItem(index)
+		Local ti:TOOLINFOW=New TOOLINFOW
+		'ti.cbSize=SizeOf(ti)
+		ti.Sethwnd(_hwnd)
+		ti.SetuId(index+1)
+		Desensitize()
+		SendMessageW _tooltips,TTM_DELTOOLW,0,ti.infoPtr
+		SendMessageW _hwnd,TB_DELETEBUTTON,index,0
+		Sensitize()
+	EndMethod
+	
+	Method SetListItemState(index,state)
+		Local enable,pressed
+		If state&STATE_DISABLED=0 enable=$1
+		If state&STATE_SELECTED pressed=$1
+		SendMessageW _hwnd,TB_ENABLEBUTTON,index+1,enable
+		SendMessageW _hwnd,TB_CHECKBUTTON,index+1,pressed
+	EndMethod
+	
+	Method ListItemState(index)
+		Local state,flags
+		state=SendMessageW(_hwnd,TB_GETSTATE,index+1,0)
+		If state=-1 Return 0
+		If Not (state&TBSTATE_ENABLED) flags:|STATE_DISABLED
+		If state&TBSTATE_CHECKED flags:|STATE_SELECTED
+		Return flags	
+	EndMethod
+
+	Method OnCommand(msg,wp:ULong)
+		Local index=wp-1
+		Local extra:Object
+		If index>=0 And index<items.length extra=items[index].extra
+		PostGuiEvent EVENT_GADGETACTION,index,0,0,0,extra
+	EndMethod
+	
+	Method Class()
+		Return GADGET_TOOLBAR
+	EndMethod
+	
+EndType
+
+Type TWindowsSlider Extends TWindowsGadget
+	Field	_slidertype,_ishorizontal,_visible = 5,_total = 10,_value
+
+	Method Create:TWindowsGadget(group:TGadget,style,Text$="")	
+		Local	xstyle,wstyle,class$
+		Local	hwnd:Byte Ptr,parent:Byte Ptr,hotkey
+								
+		_slidertype=style&$fffc
+		_ishorizontal=style&SLIDER_HORIZONTAL
+		
+		Self.style = style
+		wstyle=WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN
+		parent=group.query(QUERY_HWND_CLIENT)		
+		Select _slidertype
+			Case SLIDER_SCROLLBAR
+				If _ishorizontal wstyle:|SBS_HORZ;Else wstyle:|SBS_VERT
+				class$="SCROLLBAR"
+			Case SLIDER_TRACKBAR
+				wstyle:|TBS_AUTOTICKS|WS_TABSTOP
+				xstyle:|WS_EX_COMPOSITED	'Reduces flicker when resizing (doesn't like scrollbars/up-down controls)
+				If _ishorizontal wstyle:|TBS_HORZ Else wstyle:|TBS_VERT
+				class$=TRACKBAR_CLASS
+			Case SLIDER_STEPPER
+				If _ishorizontal wstyle:|UDS_HORZ
+				class$="msctls_updown32"
+			Default
+				Return Null
+		End Select
+		
+		hwnd=CreateWindowExW(xstyle,class,"",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
+		Register GADGET_SLIDER,hwnd
+		RefreshLook()
+		
+		Return Self		
+	EndMethod
+
+	Method SetRange(visible,total)
+		_visible = visible
+		_total = total
+		Local tmpEnabled:Int = Not( State() & STATE_DISABLED )
+		Desensitize()
+		Select _slidertype
+			Case SLIDER_SCROLLBAR
+				Local info:SCROLLINFO=New SCROLLINFO
+				'info.SecbSize=SizeOf(SCROLLINFO)
+				info.SetfMask(SIF_PAGE|SIF_RANGE)
+				info.SetnMax(total-1)
+				info.SetnPage(visible)
+				SendMessageW _hwnd,SBM_SETSCROLLINFO,True,info.infoPtr
+			Case SLIDER_TRACKBAR
+				
+				SendMessageW _hwnd,TBM_SETRANGEMIN,False,visible
+				SendMessageW _hwnd,TBM_SETRANGEMAX,True,total
+				
+				' Aesthetic tweak that should stop black tick bands forming when
+				' large ranges are used on small trackbars.
+				
+				Local tmpFirstTick% = SendMessageW( _hwnd, TBM_GETTICPOS, 0, 0 )
+				Local tmpNumTicks% = SendMessageW( _hwnd, TBM_GETNUMTICS, 0, 0)
+				Local tmpLastTick% = SendMessageW( _hwnd, TBM_GETTICPOS, tmpNumTicks-3, 0 )
+				If Not( tmpLastTick < 0 Or tmpFirstTick < 0 Or (total-visible-2) < 1) Then
+					If (tmpLastTick-tmpFirstTick)/(total-visible-2) < 4 Then
+						SendMessageW( _hwnd, TBM_CLEARTICS, True, 0 )
+					EndIf
+				EndIf
+				
+			Case SLIDER_STEPPER
+				SendMessageW _hwnd,UDM_SETRANGE32,visible,total
+		End Select
+		_value = GetProp()
+		SetEnabled(tmpEnabled)
+		Sensitize()	
+	EndMethod
+	
+	Method SetProp(value)
+		Desensitize()
+		Select _slidertype
+			Case SLIDER_SCROLLBAR
+				Local info:SCROLLINFO=New SCROLLINFO
+				'info.cbSize=SizeOf(SCROLLINFO)
+				info.SetfMask(SIF_POS)
+				info.SetnPos(value)
+				SendMessageW _hwnd,SBM_SETSCROLLINFO,True,info.infoPtr
+			Case SLIDER_TRACKBAR
+				If _ishorizontal Then
+					SendMessageW _hwnd,TBM_SETPOS,True,value
+				Else
+					'Flip the value so that the scale starts from the bottom
+					SendMessageW _hwnd,TBM_SETPOS,True,_visible + _total - value
+				EndIf
+			Case SLIDER_STEPPER
+				SendMessageW _hwnd,UDM_SETPOS,True,value
+		End Select
+		_value = value
+		Sensitize()	
+	EndMethod
+	
+	Method GetProp()
+		Local value
+		Select _slidertype
+			Case SLIDER_SCROLLBAR
+				value=GetScrollPos(_hwnd,SB_CTL)
+			Case SLIDER_TRACKBAR
+				value=SendMessageW(_hwnd,TBM_GETPOS,0,0)
+				'Flip the value so that the scale starts from the bottom
+				If Not _ishorizontal Then value = _visible + _total - value
+			Case SLIDER_STEPPER
+				value=SendMessageW(_hwnd,UDM_GETPOS32,0,Null)
+		End Select		
+		Return value
+	EndMethod
+
+	Method OnCommand(msg,wp:ULong)
+		If _slidertype=SLIDER_SCROLLBAR
+			If msg=WM_COMMAND Return
+			Local info:SCROLLINFO=New SCROLLINFO
+			'info.cbSize=SizeOf(SCROLLINFO)
+			Select Long(wp)&$ffff
+				Case SB_THUMBTRACK,SB_THUMBPOSITION
+					info.SetfMask(SIF_TRACKPOS)
+					SendMessageW _hwnd,SBM_GETSCROLLINFO,0,info.infoPtr
+					SetScrollPos _hwnd,SB_CTL,info.nTrackPos(),True
+				Default
+					info.SetfMask(SIF_POS|SIF_PAGE|SIF_RANGE)
+					SendMessageW _hwnd,SBM_GETSCROLLINFO,0,info.infoPtr
+					Local pos=info.nPos()
+					Local vis=info.nPage()
+					Select Long(wp)&$ffff
+						Case SB_LINEUP pos:-1
+						Case SB_LINEDOWN pos:+1
+						Case SB_PAGEUP pos:-vis
+						Case SB_PAGEDOWN pos:+vis
+						Default Return 0
+					End Select
+					SetScrollPos _hwnd,SB_CTL,pos,True
+			End Select
+		EndIf
+		Local index=GetProp()
+		If (index <> _value) Then
+			PostGuiEvent EVENT_GADGETACTION,index
+			_value = index
+		EndIf
+		Return 1
+	EndMethod
+	
+	Method WndProc:Byte Ptr(hwnd:Byte Ptr,msg:UInt,wp:Byte Ptr,lp:Byte Ptr)
+		Select msg
+			Case WM_ERASEBKGND
+				Return 1
+		EndSelect
+		Return Super.WndProc(hwnd,msg,wp,lp)
+	EndMethod
+	
+	Method RefreshLook()
+		Super.RefreshLook()
+		SetRange(_visible,_total)
+	EndMethod
+	
+	Method Class()
+		Return GADGET_SLIDER
+	EndMethod
+		
+EndType
+
+Type TWindowsProgressBar Extends TWindowsGadget
+
+	Method Create:TWindowsGadget(group:TGadget,style,Text$="")		
+		Local	xstyle,wstyle,hotkey
+		Local	hwnd:Byte Ptr,parent:Byte Ptr
+		Self.style = style
+		wstyle=WS_CHILD|PBS_SMOOTH|WS_CLIPSIBLINGS
+		parent=group.query(QUERY_HWND_CLIENT)
+		hwnd=CreateWindowExW(xstyle,"msctls_progress32","",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
+		Register GADGET_PROGBAR,hwnd
+		Return Self		
+	EndMethod
+	
+	Method SetValue(value#)
+		SendMessageW _hwnd,PBM_SETPOS,Int(value*100),0
+	EndMethod
+	
+	Method SetColor(r,g,b)
+		'Only works in Classic mode, but it's better than nothing.
+		SendMessageW _hwnd,PBM_SETBKCOLOR ,0,(b Shl 16)|(g Shl 8)|r
+	EndMethod
+
+	Method RemoveColor()
+		'Only works in Classic mode, but it's better than nothing.
+		SendMessageW _hwnd,PBM_SETBKCOLOR ,1,0
+	EndMethod
+
+	Method SetTextColor(r,g,b)
+		'Only works in Classic mode, but it's better than nothing.
+		SendMessageW _hwnd,PBM_SETBARCOLOR ,0,(b Shl 16)|(g Shl 8)|r
+	EndMethod
+	
+	Method Class()
+		Return GADGET_PROGBAR
+	EndMethod
+	
+EndType
+
+Type TWindowsComboBox Extends TWindowsGadget
+
+	Field _icons:TWindowsIconStrip
+	Field _editHwnd:Byte Ptr, _comboHwnd:Byte Ptr
+	Field _selected = -1
+	
+	Method Create:TWindowsGadget(group:TGadget,style,Text$="")
+		Local	xstyle,wstyle,hotkey,hwnd:Byte Ptr
+		Local	parent:Byte Ptr,editstyle,combostyle
+		
+		Self.style = style
+		wstyle=WS_CHILD|WS_TABSTOP|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|CBS_AUTOHSCROLL
+		If (style & COMBOBOX_EDITABLE) Then wstyle:|CBS_DROPDOWN Else wstyle:|CBS_DROPDOWNLIST
+		
+		parent=group.query(QUERY_HWND_CLIENT)
+		hwnd=CreateWindowExW(xstyle,"ComboBoxEx32","",wstyle,0,0,0,180,parent,hotkey,GetModuleHandleW(Null),Null)
+		
+		If (style & COMBOBOX_EDITABLE) Then
+			_editHwnd=SendMessageW(hwnd,CBEM_GETEDITCONTROL,0,0)
+			If _editHwnd Then
+				editstyle=GetWindowLongW(_editHwnd,GWL_STYLE)
+				SetWindowLongW _editHwnd,GWL_STYLE,editstyle|WS_TABSTOP
+			EndIf
+		EndIf
+
+		_comboHwnd=SendMessageW(hwnd,CBEM_GETCOMBOCONTROL,0,0)
+		comboStyle=GetWindowLongW(_comboHwnd,GWL_STYLE)
+		SetWindowLongW _comboHwnd,GWL_STYLE,comboStyle|WS_TABSTOP
+		
+		Register GADGET_COMBOBOX,hwnd
+		
+		TWindowsGUIDriver.RegisterHwnd(_combohwnd,Self)
+		If _edithwnd Then TWindowsGUIDriver.RegisterHwnd(_edithwnd,Self)
+		
+		SetColor(255,255,255)
+		
+		Return Self	
+		
+	EndMethod
+	
+	Method SetText(Text$)
+		If Not _editHwnd Then
+			Local tmpWString:Short Ptr = Text.ToWString()
+			Local tmpResult = SendMessageW(_comboHwnd, CB_SETCUEBANNER, 0, tmpWString)
+			MemFree tmpWString
+			Return tmpResult
+		Else
+			Return Super.SetText(Text)
+		EndIf
+	EndMethod
+	
+	Method GetText$()
+		If Not _editHwnd Then
+			If _selected > -1 Then Return items[_selected].Text Else Return ""
+		Else
+			Return Super.GetText()
+		EndIf
+	EndMethod
+	
+	Method Activate(cmd)
+		If _editHwnd Then
+			Select cmd
+				Case ACTIVATE_CUT	
+					SendMessageW _editHwnd,WM_CUT,0,0
+				Case ACTIVATE_COPY	
+					SendMessageW _editHwnd,WM_COPY,0,0
+					SetFocus _hwnd
+				Case ACTIVATE_PASTE
+					SendMessageW _editHwnd,WM_PASTE,0,0
+				Case ACTIVATE_FOCUS
+					SendMessageW _editHwnd,EM_SETSEL,0,-1
+			End Select
+		EndIf
+		Return Super.Activate(cmd)
+	EndMethod
+	
+	Method SetIconStrip(iconstrip:TIconStrip)
+		Local imagelist:Byte Ptr
+		_icons=TWindowsIconStrip(iconstrip)
+		If _icons Then imagelist = _icons._imagelist
+		SendMessageW _hwnd,CBEM_SETIMAGELIST,LVSIL_SMALL,imagelist
+	EndMethod
+
+	Method ClearListItems()
+		_selected=-1
+		Desensitize()
+		SendMessageW _hwnd,CB_RESETCONTENT,0,0
+		Sensitize()
+	EndMethod
+
+	Method InsertListItem(index,Text$,tip$,icon,tag:Object)
+		Local it:COMBOBOXEXITEMW = New COMBOBOXEXITEMW
+		it.Setmask(CBEIF_TEXT)
+		it.SetiItem(index)
+		it.SetpszText(Text.toWString())
+		If icon>=0
+			it.Setmask(it.mask()|CBEIF_IMAGE|CBEIF_SELECTEDIMAGE)
+			it.SetiImage(icon)
+			it.SetiSelectedImage(icon)
+		EndIf
+		Desensitize()
+		SendMessageW(_hwnd,CBEM_INSERTITEMW,0,it.itemPtr)
+		Sensitize()
+		MemFree it.pszText()
+	EndMethod
+	
+	Method SetListItem(index,Text$,tip$,icon,tag:Object)
+		Local it:COMBOBOXEXITEMW = New COMBOBOXEXITEMW
+		it.Setmask(CBEIF_TEXT)
+		it.SetiItem(index)
+		it.SetpszText(Text.toWString())
+		If _icons And icon>-1
+			it.Setmask(it.mask()|CBEIF_IMAGE|CBEIF_SELECTEDIMAGE)
+			it.SetiImage(icon)
+			it.SetiSelectedImage(icon)
+		EndIf
+		Desensitize()
+		SendMessageW(_hwnd,CBEM_SETITEMW,0,it.itemPtr)
+		Sensitize()
+		MemFree it.pszText()
+	EndMethod
+	
+	Method RemoveListItem(index)
+		Desensitize()
+		SendMessageW _hwnd,CBEM_DELETEITEM,index,0
+		Sensitize()
+	EndMethod
+	
+	Method SetListItemState(index,state)
+		If state&STATE_SELECTED
+			_selected=index
+		Else
+			If _selected=index _selected=-1
+			index=-1
+		EndIf
+		Desensitize()
+		SendMessageW _hwnd,CB_SETCURSEL,index,0
+		Sensitize()
+	EndMethod
+	
+	Method ListItemState(index)
+		Local Current,state
+		Current=SendMessageW(_hwnd,CB_GETCURSEL,0,0)
+		If Current=CB_ERR Current=-1
+		If Current=index state=STATE_SELECTED
+		Return state
+	EndMethod
+	
+	Method OnCommand(msg,wp:ULong)
+		Local index
+		Select wp Shr 16
+			Case CBN_SELCHANGE
+				index=SendMessageW(_hwnd,CB_GETCURSEL,0,0)
+				If index=CB_ERR
+					index=-1
+				Else
+					If _selected<>index	'user generated event
+						_selected=index
+						Local extra:Object
+						If index>=0 And index<items.length extra=items[index].extra
+						PostGuiEvent EVENT_GADGETACTION,index,0,0,0,extra
+					EndIf
+				EndIf
+			Case CBN_EDITCHANGE
+				_selected=-1
+				PostGuiEvent EVENT_GADGETACTION,-1
+		End Select
+	EndMethod
+
+	Method Class()
+		Return GADGET_COMBOBOX
+	EndMethod
+
+EndType
+
+Type TWindowsPanel Extends TWindowsGadget
+
+	Const PANELPANEL=0
+	Const PANELGROUP=1
+	Const PANELCANVAS=2
+
+	Field _type
+	Field _alpha#=1.0
+	Field _bitmapwidth,_bitmapheight,_bitmapflags
+	Field _canvas:TGraphics
+	Field _hasalpha
+	
+	Method Create:TWindowsGadget(group:TGadget,style,Text$="")	
+		Local	xstyle,wstyle,hotkey
+		Local	hwnd:Byte Ptr,client:Byte Ptr,parent:Byte Ptr
+		Self.style = style
+		
+		parent=group.query(QUERY_HWND_CLIENT)
+		If (style&3=PANEL_GROUP) Then
+			_type=PANELGROUP
+			hwnd=CreateWindowExW(WS_EX_CONTROLPARENT,"BUTTON","",BS_GROUPBOX|WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,0,0,0,0,parent,0,GetModuleHandleW(Null),Null )
+			client=CreateWindowExW(WS_EX_CONTROLPARENT,TWindowsGUIDriver.ClassName(),"",WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,0,0,0,0,hwnd,0,GetModuleHandleW(Null),Null)
+		Else
+			_type=PANELPANEL
+			xstyle=WS_EX_CONTROLPARENT
+			wstyle=WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS
+			Select (style&3)
+				Case PANEL_SUNKEN xstyle:|WS_EX_CLIENTEDGE
+				Case PANEL_RAISED xstyle:|WS_EX_WINDOWEDGE ; wstyle:|WS_DLGFRAME
+			EndSelect
+			If (style&PANEL_CANVAS) Then _type=PANELCANVAS																				
+			hwnd=CreateWindowExW(xstyle,TWindowsGUIDriver.ClassName(),"",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
+		EndIf
+				
+		Register GADGET_PANEL,hwnd,client
+		If (style & PANEL_ACTIVE) Then sensitivity = SENSITIZE_ALL
+		
+		Return Self	
+	EndMethod
+	
+	Method SetAlpha( alpha# )
+		_alpha=alpha
+		RedrawGadget(Self)
+	EndMethod
+	
+	Method Activate( cmd )
+		Select cmd
+			Case ACTIVATE_REDRAW
+				If (_type = PANELCANVAS) Then
+					InvalidateRect _hwnd, Null, False
+					Return True
+				EndIf
+		EndSelect
+		Return Super.Activate(cmd)
+	EndMethod
+	
+	Method SetPixmap(pixmap:TPixmap,flags)
+		If _bitmap Then DeleteObject _bitmap;_bitmap = 0
+		If pixmap Then
+			If pixmap.format=PF_RGBA8888 Or pixmap.format=PF_BGRA8888
+				_bitmap=TWindowsGraphic.PreMultipliedBitmapFromPixmap32( pixmap )
+			EndIf
+			If _bitmap
+				_hasalpha=True
+			Else
+				_bitmap=TWindowsGraphic.BitmapFromPixmap( pixmap, False )
+				_hasalpha=False
+			EndIf
+			_bitmapflags=flags
+			_bitmapwidth=pixmap.width
+			_bitmapheight=pixmap.height
+		EndIf
+		RedrawGadget(Self)
+	EndMethod
+			
+	Method AttachGraphics:TGraphics( flags )
+		_canvas=brl.Graphics.AttachGraphics( _hwnd,flags )
+	EndMethod
+	
+	Method CanvasGraphics:TGraphics()
+		Return _canvas
+	EndMethod
+	
+	Method Free()
+		If _canvas Then CloseGraphics(_canvas);_canvas = Null
+		Super.Free()
+	EndMethod
+			
+	Method WndProc:Byte Ptr(hwnd:Byte Ptr,msg:Uint,wp:Byte Ptr,lp:Byte Ptr)
+		Select msg
+				
+			Case WM_ERASEBKGND
+				
+				If _type = PANELCANVAS Then Return 1
+				
+				Local hdc:Byte Ptr=wp,hdcCanvas:Byte Ptr,hdcBitmap:Byte Ptr
+				Local srcw,srch,x,y,xoffset,yoffset
+				Local clientRect[4], updateRect[4], clipRect[4], windowRect[4]
+				
+				GetClipBox( hdc, clipRect )
+				GetWindowRect( hwnd, windowRect)
+				GetClientRect( hwnd, clientRect )
+				
+				If Not GetUpdateRect( hwnd, updateRect, False) Then updateRect = clipRect
+				If IsRectEmpty(updateRect) Then updateRect = [0,0,windowRect[2]-windowRect[0],windowRect[3]-windowRect[1]]
+				
+				'If we are drawing a bitmap or using alpha then let's do some double-buffering stuff
+				
+				If (hwnd <> _hwndclient) And ((_bitmap And _bitmapwidth And _bitmapheight) Or _alpha<1.0) Then
+				
+					hdc = CreateCompatibleDC(wp)
+					hdcCanvas = CreateCompatibleBitmap(wp,windowRect[2]-windowRect[0],windowRect[3]-windowRect[1])
+					SelectObject( hdc, hdcCanvas )
+				
+				EndIf
+				
+				'Fill the drawing context with the background colour, or the background of the parent
+				
+				If BgBrush() And (hwnd <> _hwndclient) Then FillRect(hdc,updateRect,BgBrush()) Else DrawParentBackground(hdc,hwnd)
+				
+				'If we aren't drawing to a bitmap or using alpha, then we can return now.
+				
+				If Not ((hwnd <> _hwndclient) And ((_bitmap And _bitmapwidth And _bitmapheight) Or _alpha<1.0)) Then Return 1
+				
+				If _bitmap And _bitmapwidth And _bitmapheight
+					hdcBitmap=CreateCompatibleDC(hdc)
+					SelectObject(hdcBitmap,_bitmap)
+					srcw=_bitmapwidth
+					srch=_bitmapheight
+					Select (_bitmapflags & (GADGETPIXMAP_ICON-1))
+						Case PANELPIXMAP_TILE
+							While y<windowRect[RECT_BOTTOM]-windowRect[RECT_TOP]
+								x=0
+								While x<windowRect[RECT_RIGHT]-windowRect[RECT_LEFT]
+									If _hasalpha
+										AlphaBlend_ hdc,x,y,srcw,srch,hdcBitmap,0,0,srcw,srch,$01ff0000
+									Else
+										BitBlt hdc,x,y,srcw,srch,hdcBitmap,0,0,ROP_SRCCOPY
+									EndIf
+									x:+srcw
+								Wend
+								y:+srch
+							Wend
+						Case PANELPIXMAP_CENTER
+							x=(windowRect[RECT_RIGHT]-windowRect[RECT_LEFT]-srcw)/2
+							y=(windowRect[RECT_BOTTOM]-windowRect[RECT_TOP]-srch)/2
+							If _hasalpha
+								AlphaBlend_ hdc,x,y,srcw,srch,hdcBitmap,0,0,srcw,srch,$01ff0000
+							Else
+								BitBlt hdc,x,y,srcw,srch,hdcBitmap,0,0,ROP_SRCCOPY
+							EndIf
+						
+						Case PANELPIXMAP_FIT, PANELPIXMAP_FIT2
+						
+							Local mx# = Float(windowRect[RECT_RIGHT]-windowRect[RECT_LEFT])/srcw
+							Local my# = Float(windowRect[RECT_BOTTOM]-windowRect[RECT_TOP])/srch
+							
+							If mx>my Then
+								If (_bitmapflags&(GADGETPIXMAP_ICON-1)) = PANELPIXMAP_FIT Then mx=my Else my=mx
+							EndIf
+							Local w=mx*srcw
+							Local h=mx*srch
+							x=(windowRect[RECT_RIGHT]-windowRect[RECT_LEFT]-w)/2
+							y=(windowRect[RECT_BOTTOM]-windowRect[RECT_TOP]-h)/2
+							SetStretchBltMode hdc,COLORONCOLOR
+
+							If _hasalpha
+								AlphaBlend_ hdc,x,y,w,h,hdcBitmap,0,0,srcw,srch,$01ff0000
+							Else
+								StretchBlt hdc,x,y,w,h,hdcBitmap,0,0,srcw,srch,ROP_SRCCOPY
+							EndIf
+
+						Case PANELPIXMAP_STRETCH
+							SetStretchBltMode hdc,COLORONCOLOR
+
+							If _hasalpha
+								AlphaBlend_ hdc,0,0,windowRect[RECT_RIGHT]-windowRect[RECT_LEFT],windowRect[RECT_BOTTOM]-windowRect[RECT_TOP],hdcBitmap,0,0,srcw,srch,$01ff0000
+							Else
+								StretchBlt hdc,0,0,windowRect[RECT_RIGHT]-windowRect[RECT_LEFT],windowRect[RECT_BOTTOM]-windowRect[RECT_TOP],hdcBitmap,0,0,srcw,srch,ROP_SRCCOPY
+							EndIf
+						
+					EndSelect				
+					
+					DeleteDC(hdcBitmap)
+					
+				EndIf
+				
+				If _alpha < 1.0 Then
+					
+					DrawParentBackground( wp, hwnd )
+					Local blendfunction = ((Int(_alpha*255)&$FF) Shl 16)
+					AlphaBlend_(wp,updateRect[0],updateRect[1],updateRect[2]-updateRect[0],updateRect[3]-updateRect[1],hdc,updateRect[0],updateRect[1],updateRect[2]-updateRect[0],updateRect[3]-updateRect[1],blendfunction)
+				
+				Else
+					
+					BitBlt(wp,0,0,windowRect[2]-windowRect[0],WindowRect[3]-windowRect[1],hdc,0,0,ROP_SRCCOPY)
+				
+				EndIf
+				
+				Assert hdc <> wp, "hdc == wp! Please post a MaxGUI bug report."
+				
+				DeleteObject( hdcCanvas )
+				DeleteDC( hdc )
+				
+				Return 1
+			
+			Case WM_PAINT
+				
+				Select _type
+					Case PANELCANVAS
+						PostGuiEvent EVENT_GADGETPAINT
+						ValidateRect _hwnd, Null
+						Return 1
+				EndSelect
+			
+			Case WM_LBUTTONDOWN
+				
+				SetFocus Query(QUERY_HWND_CLIENT)
+				
+		End Select
+		
+		Return Super.WndProc(hwnd,msg,wp,lp)
+		
+	EndMethod
+	
+	Method FlushBrushes(pRecurse:Int = True)
+		Super.FlushBrushes()
+		If Not pRecurse Then Return
+		For Local tmpGadget:TWindowsGadget = EachIn kids
+			tmpGadget.FlushBrushes()
+		Next
+	EndMethod
+	
+	Method ClientWidth()
+		If _hwndClient Then
+			Return (Super.ClientWidth()-8)
+		Else
+			Return Super.ClientWidth()
+		End If
+	EndMethod
+	
+	Method ClientHeight()
+		If _hwndClient Then
+			Return (Super.ClientHeight()-20)
+		Else
+			Return Super.ClientHeight()
+		End If
+	EndMethod
+	
+	Method RethinkClient(forceRedraw:Int = False)
+		If _hwndClient Then
+			MoveWindow( _hwndClient, 4+_clientX,16+_clientY,ClientWidth(),ClientHeight(),forceRedraw)
+		EndIf
+	EndMethod
+	
+	Method Class()
+		If _type = PANELCANVAS Then
+			Return GADGET_CANVAS
+		Else
+			Return GADGET_PANEL
+		End If
+	EndMethod
+			
+EndType
+
+
+Type TWindowsTextField Extends TWindowsGadget
+
+	Field _busy
+	
+	Method Create:TWindowsGadget(group:TGadget,style,Text$="")	
+		Local	xstyle,wstyle,hotkey
+		Local	hwnd:Byte Ptr,parent:Byte Ptr
+		Self.style = style
+		xstyle=WS_EX_CLIENTEDGE
+		wstyle=WS_CHILD|WS_TABSTOP|ES_AUTOHSCROLL|WS_CLIPSIBLINGS
+		If style&TEXTFIELD_PASSWORD Then wstyle:|ES_PASSWORD		
+		parent=group.query(QUERY_HWND_CLIENT)
+		hwnd=CreateWindowExW(xstyle,"EDIT","",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
+		'SendMessageW hwnd,WM_SETFONT,TWindowsGUIDriver.GDIFont.handle,1
+		Register GADGET_TEXTFIELD,hwnd
+		SetColor(255,255,255)
+		Return Self		
+	EndMethod
+
+	Method SetText(Text$)
+		Local p0,p1
+		_busy:+1
+		SendMessageW _hwnd,EM_GETSEL,Varptr p0,Varptr p1
+		Super.SetText(Text)
+		SendMessageW _hwnd,EM_SETSEL,p0,p1
+		_busy:-1
+	EndMethod
+	
+	Method Activate(cmd)
+		Select cmd
+			Case ACTIVATE_CUT	
+				SendMessageW _hwnd,WM_CUT,0,0
+			Case ACTIVATE_COPY	
+				SendMessageW _hwnd,WM_COPY,0,0
+			Case ACTIVATE_PASTE
+				SendMessageW _hwnd,WM_PASTE,0,0
+			Case ACTIVATE_FOCUS
+				SendMessageW _hwnd,EM_SETSEL,0,-1
+		End Select
+		Return Super.Activate(cmd)
+	EndMethod
+	
+	Method OnCommand(msg,wp:ULong)
+		If Not _busy
+			Select (wp Shr 16)
+				Case EN_UPDATE
+					PostGuiEvent EVENT_GADGETACTION
+				Case EN_KILLFOCUS
+					SendMessageW _hwnd,EM_SETSEL,0,0
+			End Select
+		EndIf
+	EndMethod
+	
+	Method WndProc:Byte Ptr(hwnd:Byte Ptr,msg:Uint,wp:Byte Ptr,lp:Byte Ptr)
+		Local event:TEvent
+		Select msg
+			Case WM_ERASEBKGND
+				Return 1
+			Case WM_KEYDOWN
+				If eventfilter<>Null
+					event=CreateEvent(EVENT_KEYDOWN,Self,Long(wp),keymods())
+					If Not eventfilter(event,context) Return True
+				EndIf
+			Case WM_CHAR
+				If eventfilter<>Null
+					event=CreateEvent(EVENT_KEYCHAR,Self,Long(wp),keymods())
+					If Not eventfilter(event,context) Return True
+				EndIf
+			Case WM_KILLFOCUS
+				PostGuiEvent EVENT_GADGETLOSTFOCUS
+		End Select
+		Return Super.WndProc(hwnd,msg,wp,lp)
+	EndMethod
+	
+	Method Class()
+		Return GADGET_TEXTFIELD
+	EndMethod
+	
+EndType
+
+Type TWindowsTextArea Extends TWindowsGadget
+	
+	Global _ClassName:String = Null	'See InitializeLibrary().
+	
+	Global _pagemargin# = 0.5		'Page margin for print-out in inches
+	
+	Field _locked
+
+	Field cr1:CHARRANGE=New CHARRANGE
+	Field cr2:CHARRANGE=New CHARRANGE
+	Field cf:CHARFORMATW=New CHARFORMATW
+
+	Field ole:IRichEditOLE
+	Field idoc:ITextDocument
+	Field busy,readonly
+	
+	Field IID_ITextDocument:GUID = New GUID
+	
+	Function _InitializeLibrary()
+		
+		If Not _ClassName Then
+			
+			'Load RichEdit DLL
+			If Not LoadLibraryW("msftedit.dll") Then
+				If LoadLibraryW("riched20.dll") _ClassName = "RichEdit20W"
+			Else
+				_ClassName = "RICHEDIT50W"
+			EndIf
+			
+		EndIf
+
+	EndFunction
+	
+	Method New()
+		_InitializeLibrary()
+	EndMethod
+	
+	Method Create:TWindowsGadget(group:TGadget,style,Text$="")	
+		Local	xstyle,wstyle,hotkey
+		Local	hwnd:Byte Ptr,parent:Byte Ptr
+		Local res
+		
+		xstyle=WS_EX_CLIENTEDGE
+		wstyle=WS_CHILD|WS_VSCROLL|WS_CLIPSIBLINGS
+		wstyle:|ES_MULTILINE|ES_NOOLEDRAGDROP|ES_NOHIDESEL|ES_LEFT
+		If Not (style&TEXTAREA_WORDWRAP) wstyle:|WS_HSCROLL|ES_AUTOHSCROLL
+'		If (style&TEXTAREA_READONLY) wstyle:|ES_READONLY						
+		If (style&TEXTAREA_READONLY) readonly=True
+		
+		Self.style = style
+		
+		parent=group.query(QUERY_HWND_CLIENT)
+		
+		'RichText control should be made have dimensions of 1x1 pixels to fix Windows XP vertical scrollbar drawing bug.
+		hwnd=CreateWindowExW(xstyle,_ClassName,"",wstyle,0,0,1,1,parent,hotkey,GetModuleHandleW(Null),Null)
+
+		SendMessageW hwnd,EM_SETLIMITTEXT,4*1024*1024,0
+		SendMessageW hwnd,EM_SETEVENTMASK,0,ENM_CHANGE|ENM_MOUSEEVENTS|ENM_SELCHANGE|ENM_KEYEVENTS		
+		SendMessageW hwnd,EM_SETUNDOLIMIT,0,0
+
+		ole = New IRichEditOLE
+
+		SendMessageW hwnd,EM_GETOLEINTERFACE,0, Varptr ole.unknownPtr
+		res=IIDFromString(ITextDocument_UUID,IID_ITextDocument)
+
+		idoc = New ITextDocument
+		res=ole.QueryInterface(IID_ITextDocument.guidPtr,Varptr idoc.unknownPtr)		
+
+		Register GADGET_TEXTAREA,hwnd
+
+		Return Self		
+	EndMethod
+	
+	Method Free()
+		If ole Then ole.Release_
+		If idoc Then idoc.Release_
+		Super.Free()
+	EndMethod
+	
+	Method Activate(cmd)
+		Select cmd
+			Case ACTIVATE_CUT	
+				SendMessageW _hwnd,WM_CUT,0,0
+			Case ACTIVATE_COPY	
+				SendMessageW _hwnd,WM_COPY,0,0
+				SetFocus _hwnd
+			Case ACTIVATE_PASTE
+				DoPaste	
+			Case ACTIVATE_PRINT
+				DoPrint
+			Default
+				Return Super.Activate(cmd)
+		End Select
+	EndMethod
+	
+	Method DoPaste()
+		Local h:Byte Ptr,handle:Byte Ptr,n
+		Local w:Short Ptr,cp:Short Ptr
+		Local tp:Byte Ptr,bp:Byte Ptr
+		
+		If OpenClipboard(_hwnd)
+			If IsClipboardFormatAvailable(CF_UNICODETEXT)
+				handle=GetClipboardData(CF_UNICODETEXT)
+				n=GlobalSize(handle)
+				w=Short Ptr GlobalLock(handle)
+				h=GlobalAlloc(GMEM_MOVEABLE,n)
+				cp=Short Ptr GlobalLock(h)
+				memcpy_(cp,w,n)
+				If cp[n/2-2]=10 Then cp[n/2-2]=13
+				GlobalUnlock h	
+				GlobalUnlock handle
+				If h
+					EmptyClipboard
+					SetClipboardData CF_UNICODETEXT,h
+				EndIf
+			ElseIf IsClipboardFormatAvailable(CF_OEMTEXT)
+				handle=GetClipboardData(CF_OEMTEXT)
+				n=GlobalSize(handle)		
+				tp=Byte Ptr GlobalLock(handle)				
+				h=GlobalAlloc(GMEM_MOVEABLE,n)
+				bp=Byte Ptr GlobalLock(h)
+				memcpy_(bp,tp,n)
+				If bp[n-2]=10 Then bp[n-2]=13
+				GlobalUnlock h
+				GlobalUnlock handle
+				If h
+					EmptyClipboard
+					SetClipboardData CF_OEMTEXT,h
+				EndIf
+			EndIf
+			CloseClipboard
+			SendMessageW _hwnd,WM_PASTE,0,0
+			SetFocus _hwnd
+		EndIf
+	EndMethod
+	
+	Method DoPrint()
+Rem
+		Local tmpTextSelLen = TextAreaSelLen(Self)
+		
+		Local tmpPrintDialog:PRINTDLGW = New PRINTDLGW
+		
+		tmpPrintDialog.flags = PD_RETURNDC | PD_HIDEPRINTTOFILE | PD_NOPAGENUMS
+		If Not tmpTextSelLen Then tmpPrintDialog.flags:|PD_NOSELECTION
+		
+		tmpPrintDialog.hwndOwner = _hwnd
+		
+		If Not PrintDlg( Byte Ptr tmpPrintDialog ) Then Return 0
+		
+		Local hdcPrinter = tmpPrintDialog.hdc	
+		
+		Local tmpDoc:DOCINFOW = New DOCINFOW
+		Local tmpDocTitle:Short Ptr = AppTitle.ToWString()
+		tmpDoc.lpszDocName = tmpDocTitle
+		
+		Local tmpSuccess = (StartDocW( hdcPrinter, Byte Ptr tmpDoc ) > 0)
+		
+		If tmpSuccess Then
+			
+			Local _cursor = TWindowsGUIDriver._cursor
+			
+			SetPointer( POINTER_WAIT )
+			
+			SetMapMode( hdcPrinter, MM_TEXT )
+			
+			Local wPage = GetDeviceCaps( hdcPrinter, PHYSICALWIDTH )
+			Local hPage = GetDeviceCaps( hdcPrinter, PHYSICALHEIGHT )
+			Local xPPI = GetDeviceCaps( hdcPrinter, LOGPIXELSX )
+			Local yPPI = GetDeviceCaps( hdcPrinter, LOGPIXELSY )
+			
+			Local tmpTextLengthStruct[] = [GTL_DEFAULT,1200]
+			Local tmpTextLength = SendMessageW (_hwnd, EM_GETTEXTLENGTHEX, Int Byte Ptr tmpTextLengthStruct, 0)
+			
+			Local tmpTextPrinted, tmpFormatRange:FORMATRANGE = New FORMATRANGE
+			
+			tmpFormatRange.hdc = hdcPrinter
+			tmpFormatRange.hdcTarget = hdcPrinter
+			
+			tmpFormatRange.rcPageRight = (wPage*1440:Long)/xPPI
+			tmpFormatRange.rcPageBottom = (hPage*1440:Long)/yPPI
+			
+			tmpFormatRange.rcLeft = (1440*_pagemargin);tmpFormatRange.rcTop = (1440*_pagemargin)
+			tmpFormatRange.rcRight = tmpFormatRange.rcPageRight - (2880*_pagemargin)
+			tmpFormatRange.rcBottom = tmpFormatRange.rcPageBottom - (2880*_pagemargin)
+			
+			If tmpPrintDialog.flags & PD_SELECTION Then
+				tmpTextPrinted = TextAreaCursor(Self)
+				tmpFormatRange.CHARRANGE_cpMax = tmpTextPrinted+tmpTextSelLen
+			Else
+				tmpFormatRange.CHARRANGE_cpMax = tmpTextLength
+			EndIf
+			
+			SendMessageW (_hwnd, EM_FORMATRANGE, False, 0)
+			
+			While tmpSuccess And ( tmpTextPrinted < tmpFormatRange.CHARRANGE_cpMax )
+				
+				tmpFormatRange.CHARRANGE_cpMin = tmpTextPrinted
+				
+				tmpSuccess = (StartPage(hdcPrinter) > 0)
+				If Not tmpSuccess Then Exit
+				
+				tmpTextPrinted = SendMessageW( _hwnd, EM_FORMATRANGE, True, Int Byte Ptr tmpFormatRange )
+				
+				tmpSuccess = (EndPage(hdcPrinter) > 0)
+				
+			Wend
+			
+			If tmpSuccess Then EndDoc( hdcPrinter ) Else AbortDoc( hdcPrinter )
+			
+			SendMessageW (_hwnd, EM_FORMATRANGE, False, 0)
+			
+			TWindowsGUIDriver._cursor = _cursor
+			SetCursor _cursor
+			
+		EndIf
+		
+		GlobalFree( tmpPrintDialog.hDevMode )
+		GlobalFree( tmpPrintDialog.hDevNames )
+		DeleteDC( hdcPrinter )
+		
+		MemFree tmpDocTitle
+		
+		Return tmpSuccess
+End Rem	
+	EndMethod
+	
+	Global gt[] = [GTL_DEFAULT, CP_ACP]
+	
+	Method CharCount()
+		Return SendMessageW(_hwnd,EM_GETTEXTLENGTHEX,Int Byte Ptr gt,0)
+	EndMethod
+	
+	Method SetStyle(r,g,b,flags,pos,length,units)
+		Local iifont:ITextFont
+		Local iirange:ITextRange
+		Local res, tmpOutput
+		If units=TEXTAREA_LINES
+			Local n=pos
+			pos=CharAt(pos)
+			If length>=0 length=CharAt(n+length)-pos
+		EndIf			
+		If length<0 length=charcount()-pos	
+		busy:+1		
+		res=idoc.Range(pos,pos+length,iirange)
+		res=iirange.GetFont(iifont)
+		res=iifont.SetForeColor(((b Shl 16)|(g Shl 8)|r))
+		If (flags&TEXTFORMAT_BOLD) Then iifont.SetBold(TOMTRUE) Else iifont.SetBold(TOMFALSE)
+		If (flags&TEXTFORMAT_ITALIC) Then iifont.SetItalic(TOMTRUE) Else iifont.SetItalic(TOMFALSE)
+		If (flags&TEXTFORMAT_UNDERLINE) Then iifont.SetUnderline(TOMSINGLE) Else iifont.SetUnderline(TOMFALSE)
+		If (flags&TEXTFORMAT_STRIKETHROUGH) Then iifont.SetStrikeThrough(TOMTRUE) Else iifont.SetStrikeThrough(TOMNONE)
+		iifont.Release_
+		iirange.Release_
+		busy:-1
+	EndMethod	
+		
+	Method InsertText(Text$,pos,count)
+		Local iirange:ITextRange
+		Local bstr:Short Ptr, tmpWString:Short Ptr = Text.toWString()
+		Local res, bool
+		busy:+1
+		res=idoc.Range(pos,pos+count,iirange)		
+		bstr=SysAllocStringLen(tmpWString,Text.length);MemFree tmpWString
+		LockText()
+		res=iirange.SetText(bstr)
+		UnlockText()
+		SysFreeString bstr
+		iirange.Release_
+		busy:-1
+	EndMethod
+	
+	Method ReplaceText(pos,length,Text$,units)
+		If units=TEXTAREA_LINES
+			Local n=pos
+			pos=CharAt(pos)
+			If length>=0 length=CharAt(n+length)-pos
+		EndIf			
+		If length<0 Then length=charcount()-pos	
+		InsertText Text,pos,length
+	EndMethod
+
+	Method AreaText$(pos,length,units)
+		Local iirange:ITextRange
+		Local bstr:Short Ptr
+
+		If units=TEXTAREA_LINES
+			Local n=pos
+			pos=CharAt(pos)
+			If length>=0 length=CharAt(n+length)-pos
+		EndIf			
+		If length<0 length=charcount()-pos	
+		idoc.Range(pos,pos+length,iirange)		
+		iirange.GetText(Varptr bstr)
+		Local Text$=String.FromWString(bstr)
+		SysFreeString bstr
+		iirange.Release_
+		Text=Text.Replace(Chr(13),Chr(10))
+		Return Text
+	EndMethod
+	
+	Method SetSelection(pos,length,units)
+		If units=TEXTAREA_LINES
+			Local n=pos
+			pos=CharAt(pos)
+			If length>0
+				length=CharAt(n+length)
+				length=length-pos
+			EndIf
+		EndIf			
+		If length<0 length=charcount()-pos	
+		'Local cr:CHARRANGE = New CHARRANGE
+		cr1.SetcpMin(pos)
+		cr1.SetcpMax(pos+length)
+		Desensitize()
+		SendMessageW _hwnd,EM_EXSETSEL,0,cr1.rangePtr
+		Sensitize()
+	EndMethod
+
+	Method SetMargins(leftmargin)
+		SendMessageW _hwnd,EM_SETMARGINS,EC_LEFTMARGIN,leftmargin
+	EndMethod
+	
+	' 72 points per inch
+	
+	Method SetTabs(tabs)
+		Local hdc:Byte Ptr=GetDC( 0 )
+		idoc.SetDefaultTabStop tabs * 72.0 / GetDeviceCaps( hdc,LOGPIXELSX )
+		ReleaseDC 0,hdc
+	EndMethod
+
+	Method SetTextColor(r,g,b)
+		'cf.cbSize=SizeOf(CHARFORMATW)				
+		cf.SetdwMask(CFM_COLOR|CFM_BOLD|CFM_ITALIC)
+		cf.SetcrTextColor((b Shl 16)|(g Shl 8)|r)
+		SendMessageW _hwnd,EM_SETCHARFORMAT,SCF_DEFAULT,cf.formatPtr
+		SendMessageW _hwnd,EM_SETCHARFORMAT,SCF_ALL,cf.formatPtr
+	EndMethod
+
+	Method SetColor(r,g,b)
+		SendMessageW _hwnd,EM_SETBKGNDCOLOR,0,((b Shl 16)|(g Shl 8)|r)
+	EndMethod
+
+	Method RemoveColor()
+		SendMessageW _hwnd,EM_SETBKGNDCOLOR,1,0
+	EndMethod
+	
+	Method GetCursorPos(units)
+		'Local cr:CHARRANGE = New CHARRANGE
+		SendMessageW _hwnd,EM_EXGETSEL,0,cr1.rangePtr
+		Local pos=cr1.cpMin()
+		If units=TEXTAREA_LINES pos=LineAt(pos)
+		Return pos
+	EndMethod	
+	
+	Method GetSelectionLength(units)
+		'Local cr:CHARRANGE = New CHARRANGE
+		SendMessageW _hwnd,EM_EXGETSEL,0,cr1.rangePtr
+		If units=TEXTAREA_LINES
+			Return LineAt(cr1.cpMax()-1)-LineAt(cr1.cpMin())+1
+		Else
+			Return cr1.cpMax()-cr1.cpMin()
+		EndIf
+	EndMethod
+
+	Method CharAt(Line)
+		If Line<0 Return
+		If Line>AreaLen(TEXTAREA_LINES) Return charcount()
+		Return SendMessageW(_hwnd,EM_LINEINDEX,Line,0)
+	EndMethod
+
+	Method LineAt(pos)
+		If pos<0 Return
+		If pos>charcount() Return AreaLen(TEXTAREA_LINES)
+		Return SendMessageW(_hwnd,EM_EXLINEFROMCHAR,0,pos)
+	EndMethod
+
+	Method AreaLen(units)
+		If units=TEXTAREA_LINES Return LineAt(charcount())
+		Return charcount()
+	EndMethod
+	
+	Method CharX( char )
+		Local tmpPoint[2]
+		SendMessageW(_hwnd, EM_POSFROMCHAR, tmpPoint, char )
+		Return tmpPoint[0]
+	EndMethod
+	
+	Method CharY( char )
+		Local tmpPoint[2]
+		SendMessageW(_hwnd, EM_POSFROMCHAR, tmpPoint, char )
+		Return tmpPoint[1]
+	EndMethod
+	
+	Method SetText(Text$)
+		InsertText Text,0,charcount()
+	EndMethod
+
+	Method AddText(Text$)
+		InsertText Text,charcount(),0
+		'Local cr:CHARRANGE = New CHARRANGE
+		Local p = charcount()
+		cr1.SetcpMin(p)
+		cr1.SetcpMax(p)
+		SendMessageW _hwnd,EM_EXSETSEL,0,cr1.rangePtr
+	EndMethod
+	
+	Method GetText$()
+		Return AreaText(0,charcount(),TEXTAREA_CHARS)
+	EndMethod
+	
+	Global _oldCursor:Byte Ptr = 0
+	Field _oldSelPos%, _oldSelLen% = 0
+	
+	Method LockText()
+		
+		If Not idoc.Freeze(_locked)
+			_oldSelPos = GetCursorPos(TEXTAREA_CHARS)
+			_oldSelLen = GetSelectionLength(TEXTAREA_CHARS)
+			If Not _oldCursor Then _oldCursor = GetCursor()
+		EndIf
+		
+	EndMethod
+	
+	Method UnlockText()
+		
+		If idoc.Unfreeze(_locked) = S_OK Then
+			SetSelection( _oldSelPos, _oldSelLen, TEXTAREA_CHARS )
+			If _oldCursor And (_oldCursor <> GetCursor()) Then
+				SetCursor(_oldCursor)
+			EndIf
+			_oldCursor = 0
+		EndIf
+		
+	EndMethod
+
+	Method OnCommand(msg,wp:ULong)
+		If busy Then Return
+		Select wp Shr 16
+			Case EN_CHANGE
+				If Not _locked Then PostGuiEvent EVENT_GADGETACTION
+		End Select
+	EndMethod
+
+	Method OnNotify(wp:Byte Ptr,lp:Byte Ptr)
+		Local nmhdrPtr:Byte Ptr
+		Local event:TEvent
+		
+		Super.OnNotify(wp,lp)	'Tooltip
+		
+		nmhdrPtr=lp
+		Select bmx_win32_NMHDR_code(nmhdrPtr)
+'			Case EN_PROTECTED
+'				DebugStop
+			Case EN_SELCHANGE
+				If Not (busy Or _locked)
+					PostGuiEvent EVENT_GADGETSELECT
+				EndIf
+			Case EN_MSGFILTER
+				Select bmx_win32_MSGFILTER_msg(nmhdrPtr)
+					Case WM_RBUTTONDOWN
+						If GetSelectionLength(TEXTAREA_CHARS)=0 Then
+							bmx_win32_MSGFILTER_Setmsg(nmhdrPtr, WM_LBUTTONDOWN)
+						End If
+					Case WM_RBUTTONUP
+						Local mx=Long(bmx_win32_MSGFILTER_lParam(nmhdrPtr)) & $ffff
+						Local my=Long(bmx_win32_MSGFILTER_lParam(nmhdrPtr)) Shr 16
+						PostGuiEvent EVENT_GADGETMENU,0,0,mx,my
+					Case WM_KEYDOWN
+						
+						Local k=Int(bmx_win32_MSGFILTER_wParam(nmhdrPtr))
+						
+						'Filtering out special shortcut combinations
+						If (keymods()&MODIFIER_CONTROL) Then
+							Select k
+								Case 76,69,82	'ctrl+l, ctrl+e, ctrl+r
+									Return 1	'Alignment shortcuts
+									
+								Case 188,190	'ctrl+<, ctrl+>
+											'Font size shortcuts
+									If (keymods()&MODIFIER_SHIFT) Then Return 1
+							EndSelect
+						EndIf
+						
+						'Read-only
+						If readonly
+							If k>=33 And k<=40 Return 0 'selection keys
+							If (keymods()&MODIFIER_CONTROL) Then
+								Select k
+									Case 65, 67;Return 0 'ctrl-a, ctrl+c
+								EndSelect
+							EndIf
+							Return 1						
+						EndIf
+						
+						'Event Filter
+						If eventfilter<>Null
+							event=CreateEvent(EVENT_KEYDOWN,Self,k,keymods())
+							Return Not eventfilter(event,context)
+						EndIf
+						
+					Case WM_CHAR
+						If readonly Return 1
+						If eventfilter<>Null
+							event=CreateEvent(EVENT_KEYCHAR,Self,Int(bmx_win32_MSGFILTER_wParam(nmhdrPtr)),keymods())
+							Return Not eventfilter(event,context)
+						EndIf
+				End Select
+		End Select
+	EndMethod
+
+	Method WndProc:Byte Ptr(hwnd:Byte Ptr,msg:UInt,wp:Byte Ptr,lp:Byte Ptr)
+		Select msg
+			
+			Case WM_MOUSEWHEEL
+				If (Long(wp)&MK_CONTROL) Then SendMessageW _hwnd, EM_SETZOOM, 0, 0
+				
+			Case WM_KILLFOCUS
+				PostGuiEvent EVENT_GADGETLOSTFOCUS
+			
+		End Select
+		
+		Return Super.WndProc(hwnd,msg,wp,lp)
+		
+	EndMethod
+	
+	Method Class()
+		Return GADGET_TEXTAREA
+	EndMethod
+		
+EndType
+
+Type TWindowsLabel Extends TWindowsGadget
+	
+	Method Create:TWindowsGadget(group:TGadget,style,Text$="")	
+		Local	xstyle,wstyle,hotkey
+		Local	hwnd:Byte Ptr,parent:Byte Ptr
+		
+		Self.style = style
+		wstyle=WS_CHILD|SS_NOPREFIX|WS_CLIPSIBLINGS|SS_NOTIFY
+		
+		Select style&24
+			Case LABEL_LEFT wstyle:|SS_LEFT
+			Case LABEL_RIGHT wstyle:|SS_RIGHT
+			Case LABEL_CENTER wstyle:|SS_CENTER
+		End Select
+		Select style&7
+			Case LABEL_FRAME wstyle:|WS_BORDER
+			Case LABEL_SUNKENFRAME wstyle:|SS_SUNKEN
+			Case LABEL_SEPARATOR wstyle:|SS_SUNKEN|SS_GRAYRECT
+		End Select
+		
+		parent=group.query(QUERY_HWND_CLIENT)
+		hwnd=CreateWindowExW(xstyle,"STATIC","",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
+		Register GADGET_LABEL,hwnd
+		
+		Return Self
+	EndMethod
+	
+	Method SetArea(x,y,w,h)
+		If ((style & 7) = LABEL_SEPARATOR) Then
+			If (w > h) Then h = 2 Else w = 2
+		EndIf
+		Return Super.SetArea(x,y,w,h)
+	EndMethod
+	
+	Method SetText(Text$)
+		If ((style & 7) <> LABEL_SEPARATOR) Then Return Super.SetText(Text)
+	EndMethod
+	
+	Method WndProc:Byte Ptr(hwnd:Byte Ptr,msg:Uint,wp:Byte Ptr,lp:Byte Ptr)
+		Select msg
+			Case WM_ERASEBKGND
+				Return 1
+		EndSelect
+		Return Super.WndProc(hwnd,msg,wp,lp)
+	EndMethod
+	
+	Method Class()
+		Return GADGET_LABEL
+	EndMethod
+					
+EndType
+
+Type TWindowsTreeNode Extends TGadget
+	Field	_parent:TWindowsTreeNode
+	Field	_tree:Byte Ptr		'HWND
+	Field	_item:Byte Ptr		'HTREEITEM
+	Field	_expanded
+	Field	_icon
+	Field _handle:Byte Ptr
+	Field _tv:TVITEMW
+	
+	Method Activate(cmd)
+		Local tmpTree:TWindowsTreeView = TWindowsTreeView(TWindowsGUIDriver.GadgetFromHwnd(_tree))
+		If tmpTree Then tmpTree.Desensitize()
+		Select cmd
+			Case ACTIVATE_SELECT
+				If _item <> TVI_ROOT Then
+					SendMessageW _tree,TVM_SELECTITEM,TVGN_CARET,_item
+				Else
+					SendMessageW _tree,TVM_SELECTITEM,TVGN_CARET,0
+				EndIf
+			Case ACTIVATE_EXPAND
+				SendMessageW _tree,TVM_EXPAND,TVE_EXPAND,_item
+				_expanded=True
+			Case ACTIVATE_COLLAPSE
+				SendMessageW _tree,TVM_EXPAND,TVE_COLLAPSE,_item
+				_expanded=False
+			Case ACTIVATE_REDRAW
+				RedrawNode()
+		End Select
+		If tmpTree Then tmpTree.Sensitize()
+	EndMethod
+	
+	Method CreateRoot:TWindowsTreeNode(owner:TWindowsTreeView)
+		_tree=owner._hwnd
+		_item=TVI_ROOT		
+		Return Self
+	EndMethod
+
+	Method CountKids()
+		Return kids.count()
+	EndMethod
+
+	Method Create:TWindowsTreeNode(group:TGadget,style,Text$="",index=-1,icon = -1)
+		_parent=TWindowsTreeNode(group)
+		If Not _parent Throw "Parent isn't a treeview node. Use TreeViewRoot() when creating a root node."
+		Self.style = style
+		_tree=_parent._tree
+		_icon = icon
+		Spawn(Text,index)
+		_SetParent group,index
+		If (LocalizationMode()&LOCALIZATION_OVERRIDE) Then
+			LocalizeGadget(Self, Text, "")
+		EndIf
+		Return Self
+	EndMethod
+
+	Method GetText$()
+		If Not _tv Then
+			_tv = New TVITEMW
+		End If
+		'Local item[10]
+		Local buffer:Short[260]
+		_tv.Setmask(TVIF_TEXT)
+		_tv.SethItem(_item)
+		_tv.SetpszText(buffer)
+		_tv.SetcchTextMax(256)
+		'item[0]=TVIF_TEXT
+		'item[1]=_item
+		'item[4]=Int Byte Ptr buffer
+		'item[5]=256
+		SendMessageW _tree,TVM_GETITEMW,0,_tv.itemPtr
+		Return String.FromWString(buffer)
+	EndMethod
+	
+	Method SetText(Text$)
+		If Not _tv Then
+			_tv = New TVITEMW
+		End If
+		_tv.Setmask(TVIF_HANDLE|TVIF_TEXT)
+		_tv.SethItem(_item)
+		If _icon > -1 Then
+			_tv.Setmask(_tv.mask()|TVIF_IMAGE|TVIF_SELECTEDIMAGE)
+			_tv.SetiImage(_icon)
+			_tv.SetiSelectedImage(_tv.iImage())
+		EndIf
+		_tv.SetpszText(Text.ToWString())
+		SendMessageW(_tree,TVM_SETITEMW,0,_tv.itemPtr)
+		MemFree _tv.pszText()
+	EndMethod
+	
+	Method DoLayout()
+		'Don't do anything!
+	EndMethod
+	
+	Method Free()
+		'If we don't have a parent then the node must have previously been freed.
+		If Not _parent Then Return
+		'Avoid firing events when freeing a treenode that is selected.
+		If SendMessageW(_tree,TVM_GETNEXTITEM,TVGN_CARET,0) Then DeSelect()
+		'Free treenode
+		If _item Then SendMessageW(_tree,TVM_DELETEITEM,0,_item);_item=0
+		'Redraw parent if we were its last child node
+		If Not SendMessageW(_tree, TVM_GETNEXTITEM, TVGN_CHILD, _parent._item) Then _parent.RedrawNode()
+		'Cleanup variables that could be circular references
+		_parent = Null;_tree = 0;_SetParent Null
+		'Release any handle we created using HandleFromObject() in Spawn()
+		If _handle Then Release _handle
+	EndMethod
+	
+	Method DeSelect()
+		SendMessageW _tree,TVM_SELECTITEM,TVGN_CARET,0
+	EndMethod
+	
+	Method InsertNode:TGadget(index,Text$,icon)
+		Return New TWindowsTreeNode.Create(Self,0,Text,index,icon)
+	EndMethod
+
+	Method ModifyNode(Text$,icon)
+		_icon = icon
+		SetText Text
+	EndMethod
+		
+	Method tviatindex:Byte Ptr(index)
+		If kids.IsEmpty() Then Return TVI_FIRST
+		If index<0 Or index>=kids.count() Return TVI_LAST		
+		Local child:TWindowsTreeNode
+		child=TWindowsTreeNode(kids.valueatindex(index))
+		Return child._item
+	EndMethod
+	
+	Method Spawn:Byte Ptr(name$,index=-1)
+		
+		Local it:TVINSERTSTRUCTW = New TVINSERTSTRUCTW
+		Local hitem				
+		it.SethParent(_parent._item)
+		If index = 0 Then
+			it.SethInsertAfter(TVI_FIRST)
+		Else
+			it.SethInsertAfter(_parent.tviatindex(index-1))
+		EndIf
+		it.Setitem_mask(TVIF_TEXT|TVIF_PARAM)
+		
+		If _icon > -1 Then
+			it.Setitem_mask(it.item_mask()|TVIF_IMAGE|TVIF_SELECTEDIMAGE)
+			it.Setitem_iImage(_icon)
+			it.Setitem_iSelectedImage(it.item_iImage())
+		EndIf
+		
+		Local tmpParentHadKids = SendMessageW(_tree, TVM_GETNEXTITEM, TVGN_CHILD, _parent._item)
+		
+		it.Setitem_pszText(name.ToWString())
+		it.Setitem_lparam(HandleFromObject(Self)) ' FIXME
+		
+		'Make sure that we store handle so we can release it later.
+		If _handle Then Release _handle
+		_handle = it.item_lparam()
+		
+		_item=SendMessageW(_tree,TVM_INSERTITEMW,0,it.structPtr)
+		
+		MemFree it.item_pszText()
+		
+		'Fix for tree-view parent status update problem.
+		If Not tmpParentHadKids Then _parent.RedrawNode()
+		
+		Return _item
+		
+	EndMethod
+	
+	Method RedrawNode()
+
+		If _item = TVI_ROOT Then
+			InvalidateRect _tree, Null, True
+		Else
+			Local Rect[] = [_item,0,0,0]
+			If SendMessageW(_tree, TVM_GETITEMRECT, False, Int Byte Ptr Rect) Then
+				InvalidateRect _tree, Rect, True
+			EndIf
+		EndIf
+
+	EndMethod
+	
+	Method SetTooltip( pTooltip$ )
+		'At the moment, nodes don't support tooltips.
+	EndMethod
+	
+	Method Class()
+		Return GADGET_NODE
+	EndMethod
+	
+EndType
+
+Type TWindowsTreeView Extends TWindowsGadget
+
+	Field	_root:TWindowsTreeNode
+	Field	_selected:TWindowsTreeNode
+	Field	_icons:TWindowsIconStrip
+
+	Method Create:TWindowsGadget(group:TGadget,style,Text$="")
+		Local	xstyle,wstyle,hotkey
+		Local	hwnd:Byte Ptr,parent:Byte Ptr
+		
+		Self.style = style
+		xstyle=WS_EX_CLIENTEDGE
+		wstyle=WS_CHILD|TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT|TVS_SHOWSELALWAYS|TVS_NOTOOLTIPS|WS_CLIPSIBLINGS
+		If Not(style&TREEVIEW_DRAGNDROP) wstyle:|TVS_DISABLEDRAGDROP
+		
+		parent=group.query(QUERY_HWND_CLIENT)
+		hwnd=CreateWindowExW(xstyle,"SysTreeView32","",wstyle,0,0,0,0,parent,hotkey,GetModuleHandleW(Null),Null)
+		If TWindowsGUIDriver.CheckCommonControlVersion() Then SendMessageW hwnd, TVM_SETEXTENDEDSTYLE, TVS_EX_DOUBLEBUFFER, TVS_EX_DOUBLEBUFFER
+		Register GADGET_TREEVIEW,hwnd			
+		_root=New TWindowsTreeNode.CreateRoot(Self)	
+		
+		If TWindowsGUIDriver._explorerstyle Then UseExplorerTheme()
+		
+		Return Self
+		
+	EndMethod
+
+	Method SetIconStrip(iconstrip:TIconStrip)	
+		_icons=TWindowsIconStrip(iconstrip)
+		SendMessageW _hwnd,TVM_SETIMAGELIST,TVSIL_NORMAL,_icons._imagelist
+	EndMethod
+
+	Method SetColor(r,g,b)
+		SendMessageW _hwnd,TVM_SETBKCOLOR,0,(b Shl 16)|(g Shl 8)|r
+	EndMethod
+
+	Method RemoveColor()
+		SendMessageW _hwnd,TVM_SETBKCOLOR,1,0
+	EndMethod
+
+	Method SetTextColor(r,g,b)
+		SendMessageW _hwnd,TVM_SETTEXTCOLOR,0,(b Shl 16)|(g Shl 8)|r
+	EndMethod
+
+	Method RootNode:TGadget()
+		Return _root
+	EndMethod
+
+	Method SelectedNode:TGadget()
+		Return _selected
+	EndMethod
+
+	Method CountKids()
+		Return _root.CountKids()
+	EndMethod
+	
+	Method OnNotify(wp:Byte Ptr,lp:Byte Ptr)
+		Local nmhdrPtr:Byte Ptr
+		Local itemnew:Byte Ptr
+		Local node:TWindowsTreeNode
+
+		Super.OnNotify(wp,lp)	'Tool-tips
+		
+		nmhdrPtr=lp
+		Select bmx_win32_NMHDR_code(nmhdrPtr)
+			
+			'MSLU glitch requires handling of ANSI equivalent
+			Case TVN_SELCHANGEDW, TVN_SELCHANGEDA
+				itemnew=bmx_win32_NMTREEVIEW_itemNew(nmhdrPtr)
+				'itemnew=nmhdr+14		'Int Ptr(nmhdr[5])	'itemNew
+				If bmx_win32_TVITEMW_hItem(itemnew)=TVI_ROOT	'hItem
+					_selected=_root
+				Else
+					_selected=TWindowsTreeNode(HandleToObject(size_t(bmx_win32_TVITEMW_lParam(itemnew))))	'lParaM
+				EndIf
+				PostGuiEvent EVENT_GADGETSELECT,0,0,0,0,_selected
+				
+			Case TVN_ITEMEXPANDEDW, TVN_ITEMEXPANDEDA
+				itemnew=bmx_win32_NMTREEVIEW_itemNew(nmhdrPtr)
+				'itemnew=nmhdr+14		'Int Ptr(nmhdr[5])	'itemNew.TVITEM
+				If bmx_win32_TVITEMW_hItem(itemnew)=TVI_ROOT		'hItem
+					node=_root
+				Else
+					node=TWindowsTreeNode(HandleToObject(size_t(bmx_win32_TVITEMW_lParam(itemnew))))	'lParaM
+				EndIf
+				Select bmx_win32_NMTREEVIEW_action(nmhdrPtr)'nmhdr[3]	'action itemnew[2]&TVIS_EXPANDED	'state
+					Case 1
+						PostGuiEvent EVENT_GADGETCLOSE,0,0,0,0,node
+						node._expanded=False
+					Case 2
+						PostGuiEvent EVENT_GADGETOPEN,0,0,0,0,node
+						node._expanded=True
+				End Select
+				Return True
+				
+			Case TVN_BEGINDRAGW, TVN_BEGINRDRAGW, TVN_BEGINDRAGA, TVN_BEGINRDRAGA
+				
+				If (style&TREEVIEW_DRAGNDROP) Then
+					
+					Local data% = 1
+					If (bmx_win32_NMHDR_code(nmhdrPtr) = TVN_BEGINRDRAGW) Or (bmx_win32_NMHDR_code(nmhdrPtr) = TVN_BEGINRDRAGA) Then data = 2
+					
+					'itemnew=nmhdr+14		'Int Ptr(nmhdr[5])	'itemNew
+					itemnew=bmx_win32_NMTREEVIEW_itemNew(nmhdrPtr)
+					
+					If bmx_win32_TVITEMW_hItem(itemnew)<>TVI_ROOT Then
+						TGadget.dragGadget[data-1]=TWindowsTreeNode(HandleToObject(size_t(bmx_win32_TVITEMW_lParam(itemnew))))
+						PostGuiEvent EVENT_GADGETDRAG, data, KeyMods(), bmx_win32_NMTREEVIEW_x(nmhdrPtr), bmx_win32_NMTREEVIEW_y(nmhdrPtr), TGadget.dragGadget[data-1]
+					Else
+						TGadget.dragGadget[data-1]=Null
+					EndIf
+					
+				EndIf
+				
+			Case NM_DBLCLK, NM_RETURN
+				PostGuiEvent EVENT_GADGETACTION,0,0,0,0,_selected
+				
+			Case NM_RCLICK
+				Local Rect[4]
+				Local pt[2]
+				'Local hittest[4]
+				'Local item[10]
+				Local hittest:TVHITTESTINFO = New TVHITTESTINFO
+				GetWindowRect _hwnd,Rect
+				GetCursorPos_ pt
+				hittest.Setx(pt[0]-Rect[0])
+				hittest.Sety(pt[1]-Rect[1])
+				If SendMessageW(_hwnd,TVM_HITTEST,0,hittest.infoPtr)
+					If hittest.flags()=TVI_ROOT
+						node=_root
+					Else
+						Local item:TVITEMW = New TVITEMW
+						item.Setmask(TVIF_PARAM)
+						item.SethItem(hittest.hItem())
+						SendMessageW _hwnd,TVM_GETITEMW,0,item.itemPtr
+						node=TWindowsTreeNode(HandleToObject(size_t(item.lParam())))
+					EndIf
+					PostGuiEvent EVENT_GADGETMENU,0,0,hittest.x(),hittest.y(),node
+				EndIf
+				Return True
+				
+		EndSelect
+	EndMethod
+
+	Method WndProc:Byte Ptr(hwnd:Byte Ptr,msg:UInt,wp:Byte Ptr,lp:Byte Ptr)
+		Select msg
+			'If we are using Vista's common controls, then the treeview will be double-buffered and so
+			'we don't need to clear the background when redrawing (performance tweak).
+			Case WM_ERASEBKGND
+				If TWindowsGUIDriver.CheckCommonControlVersion() >= 2 Then Return 1
+		EndSelect
+		Return Super.WndProc(hwnd,msg,wp,lp)
+	EndMethod
+
+	Method UseExplorerTheme()
+	
+		If TWindowsGUIDriver.CheckCommonControlVersion() Then
+			SetWindowTheme( _hwnd, _wstrExplorer, Null )
+			SendMessageW _hwnd, TVM_SETEXTENDEDSTYLE, TVS_EX_FADEINOUTEXPANDOS, TVS_EX_FADEINOUTEXPANDOS
+		EndIf
+	
+	EndMethod
+	
+	Method Class()
+		Return GADGET_TREEVIEW
+	EndMethod
+
+EndType
+
+Type TWindowsHTMLView Extends TWindowsGadget
+
+	Field mshtml:Byte Ptr
+	Field browser:IWebBrowser2 = New IWebBrowser2
+
+	Field IID_IHTMLDocument2:GUID=New GUID
+	
+	Method Create:TWindowsGadget(group:TGadget,style,Text$="")	
+		Self.style = style
+		Local parent:Byte Ptr=group.query(QUERY_HWND_CLIENT)
+		mshtml=msHtmlCreate(Self,TWindowsGUIDriver.ClassName(),parent,style)	
+		browser.unknownPtr=msHTMLBrowser(mshtml)
+		Register GADGET_HTMLVIEW,msHtmlHwnd(mshtml)
+		
+		Local res = IIDFromString(IHTMLDocument2_UUID,IID_IHTMLDocument2)		
+		
+		Return Self
+	EndMethod
+	
+	Method Rethink()
+		msHtmlSetShape mshtml,xpos,ypos,width,height
+	EndMethod	
+
+	Method SetText(Text$)	'sets document url
+		If Text Then msHtmlGo mshtml,Text
+	EndMethod
+	
+	Method GetText$()
+		Local bstr:Short Ptr
+		browser.lfget_LocationURL(Varptr bstr)
+		Local result$ = String.FromWString(bstr)
+		SysFreeString(bstr)
+		Return result
+	EndMethod
+	
+	Method GetTitleText$()	'returns document title
+		
+		Local bstr:Short Ptr
+		Local res
+		
+		Local disp:IDispatch = New IDispatch
+		Local doc:IHTMLDOCUMENT2 = New IHTMLDOCUMENT2
+		
+		res=browser.lfget_Document(Varptr disp.unknownPtr)
+		If res RuntimeError "no document"		
+		
+		res=disp.QueryInterface(IID_IHTMLDocument2,Varptr doc.unknownPtr)
+		If res RuntimeError "no document2 interface"
+		
+		If doc
+			doc.get_Title(Varptr bstr)
+		Else	
+			browser.lfget_LocationName(Varptr bstr)
+		EndIf
+		
+		Local result$ = String.FromWString(bstr)
+		SysFreeString(bstr)
+		Return result
+		
+	End Method
+
+	Method Activate(cmd)
+		Return msHtmlActivate(mshtml,cmd)
+	EndMethod
+	
+	Method State()
+		Return msHtmlStatus(mshtml)
+	EndMethod
+	
+	Method Run$(script$)
+		msHtmlRun(mshtml,script)
+	EndMethod
+
+	Method WndProc:Byte Ptr(hwnd:Byte Ptr,msg:UInt,wp:Byte Ptr,lp:Byte Ptr)
+		Select msg
+			'Reduces flicker on HTMLViews
+			Case WM_ERASEBKGND
+				Return 1
+		EndSelect
+		Return Super.WndProc(hwnd,msg,wp,lp)
+	EndMethod
+	
+	Method Class()
+		Return GADGET_HTMLVIEW
+	EndMethod
+	
+EndType
+
+'A collection of functions that convert between Blitz pixmaps and Windows icons/bitmaps.
+Type TWindowsGraphic Final
+	
+	Function BitmapMaskFromPixmap:Byte Ptr(pix:TPixmap)
+		
+		Local x, pix2:TPixmap, usealpha
+		
+		If PixmapFormat(pix) = PF_RGBA8888 Or PixmapFormat(pix) = PF_BGRA8888 Then usealpha = True
+		
+		pix2=ConvertPixmap(pix,PF_BGR888);ClearPixels(pix2)
+		
+		For Local y:Int = 0 Until pix.height
+			For x = 0 Until pix.width
+				If usealpha
+					If (ReadPixel(pix,x,y) Shr 24) < 128 Then WritePixel(pix2,x,y,$FFFFFF)
+				Else
+					If (ReadPixel(pix,x,y) & $FFFFFF) = $FFFFFF Then WritePixel(pix2,x,y,$FFFFFF)
+				EndIf
+			Next
+		Next
+	
+		Return BitmapFromPixmap(pix2,False)
+		
+	EndFunction
+	
+	Function PreMultipliedBitmapFromPixmap32:Int( pix:TPixmap )
+Rem		
+		Local argb, a
+		Local pix2:TPixmap = CreatePixmap( pix.width, pix.height, pix.format), x
+		
+		For Local y:Int = 0 Until pix.height
+			For x = 0 Until pix.width
+				argb = ReadPixel(pix,x,y)
+				a = ((argb Shr 24) & $FF)
+				WritePixel(pix2,x,y,((((argb&$ff00ff)*a)Shr 8)&$ff00ff)|((((argb&$ff00)*a)Shr 8)&$ff00)|(a Shl 24))
+			Next
+		Next
+		
+		Return BitmapFromPixmap(pix2,True)
+End Rem	
+	EndFunction
+	
+	Function BitmapFromPixmap:Byte Ptr(pix:TPixmap, alpha:Int = True)
+Rem	
+		Local bitCount:Int = 32, format:Int = PF_BGRA8888, bm:Byte Ptr
+		
+		If Not alpha Then
+			bitCount = 24
+			format = PF_BGR888
+		EndIf
+		
+		pix=ConvertPixmap(pix,format)
+	
+		Local hdc:Byte Ptr = GetDC(0)
+		
+		Local bi:BITMAPINFOHEADER = New BITMAPINFOHEADER	
+		bi.biSize=SizeOf(bi)
+		bi.biWidth=pix.width
+		bi.biHeight=-pix.height
+		bi.biPlanes=1
+		bi.biBitCount=bitCount
+		bi.biCompression=BI_RGB
+	
+		Local bits:Byte Ptr
+		Local src:Byte Ptr = pix.pixels
+		
+		If alpha
+			bm = CreateDibSection(hdc,bi,DIB_RGB_COLORS,Varptr bits,0,0)
+		Else
+			bm = CreateCompatibleBitmap(hdc,pix.width,pix.height)
+		EndIf
+		
+		Assert bm, "Cannot create bitmap.  The computer may be running low on resources."
+		
+		For Local y:Int = 0 Until pix.height
+			SetDIBits(hdc,bm,pix.height-y-1,1,src,bi,DIB_RGB_COLORS)
+			src:+pix.pitch
+		Next
+		
+		ReleaseDC(0,hdc)
+		
+		Return bm
+End Rem
+	EndFunction
+	
+	Function BitmapWithBackgroundFromPixmap32:Int( pix:TPixmap, pRed, pGreen, pBlue )
+Rem
+		Local tmpPixel, tmpRed, tmpGreen, tmpBlue, tmpAlpha, tmpAlphaFloat#, tmpAlphaFloat2#
+		Local pix2:TPixmap = CreatePixmap( pix.width, pix.height, pix.format), x
+		
+		For Local y:Int = 0 Until pix.height
+			For x = 0 Until pix.width
+				
+				'Read pixel and alpha info
+				tmpPixel = ReadPixel(pix,x,y)
+				tmpAlpha = ((tmpPixel Shr 24) & $FF)
+				tmpAlphaFloat = tmpAlpha/255.0
+				tmpAlphaFloat2 = 1-tmpAlphaFloat
+				
+				'Get individual colours
+				tmpBlue = tmpPixel & $FF;tmpGreen = (tmpPixel Shr 8) & $FF;tmpRed = (tmpPixel Shr 16)&$FF
+				
+				'Courtesy of Mark T
+				tmpRed = (tmpRed * tmpAlphaFloat) + (tmpAlphaFloat2 * pRed)
+				tmpGreen = (tmpGreen * tmpAlphaFloat) + (tmpAlphaFloat2  * pGreen)
+				tmpBlue = (tmpBlue * tmpAlphaFloat) + (tmpAlphaFloat2  * pBlue)
+				
+				'Write the new pixels
+				WritePixel(pix2,x,y,(tmpAlpha Shl 24)|(tmpRed Shl 16)|(tmpGreen Shl 8)|tmpBlue)
+			Next
+		Next
+		
+		Return BitmapFromPixmap(pix2,False)
+End Rem
+	EndFunction
+
+	Function IconFromPixmap32:Byte Ptr(pix:TPixmap)
+
+		' Convert the pixmap to a HBITMAP
+		Local bitmap:Byte Ptr = BitmapFromPixmap(pix,True)
+		
+		' and then copy/resize it (to the default size for icons/cusors).
+		Local hSrcBMP:Byte Ptr = CopyImage(bitmap, IMAGE_BITMAP , 0 , 0 , LR_DEFAULTSIZE)
+		
+		' Now we need to create a mask bitmap for the image
+		Local hMaskBMP:Byte Ptr = BitmapMaskFromPixmap( pix )
+		
+		' So now we have our source and mask bitmaps, we can create an ICONINFO structure
+		Local IconInf:ICONINFO = New ICONINFO
+		IconInf.SetfIcon(True)
+		IconInf.SethbmMask(hMaskBMP)
+		IconInf.SethbmColor(hSrcBMP)
+		
+		' Create the icon
+		Local tmpIcon:Byte Ptr = CreateIconIndirect(IconInf)
+		
+		' Free our temporary bitmaps
+		DeleteObject(hMaskBMP)
+		DeleteObject(hSrcBMP)
+		DeleteObject(bitmap)
+		
+		Return tmpIcon
+
+	EndFunction
+
+EndType
+
+Private
+
+Function KeyMods()
+	Local mods
+	If GetKeyState(VK_SHIFT)&$8000 mods:|MODIFIER_SHIFT
+	If GetKeyState(VK_CONTROL)&$8000 mods:|MODIFIER_CONTROL
+	If GetKeyState(VK_MENU)&$8000 mods:|MODIFIER_OPTION
+	If GetKeyState(VK_LWIN)&$8000 Or GetKeyState(VK_RWIN)&$8000 mods:|MODIFIER_SYSTEM
+	Return mods
+EndFunction
+
+Function FindGadgetWindowHwnd:Byte Ptr(g:TGadget)
+	Local wg:TWindowsWindow
+	While g
+		wg=TWindowsWindow(g)
+		If wg Return wg.Query(QUERY_HWND)	'handle
+		g=g.parent
+	Wend
+EndFunction
+
+?
+