offlineJScript#1
Administradores
Sáb 23 Jul 2011, 20:14
Olá à todos!
Fiz esta UDF: _GUIResourcePic.au3
para carregar imagens (.bmp, .jpg, .png, .gif {animadas} e outros formatos.) de arquivos ou resources de .exe, .dll, .ocx, .cpl...
Funções atuais:
_GUIResourcePic.au3 - Código fonte:
Todo comentário será bem-vindo!
Fiz esta UDF: _GUIResourcePic.au3
para carregar imagens (.bmp, .jpg, .png, .gif {animadas} e outros formatos.) de arquivos ou resources de .exe, .dll, .ocx, .cpl...
Funções atuais:
- Código:
; #CURRENT# =====================================================================================================================
;_GUICtrlPic_Create
;_GUICtrlPic_Delete
;_GUICtrlPic_SetResizing
;_GUICtrlPic_SetState
;_GUICtrlPic_SetPos
;_GUICtrlPic_GetPos
;_GUICtrlPic_SetImage
; ===============================================================================================================================
_GUIResourcePic.au3 - Código fonte:
- Código:
#include-once
; #INDEX# =======================================================================================================================
; Title .........: _GUIResourcePic
; AutoIt Version.: 3.2.12++
; Language.......: English
; Description ...: Load image (.bmp, .jpg, .png, .gif {animated} and other formats.) resources from .exe, .dll, .ocx, .cpl...
; Author ........: João Carlos (jscript)
; ===============================================================================================================================
; #CURRENT# =====================================================================================================================
;_GUICtrlPic_Create
;_GUICtrlPic_Delete
;_GUICtrlPic_SetResizing
;_GUICtrlPic_SetState
;_GUICtrlPic_SetPos
;_GUICtrlPic_GetPos
;_GUICtrlPic_SetImage
; ===============================================================================================================================
; #INTERNAL_USE_ONLY#============================================================================================================
;_GUICtrlPic_GetSysColor
;==============================================================================================================================
; #VARIABLES# ===================================================================================================================
;Global Const $RT_BITMAP = 2
;Global Const $RT_STRING = 6
;Global Const $RT_RCDATA = 10
;Global Const $RT_MESSAGETABLE = 11
;Global Const $RT_ANICURSOR = 21
;Global Const $RT_ANIICON = 22
;Global Const $RT_HTML = 23
Global $aGRP_OBJECTID[1][5]
; ===============================================================================================================================
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_Create
; Description ...: Creates a Picture control for the GUI.
; Syntax.........: _GUICtrlPic_Create( FileName, [ ResName [, Left [, Top [, Width [, Height [, ResType [, SetBkColor [, Border ]]]]]]]] )
; Parameters ....: FileName - Filename of the picture or resource to be loaded, supported types: BMP, JPG, PNG, GIF(animated).
; Can be an URL path too.
; ResName - [optional] The name of resource to be load from EXE, DLL, OCX, CPL and other formats.
; Default is -1 (no resource to be loaded, only file of local image).
; Left - [optional] The left side of the control (default is 0).
; Top - [optional] The top of the control (default if 0).
; Width - [optional] The width of the control. Default is -1 (original picture width).
; Height - [optional] The height of the control. Default is -1 (original picture height).
; ResType - [optional] The type of resource to be load. Default is -1 ($RT_RCDATA).
; SetBkColor - [optional] The bgcolor in hex RGB (does not obey opt(colormode)). Default is -1 (transparent).
; Border - [optional] Specifies that a control has a border with a sunken edge. Default is -1 (no border).
; Return values .: Success - Returns the identifier (controlID) of the new control.
; Failure - Returns 0 if picture cannot be created.
; Author ........: João Carlos (jscript)
; Modified.......:
; Remarks .......: This function attempts to embed an 'ActiveX Control' or a 'Document Object' inside the GUI.
; 'Document Objects' will only be visible if the Windows style $WS_CLIPCHILDREN has been used in GUICreate().
; The GUI functions GUICtrlRead and GUICtrlSet have no effect on this control. The object can only be
; controlled using 'methods' or 'properties' on the $ObjectVar, see:
; 1 - To set or change information in the control see _GUICtrlPic_Set...
; 2 - To update the picture after the dialog box is displayed just use _GUICtrlPic_SetImage.
; 3 - If you want to have a picture having the same size as the file content just use width=height=0 OR -1.
; 4 - Default resizing is $GUI_DOCKSIZE.
; 5 - If a picture is set as a background picture, as the other controls will overlap, it's important to disable
; the pic control and create it after the others controls: _GUICtrlPic_SetState( controlID, $GUI_DISABLE ).
; 6 - The extended style $GUI_WS_EX_PARENTDRAG can be used to allow the dragging of the parent window for windows
; that don't have a titlebar. Just use: GUICtrlSetStyle( controlID[0], -1, $GUI_WS_EX_PARENTDRAG ).
; 7 - If the "SetBkColor" is no set, the background is always set to transparent. GUICtrlSetBkColor() has not
; effect on pic control.
; Related .......: The resource type: $RT_ICON is not supported.
; Link ..........;
; Example .......; _GUICtrlPic_Create( "shell32.dll", 131, 0, 0, -1, -1, $RT_BITMAP )
; ===============================================================================================================================
Func _GUICtrlPic_Create($sFileName, $vResName = -1, $iLeft = 0, $iTop = 0, $iWidth = -1, $iHeight = -1, $vResType = -1, _
$sSetBkColor = -1, $iBorder = -1)
Local $oShell, $iActiveXID, $iControlID
Local $sInnerHTML = '<img id="image1" SRC="'
Local $sIsHttpFile = StringInStr($sFileName, "/", -1, 1)
If Not FileExists($sFileName) Then Return SetError(0, 0, 0)
If $iWidth = 0 Then $iWidth = -1
If $iHeight = 0 Then $iHeight = -1
If $vResType = -1 Then $vResType = 10 ;$RT_RCDATA
If $sIsHttpFile Then
$sInnerHTML &= $sFileName
ElseIf $vResName = -1 Then
$sInnerHTML &= 'file:///' & $sFileName
Else
$sInnerHTML &= 'res://' & $sFileName & '/' & $vResType & '/' & $vResName
EndIf
$sInnerHTML &= '">'
Switch $sSetBkColor ; 16 colors by name, HTML 4.01 standard
Case 'black', 'silver', 'gray', 'white', 'maroon', 'red', 'purple', 'fuchsia', 'green', 'lime', 'olive', 'yellow', 'navy', 'blue', 'teal', 'aqua'
Case $sSetBkColor > -1 And IsNumber($sSetBkColor)
$sSetBkColor = Hex($sSetBkColor, 6)
Case Else
$sSetBkColor = __GUICtrlPic_GetSysColor()
EndSwitch
If $iBorder = -1 Then
$iBorder = 0
Else
$iBorder = Abs($iBorder)
EndIf
$oShell = ObjCreate("Shell.Explorer.2")
If @error Then Return SetError(0, 0, 0)
$iActiveXID = GUICtrlCreateObj($oShell, $iLeft, $iTop, 0, 0)
If $iActiveXID = 0 Then Return SetError(0, 0, 0)
$oShell.navigate("about:blank")
While $oShell.Busy()
Sleep(10)
WEnd
With $oShell.document
.write('<HEAD><TITLE></TITLE><script language="javascript"></script></HEAD>')
.write('<body onselectstart="return false" oncontextmenu="return false" onclick="return false" ondragstart="return false" ondragover="return false">')
.body.innerHTML = $sInnerHTML
.body.topmargin = 0
.body.leftmargin = 0
.body.scroll = "no"
.body.bgcolor = $sSetBkColor
.body.style.backgroundColor = $sSetBkColor
.body.style.borderWidth = $iBorder
EndWith
$oShell.document.getElementById("image1" ).style.backgroundColor = "transparent"
If $iWidth <> -1 Then $oShell.document.getElementById("image1" ).width = $iWidth
If $iHeight <> -1 Then $oShell.document.getElementById("image1" ).height = $iHeight
$iWidth = $oShell.document.getElementById("image1" ).width
$iHeight = $oShell.document.getElementById("image1" ).height
GUICtrlSetPos(-1, $iLeft, $iTop, $iWidth, $iHeight)
$iControlID = GUICtrlCreateLabel("", $iLeft, $iTop, $iWidth, $iHeight, -1, 0x00000020) ; Dummy control for used by other functions like GUICtrlSetTip...
GUICtrlSetBkColor(-1, -2)
GUICtrlSetState(-1, 8192 + 2048)
; Default resizing is $GUI_DOCSIZE = 768
; The automatic resizing event can be disabled if GUIEventOptions(Option) is set to 1.
Local $sResizeMode = Opt("GUIResizeMode")
If Opt("GUIEventOptions") = 0 And $sResizeMode = 0 Then
GUICtrlSetResizing(-1, 768)
GUICtrlSetResizing($iActiveXID, 768)
ElseIf $sResizeMode > 0 Then
GUICtrlSetResizing(-1, $sResizeMode)
GUICtrlSetResizing($iActiveXID, $sResizeMode)
EndIf
For $i = 1 To $aGRP_OBJECTID[0][0]
If $aGRP_OBJECTID[$i][0] = $iControlID Then
$aGRP_OBJECTID[$i][1] = $oShell
$aGRP_OBJECTID[$i][2] = $iActiveXID
$aGRP_OBJECTID[$i][3] = $iLeft
$aGRP_OBJECTID[$i][4] = $iTop
Return $iControlID
EndIf
Next
ReDim $aGRP_OBJECTID[UBound($aGRP_OBJECTID, 1) + 1][5]
$aGRP_OBJECTID[0][0] += 1
$aGRP_OBJECTID[$aGRP_OBJECTID[0][0]][0] = $iControlID
$aGRP_OBJECTID[$aGRP_OBJECTID[0][0]][1] = $oShell
$aGRP_OBJECTID[$aGRP_OBJECTID[0][0]][2] = $iActiveXID
$aGRP_OBJECTID[$aGRP_OBJECTID[0][0]][3] = $iLeft
$aGRP_OBJECTID[$aGRP_OBJECTID[0][0]][4] = $iTop
Return $iControlID
EndFunc ;==>_GUICtrlPic_Create
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_Delete
; Description ...: Deletes a control returned by _GUICtrlPic_Create.
; Syntax.........: _GUICtrlPic_Delete( controlID )
; Parameters ....: controlID - The control identifier (controlID) as returned by a _GUICtrlPic_Create function.
; Return values .: Success - Returns 1.
; Failure - Returns 0.
; Author ........: João Carlos (jscript)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _GUICtrlPic_Delete($iCtrlID)
; ===============================================================================================================================
Func _GUICtrlPic_Delete($iCtrlID)
Local $aClone[1][5]
If $iCtrlID = -1 Then $iCtrlID = __GUIGetLastCtrlID()
For $i = 1 To $aGRP_OBJECTID[0][0]
If $aGRP_OBJECTID[$i][0] = $iCtrlID Then ContinueLoop
ReDim $aClone[UBound($aClone, 1) + 1][5]
$aClone[0][0] += 1
For $j = 0 To 4
$aClone[$aClone[0][0]][$j] = $aGRP_OBJECTID[$i][$j]
Next
Next
$aGRP_OBJECTID = $aClone
$aClone = 0
GUICtrlSetState(($iCtrlID - 1), 32 + 128)
Return GUICtrlDelete($iCtrlID)
EndFunc ;==>_GUICtrlPic_Delete
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_SetResizing
; Description ...: Defines the resizing method used by a _GUICtrlPic_Create.
; Syntax.........: _GUICtrlPic_SetResizing( FileName, [ ResName [, Left [, Top [, Width [, Height [, ResType [, SetBkColor [, Border ]]]]]]]] )
; Parameters ....: controlID - The control identifier (controlID) as returned by a _GUICtrlPic_Create function.
; resizing - The type of resize values to be used, add together multiple values if required.
; See the Docking Values table in the GUICtrlSetResizing Function Reference
; Return values .: Success - Returns 1
; Failure - Returns 0.
; Author ........: João Carlos (jscript)
; Modified.......:
; Remarks .......: The default resizing for a given control is control dependent see the control doc.
; A default value for any control can be set with GUIResizeMode(Option).
; The automatic resizing event can be disabled if GUIEventOptions(Option) is set to 1.
; Related .......:
; Link ..........;
; Example .......; _GUICtrlPic_SetResizing($iCtrlID, $GUI_DOCKALL)
; ===============================================================================================================================
Func _GUICtrlPic_SetResizing($iCtrlID, $iResizing)
If $iCtrlID = -1 Then $iCtrlID = __GUIGetLastCtrlID()
For $i = 1 To $aGRP_OBJECTID[0][0]
If $aGRP_OBJECTID[$i][0] <> $iCtrlID Then ContinueLoop
GUICtrlSetResizing($aGRP_OBJECTID[$i][2], $iResizing)
Return GUICtrlSetResizing($aGRP_OBJECTID[$i][0], $iResizing)
Next
Return 0
EndFunc ;==>_GUICtrlPic_SetResizing
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_SetState
; Description ...: Defines the resizing method returned by a _GUICtrlPic_Create.
; Syntax.........: _GUICtrlPic_SetState( controlID, state )
; Parameters ....: controlID - The control identifier (controlID) as returned by a _GUICtrlPic_Create function.
; state - See the State values below.
; Return values .: Success - Returns 1
; Failure - Returns 0.
; Author ........: João Carlos (jscript)
; Modified.......:
; Remarks .......: Suported state values:
; _________________________________________________________________________
; $GUI_SHOW -> Control will be visible.
; $GUI_HIDE -> Control will not be visible.
; $GUI_ENABLE -> Control will be enabled.
; $GUI_DISABLE -> Control will be greyed out.
; $GUI_ONTOP -> Control will be have the ontop attribute for the window .
; ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
; State values can be summed up as: $GUI_DISABLE + $GUI_HIDE sets the control in an disabled and hidden state.
; Related .......:
; Link ..........;
; Example .......; _GUICtrlPic_SetState($iCtrlID, $GUI_HIDE)
; ===============================================================================================================================
Func _GUICtrlPic_SetState($iCtrlID, $iState)
If $iCtrlID = -1 Then $iCtrlID = __GUIGetLastCtrlID()
For $i = 1 To $aGRP_OBJECTID[0][0]
If $aGRP_OBJECTID[$i][0] <> $iCtrlID Then ContinueLoop
If BitAND($iState, 16) Then $aGRP_OBJECTID[$i][1] .document.getElementById("image1" ).style.visibility = "visible"
If BitAND($iState, 32) Then $aGRP_OBJECTID[$i][1] .document.getElementById("image1" ).style.visibility = "hidden"
GUICtrlSetState($aGRP_OBJECTID[$i][2], $iState)
Return GUICtrlSetState($aGRP_OBJECTID[$i][0], $iState)
Next
Return 0
EndFunc ;==>_GUICtrlPic_SetState
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_SetPos
; Description ...: Changes the position of a control _GUICtrlPic_Create in the GUI window.
; Syntax.........: _GUICtrlPic_SetPos( controlID, left, top [, width [, height]] )
; Parameters ....: controlID - The control identifier (controlID) as returned by a _GUICtrlPic_Create function.
; left - The left side of the control.
; top - The top of the control.
; width - [optional] The width of the control. Default is keyword "Default".
; height - [optional] The height of the control. Default is keyword "Default".
; Return values .: Success - Returns 1
; Failure - Returns 0.
; Author ........: João Carlos (jscript)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _GUICtrlPic_SetPos($iCtrlID, $iLeft, $iTop)
; ===============================================================================================================================
Func _GUICtrlPic_SetPos($iCtrlID, $iLeft, $iTop, $iWidth = Default, $iHeight = Default)
If $iCtrlID = -1 Then $iCtrlID = __GUIGetLastCtrlID()
For $i = 1 To $aGRP_OBJECTID[0][0]
If $aGRP_OBJECTID[$i][0] <> $iCtrlID Then ContinueLoop
$aGRP_OBJECTID[$i][3] = $iLeft
$aGRP_OBJECTID[$i][4] = $iTop
If $iWidth <> Default And $iWidth <> -1 Then $aGRP_OBJECTID[$i][1] .document.getElementById("image1" ).width = $iWidth
If $iHeight <> Default And $iHeight <> -1 Then $aGRP_OBJECTID[$i][1] .document.getElementById("image1" ).height = $iHeight
$aGRP_OBJECTID[$i][1] .document.getElementById("image1" ).style.visibility = "hidden"
GUICtrlSetPos($aGRP_OBJECTID[$i][2], $iLeft, $iTop, $iWidth, $iHeight)
GUICtrlSetPos($aGRP_OBJECTID[$i][0], $iLeft, $iTop, $iWidth, $iHeight)
$aGRP_OBJECTID[$i][1] .document.getElementById("image1" ).style.visibility = "visible"
Return 1;_GUICtrlPic_SetState($iCtrlID, 16)
Next
Return 0
EndFunc ;==>_GUICtrlPic_SetPos
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_GetPos
; Description ...: Retrieves the position and size of a control returned by _GUICtrlPic_Create relative to it's window.
; Syntax.........: _GUICtrlPic_SetPos( controlID )
; Parameters ....: controlID - The control identifier (controlID) as returned by a _GUICtrlPic_Create function.
; Return values .: Success - Returns an array containing the size and the control's position relative to it's client window:
; $array[0] = X position
; $array[1] = Y position
; $array[2] = Width
; $array[3] = Height
; Failure - Sets @error to 1.
; Author ........: João Carlos (jscript)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _GUICtrlPic_GetPos($iCtrlID)
; ===============================================================================================================================
Func _GUICtrlPic_GetPos($iCtrlID)
Local $aReturn[4]
If $iCtrlID = -1 Then $iCtrlID = __GUIGetLastCtrlID()
For $i = 1 To $aGRP_OBJECTID[0][0]
If $aGRP_OBJECTID[$i][0] <> $iCtrlID Then ContinueLoop
$aReturn[0] = $aGRP_OBJECTID[$i][3]
$aReturn[1] = $aGRP_OBJECTID[$i][4]
$aReturn[2] = $aGRP_OBJECTID[$i][1] .document.getElementById("image1" ).width
$aReturn[3] = $aGRP_OBJECTID[$i][1] .document.getElementById("image1" ).height
Return $aReturn
Next
Return SetError(1, 0, 0)
EndFunc ;==>_GUICtrlPic_GetPos
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_SetImage
; Description ...: Sets the picture or resource to be loaded, supported types: BMP, JPG, PNG, GIF(animated).
; Syntax.........: _GUICtrlPic_SetImage( controlID, FileName [, ResName [, ResType [, FixSize ]]] )
; Parameters ....: controlID - The control identifier (controlID) as returned by a _GUICtrlPic_Create function.
; FileName - Filename of the picture or resource to be loaded, supported types: BMP, JPG, PNG, GIF(animated).
; Can be an URL path too.
; ResName - [optional] The name of resource to be load from EXE, DLL, OCX, CPL and other formats.
; Default is -1 (no resource to be loaded, only file of local image).
; ResType - [optional] The type of resource to be load. Default is -1 ($RT_RCDATA).
; Return values .: Success - Returns 1
; Failure - Returns 0.
; Author ........: João Carlos (jscript)
; Modified.......:
; Remarks .......: The resource type: $RT_ICON is not supported.
; Related .......:
; Link ..........;
; Example .......; _GUICtrlPic_SetImage($iCtrlID, $iLeft, $iTop)
; ===============================================================================================================================
Func _GUICtrlPic_SetImage($iCtrlID, $sFileName, $vResName = -1, $vResType = -1, $lFixSize = True)
Local $sInnerHTML = '<img id="image1" SRC="'
Local $sIsHttpFile = StringInStr($sFileName, "/", 0, 1)
Local $iWidth, $iHeight, $iIsVideo
If $iCtrlID = -1 Then $iCtrlID = __GUIGetLastCtrlID()
If $sIsHttpFile = 0 And FileExists($sFileName) = 0 Then Return SetError(0, 0, 0)
If $vResType = -1 Then $vResType = 10 ;$RT_RCDATA
For $i = 1 To $aGRP_OBJECTID[0][0]
If $aGRP_OBJECTID[$i][0] <> $iCtrlID Then ContinueLoop
$iIsVideo = StringInStr($aGRP_OBJECTID[$i][1] .document.body.outerHTML, "<embed", 0, 1)
If StringInStr($sFileName, "<embed", 0, 1) Then
$sInnerHTML = $sFileName
Else
If Not $iIsVideo Then
$iWidth = $aGRP_OBJECTID[$i][1] .document.getElementById("image1" ).width
$iHeight = $aGRP_OBJECTID[$i][1] .document.getElementById("image1" ).height
EndIf
If $sIsHttpFile Then
$sInnerHTML &= $sFileName
ElseIf $vResName = -1 Then
$sInnerHTML &= 'file:///' & $sFileName
Else
$sInnerHTML &= 'res://' & $sFileName & '/' & $vResType & '/' & $vResName
EndIf
$sInnerHTML &= '">'
EndIf
$aGRP_OBJECTID[$i][1] .document.body.innerHTML = $sInnerHTML
If $lFixSize And Not $iIsVideo Then
$aGRP_OBJECTID[$i][1] .document.getElementById("image1" ).width = $iWidth
$aGRP_OBJECTID[$i][1] .document.getElementById("image1" ).height = $iHeight
EndIf
Return 1
Next
Return 0
EndFunc ;==>_GUICtrlPic_SetImage
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: _GUICtrlPic_GetSysColor
; Description ...: Returns the system color.
; Syntax.........: _GUICtrlPic_GetSysColor( [ ColorRegion ] )
; Parameters ....: ColorRegion - [optional] The region of the system color. Default is COLOR_BTNFACE.
; Return values .: Hex color
; Author ........: jscript
; Modified.......:
; Remarks .......: If EzSkin.au3 modified by jscript from original by Valuater is used, return $vDAT_COLOR_BACKGND.
; Related .......:
; Link ..........;
; Example .......; _GUICtrlPic_GetSysColor()
; ===============================================================================================================================
Func __GUICtrlPic_GetSysColor($iColorRegion = 15); 15 = COLOR_BTNFACE
Local $sGetSysColor
; If EzSkin.au3 modified by jscript from original by Valuater is used...
If IsDeclared("vDAT_COLOR_BACKGND") Then Return Hex(Eval("vDAT_COLOR_BACKGND"), 6)
$sGetSysColor = DllCall('user32.dll', 'int', 'GetSysColor', 'int', $iColorRegion)
$sGetSysColor = Hex($sGetSysColor[0], 6); BGR format
; Converts BGR to RGB color mode
Return StringTrimLeft($sGetSysColor, 4) & StringTrimLeft(StringTrimRight($sGetSysColor, 2), 2) & StringTrimRight($sGetSysColor, 4)
EndFunc ;==>__GUICtrlPic_GetSysColor
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: _GUIGetLastCtrlID
; Description ...: Returns the last ctrlID referenced
; Syntax ........: _GUIGetLastCtrlID( )
; Parameters ....:
; Return values .: None
; Author(s) .....: MrCreaTor
; Modified ......: João Carlos (Jscript FROM Brazil)
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __GUIGetLastCtrlID()
Local $aRet = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", GUICtrlGetHandle(-1))
Return $aRet[0]
EndFunc ;==>__GUIGetLastCtrlID
Todo comentário será bem-vindo!