#include-once


Global $gdi32dll		=	DllOpen('gdi32.dll')
Global $user32dll		=	DllOpen('user32.dll')
Global $shell32dll		=	DllOpen('shell32.dll')
Global $kernel32dll		=	DllOpen('kernel32.dll')

Func CloseDllHandles()

	DllClose($gdi32dll)
	DllClose($user32dll)
	DllClose($shell32dll)
	DllClose($kernel32dll)

EndFunc


Global Const $IDM_FILE_NEWHELLO               = 40001
Global Const $IDM_FILE_NEWRECT                = 40002
Global Const $IDM_APP_EXIT                    = 40003
Global Const $IDM_FILE_CLOSE                  = 40004
Global Const $IDM_COLOR_BLACK                 = 40005
Global Const $IDM_COLOR_RED                   = 40006
Global Const $IDM_COLOR_GREEN                 = 40007
Global Const $IDM_COLOR_BLUE                  = 40008
Global Const $IDM_COLOR_WHITE                 = 40009
Global Const $IDM_WINDOW_CASCADE              = 40010
Global Const $IDM_WINDOW_TILE                 = 40011
Global Const $IDM_WINDOW_ARRANGE              = 40012
Global Const $IDM_WINDOW_CLOSEALL             = 40013


If Not IsDeclared ('NULL') Then Global Const $NULL = Ptr(0)


; Fensterklassenstile
Global Const $CS_VREDRAW = 0x0001
Global Const $CS_HREDRAW = 0x0002

Global Const $CW_USEDEFAULT = 0x80000000

Global Const $LOCALE_USER_DEFAULT = 0x400
Global Const $LOCALE_ITIME = 35
Global Const $LOCALE_ITLZERO = 0x00000025

Global Const $WM_QUERYENDSESSION	= 0x0011

Global Const $WM_MDIACTIVATE	= 546
Global Const $WM_MDICASCADE	= 551
Global Const $WM_MDICREATE	= 544
Global Const $WM_MDIDESTROY	= 545
Global Const $WM_MDIGETACTIVE	= 553
Global Const $WM_MDIICONARRANGE	= 552
Global Const $WM_MDIMAXIMIZE	= 549
Global Const $WM_MDINEXT	= 548
Global Const $WM_MDIREFRESHMENU	= 564
Global Const $WM_MDIRESTORE	= 547
Global Const $WM_MDISETMENU	= 560
Global Const $WM_MDITILE	= 550

; /* Mapping Modes */
Global Const $MM_TEXT            = 1
Global Const $MM_LOMETRIC        = 2
Global Const $MM_HIMETRIC        = 3
Global Const $MM_LOENGLISH       = 4
Global Const $MM_HIENGLISH       = 5
Global Const $MM_TWIPS           = 6
Global Const $MM_ISOTROPIC       = 7
Global Const $MM_ANISOTROPIC     = 8

Global Const $ULW_COLORKEY   = 0x01
Global Const $ULW_ALPHA      = 0x02
Global Const $ULW_OPAQUE     = 0x04

Global Const $WHITE_BRUSH         = 0
Global Const $LTGRAY_BRUSH        = 1
Global Const $GRAY_BRUSH          = 2
Global Const $DKGRAY_BRUSH        = 3
Global Const $BLACK_BRUSH         = 4
Global Const $NULL_BRUSH          = 5
Global Const $HOLLOW_BRUSH        = 5
Global Const $WHITE_PEN           = 6
Global Const $BLACK_PEN           = 7
Global Const $NULL_PEN            = 8
Global Const $SYSTEM_FONT         = 13
Global Const $DEFAULT_PALETTE     = 15
Global Const $ANSI_FIXED_FONT     = 11
Global Const $ANSI_VAR_FONT       = 12
Global Const $DEVICE_DEFAULT_FONT = 14
;Global Const $DEFAULT_GUI_FONT    = 17
Global Const $OEM_FIXED_FONT      = 10
Global Const $SYSTEM_FIXED_FONT   = 16

Global Const $SW_HIDE = 0
Global Const $SW_NORMAL = 1
Global Const $SW_SHOWNORMAL = 1
Global Const $SW_SHOWMINIMIZED = 2
Global Const $SW_MAXIMIZE = 3
Global Const $SW_SHOWMAXIMIZED = 3
Global Const $SW_SHOWNOACTIVATE = 4
Global Const $SW_SHOW = 5
Global Const $SW_MINIMIZE = 6
Global Const $SW_SHOWMINNOACTIVE = 7
Global Const $SW_SHOWNA = 8
Global Const $SW_RESTORE = 9
Global Const $SW_SHOWDEFAULT = 1= 0
Global Const $SW_FORCEMINIMIZE = 1= 1
Global Const $SW_MAX = 1= 1

Global Const $SIZE_RESTORED	= 0
Global Const $SIZE_MINIMIZED	= 1
Global Const $SIZE_MAXIMIZED	= 2
Global Const $SIZE_MAXSHOW	= 3
Global Const $SIZE_MAXHIDE	= 4
Global Const $SIZENORMAL	= 0
Global Const $SIZEICONIC	= 1
Global Const $SIZEFULLSCREEN	= 2
Global Const $SIZEZOOMSHOW	= 3
Global Const $SIZEZOOMHIDE	= 4

Global Const $MIIM_STATE      = 0x00000001
Global Const $MIIM_ID         = 0x00000002
Global Const $MIIM_SUBMENU    = 0x00000004
Global Const $MIIM_CHECKMARKS = 0x00000008
Global Const $MIIM_TYPE       = 0x00000010
Global Const $MIIM_DATA       = 0x00000020
Global Const $MIIM_STRING     = 0x00000040
Global Const $MIIM_BITMAP     = 0x00000080
Global Const $MIIM_FTYPE      = 0x00000100

;/*
; * Menu flags for Add/Check/EnableMenuItem()
; */
Global Const $MF_INSERT           =    0x00000000
Global Const $MF_CHANGE           =    0x00000080
Global Const $MF_APPEND           =    0x00000100
Global Const $MF_DELETE           =    0x00000200
Global Const $MF_REMOVE           =    0x00001000

Global Const $MF_BYCOMMAND        =    0x00000000
Global Const $MF_BYPOSITION       =    0x00000400

Global Const $MF_SEPARATOR        =    0x00000800

Global Const $MF_ENABLED          =    0x00000000
Global Const $MF_GRAYED           =    0x00000001
Global Const $MF_DISABLED         =    0x00000002

Global Const $MF_UNCHECKED        =    0x00000000
Global Const $MF_CHECKED          =    0x00000008
Global Const $MF_USECHECKBITMAPS  =    0x00000200

Global Const $MF_STRING           =    0x00000000
Global Const $MF_BITMAP           =    0x00000004
Global Const $MF_OWNERDRAW        =    0x00000100

Global Const $MF_POPUP            =    0x00000010
Global Const $MF_MENUBARBREAK     =    0x00000020
Global Const $MF_MENUBREAK        =    0x00000040

Global Const $MF_UNHILITE         =    0x00000000
Global Const $MF_HILITE           =    0x00000080

Global Const $MF_DEFAULT          =    0x00001000
Global Const $MF_SYSMENU          =    0x00002000
Global Const $MF_HELP             =    0x00004000
Global Const $MF_RIGHTJUSTIFY     =    0x00004000

Global Const $MF_MOUSESELECT      =    0x00008000

Global Const $MFT_STRING       =  $MF_STRING
Global Const $MFT_BITMAP       =  $MF_BITMAP
Global Const $MFT_MENUBARBREAK =  $MF_MENUBARBREAK
Global Const $MFT_MENUBREAK    =  $MF_MENUBREAK
Global Const $MFT_OWNERDRAW    =  $MF_OWNERDRAW
Global Const $MFT_RADIOCHECK   =  0x00000200
Global Const $MFT_SEPARATOR    =  $MF_SEPARATOR
Global Const $MFT_RIGHTORDER   =  0x00002000
Global Const $MFT_RIGHTJUSTIFY =  $MF_RIGHTJUSTIFY

;/* Menu flags for Add/Check/EnableMenuItem() */
Global Const $MFS_GRAYED      =    0x00000003
Global Const $MFS_DISABLED    =    $MFS_GRAYED
Global Const $MFS_CHECKED     =    $MF_CHECKED
Global Const $MFS_HILITE      =    $MF_HILITE
Global Const $MFS_ENABLED     =    $MF_ENABLED
Global Const $MFS_UNCHECKED   =    $MF_UNCHECKED
Global Const $MFS_UNHILITE    =    $MF_UNHILITE
Global Const $MFS_DEFAULT     =    $MF_DEFAULT

Global Const $VK_F4	= 0x73
Global Const $VK_F5	= 0x74

Global Const $FALT	= 16
Global Const $FCONTROL	= 8
Global Const $FNOINVERT	= 2
Global Const $FSHIFT	= 4
Global Const $FVIRTKEY	= 1


;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

; --- $ACCEL
Global Const $_ACCEL = _
	'ubyte fVirt;'& _
	'ushort key;'& _
	'ushort cmd;'

; --- $WNDCLASSEX
Global Const $WNDCLASSEX = _
	'uint cbSize;'& _
	'uint style;'& _
	'ptr lpfnWndProc;'& _
	'int cbClsExtra;'& _
	'int cbWndExtra;'& _
	'ptr hInstance;'& _
	'ptr hIcon;'& _
	'ptr hCursor;'& _
	'ptr hbrBackground;'& _
	'ptr lpszMenuName;'& _
	'ptr lpszClassName;'& _
	'ptr hIconSm;'

; --- $POINT
Global Const $POINT = _
	'long x;'& _
	'long y;'

; --- $MSG
Global Const $_MSG = _
	'hwnd hwnd;'& _
	'uint message;'& _
	'uint wParam;'& _
	'long_ptr lParam;'& _
	'dword time;'& _
	$POINT

; --- RECT
Global Const $_RECT = _
	"long left;" & _
	"long top;" & _
	"long right;" & _
	"long bottom;"

Global Const $PAINTSTRUCT = _
	'hwnd hDC;' & _
	'int  fErase;' & _
	'long rcPaint[4];' & _
	'int  fRestore;' & _
	'int  fIncUpdate;' & _
	'byte rgbReserved[32]'

Global Const $tagTEXTMETRIC =  _
  'LONG tmHeight;' & _
  'LONG tmAscent; ' & _
  'LONG tmDescent; ' & _
  'LONG tmInternalLeading; ' & _
  'LONG tmExternalLeading; ' & _
  'LONG tmAveCharWidth; ' & _
  'LONG tmMaxCharWidth; ' & _
  'LONG tmWeight; ' & _
  'LONG tmOverhang; ' & _
  'LONG tmDigitizedAspectX; ' & _
  'LONG tmDigitizedAspectY; ' & _
  'TCHAR tmFirstChar; ' & _
  'TCHAR tmLastChar; ' & _
  'TCHAR tmDefaultChar; ' & _
  'TCHAR tmBreakChar; ' & _
  'BYTE tmItalic; ' & _
  'BYTE tmUnderlined; ' & _
  'BYTE tmStruckOut; ' & _
  'BYTE tmPitchAndFamily; ' & _
  'BYTE tmCharSet;'

; --- $CLIENTCREATESTRUCT
Global Const $CLIENTCREATESTRUCT = _
	'ptr hWindowMenu;'& _
	'uint idFirstChild;'


; --- $MDICREATESTRUCT
Global Const $MDICREATESTRUCT = _
	'ptr szClass;'& _
	'ptr szTitle;'& _
	'ptr hOwner;'& _
	'int x;'& _
	'int y;'& _
	'int cx;'& _
	'int cy;'& _
	'dword style;'& _
	'lparam lParam;'

; --- $MENUITEMINFO
Global Const $MENUITEMINFO = _
	'uint cbSize;'& _
	'uint fMask;'& _
	'uint fType;'& _
	'uint fState;'& _
	'uint wID;'& _
	'ptr hSubMenu;'& _
	'ptr hbmpChecked;'& _
	'ptr hbmpUnchecked;'& _
	'ulong_ptr dwItemData;'& _
	'ptr dwTypeData;'& _
	'uint cch;'& _
	'ptr hbmpItem;'



;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

Func BeginPaint ($hWnd, $lpPaint)

	Local $aResult = DllCall($user32dll, 'hwnd', 'BeginPaint', 'hwnd', $hWnd, 'ptr', $lpPaint)
	Return $aResult[0]

EndFunc

Func CheckMenuItem ($hmenu, $uIDCheckItem, $uCheck)

	Local $aRes = DllCall ($user32dll, 'dword', 'CheckMenuItem', _
								'ptr', $hmenu, _
								'uint', $uIDCheckItem, _
								'uint', $uCheck)



	Return $aRes[0]

EndFunc

Func CreateAcceleratorTable ($lpaccl, $cEntries)

	Local $aRes = DllCall ($user32dll, 'ptr', 'CreateAcceleratorTableW', _
								'ptr', $lpaccl, _
								'int', $cEntries)
	Return $aRes[0]

EndFunc

Func CreateMenu ( )

	Local $aRes = DllCall ($user32dll, 'ptr', 'CreateMenu')
	Return $aRes[0]

EndFunc

Func CreatePopupMenu ( )

	Local $aRes = DllCall ($user32dll, 'ptr', 'CreatePopupMenu')
	Return $aRes[0]

EndFunc

Func CreateWindowEx ($dwExStyle, $szClassName, $szWindowName, $dwStyle, _
				 $x, $y, $nWidth, $nHeight, $hWndParent, $hMenu, $hInstance, $lpParam)

	Local $tClassName = 'wstr'
	Local $tWindowName = 'wstr'
	If (IsPtr ($szClassName)) Then
		$tClassName = 'ptr'
	EndIf

	If (IsPtr ($szWindowName)) Then
		$tWindowName = 'ptr'
	EndIf

	Local $aRes = DllCall ($user32dll, 'hwnd', 'CreateWindowExW', _
								'dword', $dwExStyle, _
							$tClassName , $szClassName, _
							$tWindowName , $szWindowName, _
								'dword', $dwStyle, _
								'int'  , $x, _
								'int'  , $y, _
								'int'  , $nWidth, _
								'int'  , $nHeight, _
								'hwnd' , $hWndParent, _
								'ptr'  , $hMenu, _
								'ptr'  , $hInstance, _
								'ptr'  , $lpParam)
	DebugDllCall ($aRes, "CreateWindowExW")
	Return $aRes[0]

EndFunc

Func CreateSolidBrush ($crColor)

	Local $aRes = DllCall ($gdi32dll, 'ptr', 'CreateSolidBrush', _
											 'dword', $crColor)  ; // brush color value
	Return $aRes [0]

EndFunc

Func EndPaint ($hWnd, $lpPaint)

	Local $aResult = DllCall($user32dll, 'int', 'EndPaint', 'hwnd', $hWnd, 'ptr', $lpPaint)
	Return $aResult[0]

EndFunc

Func DefFrameProc ($hWnd, $hWndMDIClient, $uMsg, $wParam, $lParam)

	Local $aRes = DllCall ($user32dll, 'ulong', 'DefFrameProcW', _
								'hwnd', $hWnd, _
								'hwnd', $hWndMDIClient, _
								'uint', $uMsg, _
								'wparam', $wParam, _
								'lparam', $lParam)
	Return $aRes[0]

EndFunc

Func DefMDIChildProc ($hWnd, $uMsg, $wParam, $lParam)

	Local $aRes = DllCall ($user32dll, 'ulong', 'DefMDIChildProcW', _
								'hwnd', $hWnd, _
								'uint', $uMsg, _
								'wparam', $wParam, _
								'lparam', $lParam)
	Return $aRes[0]

EndFunc

