Jump to content

guinness

Developers
  • Posts

    19,630
  • Joined

  • Last visited

  • Days Won

    94

Reputation Activity

  1. Like
    guinness got a reaction from argumentum in Help File/Documentation Issues. (Discussion Only)   
    Excellent find. Fixed
  2. Like
    guinness got a reaction from pixelsearch in Help File/Documentation Issues. (Discussion Only)   
    Thanks @pixelsearch. Indeed I double checked and it seems this constant was missing from the list. I have fixed it now.
  3. Thanks
  4. Like
    guinness got a reaction from Netol in Correct way to clear a ListView? [Solved]   
    Retrieve the handle of the ListView using GUICtrlGetHandle($iListView) and then use the handle with _GUICtrlListView_DeleteAllItems()
  5. Thanks
    guinness got a reaction from Parsix in GUIGetBkColor() - Get the background color of the GUI.   
    If you set the GUI background colour with GUISetBkColor() and happen to forget the colour you set it as, then why not try GUIGetBkColor()

    Function:

    #include-once #include <WinAPIGdi.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: GUIGetBkColor ; Description ...: Retrieves the RGB value of the GUI background. ; Syntax ........: GUIGetBkColor($hWnd) ; Parameters ....: $hWnd - A handle of the GUI. ; Return values .: Success - RGB value ; Failure - 0 ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func GUIGetBkColor($hWnd) Local $iColor = 0 If IsHWnd($hWnd) Then Local $hDC = _WinAPI_GetDC($hWnd) $iColor = _WinAPI_GetBkColor($hDC) _WinAPI_ReleaseDC($hWnd, $hDC) EndIf Return $iColor EndFunc ;==>GUIGetBkColor Example use of Function:

    #include <MsgBoxConstants.au3> #include 'GUIGetBkColor.au3' Example() Func Example() Local $hGUI = GUICreate('GUIGetBkColor() Example', 500, 350) GUISetState(@SW_SHOW, $hGUI) Local $aColor = [0x0000FF, 0x8FFF9F, 0xEC4841, 0xB0E35D, 0x440BFD] ; Random colour array. Local $iColor = 0 For $i = 0 To UBound($aColor) - 1 GUISetBkColor($aColor[$i]) Sleep(20) $iColor = GUIGetBkColor($hGUI) ; Pass the GUI handle to the function. MsgBox($MB_SYSTEMMODAL, '', 'Background Color: ' & _ConvertToHexFormat($aColor[$i]) & @CRLF & _ 'GUIGetBkColor() Hex Format: ' & _ConvertToHexFormat($iColor) & @CRLF & _ 'GUIGetBkColor() Returned: ' & $iColor, 0, $hGUI) Next GUIDelete($hGUI) EndFunc ;==>Example Func _ConvertToHexFormat($iColor) Return Hex($iColor, 6) EndFunc ;==>_ConvertToHexFormat
  6. Like
    guinness got a reaction from Zedna in _GetSavedSource() - Retrieve the saved source file from an AutoIt exe.   
    For those of us who use SciTE4AutoIt3 then you would've come across (at some stage) the directive #AutoIt3Wrapper_Res_SaveSource, it allows you to save the script to the compiled exe thus allowing you to retrieve at a later stage, great if you accidentally delete your source file.
    _GetSavedSource() allows you to extract the source file from the compiled executable and save to a file of your choice.
    Note: You must use #AutoIt3Wrapper_Res_SaveSource=Y at the top of the script for this to work & it must be compiled.
    Function:
    #include-once #include <WinAPIRes.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GetSavedSource ; Description ...: Retrieve the source file from a compiled executable, #AutoIt3Wrapper_Res_SaveSource=Y must be used beforehand to embed the file to the executable ; Syntax ........: _GetSavedSource([$sExecutable = ''[, $sSaveFilePath = '']]) ; Parameters ....: $sExecutable - [optional] Executable to retrieve the source file from ; Use a blank string or the Default keyword to use the current executable. Default is '' ; $sSaveFilePath - [optional] FilePath to save the source file to. Nore: The file doesn't have to exist. Default is '' ; Use a blank string or the Default keyword to save to the current directory and using the script's ; name with the au3 prefix. Default is '' ; Return values .: Success - True ; Failure - False and sets @error to non-zero ; Author ........: guinness ; Remarks .......: ; Example .......: Yes ; Note ..........: Thanks to Jos, Yashied & Zedna ; =============================================================================================================================== Func _GetSavedSource($sExecutable = '', $sSaveFilePath = '') Local Enum $GETSAVEDSOURCE_ERROR_NONE, $GETSAVEDSOURCE_ERROR_FILEWRITE, $GETSAVEDSOURCE_ERROR_FINDRESOURCE, $GETSAVEDSOURCE_ERROR_LOADMODULE Local $iError = $GETSAVEDSOURCE_ERROR_LOADMODULE Local $hInstance = (($sExecutable = Default Or StringStripWS($sExecutable, $STR_STRIPALL) = '') ? _WinAPI_GetModuleHandle(Null) : _WinAPI_LoadLibraryEx($sExecutable, $LOAD_LIBRARY_AS_DATAFILE)) If Not @error Then $iError = $GETSAVEDSOURCE_ERROR_FINDRESOURCE ; Get the source file from the executable. This is located at resname 999 Local $hResource = _WinAPI_FindResource($hInstance, $RT_RCDATA, 999) If Not @error Then Local $hData = _WinAPI_LoadResource($hInstance, $hResource) Local $iSize = _WinAPI_SizeOfResource($hInstance, $hResource) Local $pResource = _WinAPI_LockResource($hData) If $sSaveFilePath = Default Or StringStripWS($sSaveFilePath, $STR_STRIPALL) = '' Then $sSaveFilePath = @ScriptDir & '\' & StringLeft(@ScriptName, StringInStr(@ScriptName, '.', $STR_NOCASESENSEBASIC, -1) - 1) EndIf $iError = $GETSAVEDSOURCE_ERROR_FILEWRITE Local $hFilePath = FileOpen($sSaveFilePath, BitOR($FO_OVERWRITE, $FO_BINARY, $FO_UTF8)) If $hFilePath > -1 Then $iError = $GETSAVEDSOURCE_ERROR_NONE Local $tBuffer = DllStructCreate('byte array[' & $iSize & ']', $pResource) FileWrite($hFilePath, DllStructGetData($tBuffer, 'array')) FileClose($hFilePath) EndIf EndIf _WinAPI_FreeLibrary($hInstance) EndIf Return SetError($iError, 0, $iError = $GETSAVEDSOURCE_ERROR_NONE) EndFunc ;==>_GetSavedSource Example 1 of Function:
    #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 ; Use the full version of SciTE4AutoIt3 by Jos #AutoIt3Wrapper_Res_SaveSource=Y #AutoIt3Wrapper_UseX64=N #include <MsgBoxConstants.au3> #include '_GetSavedSource.au3' Example() Func Example() If @Compiled Then If _GetSavedSource(@ScriptFullPath, @ScriptDir & '\' & GetScriptName() & '.au3') Then MsgBox($MB_SYSTEMMODAL, 'Completed', 'The Au3 script was saved in the script directory and is called ' & GetScriptName() & '.au3') Else MsgBox($MB_SYSTEMMODAL, 'Error' & @error, 'An error occurred whilst extracting the Au3 script located in the resources.') EndIf Else MsgBox($MB_SYSTEMMODAL, 'Compile first', 'Please compile this script first and then run the compiled file, you''ll see a new file called "' & _ GetScriptName() & '.au3' & '" is created in the same directory.') EndIf EndFunc ;==>Example ; Return the @ScriptName minus the .exe or .au3 extension and with _SAVEDSOURCE_ appended Func GetScriptName() Return StringLeft(@ScriptName, StringInStr(@ScriptName, '.', $STR_NOCASESENSEBASIC, -1) - 1) & '_SAVEDSOURCE_' EndFunc ;==>GetScriptName Example 2 of Function:
    #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 ; Use the full version of SciTE4AutoIt3 by Jos #AutoIt3Wrapper_Res_SaveSource=Y #AutoIt3Wrapper_UseX64=N #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include '_GetSavedSource.au3' If Not @Compiled Then Exit MsgBox($MB_SYSTEMMODAL, 'Compile first', 'Please compile this script first and then run the compiled file, you''ll see a new file called "' & _ GetScriptName() & '.au3' & '" is created in the same directory.') EndIf ; Check if the commandline parameter 'SaveSource' has been passed to the executable IsSaveSource() Example() Func Example() ; The example of using AutoItWinGetTitle() can be found at: http://www.autoitscript.com/forum/topic/133648-autoitwingettitleautoitwinsettitle-an-example-of-usage/ ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window Local $hAutoIt = AutoItWinShow() ; Read the source file that was extracted from the executable Local $sData = FileRead(@ScriptDir & '\' & GetScriptName() & '.au3') If @error Then ; If the file wasn't extracted then show an error string $sData = '## @error - can''t open the file ##' EndIf ; Set the text of the edit box using the data returned from _GetFile AutoItWinSetText($hAutoIt, $sData) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ; Just hit the close button to Exit the application ExitLoop EndSwitch WEnd EndFunc ;==>Example ; Add text to AutoIt's Hidden Window Func AutoItWinSetText($sString, $hWnd = Default) If Not IsHWnd($hWnd) Or $hWnd = Default Then ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window $hWnd = WinGetHandle(AutoItWinGetTitle()) EndIf Return ControlSetText($hWnd, '', ControlGetHandle($hWnd, '', 'Edit1'), $sString) EndFunc ;==>AutoItWinSetText ; Display AutoIt's Hidden Window. Returns the handle of the window Func AutoItWinShow() ; Get the handle of the AutoIt Hidden Window by finding out the title of the AutoIt Hidden Window Local $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Move the AutoIt Hidden Window and re-size for a better view of the data that will be set WinMove($hWnd, '', (@DesktopWidth / 2) - 250, (@DesktopHeight / 2) - 250, 500, 500) ; Show the AutoIt Hidden Window, normally this is hidden, but in the interest of this example I'm displaying it WinSetState($hWnd, '', @SW_SHOW) Return $hWnd EndFunc ;==>AutoItWinShow ; Return the @ScriptName minus the .exe or .au3 extension and with _SAVEDSOURCE_ appended Func GetScriptName() Return StringLeft(@ScriptName, StringInStr(@ScriptName, '.', $STR_NOCASESENSEBASIC, -1) - 1) & '_SAVEDSOURCE_' EndFunc ;==>GetScriptName ; Check if the commandline parameter 'SaveSource' has been passed to the executable Func IsSaveSource() Return (StringInStr($CmdLineRaw, 'SaveSource') ? _GetSavedSource(@ScriptFullPath, @ScriptDir & '\' & GetScriptName() & '.au3') : Null) EndFunc ;==>IsSaveSource All of the above has been included in a ZIP file. GetSavedSource.zip
  7. Like
    guinness got a reaction from yutijang in ResourcesEx UDF.   
    So if you haven't noticed  Zedna's Resources UDF has been a very popular UDF over the last 7 years and was last updated in 2011, but now is the time to bring the UDF up to date with the current AutoIt language syntax (v3.3.14.2). So with the blessing of Zedna may I present to you ResourcesEx. It's built using the UDF standards I have tried to enforce around here, with improved documentation and an overall UDF structure.
    I please ask that you try and break the UDF, criticise, educate, whatever, just play around with the functions and example. I do ask that you just don't say "you've missed the point" and leave at that. Provide an alternative or constructive reason as to why I have "missed the point".
    Thanks.
    IMPORTANT: You must be using SciTE4AutoIt3, as this comes included with AutoItWrapper
    Changes between Zedna's UDF and guinness' UDF. _ResourceGet() => _Resource_Get() _ResourceGetAsString() => _Resource_GetAsString() with an additional param of whether to return ANSI. _ResourceGetAsStringW() => _Resource_GetAsString() _ResourceGetAsBytes() => _Resource_GetAsBytes() _ResourceGetAsImage() => _Resource_GetAsImage() _ResourceGetAsBitmap() => _Resource_GetAsBitmap() _ResourceSaveToFile() => _Resource_SaveToFile() _ResourceSetImageToCtrl() => _Resource_SetToCtrlID() _SetBitmapToCtrl() => _Resource_SetBitmapToCtrlID() As to JFX's question of what makes this different...
    Known problems/limitations: (Taken for Zedna's Resources UDF)
    _ResourceGet() returns resource size (in bytes) in @extended macro but not for resource type RT_BITMAP [FIXED] _ResourceSetImageToCtrl() works with "static/button" type of controls (picture,label,icon,button,checkbox,radiobutton,groupbox) [NO_ISSUE] _ResourcePlaySound() plays only WAV files (not MP3 files) [FIXED] _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 [FIXED] _GDIPlus_Startup() is called once at start of whole include --> no _GDIPlus_Shutdown() is called [FIXED] Download the ZIP and play around with the Example/UDF.  ResourcesEx.zip
    Jos: 15-9-2022 Updated version replaced $__WINVER with _WinAPI_GetVersion()
    Jos: 27-4-2023 updated script as they required extra #include: ResourcesEx.zip
    Changelog: 2015/09/26 Changed: Comments throughout the UDF, removing trailing dot Fixed: Various cosmetic changes 2015/01/12 Fixed: Example directive using double equals sign Fixed: Delete functions not being cast as a bool value. (Thanks Synix) Fixed: @error and @extended not be passed back in nested functions e.g. _Resource_GetAsRaw() 2014/07/19 Added: _Resource_SetBitmapToCtrlID() formely known as _Resource_SetImageToCtrlID() Added: Note about using #AutoIt3Wrapper_Res_Icon_Add to the example. (Thanks Zedna) Added: Passing a blank string to _Resource_SetToCtrlID() through the $sResNameOrID parameter, will delete the image and previous handle Changed: _Resource_SetImageToCtrlID() now accepts a hBitmap not a HBITMAP object Fixed: _Resource_GetAsBitmap() now works the same way as _ResourceGetAsBitmap() did, by converting a jpg, png etc... to HBITMAP Fixed: Memory management of some functions 2014/07/18 Fixed: Destroying a cursor Fixed: Regression from loading the current of external module. (Thanks UEZ) 2014/07/17 Added: Additonal checks to destroy cursors and icons Added: Checking if the dll or exe filepath has a valid extension Added: Example of using an icon and image on a button control Fixed: Icons and cursors (finally) being re-sized to a control Fixed: Using GUIGetStyle() on a non-AutoIt handle would cause issue with controls Fixed: Variable naming of $sDLL to $sDllOrExePath for improved clarity Removed: Workaround for setting icons to AutoIt controls 2014/07/17 Added: Commented workaround in the example for re-sizing an icon control Added: ResourcesEx_PE.au3 created by PreExpand for all you constant variable haters out there!!! Fixed: Changelog comments and source code comments Fixed: Re-sizing icons when the control was different to the icon's size. (Thanks czardas for the MSDN link and Jon.) Fixed: Re-sizing cursors and icons in general 2014/07/15 Added: Comments about using SOUND for wav files and RT_RCDATA for mp3 files. (Thanks Melba23) Added: Option to relevant functions to re-size the image based on the control's dimensions. (Requested by kinch: http://www.autoitscript.com/forum/topic/51103-resources-udf/?p=1147525) Added: Using _Resource_LoadFont() example. (Thanks UEZ) Changed: Certain example resources to now use those found in %AUTOITDIR%\Examples\Helpfile\Extras Changed: Constants and enums readability. (Thank mLipok) Changed: Internal functions for destroying resources Changed: Removed changes made from the previous version for loading resources multiple times. The design needs to be re-thought Changed: Setting styles of controls using native AutoIt functions Fixed: Destroying control resource images would fail to show if reinstated again Fixed: Documentation comments Fixed: Missing certain users who helped with creating this UDF Fixed: Outdated SciTE files 2014/07/14: Added: _Resource_GetAsCursor(), for the loading of animated cursors and standard cursors which can then be used with _WinAPI_SetCursor() Added: _Resource_GetAsIcon(), for loading icon resource types Added: _Resource_LoadFont(), which retrieves a font resource and adds to the current memory of the associated module Added: _Resource_SetCursorToCtrlID() and _Resource_SetIconToCtrlID() Added: Additional resource types to destroy on exit, including $RT_FONT, $RT_ICON and $RT_MENU Added: Playing Mp3s to _Resource_LoadSound(). (Thanks to UEZ and Melba23 with changes made by me.) Changed: _Resource_GetAsBitmap() returns a HTBITMAP handle without converting from hBitmap to HBITMAP Changed: _Resource_PlaySound() to _Resource_LoadSound() Changed: _Resource_SetBitmapToCtrlID() to _Resource_SetImageToCtrlID() Changed: _SendMessage() to GUICtrlSendMsg() Changed: Example files Changed: Setting $iError in the internal get function Changed: Signature of _Resource_Destroy() Changed: Updated example to reflect major changes to the ResourcesEx UDF Changed: Various UDF tweaks that I didn't document because I simply couldn't keep track of all the playing around I did in the last week Fixed: _Resource_GetAsImage() not returning an error when a bitmap couldn't be found in the resource table Fixed: Retrieving length of a string Fixed: Using the current module instead of zero in _Resource_LoadSound() Fixed: Various comment changes. (Thanks mLipok) Fixed: Loading resources multiple times. This is fixed thanks to using the internal storage array 2014/07/07: Added: _Resource_Destroy() and _Resource_DestroyAll() to destroy a particular resource name or all resources Added: Checking if the resource name of id value is empty Added: Descriptions, though could do with a little tweaking Changed: _Resource_Get() to _Resource_GetAsRaw() Changed: Internal workings of __Resource_Storage() Changed: Re-size the storage array when destroyed or on shutdown Fixed: _Resource_GetAsString() with default encoding of ANSI Fixed: Calltips API referencing Resources.au3 and not ResourcesEx.au3 Removed: _Resource_Shudown() due to the addition of _Resource_Destroy() and _Resource_DestroyAll() 2014/07/06: Added: _Resource_Shudown() to free up those resources which aren't loaded using _WinAPI_LockResource(). UnlockResource is obsolete Added: Support for using $RT_STRING Changed: _Resource_GetAsString() now works correctly for most encodings. (Thanks Jos) Changed: _Resource_GetAsString() will now load as a string if the resource type requested is $RT_STRING 2014/07/04: Added: #Regions. (Thanks mLipok) Added: #Tidy_Parameters=/sort_funcs /reel (Thanks mLipok) Added: All optional params now accept the default keyword Added: Link to this thread. (Thanks mLipok) Added: Main header. (Thanks mLipok) Changed: $f.... >> $b..... (Thanks mLipok) 2014/07/03: Initial release  
  8. Like
    guinness got a reaction from web2win in AutoIt Snippets   
    #NoTrayIcon ; So no icon is displayed in the trayicon menu. #include <GUIConstants.au3> Example() Func Example() Local $hGUI = _GUICreateNoTaskBar('Example of a GUI with no TaskBar icon/button', 500, 500, -1, -1) Local $iClose = GUICtrlCreateButton('Close', 410, 470, 85, 25) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $iClose ExitLoop EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example ; Version: 1.00. AutoIt: V3.3.8.1 ; Create a GUI without a taskbar icon/button, this uses AutoIt's internal hidden window as the parent GUI. Func _GUICreateNoTaskBar($sTitle, $iWidth, $iHeight = Default, $iLeft = Default, $iTop = Default, $bStyle = Default, $bStyleEx = Default) Return GUICreate($sTitle, $iWidth, $iHeight, $iLeft, $iTop, $bStyle, $bStyleEx, WinGetHandle(AutoItWinGetTitle())) EndFunc ;==>_GUICreateNoTaskBar
  9. Haha
    guinness got a reaction from Norm73 in How to check if the network internet connection is up or down   
    If you use WinAPIEx then you can find the equivalent >> _WinAPI_IsNetworkAlive OR _WinAPI_IsInternetConnected
  10. Thanks
    guinness got a reaction from mLipok in InetGetSize returns 0, though sometimes it will return a value greater than 0.   
    Thanks trancexx.
    Reading material:: https://en.wikipedia.org/wiki/Chunked_transfer_encoding
  11. Like
    guinness got a reaction from Parsix in GUICtrlGetStyle() - Get the Styles of a control.   
    If you set the styles of a control with GUICtrlSetStyle() and happen to forget the styles you set, then why not try GUICtrlGetStyle()

    To get the Hex value e.g. 00100000 then use this little conversion >>

    Local $aArray = GUICtrlGetStyle($iLabel) _GUICtrlGetStyle_Convert($aArray) _ArrayDisplay($aArray, 'The Style = 0101 & the ExStyle = 00100000'))Function:
    #include-once #include <WinAPI.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: GUICtrlGetStyle ; Description ...: Retrieves the Styles/ExStyles value(s) of a control. ; Syntax ........: GUICtrlGetStyle($hWnd) ; Parameters ....: $hWnd - Control ID/Handle to the control ; Return values .: $aArray[2] = [Style, ExStyle] ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func GUICtrlGetStyle($hWnd) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) EndIf Local $aReturn = [_WinAPI_GetWindowLong($hWnd, $GWL_STYLE), _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE)] Return $aReturn EndFunc ;==>GUICtrlGetStyleExample use of Function:
    #include <Array.au3> ; Required only for _ArrayDisplay(), but not the UDF! #include <GUIConstantsEx.au3> #include 'GUICtrlGetStyle.au3' Example() Func Example() Local $hGUI = GUICreate('GUICtrlGetStyle() Example', 280, 90) ; This label is using 'magic numbers' instead of the constant variables. It's advisable to use $SS_CENTER & $GUI_WS_EX_PARENTDRAG ; instead of 0x0101 & 0x00100000, but this has been done for proof of concept only. See the second _Array display for more details. Local $iLabel = GUICtrlCreateLabel('This is a Label with $SS_CENTER & $GUI_WS_EX_PARENTDRAG set as the Styles.', 10, 10, 270, 45, 0x0101, 0x00100000) ; $SS_CENTER, $GUI_WS_EX_PARENTDRAG Local $iButton = GUICtrlCreateButton('GetStyle Array', 95, 55, 85, 25) GUISetState(@SW_SHOW, $hGUI) Local $aArray = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iButton $aArray = GUICtrlGetStyle($iLabel) _ArrayDisplay($aArray) GUICtrlDelete($iLabel) GUICtrlCreateLabel('This is a NEW Label with $SS_CENTER & $GUI_WS_EX_PARENTDRAG set as the Styles/ExStyles.', 10, 10, 270, 50, $aArray[0], $aArray[1]) ; This is the reason why 'magic numbers' were used, so as to see they match the same values in GUICtrlCreateLabel. $aArray = GUICtrlGetStyle($iLabel) _GUICtrlGetStyle_Convert($aArray) _ArrayDisplay($aArray, 'The Style = 0x0101 & the ExStyle = 0x00100000') EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example Func _GUICtrlGetStyle_Convert(ByRef $aArray) If UBound($aArray) = 2 Then $aArray[0] = '0x' & Hex($aArray[0], 4) $aArray[1] = '0x' & Hex($aArray[1], 8) EndIf EndFunc ;==>_GUICtrlGetStyle_Convert
  12. Thanks
    guinness got a reaction from FourLC in Good coding practices in AutoIt   
    We see a lot of examples submitted by users but rarely do we see threads about good coding practice. Post below if you have an example which exhibits the "dos and don'ts" of coding in AutoIt.
    Why using Dim over Local/Global is not always a good option:
    #include <MsgBoxConstants.au3> Dim $vVariableThatIsGlobal = "This is a variable that has ""Program Scope"" aka Global." MsgBox($MB_SYSTEMMODAL, "", "An example of why Dim can cause more problems than solve them.") Example() Func Example() MsgBox($MB_SYSTEMMODAL, "", $vVariableThatIsGlobal) ; That looks alright to me as it displays the following text: This is a variable that has "Program Scope" aka Global. Local $vReturn = SomeFunc() ; Call some random function. MsgBox($MB_SYSTEMMODAL, $vReturn, $vVariableThatIsGlobal) ; The Global variable ($vVariableThatIsGlobal) changed because I totally forgot I had a duplicate variable name in "SomeFunc". EndFunc ;==>Example Func SomeFunc() ; This should create a variable in Local scope if the variable name doesn"t already exist. ; For argument sake I totally forgot that I declared a variable already with the same name. ; Well I only want this to be changed in the function and not the variable at the top of the script. ; Should be OK right? Think again. Dim $vVariableThatIsGlobal = "" For $i = 1 To 10 $vVariableThatIsGlobal &= $i ; This will return 12345678910 totally wiping the previous contents of $vVariableThatIsGlobal. Next Return $vVariableThatIsGlobal EndFunc ;==>SomeFunc
  13. Like
    guinness got a reaction from Skysnake in Correct way to clear a ListView? [Solved]   
    Retrieve the handle of the ListView using GUICtrlGetHandle($iListView) and then use the handle with _GUICtrlListView_DeleteAllItems()
  14. Like
    guinness got a reaction from noellarkin in Best multi-threading solution?   
    How I do it is...
    1. Compile a second AutoIt file as an a3x file.
    2. Use _RunAu3 (search the Forum)
    3. Communicate with the file using WM_COPYDATA (see my signature.)
    It's what I do for SciTE Jump, see my signature again.
  15. Haha
    guinness got a reaction from SOLVE-SMART in AutoIt Snippets   
    ...and the worst snippet too. Please put a little more effort into your snippets. Even something like this makes more sense e.g.
    #include <Array.au3> Example() Func Example() Local $aArray[100] _ArrayDisplay($aArray) PurgeVar($aArray) _ArrayDisplay($aArray) EndFunc ;==>Example Func PurgeVar(ByRef $vVar) Switch VarGetType($vVar) Case "Array" Local $aEmpty[0] $vVar = $aEmpty ; Default value of an array. Case "Binary" $vVar = Binary(0) ; Default value of binary. Case "Bool" $vVar = False ; Default value of a boolean. Case "Double" $vVar = 0.0 ; Default value of a double. Case "Int32", "Int64" $vVar = 0 ; Default value of an integer. Case "Function", "Keyword", "DLLStruct", "Object", "Ptr" $vVar = Null ; Default value of an object/pointer. Case "String" $vVar = "" ; Default value of a string. EndSwitch EndFunc ;==>PurgeVar
  16. Like
    guinness got a reaction from Dotaznik in _GetHardwareID() - Generates a unique hardware identifier (ID) for the local computer.   
    All done. I have updated the function.
  17. Like
    guinness got a reaction from Dotaznik in _GetHardwareID() - Generates a unique hardware identifier (ID) for the local computer.   
    This function is based on _WinAPI_UniqueHardwareID() in WinAPIDiag.au3. The flags which can be used in this function are exactly the same flags as in _WinAPI_UniqueHardwareID().
    Any problems please post below. Thanks.
    Function:
    ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GetHardwareID ; Description ...: Generates a unique hardware identifier (ID) for the local computer. ; Syntax ........: _GetHardwareID([$iFlags = Default]) ; Parameters ....: $iFlags - [optional] The flags that specifies what information would be used to generate ID. ; This parameter can be one or more of the following values. ; ; $UHID_MB (0) ; Uses information about your motherboard. This flag is used by default regardless of whether specified or not. ; ; $UHID_BIOS (1) ; Uses information about the BIOS. ; ; $UHID_CPU (2) ; Uses information about the processor(s). ; ; $UHID_HDD (4) ; Uses information about the installed hard drives. Any change in the configuration disks will change ID ; returned by this function. Taken into account only non-removable disks. ; ; $UHID_All (7) ; The sum of all the previous flags. Default is $UHID_MB (0). ; ; $bIs64Bit - [optional] Search the 64-bit section of the registry. Default is dependant on AutoIt bit version. ; Note: 64-bit can't be searched when running the 32-bit version of AutoIt. ; Return values..: Success - The string representation of the ID. @extended returns the value that contains a combination of flags ; specified in the $iFlags parameter. If flag is set, appropriate information is received successfully, ; otherwise fails. The function checks only flags that were specified in the $iFlags parameter. ; Failure - Null and sets @error to non-zero. ; Author.........: guinness with the idea by Yashied (_WinAPI_UniqueHardwareID() - WinAPIDiag.au3) ; Modified ......: Additional suggestions by SmOke_N. ; Remarks .......: The constants above can be found in APIDiagConstant.au3. It also requires StringConstants.au3 and Crypt.au3 to be included. ; Example........: Yes ; =============================================================================================================================== Func _GetHardwareID($iFlags = Default, $bIs64Bit = Default) Local $sBit = @AutoItX64 ? '64' : '' If IsBool($bIs64Bit) Then ; Use 64-bit if $bIs64Bit is true and AutoIt is a 64-bit process; otherwise 32-bit $sBit = $bIs64Bit And @AutoItX64 ? '64' : '' EndIf If $iFlags == Default Then $iFlags = $UHID_MB EndIf Local $aSystem = ['Identifier', 'VideoBiosDate', 'VideoBiosVersion'], _ $iResult = 0, _ $sHKLM = 'HKEY_LOCAL_MACHINE' & $sBit, $sOutput = '', $sText = '' For $i = 0 To UBound($aSystem) - 1 $sOutput &= RegRead($sHKLM & '\HARDWARE\DESCRIPTION\System\', $aSystem[$i]) Next $sOutput &= @CPUArch $sOutput = StringStripWS($sOutput, $STR_STRIPALL) If BitAND($iFlags, $UHID_BIOS) Then Local $aBIOS = ['BaseBoardManufacturer', 'BaseBoardProduct', 'BaseBoardVersion', 'BIOSVendor', 'BIOSReleaseDate'] $sText = '' For $i = 0 To UBound($aBIOS) - 1 $sText &= RegRead($sHKLM & '\HARDWARE\DESCRIPTION\System\BIOS\', $aBIOS[$i]) Next $sText = StringStripWS($sText, $STR_STRIPALL) If $sText Then $iResult += $UHID_BIOS $sOutput &= $sText EndIf EndIf If BitAND($iFlags, $UHID_CPU) Then Local $aProcessor = ['ProcessorNameString', '~MHz', 'Identifier', 'VendorIdentifier'] $sText = '' For $i = 0 To UBound($aProcessor) - 1 $sText &= RegRead($sHKLM & '\HARDWARE\DESCRIPTION\System\CentralProcessor\0\', $aProcessor[$i]) Next For $i = 0 To UBound($aProcessor) - 1 $sText &= RegRead($sHKLM & '\HARDWARE\DESCRIPTION\System\CentralProcessor\1\', $aProcessor[$i]) Next $sText = StringStripWS($sText, $STR_STRIPALL) If $sText Then $iResult += $UHID_CPU $sOutput &= $sText EndIf EndIf If BitAND($iFlags, $UHID_HDD) Then Local $aDrives = DriveGetDrive('FIXED') $sText = '' For $i = 1 To UBound($aDrives) - 1 $sText &= DriveGetSerial($aDrives[$i]) Next $sText = StringStripWS($sText, $STR_STRIPALL) If $sText Then $iResult += $UHID_HDD $sOutput &= $sText EndIf EndIf Local $sHash = StringTrimLeft(_Crypt_HashData($sOutput, $CALG_MD5), StringLen('0x')) If Not $sHash Then Return SetError(1, 0, Null) EndIf Return SetExtended($iResult, StringRegExpReplace($sHash, '([[:xdigit:]]{8})([[:xdigit:]]{4})([[:xdigit:]]{4})([[:xdigit:]]{4})([[:xdigit:]]{12})', '{\1-\2-\3-\4-\5}')) EndFunc ;==>_GetHardwareID Example use of Function:
    #include <APIDiagConstants.au3> #include <Crypt.au3> #include <StringConstants.au3> Local $sUniqueID = _GetHardwareID($UHID_All) ConsoleWrite('UniqueID: ' & $sUniqueID & @CRLF & _ 'Flags used: ' & @extended & @CRLF)
  18. Thanks
    guinness got a reaction from obiwanceleri in _ShellFolder() - Create an entry in the shell contextmenu when selecting a folder, includes the program icon as well.   
    I created this after I developed because I was interested in the entry displaying when a folder was right clicked on. The entry will pass the folder name to your program via a commandline argument, so you'll have to use $CmdLine/$CmdLineRaw to access the folder that was selected.

    Any problems or suggestions then please post below. Thanks.

    UDF:

    #include-once ; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; #INDEX# ======================================================================================================================= ; Title .........: _ShellFolder ; AutoIt Version : v3.2.12.1 or higher ; Language ......: English ; Description ...: Create an entry in the shell contextmenu when selecting a folder, includes the program icon as well. ; Note ..........: ; Author(s) .....: guinness ; Remarks .......: Special thanks to KaFu for EnumRegKeys2Array() which I used as inspiration for enumerating the Registry Keys. ; =============================================================================================================================== ; #INCLUDES# ==================================================================================================================== ; None ; #GLOBAL VARIABLES# ============================================================================================================ ; None ; #CURRENT# ===================================================================================================================== ; _ShellFolder_Install: Creates an entry in the 'All Users/Current Users' registry for displaying a program entry in the shell contextmenu, but only displays when selecting a folder. ; _ShellFolder_Uninstall: Deletes an entry in the 'All Users/Current Users' registry for displaying a program entry in the shell contextmenu. ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; __ShellFolder_RegistryGet ......; Retrieve an array of registry entries for a specific key. ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ShellFolder_Install ; Description ...: Creates an entry in the 'All Users/Current Users' registry for displaying a program entry in the shell contextmenu, but only displays when selecting a file and folder. ; Syntax ........: _ShellFolder_Install($sText[, $sName = @ScriptName[, $sFilePath = @ScriptFullPath[, $sIconPath = @ScriptFullPath[, ; $iIcon = 0[, $fAllUsers = False[, $fExtended = False]]]]]]) ; Parameters ....: $sText - Text to be shown in the contextmenu. ; $sName - [optional] Name of the program. Default is @ScriptName. ; $sFilePath - [optional] Location of the program executable. Default is @ScriptFullPath. ; $sIconPath - [optional] Location of the icon e.g. program executable or dll file. Default is @ScriptFullPath. ; $iIcon - [optional] Index of icon to be used. Default is 0. ; $fAllUsers - [optional] Add to Current Users (False) or All Users (True) Default is False. ; $fExtended - [optional] Show in the Extended contextmenu using Shift + Right click. Default is False. ; Return values .: Success - Returns True ; Failure - Returns False and sets @error to non-zero. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _ShellFolder_Install($sText, $sName = @ScriptName, $sFilePath = @ScriptFullPath, $sIconPath = @ScriptFullPath, $iIcon = 0, $fAllUsers = False, $fExtended = False) Local $i64Bit = '', $sRegistryKey = '' If $iIcon = Default Then $iIcon = 0 EndIf If $sFilePath = Default Then $sFilePath = @ScriptFullPath EndIf If $sIconPath = Default Then $sIconPath = @ScriptFullPath EndIf If $sName = Default Then $sName = @ScriptName EndIf If @OSArch = 'X64' Then $i64Bit = '64' EndIf If $fAllUsers Then $sRegistryKey = 'HKEY_LOCAL_MACHINE' & $i64Bit & 'SOFTWAREClassesFoldershell' Else $sRegistryKey = 'HKEY_CURRENT_USER' & $i64Bit & 'SOFTWAREClassesFoldershell' EndIf $sName = StringLower(StringRegExpReplace($sName, '.[^./]*$', '')) If StringStripWS($sName, 8) = '' Or FileExists($sFilePath) = 0 Then Return SetError(1, 0, False) EndIf _ShellFolder_Uninstall($sName, $fAllUsers) Local $iReturn = 0 $iReturn += RegWrite($sRegistryKey & $sName, '', 'REG_SZ', $sText) $iReturn += RegWrite($sRegistryKey & $sName, 'Icon', 'REG_EXPAND_SZ', $sIconPath & ',' & $iIcon) $iReturn += RegWrite($sRegistryKey & $sName & 'command', '', 'REG_SZ', '"' & $sFilePath & '" "%1"') If $fExtended Then $iReturn += RegWrite($sRegistryKey & $sName, 'Extended', 'REG_SZ', '') EndIf Return $iReturn > 0 EndFunc ;==>_ShellFolder_Install ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ShellFolder_Uninstall ; Description ...: Deletes an entry in the 'All Users/Current Users' registry for displaying a program entry in the shell contextmenu. ; Syntax ........: _ShellFolder_Uninstall([$sName = @ScriptName[, $fAllUsers = False]]) ; Parameters ....: $sName - [optional] Name of the Program. Default is @ScriptName. ; $fAllUsers - [optional] Was it added to Current Users (False) or All Users (True) Default is False. ; Return values .: Success - Returns True ; Failure - Returns False and sets @error to non-zero. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _ShellFolder_Uninstall($sName = @ScriptName, $fAllUsers = False) Local $i64Bit = '', $sRegistryKey = '' If $sName = Default Then $sName = @ScriptName EndIf If @OSArch = 'X64' Then $i64Bit = '64' EndIf If $fAllUsers Then $sRegistryKey = 'HKEY_LOCAL_MACHINE' & $i64Bit & 'SOFTWAREClassesFoldershell' Else $sRegistryKey = 'HKEY_CURRENT_USER' & $i64Bit & 'SOFTWAREClassesFoldershell' EndIf $sName = StringLower(StringRegExpReplace($sName, '.[^./]*$', '')) If StringStripWS($sName, 8) = '' Then Return SetError(1, 0, 0) EndIf Local $aReturn = __ShellFolder_RegistryGet($sRegistryKey), $iReturn = 0, $sNameDeleted = '' If $aReturn[0][0] Then For $i = 1 To $aReturn[0][0] If $aReturn[$i][0] = $sName And $sNameDeleted <> $aReturn[$i][1] Then $sNameDeleted = $aReturn[$i][1] $iReturn += RegDelete($sNameDeleted) EndIf Next EndIf $aReturn = 0 Return $iReturn > 0 EndFunc ;==>_ShellFolder_Uninstall ; #INTERNAL_USE_ONLY#============================================================================================================ Func __ShellFolder_RegistryGet($sRegistryKey) Local $aArray[1][5] = [[0, 5]], $iCount_1 = 0, $iCount_2 = 0, $iDimension = 0, $iError = 0, $sRegistryKey_All = '', $sRegistryKey_Main = '', $sRegistryKey_Name = '', _ $sRegistryKey_Value = '' While 1 If $iError Then ExitLoop EndIf $sRegistryKey_Main = RegEnumKey($sRegistryKey, $iCount_1 + 1) If @error Then $sRegistryKey_All = $sRegistryKey $iError = 1 Else $sRegistryKey_All = $sRegistryKey & $sRegistryKey_Main EndIf $iCount_2 = 0 While 1 $sRegistryKey_Name = RegEnumVal($sRegistryKey_All, $iCount_2 + 1) If @error Then ExitLoop EndIf If ($aArray[0][0] + 1) >= $iDimension Then $iDimension = Ceiling(($aArray[0][0] + 1) * 1.5) ReDim $aArray[$iDimension][$aArray[0][1]] EndIf $sRegistryKey_Value = RegRead($sRegistryKey_All, $sRegistryKey_Name) $aArray[$aArray[0][0] + 1][0] = $sRegistryKey_Main $aArray[$aArray[0][0] + 1][1] = $sRegistryKey_All $aArray[$aArray[0][0] + 1][2] = $sRegistryKey & $sRegistryKey_Main & '' & $sRegistryKey_Name $aArray[$aArray[0][0] + 1][3] = $sRegistryKey_Name $aArray[$aArray[0][0] + 1][4] = $sRegistryKey_Value $aArray[0][0] += 1 $iCount_2 += 1 WEnd $iCount_1 += 1 WEnd ReDim $aArray[$aArray[0][0] + 1][$aArray[0][1]] Return $aArray EndFunc ;==>__ShellFolder_RegistryGetExample 1:

    #include "_ShellFolder.au3" Example() Func Example() _ShellFolder_Install('Start ShellFolder') ; Add the running EXE to the Shell ContextMenu. This will only display when selecting a drive and folder. Sleep(10000) _ShellFolder_Uninstall() ; Remove the running EXE from the Shell ContextMenu. EndFunc ;==>ExampleAll of the above has been included in a ZIP file. ShellFolder.zip
  19. Sad
    guinness got a reaction from jay97 in get variable name   
    Why would you want to do that? There seems no logical reason in my book.
  20. Like
    guinness got a reaction from SkysLastChance in Close multiple processes have the same name   
    Sorry Varian, thats one way! But another way is to use _WinAPI_GetProcessCommandLine() which is in WinAPIEx.au3 it shows the command-line parameters of the executed process, therefore not having to save to an INI File.

    This Example creates a 2D Array with 3 Columns [Process Name, PID, Command-Line]

    #include <Array.au3> #include <WinAPIEx.au3> Global $ProcessArray = ProcessList(@ScriptName) ; <<<<< Change to Blank to see all Processes! If Not $ProcessArray[0][0] = 0 Then ReDim $ProcessArray[$ProcessArray[0][0] + 1][3] For $A = 1 To $ProcessArray[0][0] $ProcessArray[$A][2] = _WinAPI_GetProcessCommandLine($ProcessArray[$A][1]) Next If IsArray($ProcessArray) Then _ArrayDisplay($ProcessArray, '_WinAPI_GetProcessCommandLine')
  21. Like
    guinness got a reaction from ashraful089 in Find Display Resolution   
    It's better than not, don't you agree!
    Here is what I meant, with a slight performance fix:
    #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: Chimaera Script Function: Desktop Resolution #ce ---------------------------------------------------------------------------- #include <MsgBoxConstants.au3> ; Only required for the MsgBox constant MsgBox($MB_SYSTEMMODAL, "Desktop Resolution", _Desktop_Resolution() & " @ " & @DesktopRefresh & " Hertz") Func _Desktop_Resolution() Local $iDesktopWidth = @DesktopWidth, $iDesktopHeight = @DesktopHeight ; Slight speed increase by storing in variables Select Case $iDesktopWidth = 640 And $iDesktopHeight = 480 ; Video Graphics Array Return "640 x 480 (4:3) VGA" Case $iDesktopWidth = 800 And $iDesktopHeight = 480 ; Wide Video Graphics Array Return "800 x 480 (4:3) WVGA" Case $iDesktopWidth = 854 And $iDesktopHeight = 480 ; Full Wide Video Graphics Array Return "854 x 480 (4:3) FWVGA" Case $iDesktopWidth = 800 And $iDesktopHeight = 600 ; Super Video Graphics Array Return "800 x 600 (4:3) SVGA" Case $iDesktopWidth = 960 And $iDesktopHeight = 540 ; Quarter Full HD Return "960 x 540 (16:9) qHD" Case $iDesktopWidth = 1024 And $iDesktopHeight = 576; Wide Super Video Graphics Array Return "1024 x 576 (5:3) WSVGA" Case $iDesktopWidth = 1024 And $iDesktopHeight = 600 ; Wide Super Video Graphics Array Return "1024 x 600 (5:3) WSVGA" Case $iDesktopWidth = 1024 And $iDesktopHeight = 768; eXtended Graphics Array Return "1024 x 768 (4:3) XGA" Case $iDesktopWidth = 1152 And $iDesktopHeight = 864; eXtended Graphics Array Plus Return "1152 x 864 (4:3) XGA+" Case $iDesktopWidth = 1280 And $iDesktopHeight = 720 ; Wide eXtended Graphics Array Return "1280 x 720 (16:9) HD Ready" Case $iDesktopWidth = 1280 And $iDesktopHeight = 768; Wide eXtended Graphics Array Return "1280 x 768 (15:9) WXGA" Case $iDesktopWidth = 1280 And $iDesktopHeight = 800 ; Wide eXtended Graphics Array Return "1280 x 800 (16:10) WXGA" Case $iDesktopWidth = 1280 And $iDesktopHeight = 960 ; Super eXtended Graphics Array Return "1280 x 960 (4:3) SXGA" Case $iDesktopWidth = 1280 And $iDesktopHeight = 1024; Super eXtended Graphics Array Return "1280 x 1024 (5:4) SXGA" Case $iDesktopWidth = 1360 And $iDesktopHeight = 768; Wide eXtended Graphics Array Return "1360 x 768 (16:9) WXGA" Case $iDesktopWidth = 1366 And $iDesktopHeight = 768; High Definition (720p) Return "1366 x 768 (16:9) HD [720p]" Case $iDesktopWidth = 1440 And $iDesktopHeight = 900 ; Wide Super eXtended Graphics Array Return "1440 x 900 (16:10) WSXGA" Case $iDesktopWidth = 1400 And $iDesktopHeight = 1050 ; Wide Super eXtended Graphics Array Return "1440 x 900 (16:10) WSXGA" Case $iDesktopWidth = 1600 And $iDesktopHeight = 900 ; High Definition Plus (900p) Return "1600 x 900 (16:9) HD+ [900p]" Case $iDesktopWidth = 1600 And $iDesktopHeight = 1200 ; Ultra eXtended Graphics Array Return "1600 x 1200 (4:3) UXGA" Case $iDesktopWidth = 1680 And $iDesktopHeight = 1050 ; Wide Super eXtended Graphics Array Plus Return "1680 x 1050 (16:10) WSXGA+" Case $iDesktopWidth = 1920 And $iDesktopHeight = 1080 ; Full High Definition (1080p) Return "1920 x 1080 (16:9) HD [1080p]" Case $iDesktopWidth = 1920 And $iDesktopHeight = 1200 ; Wide Ultra eXtended Graphics Array Return "1920 x 1200 (16:10) WUXGA" Case $iDesktopWidth = 1920 And $iDesktopHeight = 1400 ; Tesselar eXtended Graphics Array Return "1920 x 1400 (48:35) TXGA" Case $iDesktopWidth = 2048 And $iDesktopHeight = 1080 ; Digital Film Projection Return "2048 x 1080 (19:10) 2K" Case $iDesktopWidth = 2048 And $iDesktopHeight = 1152; Quad Wide eXtended Graphics Array Return "2048 x 1152 (4:3) QWXGA" Case $iDesktopWidth = 2048 And $iDesktopHeight = 1536 ; Quad eXtended Graphics Array Return "2048 x 1536 (4:3) QXGA" Case $iDesktopWidth = 2538 And $iDesktopHeight = 1080 ; Wide Projector Return "2538 x 1080 (47:20) Wide Projector" Case $iDesktopWidth = 2560 And $iDesktopHeight = 1080 ; Cinema TV Return "2560 x 1080 (64:27) Cinema TV" Case $iDesktopWidth = 2560 And $iDesktopHeight = 1440 ; Wide Quad High Definition Return "2560 x 1440 (16:9) WQHD" Case $iDesktopWidth = 2560 And $iDesktopHeight = 1600 ; Wide Quad eXtended Graphics Array Return "2560 x 1600 (16:10) WQXGA" Case $iDesktopWidth = 2560 And $iDesktopHeight = 2048 ; Quad Super eXtended Graphics Array Return "2560 x 2048 (5:4) QSXGA" Case $iDesktopWidth = 2880 And $iDesktopHeight = 900 ; Dell Alienware Return "2880 x 900 (16:5) Curved Display" Case $iDesktopWidth = 3200 And $iDesktopHeight = 2048 ; Wide Quad Super eXtended Graphics Array Return "3200 x 2048 (25:16) WQSXGA" Case $iDesktopWidth = 3200 And $iDesktopHeight = 2400 ; Quad Ultra eXtended Graphics Array Return "3200 x 2048 (4:3) QUXGA" Case $iDesktopWidth = 3840 And $iDesktopHeight = 2160 ; Quad Full High Definition Return "3840 x 2160 (16:9) QFHD" Case $iDesktopWidth = 3840 And $iDesktopHeight = 2400 ; Wide Quad Ultra eXtended Graphics Array Return "3840 x 2048 (16:10) WQUXGA" Case $iDesktopWidth = 4096 And $iDesktopHeight = 1716 ; Digital Film Projection Return "4096 x 1716 (2:39) 4K" Case $iDesktopWidth = 4096 And $iDesktopHeight = 3072 ; Hex[adecatuple] eXtended Graphics Array Return "4096 x 3072 (4:3) HXGA" Case $iDesktopWidth = 5120 And $iDesktopHeight = 3200 ; Wide Hex[adecatuple] Extended Graphics Array Return "5120 x 3200 (16:10) WHXGA" Case $iDesktopWidth = 5120 And $iDesktopHeight = 4096 ; Hex[adecatuple] Super eXtended Graphics Array Return "5120 x 4096 (5:4) HSXGA" Case $iDesktopWidth = 6400 And $iDesktopHeight = 4096 ; Wide Hex[adecatuple] Super eXtended Graphics Array Return "6400 x 4096 (25:16) WHSXGA" Case $iDesktopWidth = 6400 And $iDesktopHeight = 4800 ; Hex[adecatuple] Ultra eXtended Graphics Array Return "6400 x 4800 (4:3) HUXGA" Case $iDesktopWidth = 7680 And $iDesktopHeight = 4320 ; Ultra High Definition Television Return "7680 x 4320 (16:9) UHDT" Case $iDesktopWidth = 7680 And $iDesktopHeight = 4800 ; Wide Hex[adecatuple] Ultra eXtended Graphics Array Return "7680 x 4800 (16:10) WHUXGA" Case Else ; If nothing matches then return the following Return SetError(1, 0, "") EndSelect EndFunc ;==>_Desktop_Resolution
  22. Like
    guinness got a reaction from Norm73 in Remove GUI title bar icon   
    Does this help? >>


    Edit: Actually look at the style $WS_DLGFRAME
  23. Like
    guinness got a reaction from Skeletor in Clear memory after loops   
    Firstly don't necro old threads, secondly search the forum for WinAPIEx and the function _WinAPI_EmptyWorkingSet. Case closed.
  24. Like
    guinness got a reaction from IgImAx in _IdleTime() - Move the mouse to stop the computer becoming idle and without changing any settings.   
    This is a quick example I created in which it move the mouse after a certain period of time of being idle. I could have changed the system settings, but then this wasn't an option.
     
    #include <WinAPISys.au3> Global Const $IDLETIME_GUID = '5816AA22-EEB4-4C92-BB07-4A5E1DBA4A6A' Global Enum $IDLETIME_DELEGATE, $IDLETIME_ID, $IDLETIME_ISRUNNING, $IDLETIME_TIME, $IDLETIME_MAX Global $g_bIsRunning = True ; For the example only. This is set to false when ESC is pressed. HotKeySet('{ESC}', Close) Example() Func Example() Local $hIdle = _IdleTime(10000, WakeUp) ; Create an idle time object and set the time to move the mouse every 10 seconds and call the parameterless function WakeUp(). ConsoleWrite('IsRunning: ' & _IdleTime_IsRunning($hIdle) & @CRLF) ; Display running status. ConsoleWrite('Time: ' & _IdleTime_GetTime($hIdle) & @CRLF) _IdleTime_StopStartPause($hIdle) ; Start the idle time monitoring. ConsoleWrite('IsRunning: ' & _IdleTime_IsRunning($hIdle) & @CRLF) ; Display running status. While Sleep(250) And $g_bIsRunning WEnd If _IdleTime_IsRunning($hIdle) Then _IdleTime_StopStartPause($hIdle) ; Stop if the idle time is currently running. EndIf ConsoleWrite('IsRunning: ' & _IdleTime_IsRunning($hIdle) & @CRLF) Return True EndFunc ;==>Example Func Close() $g_bIsRunning = False EndFunc ;==>Close Func WakeUp() MsgBox($MB_SYSTEMMODAL, '', 'Please wake up!') EndFunc ;==>WakeUp #Region IdleTime UDF Func _IdleTime($iTime = Default, $hFunc = Default) Local $aIdleTime[$IDLETIME_MAX] $aIdleTime[$IDLETIME_ID] = $IDLETIME_GUID $aIdleTime[$IDLETIME_ISRUNNING] = False __IdleTime_Delegate($aIdleTime, $hFunc) ; Set the delegate function. This should have no parameters. __IdleTime_Time($aIdleTime, $iTime) ; Set the time. Return $aIdleTime EndFunc ;==>_IdleTime Func _IdleTime_GetDelegate(ByRef $aIdleTime) Return (__IdleTime_IsAPI($aIdleTime) ? $aIdleTime[$IDLETIME_DELEGATE] : Null) EndFunc ;==>_IdleTime_GetDelegate Func _IdleTime_GetTime(ByRef $aIdleTime) Return (__IdleTime_IsAPI($aIdleTime) ? $aIdleTime[$IDLETIME_TIME] : Null) EndFunc ;==>_IdleTime_GetTime Func _IdleTime_IsRunning(ByRef $aIdleTime) Return (__IdleTime_IsAPI($aIdleTime) ? $aIdleTime[$IDLETIME_ISRUNNING] : False) EndFunc ;==>_IdleTime_IsRunning Func _IdleTime_SetDelegate(ByRef $aIdleTime, $hFunc) Local $bReturn = False If __IdleTime_IsAPI($aIdleTime) And __IdleTime_Time($aIdleTime, $hFunc) Then ; Set the delegate. $bReturn = True If _IdleTime_IsRunning($aIdleTime) Then _IdleTime_StopStartPause($aIdleTime) ; Stop. _IdleTime_StopStartPause($aIdleTime) ; Start. EndIf EndIf Return $bReturn EndFunc ;==>_IdleTime_SetDelegate Func _IdleTime_SetTime(ByRef $aIdleTime, $iTime) Local $bReturn = False If __IdleTime_IsAPI($aIdleTime) And __IdleTime_Time($aIdleTime, $iTime) Then ; Set the time. $bReturn = True If _IdleTime_IsRunning($aIdleTime) Then _IdleTime_StopStartPause($aIdleTime) ; Stop. _IdleTime_StopStartPause($aIdleTime) ; Start. EndIf EndIf Return $bReturn EndFunc ;==>_IdleTime_SetTime Func _IdleTime_StopStartPause(ByRef $aIdleTime) Local $bReturn = False If __IdleTime_IsAPI($aIdleTime) Then $bReturn = True If $aIdleTime[$IDLETIME_ISRUNNING] Then __IdleTime_Proc(0, 0) ; Set the static variablse in the procedure to the default of zero, thus clearing the previous values. AdlibUnRegister(__IdleTime_AdLibRegister) Else __IdleTime_Proc($aIdleTime[$IDLETIME_DELEGATE], $aIdleTime[$IDLETIME_TIME]) ; Set the static variables in the procedure to the required time when to move the mouse and delegate to call. AdlibRegister(__IdleTime_AdLibRegister, Ceiling($aIdleTime[$IDLETIME_TIME] / 3)) ; Register the function to be called time / 3. EndIf $aIdleTime[$IDLETIME_ISRUNNING] = Not $aIdleTime[$IDLETIME_ISRUNNING] EndIf Return $bReturn EndFunc ;==>_IdleTime_StopStartPause Func __IdleTime_IsAPI(ByRef $aIdleTime) Return UBound($aIdleTime) = $IDLETIME_MAX And $aIdleTime[$IDLETIME_ID] = $IDLETIME_GUID EndFunc ;==>__IdleTime_IsAPI Func __IdleTime_AdLibRegister() ; Wrapper for __IdleTime_Proc(), since AdLibRegister() doesn't accept functions with parameters. Return __IdleTime_Proc() EndFunc ;==>__IdleTime_AdLibRegister Func __IdleTime_Delegate(ByRef $aIdleTime, $hFunc) If Not IsFunc($hFunc) Then $hFunc = 0 $aIdleTime[$IDLETIME_DELEGATE] = $hFunc Return True EndFunc ;==>__IdleTime_Delegate Func __IdleTime_Proc($hSetFunc = Default, $iSetTime = Default) Local Static $hFunc = 0, _ $iTime = 0 If $hSetFunc = Default And $iSetTime = Default And $iTime > 0 Then If _WinAPI_GetIdleTime() >= $iTime Then Local $aPos = MouseGetPos() If Not @error Then Local Enum $POS_X, $POS_Y MouseMove($aPos[$POS_X] + 1, $aPos[$POS_Y]) MouseMove($aPos[$POS_X], $aPos[$POS_Y]) If IsFunc($hFunc) Then ; Call a function if it's set. $hFunc() EndIf EndIf EndIf Else If Not ($hSetFunc = Default) Then $hFunc = $hSetFunc If Not ($iSetTime = Default) Then $iTime = $iSetTime EndIf Return True EndFunc ;==>__IdleTime_Proc Func __IdleTime_Time(ByRef $aIdleTime, $iTime) If $iTime = Default Or $iTime < 750 Then $iTime = 750 ; 750 ms by default, since the procedure is checked 750 / 3 = 250 (which is the minimum for AdLibRegister()). $aIdleTime[$IDLETIME_TIME] = $iTime Return True EndFunc ;==>__IdleTime_Time #EndRegion IdleTime UDF
  25. Like
    guinness got a reaction from NassauSky in _ShellFile() - Create an entry in the shell contextmenu when selecting an assigned filetype, includes the program icon as well.   
    I created this after I developed >_ShellFolder() because I was interested in the entry displaying when an associated file was right clicked on. I was also intrigued to see how easy it would be to register a file type with my program, quite easy it appears. The UDF is a little different to what I've seen on the forum as this works with the Current User and/or All Users and an icon is created in the ContextMenu too.

    The entry will pass the file name to your program via a commandline argument, so you'll have to use $CmdLine/$CmdLineRaw to access the file that was selected.

    Any problems or suggestions then please post below. Thanks.

    UDF:

    #include-once ; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 ; #INDEX# ======================================================================================================================= ; Title .........: _ShellFile ; AutoIt Version : v3.2.12.1 or higher ; Language ......: English ; Description ...: Create an entry in the shell contextmenu when selecting an assigned filetype, includes the program icon as well. ; Note ..........: ; Author(s) .....: guinness ; Remarks .......: ; =============================================================================================================================== ; #INCLUDES# ==================================================================================================================== #include <Constants.au3> ; #GLOBAL VARIABLES# ============================================================================================================ ; None ; #CURRENT# ===================================================================================================================== ; _ShellFile_Install: Creates an entry in the 'All Users/Current Users' registry for displaying a program entry in the shell contextmenu, but only displays when selecting an assigned filetype to the program. ; _ShellFile_Uninstall: Deletes an entry in the 'All Users/Current Users' registry for displaying a program entry in the shell contextmenu. ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; None ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ShellFile_Install ; Description ...: Creates an entry in the 'All Users/Current Users' registry for displaying a program entry in the shell contextmenu, but only displays when selecting an assigned filetype to the program. ; Syntax ........: _ShellFile_Install($sText, $sFileType[, $sName = @ScriptName[, $sFilePath = @ScriptFullPath[, $sIconPath = @ScriptFullPath[, ; $iIcon = 0[, $fAllUsers = False[, $fExtended = False]]]]]]) ; Parameters ....: $sText - Text to be shown in the contextmenu. ; $sFileType - Filetype to be associated with the application e.g. .autoit or autoit. ; $sName - [optional] Name of the program. Default is @ScriptName. ; $sFilePath - [optional] Location of the program executable. Default is @ScriptFullPath. ; $sIconPath - [optional] Location of the icon e.g. program executable or dll file. Default is @ScriptFullPath. ; $iIcon - [optional] Index of icon to be used. Default is 0. ; $fAllUsers - [optional] Add to Current Users (False) or All Users (True) Default is False. ; $fExtended - [optional] Show in the Extended contextmenu using Shift + Right click. Default is False. ; Return values .: Success - Returns True ; Failure - Returns False and sets @error to non-zero. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _ShellFile_Install($sText, $sFileType, $sName = @ScriptName, $sFilePath = @ScriptFullPath, $sIconPath = @ScriptFullPath, $iIcon = 0, $fAllUsers = False, $fExtended = False) Local $i64Bit = '', $sRegistryKey = '' If $iIcon = Default Then $iIcon = 0 EndIf If $sFilePath = Default Then $sFilePath = @ScriptFullPath EndIf If $sIconPath = Default Then $sIconPath = @ScriptFullPath EndIf If $sName = Default Then $sName = @ScriptName EndIf If @OSArch = 'X64' Then $i64Bit = '64' EndIf If $fAllUsers Then $sRegistryKey = 'HKEY_LOCAL_MACHINE' & $i64Bit & '\SOFTWARE\Classes\' Else $sRegistryKey = 'HKEY_CURRENT_USER' & $i64Bit & '\SOFTWARE\Classes\' EndIf $sFileType = StringRegExpReplace($sFileType, '^\.+', '') $sName = StringLower(StringRegExpReplace($sName, '\.[^.\\/]*$', '')) If StringStripWS($sName, $STR_STRIPALL) = '' Or FileExists($sFilePath) = 0 Or StringStripWS($sFileType, $STR_STRIPALL) = '' Then Return SetError(1, 0, False) EndIf _ShellFile_Uninstall($sFileType, $fAllUsers) Local $iReturn = 0 $iReturn += RegWrite($sRegistryKey & '.' & $sFileType, '', 'REG_SZ', $sName) $iReturn += RegWrite($sRegistryKey & $sName & '\DefaultIcon\', '', 'REG_SZ', $sIconPath & ',' & $iIcon) $iReturn += RegWrite($sRegistryKey & $sName & '\shell\open', '', 'REG_SZ', $sText) $iReturn += RegWrite($sRegistryKey & $sName & '\shell\open', 'Icon', 'REG_EXPAND_SZ', $sIconPath & ',' & $iIcon) $iReturn += RegWrite($sRegistryKey & $sName & '\shell\open\command\', '', 'REG_SZ', '"' & $sFilePath & '" "%1"') $iReturn += RegWrite($sRegistryKey & $sName, '', 'REG_SZ', $sText) $iReturn += RegWrite($sRegistryKey & $sName, 'Icon', 'REG_EXPAND_SZ', $sIconPath & ',' & $iIcon) $iReturn += RegWrite($sRegistryKey & $sName & '\command', '', 'REG_SZ', '"' & $sFilePath & '" "%1"') If $fExtended Then $iReturn += RegWrite($sRegistryKey & $sName, 'Extended', 'REG_SZ', '') EndIf Return $iReturn > 0 EndFunc ;==>_ShellFile_Install ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ShellFile_Uninstall ; Description ...: Deletes an entry in the 'All Users/Current Users' registry for displaying a program entry in the shell contextmenu. ; Syntax ........: _ShellFile_Uninstall($sFileType[, $fAllUsers = False]) ; Parameters ....: $sFileType - Filetype to be associated with the application e.g. .autoit or autoit. ; $fAllUsers - [optional] Add to Current Users (False) or All Users (True) Default is False. ; Return values .: Success - Returns True ; Failure - Returns False and sets @error to non-zero. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _ShellFile_Uninstall($sFileType, $fAllUsers = False) Local $i64Bit = '', $sRegistryKey = '' If @OSArch = 'X64' Then $i64Bit = '64' EndIf If $fAllUsers Then $sRegistryKey = 'HKEY_LOCAL_MACHINE' & $i64Bit & '\SOFTWARE\Classes\' Else $sRegistryKey = 'HKEY_CURRENT_USER' & $i64Bit & '\SOFTWARE\Classes\' EndIf $sFileType = StringRegExpReplace($sFileType, '^\.+', '') If StringStripWS($sFileType, $STR_STRIPALL) = '' Then Return SetError(1, 0, False) EndIf Local $iReturn = 0, $sName = RegRead($sRegistryKey & '.' & $sFileType, '') If @error Then Return SetError(2, 0, False) EndIf $iReturn += RegDelete($sRegistryKey & '.' & $sFileType) $iReturn += RegDelete($sRegistryKey & $sName) Return $iReturn > 0 EndFunc ;==>_ShellFile_UninstallExample 1:


    #include <GUIConstantsEx.au3> #include '_ShellFile.au3' If @Compiled = 0 Then Exit MsgBox($MB_SYSTEMMODAL, '@Compiled Returned 0.', 'Please compile the program before testing. Thanks.') EndIf _Main() Func _Main() Local $sFilePath = '' If $CmdLine[0] > 0 Then $sFilePath = $CmdLine[1] EndIf Local $hGUI = GUICreate('_ShellFile() Example', 370, 110) GUICtrlCreateEdit(_GetFile($sFilePath), 10, 5, 350, 65) ; If a file was passed via commandline then random text will appear in the GUICtrlCreateEdit(). Local $iAdd = GUICtrlCreateButton('Add FileType', 10, 80, 75, 25) Local $iRemove = GUICtrlCreateButton('Remove FileType', 90, 80, 95, 25) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iAdd _ShellFile_Install('Open with _ShellFile()', 'autoit') ; Add the running EXE to the Shell ContextMenu. If @error Then MsgBox($MB_SYSTEMMODAL, 'Association NOT Created.', '".autoit" was not associated due to an error occurring.') Else MsgBox($MB_SYSTEMMODAL, 'Association Created.', '"RandomFile.autoit" file was created to show that the filetype ".autoit" has been associtated with ' & @ScriptName & '.' & _ @CRLF & @CRLF & 'If you restart the computer you''ll see the icon of "RandomFile.autoit" is the same as the program icon.' & _ @CRLF & @CRLF & 'Now close the program and double/right click on "RandomFile.autoit" to display the random text in the edit box.') EndIf _SetFile(_RandomText(5000), @ScriptDir & '\RandomFile.autoit', 1) ; Create a file with Random text. Case $iRemove _ShellFile_Uninstall('autoit') ; Remove the running EXE from the Shell ContextMenu. If @error Then MsgBox($MB_SYSTEMMODAL, 'Association NOT Deleted.', '".autoit" was not deleted from the Registry due to an error occurring.') Else MsgBox($MB_SYSTEMMODAL, 'Association Deleted.', '".autoit" was successfully deleted from the Registry and is no longer associated with ' & @ScriptName & '.') EndIf EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>_Main Func _GetFile($sFilePath, $sFormat = 0) Local $hFileOpen = FileOpen($sFilePath, $sFormat) If $hFileOpen = -1 Then Return SetError(1, 0, 'No File Was Passed Via Commandline.') EndIf Local $sData = FileRead($hFileOpen) FileClose($hFileOpen) Return $sData EndFunc ;==>_GetFile Func _RandomText($iLength = 7) Local $iCount = 0, $iCRLF, $sData = '', $sRandom For $i = 1 To $iLength $sRandom = Random(55, 116, 1) If $iCount = 100 Then $iCRLF = @CRLF $iCount = 0 EndIf $sData &= Chr($sRandom + 6 * ($sRandom > 90) - 7 * ($sRandom < 65)) & $iCRLF $iCount += 1 $iCRLF = '' Next Return $sData EndFunc ;==>_RandomText Func _SetFile($sString, $sFilePath, $iOverwrite = 0) Local $hFileOpen = FileOpen($sFilePath, $iOverwrite + 1) FileWrite($hFileOpen, $sString) FileClose($hFileOpen) If @error Then Return SetError(1, 0, $sString) EndIf Return $sString EndFunc ;==>_SetFileAll of the above has been included in a ZIP file. ShellFile.zip
×
×
  • Create New...