Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/28/2013 in all areas

  1. Zedna

    Resources UDF

    Link to pages with general resources description MSDN - Resources OverView & Reference You can embed any binary data into your AutoIt compiled EXE files in it's resources at compile time. As opposite to FileInstall() with resources you can use your embedded data directly without any temporary files on disk. If you wish you can save resources to disk with _ResourceSaveToFile() however. Adding data to resources can be done simply by AutoIt3Wrapper directive: #AutoIt3Wrapper_Res_File_Add=FileName, ResType, ResName As data can be used for example images,cursors,texts,sounds,videos,binary files etc. For loading/using data from resources at run time I made this tiny helper Resources UDF. Functions inside UDF: _ResourceGet($ResName, $ResType = $RT_RCDATA, $ResLang = 0, $DLL = -1) _ResourceGetAsString($ResName, $ResType = $RT_RCDATA, $ResLang = 0, $DLL = -1) _ResourceGetAsStringW($ResName, $ResType = $RT_RCDATA, $ResLang = 0, $DLL = -1) _ResourceGetAsBytes($ResName, $ResType = $RT_RCDATA, $ResLang = 0, $DLL = -1) _ResourceGetAsImage($ResName, $ResType = $RT_RCDATA, $DLL = -1) _ResourceGetAsBitmap($ResName, $ResType = $RT_RCDATA, $DLL = -1) _ResourceSaveToFile($FileName, $ResName, $ResType = $RT_RCDATA, $ResLang = 0, $CreatePath = 0, $DLL = -1) _ResourceSetImageToCtrl($CtrlId, $ResName, $ResType = $RT_RCDATA, $DLL = -1) _SetBitmapToCtrl($CtrlId, $hBitmap) _ResourcePlaySound($ResName, $Flag = 0, $DLL = -1) Notes: * to compile all script examples you must have installed Scite4AutoIt3 --> you must compile script by F7 from full Scite * for using #AutoIt3Wrapper_Res_File_Add directive you must have AutoIt3Wrapper at least version 2.0.1.22 (it's part of latest Scite4AutoIt3) * to compile all script examples must be apropriate resource data files in script directory (from resource_data.zip) * _ResourceGet() always returns pointer to data (for RT_BITMAP returns hBitmap), returning other types can be done by additional wrapper functions like _ResourceGetAsString() or _ResourceGetAsBytes() * _ResourceGetAsStringW() is for Unicode strings (Widechar) * you can use also #number instead of resource name, see examples * general supported resource types are listed in UDF as constants ($RT_BITMAP, $RT_RCDATA, ...) * information about playing video files (AVI) from resources is here thanks matrixnz * information/examples about using animated GIFs from resources is here and here thanks smashly/ProgAndy * information about running EXE files/DLL functions directly from resources is here thanks trancexx/Ward Known problems/limitations: * _ResourceGet() returns resource size (in bytes) in @extended macro but not for resource type RT_BITMAP * _ResourceSetImageToCtrl() works with "static/button" type of controls (picture,label,icon,button,checkbox,radiobutton,groupbox) * _ResourcePlaySound() plays only WAV files (not MP3 files) * _ResourceGetAsBytes() doesn't work for RT_BITMAP type because _ResourceGet() returns hBitmap instead of memory pointer in this case there could be used _ResourceGetAsImage() as workaround * _ResourceGet() has potential memory leak releasing of resources UnlockResource,FreeResource (opposite of LoadResource,LockResource) is not done because it must be done after using of resources at the end and not inside UDF * _GDIPlus_Startup() is called once at start of whole include --> no _GDIPlus_Shutdown() is called History: 2011-06-20 - fixed x64 compatibility (type: int->ptr) - internal change: FindResourceA -> FindResourceW (& type: str->wstr) - _SetBitmapToCtrl() --> $CtrlId parameter now supports also -1 (thanks guinness) - _WinAPI_LoadLibraryEx($DLL, $LOAD_LIBRARY_AS_DATAFILE) instead of _WinAPI_LoadLibrary($DLL) (thanks arcker) - added au3.user.calltips.api, au3.userudfs.properties (thanks guinness) - merged resource_au3.zip + resource_data.zip to one file resources.zip 2010-02-12 - all examples now use fixed #AutoIt3Wrapper_Res_File_Add directive from latest Scite4Autoit3 (no need for ResHacker.exe) - added support for buttons (also checkboxes,radiobuttons,groupboxes) in _ResourceSetImageToCtrl()/_SetBitmapToCtrl() thanks Melba 2009-08-25 - fixed corrupted topic (appeared after forum upgrade) - removed some AU3 tags from topic, note: all AU3 code is untouched inside attached ZIP 2008-11-27 - added _ResourceGetAsStringW() --> for Unicode strings (Widechar) 2008-11-10 - added two very simple examples 2008-08-14 - change: _GDIPlus_Startup() is called once at start of whole include--> no _GDIPlus_Shutdown() is called - fixed support for animated GIFs in _ResourceGetAsImage() --> removed_MemGlobalFree($hData) - used simpler UDF syntax (from WinAPI) instead of DllCall() where possible - added new example for animated GIF image 2008-07-08 - just corrected some typos in this topic (no code changes) 2008-06-25 - big thanks to ProgAndy for ideas,improvements! - added _ResourceGetAsImage(), _ResourceGetAsBitmap() - added optional $DLL parameter to all functions - for loading resources from external EXE,DLL files - fixed previous limitation in _ResourceSaveToFile() - now supports also RT_BITMAP type - new examples in resource_test.au3 2008-05-02 - added new RT,SND constants - fixed bad order of parameters ResName x ResType in FindResourceExA (thanks SmOke_N) - added DeleteObject of oldBmp from STM_SETIMAGE in _SetBitmapToCtrl (thanks ProgAndy) - added settinng SS_BITMAP style to control before STM_SETIMAGE in_SetBitmapToCtrl (support for labels) 2008-04-24 - added support for JPG,GIF,PNG in _ResourceSetImageToCtrl() using GDI+ - thanks ProgAndy - reverted all examples back from #AutoIt3Wrapper_Res_File_Add= to#AutoIt3Wrapper_run_after=ResHacker.exe -add - updated both ZIP archives 2007-10-16 - added _ResourcePlaySound() - thanks Larry - corrected local declaration of $struxt - was problem when Opt("MustDeclareVars",1) - updated resource_test.au3 and resource.au3 in resource_au3.zip 2007-09-14 - added optional parameter $CreatePath in _ResourceSaveToFile() - updated resource_test.au3 and resource.au3 in resource_au3.zip 2007-09-11 - in examples used new AutoIt3Wrapper directive#AutoIt3Wrapper_Res_File_Add from latest Scite4AutoIt3 (instead of #AutoIt3Wrapper_run_after=ResHacker.exe -add ...) - updated resource_test.au3 and resource_test_ie.au3 in resource_au3.zip 2007-09-05 - in #AutoIt3Wrapper_run_after=ResHacker.exe -add ... directive can be resource type in text form -->rcdata instead of 10, bitmap instead of 2 and so on (note: but for htmlmust be used 23 still) - updated only resource_test.au3 in resource_au3.zip 2007-09-04 - added description at top of this topic - added _ResourceSaveToFile() - source is also example for using _ResourceGetAsBytes() - more error checking in UDF and error codes are now differrent todistinguish possible problem - default ResType = 10 ($RT_RCDATA) in all functions - updated both ZIP archives 2007-08-29 - added TODO list - removed not used local variables in _ResourceSetImageToCtrl() - ziparchive not updated yet - revisited WWW links and TODO list and added list of functions 2007-08-10 - first version resource_test_min1.au3 - very simple example script of using UDF #AutoIt3Wrapper_Res_File_Add=image3.jpg, rt_rcdata, TEST_JPG_1 #include "resources.au3" $gui = GUICreate("Data from resources simple example 1",400,150) $pic1 = GUICtrlCreatePic("",0,0,400,150) _ResourceSetImageToCtrl($pic1, "TEST_JPG_1") ; set JPG image to picture control from resource GUISetState(@SW_SHOW) While 1 If GUIGetMsg() = -3 Then Exit WEnd resource_test.au3 - complex example script of using UDF #AutoIt3Wrapper_Res_File_Add=test_1.txt, rt_rcdata, TEST_TXT_1 #AutoIt3Wrapper_Res_File_Add=image1.bmp, rt_bitmap, TEST_BMP_1 #AutoIt3Wrapper_Res_File_Add=image2.bmp, rt_bitmap, TEST_BMP_2 #AutoIt3Wrapper_Res_File_Add=image3.jpg, rt_rcdata, TEST_JPG_3 #AutoIt3Wrapper_Res_File_Add=binary1.dat, rt_rcdata, TEST_BIN_1 #AutoIt3Wrapper_Res_File_Add=C:\WINDOWS\Media\tada.wav, sound, TEST_WAV_1 #include "resources.au3" $gui = GUICreate("Data from resources example",820,400) $pic1 = GUICtrlCreatePic("",0,0,400,300) $pic2 = GUICtrlCreatePic("",400,0,400,150) $pic3 = GUICtrlCreatePic("",400,150,400,150) $pic4 = GUICtrlCreatePic("",600,320,400,100) $label1 = GUICtrlCreateLabel("",20,320,380,100) $label2 = GUICtrlCreateLabel("",400,320,200,100) GUISetState(@SW_SHOW) ; get string from resource $string = _ResourceGetAsString("TEST_TXT_1") GUICtrlSetData($label1, $string) ; set BMP image to picture control from resource bitmap _ResourceSetImageToCtrl($pic1, "TEST_BMP_1", $RT_BITMAP) ; get bitmap from resource (as pointer) $hBmp = _ResourceGet("TEST_BMP_2", $RT_BITMAP) ; and use it for whatever you like _SetBitmapToCtrl($pic2, $hBmp) ; set JPG image to picture control from resource _ResourceSetImageToCtrl($pic3, "TEST_JPG_3") ; set image to picture control from external DLL resource _ResourceSetImageToCtrl($pic4, "#14355", $RT_BITMAP, @SystemDir & "\shell32.dll") ; get/use picture from resources as hImage type $size1 = _ResourceGetImageSize("TEST_BMP_1", $RT_BITMAP) $size2 = _ResourceGetImageSize("TEST_JPG_3") GUICtrlSetData($label2, $size1 & @CRLF & $size2) ; save binary data or another type (image) from resource to file and get its size in bytes $size1 = _ResourceSaveToFile(@ScriptDir & "\binary_data1.dat", "TEST_BIN_1") $size2 = _ResourceSaveToFile(@ScriptDir & "\binary_data2.bmp", "TEST_BMP_1", $RT_BITMAP) ; save binary data from resource to file (create not existing directory) _ResourceSaveToFile("C:\Dir1\SubDir2\binary_data1.dat", "TEST_BIN_1", $RT_RCDATA, 0, 1) _ResourceSaveToFile("C:\Dir1\SubDir2\binary_data2.bmp", "TEST_BMP_1", $RT_BITMAP, 0, 1) ; play WAV from resource (sync/async) _ResourcePlaySound("TEST_WAV_1") _ResourcePlaySound("TEST_WAV_1", $SND_ASYNC) While 1 If GUIGetMsg() = -3 Then Exit WEnd Func _ResourceGetImageSize($ResName, $ResType = 10) ; $RT_RCDATA = 10 ; get/use picture from resources as hImage type $hImage = _ResourceGetAsImage($ResName, $ResType) $width = _GDIPlus_ImageGetWidth ($hImage) $height = _GDIPlus_ImageGetHeight($hImage) Return "Size of " & $ResName & " is: " & $width & "x" & $height EndFunc resources.zip - UDF + examples + sample resource data for examples Previous downloads: 7195 resources.zip
    1 point
  2. List all the unique variables in an Au3 script. #include <Array.au3> Example() Func Example() ; Au3 Script. Local Const $sFilePath = @ScriptFullPath ; Read the filepath. Local $sData = FileRead($sFilePath) Local $aVariables = _GetUniqueVariableNames($sData) ; Get a list of unique variables used in the Au3 script. _ArrayDisplay($aVariables) EndFunc ;==>Example #Obfuscator_Off Func _AssociativeArray_Startup(ByRef $aArray, $fIsCaseSensitive = False) ; Idea from MilesAhead. Local $fReturn = False $aArray = ObjCreate('Scripting.Dictionary') ObjEvent('AutoIt.Error', '__AssociativeArray_Error') If IsObj($aArray) Then $aArray.CompareMode = Int(Not $fIsCaseSensitive) $fReturn = True EndIf Return $fReturn EndFunc ;==>_AssociativeArray_Startup #Obfuscator_On Func _GetUniqueVariableNames($sData, $fIsCount = Default) ; Return zeroth index with count. _StripStringLiterals($sData) ; Strip string literals, so they don't display possible variables matches. Local $aVariables = StringRegExp($sData, '(\$\w+)', 3), $hVariables = 0 _AssociativeArray_Startup($hVariables) If $fIsCount Then $hVariables('Count') = 'Count' For $i = 0 To UBound($aVariables) - 1 $hVariables($aVariables[$i]) = $aVariables[$i] Next $aVariables = $hVariables.Items() If $fIsCount Then $aVariables[0] = UBound($aVariables) - 1 Return $aVariables EndFunc ;==>_GetUniqueVariableNames Func _StripStringLiterals(ByRef $sData) $sData = StringRegExpReplace($sData, '([''"])\V*?\1', '') ; Strip string literals. By PhoenixXL & guinness. EndFunc ;==>_StripStringLiterals
    1 point
  3. I think I figured out what the issue is with the browser tool icon. If you specifically set the icon image in the creation of the control it works fine. But if the filename parameter of the function is blank, GUICtrlSetImage won't update it later. It obviously worked before, but not now. I'm wondering if something changed from when this first came out until now that causes this. EDIT: I figured I should put the corrected code that works with 3.3.8.1 and 3.3.9.4 ; Browse Tool Group GUICtrlCreateGroup('Browse Tool', 313, 7, 98, 104) If Not @Compiled Then $Icon[0] = GUICtrlCreateIcon(@ScriptDir & '\Resources\202.ico', 0, 330, 30, 64, 64) Else $Icon[0] = GUICtrlCreateIcon(@ScriptFullPath, 202, 330, 30, 64, 64) EndIf _SetStyle(-1, $WS_TABSTOP, 0) If you search for the Browse Tool text in the script, and change the code from below the CreateGroup function to just before the Info Group comment, it should work. EDIT 2: I tried running the original code in 3.3.6.1 and it worked fine, so it's an issue with AutoIt versions above that.
    1 point
  4. Get all includes used in a Au3 Script file. #include <Array.au3> #include <Constants.au3> #include <WinAPIEx.au3> ; By Yashied. Example() Func Example() ; Au3 Script. Local Const $sFilePath = @ScriptFullPath ; Create a string variable to hold includes found. Local $sIncludeString = '' Local $hTimer = TimerInit() If _GetIncludes($sFilePath, $sIncludeString) Then ConsoleWrite(TimerDiff($hTimer) & @CRLF) ; Split the string. Local Const $aIncludes = StringSplit($sIncludeString, '|') _ArrayDisplay($aIncludes) EndIf EndFunc ;==>Example Func _GetIncludes($sFilePath, ByRef $sIncludeString) Local Static $iRecursionCall = 0, _ $sIncludePath = _WinAPI_PathRemoveFileSpec(@AutoItExe) & '\Include', $sUserIncludePath = '' If Not $iRecursionCall Then If $sUserIncludePath = '' Then $sUserIncludePath = RegRead('HKEY_CURRENT_USER\SOFTWARE\AutoIt v3\AutoIt', 'Include') If $sUserIncludePath = '' Then $sUserIncludePath = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt', 'Include') EndIf If Not ($sUserIncludePath = '') Then If StringLeft($sUserIncludePath, 1) == ';' Then $sUserIncludePath = StringTrimLeft($sUserIncludePath, 1) EndIf If Not (StringRight($sUserIncludePath, 1) == ';') Then $sUserIncludePath &= ';' EndIf EndIf EndIf $sIncludeString &= $sFilePath & '|' EndIf Local Const $sFileFolder = _WinAPI_PathRemoveFileSpec($sFilePath) ; StringLeft($sFilePath, StringInStr($sFilePath, '\', Default, -1) - 1) Local $fFileExists = False, _ $iAutoItInclude = 1 Local Const $aFilePaths[2] = [$sFileFolder, $sIncludePath] Local $aArray = StringRegExp(FileRead($sFilePath), '(?im)^#include\h*([<"''][^*?"''<>|]+)', 3) For $i = 0 To UBound($aArray) - 1 Switch StringLeft($aArray[$i], 1) Case '<' ; AutoIt includes, Registry, Relative path. $iAutoItInclude = 1 Case '''', '"' ; Relative path, Registry, AutoIt includes. $iAutoItInclude = 0 EndSwitch $aArray[$i] = StringStripWS(StringTrimLeft($aArray[$i], 1), $STR_STRIPLEADING + $STR_STRIPTRAILING) $fFileExists = FileExists($aArray[$i]) If Not (StringMid($aArray[$i], 2, 2) == ':\') Or Not $fFileExists Then $fFileExists = FileExists($aFilePaths[$iAutoItInclude] & '\' & $aArray[$i]) If $fFileExists Then $aArray[$i] = $aFilePaths[$iAutoItInclude] & '\' & $aArray[$i] Else $aIncludesSplit = StringSplit($sUserIncludePath & $aFilePaths[Int(Not $iAutoItInclude)], ';') For $j = 1 To $aIncludesSplit[0] $aIncludesSplit[$j] = _WinAPI_PathRemoveBackslash($aIncludesSplit[$j]) $aArray[$i] = $aIncludesSplit[$j] & '\' & $aArray[$i] $aArray[$i] = _WinAPI_GetFullPathName($aArray[$i]) $fFileExists = FileExists($aArray[$i]) If $fFileExists Then ExitLoop EndIf Next EndIf EndIf If $fFileExists And Not StringInStr('|' & $sIncludeString, '|' & $aArray[$i] & '|') Then $sIncludeString &= $aArray[$i] & '|' $iRecursionCall += 1 _GetIncludes($aArray[$i], $sIncludeString) $iRecursionCall -= 1 EndIf Next If Not $iRecursionCall Then $sIncludeString = StringTrimLeft($sIncludeString, StringInStr($sIncludeString, '|', Default, 1)) ; Remove the main script file. $sIncludeString = StringTrimRight($sIncludeString, StringLen('|')) EndIf Return Not ($sIncludeString == '') EndFunc ;==>_GetIncludes
    1 point
  5. 1 point
  6. Melba23

    OnEvent für ListView

    Sentan, Here is how to detect doubleclicks on ListView items - whether created by the native or UDF commands. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> ; Set flag to indicate double click in ListView Global $fDblClk = False $Gui = GUICreate("Test", 400, 250) ; This works with either type of ListView ;#cs $hListView = GUICtrlCreateListView("Items", 2, 2, 220, 196) _GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE_USEHEADER) GUICtrlCreateListViewItem("Item 1", $hListView) GUICtrlCreateListViewItem("Item 2", $hListView) GUICtrlCreateListViewItem("Item", $hListView) GUICtrlCreateListViewItem("Item 4", $hListView) ;#ce #cs $hListView = _GUICtrlListView_Create($Gui, "Items", 2, 2, 220, 196, $LVS_REPORT) _GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_AddItem($hListView, "Item 1",0) _GUICtrlListView_AddItem($hListView, "Item 2",2) _GUICtrlListView_AddItem($hListView, "Item 3",1) _GUICtrlListView_AddItem($hListView, "Item 4",3) #ce GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch ; If an item was double clicked If $fDblClk Then $fDblClk = False $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) ConsoleWrite(_GUICtrlListView_GetItemText($hWndListView, _GUICtrlListView_GetSelectedIndices($hWndListView)) & @CRLF) EndIf WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_DBLCLK $fDblClk = True EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFuncIf you want to detect clicks, just change the $NM_DBLCLK to $NM_CLICK. But I recommend sticking with the doubleclick - the ListView uses single clicks to set the selected item and I have found that the clicks are sometimes eaten and not passed to the handler. If you are not very used to using GUIRegisterMsg, could I recommend the GUIRegisterMsg tutorial in the Wiki. M23
    1 point
  7. Hello, I try a problem with my script for simple login, I added a script of a button, that when the button is clicked, open my site The script is right, the problem and that it does not work Look Script : #include <ButtonConstants.au3> #include <GUIConstantsEx.au3>; #include <EditConstants.au3> $Form1 = GUICreate("Login", 400, 250, -1, -1) ; begining of Login $PASSWORD = GUICtrlCreateInput("", 65, 167, 220, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $ButtonOk = GUICtrlCreateButton("&OK", 200, 220, 75, 25, 0) $ButtonCancel = GUICtrlCreateButton("&Cancel", 280, 220, 75, 25, 0) $passwordlabel = GUICtrlCreateLabel("Password:", 8, 172, 50, 17) $usernamelabel = GUICtrlCreateLabel("Username:", 8, 143, 52, 17) $USERNAME = GUICtrlCreateInput("", 65, 144, 220, 21) Global $url = "http://forumgohc.freehostia.com/forum/index.php?action=register" ; here button that not work $Forum = GUICtrlCreateButton("Cadastre-se no Forum",10,220,110,25) Guictrlsetonevent(-1,"_website") GUICtrlCreateGroup('',10,2,380,100) GUICtrlCreateLabel('Terms of use of this Software',30,10,340,18) GUICtrlSetColor(-1, 0x0012FF) GUICtrlSetFont(-1,12,400) GUICtrlCreateLabel('',30,28,340,18) GUICtrlSetFont(-1,12,400) GUICtrlCreateLabel('',30,46,340,18) GUICtrlSetFont(-1,12,400) GUICtrlCreateLabel('',30,64,340,18) GUICtrlSetFont(-1,12,400) GUICtrlCreateLabel('',30,82,340,18) GUICtrlSetFont(-1,12,400) GUICtrlCreateGroup('',-99,-99,1,1) GUICtrlSetBkColor(-1,0x000000) GUISetState(@SW_SHOW) While 1 $MSG = GUIGetMsg() Switch $MSG Case $ButtonOk If VerifyLogin(GUICtrlRead($USERNAME),GUICtrlRead($PASSWORD)) = 1 Then GUIDelete($Form1) MsgBox(-1,"Logado com Sucesso","Login Succ..") RunP() Else MsgBox(-1,"Error"," Username ou Senha está incorreto, Tente denovo") EndIf Case -3 Exit Case $ButtonCancel Exit EndSwitch WEnd Func _website() ; part of script for run ShellExecute($url) Endfunc Func VerifyLogin($USERNAME,$PASSWORD) If $USERNAME = "your username here" And $PASSWORD = "your pass here" Then Return 1 Else Return 0 EndIf EndFunc ; End login Func Runp() ;Your Code begining here EndFunc Func onautoitexit() Exit EndFunc ;==>onautoitexit Awaiting Answers
    1 point
  8. thanks. this is great. I could make software for disabled people using this code. thanks
    1 point
×
×
  • Create New...