Func DefWindowProc ($hWnd, $nMsg, $wParam, $lParam)

	Local $aRes = DllCall($user32dll, 'int', 'DefWindowProcW', _
								'hwnd', $hWnd, _
								'int',  $nMsg, _
								'uint', $wParam, _
								'long', $lParam)
	Return $aRes[0]

EndFunc

Func DeleteObject ($hGdiObj)

	Local $aResult = DllCall($gdi32dll, 'int', 'DeleteObject', 'ptr', $hGdiObj)
	Return $aResult[0]

EndFunc

Func DestroyMenu ($hMenu)

	Local $aRes = DllCall ($user32dll, 'int', 'DestroyMenu', _
								'ptr', $hMenu)
	Return $aRes[0]

EndFunc

Func DestroyWindow ($hWnd)

	Local $aResult = DllCall($user32dll, 'int', 'DestroyWindow', 'hwnd', $hWnd)
	Return $aResult[0]

EndFunc

Func DispatchMessage ($lpMsg)

	Local $aResult = DllCall($user32dll, 'long', 'DispatchMessage', 'ptr', $lpMsg)
	Return $aResult

EndFunc

Func DrawMenuBar ($hWnd)

	Local $aRes = DllCall ($user32dll, 'int', 'DrawMenuBar', _
								'hwnd', $hWnd)
	Return $aRes[0]

EndFunc

Func DrawText ($hdc, $lpString, $nCount, $lpRect, $uFormat)

	Local $type = 'wstr'
	If (IsPtr ($lpString)) Then $type = 'ptr'
	Local $aRes = DllCall($user32dll, 'int', 'DrawTextW', _
							  'ptr',  $hdc, _
							  $type,  $lpString, _
							  'int',  $nCount, _
							  'ptr',  $lpRect, _
							  'uint', $uFormat)
	Return $aRes[0]

EndFunc

Func EnumChildWindows ($hWndParent, $lpEnumFunc, $lParam)

	Local $aRes = DllCall ($user32dll, 'int', 'EnumChildWindows', _
								'hwnd', $hWndParent, _
								'ptr', $lpEnumFunc, _
								'lparam', $lParam)
	Return $aRes[0]

EndFunc

Func GetDC ($hWnd)

	Local $aRes = DllCall ($user32dll, 'ptr', 'GetDC', _
								'hwnd', $hWnd)   ; handle to window
	Return $aRes[0]

EndFunc

Func GetMessage ($lpMsg, $hWnd, $wMsgFilterMin, $wMsgFilterMax)

	Local $aResult = DllCall($user32dll, 'int', 'GetMessage', _
												'ptr',  $lpMsg, _
												'hwnd', $hWnd, _
												'uint', $wMsgFilterMin, _
												'uint', $wMsgFilterMax)
    Return $aResult[0]

EndFunc

Func GetClientRect ($hWnd, $lpRect)

	Local $arResult = DllCall($user32dll, 'int', 'GetClientRect', 'hwnd', $hWnd, 'ptr', $lpRect)
	Return $arResult[0]

EndFunc

Func GetMenu ($hWnd)

	Local $aRes = DllCall ($user32dll, 'ptr', 'GetMenu', _
								'hwnd', $hWnd)
	Return $aRes[0]

EndFunc

Func GetMenuItemCount ($hMenu)

	Local $aRes = DllCall ($user32dll, 'int', 'GetMenuItemCount', _
								'ptr', $hMenu)
	Return $aRes[0]

EndFunc

Func GetModuleHandle ($sModuleName)

	Local $type = 'wstr'
	If (not $sModuleName or IsPtr ($sModuleName)) Then $type = 'ptr'
	Local $aRes = DllCall ($kernel32dll, "ptr", "GetModuleHandleW", _
									$type, $sModuleName)
	Return $aRes[0]

EndFunc

Func GetParent ($hWnd)

	Local $aRes = DllCall ($user32dll, 'hwnd', 'GetParent', _
								'hwnd', $hWnd)
	Return $aRes[0]

EndFunc

