Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Include <GDIPlus.au3>
- #Include <WinAPIEx.au3>
- #Include <APIConstants.au3>
- _GDIPlus_Startup()
- ; ---
- Global $Kernel32Dll = DllOpen( "kernel32.dll" )
- Global Const $tagCWPSTRUCT = "lparam lParam;wparam wParam;uint iMsg;hwnd hWnd"
- Global Enum $im_hWnd, $im_tClassEx, $im_hModule, $im_cbProc, $im_IsDwm, $im_hParent, _
- $im_sName, $im_sClass, $im_iStyle, $im_iExStyle, $im_iDefColor, _
- $im_fInit, $im_iMsg, $im_iMsgExt, $im_aCtrl, _
- $im_hGraph, $im_hFont, $im_hBrush, $im_hCursor, $imUB
- ; *
- Global $__im_cbHook = DllCallbackRegister( '__imWnd_Hook', 'lresult', 'int;wparam;lparam' ), _
- $__im_cbCtrlProc = DllCallbackRegister( '__imCtrl_Proc', 'lresult', 'hwnd;uint;wparam;lparam' ), _
- $__im_hHook = _WinAPI_SetWindowsHookEx( $WH_CALLWNDPROC, DllCallbackGetPtr( $__im_cbHook ), 0, _WinAPI_GetCurrentThreadId() )
- Global Const $__imWnd[$imUB] = [ 0 ]
- Global $Wnd = _imWnd_Init() ;Default imWindow|+INTERNAL_WNDPROC
- #Region imWnd.Public
- Func _imWnd_Init()
- Return $__imWnd
- EndFunc
- Func _imWnd_Create( ByRef $Wnd, $iW = 0, $iH = 0, $iX = -1, $iY = -1 )
- If Not __imWnd_DefParams( $Wnd ) Then _
- Return
- If $iW < 1 Or $iH < 1 Then
- $iW = 150
- $iH = 150
- EndIf
- If $iX = -1 Or $iY = -1 Then
- $iX = ( @DesktopWidth / 2 ) - ( $iW / 2 )
- $iY = ( @DesktopHeight/ 2 ) - ( $iH / 2 )
- EndIf
- ; ---
- Local $tClass = DllStructCreate( 'wchar[' & StringLen( $Wnd[$im_sClass] ) + 1 & ']' )
- DllStructSetData( $tClass, 1, $Wnd[$im_sClass] )
- $Wnd[$im_cbProc] = DllCallbackRegister( $Wnd[$im_cbProc], 'lresult', 'hwnd;uint;wparam;lparam' )
- $Wnd[$im_tClassEx] = DllStructCreate( $tagWNDCLASSEX )
- With $Wnd[$im_tClassEx]
- .Size = DllStructGetSize( $Wnd[$im_tClassEx] )
- .Style = 0
- .hWndProc = DllCallbackGetPtr( $Wnd[$im_cbProc])
- .ClsExtra = 0
- .WndExtra = 0
- .hInstance = $Wnd[$im_hModule]
- .hIcon = 0
- .hCursor = $Wnd[$im_hCursor]
- .hBackground = $Wnd[$im_hBrush]
- .MenuName = 0
- .ClassName = DllStructGetPtr( $tClass )
- .hIconSm = 0
- EndWith
- _WinAPI_RegisterClassEx( $Wnd[$im_tClassEx] )
- ; ---
- Local $hWnd = DllCall( 'user32.dll', 'hwnd', 'CreateWindowExW', _
- 'dword', $Wnd[$im_iExStyle], _ ;Extended style
- 'wstr', $Wnd[$im_sClass], _ ;Window class
- 'str', $Wnd[$im_sName], _ ;Window name
- 'dword', $Wnd[$im_iStyle], _ ;Window style
- 'int', $iX, 'int', $iY, _ ;Window pos
- 'int', $iW, 'int', $iH, _ ;Window size
- 'hwnd', $Wnd[$im_hParent], _ ;Parent window
- 'hwnd', 0, _ ;Window menu
- 'hwnd', $Wnd[$im_hModule], 'ptr', 0 )
- If Not @Error And $hWnd[0] Then
- Local $aCtrl[99][4] = [[0]]
- ; -
- $Wnd[$im_hWnd] = $hWnd[0]
- $Wnd[$im_aCtrl] = $aCtrl
- ; -
- $Wnd[$im_hGraph] = _GDIPlus_GraphicsCreateFromHWND( $hWnd[0] )
- ;If _WinAPI_DwmIsCompositionEnabled() Then
- $Wnd[$im_IsDwm] = False
- ;_WinAPI_DwmExtendFrameIntoClientArea( $hWnd[0] )
- ;EndIf
- ; -
- _imWnd_SetState( $Wnd, @SW_HIDE )
- Return True
- EndIf
- Return SetError( @Error, 0, False )
- EndFunc
- Func _imWnd_MsgBox( $iFlags, $sTitle, $sText, $hInstance, $hParent = 0 )
- Local $aRet, $tMBP = DllStructCreate($tagMSGBOXPARAMS), _
- $tTitle = DllStructCreate('wchar[' & (StringLen($sTitle) + 1) & ']')
- $tText = DllStructCreate('wchar[' & (StringLen($sText) + 1) & ']')
- ; ---
- DllStructSetData($tTitle, 1, $sTitle)
- DllStructSetData($tText, 1, $sText)
- $tMBP.Size = DllStructGetSize($tMBP)
- $tMBP.hOwner = $hParent
- $tMBP.hInstance = $hInstance
- $tMBP.Text = DllStructGetPtr($tText)
- $tMBP.Caption = DllStructGetPtr($tTitle)
- $tMBP.Style = BitAND($iFlags, 0xFFFFBFF8)
- $tMBP.Icon = 0
- $tMBP.ContextHelpId = 0
- $tMBP.MsgBoxCallback = 0
- $tMBP.LanguageId = 0
- $aRet = DllCall( $Kernel32Dll, 'ptr', 'GetModuleHandleW', 'wstr', 'user32.dll' )
- If Not @Error And $aRet[0] Then
- $aRet = DllCall( $Kernel32Dll, 'ptr', 'GetProcAddress', 'ptr', $aRet[0], 'str', 'MessageBoxIndirectW' )
- If Not @Error And $aRet[0] Then _
- $aRet = DllCall( $Kernel32Dll, 'ptr', 'CreateThread', 'ptr', 0, 'dword_ptr', 0, 'ptr', $aRet[0], 'ptr', DllStructGetPtr($tMBP), 'dword', 0, 'dword*', 0 )
- EndIf
- Return Sleep( 10 )
- EndFunc
- Func _imWnd_Destroy( ByRef $Wnd, $fFree = True )
- Local $Id, $aCtrl = $Wnd[$im_aCtrl]
- ; -
- For $Id = 1 To $aCtrl[0][0] Step 1
- _imCtrl_Destroy( $Wnd, $Id )
- Next
- __imWnd_Proc( $Wnd[$im_hWnd], $WM_CLOSE, 1, 1, $Wnd )
- ; -
- _WinAPI_DestroyCursor( $Wnd[$im_hCursor] )
- _WinAPI_DeleteObject( $Wnd[$im_hBrush] )
- _GDIPlus_GraphicsDispose( $Wnd[$im_hGraph] )
- ; -
- _WinAPI_UnregisterClass( $Wnd[$im_sClass], $Wnd[$im_hModule] )
- DllCallbackFree( $Wnd[$im_cbProc] )
- If $fFree Then _
- $Wnd = 0
- EndFunc
- Func _imWnd_SetState( ByRef $Wnd, $iState = @SW_SHOW )
- Local $iRet = _WinAPI_ShowWindow( $Wnd[$im_hWnd], $iState )
- ; ---
- If $iState = @SW_SHOW Then _
- _imWnd_DefProc( $Wnd, $WM_PAINT, 0, 0 )
- Return $iRet
- EndFunc
- Func _imWnd_AddMsg( ByRef $Wnd, $iMsgId, $iMsgExt = 0 )
- If Not $Wnd[$im_iMsg] And Not $Wnd[$im_iMsgExt] Then
- $Wnd[$im_iMsg] = $iMsgId
- $Wnd[$im_iMsgExt] = $iMsgExt
- EndIf
- EndFunc
- Func _imWnd_FreeMsg( ByRef $Wnd )
- $Wnd[$im_iMsg] = 0
- $Wnd[$im_iMsgExt] = 0
- EndFunc
- Func _imWnd_DefProc( ByRef $Wnd, $iMsg, $wParam, $lParam )
- Return __imWnd_Proc( $Wnd[$im_hWnd], $iMsg, $wParam, $lParam, $Wnd )
- EndFunc ;Feature is experimental, possible unexpected errors/crashes.
- #EndRegion imWnd.Public
- #Region imWnd.CtrlPublic
- Func _imCtrlEdit_Create( ByRef $Wnd, $iColor, $sText, $iX, $iY, $iW, $iH, $iStyle = 0x003010C4, $iExStyle = 0x00000200 )
- Return _imCtrl_CreateEx( $Wnd, "Edit", 0, $iColor, $sText, $iX, $iY, $iW, $iH, $iStyle, $iExStyle )
- EndFunc
- Func _imCtrlButton_Create( ByRef $Wnd, $iId, $sText, $iX, $iY, $iW, $iH, $iStyle = 0, $iExStyle = 0 )
- Return _imCtrl_CreateEx( $Wnd, "Button", 0, $iId, $sText, $iX, $iY, $iW, $iH, $iStyle, $iExStyle )
- EndFunc
- Func _imCtrlLabel_Create( ByRef $Wnd, $iColor, $sText, $iX, $iY, $iW, $iH, $iStyle = 0x00020000, $iExStyle = 0 )
- Return _imCtrl_CreateEx( $Wnd, "Static", "Label", $iColor, $sText, $iX, $iY, $iW, $iH, $iStyle, $iExStyle )
- EndFunc
- Func _imCtrlListbox_Create( ByRef $Wnd, $iX, $iY, $iW, $iH, $iStyle = 0x20000000, $iExStyle = 0x00000200 )
- $iStyle = BitOr( $iStyle, $LBS_NOTIFY )
- ; ---
- Return _imCtrl_CreateEx( $Wnd, "ListBox", 0, 0, '', $iX, $iY, $iW, $iH, $iStyle, $iExStyle )
- EndFunc
- Func _imCtrlPic_Create( ByRef $Wnd, ByRef $hImg, $iX, $iY, $iW = 0, $iH = 0, $iStyle = 0x0002000E, $iExStyle = 0 )
- Local $hWnd, _
- $iImgW = _GDIPlus_ImageGetWidth( $hImg ), _
- $iImgH = _GDIPlus_ImageGetHeight( $hImg )
- ; -
- If $iW And $iH Then
- If $iImgW <> $iW Or $iImgH <> $iH Then
- Local $hTmp = $hImg
- ; -
- $hImg = _GDIPlus_ImageResize( $hImg, $iW, $iH )
- _GDIPlus_ImageDispose( $hTmp )
- EndIf
- Else
- $iW = $iImgW
- $iH = $iImgH
- EndIf
- $hWnd = _imCtrl_CreateEx( $Wnd, "Static", "Pic", $hImg, '', $iX, $iY, $iW, $iH, $iStyle, $iExStyle )
- _imCtrl_SetBitmap( $hWnd, $hImg )
- ; -
- Return $hWnd
- EndFunc
- Func _imCtrl_CreateEx( ByRef $Wnd, $sWndClass, $sImClass, $iExtOpt, $sText, $iX, $iY, $iW, $iH, $iStyle, $iExStyle )
- Local $hWnd, $aCtrl = $Wnd[$im_aCtrl], _
- $iCtrlID = Random( 10000, 19999, 1 ), _
- $iImId = $aCtrl[0][0] + 1
- ; *
- $iStyle = BitOr( 0x40000000, 0x10000000, $iStyle )
- If Not $sImClass Then _
- $sImClass = $sWndClass
- ; ---
- $hWnd = _WinAPI_CreateWindowEx( $iExStyle, $sWndClass, "", $iStyle, $iX, $iY, $iW, $iH, $Wnd[$im_hWnd], $iCtrlID, $Wnd[$im_hModule] )
- $aCtrl[0][0] = $iImId
- $aCtrl[$iImId][0] = $hWnd
- $aCtrl[$iImId][1] = $sImClass
- $aCtrl[$iImId][2] = $iExtOpt
- $aCtrl[$iImId][3] = 0
- $Wnd[$im_aCtrl] = $aCtrl
- ; *
- _imCtrl_SetFont( $hWnd, $Wnd[$im_hFont] )
- If $sText Then _
- _imCtrl_SetText( $hWnd, $sText )
- If Not $Wnd[$im_IsDwm] Then _
- DllCall( "UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hWnd, "wstr", 0, "wstr", 0 )
- ; ---
- Return $hWnd
- EndFunc
- Func _imCtrl_Destroy( ByRef $Wnd, $iId = 0, $hWnd = 0 )
- Local $aCtrl = $Wnd[$im_aCtrl]
- ; ---
- For $Id = 1 To $aCtrl[0][0] Step 1
- If $Id = $iId Or $hWnd = $aCtrl[$Id][0] Then
- Switch $aCtrl[$Id][1]
- Case "Pic"
- _imCtrl_SetBitmap( $aCtrl[$Id][0], 0 )
- _GDIPlus_ImageDispose( $aCtrl[$Id][2] )
- EndSwitch
- _WinAPI_DestroyWindow( $aCtrl[$Id][0] )
- $aCtrl[$Id][0] = 0
- $aCtrl[$Id][1] = 0
- $aCtrl[$Id][2] = 0
- $aCtrl[$Id][3] = 0
- ; -
- $Wnd[$im_aCtrl] = $aCtrl
- Return True
- EndIf
- Next
- Return False
- EndFunc
- Func _imCtrl_FindMe( ByRef $aCtrl, $hWnd, $iRet = 0 )
- Local $Id
- ; ---
- For $Id = 1 To $aCtrl[0][0] Step 1
- If $aCtrl[$Id][0] = $hWnd Then
- Switch $iRet
- Case -1
- Local $aRet[4] = [ _
- $aCtrl[$Id][0], _
- $aCtrl[$Id][1], _
- $aCtrl[$Id][2], _
- $aCtrl[$Id][3] ]
- Return $aRet
- Case 1 To 3
- Return $aCtrl[$Id][$iRet]
- Case Else ;
- Return $Id
- EndSwitch
- EndIf
- Next
- Return 0
- EndFunc
- ; ## CONTROL_MACROSES
- Func _imCtrl_SetFont( $hWnd, $hFont )
- _SendMessage( $hWnd, $WM_SETFONT, $hFont, True )
- EndFunc
- Func _imCtrl_SetText( $hWnd, $sText )
- _SendMessage( $hWnd, $WM_SETTEXT, 0, $sText, 0, "wparam", "wstr")
- EndFunc
- Func _imCtrl_SetBitmap( $hWnd, $hImg, $fCleanup = True )
- Local $hBitmap, $hRet
- ; ---
- If $hImg Then _
- $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap( $hImg )
- $hRet = _SendMessage( $hWnd, 0x172, 0, $hBitmap )
- If $fCleanup Then _
- _WinAPI_DeleteObject( $hRet )
- EndFunc
- Func _imCtrl_GetText( $hWnd )
- Local $iLength = _SendMessage( $hWnd, $WM_GETTEXTLENGTH ) + 1, _
- $tText = DllStructCreate("wchar Text[" & $iLength & "]")
- ; ---
- _SendMessage($hWnd, $WM_GETTEXT, $iLength, $tText, 0, "wparam", "struct*")
- Return DllStructGetData( $tText, 'Text' )
- EndFunc
- Func _imEdit_Appbegin($hWnd, $sText, $fEndRn = True )
- If $fEndRn Then $sText &= @CRLF
- ; ---
- _SendMessage( $hWnd, $EM_SETSEL, 0, 0 )
- _SendMessage( $hWnd, $EM_REPLACESEL, True, $sText, 0, "wparam", "wstr" )
- EndFunc
- Func _imEdit_Append($hWnd, $sText, $fEndRn = True )
- Local $iLength = _SendMessage( $hWnd, $WM_GETTEXTLENGTH )
- If $fEndRn Then $sText &= @CRLF
- ; ---
- _SendMessage( $hWnd, $EM_SETSEL, $iLength, $iLength )
- _SendMessage( $hWnd, $EM_REPLACESEL, True, $sText, 0, "wparam", "wstr" )
- EndFunc ;==>_GUICtrlEdit_AppendText
- Func _imListBox_AddString($hWnd, $sText)
- Return _SendMessage($hWnd, $LB_ADDSTRING, 0, $sText, 0, "wparam", "wstr")
- EndFunc ;==>_GUICtrlListBox_AddString
- Func _imListBox_BeginUpdate($hWnd)
- Return _SendMessage($hWnd, 0x000B ) = 0
- EndFunc ;==>_GUICtrlListBox_BeginUpdate
- Func _imListBox_EndUpdate($hWnd)
- Return _SendMessage($hWnd, 0x000B, 1, 0) = 0
- EndFunc ;==>_GUICtrlListBox_EndUpdate
- Func _imListBox_GetCurSel($hWnd)
- Return _SendMessage($hWnd, $LB_GETCURSEL)
- EndFunc ;==>_GUICtrlListBox_GetCurSel
- ; ## CONTROL_INTERNAL MACROSES
- Func _imCtrl_SetColor( ByRef $Wnd, $hWnd, $iColor )
- Local $aCtrl = $Wnd[$im_aCtrl], _
- $Id = _imCtrl_FindMe( $aCtrl, $hWnd )
- ; -
- If $Id Then
- $aCtrl[$Id][2] = $iColor
- $Wnd[$im_aCtrl] = $aCtrl
- ; -
- _WinAPI_RedrawWindow($hWnd)
- EndIf
- EndFunc
- #EndRegion imWnd.CtrlPublic
- #Region imWnd.Callbacks
- Func __imWnd_Proc($hWnd, $iMsg, $wParam, $lParam, $Wnd)
- If $Wnd[$im_fInit] Then
- Switch $iMsg
- Case $WM_PAINT
- ; Custom draw
- Case $WM_CLOSE
- If Not $wParam Or Not $lParam Then
- _imWnd_AddMsg( $Wnd, -3 )
- Return
- Else
- $wParam = 0
- $lParam = 0
- EndIf
- Case $WM_COMMAND
- Switch BitShift( $wParam, 16 )
- Case 0 ;BN_CLICKED
- Local $aInfo = _imCtrl_FindMe( $Wnd[$im_aCtrl], $lParam, -1 )
- If IsArray( $aInfo ) Then
- Switch $aInfo[1]
- Case "Button"
- _imWnd_AddMsg( $Wnd, $aInfo[2] )
- EndSwitch
- EndIf
- EndSwitch
- Case $WM_CTLCOLORSTATIC, $WM_CTLCOLORBTN, $WM_CTLCOLOREDIT ;$WM_CTLCOLORLISTBOX
- Local $aInfo = _imCtrl_FindMe( $Wnd[$im_aCtrl], $lParam, -1 )
- Switch $aInfo[1]
- Case "Label", "Edit"
- _WinAPI_SetTextColor( $wParam, $aInfo[2] )
- _WinAPI_SetBkColor( $wParam, $Wnd[$im_iDefColor] )
- ContinueCase
- Case "Pic", "Button" ;"ListBox"
- Return _WinAPI_CreateSolidBrush( $Wnd[$im_iDefColor] )
- EndSwitch
- EndSwitch
- EndIf
- Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam)
- EndFunc
- Func __imCtrl_Proc($hWnd, $iMsg, $wParam, $lParam, $Wnd)
- Local $vProcRet
- ; ---
- If $Wnd[$im_fInit] Then
- Local $aCtrl = $Wnd[$im_aCtrl], _
- $Id = _imCtrl_FindMe( $aCtrl, $hWnd )
- ; -
- If $Id Then
- ; -
- _WinAPI_SetWindowLong( $hWnd, $GWL_WNDPROC, $aCtrl[$Id][3] )
- $aCtrl[$Id][3] = 0
- $Wnd[$im_aCtrl] = $aCtrl
- EndIf
- EndIf
- Return $vProcRet
- EndFunc ;imCtrl_INTERNAL_PROC
- Func __imWnd_Hook( $iCode, $wParam, $lParam )
- If $Wnd[$im_fInit] Then
- Local $tCWPS = DllStructCreate( $tagCWPSTRUCT, $lParam ), _
- $hWnd = DllStructGetData( $tCWPS, 'hWnd' ), _
- $aCtrl = $Wnd[$im_aCtrl], $fCatch, _
- $Id = _imCtrl_FindMe( $aCtrl, $hWnd )
- ; -
- If $Id Then
- Switch $aCtrl[$Id][1]
- Case "Edit" ;Example: blocking messages
- Switch DllStructGetData( $tCWPS, 'iMsg' )
- Case $WM_CONTEXTMENU
- $fCatch = True
- EndSwitch
- EndSwitch
- If $fCatch Then
- If Not $aCtrl[$Id][3] Then
- $aCtrl[$Id][3] = _WinAPI_SetWindowLong( $hWnd, $GWL_WNDPROC, DllCallbackGetPtr( $__im_cbCtrlProc ) )
- EndIf
- $Wnd[$im_aCtrl] = $aCtrl
- EndIf
- EndIf
- EndIf
- Return _WinAPI_CallNextHookEx( $__im_hHook, $iCode, $wParam, $lParam )
- EndFunc
- #EndRegion imWnd.Callbacks
- #Region imWnd.Internal
- Func __imWnd_DefParams( ByRef $Wnd )
- If UBound( $Wnd ) <> $imUB Then _
- Return False
- ; ---
- For $imId = 1 To $imUB - 1
- If Not $Wnd[$imId] Then
- Switch $imId
- Case $im_cbProc
- $Wnd[$imId] = '__imWnd_Proc'
- ; -
- Case $im_sName
- $Wnd[$imId] = "imWindow"
- Case $im_sClass
- $Wnd[$imId] = "imClass"
- Case $im_iStyle
- $Wnd[$imId] = 0x96CB00CC ;0x96CB00CC
- Case $im_iExStyle
- $Wnd[$imId] = 0x00050181
- Case $im_iDefColor
- $Wnd[$imId] = 0xFFFFFF
- ; -
- Case $im_hModule
- $Wnd[$imId] = _WinAPI_GetModuleHandle( 0 )
- Case $im_hFont
- $Wnd[$imId] = _WinAPI_GetStockObject( 17 )
- Case $im_hBrush
- $Wnd[$imId] = _WinAPI_CreateSolidBrush( $Wnd[$im_iDefColor] )
- Case $im_hCursor
- $Wnd[$imId] = _WinAPI_LoadCursor( 0, 32512 )
- EndSwitch
- EndIf
- Next
- ; ---
- Return True
- EndFunc
- #EndRegion imWnd.Internal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement