Leaderboard
Popular Content
Showing content with the highest reputation on 10/11/2018 in all areas
-
FAQ - Updated - Please Read Before Posting
Doniel and 2 others reacted to JLogan3o13 for a topic
Welcome to the forum! As a note to both new and current members and as mentioned above, please read the FAQs on the AutoIt Wiki before posting. This will save you time, as the answers to many common questions are out there. Most importantly for new forum members, please see the section on Why isn't my thread getting any replies? Forum members are here, volunteering their time to help you with your questions, and we will always do our best to assist. Below are just a few of the items we need from you in order to provide the best help, please see the FAQ section for more: First, foremost and always, know and follow the forum rules: Every member of this forum is expected to know and adhere to the forum rules. The rules are based on common sense and should not be daunting for anyone to follow. Doing so will ensure you receive assistance and will prevent any necessary sanctions by the Moderation team. We would much rather help you with your scripts than have to attend to the unpleasant business of suspending or banning accounts. Add a meaningful title to your thread: "HELP!!" tells no one anything, and will often delay your receiving assistance. Include a detailed description of what you are trying to do, what you have tried on your own, and what problem/error you are experiencing: "Doesn't work" or "AutoIt's broke" doesn't cut it. Forum members are also here to help you write and improve your own scripts; this is not a forum where you put in an order and someone writes the code for you. Always Post Code: Even if the code is not doing what you want it to, posting the code you are working from rather than asking forum members to guess is always going to result in more rapid assistance. If you cannot post the code for business reasons, create a script that reproduces the issue you are seeing.3 points -
Here is my ErrorLog.au3 UDF which I use every day. ErrorLog.au3 UDF is for log program activities and errors, to different output with possibility to switch output function instantly. UDF: #include-once #AutoIt3Wrapper_Run_AU3Check=Y #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #Tidy_Parameters=/sort_funcs /reel ; #AutoIt3Wrapper_Run_Debug_Mode=Y Global $__g_bUDF_ERRORLOG_FORCE_DEBUG = False Global $__g_sUDF_ERRORLOG_PREFIX = '--> ' Global $__g_sUDF_ERRORLOG_PREFIX_SUCCESS = '+ ' Global $__g_sUDF_ERRORLOG_PREFIX_EXTENDED = '- ' Global $__g_sUDF_ERRORLOG_PREFIX_ERROR = '! ' #Region ErrorLog.au3 - UDF Header ; #INDEX# ======================================================================================================================= ; Title .........: ErrorLog.au3 UDF - A logging Library ; AutoIt Version : 3.3.10.2++ ; Language ......: English ; Description ...: ErrorLog.au3 UDF is for log program activities and errors, to different output with possibility to switch output function instantly ; Author(s) .....: mLipok ; Modified ......: ; URL ...........: https://www.autoitscript.com/forum/topic/195882-errorlogau3-a-logging-library/ ; =============================================================================================================================== #cs UDF ChangeLog 2018/10/11 v1.0 * Added: UDF #INDEX# - mLipok * Added: UDF ChangeLog - mLipok * Added: Function: _Log_Errors_Reset() - mLipok * Renamed: Function: _Log_Errors() >> _Log_OnError() - mLipok * Changed: Function: better documentation in function headers - mLipok * Added: ErrorLog__Example.au3 - _Log_Example_1() , _Log_Example_2(), _Log_Example_3() - mLipok 2018/10/12 v1.1 * Added: Function: __Log_Wrapper() - a wrapper which put report to the output function - mLipok * Changed: Function: _Log_SetOutputFunction(Default) - return only function in any other case fires @error - mLipok * Refactored: Function: _Log() - mLipok * Refactored: Function: _Log_OnError() - mLipok * Added: GLOBAL: $__g_bUDF_ERRORLOG_FORCE_DEBUG - mLipok * Added: GLOBAL: $__g_sUDF_ERRORLOG_PREFIX_EXTENDED - mLipok * Added: GLOBAL: $__g_sUDF_ERRORLOG_PREFIX_SUCCESS - mLipok * Changed: GLOBAL: $__g_sUDF_ERRORLOG_ERROR_PREFIX >> $__g_sUDF_ERRORLOG_PREFIX_ERROR - mLipok * Added: Function: _Log_OnSuccess() - Log report to the output function but only if @error was not fired - mLipok * Added: Function: _Log_OnExtended() - Log report to the output function but only if @extended is set and @error was not fired - mLipok * Added: Function: _Log_Debug() - Log report to the output function but only if _Log_SetDebugMode(True) was used - mLipok * Added: Function: _Log_SetDebugMode() - Set the _Log_Debug() ON/OFF - mLipok * Changed: Function: much better documentation in function headers - mLipok * Added: UDF: #Region <> #EndRegion - mLipok * Added: UDF: #Tidy_Parameters=/sort_funcs /reel * Added: ErrorLog__Example.au3 - $__g_bUDF_ERRORLOG_FORCE_DEBUG - _Log_SetDebugMode() - mLipok * Added: ErrorLog__Example.au3 - _Log_Debug() - mLipok @LAST CHANGE LOG #ce UDF ChangeLog #EndRegion ErrorLog.au3 - UDF Header #Region ErrorLog.au3 - Functions ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Log ; Description ...: Log report to the output function ; Syntax ........: _Log($sText[, $iError = @error[, $iExtended = @extended]]) ; Parameters ....: $sText - a string value. Textual data which should be reported to the output function ; $iError - [optional] an integer value. Default is @error. Used to store @error ; $iExtended - [optional] an integer value. Default is @extended. Used to store @extended ; Return values .: None - and set @error and @extended to stored values ; Author ........: mLipok ; Modified ......: ; Remarks .......: This function will not send log reports to output if _Log_SetOutputFunction() is not properly set ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _Log($sText = '', $iError = @error, $iExtended = @extended) __Log_Wrapper( _ (($iError Or $iExtended) ? ($__g_sUDF_ERRORLOG_PREFIX_ERROR & '[ ' & $iError & ' / ' & $iExtended & ' ] : ') : ($__g_sUDF_ERRORLOG_PREFIX)) _ & $sText _ ) Return SetError($iError, $iExtended) EndFunc ;==>_Log ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Log_Change ; Description ...: Log report to the output function but only if @error or @extended occurs OR if reported data has changed ; Syntax ........: _Log_Change([$sText = ''[, $iError = @error[, $iExtended = @extended]]]) ; Parameters ....: $sText - a string value. Textual data which should be reported to the output function ; $iError - [optional] an integer value. Default is @error. ; $iExtended - [optional] an integer value. Default is @extended. ; Return values .: None - and set @error and @extended to stored values ; Author ........: mLipok ; Modified ......: ; Remarks .......: This function will not send log reports to output if there is no change and no message, or if _Log_SetOutputFunction() is not properly set ; Related .......: _Log ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _Log_Change($sText = '', $iError = @error, $iExtended = @extended) Local Static $sText_static = '' Local Static $iError_static = 0 Local Static $iExtended_static = 0 If $sText <> '' Or $iError Or $iExtended And _ ($sText_static <> $sText Or $iError_static <> $iError Or $iExtended_static <> $iExtended) _ Then _Log($sText, $iError, $iExtended) $sText_static = $sText $iError_static = $iError $iExtended_static = $iExtended EndIf Return SetError($iError, $iExtended) EndFunc ;==>_Log_Change ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Log_Debug ; Description ...: Log report to the output function but only if _Log_SetDebugMode(True) was used ; Syntax ........: _Log_Debug($sText[, $iError = @error[, $iExtended = @extended]]) ; Parameters ....: $sText - a string value. Textual data which should be reported to the output function ; $iError - [optional] an integer value. Default is @error. Used to store @error ; $iExtended - [optional] an integer value. Default is @extended. Used to store @extended ; Return values .: None - and set @error and @extended to stored values ; Author ........: mLipok ; Modified ......: ; Remarks .......: This function will not send log reports to output if _Log_SetOutputFunction() is not properly set ; Related .......: _Log ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _Log_Debug($sText, $iScriptLineNumber = @ScriptLineNumber, $iError = @error, $iExtended = @extended) If $__g_bUDF_ERRORLOG_FORCE_DEBUG == True Then __Log_Wrapper('@@ Debug(' & $iScriptLineNumber & ') : [ ' & $iError & ' / ' & $iExtended & ' ] : ' & $sText) Return SetError($iError, $iExtended) EndFunc ;==>_Log_Debug ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Log_Errors_Reset ; Description ...: Resetting @error and @extended to 0 ; Syntax ........: _Log_Errors_Reset() ; Parameters ....: None ; Return values .: None - and set @error and @extended to 0 ; Author ........: mLipok ; Modified ......: ; Remarks .......: this is only wrapper for SetError(0, 0) ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _Log_Errors_Reset() Return SetError(0, 0) EndFunc ;==>_Log_Errors_Reset ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Log_Errors_ReStore ; Description ...: Restore previously stored @error and @extended ; Syntax ........: _Log_Errors_ReStore() ; Parameters ....: None ; Return values .: None - and set @error and @extended to stored values ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: _Log_Errors_Store ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _Log_Errors_ReStore() _Log_Errors_Store(Default, Default) Return SetError(@error, @extended) EndFunc ;==>_Log_Errors_ReStore ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Log_Errors_Store ; Description ...: Store @error and @extended ; Syntax ........: _Log_Errors_Store([$iError = @error[, $iExtended = @extended]]) ; Parameters ....: $iError - [optional] an integer value. Default is @error. ; $iExtended - [optional] an integer value. Default is @extended. ; Return values .: None - and set @error and @extended to stored values ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: _Log_Errors_ReStore ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _Log_Errors_Store($iError = @error, $iExtended = @extended) Local Static $iError_static = 0, $iExtended_static = 0 If $iError = Default And $iExtended = Default Then $iError = $iError_static $iExtended = $iExtended_static $iError_static = 0 $iExtended_static = 0 Return SetError($iError, $iExtended) EndIf $iError_static = $iError $iExtended_static = $iExtended Return SetError($iError, $iExtended) EndFunc ;==>_Log_Errors_Store ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Log_OnError ; Description ...: Log report to the output function but only if @error occurs ; Syntax ........: _Log_OnError($sText[, $iError = @error[, $iExtended = @extended]]) ; Parameters ....: $sText - a string value. Textual data which should be reported to the output function ; $iError - [optional] an integer value. Default is @error. Used to store @error ; $iExtended - [optional] an integer value. Default is @extended. Used to store @extended ; Return values .: None - and set @error and @extended to stored values ; Author ........: mLipok ; Modified ......: ; Remarks .......: This function will not send log reports to output if _Log_SetOutputFunction() is not properly set ; Related .......: _Log ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _Log_OnError($sText, $iError = @error, $iExtended = @extended) If $iError Then __Log_Wrapper($__g_sUDF_ERRORLOG_PREFIX_ERROR & '@error=' & $iError & ' @extended=' & $iExtended & ' :: ' & $sText) Return SetError($iError, $iExtended) EndFunc ;==>_Log_OnError ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Log_OnExtended ; Description ...: Log report to the output function but only if @extended is set and @error was not fired - mLipok ; Syntax ........: _Log_OnExtended($sText[, $iError = @error[, $iExtended = @extended]]) ; Parameters ....: $sText - a string value. Textual data which should be reported to the output function ; $iError - [optional] an integer value. Default is @error. Used to store @error ; $iExtended - [optional] an integer value. Default is @extended. Used to store @extended ; Return values .: None - and set @error and @extended to stored values ; Author ........: mLipok ; Modified ......: ; Remarks .......: This function will not send log reports to output if _Log_SetOutputFunction() is not properly set ; Related .......: _Log ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _Log_OnExtended($sText, $iError = @error, $iExtended = @extended) If $iExtended And $iError = 0 Then __Log_Wrapper($__g_sUDF_ERRORLOG_PREFIX_EXTENDED & '[ ' & $iError & ' / ' & $iExtended & ' ] : ' & $sText) Return SetError($iError, $iExtended) EndFunc ;==>_Log_OnExtended ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Log_OnSuccess ; Description ...: Log report to the output function but only if @error was not fired ; Syntax ........: _Log_OnSuccess($sText[, $iError = @error[, $iExtended = @extended]]) ; Parameters ....: $sText - a string value. Textual data which should be reported to the output function ; $iError - [optional] an integer value. Default is @error. Used to store @error ; $iExtended - [optional] an integer value. Default is @extended. Used to store @extended ; Return values .: None - and set @error and @extended to stored values ; Author ........: mLipok ; Modified ......: ; Remarks .......: This function will not send log reports to output if _Log_SetOutputFunction() is not properly set ; Related .......: _Log ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _Log_OnSuccess($sText, $iError = @error, $iExtended = @extended) If $iError = 0 Then __Log_Wrapper($__g_sUDF_ERRORLOG_PREFIX_SUCCESS & '[ ' & $iError & ' / ' & $iExtended & ' ] : ' & $sText) Return SetError($iError, $iExtended) EndFunc ;==>_Log_OnSuccess ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Log_SetDebugMode ; Description ...: Set the _Log_Debug() ON/OFF ; Syntax ........: _Log_SetOutputFunction($bForceDebug) ; Parameters ....: $bForceDebug - a boolean value. True=ON, False=OFF for _Log_Debug() ; Return values .: none or set @error to 1 ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: _Log_Debug ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _Log_SetDebugMode($bForceDebug) If Not IsBool($bForceDebug) Then Return SetError(1) $__g_bUDF_ERRORLOG_FORCE_DEBUG = $bForceDebug EndFunc ;==>_Log_SetDebugMode ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Log_SetOutputFunction ; Description ...: Set the function to which Log reports should be passed ; Syntax ........: _Log_SetOutputFunction([$fnFunction = Default]) ; Parameters ....: $fnFunction - [optional] a floating point value. Default is Default. ; Return values .: $fnFunction_static - saved output function, in any other case fires @error ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _Log_SetOutputFunction($fnFunction = Default) Local Static $fnFunction_static = Null If $fnFunction = Default And IsFunc($fnFunction_static) Then Return $fnFunction_static If Not IsFunc($fnFunction) Then Return SetError(1) $fnFunction_static = $fnFunction Return $fnFunction_static EndFunc ;==>_Log_SetOutputFunction #EndRegion ErrorLog.au3 - Functions #Region ErrorLog.au3 - Internal Functions ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __Log_Wrapper ; Description ...: a wrapper which put report to the output function ; Syntax ........: __Log_Wrapper($sText) ; Parameters ....: $sText - a string value. Textual data which should be reported to the output function ; Return values .: None or set @error = 1 in case _Log_SetOutputFunction() was not used or used not properly ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: _Log, _Log_OnError, _Log_OnExtended, _Log_OnSuccess, _Log_Change ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __Log_Wrapper($sText) Local $fnFunction = _Log_SetOutputFunction() If @error Then Return SetError(1) $fnFunction($sText) EndFunc ;==>__Log_Wrapper #EndRegion ErrorLog.au3 - Internal Functions EXAMPLE: #include <WinAPIProc.au3> #include-once #AutoIt3Wrapper_Run_AU3Check=Y #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; #AutoIt3Wrapper_Run_Debug_Mode=Y ; #Tidy_Parameters=/sort_funcs /reel #include <Debug.au3> #include "ErrorLog.au3" If Not @Compiled Then $__g_bUDF_ERRORLOG_FORCE_DEBUG = True ; Pre set function to where log report is passed _Log_SetOutputFunction(ConsoleWrite) _Log_Debug("EXAMPLE 1: START" & @CRLF, @ScriptLineNumber) _Log_Example_1() ; check again for @error If @error Then MsgBox($MB_ICONERROR, 'Example 1: Error Occured', _ 'File Reading Problem.' & @CRLF & _ '@error = ' & @error & @CRLF & _ '@extended = ' & @extended _ ) _Log_Debug("EXAMPLE 2: START" & @CRLF, @ScriptLineNumber) _Log_Example_2() _Log_Debug("EXAMPLE 3: START", @ScriptLineNumber) _Log_Example_3() _Log_SetOutputFunction(_ConsoleWrite_Wrapper) _Log_Debug("EXAMPLES: END", @ScriptLineNumber) Func _Log_Example_1() ; sending description to log output _Log('Example 1: We are trying to read file.' & @CR) ; fire @error FileRead('FILE PATH WHICH NOT EXIST') ; report @error but do not change it - store it and back it again _Log_OnError('Example 1: File Reading Problem.' & @CR) Return SetError(@error, @extended) EndFunc ;==>_Log_Example_1 Func _Log_Example_2() ; set function to where log reports will be passed _Log_SetOutputFunction(_ConsoleWrite_Wrapper) ; sending description to log output _Log('Example 2: We are trying to read file.') For $iAttempt_idx = 1 To 15 _log('Example 2: $iAttempt_idx = ' & $iAttempt_idx) ; fire @error If $iAttempt_idx < 14 Then FileRead('FILE PATH WHICH NOT EXIST') ; next line will log only in step #12 and #13 - as only to step #13 , errors ocurrs If $iAttempt_idx > 11 Then _Log_OnError('Example 2: File Reading error' & @CR) ; fake @error to show what _Log_Change() will do when @error is changing If $iAttempt_idx = 5 Then SetError(2) ; fake @exteneded to show what _Log_Change() will do when @exteneded is changing If $iAttempt_idx = 10 Then SetError(@error, 2) ; string change If $iAttempt_idx > 13 Then _Log_Change('Some other log data') ; report to log output but only first unique occurance _Log_Change('Example 2: File Reading Problem.' & @CR) _Log_Errors_Reset() ; if you do not reset then @error and @extended could be followed to next loop. Next EndFunc ;==>_Log_Example_2 Func _Log_Example_3() ; set function to where log reports will be passed _Log_SetOutputFunction(_ConsoleWrite_Wrapper) ; sending description to log output _Log('Example 3: We are trying to read file.') For $iAttempt_idx = 1 To 15 ; If $iAttempt_idx = 9 change output function - from this moment log reports will be passed to _DebugOut() instead _ConsoleWrite_Wrapper() If $iAttempt_idx = 9 Then _DebugSetup("Example 3: ErrorLog.au3 - output") _Log_SetOutputFunction(_DebugOut) EndIf _log('Example 3: $iAttempt_idx = ' & $iAttempt_idx) ; fire @error If $iAttempt_idx < 14 Then FileRead('FILE PATH WHICH NOT EXIST') ; next line will log only in step #12 and #13 - as only to step #13 , errors ocurrs If $iAttempt_idx > 11 Then _Log_OnError('Example 3: File Reading error') ; fake @error to show what _Log_Change() will do when @error is changing If $iAttempt_idx = 5 Then SetError(2) ; fake @exteneded to show what _Log_Change() will do when @exteneded is changing If $iAttempt_idx = 10 Then SetError(@error, 2) ; string change If $iAttempt_idx > 13 Then _Log_Change('Example 3: Some other log data') ; report to log output but only first unique occurance _Log_Change('Example 3: File Reading Problem.' & @CR) _Log_Errors_Reset() ; if you do not reset then @error and @extended could be followed to next loop. Next EndFunc ;==>_Log_Example_3 Func _ConsoleWrite_Wrapper($sData) ConsoleWrite($sData & @CRLF) EndFunc ;==>_ConsoleWrite_Wrapper REMARKS: Documentation in function headers is currently complete1 point
-
[UDF] Gmail API - Emails automation with AutoIt!
argumentum reacted to BrewManNH for a topic
It's not used correctly, the Ternary operator doesn't return a value, so assigning it to one is pointless. Remove all variable references used with the Ternary operator anywhere you see something like this: $bQuestion = IsArray($aEmailAdress) ? _TableInsert($aTable, $aEmailAdress[0]) : _TableInsert($aTable, "") Also remove the variable declaration because $bQuestion isn't used anywhere that it is needed. Second, don't declare variables conditionally like this: If IsArray($sRemoveLabelIds) Then Local $iUbound = UBound($sRemoveLabelIds) Declare the variable, then assign something to it inside the If statements. Don't declare it twice depending on whether the If statement is valid1 point -
I've been using this for years. works great! I'm sure I got it from this site, but I can't remember who posted it. $aRet = DllCall('kernel32.dll', 'long', 'SetThreadExecutionState', 'long', 0x80000003) ;Disable windows sleep mode by making it think it's playing a movie in full screen $aRet=DllCall('kernel32.dll','long','SetThreadExecutionState','long',0x80000000) ;Remove the always on so it will go to sleep1 point
-
You can use _WinAPI_SetThreadExecutionState. Remarks say: This function does not stop the screen saver from executing. But actually You could do this to prevent screen saver execution. _WinAPI_SetThreadExecutionState(BitOR($ES_DISPLAY_REQUIRED, $ES_CONTINUOUS)) Saludos1 point
-
<Please Delete! Solved> - Send keys to cmd.exe only working if already open
spudw2k reacted to JLogan3o13 for a topic
@Fractured as a rule we do not deleted threads. We have all had that experience where we post a question and then 2 minutes later figure it out ourselves. If you post a detailed explanation of what you did to resolve the issue, it may help someone down the road looking at the same problem.1 point -
Word Searching (Fun Little program)
Skeletor reacted to kingjacob90 for a topic
I have this very simple but possibly quite complicated idea for a program. It is kind of a rip of the "Find" function used in many programs and really is in a way a re-create. The problem is it take ages for the program to process the information and that is on a good PC (i5-6600, 16GB DDR4, SSD). The question, why? Why cant it work just like the find function, and how does the find function in many programs work so efficiently? Website for the words file as only allowed 4MB and it is 5MB : https://raw.githubusercontent.com/dwyl/english-words/master/words.txt Code: #include <File.au3> $Letters = InputBox("Letters","Input the letters you have.","","") If @error Then Exit $File_Words = @ScriptDir&"\words.txt" $Words = "Words:" $Amount = StringLen($Letters) $lines = _FileCountLines($File_Words) ProgressOn("Searching...","","") ProgressSet(0) For $i = 0 To $Amount $string = StringTrimRight($Letters,$i) For $j = 1 To $lines ProgressSet($lines/$j) If FileReadLine($File_Words,$j) = $string Then $Words = $Words&@CRLF&$string EndIf Next Next MsgBox(0,'',$Words)1 point -
Oh... Yeah no doubt filefindfirstfile @careca had it for you $hSearch = FileFindFirstFile("*.*") $sFileName = "" $sFileName = FileFindNextFile($hSearch)1 point
-
Try this: #include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <GuiListBox.au3> Global $Files[0] Global $File_Attr[0][3] Global $Attr_Name[3] = ["", "", ""] Global $DB_Name = "Database4.accdb" Global $Table_Name = "bhanu" Global $Attr_Name[3] = ["", "", ""] _DBUpdate() $Form_Main = GUICreate("GUI managing Database", 250, 380) $Group_Attributes = GUICtrlCreateGroup("Attributes", 20, 20, 200, 130) $Checkbox_1 = GUICtrlCreateCheckbox($Attr_Name[0], 40, 50) $Checkbox_2 = GUICtrlCreateCheckbox($Attr_Name[1], 40, 80) $Checkbox_3 = GUICtrlCreateCheckbox($Attr_Name[2], 40, 110) $idAddFile = GUICtrlCreateButton("Add", 160, 110, 50, 20) $Group_Files = GUICtrlCreateGroup("Files", 20, 160, 200, 200) $List = GUICtrlCreateList("", 40, 180, 180, 180) GUISetState(@SW_SHOW) ; GUI loop While 1 $msg = GUIGetMsg() Switch $msg Case $Checkbox_1, $Checkbox_2, $Checkbox_3 GUICtrlSetData($List, "") Access($Checkbox_1) Access($Checkbox_2) Access($Checkbox_3) Case $GUI_EVENT_CLOSE ; Close GUI ExitLoop Case $idAddFile $sFiles = FileOpenDialog("Select Files", @ScriptDir, "Text Files(*.txt)", 5) If @error Then ContinueLoop $AdoCon = ObjCreate("ADODB.Connection") $AdoCon.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & $DB_Name) $AdoRs = ObjCreate("ADODB.Recordset") $AdoRs.CursorType = 2 $AdoRs.LockType = 3 $AdoRs.Open("SELECT * FROM " & $Table_Name, $AdoCon) $aFiles = StringSplit($sFiles, "|") Switch $aFiles[0] Case 1 $AdoRs.AddNew $AdoRs.Fields("Feld1").value = StringTrimLeft($aFiles[1], StringInStr($aFiles[1], "\", 0, -1)) If BitAnd(GUICtrlRead($Checkbox_1),$GUI_CHECKED) = $GUI_CHECKED Then $AdoRs.Fields("Feld2").value = GUICtrlRead($Checkbox_1, 1) If BitAnd(GUICtrlRead($Checkbox_2),$GUI_CHECKED) = $GUI_CHECKED Then $AdoRs.Fields("Feld3").value = GUICtrlRead($Checkbox_2, 1) If BitAnd(GUICtrlRead($Checkbox_3),$GUI_CHECKED) = $GUI_CHECKED Then $AdoRs.Fields("Feld4").value = GUICtrlRead($Checkbox_3, 1) $AdoRs.Update Case 2 To $aFiles[0] For $i = 2 To $aFiles[0] $AdoRs.AddNew $AdoRs.Fields("Feld1").value = $aFiles[$i] If BitAnd(GUICtrlRead($Checkbox_1),$GUI_CHECKED) = $GUI_CHECKED Then $AdoRs.Fields("Feld2").value = GUICtrlRead($Checkbox_1, 1) If BitAnd(GUICtrlRead($Checkbox_2),$GUI_CHECKED) = $GUI_CHECKED Then $AdoRs.Fields("Feld3").value = GUICtrlRead($Checkbox_2, 1) If BitAnd(GUICtrlRead($Checkbox_3),$GUI_CHECKED) = $GUI_CHECKED Then $AdoRs.Fields("Feld4").value = GUICtrlRead($Checkbox_3, 1) $AdoRs.Update Next EndSwitch $AdoRs.close $AdoCon.Close _DBUpdate() GUICtrlSetData($List, "") Access($Checkbox_1) Access($Checkbox_2) Access($Checkbox_3) EndSwitch WEnd Func Access($Checkbox) If GUICtrlRead($Checkbox) = $GUI_CHECKED Then Local $Chkbox_label = GUICtrlRead($Checkbox, 1) For $i = 0 To UBound($Files) - 1 Step 1 If $File_Attr[$i][0] = $Chkbox_label Or $File_Attr[$i][1] = $Chkbox_label Or $File_Attr[$i][2] = $Chkbox_label Then _GUICtrlListBox_AddString($List, $Files[$i]) EndIF Next EndIF EndFunc Func _DBUpdate() $AdoCon = ObjCreate("ADODB.Connection") $AdoCon.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & $DB_Name) $AdoRs = ObjCreate("ADODB.Recordset") $AdoRs.CursorType = 1 $AdoRs.LockType = 3 $AdoRs.Open("SELECT COUNT(*) FROM " & $Table_Name, $AdoCon) $dimension = $AdoRs.Fields(0).Value ReDim $Files[$dimension] ReDim $File_Attr[$dimension][3] For $i = 0 To UBound($Files) - 1 Step 1 $AdoRs = ObjCreate("ADODB.Recordset") $AdoRs.CursorType = 1 $AdoRs.LockType = 3 $AdoRs.Open("SELECT * FROM " & $Table_Name & " WHERE ID = " & ($i + 1), $AdoCon) $Files[$i] = $AdoRs.Fields(1).Value $File_Attr[$i][0] = $AdoRs.Fields(2).Value $File_Attr[$i][1] = $AdoRs.Fields(3).Value $File_Attr[$i][2] = $AdoRs.Fields(4).Value Next $AdoRs.Close $AdoCon.Close Local $a = 0 For $i = 0 To UBound($Files) - 1 Step 1 For $j = 0 To 2 Step 1 If $a < 3 And Not $File_Attr[$i][$j] = "" Then For $k = $a To 2 Step 1 If $Attr_Name[$k] = $File_Attr[$i][$j] Then ContinueLoop 2 EndIf Next $Attr_Name[$a] = $File_Attr[$i][$j] $a = $a + 1 EndIf Next Next EndFunc1 point
-
There are some ways, you can retrieve all folders to array and stringinstr it, or go with FileFindFirstFile1 point
-
New version in first post:1 point
-
MS .NET frammework issue ? https://en.wikipedia.org/wiki/Microsoft_UI_Automation And #RequireAdmin if the application [CLASS:#32770] Is runned as admin.1 point
-
Random() But biased
FrancescoDiMuro reacted to mikell for a topic
This requirement makes the use of Random difficult Suggestion : #Include <Array.au3> ; first populate the array with 90% 0 and 10% 1 Local $array[100] For $i = 0 to 89 $array[$i] = 0 Next For $i = 89 to 99 $array[$i] = 1 Next ; then shuffle the array _ArrayShuffle($array) _ArrayDisplay($array)1 point -
#include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() Local $sGetData Local $sFilename = @ScriptDir & "\File.txt" Local $aFilename, $x = 10, $y = 10 _FileReadToArray($sFilename, $aFilename, 0, ",") If @error Then Exit MsgBox(4096, "File Read Error", "Unable to read file into an Array") If UBound($aFilename, 2) <= 1 Then Exit MsgBox(4096, "File Read Error", "File cannot be stored in 2d Array") Local $aControl = $aFilename GUICreate("", 330, 10 + (30 * UBound($aFilename) - 1) + 40) $iStart = GUICtrlCreateDummy() For $i = 0 To UBound($aFilename) - 1 For $j = 0 To UBound($aFilename, 2) - 1 $aControl[$i][$j] = GUICtrlCreateInput($aFilename[$i][$j], $x, $y, 100, 20) $x += 105 Next $x = 10 $y += 30 Next Local $idData = GUICtrlCreateButton("Get Data", 220, $y, 100, 30) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $idData For $i = 0 To UBound($aControl) - 1 MsgBox(4096, $i & " Line Data", 'Name is: '&GUICtrlRead($aControl[$i][0])&', '&GUICtrlRead($aControl[$i][1])&' years old, '&GUICtrlRead($aControl[$i][2])&' city') Next EndSwitch WEnd EndFunc Like that?1 point
-
Another example: #include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() Local $sGetData Local $sFilename = @ScriptDir & "\File.txt" Local $aFilename, $x = 10, $y = 10 _FileReadToArray($sFilename, $aFilename, 0, ",") If @error Then Exit MsgBox(4096, "File Read Error", "Unable to read file into an Array") If UBound($aFilename, 2) <= 1 Then Exit MsgBox(4096, "File Read Error", "File cannot be stored in 2d Array") Local $aControl = $aFilename GUICreate("", 330, 10 + (30 * UBound($aFilename) - 1) + 40) $iStart = GUICtrlCreateDummy() For $i = 0 To UBound($aFilename) - 1 For $j = 0 To UBound($aFilename, 2) - 1 $aControl[$i][$j] = GUICtrlCreateInput($aFilename[$i][$j], $x, $y, 100, 20) $x += 105 Next $x = 10 $y += 30 Next Local $idData = GUICtrlCreateButton("Get Data", 220, $y, 100, 30) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $idData For $i = 0 To UBound($aControl) - 1 $sGetData = "" For $j = 0 To UBound($aControl, 2) - 1 $sGetData &= GUICtrlRead($aControl[$i][$j]) & @CRLF Next MsgBox(4096, $i & " Line Data", $sGetData) Next EndSwitch WEnd EndFunc1 point
-
I have understand ! In your function _WD_Option you're waiting fot an integer and my variable $sPort is string, so the process doen't assign the port value ! I changed it in integer an it is working ! Case "Port" If $vValue == "" Then Return $_WD_PORT If Not IsInt($vValue) Then Return SetError(__WD_Error($sFuncName, $_WD_ERROR_InvalidDataType, "(int) $vValue: " & $vValue), 0, 0) EndIf $_WD_PORT = $vValue By chance in the parameter of Chromedriver.exe do you know the difference between "port" and "adb-port" ? To be shure I fix both ! Thank for helping1 point
-
How to read from txt file
Lisuter reacted to JLogan3o13 for a topic
@Lisuter as an awareness, in the future - especially when dealing with a GUI - you will always receive more help if you post your entire code rather than asking us to guess at what you are trying to do. That said, if you are trying to simply update the input fields on the GUI with a line from the text file, you could do something like this: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Local $aFile = FileReadToArray("test.txt") Local $hGUI = GuiCreate("Test", 300, 200) Local $Input1 = GUICtrlCreateInput("", 10, 10, 90, 50) Local $Input2 = GUICtrlCreateInput("", 105, 10, 90, 50) Local $Input3 = GUICtrlCreateInput("", 200, 10, 90, 50) Local $sGo = GUICtrlCreateButton("Go", 250, 150, 40, 40) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $sGo For $sLine In $aFile $aTemp = StringSplit($sLine, ",") GUICtrlSetData($Input1, $aTemp[1]) GUICtrlSetData($Input2, $aTemp[2]) GUICtrlSetData($Input3, $aTemp[3]) Sleep(1000) Next EndSwitch WEnd If you are looking rather to add all the lines into the input fields, you can do something like this: #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Local $aFile = FileReadToArray("test.txt") Local $hGUI = GuiCreate("Test", 300, 200) Local $Input1 = GUICtrlCreateInput("", 10, 10, 90, 50, $ES_MULTILINE) Local $Input2 = GUICtrlCreateInput("", 105, 10, 90, 50, $ES_MULTILINE) Local $Input3 = GUICtrlCreateInput("", 200, 10, 90, 50, $ES_MULTILINE) Local $sGo = GUICtrlCreateButton("Go", 250, 150, 40, 40) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $sGo For $sLine In $aFile $aTemp = StringSplit($sLine, ",") GUICtrlSetData($Input1, ((GUICtrlRead($Input1) = "") ? $aTemp[1] :GUICtrlRead($Input1) & @CRLF & $aTemp[1])) GUICtrlSetData($Input2, ((GUICtrlRead($Input2) = "") ? $aTemp[2] :GUICtrlRead($Input2) & @CRLF & $aTemp[2])) GUICtrlSetData($Input3, ((GUICtrlRead($Input3) = "") ? $aTemp[3] :GUICtrlRead($Input3) & @CRLF & $aTemp[3])) Sleep(1000) Next EndSwitch WEnd Beyond a couple of lines, however, you may want to switch to a listview for easier handling.1 point -
You could use an array. Here's one example: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $aCheckbox[2] #Region ### START Koda GUI section ### Form= Global $frmMainForm = GUICreate("A Form", 161, 112, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") $aCheckbox[0] = GUICtrlCreateCheckbox("First Checkbox", 16, 15, 113, 17) GUICtrlSetFont(-1, 10, 400, 0, "Arial") $aCheckbox[1] = GUICtrlCreateCheckbox("Second Checkbox", 16, 39, 129, 17) GUICtrlSetFont(-1, 10, 400, 0, "Arial") Global $btnButton1 = GUICtrlCreateButton("Button", 43, 71, 75, 25) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUICtrlSetOnEvent(-1, "ButtonPress") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func ExitApplication() Exit EndFunc Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc Func ButtonPress() For $iCheckbox = 0 to UBound($aCheckbox)-1 If _IsChecked($aCheckbox[$iCheckbox]) Then ConsoleWrite("$aCheckbox[" & $iCheckbox & "] is selected." & @CRLF) Else ConsoleWrite("$aCheckbox[" & $iCheckbox & "] is NOT selected." & @CRLF) EndIf Next EndFunc If you wanted to get fancy, you could keep track of the checked boxes as they are checked and not have to enumerate through all of them later.1 point
-
Haven't tested, but you should be able to modify the following code to fit your needs. #include <Array.au3> #include <GUIConstantsEx.au3> #include <GuiListBox.au3> Global $Files[0] Global $File_Attr[0][3] Global $Attr_Name[3] = ["", "", ""] Global $DB_Name = "Database4.accdb" Global $Table_Name = "bhanu" Global $Attr_Name[3] = ["", "", ""] _DBUpdate() $Form_Main = GUICreate("GUI managing Database", 250, 380) $Group_Attributes = GUICtrlCreateGroup("Attributes", 20, 20, 200, 130) $Checkbox_1 = GUICtrlCreateCheckbox($Attr_Name[0], 40, 50) $Checkbox_2 = GUICtrlCreateCheckbox($Attr_Name[1], 40, 80) $Checkbox_3 = GUICtrlCreateCheckbox($Attr_Name[2], 40, 110) $idAddFile = GUICtrlCreateButton("Add", 160, 110, 50, 20) $Group_Files = GUICtrlCreateGroup("Files", 20, 160, 200, 200) $List = GUICtrlCreateList("", 40, 180, 180, 180) GUISetState(@SW_SHOW) ; GUI loop While 1 $msg = GUIGetMsg() Switch $msg Case $Checkbox_1, $Checkbox_2, $Checkbox_3 GUICtrlSetData($List, "") Access($Checkbox_1) Access($Checkbox_2) Access($Checkbox_3) Case $GUI_EVENT_CLOSE ; Close GUI ExitLoop Case $idAddFile $sFiles = FileOpenDialog("Select Files", @ScriptDir, "Text Files(*.txt)", 5) If @error Then ContinueLoop $AdoCon = ObjCreate("ADODB.Connection") $AdoCon.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & $DB_Name) $AdoRs = ObjCreate("ADODB.Recordset") $AdoRs.CursorType = 2 $AdoRs.LockType = 3 $AdoRs.Open("SELECT * FROM " & $Table_Name, $AdoCon) $aFiles = StringSplit($sFiles, "|") Switch $aFiles[0] Case 1 $AdoRs.AddNew $AdoRs.Fields("Feld1").value = $aFiles[1] If BitAnd(GUICtrlRead($Checkbox_1),$GUI_CHECKED) = $GUI_CHECKED Then $AdoRs.Fields("Feld2").value = GUICtrlRead($Checkbox_1, 1) If BitAnd(GUICtrlRead($Checkbox_2),$GUI_CHECKED) = $GUI_CHECKED Then $AdoRs.Fields("Feld3").value = GUICtrlRead($Checkbox_2, 1) If BitAnd(GUICtrlRead($Checkbox_3),$GUI_CHECKED) = $GUI_CHECKED Then $AdoRs.Fields("Feld4").value = GUICtrlRead($Checkbox_3, 1) $AdoRs.Update Case 2 To $aFiles[0] For $i = 2 To $aFiles[0] $AdoRs.AddNew $AdoRs.Fields("Feld1").value = $aFiles[1] & "\" & $aFiles[$i] If BitAnd(GUICtrlRead($Checkbox_1),$GUI_CHECKED) = $GUI_CHECKED Then $AdoRs.Fields("Feld2").value = GUICtrlRead($Checkbox_1, 1) If BitAnd(GUICtrlRead($Checkbox_2),$GUI_CHECKED) = $GUI_CHECKED Then $AdoRs.Fields("Feld3").value = GUICtrlRead($Checkbox_2, 1) If BitAnd(GUICtrlRead($Checkbox_3),$GUI_CHECKED) = $GUI_CHECKED Then $AdoRs.Fields("Feld4").value = GUICtrlRead($Checkbox_3, 1) $AdoRs.Update Next EndSwitch $AdoRs.close $AdoCon.Close _DBUpdate() GUICtrlSetData($List, "") Access($Checkbox_1) Access($Checkbox_2) Access($Checkbox_3) EndSwitch WEnd Func Access($Checkbox) If GUICtrlRead($Checkbox) = $GUI_CHECKED Then Local $Chkbox_label = GUICtrlRead($Checkbox, 1) For $i = 0 To UBound($Files) - 1 Step 1 If $File_Attr[$i][0] = $Chkbox_label Or $File_Attr[$i][1] = $Chkbox_label Or $File_Attr[$i][2] = $Chkbox_label Then _GUICtrlListBox_AddString($List, $Files[$i]) EndIF Next EndIF EndFunc Func _DBUpdate() $AdoCon = ObjCreate("ADODB.Connection") $AdoCon.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & $DB_Name) $AdoRs = ObjCreate("ADODB.Recordset") $AdoRs.CursorType = 1 $AdoRs.LockType = 3 $AdoRs.Open("SELECT COUNT(*) FROM " & $Table_Name, $AdoCon) $dimension = $AdoRs.Fields(0).Value ReDim $Files[$dimension] ReDim $File_Attr[$dimension][3] For $i = 0 To UBound($Files) - 1 Step 1 $AdoRs = ObjCreate("ADODB.Recordset") $AdoRs.CursorType = 1 $AdoRs.LockType = 3 $AdoRs.Open("SELECT * FROM " & $Table_Name & " WHERE ID = " & ($i + 1), $AdoCon) $Files[$i] = $AdoRs.Fields(1).Value $File_Attr[$i][0] = $AdoRs.Fields(2).Value $File_Attr[$i][1] = $AdoRs.Fields(3).Value $File_Attr[$i][2] = $AdoRs.Fields(4).Value Next $AdoRs.Close $AdoCon.Close Local $a = 0 For $i = 0 To UBound($Files) - 1 Step 1 For $j = 0 To 2 Step 1 If $a < 3 And Not $File_Attr[$i][$j] = "" Then For $k = $a To 2 Step 1 If $Attr_Name[$k] = $File_Attr[$i][$j] Then ContinueLoop 2 EndIf Next $Attr_Name[$a] = $File_Attr[$i][$j] $a = $a + 1 EndIf Next Next EndFunc1 point
-
Does this help? HotKeySet("{F1}", "ExtendDisplay") HotKeySet("{F2}", "Secondmonitor") HotKeySet("{F3}", "ComputersMonitor") HotKeySet("{F4}", "DuplicateDisplay") While 1 sleep(1000) WEnd Func ExtendDisplay() Run("DisplaySwitch.exe /extend") EndFunc Func Secondmonitor() Run("DisplaySwitch.exe /external") EndFunc Func ComputersMonitor() Run("DisplaySwitch.exe /internal") EndFunc Func DuplicateDisplay() Run("DisplaySwitch.exe /clone") EndFunc1 point
-
I use enumdisplaymonitors for this purpose, (I have a number of scripts to start apps on specific monitors, or on the monitor the mouse is on (from toolbars or other apps tool menus etc.)) here is the MultiMon.au3 I wrote and am currently using (could have a whole bunch more capability, but does what i need it to, the one thing I keep meaning to add is a custom MsgBox that I can place on a specific monitor) It all seems to still work, (I just cleaned up the code a bit, added some minimal info above each function and renamed a bunch of variables ($t1, $t2, $h etc just doesn't cut it if someone else is looking at the code ) #include-Once Global $__MonitorList[1][5] $__MonitorList[0][0] = 0 ; Just for testing _ShowMonitorInfo() ;================================================================================================== ; Function Name: _ShowMonitorInfo() ; Description:: Show the info in $__MonitorList in a msgbox (line 0 is entire screen) ; Parameter(s): n/a ; Return Value(s): n/a ; Author(s): xrxca (autoit@forums.xrx.ca) ;================================================================================================== Func _ShowMonitorInfo() If $__MonitorList[0][0] == 0 Then _GetMonitors() EndIf Local $Msg = "" Local $i = 0 For $i = 0 To $__MonitorList[0][0] $Msg &= $i & " - L:" & $__MonitorList[$i][1] & ", T:" & $__MonitorList[$i][2] $Msg &= ", R:" & $__MonitorList[$i][3] & ", B:" & $__MonitorList[$i][4] If $i < $__MonitorList[0][0] Then $Msg &= @CRLF Next MsgBox(0, $__MonitorList[0][0] & " Monitors: ", $Msg) EndFunc ;==>_ShowMonitorInfo ;================================================================================================== ; Function Name: _MaxOnMonitor($Title[, $Text = ''[, $Monitor = -1]]) ; Description:: Maximize a window on a specific monitor (or the monitor the mouse is on) ; Parameter(s): $Title The title of the window to Move/Maximize ; optional: $Text The text of the window to Move/Maximize ; optional: $Monitor The monitor to move to (1..NumMonitors) defaults to monitor mouse is on ; Note: Should probably have specified return/error codes but haven't put them in yet ; Author(s): xrxca (autoit@forums.xrx.ca) ;================================================================================================== Func _MaxOnMonitor($Title, $Text = '', $Monitor = -1) _CenterOnMonitor($Title, $Text, $Monitor) WinSetState($Title, $Text, @SW_MAXIMIZE) EndFunc ;==>_MaxOnMonitor ;================================================================================================== ; Function Name: _CenterOnMonitor($Title[, $Text = ''[, $Monitor = -1]]) ; Description:: Center a window on a specific monitor (or the monitor the mouse is on) ; Parameter(s): $Title The title of the window to Move/Maximize ; optional: $Text The text of the window to Move/Maximize ; optional: $Monitor The monitor to move to (1..NumMonitors) defaults to monitor mouse is on ; Note: Should probably have specified return/error codes but haven't put them in yet ; Author(s): xrxca (autoit@forums.xrx.ca) ;================================================================================================== Func _CenterOnMonitor($Title, $Text = '', $Monitor = -1) $hWindow = WinGetHandle($Title, $Text) If Not @error Then If $Monitor == -1 Then $Monitor = _GetMonitorFromPoint() ElseIf $__MonitorList[0][0] == 0 Then _GetMonitors() EndIf If ($Monitor > 0) And ($Monitor <= $__MonitorList[0][0]) Then ; Restore the window if necessary Local $WinState = WinGetState($hWindow) If BitAND($WinState, 16) Or BitAND($WinState, 32) Then WinSetState($hWindow, '', @SW_RESTORE) EndIf Local $WinSize = WinGetPos($hWindow) Local $x = Int(($__MonitorList[$Monitor][3] - $__MonitorList[$Monitor][1] - $WinSize[2]) / 2) + $__MonitorList[$Monitor][1] Local $y = Int(($__MonitorList[$Monitor][4] - $__MonitorList[$Monitor][2] - $WinSize[3]) / 2) + $__MonitorList[$Monitor][2] WinMove($hWindow, '', $x, $y) EndIf EndIf EndFunc ;==>_CenterOnMonitor ;================================================================================================== ; Function Name: _GetMonitorFromPoint([$XorPoint = -654321[, $Y = 0]]) ; Description:: Get a monitor number from an x/y pos or the current mouse position ; Parameter(s): ; optional: $XorPoint X Position or Array with X/Y as items 0,1 (ie from MouseGetPos()) ; optional: $Y Y Position ; Note: Should probably have specified return/error codes but haven't put them in yet, ; and better checking should be done on passed variables. ; Used to use MonitorFromPoint DLL call, but it didn't seem to always work. ; Author(s): xrxca (autoit@forums.xrx.ca) ;================================================================================================== Func _GetMonitorFromPoint($XorPoint = 0, $y = 0) If @NumParams = 0 then local $MousePos = MouseGetPos() Local $myX = $MousePos[0] Local $myY = $MousePos[1] Elseif ( @NumParams = 1 ) and IsArray($XorPoint) Then Local $myX = $XorPoint[0] Local $myY = $XorPoint[1] Else Local $myX = $XorPoint Local $myY = $y EndIf If $__MonitorList[0][0] == 0 Then _GetMonitors() EndIf Local $i = 0 Local $Monitor = 0 For $i = 1 To $__MonitorList[0][0] If ($myX >= $__MonitorList[$i][1]) _ And ($myX < $__MonitorList[$i][3]) _ And ($myY >= $__MonitorList[$i][2]) _ And ($myY < $__MonitorList[$i][4]) Then $Monitor = $i Next Return $Monitor EndFunc ;==>_GetMonitorFromPoint ;================================================================================================== ; Function Name: _GetMonitors() ; Description:: Load monitor positions ; Parameter(s): n/a ; Return Value(s): 2D Array of Monitors ; [0][0] = Number of Monitors ; [i][0] = HMONITOR handle of this monitor. ; [i][1] = Left Position of Monitor ; [i][2] = Top Position of Monitor ; [i][3] = Right Position of Monitor ; [i][4] = Bottom Position of Monitor ; Note: [0][1..4] are set to Left,Top,Right,Bottom of entire screen ; hMonitor is returned in [i][0], but no longer used by these routines. ; Also sets $__MonitorList global variable (for other subs to use) ; Author(s): xrxca (autoit@forums.xrx.ca) ;================================================================================================== Func _GetMonitors() $__MonitorList[0][0] = 0 ; Added so that the global array is reset if this is called multiple times Local $handle = DllCallbackRegister("_MonitorEnumProc", "int", "hwnd;hwnd;ptr;lparam") DllCall("user32.dll", "int", "EnumDisplayMonitors", "hwnd", 0, "ptr", 0, "ptr", DllCallbackGetPtr($handle), "lparam", 0) DllCallbackFree($handle) Local $i = 0 For $i = 1 To $__MonitorList[0][0] If $__MonitorList[$i][1] < $__MonitorList[0][1] Then $__MonitorList[0][1] = $__MonitorList[$i][1] If $__MonitorList[$i][2] < $__MonitorList[0][2] Then $__MonitorList[0][2] = $__MonitorList[$i][2] If $__MonitorList[$i][3] > $__MonitorList[0][3] Then $__MonitorList[0][3] = $__MonitorList[$i][3] If $__MonitorList[$i][4] > $__MonitorList[0][4] Then $__MonitorList[0][4] = $__MonitorList[$i][4] Next Return $__MonitorList EndFunc ;==>_GetMonitors ;================================================================================================== ; Function Name: _MonitorEnumProc($hMonitor, $hDC, $lRect, $lParam) ; Description:: Enum Callback Function for EnumDisplayMonitors in _GetMonitors ; Author(s): xrxca (autoit@forums.xrx.ca) ;================================================================================================== Func _MonitorEnumProc($hMonitor, $hDC, $lRect, $lParam) Local $Rect = DllStructCreate("int left;int top;int right;int bottom", $lRect) $__MonitorList[0][0] += 1 ReDim $__MonitorList[$__MonitorList[0][0] + 1][5] $__MonitorList[$__MonitorList[0][0]][0] = $hMonitor $__MonitorList[$__MonitorList[0][0]][1] = DllStructGetData($Rect, "left") $__MonitorList[$__MonitorList[0][0]][2] = DllStructGetData($Rect, "top") $__MonitorList[$__MonitorList[0][0]][3] = DllStructGetData($Rect, "right") $__MonitorList[$__MonitorList[0][0]][4] = DllStructGetData($Rect, "bottom") Return 1 ; Return 1 to continue enumeration EndFunc ;==>_MonitorEnumProc Edited Jan 8, 2009 to correct minor bug in _GetMonitors routine (Pointed out by Cusem).1 point
-
Form Snap to screen edges by Lazycat: http://www.autoitscript.com/forum/index.ph...st&p=170144 Just run this code and move GUI form near to the edge of screen and you will see ... EDIT: Now placed code also directly to this post. #include <GUIConstants.au3> Global Const $WM_WINDOWPOSCHANGING = 0x0046 Global Const $SPI_GETWORKAREA = 0x30 Global $nGap = 20, $nEdge = BitOR(1, 2, 4, 8); Left, Top, Right, Bottom $hGUI = GUICreate("Snapped window", 300, 200) GUIRegisterMsg($WM_WINDOWPOSCHANGING, "MY_WM_WINDOWPOSCHANGING") GUISetState() While 1 $GUIMsg = GUIGetMsg() Switch $GUIMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func MY_WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam) #cs HWND hwnd; HWND hwndInsertAfter; int x; int y; int cx; int cy; UINT flags; #ce Local $stRect = DllStructCreate("int;int;int;int") Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam) DllCall("User32.dll", "int", "SystemParametersInfo", "int", $SPI_GETWORKAREA, "int", 0, "ptr", DllStructGetPtr($stRect), "int", 0) Local $nLeft = DllStructGetData($stRect, 1) Local $nTop = DllStructGetData($stRect, 2) Local $nRight = DllStructGetData($stRect, 3) - DllStructGetData($stWinPos, 5) Local $nBottom = DllStructGetData($stRect, 4) - DllStructGetData($stWinPos, 6) If BitAND($nEdge, 1) and Abs($nLeft - DllStructGetData($stWinPos, 3)) <= $nGap Then DllStructSetData($stWinPos, 3, $nLeft) If BitAND($nEdge, 2) and Abs($nTop - DllStructGetData($stWinPos, 4)) <= $nGap Then DllStructSetData($stWinPos, 4, $nTop) If BitAND($nEdge, 4) and Abs($nRight - DllStructGetData($stWinPos, 3)) <= $nGap Then DllStructSetData($stWinPos, 3, $nRight) If BitAND($nEdge, 8) and Abs($nBottom - DllStructGetData($stWinPos, 4)) <= $nGap Then DllStructSetData($stWinPos, 4, $nBottom) Return 0 EndFunc1 point