Func GetStockObject ($iObject)

	Local $aResult = DllCall($gdi32dll, 'hwnd', 'GetStockObject', 'int', $iObject)
	Return $aResult[0]

EndFunc

Func GetSubMenu ($hMenu, $nPos)

	Local $aRes = DllCall ($user32dll, 'ptr', 'GetSubMenu', _
								'ptr', $hMenu, _
								'int', $nPos)
	Return $aRes[0]

EndFunc

Func GetWindow ($hWnd, $uCmd)

	Local $aRes = DllCall ($user32dll, 'hwnd', 'GetWindow', _
								'hwnd', $hWnd, _
								'uint', $uCmd)
	Return $aRes[0]

EndFunc

Func GetWindowLong ($hWnd, $nIndex)

	Local $aRes = DllCall ($user32dll, 'long', 'GetWindowLongW', _
								'hwnd', $hWnd, _
								'int',  $nIndex)
	Return $aRes[0]

EndFunc

Func InsertMenuItem ($hMenu, $uItem, $fByPosition, $lpmii)

	Local $aRes = DllCall ($user32dll, 'int', 'InsertMenuItemW', _
								'ptr',  $hMenu, _
								'uint', $uItem, _
								'int',  $fByPosition, _
								'ptr',  $lpmii)
	Return $aRes[0]

EndFunc

Func InvalidateRect ($hWnd, $lpRect = 0, $bErase = True)

  Local $aResult = DllCall($user32dll, 'int', 'InvalidateRect', _
											  'hwnd', $hWnd, _
											  'ptr',  $lpRect, _
											  'int',  $bErase)
	Return $aResult[0]

EndFunc

Func IsMenu ($hMenu)

	Local $aRes = DllCall ($user32dll, 'int', 'IsMenu', _
								'ptr', $hMenu)
	Return $aRes[0]

EndFunc

Func IsWindow ($hWnd)

	Local $aRes = DllCall ($user32dll, 'int', 'IsWindow', _
								'hwnd', $hWnd)
	Return $aRes[0]

EndFunc

Func KillTimer ($hwnd, $uIDEvent)

	Local $aRes = DllCall ($user32dll, 'int', 'KillTimer', _
											  'hwnd', $hwnd, _
											  'uint', $uIDEvent)

	Return $aRes [0]

EndFunc

Func LoadCursor($hInstance, $szCursorName)

	Local $type = "ptr"
	If IsNumber($szCursorName) Then
		$szIconName = MAKEINTRESOURCE($szCursorName)
	Else
		$type = "wstr"
	EndIf
	Local $aResult = DllCall($user32dll, 'ptr', 'LoadCursorW', _
									'ptr', $hInstance, _
									$type, $szCursorName)
	Return $aResult[0]

EndFunc

Func LoadIcon ($hInstance, $szIconName)

	Local $type = "ptr"
	If IsNumber($szIconName) Then
		$szIconName = MAKEINTRESOURCE($szIconName)
	Else
		$type = "wstr"
	EndIf
	Local $aResult = DllCall($user32dll, 'ptr', 'LoadIconW', _
									'ptr', $hInstance, _
									$type, $szIconName)
	Return $aResult[0]

EndFunc

Func PostQuitMessage ($nExitCode)

	Local $aRes = DllCall($user32dll, 'none', 'PostQuitMessage', _
								'int', $nExitCode)
	Return $aRes[0]

EndFunc

Func Rectangle ($hdc, $nLeftRect, $nTopRect, $nRightRect, $nBottomRect)

	Local $aRes = DllCall ($gdi32dll, 'int', 'Rectangle', _
								'ptr', $hdc, _         ; handle to DC
								'int', $nLeftRect, _   ; x-coord of upper-left corner of rectangle
								'int', $nTopRect, _    ; y-coord of upper-left corner of rectangle
								'int', $nRightRect, _  ; x-coord of lower-right corner of rectangle
								'int', $nBottomRect)  ; y-coord of lower-right corner of rectangle
	Return $aRes[0]

EndFunc

