Leaderboard
Popular Content
Showing content with the highest reputation on 11/22/2012 in all areas
-
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.zip1 point
-
LAST VERSION - 3.8 03-Jul-12 This library contains the WinAPI functions are not included for unknown reasons to the native AutoIt WinAPI library. I use this UDF in nearly all of my programs, and decided to share it with the AutoIt community. I agree that over time some of these functions will be part of the native AutoIt library, but still... The library includes some undocumented, but useful functions (eg _WinAPI_GetFontResourceInfo()). The library also contains all the necessary constants to work with the appropriate functions. Most functions from this UDF intended for experienced users, but beginners will find the same lot of useful information for yourself. I will be to periodically add new functions to the library. The archive contains WinAPIEx library, and as usual an excellent examples from me. Some examples I took from this forum and to simplify them for better understanding. For those who use SciTE (full version) I have prepared the au3.userudfs.properties and au3.user.calltips.api files to highlight functions from this UDF in your scripts. Just copy this files to ...SciTEProperties and ...SciTEAPI, respectively. I hope this UDF will be useful for many as for me. I look forward to any feedback and suggestions. Maybe somebody wants to add new WinAPI functions? Credits Available functions Files to download WinAPIEx UDF v3.8 for AutoIt 3.3.6.1 Previous downloads: 27953 WinAPIEx UDF v3.8 for AutoIt 3.3.8.x Previous downloads: 148501 point
-
Hello, I just added a few scripts together to get a function for creating a resource dll. You can add icons und pictures to the library for now. I hope you like it. #include <WinAPIEx.au3> #include <Array.au3> #include <APIConstants.au3> #include <GDIPlus.au3> #include <Memory.au3> #include <StaticConstants.au3> Global $sDLL = @ScriptDir & "Resourcen.dll" Global $sTempFile, $aFiles[1] Global Const $tagICONDIRENTRY = "BYTE bWidth;BYTE bHeight;BYTE bColorCount;BYTE bReserved;WORD wPlanes;WORD wBitCount;DWORD dwBytesInRes;DWORD dwImageOffset" Global Const $tagGRPICONDIRENTRY = "BYTE bWidth;BYTE bHeight;BYTE bColorCount;BYTE bReserved;WORD wPlanes;WORD wBitCount;DWORD dwBytesInRes;WORD nID" Global Const $SS_REALSIZECONTROL = 0x40 While 1 $sTempFile = FileOpenDialog("Select resource files", @ScriptDir, "All files (*.*)|Icons (*.ico)|Bitmaps (*.bmp)", 3) If @error Then ExitLoop If $aFiles[0] = "" Then $aFiles[0] = $sTempFile Else _ArrayAdd($aFiles, $sTempFile) EndIf WEnd _CreateResourceDLL($sDLL, $aFiles) Global $aIcon = _ArrayFindAll($aFiles, ".ico", 0, 0, 0, 1, 0) Global $aBitmap = _ArrayFindAll($aFiles, ".bmp", 0, 0, 0, 1, 0) Global $aJpg = _ArrayFindAll($aFiles, ".jpg", 0, 0, 0, 1, 0) GUICreate("Resource DLL", 800, 800) If IsArray($aIcon) Then For $i = 0 To UBound($aIcon) - 1 GUICtrlCreateIcon($sDLL, $aFiles[$aIcon[$i]], 10, 10 + 40 * $i, 32, 32, $SS_SUNKEN) GUICtrlCreateLabel($aFiles[$aIcon[$i]], 50, 10 + 40 * $i, 120, 32, $SS_CENTERIMAGE) Next EndIf If IsArray($aBitmap) Then For $i = 0 To UBound($aBitmap) - 1 GUICtrlCreatePic("", 200, 30 + 120 * $i, 100, 100, BitOR($SS_REALSIZECONTROL, $SS_SUNKEN)) _SetImagefromResource(-1, $aFiles[$aBitmap[$i]], $sDLL, $RT_BITMAP) GUICtrlCreatePic("", 310, 30 + 120 * $i, 100, 100, BitOR($SS_CENTERIMAGE, $SS_SUNKEN)) _SetImagefromResource(-1, $aFiles[$aBitmap[$i]], $sDLL, $RT_BITMAP) GUICtrlCreateLabel($aFiles[$aBitmap[$i]], 200, 10 + 120 * $i, 120, 20, 0x200) Next EndIf If IsArray($aJpg) Then For $i = 0 To UBound($aJpg) - 1 GUICtrlCreatePic("", 440, 30 + 120 * $i, 100, 100, BitOR($SS_REALSIZECONTROL, $SS_SUNKEN)) _SetImagefromResource(-1, $aFiles[$aJpg[$i]], $sDLL, $RT_RCDATA) GUICtrlCreatePic("", 550, 30 + 120 * $i, 100, 100, BitOR($SS_CENTERIMAGE, $SS_SUNKEN)) _SetImagefromResource(-1, $aFiles[$aJpg[$i]], $sDLL, $RT_RCDATA) GUICtrlCreateLabel($aFiles[$aJpg[$i]], 440, 10 + 120 * $i, 120, 20, 0x200) Next EndIf GUISetState() Do Until GUIGetMsg() = -3 Func _CreateResourceDLL($sDLL, ByRef $aFiles) If Not IsArray($aFiles) Or $aFiles[0] = "" Then Return SetError(1, 0, 0) _CreateEmptyDLL($sDLL) Local $hUpdate = _WinAPI_BeginUpdateResource($sDLL, 0) If @error Then Return SetError(2, 0, 0) Local $hFile, $bFile, $lFile, $tFile, $pFile, $sName, $sExt, $RT_TYPE, $Resource_ID = 0 Local $tICONDIR, $tICONDIRENTRY, $tGRPICONDIR, $pGRPICONDIR Local $Temp Local $nSize For $i = 0 To UBound($aFiles) - 1 If Not FileExists($aFiles[$i]) Then SetError(3, 0, 0) $hFile = FileOpen($aFiles[$i], 0) $bFile = FileRead($hFile) FileClose($hFile) $lFile = FileGetSize($aFiles[$i]) $tFile = DllStructCreate("char[" & $lFile & "]") DllStructSetData($tFile, 1, $bFile) $pFile = DllStructGetPtr($tFile) $sName = StringUpper(StringTrimLeft($aFiles[$i], StringInStr($aFiles[$i], "", 0, -1))) $sExt = StringTrimLeft($aFiles[$i], StringInStr($aFiles[$i], ".", 0, -1)) $aFiles[$i] = $sName Switch $sExt Case "bmp" $RT_TYPE = $RT_BITMAP $lFile = $lFile - 14 $pFile = Ptr($pFile + 14) Case "ico" $RT_TYPE = $RT_ICON Local $tB_Input_Header = DllStructCreate("short res;short type;short ImageCount;char rest[" & $lFile - 5 & "]", $pFile) Local $pB_Input_Header = DllStructGetPtr($tB_Input_Header) Local $IconType = DllStructGetData($tB_Input_Header, "Type") Local $IconCount = DllStructGetData($tB_Input_Header, "ImageCount") Local $tB_IconGroupHeader = DllStructCreate("short Res;short Type;short ImageCount;char Rest[" & $IconCount * 14 & "]") Local $pB_IconGroupHeader = DllStructGetPtr($tB_IconGroupHeader) DllStructSetData($tB_IconGroupHeader, "Res", 0) DllStructSetData($tB_IconGroupHeader, "Type", $IconType) DllStructSetData($tB_IconGroupHeader, "ImageCount", $IconCount) For $X = 1 To $IconCount Local $pB_Input_IconHeader = DllStructGetPtr($tB_Input_Header, 4) + ($X - 1) * 16 Local $tB_Input_IconHeader = DllStructCreate($tagICONDIRENTRY, $pB_Input_IconHeader) Local $IconWidth = DllStructGetData($tB_Input_IconHeader, "bWidth") Local $IconHeigth = DllStructGetData($tB_Input_IconHeader, "bHeight") Local $IconColors = DllStructGetData($tB_Input_IconHeader, "bColorCount") Local $IconPlanes = DllStructGetData($tB_Input_IconHeader, "wPlanes") Local $IconBitPerPixel = DllStructGetData($tB_Input_IconHeader, "wBitCount") Local $IconImageSize = DllStructGetData($tB_Input_IconHeader, "dwBytesInRes") Local $IconImageOffset = DllStructGetData($tB_Input_IconHeader, "dwImageOffset") $pB_IconGroupHeader = DllStructGetPtr($tB_IconGroupHeader, 4) + ($X - 1) * 14 Local $tB_GroupIcon = DllStructCreate($tagGRPICONDIRENTRY, $pB_IconGroupHeader) DllStructSetData($tB_GroupIcon, "bWidth", $IconWidth) DllStructSetData($tB_GroupIcon, "bHeigth", $IconHeigth) DllStructSetData($tB_GroupIcon, "bColorCount", $IconColors) DllStructSetData($tB_GroupIcon, "bReserved", 0) DllStructSetData($tB_GroupIcon, "wPlanes", $IconPlanes) DllStructSetData($tB_GroupIcon, "wBitCount", $IconBitPerPixel) DllStructSetData($tB_GroupIcon, "dwBytesInRes", $IconImageSize) $Resource_ID += 1 DllStructSetData($tB_GroupIcon, "nID", $Resource_ID) Local $PB_IconData = DllStructGetPtr($tB_Input_Header) + $IconImageOffset _WinAPI_UpdateResource($hUpdate, $RT_TYPE, $Resource_ID, Int("0x" & @OSLang), $PB_IconData, $IconImageSize) Next $pB_IconGroupHeader = DllStructGetPtr($tB_IconGroupHeader) Case "jpg", "jpeg", "gif" $RT_TYPE = $RT_RCDATA ;~ Case "cur" ;~ $RT_TYPE = $RT_CURSOR ;~ Case "txt", "au3", "ini", "c", "cpp", "h" ;~ $RT_TYPE = $RT_STRING Case Else ContinueLoop EndSwitch If $RT_TYPE = $RT_ICON Then _WinAPI_UpdateResource($hUpdate, $RT_GROUP_ICON, $sName, Int("0x" & @OSLang), $pB_IconGroupHeader, DllStructGetSize($tB_IconGroupHeader)) Else $Resource_ID += 1 _WinAPI_UpdateResource($hUpdate, $RT_TYPE, $sName, Int("0x" & @OSLang), $pFile, $lFile) EndIf ;~ If @error Then SetError(4, $i, 0) $tFile = 0 Next _WinAPI_EndUpdateResource($hUpdate) If @error Then Return SetError(5, @extended) Return 1 EndFunc ;==>_CreateResourceDLL Func _CreateEmptyDLL($sFilePath) Local $bEmptyDll = _Empty_DLL() Local $hFile = FileOpen($sFilePath, 18) ;Binary mode + Write mode (Erase old content!) FileWrite($hFile, $bEmptyDll) FileClose($hFile) EndFunc ;==>_CreateEmptyDLL Func _Empty_DLL() Local $Empty_DLL $Empty_DLL &= 'TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAATAEFAP6WNU0AAAAAAAAAAOAADiELAQIyAAQAAAAGAAAAAAAAABAAAAAQAAAAMAAAAAAAEAAQAAAAAgAABAAAAAAAAAAEAAAAAAAAAABgAAAABAAAAAAAAAMAAAAAABAAABAAAAAAEAAAEAAAAAAAABAAAAAAAAAAAAAAAAAwAAA8AAAAAFAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAC' $Empty_DLL &= 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABUMAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC5jb2RlAAAAYwAAAAAQAAAAAgAAAAQAAAAAAAAAAAAAAAAAACAAAGAudGV4dAAAABgAAAAAIAAAAAIAAAAGAAAAAAAAAAAAAAAAAAAgAABgLmRhdGEAAADMAAAAADAAAAACAAAACAAAAAAAAAAAAAAAAAAAQAAAwC5yZWxvYwAAIAAAAABAAAAAAgAAAAoAAAAAAAAAAAAAAAAAAEAAAEIucnNyYwAAABAAAAAAUAAAAAIAAAAMAAAAAAAAAAAAAAAAAABAAAB' $Empty_DLL &= StringRepeat("A", 598) & 'IN8JAgBdQ6LRCQEo8QwABDoIgAAAIN8JAgCdQCDfCQIAHUF6CkAAACDfCQIA3UAuAEAAADCDABoAAAAAGgAEAAAaAAAAADouw8AAKPAMAAQw+gMAAAA/zXAMAAQ6KsPAADDww' $Empty_DLL &= StringRepeat("A", 550) & '/yVUMAAQ/yVcMAAQ/yVgMAAQ/yVkMAAQ' $Empty_DLL &= StringRepeat("A", 651) $Empty_DLL &= '8MAAAAAAAAAAAAAB2MAAAVDAAAEQwAAAAAAAAAAAAALIwAABcMAAAAAAAAAAAAAAAAAAAAAAAAAAAAABsMAAAAAAAAIIwAACQMAAAnjAAAAAAAABsMAAAAAAAAIIwAACQMAAAnjAAAAAAAACZAm1lbXNldAAATVNWQ1JULmRsbAAApAJIZWFwQ3JlYXRlAAClAkhlYXBEZXN0cm95APoBR2V0TW9kdWxlSGFuZGxlVwAAS0VSTkVMMzIuZGxs' $Empty_DLL &= StringRepeat("A", 431) & 'QAAAQAAAADDBMMFgwAAAAIAAAEAAAAAIwCDAOMBQw' $Empty_DLL &= StringRepeat("A", 645) & 'BSXNk0DAAc' $Empty_DLL &= StringRepeat("A", 668) & '=' Return Binary(_Base64Decode($Empty_DLL)) EndFunc ;==>_Empty_DLL Func _Base64Decode($input_string) Local $struct = DllStructCreate("int") Local $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $input_string, "int", 0, "int", 1, "ptr", 0, "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $input_string, "int", 0, "int", 1, "ptr", DllStructGetPtr($a), "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(2, 0, "") Return DllStructGetData($a, 1) EndFunc ;==>_Base64Decode Func StringRepeat($sChar, $nCount) $tBuffer = DllStructCreate("char[" & $nCount + 1 & "]") DllCall("msvcrt.dll", "ptr:cdecl", "memset", "ptr", DllStructGetPtr($tBuffer), "int", Asc($sChar), "int", $nCount) Return DllStructGetData($tBuffer, 1) EndFunc ;==>StringRepeat Func _SetImagefromResource($CtrlID, $Resname, $Resfile = -1, $ResType = 10) ;Raupi ;Diese Funktion basiert auf der UDF von Zedna@Autitscript.com und Code von Progandy@AutoIt.de Local Const $IMAGE_BITMAP = 0 Local Const $STM_SETIMAGE = 0x0172 Local $hmod, $hwnd, $InfoBlock, $ResSize, $Mem, $pMem, $dll, $dll2, $hData, $pData, $pStream, $ret, $hBitmap, $pBitmap If $Resfile = -1 Then $hmod = _WinAPI_GetModuleHandle("") Else $hmod = _WinAPI_LoadLibrary($Resfile) EndIf If $ResType = $RT_BITMAP Then $hBitmap = _WinAPI_LoadImage($hmod, $Resname, $IMAGE_BITMAP, 0, 0, 0) If @error Then Return SetError(1, 0, 0) $hwnd = GUICtrlGetHandle($CtrlID) If $hwnd = 0 Then Return SetError(2, 0, 0) DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hwnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap) If @error Then Return SetError(3, 0, 0) Else $InfoBlock = DllCall("kernel32.dll", "int", "FindResourceA", "int", $hmod, "str", $Resname, "long", $ResType) If @error Then Return SetError(4, 0, 0) $InfoBlock = $InfoBlock[0] If $InfoBlock = 0 Then Return SetError(5, 0, 0) $ResSize = DllCall("kernel32.dll", "dword", "SizeofResource", "int", $hmod, "int", $InfoBlock) If @error Then Return SetError(6, 0, 0) $ResSize = $ResSize[0] If $ResSize = 0 Then Return SetError(7, 0, 0) $Mem = DllCall("kernel32.dll", "int", "LoadResource", "int", $hmod, "int", $InfoBlock) If @error Then Return SetError(8, 0, 0) $Mem = $Mem[0] If $Mem = 0 Then Return SetError(9, 0, 0) $pMem = DllCall("kernel32.dll", "int", "LockResource", "int", $Mem) If @error Then Return SetError(8, 0, 0) $pMem = $pMem[0] If $pMem = 0 Then Return SetError(10, 0, 0) If $Resfile <> -1 Then DllCall("Kernel32.dll", "int", "FreeLibrary", "str", $hmod) $hData = _MemGlobalAlloc($ResSize, 2) $pData = _MemGlobalLock($hData) _MemMoveMemory($pMem, $pData, $ResSize) _MemGlobalUnlock($hData) $ret = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "int", $hData, "long", 1, "Int*", 0) $pStream = $ret[3] _GDIPlus_Startup() $pBitmap = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromStream", "ptr", $pStream, "int*", 0) $pBitmap = $pBitmap[2] $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap) $hwnd = GUICtrlGetHandle($CtrlID) If $hwnd = 0 Then Return SetError(11, 0, 0) DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hwnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap) If @error Then Return SetError(12, 0, 0) _GDIPlus_BitmapDispose($pBitmap) _GDIPlus_Shutdown() $dll = DllStructCreate("Uint", $pStream) $dll2 = DllStructCreate("uInt", DllStructGetData($dll, 1) + 8) DllCall("", "UInt", DllStructGetData($dll2, 1), "UInt", $pStream) _WinAPI_DeleteObject($pStream) $pStream = 0 _MemGlobalFree($hData) If $Resfile <> -1 Then _WinAPI_FreeLibrary($hmod) EndIf EndFunc ;==>_SetImagefromResource Download au3 Download au3 with function for icons, pictures(bmp, jpg, gif), fonts(only ttf tested) Download new au3 without temp file creating in example part1 point
-
Mouseclick
232showtime reacted to JohnOne for a topic
You do not need coordinates, they are optional and very rarely used, just leave them out. The control ID is what you have wrong in your code. Use window info and look at the control tab, advanced class.1 point -
Hi, I'm late to the party I see, but here is some additional information. The circumflex/caret has 3 functions in a regular expression, depending on the mode and position in the pattern. (1) By default it matches the beginning of the subject, same as \A. ($ will match the end of subject, same as \z) (2) If multiline mode is enabled, by setting the m flag, it matches the beginning of the subject and the start of a new line ($ will match the end of subject and end of line). (3) If it is used in a character class it only has a special meaning if it is the first character in the class. It will then negate the class, i.e. the class will match any character not in it. If you want to match a literal circumflex in a pattern it must be escaped (with a backslash, \^), in a character class it only needs to be escaped if it is the first character because it has no special meaning at any other position. It is also a zero-width expression, meaning it will match the position of a character (start of subject or newline) but not the character itsef, i.e. it will not include/return the character(s) in the match. ; normal mode, beginning of subject anchor #cs - Match a string of only word characters (word characters are A-Z, a-z, 0-9 and _ (underscore). Equivalent to class [A-Za-z0-9_]) ^ the start of the subject \w+ one or more word characters $ the end of the subject #ce If StringRegExp("ABCD", '^\w+$') Then ConsoleWrite("The string consists only of ""word"" characters." & @LF) Else ConsoleWrite("The string does NOT consist of only ""word"" characters." & @LF) EndIf ; multiline mode, beginning of subject or newline #cs - Match full line comments (?m) m flag, enables multiline mode ^ the beginning of the subject or the beginning of a newline \h*; 0 or more horizontal whitespaces followed by a semicolon (?: open non-capturing group [[:punct:]]\h* non-alphanumeric priniting character followed by 0 or more horizontal whitespaces )? close non-capturing group, match group 0 or 1 times (? makes the group optional) ( open capturing group [^\r\n]* match any character except for \r (CR) or \n (LF) 0 or more times (^ negates the class) ) close capturing group #ce $aMatches = StringRegExp(FileRead(@ScriptFullPath), '(?m)^\h*;(?:[[:punct:]]\h*)?([^\r\n]*)', 3) For $i = 0 To UBound($aMatches) - 1 Step 1 ConsoleWrite("COMMENT: " & $aMatches[$i] & @LF) Next To answer your question more directly... The beginning of a subject/string is always at position 0 (before the first character). The beginning of a line is either the beginning of the subject or directly after a newline (CRLF/CR/LF). Example: #include <Array.au3> ; subject $sString = "This is an example subject." & @LF & "Made up of two lines." ; ^ singleline mode, match the first 4 characters of the subject #cs ^ start of the subject .... followed by 4 characters #ce $aMatches = StringRegExp($sString, "^....", 3) _ArrayDisplay($aMatches, "Singleline") ; ^ multiline mode, match the first 4 characters of a line #cs (?m) m flag, enables multiline mode ^ start of the subject or line .... followed by 4 characters #ce $aMatches = StringRegExp($sString, "(?m)^....", 3) _ArrayDisplay($aMatches, "Multiline") ; singleline mode reproducer, match the first 4 characters of a subject #cs (....) capture 4 characters that are not newline characters [\s\S]* match any character (space and non-space) 0 or more times #ce $aMatches = StringRegExp($sString, "(....)[\s\S]*", 3) _ArrayDisplay($aMatches, "Singleline Reproducer") ; multiline mode reproducer, match the first 4 characters of a line #cs (?: open non-capturing group \A|\r\n|\r|\n match the start of the subject or newline characters ) close non-capturing group (....) capture 4 characters that are not newline characters #ce $aMatches = StringRegExp($sString, "(?:\A|\r\n|\r|\n)(....)", 3) _ArrayDisplay($aMatches, "Multiline Reproducer") ; advanced multiline mode reproducer, match the first 4 characters of a line #cs (?<= open positive lookbehind \A|\r\n|\r|\n match the start of the subject or newline characters ) close positive lookbehind .... match (and capture as global match) 4 characters that are not newline characters #ce $aMatches = StringRegExp($sString, "(?<=\A|\r\n|\r|\n)....", 3) _ArrayDisplay($aMatches, "Advanced Multiline Reproducer") Edit: Fixed spacing of comments Edit2: added "word" character description Edit3: added more direct answer1 point
-
WindowFromPoint should be fed a [$tag]POINT structure instead. This is how it should be done. #include <Misc.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> HotKeySet('{ESC}', '_Exit') Example() Func Example() Local $hWnd = 0, $hWnd_Previous = 0, $tGetMousePos = 0 ; Declaring variables in the loop will slow it down. While 1 $tGetMousePos = _WinAPI_GetMousePos() $hWnd = _WinAPI_WindowFromPoint($tGetMousePos) If $hWnd <> $hWnd_Previous Then $hWnd_Previous = $hWnd ConsoleWrite('Handle:' & $hWnd & ', ControlID: ' & _WinAPI_GetDlgCtrlID($hWnd) & @CRLF) TrayTip('', $hWnd, 2) EndIf Sleep(20) WEnd EndFunc ;==>Example Func _Exit() Exit MsgBox(4096, '', 'Exiting...', 1) EndFunc ;==>_Exit1 point
-
If application is idle for 15 minutes, show a pup up message
stormbreaker reacted to guinness for a topic
I read your function wrong then. This will work for those that don't use Notepad2. Example() Func Example() ; Run Notepad Run("notepad.exe") ; Wait 5 seconds for the Notepad window to appear. Local $hWnd = WinWait('[CLASS:Notepad]', '', 5) WinSetState($hWnd, '', @SW_MINIMIZE) ; Monitor how long a particular window is not active for. WinActiveIdle($hWnd) EndFunc ;==>Example Func WinActiveIdle($sTitle, $sText = Default) ; See syntax for WinWait etc. If $sText = Default Then $sText = '' EndIf Local $hWnd= 0, $hTimer = TimerInit() While 1 Sleep(100) $hWnd = WinActive($sTitle, $sText) If $hWnd Then ; Add MKISH's function here. ExitLoop EndIf WEnd MsgBox(4096, '', 'The program was idle for ' & Int(TimerDiff($hTimer) / 1000) & ' seconds.') EndFunc ;==>WinActiveIdle1 point -
@davidkim Excellent ideas, but how about using the tag [AutoIt ] and even tag [spoiler ] to make the topic more organized and easy to read? JS1 point
-
"Good things come to those who wait!" -_01 point
-
how to : monitor Run button of win32 application
Sonic94168 reacted to JohnOne for a topic
One method I believe could work is monitoring for the window to be active If Primary mouse clicked, find where it was clicked in some fashion. One fashion could be coordinates relative to window, but I believe you could determine the exact control the mouse is over using by Yashied.1 point -
how to : monitor Run button of win32 application
Sonic94168 reacted to Melba23 for a topic
Sonic94168, If you have another of determining that the "Run" button has been pressed then I would suggest you go down that route. Trying to hook into the other app would not be easy, even if it were possible to do so which I am not at all sure would be the case. Have you used the Window Info tool on the app GUI to see if the status box you mention is easily identifiable and so accessible to AutoIt? M231 point