Leaderboard
Popular Content
Showing content with the highest reputation on 04/04/2013 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
-
Resources viewer and compiler. You can drop file (dll, exe ...) on treeview or use menu control to load file, or drop file on executable after compiled or just run and use it as a resource dll compiler. Constructive comments are always welcomed. New script attached (16th April 2009) How to use compiling option: - click on Action menu. - choose Initialize Compiler. - go to menu again and choose Generate Initial DLL - any file that you want to add to your resource dll drop on tree view or use Add Resource button. New window pops up. You need to chose type, name and language of resource. You can choose to use predifined values, only name is required in that case. - when you are done with modifications save new dll file. File menu will have Save as... option - that's it. You have your resource dll compiled with AutoIt Supported resources: - RT_CURSOR - RT_BITMAP - RT_ICON - RT_MENU - RT_DIALOG - RT_STRING - RT_ACCELERATOR - RT_GROUP_CURSOR - RT_GROUP_ICON - RT_VERSION - RT_ANICURSOR - RT_ANIICON - RT_HTML - RT_MANIFEST - AVI (special) - WAV (special) - JPEG (special) - PNG (special) - GIF (special) By supported I mean that resource can be viewed and/or saved. Other resources are shown as hexadecimals, with ASCII character and address display. Download script (zip format due to upload size limit): ResourcesViewerAndCompiler.zip edit: had to remove the old attachment to make more space in my attachment folder.1 point
-
Here We go #include <WinAPI.au3> ;Works for Minimized Hidden and disabled Windows $hWinMain = GUICreate("Test", 500, 100) GUICtrlCreateLabel("This is a Label", 10, 10, 50, 30 ) GUISetState( @SW_MINIMIZE ) $hLabel = _ChildWindowFromPointEx( $hWinMain, 11, 16 ) MsgBox ( 64, "Result:", StringFormat("hWnd: %s\nClass: %s",$hLabel, _WinAPI_GetClassName($hLabel))) GUISetState() While GUIGetMsg()<>-3 Sleep(10) WEnd Func _ChildWindowFromPointEx($hWnd, $iX, $iY, $iFlags = 0) Local $Ret = DllCall('user32.dll', 'hwnd', 'ChildWindowFromPointEx', 'hwnd', $hWnd, 'int', $iX, 'int', $iY, 'uint', $iFlags) If @error Then Return SetError(1, 0, 0) EndIf Return $Ret[0] EndFunc ;==>_WinAPI_ChildWindowFromPointExThumbs up if it helped Regards1 point
-
This is a more appropriate example; #include <Constants.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_GetAncestor(_WinAPI_WindowFromPoint($tGetMousePos), $GA_ROOT) If Not ($hWnd = $hWnd_Previous) Then $hWnd_Previous = $hWnd ConsoleWrite($hWnd & @CRLF) TrayTip('', $hWnd, 2) EndIf Sleep(20) WEnd EndFunc ;==>Example Func _Exit() Exit MsgBox($MB_SYSTEMMODAL, '', 'Exiting...', 1) EndFunc ;==>_Exit I'm not really following your last point, sorry.1 point
-
Search for _WinAPI_WindowFromPoint and search the Examples section for an example by Yashied.1 point
-
Sure, here you go : #include <GuiButton.au3> #include <GuiConstantsEx.au3> #region GUI Local Const $hGUI = GUICreate("MyGUI") Local Const $iBtnElevate = GUICtrlCreateButton("Elevate", 10, 10, 70, 25) _GUICtrlButton_SetShield($iBtnElevate) If IsAdmin() Then GUICtrlSetState($iBtnElevate, $GUI_DISABLE) GUISetState(@SW_SHOW, $hGUI) #endregion While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iBtnElevate ; restart elevated If @Compiled Then ShellExecute(@ScriptFullPath, "", @WorkingDir, "runas") Else ShellExecute(@AutoItExe, '/AutoIt3ExecuteScript "' & @ScriptFullPath & '"', @WorkingDir, "runas") EndIf Exit EndSwitch WEnd This is a simplified script from this UDF : Br, FireFox.1 point
-
#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> GUICreate("Form1", 500, 500, -1, -1) GUICtrlCreatePic("img.bmp", 0, 0, 500, 500) GUICtrlSetState(-1, $GUI_DISABLE) ; DISABLE THE IMAGE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlCreateLabel("Don't tell it before was an image...", 100, 100, 500, 20) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd Next time post your code, here we don't like to lose time specially MVPs...a trasparent label OVER AN IMAGE1 point
-
4cc, This extracts all instances of the test string from the samples you gave: Global $aLines[6] = [5, _ 'net_graph', _ 'net_graph "0"', _ 'net_graph 0', _ 'bind "v" "net_graph 0; buy m4a1; [...]"', _ 'alias +whatever "net_graph 0; net_graph 3; [...]"'] $sTest_String = "net_graph" For $i = 1 To $aLines[0] ; Just for display ConsoleWrite(@CRLF & $aLines[$i] & @CRLF & "Found values: ") ; Extract an array of matching elements $aRet = StringRegExp(StringReplace($aLines[$i], '"', ''), "(?i)(?U)" & $sTest_String & "\s.*(\d)", 3) ; Just for display - show the array elements For $j = 0 To UBound($aRet) - 1 ConsoleWrite($aRet[$j] & " ") Next ConsoleWrite(@CRLF) Next Now as I have no interest in gaming whatsoever, I am withdrawing from this thread. Good luck with the rest of your project. M231 point
-
4cc, Good spot about the multiple returns - adding a space should solve the problem as you have found for yourself. What was wrong with the SRE I used? Your version looks very much more complicated. If you provide a decode of what it is supposed to do I will try and see why it does not do it, although I am far from expert in these beasts. M231 point
-
4cc, Now we have determined that your thread is legal, let us see what we can do to help you. Reading your requirements I believe that getting the downloaded config file into an array would be a sensible first step (_FileReadToArray). You search the array for the elements you wish to check (_ArraySearch) and then use StringRegExpReplace to extract the set value. It is easy to check this value against the valid values associated with that particular key(StringInStr) if we place the key/values into a 2D array as we use the same index to access both. Here is a short example using the example config file to which you linked above: #include <Array.au3> #include <File.au3> ; Get the file onto disk ; Now read it into an array Local $aLines _FileReadToArray("CS.cfg", $aLines) _ArrayDisplay($aLines) ; Just for display purposes ; Create an array to hold the rule set - here we only have 2 rules Local $aRuleSet[2][2] = [["net_graph", "0|1"], _ ["hud_draw", "0|1"]] ; Note use of "|" to delimit valid values ; Now we look for each "rule key" within the file For $iRule = 0 To UBound($aRuleSet) - 1 ; Search for the rule key in the array $iIndex = _ArraySearch($aLines, $aRuleSet[$iRule][0], 0, 0, 0, 1) ; Use the partial search algorithm ; Check we found it If $iIndex <> -1 Then ; Extract the set value $sSetValue = StringRegExpReplace($aLines[$iIndex], '^.*"(.*)".*$', '$1') ; Compare the set value with the legal values in the rule set If StringInStr("|" & $aRuleSet[$iRule][1], "|" & $sSetValue) Then ; Add a leading "|" to the valid results and the set value to cater for multicharacter values $sValid = "Valid" Else $sValid = "Invalid" EndIf MsgBox(0, "Rule Check", "Rule: " & $aRuleSet[$iRule][0] & @CRLF & "set to: " & $sSetValue & @CRLF & @CRLF & "Result: " & $sValid) EndIf NextI hope the comments make it clear what is going on and that it is obvious how to expand the code to check all the rules you require. But do ask if you have any questions. M231 point
-
Zip32
mLipok reacted to Undutchable for a topic
rasim, Your example gives the same results. Maybe we're talking about different things. What I mean is that, INSIDE the zip, the folder structure remains like the source. For example: If I zip the file c:\folder1\subfolder1\teste.txt when opening up the file with WinZip, you will have to navigate the sames levels to get there (folder1 > subfolder1 > teste.txt) I am looking for a way to prevent storing the entire path. Thanks!1 point