Func RegisterClassEx ($lpwcx)

	Local $aRes = DllCall ($user32dll, 'ushort', 'RegisterClassExW', _
								'ptr', $lpwcx)
	Return $aRes[0]

EndFunc

Func ReleaseDC ($hWnd, $hDC)

	Local $aRes = DllCall ($user32dll, 'int', 'ReleaseDC', _
							'hwnd', $hWnd, _  ; handle to window
							'ptr', $hDC)      ; handle to DC
	Return $aRes[0]

EndFunc

Func ShowWindow ($hWnd, $nCmdShow = 5)

	Local $aRes = DllCall($user32dll, 'int', 'ShowWindow', 'hwnd', $hWnd, 'int', $nCmdShow)
	Return $aRes[0]

EndFunc

Func SelectObject ($hdc, $hGdiObj)

	Local $aRes = DllCall ($gdi32dll, 'ptr', 'SelectObject', _
											  'ptr', $hdc, _
											  'ptr', $hGdiObj)
	Return $aRes [0]

EndFunc

Func SendMessage ($hWnd, $nMsg, $wParam, $lParam)

	$aResult = DllCall($user32dll, 'lparam', 'SendMessageW', _
											 'hwnd',   $hWnd, _
											 'uint',   $nMsg, _
											 'wparam', $wParam, _
											 'lparam', $lParam)
	Return $aResult[0]

EndFunc

Func SetTextColor ($hdc, $crColor)

	Local $aRes = DllCall ($gdi32dll, 'dword', 'SetTextColor', _
								'ptr', $hdc, _           ; handle to DC
								'dword', $crColor)   ; text color
	Return $aRes[0]

EndFunc

Func SetTimer ($hwnd, $uIDEvent, $uElapse, $lpTimerFunc)

	Local $aRes = DllCall ($user32dll, 'int', 'SetTimer', _
								  'hwnd', $hwnd, _
								  'uint', $uIDEvent, _
								  'uint', $uElapse, _
								  'ptr',  $lpTimerFunc)
	Return $aRes [0]

EndFunc

Func SetWindowLong ($hWnd, $nIndex, $dwNewLong)

	Local $aRes = DllCall ($user32dll, 'long', 'SetWindowLongW', _
								'hwnd', $hWnd, _
								'int',  $nIndex, _
								'long', $dwNewLong)
	Return $aRes[0]

EndFunc

Func UpdateWindow ($hWnd)

	Local $aResult = DllCall($user32dll, 'int', 'UpdateWindow', 'hwnd', $hWnd)
	Return $aResult[0]

EndFunc

Func TranslateAccelerator ($hWnd, $hAccTable, $lpMsg)

	Local $aRes = DllCall ($user32dll, 'int', 'TranslateAcceleratorW', _
								'hwnd', $hWnd, _
								'ptr', $hAccTable, _
								'ptr', $lpMsg)
	Return $aRes[0]

EndFunc

Func TranslateMDISysAccel ($hWndClient, $lpMsg)

	Local $aRes = DllCall ($user32dll, 'int', 'TranslateMDISysAccel', _
								'hwnd', $hWndClient, _
								'ptr', $lpMsg)
	Return $aRes[0]

EndFunc

Func TranslateMessage ($lpMsg)

	Local $aResult = DllCall($user32dll, 'int', 'TranslateMessage', 'ptr', $lpMsg)
	Return $aResult[0]

EndFunc

;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

Func RGB ($red, $green, $blue)
	Return BitOR ( $red, BitShift ($green, -8), BitShift ($blue, -16) ) ; COLORREF / BGR
EndFunc

Func IS_INTRESOURCE($wInteger)
	Return (not BitShift ($wInteger, 16))
EndFunc

Func LOWORD($DWORD)
	Return BitAND($DWORD, 0xFFFF)
EndFunc

Func HIWORD($DWORD)
	Return BitShift($DWORD, 16)
EndFunc

Func HIBYTE ($w)
	Return BitAND ( BitShift ( $w, 8 ), 0xFF )
EndFunc

Func LOBYTE ($w)
	Return BitAND ( $w, 0xFF )
EndFunc

Func MAKEINTRESOURCE ($i)
	Return Ptr ($i)
EndFunc

Func MAKEWPARAM($wLow, $wHigh)
	Return BitOR ( BitAND ( $wLow, 0xFFFF ), BitShift (BitAND ( $wHigh, 0xFFFF ), -16) )
EndFunc

Func MAKELPARAM($wLow, $wHigh)
	Return BitOR ( BitAND ( $wLow, 0xFFFF ), BitShift (BitAND ( $wHigh, 0xFFFF ), -16) )
EndFunc

Func min ($a, $b)

	If ($a < $b) Then _
		Return $a
	Return $b

EndFunc

Func max ($a, $b)

	If ($a > $b) Then _
		Return $a
	Return $b

EndFunc

;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

Func ElIf ($a, $b, $c)

	If ($a) Then _
		Return $b

	Return $c

EndFunc

;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

Func DebugStruct (ByRef $struct, $sStruct = "", $sStructName = "")

	Local $i		= 1
	Local $val
	Local $asStruct
	Local $bMembername = FALSE

	If (not IsDllStruct ($struct)) Then _
		Return ConsoleWrite ("!> Ungültige Struktur !" & @crlf)

	If ($sStruct) Then

		If (StringRegExp ($sStruct, ";\h?\w+", 0)) Then

			$asStruct = StringRegExp ($sStruct, "(\w+\h?\[?\d?\d?\d?\d?\d?\]?;)", 3)

			If (IsArray ($asStruct)) Then _
				$bMembername = TRUE
		EndIf
	EndIf

	ConsoleWrite ("--- Debug Struct "&$sStructName&" ---" & @crlf)

	While (True)

		$val = DllStructGetData ($struct, $i)

		If (@error) Then
			ExitLoop
		EndIf

		If (IsArray ($asStruct)) Then

			ConsoleWrite (StringFormat ("> %-20s = %s\n", $asStruct[$i - 1], $val))
		Else
			ConsoleWrite ("> " & $i & " = " &$val & @crlf)
		EndIf

		$i += 1
	WEnd

	ConsoleWrite ("--------------------" & @crlf)

EndFunc

Func DebugStructPtr ($lpstruct, $sStruct, $sStructName = "")

	Local $i		= 1
	Local $val
	Local $struct
	Local $asStruct
	Local $bMembername

	If (not IsPtr ($lpstruct)) Then _
		Return ConsoleWrite ("!> Ungültiger Zeiger !" & @crlf)

	$struct = DllStructCreate ($sStruct, $lpstruct)

	If (not IsDllStruct ($struct)) Then _
		Return ConsoleWrite ("!> Ungültige Struktur !" & @crlf)

	If ($sStruct) Then

		If (StringRegExp ($sStruct, ";\h?\w+", 0)) Then

			$asStruct = StringRegExp ($sStruct, "(\w+\h?\[?\d?\d?\d?\d?\d?\]?;)", 3)

			If (IsArray ($asStruct)) Then _
				$bMembername = TRUE

		EndIf
	EndIf

	ConsoleWrite ("--- Debug Struct "&$sStructName&" ---" & @crlf)

	While (True)

		$val = DllStructGetData ($struct, $i)

		If (@error) Then
			ExitLoop
		EndIf

		If (IsArray ($asStruct)) Then

			ConsoleWrite (StringFormat ("> %-20s = %s\n", $asStruct[$i - 1], $val))
		Else
			ConsoleWrite ("> " & $i & " = " &$val & @crlf)
		EndIf

		$i += 1
	WEnd

	ConsoleWrite ("--------------------" & @crlf)

EndFunc

Func DebugDllCall (ByRef $array, $sFuncName = "")

	If (not IsArray ($array)) Then _
		Return

	ConsoleWrite ("--- "&$sFuncName&" ---" & @crlf)

	For $i = 0 To UBound ($array) - 1

		ConsoleWrite ("> aResult ["&$i&"] = "&$array[$i] & @crlf)
	Next

	ConsoleWrite ("--------------------" & @crlf)

EndFunc




