Jump to content

johnmcloud

Active Members
  • Posts

    739
  • Joined

  • Last visited

Everything posted by johnmcloud

  1. Another alternative: Just change the line #14 with this: Exit Run(@ComSpec & " /c PING -n 1 127.0.0.1 | """ & @ScriptFullPath & """" & ' /ErrorStdOut >> ' & '"' & @ScriptDir & '\Test.txt' & '"', "", @SW_HIDE) Test.txt: C:\Test.exe (4) : ==> Variable used without being declared.:
  2. https://msdn.microsoft.com/en-us/library/windows/desktop/mt637065(v=vs.85).aspx Avoid bug that was exploitable by an attacker even if the attacker succeeded in his first steps to exploit the security hole. Can be used in autoit or is useless for his nature? We can enable it maybe hex editing the .exe? Anyway enabling CFG don't cause any problem on older system but it works only on Windows 10 and in Windows 8.1 with the last update.
  3. ; Johnmcloud - 2016 #include <GUIConstantsEx.au3> $hGUI = GUICreate("", 180, 104, -1, -1) $Button = GUICtrlCreateButton("Click Me", 24, 16, 137, 65) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch $aInfo = GUIGetCursorInfo($hGUI) If IsArray($aInfo) And $aInfo[2] = 1 Then ; Primary down (1 if pressed, 0 if not pressed) Select Case $aInfo[4] = $Button ; ID of the control that the mouse cursor is hovering over (or 0 if none) _MouseRelease() ConsoleWrite("!Button clicked" & @CRLF) EndSelect EndIf WEnd Func _MouseRelease() Do $aInfo = GUIGetCursorInfo($hGUI) Sleep(10) Until $aInfo[2] = 0 ; Primary down - wait for release 0 if not pressed EndFunc ;==>_MouseRelease Think outside of the box!
  4. ; Johnmcloud - 2016 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> Global $iBegin, $fFlag = False $hGUI = GUICreate("Test", 325, 100) $cInput = GUICtrlCreateInput("", 10, 20, 300, 20) GuiSetState() GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch If $fFlag And TimerDiff($iBegin) > 3000 Then $fFlag = False MsgBox(64, "Error", "Timed out") EndIf WEnd Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $iIDFrom = BitAND($wParam, 0xFFFF) Local $iCode = BitShift($wParam, 16) If $iIDFrom = $cInput And $iCode = $EN_CHANGE Then $iBegin = TimerInit() $fFlag = True If GUICtrlRead($cInput) = "secretpass" Then Exit MsgBox(64, "Congrats", "Done") EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND
  5. Agree with water. Anyway just for fun ; Johnmcloud - 2016 ;~ #include <WinAPI.au3> ;~ #include <WinAPIProc.au3> #NoTrayIcon ; COMPILE ME! _SuppressErrors() MsgBox(64, "DEBUG_ONLY", "Commandline parameter used: " & _WinAPI_GetProcessCommandLine()) MsgBox(0,0,$NotExistVar) ; variable used without declared Func _SuppressErrors() If @Compiled And _WinAPI_GetProcessCommandLine() = "" Then Exit Run(@ComSpec & " /c PING -n 1 127.0.0.1 | """ & @ScriptFullPath & """" & ' /ErrorStdOut', "", @SW_HIDE) EndIf EndFunc ; ####### 3.3.8.1 INTERNAL USE ONLY - DELETE IF YOU USE VERSIONE ABOVE THAT ################ Func _WinAPI_GetProcessCommandLine($iPID = 0) If Not $iPID Then $iPID = @AutoItPID Local $hProcess = DllCall('kernel32.dll', 'handle', 'OpenProcess', 'dword', __Iif(__WINVER() < 0x0600, 0x00000410, 0x00001010), 'bool', 0, 'dword', $iPID) If @error Or Not $hProcess[0] Then Return SetError(@error + 20, @extended, '') $hProcess = $hProcess[0] Local $tPBI = DllStructCreate('ulong_ptr ExitStatus;ptr PebBaseAddress;ulong_ptr AffinityMask;ulong_ptr BasePriority;ulong_ptr UniqueProcessId;ulong_ptr InheritedFromUniqueProcessId') Local $tPEB = DllStructCreate('byte InheritedAddressSpace;byte ReadImageFileExecOptions;byte BeingDebugged;byte Spare;ptr Mutant;ptr ImageBaseAddress;ptr LoaderData;ptr ProcessParameters;ptr SubSystemData;ptr ProcessHeap;ptr FastPebLock;ptr FastPebLockRoutine;ptr FastPebUnlockRoutine;ulong EnvironmentUpdateCount;ptr KernelCallbackTable;ptr EventLogSection;ptr EventLog;ptr FreeList;ulong TlsExpansionCounter;ptr TlsBitmap;ulong TlsBitmapBits[2];ptr ReadOnlySharedMemoryBase;ptr ReadOnlySharedMemoryHeap;ptr ReadOnlyStaticServerData;ptr AnsiCodePageData;ptr OemCodePageData;ptr UnicodeCaseTableData;ulong NumberOfProcessors;ulong NtGlobalFlag;byte Spare2[4];int64 CriticalSectionTimeout;ulong HeapSegmentReserve;ulong HeapSegmentCommit;ulong HeapDeCommitTotalFreeThreshold;ulong HeapDeCommitFreeBlockThreshold;ulong NumberOfHeaps;ulong MaximumNumberOfHeaps;ptr ProcessHeaps;ptr GdiSharedHandleTable;ptr ProcessStarterHelper;ptr GdiDCAttributeList;ptr LoaderLock;ulong OSMajorVersion;ulong OSMinorVersion;ulong OSBuildNumber;ulong OSPlatformId;ulong ImageSubSystem;ulong ImageSubSystemMajorVersion;ulong ImageSubSystemMinorVersion;ulong GdiHandleBuffer[34];ulong PostProcessInitRoutine;ulong TlsExpansionBitmap;byte TlsExpansionBitmapBits[128];ulong SessionId') Local $tUPP = DllStructCreate('ulong AllocationSize;ulong ActualSize;ulong Flags;ulong Unknown1;ushort LengthUnknown2;ushort MaxLengthUnknown2;ptr Unknown2;ptr InputHandle;ptr OutputHandle;ptr ErrorHandle;ushort LengthCurrentDirectory;ushort MaxLengthCurrentDirectory;ptr CurrentDirectory;ptr CurrentDirectoryHandle;ushort LengthSearchPaths;ushort MaxLengthSearchPaths;ptr SearchPaths;ushort LengthApplicationName;ushort MaxLengthApplicationName;ptr ApplicationName;ushort LengthCommandLine;ushort MaxLengthCommandLine;ptr CommandLine;ptr EnvironmentBlock;ulong Unknown[9];ushort LengthUnknown3;ushort MaxLengthUnknown3;ptr Unknown3;ushort LengthUnknown4;ushort MaxLengthUnknown4;ptr Unknown4;ushort LengthUnknown5;ushort MaxLengthUnknown5;ptr Unknown5') Local $tCMD Local $aRet, $iError = 0 Do $aRet = DllCall('ntdll.dll', 'long', 'NtQueryInformationProcess', 'handle', $hProcess, 'ulong', 0, 'struct*', $tPBI, 'ulong', DllStructGetSize($tPBI), 'ulong*', 0) If @error Or $aRet[0] Then $iError = @error + 30 ExitLoop EndIf $aRet = DllCall('kernel32.dll', 'bool', 'ReadProcessMemory', 'handle', $hProcess, 'ptr', DllStructGetData($tPBI, 'PebBaseAddress'), 'struct*', $tPEB, 'ulong_ptr', DllStructGetSize($tPEB), 'ulong_ptr*', 0) If @error Or Not $aRet[0] Or (Not $aRet[5]) Then $iError = @error + 40 ExitLoop EndIf $aRet = DllCall('kernel32.dll', 'bool', 'ReadProcessMemory', 'handle', $hProcess, 'ptr', DllStructGetData($tPEB, 'ProcessParameters'), 'struct*', $tUPP, 'ulong_ptr', DllStructGetSize($tUPP), 'ulong_ptr*', 0) If @error Or Not $aRet[0] Or (Not $aRet[5]) Then $iError = @error + 50 ExitLoop EndIf $tCMD = DllStructCreate('byte[' & DllStructGetData($tUPP, 'MaxLengthCommandLine') & ']') If @error Then $iError = @error + 60 ExitLoop EndIf $aRet = DllCall('kernel32.dll', 'bool', 'ReadProcessMemory', 'handle', $hProcess, 'ptr', DllStructGetData($tUPP, 'CommandLine'), 'struct*', $tCMD, 'ulong_ptr', DllStructGetSize($tCMD), 'ulong_ptr*', 0) If @error Or Not $aRet[0] Or (Not $aRet[5]) Then $iError = @error + 70 ExitLoop EndIf Until 1 DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hProcess) If $iError Then Return SetError($iError, 0, '') Return StringStripWS(_WinAPI_PathGetArgs(_WinAPI_GetString(DllStructGetPtr($tCMD, 1))), 1 + 2) EndFunc ;==>_WinAPI_GetProcessCommandLine Func _WinAPI_GetString($pString, $bUnicode = True) Local $iLength = _WinAPI_StrLen($pString, $bUnicode) If @error Or Not $iLength Then Return SetError(@error + 10, @extended, '') Local $tString = DllStructCreate(__Iif($bUnicode, 'wchar', 'char') & '[' & ($iLength + 1) & ']', $pString) If @error Then Return SetError(@error, @extended, '') Return SetExtended($iLength, DllStructGetData($tString, 1)) EndFunc ;==>_WinAPI_GetString Func _WinAPI_StrLen($pString, $bUnicode = True) Local $W = '' If $bUnicode Then $W = 'W' Local $aRet = DllCall('kernel32.dll', 'int', 'lstrlen' & $W, 'struct*', $pString) If @error Then Return SetError(@error, @extended, 0) Return $aRet[0] EndFunc ;==>_WinAPI_StrLen Func _WinAPI_PathGetArgs($sFilePath) Local $tPath = DllStructCreate('wchar[' & (StringLen($sFilePath) + 1) & ']') DllStructSetData($tPath, 1, $sFilePath) Local $aRet = DllCall('shlwapi.dll', 'ptr', 'PathGetArgsW', 'struct*', $tPath) If @error Or Not $aRet[0] Then Return SetError(@error, @extended, '') Return _WinAPI_GetString($aRet[0]) EndFunc ;==>_WinAPI_PathGetArgs Func __WINVER() Local Const $tagOSVERSIONINFO = 'struct;dword OSVersionInfoSize;dword MajorVersion;dword MinorVersion;dword BuildNumber;dword PlatformId;wchar CSDVersion[128];endstruct' Local $tOSVI = DllStructCreate($tagOSVERSIONINFO) DllStructSetData($tOSVI, 1, DllStructGetSize($tOSVI)) Local $aRet = DllCall('kernel32.dll', 'bool', 'GetVersionExW', 'struct*', $tOSVI) If @error Or Not $aRet[0] Then Return SetError(@error, @extended, 0) Return BitOR(BitShift(DllStructGetData($tOSVI, 2), -8), DllStructGetData($tOSVI, 3)) EndFunc ;==>__WINVER Func __Iif($fTest, $vTrueVal, $vFalseVal) If $fTest Then Return $vTrueVal Else Return $vFalseVal EndIf EndFunc ;==>_Iif ; ############################# END ################################################
  6. skysnake is VBS not VB. You can use whatever you like but the _DateAdd method like the one your first post is slower then the "internal" one. Check it out by yourself: #include <Date.au3> Local $iYear = 2016, $iMonth = 5 Local $sDate, $iBegin, $iDiff Sleep(1000) $iBegin = TimerInit() $sDate = _DateAdd('M', 1, $iYear & "/" & $iMonth & "/" & "01") $sDate = _DateAdd('D', -1, $sDate) $iDiff = TimerDiff($iBegin) MsgBox(0, 0, "Timer: " & $iDiff & @CRLF & "Last day of month is " & _DateTimeFormat($sDate, 2)) $iBegin = TimerInit() $sDate = _LastDayOfMonth($iMonth, $iYear) $iDiff = TimerDiff($iBegin) MsgBox(0, "Information", "Timer: " & $iDiff & @CRLF & "Last day of month is " & $sDate & "/" & StringFormat("%02i", $iMonth) & "/" & $iYear) Func _LastDayOfMonth($iMonth = @MON, $iYear = @YEAR) Switch $iMonth Case 2 If Mod($iYear, 4) = 0 And Mod($iYear, 100) <> 0 Or Mod($iYear, 400) = 0 Then Return 29 Return 28 Case 4, 6, 9, 11 Return 30 Case Else Return 31 EndSwitch EndFunc ;==>_LastDayOfMonth 4.26 ms is the _DateAdd vs 0.042 ms of the Switch on my test machine, result may vary but the second one is always faster then the first. But again if you prefer _DateAdd use _DateAdd.
  7. I'll never apologize because i don't like this behavior which I consider absurd. If i see an error in a code i'll just write it directly. If you want to help but not write the "solution" for a whatever reason ( i really don't understand it but seems is my problem, whatever ) i expect a positive contribute, which absolutely needs a "thanks", at least something like "hey check better the line n of your code" or "you have made a mistake in calculation of the leaf year, correct it" instead of an generic "wrong"...was too much effort, really? For me don't have any sense to make a treasure hunting when other one knows exactly where the treasure is at start, it is a useless mockery and a child play. I'm surprised of you Jos, really, that endorsing this type of behavior for the MVPs group. You're not exactly what I've expected, you really leave me disappointed. If this is the forum "guide line" I will keep it in mind and i will act accordingly next time...
  8. Oh no no you totally miss the point, don't turn this around on me. Do you want to know what i pretend? The next time you see an error in my code just correct it or tell me where the error is so i can correct it. Write "the code is wrong" or "did you test it?" for me don't have any sense, is like guys that just write "don't work" without any other information, did you like it if some guy make a post like that for one of your code? I don't think because no one like to lose time. So if for you is a problem to correct me directly at first sight without make unuseful post i'm glad and i'll really appreciate it, i'm here to learn. If is a problem for you and you think your first approach at #4 are correct next time please just don't write nothing and leave the error where it is, i'm sure some other ones will correct that. Case closed, go on with the subject of the thread. Thanks and have a nice day/night,
  9. Yes? The example like i have write return me 31/3/2016 ( day month year ) and is correct. Other examples: Month = 2 and Year = 2000 = 29/2/2000, correct Month = 2 and Year = 2001 = 28/2/2001, correct Month = 2 and Year = 2004 = 29/2/2004, correct Other months are obviously correct... Thirty days hath September, April, June, and November ( Case 4,6,8,9 ) all the rest have thirty-one ( Case Else ) So i'll repeat again, do you want to tell me what is "wrong" in that code? EDIT: I have forget "not divided by 100" for the 2100 year...next time just tell me that instead of "wrong" lol.
  10. What is wrong? You can't say "is wrong" without any explaination. I have calculate also the leaf year. Or do you mean the OP code? Because i haven't tried it.
  11. Without UDF, short version ; Johnmcloud - 2016 Local $iMonth = 3, $iYear = 2016 MsgBox(0, "Information", "Last day of month is " & _LastDayOfMonth($iMonth, $iYear) & "/" & StringFormat("%02i", $iMonth) & "/" & $iYear) Func _LastDayOfMonth($iMonth = @MON, $iYear = @YEAR) Switch $iMonth Case 2 If Mod($iYear, 4) = 0 And Mod($iYear, 100) <> 0 Or Mod($iYear, 400) = 0 Then Return 29 Return 28 Case 4, 6, 9, 11 Return 30 Case Else Return 31 EndSwitch EndFunc ;==>_LastDayOfMonth
  12. Local $iBegin, $sPrime = "" Local $iLimit = InputBox("The limit", "What would you lke to make the limit?", 1000) If (Int(StringIsInt($iLimit)) + Int(StringIsFloat($iLimit)) > 0) Then $iBegin = TimerInit() For $x = 1 To $iLimit If _IsPrime($x) Then $sPrime &= $x & ", " Next ConsoleWrite("TIME: " & TimerDiff($iBegin) & @CRLF) EndIf If $sPrime <> "" Then MsgBox(64, "Info", StringTrimRight($sPrime, 2)) Func _IsPrime($iNum) ; Alexander Alvonellos If($iNum < 2) Then Return False If($iNum = 2) Then Return True If(BitAnd($iNum, 1) = 0) Then Return False For $i = 3 To Sqrt($iNum) Step 2 If(Mod($iNum, $i) = 0) Then Return False Next Return True EndFunc ;==>_IsPrime
  13. wakillon, I'm still using the old old stable for XP compatibility, i'll add it has reminder/memorandum. Don't spoiler the solutions lol JohnOne, The gamplay is easy, there are 4 images and the images has a word in common can be applied to all of that. In the example "Autoit" can be applied to all of that so is the solution.
  14. I have just notice i don't have never post in this section if i remember well...bad. So in this Saturday i have think what i can post here, something that someone never already script, something different so... 4Images1Word Based on the popular mobile game, just a "proof of concept" but working fine, 5 levels but can be added ( by you lol ) I'll release the source but if you want to use in a compiled project i want to know before any development. I have take the images from Google Images, if someone of that has some form of copyright i'll remove it. Interface: Source: ;~ Johnmcloud - 2016 ;~ #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <WinAPI.au3> _GDIPlus_Startup() Global $iLetter[16] Global $iSolution[8] Global $sGuessWord, $aWord, $iLevel = 1 Global $sPng1, $iPic1, $sPng2, $iPic2, $sPng3, $iPic3, $sPng4, $iPic4 _ChoiceLevel($iLevel, False) Global $hGUI = GUICreate("4Images1Word", 455, 520, -1, -1) For $i = 0 To 7 $iLetter[$i] = GUICtrlCreateLabel($aWord[$i], 10 + ($i * 55), 408, 45, 45, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 25, 400, 0, "Arial") GUICtrlSetBkColor(-1, 0xFFFFFF) Next For $i = 0 To 7 $iLetter[$i + 8] = GUICtrlCreateLabel($aWord[$i + 8], 10 + ($i * 55), 465, 45, 45, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 25, 400, 0, "Arial") GUICtrlSetBkColor(-1, 0xFFFFFF) Next For $i = 0 To StringLen($sGuessWord) - 1 $iSolution[$i] = GUICtrlCreateLabel("", 10 + ($i * 55), 350, 45, 45, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 25, 400, 0, "Arial") GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetColor(-1, 0xFFFFFF) Next $iPic1 = GUICtrlCreatePic("", 65, 10, 150, 150) $iPic2 = GUICtrlCreatePic("", 225, 10, 150, 150) $iPic3 = GUICtrlCreatePic("", 65, 180, 150, 150) $iPic4 = GUICtrlCreatePic("", 225, 180, 150, 150) GUISetState(@SW_SHOW) _GUICtrlCreatePic_SetImage($iPic1, $sPng1) _GUICtrlCreatePic_SetImage($iPic2, $sPng2) _GUICtrlCreatePic_SetImage($iPic3, $sPng3) _GUICtrlCreatePic_SetImage($iPic4, $sPng4) Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case Else _SetReadLetter() EndSwitch WEnd Func _SetReadLetter() Local Static $sTempSolution For $i = 0 To UBound($iLetter) - 1 If $iMsg <> "" And $iMsg = $iLetter[$i] Then For $y = 0 To UBound($iSolution) - 1 If GUICtrlRead($iSolution[$y]) = "" Then GUICtrlSetData($iSolution[$y], GUICtrlRead($iLetter[$i])) GUICtrlSetData($iLetter[$i], "") $sTempSolution &= GUICtrlRead($iSolution[$y]) ExitLoop EndIf Next If $sTempSolution = $sGuessWord Then MsgBox(64, "Congratulations!", "You have beat the Level " & $iLevel & "!", "", $hGUI) $sTempSolution = "" ; reset $iLevel += 1 _ChoiceLevel($iLevel) EndIf ExitLoop EndIf Next For $x = 0 To UBound($iSolution) - 1 If $iMsg <> "" And $iMsg = $iSolution[$x] Then For $z = 0 To UBound($iLetter) - 1 If GUICtrlRead($iLetter[$z]) = "" Then GUICtrlSetData($iLetter[$z], GUICtrlRead($iSolution[$x])) GUICtrlSetData($iSolution[$x], "") $sTempSolution = StringMid($sTempSolution, 1, ($x + 1) - 1) & StringMid($sTempSolution, ($x + 1) + 1) ExitLoop EndIf Next ExitLoop EndIf Next EndFunc ;==>_SetReadLetter Func _RandomizeShuffle($sString, $iNum = 16) Local $sText, $sTemp, $iLength = $iNum - StringLen($sString) For $i = 1 To $iLength $sTemp = Random(65, 90, 1) $sText &= Chr($sTemp + 6 * ($sTemp > 90)) Next Local $aArray = StringSplit($sText & $sString, "", 2) Local $iNumber, $aTmp, $iUBound = UBound($aArray) - 1 While $iUBound > 1 $iNumber = Random(0, $iUBound - 1, 1) $aTmp = $aArray[$iUBound] $aArray[$iUBound] = $aArray[$iNumber] $aArray[$iNumber] = $aTmp $iUBound -= 1 WEnd Return $aArray EndFunc ;==>_RandomizeShuffle Func _GetURLImage($sURL, $sDirectory = @TempDir) ; author is guinness, nothing changed from original one Local $hDownload, $sFile $sFile = StringRegExpReplace($sURL, "^.*/", "") If @error Then Return SetError(1, 0, $sFile) EndIf If StringRight($sDirectory, 1) <> "" Then $sDirectory = $sDirectory & "" EndIf $sDirectory = $sDirectory & $sFile If FileExists($sDirectory) Then Return $sDirectory EndIf $hDownload = InetGet($sURL, $sDirectory, 17, 1) While InetGetInfo($hDownload, 2) = 0 If InetGetInfo($hDownload, 4) <> 0 Then InetClose($hDownload) Return SetError(1, 0, $sDirectory) EndIf Sleep(100) WEnd InetClose($hDownload) Return $sDirectory EndFunc ;==>_GetURLImage Func _GUICtrlCreatePic_SetImage($hWnd, $sImage) ; original author Yashied, i have changed it and merge in one function If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) If $hWnd = 0 Then Return 0 EndIf EndIf Local $Result, $hImage, $hBitmap, $hFit $hImage = _GDIPlus_BitmapCreateFromFile($sImage) Local $tRect = DllStructCreate($tagRECT) Local $Ret = DllCall('user32.dll', 'int', 'GetClientRect', 'hwnd', $hWnd, 'ptr', DllStructGetPtr($tRect)) If (@error) Or ($Ret[0] = 0) Then Return 0 Local $Size[2] = [DllStructGetData($tRect, 3) - DllStructGetData($tRect, 1), DllStructGetData($tRect, 4) - DllStructGetData($tRect, 2)] If ($Size[0] = 0) Or ($Size[1] = 0) Then Return 0 If $Size = 0 Then Return SetError(1, 0, $hImage) Local $Width = _GDIPlus_ImageGetWidth($hImage), $Height = _GDIPlus_ImageGetHeight($hImage) If Not ($Width = -1) Or Not ($Height = -1) Then If ($Width <> $Size[0]) Or ($Height <> $Size[1]) Then $Ret = DllCall($ghGDIPDll, 'int', 'GdipGetImageThumbnail', 'ptr', $hImage, 'int', $Size[0], 'int', $Size[1], 'ptr*', 0, 'ptr', 0, 'ptr', 0) If (Not @error) And ($Ret[0] = 0) Then _GDIPlus_ImageDispose($hImage) $hImage = $Ret[4] EndIf EndIf EndIf $hFit = $hImage $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hFit) _GDIPlus_ImageDispose($hFit) Local $Style = _WinAPI_GetWindowLong($hWnd, 0xFFFFFFF0) If @error Then Return 0 EndIf _WinAPI_SetWindowLong($hWnd, 0xFFFFFFF0, BitOR($Style, 0x0E)) If @error Then Return 0 EndIf Local $Pos = ControlGetPos($hWnd, '', '') If (@error) Or ($Pos[2] = 0) Or ($Pos[3] = 0) Then Return 0 EndIf $tRect = DllStructCreate($tagRECT) DllStructSetData($tRect, 1, $Pos[0]) DllStructSetData($tRect, 2, $Pos[1]) DllStructSetData($tRect, 3, $Pos[0] + $Pos[2]) DllStructSetData($tRect, 4, $Pos[1] + $Pos[3]) Local $hPrev = _SendMessage($hWnd, 0x0172, 0, $hBitmap) If @error Then Return 0 EndIf If $hPrev Then _WinAPI_DeleteObject($hPrev) EndIf If (Not $hBitmap) And (IsDllStruct($tRect)) Then _WinAPI_MoveWindow($hWnd, DllStructGetData($tRect, 1), DllStructGetData($tRect, 2), DllStructGetData($tRect, 3) - DllStructGetData($tRect, 1), DllStructGetData($tRect, 4) - DllStructGetData($tRect, 2), 0) EndIf If IsDllStruct($tRect) Then _WinAPI_InvalidateRect(_WinAPI_GetParent($hWnd), $tRect) EndIf $hImage = _SendMessage($hWnd, 0x0173, 0, 0) If (@error) Or ($hBitmap = $hImage) Then $hBitmap = 0 EndIf If $hBitmap Then _WinAPI_DeleteObject($hBitmap) FileDelete($sImage) Return SetError(1 - $Result, 0, $Result) EndFunc ;==>_GUICtrlCreatePic_SetImage Func _ChoiceLevel($Level, $sLoadImage = True) Select Case $Level = 1 $sGuessWord = "AUTOIT" $sPng1 = _GetURLImage("https://upload.wikimedia.org/wikipedia/commons/d/d8/Autoit-icon.png") $sPng2 = _GetURLImage("http://www.tech2tech.fr/wp-content/uploads/2013/06/autoit-autocompletion.png") $sPng3 = _GetURLImage("https://www.autoitscript.com/forum/uploads/monthly_2015_04/profile_egypt.jpg.656c82deaa5d3f40f8dd3cead64a67c4.thumb.jpg.911aa23cb8c21db2434388eb7138fecf.jpg") $sPng4 = _GetURLImage("https://www.autoitscript.com/forum/screenshots/monthly_2015_07/autoit_screenshot_128x128.thumb.png.3e6c4b91bbeb05b8b88f070a077e018a.png") Case $Level = 2 $sGuessWord = "CAR" $sPng1 = _GetURLImage("http://auto.ferrari.com/it_IT/wp-content/uploads/sites/8/2014/02/ferrari-official-web.jpg") $sPng2 = _GetURLImage("http://www.usa.philips.com/c-dam/b2c/category-pages/lighting/car-lights/master/footer/nafta-car.png") $sPng3 = _GetURLImage("https://www.enterprise.ca/content/dam/global-vehicle-images/cars/CHRY_200_2015.png") $sPng4 = _GetURLImage("https://upload.wikimedia.org/wikipedia/commons/thumb/d/d0/1957_Rambler_Rebel_hardtop_rfd-Cecil'10.jpg/800px-1957_Rambler_Rebel_hardtop_rfd-Cecil'10.jpg") Case $Level = 3 $sGuessWord = "NUMBERS" $sPng1 = _GetURLImage("http://st.hzcdn.com/simgs/ff5158970576289a_4-8128/mediterranean-house-numbers.jpg") $sPng2 = _GetURLImage("http://static.nautil.us/3006_5f268dfb0fbef44de0f668a022707b86.jpg") $sPng3 = _GetURLImage("http://www.barnlightelectric.com/images/detailed/19/60587_NUMBERS---RED.jpg") $sPng4 = _GetURLImage("http://www.yareah.com/wp-content/uploads/2014/04/numbers.jpg") Case $Level = 4 $sGuessWord = "BLIZZARD" $sPng1 = _GetURLImage("https://upload.wikimedia.org/wikipedia/en/9/93/StarCraft_box_art.jpg") $sPng2 = _GetURLImage("http://www.gannett-cdn.com/-mm-/af47823baecdb03f6081ce254672a5777756878b/c=118-0-1881-1322&r=x404&c=534x401/local/-/media/AsburyPark/2015/03/06/B9316488430Z.1_20150306130352_000_GHLA4R7D4.1-0.jpg") $sPng3 = _GetURLImage("http://cdn.abclocal.go.com/content/creativeContent/images/cms/012615-cc-past-blizzards-2-4.jpg") $sPng4 = _GetURLImage("http://imgc.allpostersimages.com/images/P-473-488-90/21/2169/9RJCD00Z/posters/thorsten-milse-snow-storm-blizzard-churchill-hudson-bay-manitoba-canada.jpg") Case $Level = 5 $sGuessWord = "HAPPY" $sPng1 = _GetURLImage("http://cdn.tinybuddha.com/wp-content/uploads/2015/04/Happy-Hands.jpg") $sPng2 = _GetURLImage("http://i.livescience.com/images/i/000/051/022/original/happy-worker.jpg") $sPng3 = _GetURLImage("http://findicons.com/files/icons/2770/ios_7_icons/512/happy.png") $sPng4 = _GetURLImage("http://law2.umkc.edu/faculty/projects/ftrials/happylawyers/jumpinglawyer.JPG") Case Else Exit MsgBox(64, "Game Over", "Thanks for the playing - Johnmcloud") EndSelect $iLevel = $Level ; update the selection level If StringLen($sGuessWord) > 8 Or StringLen($sGuessWord) < 3 Then Exit ; max-min allowed character $aWord = _RandomizeShuffle($sGuessWord) For $i = 0 To 7 GUICtrlSetData($iLetter[$i], $aWord[$i]) Next For $i = 0 To 7 GUICtrlSetData($iLetter[$i + 8], $aWord[$i + 8]) Next For $i = 0 To UBound($iSolution) - 1 GUICtrlDelete($iSolution[$i]) Next For $i = 0 To StringLen($sGuessWord) - 1 $iSolution[$i] = GUICtrlCreateLabel("", 10 + ($i * 55), 350, 45, 45, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 25, 400, 0, "Arial") GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetColor(-1, 0xFFFFFF) Next If $sLoadImage Then _GUICtrlCreatePic_SetImage($iPic1, $sPng1) _GUICtrlCreatePic_SetImage($iPic2, $sPng2) _GUICtrlCreatePic_SetImage($iPic3, $sPng3) _GUICtrlCreatePic_SetImage($iPic4, $sPng4) EndIf EndFunc ;==>_ChoiceLevel Have fun P.S. Change $ghGDIPDll with $__g_hGDIPDll if you are using an Autoit version over the 3.3.8.1
  15. It's return -1 because the function return -1 if @error or "Not $aRet[0]" If @error Or Not $aRet[0] Then Return -1 The _WinAPI_GetLayeredWindowAttributes in the WinAPI NEVER check the 0 based array but only two, three and four and just the @error from DllCall, i have stripped into the example so you can see with your eyes. Next time: 1) Don't use DllCall if you don't know how to manage. 2) Check the help and MSDN for the function, failure = 0 ; Johnmcloud - 2016 Local $iInfo, $iTransparency, $iTransColor, $hWnd Run("notepad") WinWait("[CLASS:Notepad]") $hWnd = WinGetHandle("[CLASS:Notepad]") WinSetTrans($hWnd, "", 255) Local $iCounter = 0 Do ;~ WinSetTrans($hWnd, "", 255) you can un-comment out if you want $iCounter += 1 $iInfo = _WinAPI_GetLayeredWindowAttributes($hWnd, $iTransColor, $iTransparency) If @error Then Exit ConsoleWrite("ERROR:" & @extended & @CRLF) ConsoleWrite("N:" & $iCounter & " - Alpha Value: " & $iTransparency & " " & @CRLF) Until $iCounter = 100 Func _WinAPI_GetLayeredWindowAttributes($hWnd, ByRef $i_transcolor, ByRef $Transparency, $asColorRef = False) $i_transcolor = -1 $Transparency = -1 Local $aResult = DllCall("user32.dll", "bool", "GetLayeredWindowAttributes", "hwnd", $hWnd, "dword*", $i_transcolor, "byte*", $Transparency, "dword*", 0) If @error Then Return SetError(@error, @extended, 0) If Not $asColorRef Then $aResult[2] = Int(BinaryMid($aResult[2], 3, 1) & BinaryMid($aResult[2], 2, 1) & BinaryMid($aResult[2], 1, 1)) EndIf $i_transcolor = $aResult[2] $Transparency = $aResult[3] Return $aResult[4] EndFunc ;==>_WinAPI_GetLayeredWindowAttributes Result: N:1 - Alpha Value: 255 N:2 - Alpha Value: 255 N:3 - Alpha Value: 255 N:4 - Alpha Value: 255 N:5 - Alpha Value: 255 N:6 - Alpha Value: 255 N:7 - Alpha Value: 255 N:8 - Alpha Value: 255 N:9 - Alpha Value: 255 N:10 - Alpha Value: 255 N:11 - Alpha Value: 255 N:12 - Alpha Value: 255 N:13 - Alpha Value: 255 N:14 - Alpha Value: 255 N:15 - Alpha Value: 255 N:16 - Alpha Value: 255 N:17 - Alpha Value: 255 N:18 - Alpha Value: 255 N:19 - Alpha Value: 255 N:20 - Alpha Value: 255 N:21 - Alpha Value: 255 N:22 - Alpha Value: 255 N:23 - Alpha Value: 255 N:24 - Alpha Value: 255 N:25 - Alpha Value: 255 N:26 - Alpha Value: 255 N:27 - Alpha Value: 255 N:28 - Alpha Value: 255 N:29 - Alpha Value: 255 N:30 - Alpha Value: 255 N:31 - Alpha Value: 255 N:32 - Alpha Value: 255 N:33 - Alpha Value: 255 N:34 - Alpha Value: 255 N:35 - Alpha Value: 255 N:36 - Alpha Value: 255 N:37 - Alpha Value: 255 N:38 - Alpha Value: 255 N:39 - Alpha Value: 255 N:40 - Alpha Value: 255 N:41 - Alpha Value: 255 N:42 - Alpha Value: 255 N:43 - Alpha Value: 255 N:44 - Alpha Value: 255 N:45 - Alpha Value: 255 N:46 - Alpha Value: 255 N:47 - Alpha Value: 255 N:48 - Alpha Value: 255 N:49 - Alpha Value: 255 N:50 - Alpha Value: 255 N:51 - Alpha Value: 255 N:52 - Alpha Value: 255 N:53 - Alpha Value: 255 N:54 - Alpha Value: 255 N:55 - Alpha Value: 255 N:56 - Alpha Value: 255 N:57 - Alpha Value: 255 N:58 - Alpha Value: 255 N:59 - Alpha Value: 255 N:60 - Alpha Value: 255 N:61 - Alpha Value: 255 N:62 - Alpha Value: 255 N:63 - Alpha Value: 255 N:64 - Alpha Value: 255 N:65 - Alpha Value: 255 N:66 - Alpha Value: 255 N:67 - Alpha Value: 255 N:68 - Alpha Value: 255 N:69 - Alpha Value: 255 N:70 - Alpha Value: 255 N:71 - Alpha Value: 255 N:72 - Alpha Value: 255 N:73 - Alpha Value: 255 N:74 - Alpha Value: 255 N:75 - Alpha Value: 255 N:76 - Alpha Value: 255 N:77 - Alpha Value: 255 N:78 - Alpha Value: 255 N:79 - Alpha Value: 255 N:80 - Alpha Value: 255 N:81 - Alpha Value: 255 N:82 - Alpha Value: 255 N:83 - Alpha Value: 255 N:84 - Alpha Value: 255 N:85 - Alpha Value: 255 N:86 - Alpha Value: 255 N:87 - Alpha Value: 255 N:88 - Alpha Value: 255 N:89 - Alpha Value: 255 N:90 - Alpha Value: 255 N:91 - Alpha Value: 255 N:92 - Alpha Value: 255 N:93 - Alpha Value: 255 N:94 - Alpha Value: 255 N:95 - Alpha Value: 255 N:96 - Alpha Value: 255 N:97 - Alpha Value: 255 N:98 - Alpha Value: 255 N:99 - Alpha Value: 255 N:100 - Alpha Value: 255
  16. ; Johnmcloud - 2016 ; _GetAllProcessThreads by monoceres, a little edited Local $iPID = Run("notepad") Sleep(1000) _ProcessSuspend($iPID) Sleep(2000) _ProcessResume($iPID) Func _ProcessSuspend($iPID) Local $THREAD_SUSPEND_RESUME = 0x0002 Local $hWnd, $aProcessThreads = _GetAllProcessThreads($iPID) For $i = 1 To $aProcessThreads[0][0] $hWnd = DllCall('Kernel32.dll', 'hwnd', "OpenThread", "int", $THREAD_SUSPEND_RESUME, "int", 0, 'int', $aProcessThreads[$i][0]) If Not @error Then DllCall('Kernel32.dll', 'uint', "SuspendThread", 'hwnd', $hWnd[0]) Next Return 1 EndFunc ;==>_ProcessSuspend Func _ProcessResume($iPID) Local $THREAD_SUSPEND_RESUME = 0x0002 Local $hWnd, $aProcessThreads = _GetAllProcessThreads($iPID) For $i = 1 To $aProcessThreads[0][0] $hWnd = DllCall('Kernel32.dll', 'hwnd', "OpenThread", "int", $THREAD_SUSPEND_RESUME, "int", 0, 'int', $aProcessThreads[$i][0]) If Not @error Then DllCall('Kernel32.dll', 'uint', "ResumeThread", 'hwnd', $hWnd[0]) Next Return 1 EndFunc ;==>_ProcessResume Func _GetAllProcessThreads($iPID) Local Const $TH32CS_SNAPTHREAD = 0x00000004 Local Const $THREADENTRY32 = "dword dwSize;dword cntUsage;dword th32ThreadId;dword th32OwnerProcessID;long tpBasePri;long tpDeltaPri;dword dwFlags;" Local $aCall = DllCall("Kernel32.dll", "ptr", "CreateToolhelp32Snapshot", "dword", $TH32CS_SNAPTHREAD, "dword", 0) If @error Then Return SetError(1, 0, 0) Local $hThread = $aCall[0] Local $aReturn[1][3] Local $Thread32 = DllStructCreate($THREADENTRY32) DllStructSetData($Thread32, "dwSize", DllStructGetSize($Thread32)) $aCall = DllCall("Kernel32.dll", "int", "Thread32First", "ptr", $hThread, "ptr", DllStructGetPtr($Thread32)) If @error Then Return SetError(2, 0, 0) If DllStructGetData($Thread32, "th32OwnerProcessID") = $iPID Then _GetAllThreads_ArrHelper($aReturn, $Thread32) Do $aCall = DllCall("Kernel32.dll", "int", "Thread32Next", "ptr", $hThread, "ptr", DllStructGetPtr($Thread32)) If Not $aCall[0] Then ExitLoop If DllStructGetData($Thread32, "th32OwnerProcessID") = $iPID Then _GetAllThreads_ArrHelper($aReturn, $Thread32) Until True And False $aReturn[0][0] = UBound($aReturn) - 1 ; number of items in the array DllCall("Kernel32.dll", "bool", "CloseHandle", "handle", $hThread) If @error Then Return SetError(3, 0, 0) Return $aReturn EndFunc ;==>_GetAllProcessThreads Func _GetAllThreads_ArrHelper(ByRef $aArray, $Thread32_Struct) Local $iUBound = UBound($aArray) ReDim $aArray[$iUBound + 1][3] $aArray[$iUBound][0] = DllStructGetData($Thread32_Struct, "th32ThreadId") $aArray[$iUBound][1] = DllStructGetData($Thread32_Struct, "th32OwnerProcessID") $aArray[$iUBound][2] = DllStructGetData($Thread32_Struct, "tpBasePri") EndFunc ;==>_GetAllThreads_ArrHelper
  17. Make a copy of CaptureWnd function and add a couple of new variable for check SM_CXSCREEN - $SM_CYSCREEN using _WinAPI_GetSystemMetrics. Than compare the original variable of the Window with that and if is > than use the value reported from GetSystemMetrics. In this case you have always a good image I don't know if it work in a multi monitor configuration, i don't have one. Maybe UEZ know.
  18. Hello guys, long time no see Weel, i want to write some output to CMD if the software has lanched from the console, not if is lanched by Explorer. After some reseach i have understand i need to use AttachConsole from Kernel32.dll. Work? Yes...but is not the same "output" like the CUI version and i don't know if is a thing can be resolved or not. I'll explain, this is an image of CUI: With this code: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ConsoleWrite(@CRLF & "Hello World" & @CRLF)And is ok, i want to get the same result. Insted this is my output: Using this code: #include <WinAPI.au3> Local $iConsole, $hConsole, $aGetConsoleWin $iConsole = _WinAPI_AttachConsole(-1) If $iConsole = 0 Then Exit $hConsole = _WinAPI_GetStdHandle(1) If $hConsole = -1 Then Exit _WinAPI_WriteConsole($hConsole, @CRLF & @CRLF & "Hello World" & @CRLF) $aGetConsoleWin = DllCall("kernel32", "ptr", "GetConsoleWindow") If Not @error Then DllCall("user32", "bool", "PostMessage", _ "hwnd", $aGetConsoleWin[0], _ "uint", 256, _ ; WM_KEYDOWN "wparam", 13, _ ; VK_RETURN "lparam", 0) EndIfAs you can see there is one line more then the CUI version, yes i know i have used two @CRLF because with only one write on C:\Windows\System32> So there are errors? Can be removed that line to have the same output of a CUI? Thanks and have a nice day
  19. I forgot it Thanks BrewManNH, code updated
  20. ;Johnmcloud - 2015 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MenuConstants.au3> $hGUI = GUICreate("NO_CONTEXT_MENU", 300, 300, -1, -1) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NCRBUTTONDOWN, "WM_NCRBUTTONDOWN") GUIRegisterMsg($WM_SYSCOMMAND,"WM_SYSCOMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_NCRBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Switch $wParam Case $HTCAPTION, $HTSYSMENU, $HTMINBUTTON, $HTMAXBUTTON, $HTTOPRIGHT, $HTBOTTOM Return 0 EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NCRBUTTONDOWN Func WM_SYSCOMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Switch $wParam Case $SC_KEYMENU, BitOr($SC_MOUSEMENU, $wParam) Return 0 EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_SYSCOMMAND
  21. ; Author: Mikell #include <WinAPI.au3> Run("notepad.exe") Do Sleep(10) Until WinExists("[CLASS:Notepad]") Local $hWnd = WinGetHandle("[CLASS:Notepad]") _WinSetIcon($hWnd, "shell32.dll", 25) ;~ _WinSetIcon($hWnd, "X:\Path\Icon.ico") WinSetTitle($hWnd, "", "Testing") ;========================================= Func _WinSetIcon($hWnd, $sFile, $iIndex = 0) Local $tIcons = DllStructCreate("ptr Data") DllCall("shell32.dll", "uint", "ExtractIconExW", "wstr", $sFile, "int", $iIndex, "struct*", 0, "struct*", $tIcons, "uint", 1) If @error Then Return SetError(1, 0, 0) Local $hIcon = DllStructGetData($tIcons, "Data") _SendMessage($hWnd, 0x0080, 1, $hIcon ) ;$WM_SETICON = 0x0080 _WinAPI_DestroyIcon($hIcon) Return 1 EndFunc
  22. mLipok, The first website to check is Internet Archive: Wayback Machine #include-once ; #INDEX# ======================================================================== ; Title .........: _ConfigIO ; AutoIt Version : 3.3.0++ ; Language ......: English ; Description ...: Functions that assist with reading and writiing configuration files. A very simple XML reader/writer. ; Author ........: Stephen Podhajecki (eltorro) ; ================================================================================ ; #VARIABLES# ==================================================================== Global $__COM_ERR Global Const $NODE_XML_INVALID = 0; Global Const $NODE_XML_ELEMENT = 1; Global Const $NODE_XML_ATTRIBUTE = 2; Global Const $NODE_XML_TEXT = 3; Global Const $NODE_XML_CDATA_SECTION = 4; Global Const $NODE_XML_ENTITY_REFERENCE = 5; Global Const $NODE_XML_ENTITY = 6; Global Const $NODE_XML_PROCESSING_INSTRUCTION = 7; Global Const $NODE_XML_COMMENT = 8; Global Const $NODE_XML_DOCUMENT = 9; Global Const $NODE_XML_DOCUMENT_TYPE = 10; Global Const $NODE_XML_DOCUMENT_FRAGMENT = 11; Global Const $NODE_XML_NOTATION = 12; Global $XML_ENCODING[4] = [3, "iso-8859-1", "UTF-8", "UTF-16"] ; the first element sets the default encoding Global $aCONFIG_FHDS[1][2] ;hold handles and filenames ; ================================================================================ ; #NO_DOC_FUNCTION# ============================================================== ; Not working/documented/implimented at this time ; ================================================================================ ; __Config_COMErr ; ================================================================================ ; #CURRENT# ====================================================================== ;_Config_Create ;_Config_Open ;_Config_Read ;_Config_Write ;_Config_Delete ;_Config_EnumParam ;_Config_EnumVal ;_Config_Save ;_Config_SaveAs ;_Config_Close ;_Config_Indent ;_Config_Base64_Encode ;_Config_Base64_Decode ; ================================================================================ ; #INTERNAL_USE_ONLY#============================================================= ;__Config_CreateKeyRecursive ;__Config_KeyExists ;__Config_SetFileToHandle ;__Config_GetFileFromHandle ;__Config_RemoveFileHandle ;__Config_COMErr ;__Config_InitCOMErr ; ================================================================================ ; #FUNCTION# ===================================================================== ; Name...........: _Config_Create ; Description ...: Creates a configuration file ; Syntax.........: _Config_Create($szFileName, $iOverwrite = 0, $szRoot = "",$iEncoding = 0) ; Parameters ....: $szFileName - The filename for the configuration file ; : $iOverwrite - Overwrite exisiting file ; |0 - Don't overwrite, and return error ; |1 - Overwrite the file. ; |2 - Prompt to overwrite. ; $szRoot - The value for the root node ; $iEncoding - The encoding to use ; |0 - Default (UTF-16) ; |1 - iso-8859-1 ; |2 - UTF-8 ; |3 - UTF-16 ; Return values .: Success - An XML object handle ; Failure - 0 and @error set to 1 ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: Creates the configuration file using the default encoding and root name. After creation, ; _Config_Open is called and the handle returned. This file handle and the filename are cached ; and later used by _Config_Close and _Config_Save ; Related .......: _Config_Open, _Config_Close, _Config_Save, _Config_SaveAs ; Link ..........: ; Example .......: Yes ; ================================================================================ Func _Config_Create($szFileName, $iOverwrite = 0, $szRoot = "", $iEncoding = 0) If $szRoot = "" Then $szRoot = "CONFIG" If FileExists($szFileName) Then If $iOverwrite = 0 Then Return SetError(1, 0, 0) If $iOverwrite = 2 Then If MsgBox(266292, @ScriptName, "The file: " & $szFileName & " , already exists. Do you wish to overwrite the file?") <> 6 Then Return SetError(1, 0, 0) EndIf EndIf Local $hConfig, $objPI, $objRoot $hConfig = ObjCreate("MSXML2.DOMDocument") If $iEncoding <= 0 Or $iEncoding > UBound($XML_ENCODING) Then $iEncoding = $XML_ENCODING[0] $objPI = $hConfig.createProcessingInstruction("xml", StringFormat('version="1.0" encoding="%s"', $XML_ENCODING[$iEncoding])) $hConfig.appendChild($objPI) $objRoot = $hConfig.createElement($szRoot) $hConfig.documentElement = $objRoot $hConfig.save($szFileName) If $hConfig.parseError.errorCode <> 0 Then ConsoleWriteError("Error Creating specified file: " & $szFileName) SetError($hConfig.parseError.errorCode, 0, 0) Return 0 EndIf $objPI = 0 $objRoot = 0 $hConfig = 0 Return _Config_Open($szFileName) EndFunc ;==>_Config_Create ; #FUNCTION# =================================================================== ; Name...........: _Config_Open ; Description ...: Opens a configuration file ; Syntax.........: _Config_Open($szFileName) ; Parameters ....: $szFileName - The configuration file to open ; Return values .: Success - An XML object handle. ; Failure - 0 and @error set to 1 ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: Opens an XML configuration file and if succesful returns the object handle to the file. ; Related .......: _Config_Create, _Config_Close, _Config_Save, _Config_SaveAs ; Link ..........: ; Example .......: Yes ; ================================================================================ Func _Config_Open($szFileName) Local $hConfig $hConfig = ObjCreate("Msxml2.DOMDocument") If @error Then Return SetError(1, 0, 0) If IsObj($hConfig) Then __Config_InitCOMErr() $hConfig.async = False $hConfig.preserveWhiteSpace = True $hConfig.Load($szFileName) $hConfig.setProperty("SelectionLanguage", "XPath") If $hConfig.parseError.errorCode <> 0 Then ;ConsoleWriteError("Error opening specified file: " & $szFileName & @CRLF & $hConfig.parseError.reason) SetError($hConfig.parseError.errorCode, 0, 0) Return 0 EndIf __Config_SetFileToHandle($hConfig, $szFileName) Return $hConfig EndIf Return SetError(1, 0, 0) EndFunc ;==>_Config_Open ; #FUNCTION# =================================================================== ; Name...........: _Config_Read ; Description ...: Read a value from the configuration file. ; Syntax.........: _Config_Read($hConfig, $szParam, $szValue) ; Parameters ....: $hConfig - The object handle returned by _Config_Open or _Config_Create. ; $szParam - The name of the parameter to Read the value of. ; $szValue - The value name to read. ; Return values .: Success - The value. ; Failure - 0 and @error set to 1 ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: ; Related .......: _Config_Write, _Config_Delete ; Link ..........: ; Example .......: Yes ; ================================================================================ Func _Config_Read(ByRef $hConfig, $szParam, $szValue) If Not IsObj($hConfig) Then Return SetError(1, 0, 0) If $szParam = "" Then Return SetError(1, 0, 0) If $szValue Then $szParam &= "/" & $szValue Local $objKey, $szRet $szParam = StringReplace($szParam, "\", "/") $objKey = $hConfig.documentElement.selectSingleNode($szParam & "/child::text()") If IsObj($objKey) Then $szRet = $objKey.nodeValue $objKey = 0 Return $szRet EndIf Return SetError(1, 0, 0) EndFunc ;==>_Config_Read ; #FUNCTION# =================================================================== ; Name...........: _Config_Write ; Description ...: Write a value in the configuration file. ; Syntax.........: _Config_Set($hConfig, $szParam, $vValue) ; Parameters ....: $hConfig - The object handle returned by _Config_Open or _Config_Create. ; $szParam - The name of the parameter to write to ; $szValue - The value name to write to ; $vValue - The value to write. ; Return values .: Success - 1 ; Failure - 0 and @error set to 1 ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: Call _Config_Save or _Config_SaveAs to save any changes made. ; Related .......: _Config_Read, _Config_Delete ; Link ..........: ; Example .......: Yes ; ================================================================================ Func _Config_Write(ByRef $hConfig, $szParam, $szValue, $vValue) Local $err If Not IsObj($hConfig) Then Return SetError(1, 0, 0) If $szParam = "" Then Return SetError(1, 0, 0) If $szValue Then $szParam &= "/" & $szValue $szParam = StringReplace($szParam, "\", "/") If __Config_KeyExists($hConfig, $szParam) Then Local $objKey = $hConfig.documentElement.selectSingleNode($szParam & "/child::text()") If IsObj($objKey) Then $objKey.text = $vValue Else Local $objChild = $hConfig.createTextNode($vValue) $objKey = $hConfig.documentElement.selectSingleNode($szParam) $objKey.appendChild($objChild) $err = @error $objChild = 0 $objKey = 0 If $err Then Return SetError(1, 0, 0) EndIf $objKey = 0 Else __Config_CreateKeyRecursive($hConfig, $szParam, $vValue) If @error Then Return SetError(1, 0, 0) EndIf Return 1 EndFunc ;==>_Config_Write ; #FUNCTION# =================================================================== ; Name ..........: _Config_Delete ; Description ...: Delete a param from the config file. ; Syntax ........: _Config_Delete($hConfig, $szParam ,$szValue = "") ; Parameters ....: $hConfig - The config file handle ; $szParam - The name of the parameter to delete ; $szValue - The name of the value to delete ; Return values .: Success - 1 ; Failure - 0 and @error set to 1 ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: Call _Config_Save or _Config_SaveAs to save any changes made. ; If $szValue is skipped then the parameter and sub-parameters are deleted. ; Related .......: _Config_Read, _Config_Write ; Link ..........: ; Example .......: Yes ; ================================================================================ Func _Config_Delete(ByRef $hConfig, $szParam, $szValue = "") If Not IsObj($hConfig) Then Return SetError(1, 0, 0) If $szParam = "" Then Return SetError(1, 0, 0) If $szValue Then $szParam &= "/" & $szValue $szParam = StringReplace($szParam, "\", "/") Local $objKey, $objChild $objKey = $hConfig.documentElement.selectSingleNode($szParam) If IsObj($objKey) Then ;only remove param if no sub-params like regedit If $objKey.hasChildNodes Then $objChild = $hConfig.documentElement.selectSingleNode($szParam & "/child::text()") If IsObj($objChild) Then $objChild.parentNode.removeChild($objChild) EndIf $objKey = $hConfig.documentElement.selectSingleNode($szParam) If Not $objKey.hasChildNodes Then $objKey.parentNode.removeChild($objKey) EndIf $objChild = 0 $objKey = 0 Return 1 EndIf Return SetError(1, 0, 0) EndFunc ;==>_Config_Delete ; #FUNCTION# =================================================================== ; Name ..........: _Config_EnumParam ; Description ...: Reads the name of a parameter according to it's index. ; Syntax ........: _Config_EnumParam($hConfig,$szParam,$iIndex = 1) ; Parameters ....: $hConfig - The config file handle ; $szParam - The name of the parameter to enumerate ; $iIndex - The 1-based index to retrieve ; Return values .: Success - The param ; Failure - 0 or empty String ("") and @error set to 1 ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: An empty string can be used for $szParam to enumerate the parameters under the root node. ; Related .......: _Config_EnumVal ; Link ..........: ; Example .......: Yes ; ================================================================================ Func _Config_EnumParam($hConfig, $szParam, $iIndex = 1) If $iIndex < 1 Or Not IsObj($hConfig) Then Return SetError(1, 0, 0) $szParam = StringReplace($szParam, "\", "/") Local $objKey, $vRet If $szParam = "" Then $szParam = "*[" & $iIndex & "]" Else $szParam &= "/*[" & $iIndex & "]" EndIf $objKey = $hConfig.documentElement.selectSingleNode($szParam) If IsObj($objKey) Then $vRet = $objKey.nodeName $objKey = 0 Return SetError(($vRet = ""), 0, $vRet) EndFunc ;==>_Config_EnumParam ; #FUNCTION# =================================================================== ; Name ..........: _Config_EnumVal ; Description ...: Reads the value to a parameter according to it's index. ; Syntax ........: _Config_EnumVal($hConfig,$szParam,$iIndex) ; Parameters ....: $hConfig - The config file handle ; $szParam - The name of the parameter to enumerate ; $iIndex - The 1-based index to retrieve ; Return values .: Success - The value of the parameter ; Failure - 0 or empty string ("") and @error set to 1 ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: An empty string can be used for $szParam to enumerate the parameters under the root node. ; Related .......: ; Link ..........: _Config_EnumParam ; Example .......: Yes ; ================================================================================ Func _Config_EnumVal($hConfig, $szParam, $iIndex) If $iIndex < 1 Or Not IsObj($hConfig) Then Return SetError(1, 0, 0) $szParam = StringReplace($szParam, "\", "/") Local $objKey, $objChild, $vRet If $szParam = "" Then $szParam = "*[" & $iIndex & "]" Else $szParam &= "/*[" & $iIndex & "]" EndIf $objKey = $hConfig.documentElement.selectSingleNode($szParam) If IsObj($objKey) Then If $objKey.hasChildNodes Then $objChild = $hConfig.documentElement.selectSingleNode($szParam & "/child::text()") If IsObj($objChild) Then $vRet = $objChild.nodeValue EndIf EndIf $objChild = 0 $objKey = 0 Return SetError(($vRet = ""), 0, $vRet) EndFunc ;==>_Config_EnumVal ; #FUNCTION# =================================================================== ; Name...........: _Config_Save ; Description ...: Save the config file ; Syntax.........: _Config_Save($hConfig) ; Parameters ....: $hConfig - The config file handle ; Return values .: Success - 1 ; Failure - 0 ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: This function explicitly saves the configuration file. The filename is ; retrieved from the handle cache. Use _Config_SaveAs the specify a filename. ; Related .......: _Config_SaveAs ; Link ..........: ; Example .......: Yes ; ================================================================================ Func _Config_Save(ByRef $hConfig) If IsObj($hConfig) Then Local $szFileName = __Config_GetFileFromHandle($hConfig) If $szFileName <> "" Then $hConfig.save($szFileName) If @error = 0 Then Return 1 EndIf EndIf Return SetError(1, 0, 0) EndFunc ;==>_Config_Save ; #FUNCTION# =================================================================== ; Name...........: _Config_SaveAs ; Description ...: Save the config file as another filename ; Syntax.........: _Config_SaveAs($hConfig, $szFileName, $iOverwrite = 0) ; Parameters ....: $hConfig - The config file handle ; $szFileName - The file name to save as. ; $iOverwrite - The overwrite flag. ; |0 - Don't overwrite, and return error ; |1 - Overwrite the file. ; |2 - Prompt to overwrite. ; Return values .: Success - 1 ; Failure - 0 ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: This function will save the configuration using the supplied file name. The new file name will ; now be associated with the file handle. ; Related .......: _Config_Save ; Link ..........: ; Example .......: Yes ; ================================================================================ Func _Config_SaveAs(ByRef $hConfig, $szFileName, $iOverwrite = 0) If IsObj($hConfig) And $szFileName <> "" Then If FileExists($szFileName) Then If $iOverwrite = 0 Then Return SetError(1, 0, 0) If $iOverwrite = 2 Then If MsgBox(266292, @ScriptName, "The file: " & $szFileName & " , already exists. Do you wish to overwrite the file?") <> 6 Then Return SetError(1, 0, 0) EndIf EndIf $hConfig.save($szFileName) If @error = 0 Then __Config_SetFileToHandle($hConfig, $szFileName) Return 1 EndIf EndIf Return SetError(1, 0, 0) EndFunc ;==>_Config_SaveAs ; #FUNCTION# =================================================================== ; Name...........: _Config_Close ; Description ...: Close the config file ; Syntax.........: _Config_Close($hConfig,$iSaveOnClose = 1) ; Parameters ....: $hConfig - The config file handle ; $iSaveOnClose - Save when closing the file. Defaults to 1 (yes) ; Return values .: Success - 1 ; Failure - 0 ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: If $iSaveOnClose = 1 then the an attempt to save the config file will be made. ; Related .......: _Config_Create, _Config_Open, _Config_Save ; Link ..........: ; Example .......: Yes ; ================================================================================ Func _Config_Close(ByRef $hConfig, $iSaveOnClose = 1) Local $vRet If IsObj($hConfig) Then If $iSaveOnClose Then _Config_Save($hConfig) $vRet = @error EndIf EndIf __Config_RemoveFileHandle($hConfig) $hConfig = 0 Return SetError($vRet, 0, ($vRet = 0)) EndFunc ;==>_Config_Close ; #FUNCTION# =================================================================== ; Name ..........: _Config_Indent ; Description ...: Indents an XML file ; Syntax ........: _Config_Indent($szFileName, $iEncoding = 0) ; Parameters ....: $szFileName - The file to indent ; $iEncoding - The encoding to use ; |0 - Default (UTF-16) ; |1 - iso-8859-1 ; |2 - UTF-8 ; |3 - UTF-16 ; Return values .: None ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: Uses msxml SAX methods to indent an xml file. It is NOT PERFECT. HTML-Tidy does a much better job. ; Requires MSXML4.0 or greater. ; Related .......: ; Link ..........: http://tidy.sourceforge.net ; Example .......: Yes ; ================================================================================ Func _Config_Indent($szFileName, $iEncoding = 0) Local $oOutput = ObjCreate("MSXML2.DOMDocument.4.0") Local $oReader = ObjCreate("MSXML2.SAXXMLReader.4.0") Local $oWriter = ObjCreate("MSXML2.MXXMLWriter.4.0") If @error Then $oWriter = ObjCreate("MSXML2.MXXMLWriter.6.0") If @error Then Return SetError(1, 0, 0) EndIf If $iEncoding <= 0 Or $iEncoding > UBound($XML_ENCODING) Then $iEncoding = $XML_ENCODING[0] $oWriter.indent = True $oWriter.byteOrderMark = True $oWriter.encoding = $XML_ENCODING[$iEncoding] $oWriter.omitXMLDeclaration = False $oWriter.standalone = True $oReader.contentHandler = $oWriter $oReader.parseURL($szFileName) $oOutput.loadXML($oWriter.output) $oOutput.save($szFileName) $oReader = 0 $oWriter = 0 $oOutput = 0 EndFunc ;==>_Config_Indent ; #FUNCTION# =================================================================== ; Name ..........: _Config_Base64_Encode ; Description ...: Encodes the data input to base64. ; Syntax ........: _Config_Base64_Encode($vData) ; Parameters ....: $vData - The base64 string to Encode ; Return values .: Success - The encoded base64 string. ; Failure -0 or empty string ("") and @error set to 1 ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: This fails to produce desired results unless using AutoIt ver 3.3.0.0 ; or greater as byte array support for COM was not included previously. ; Related .......: ; Link ..........: ; Example .......: yes ; ================================================================================ Func _Config_Base64_Encode($vData) Local $err, $oXML If StringLeft(@AutoItVersion, 3) = "3.3" Then $oXML = ObjCreate("MSXML2.DOMDocument") $oXML.loadXML("<root/>") $oXML.documentElement.dataType = "bin.base64" If IsString($vData) Then $vData = StringToBinary($vData) $oXML.documentElement.NodeTypedValue = $vData Local $vRet = $oXML.documentElement.Text $err = @error $oXML = 0 Return SetError(($err <> 0 Or $vRet = ""), $err, $vRet) EndIf Return SetError(1, 0, 0) EndFunc ;==>_Config_Base64_Encode ; #FUNCTION# =================================================================== ; Name ..........: _Config_Base64_Decode ; Description ...: Decodes a Base64 string to binary. ; Syntax ........: _Config_Base64_Decode($vData, $iFlag = 0) ; Parameters ....: $vData - The base64 string to decode ; $iFlag - Set return type 0 = binary, anything else = text(String). ; Return values .: Success - The decoded base64 string in binary or text. ; Failure - @error set to 1. Return value may contain an error message. ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: This fails to produce desired results unless using AutoIt ver 3.3.0.0 ; or greater as byte array support for COM was not included previously. ; Related .......: ; Link ..........: ; Example .......: yes ; ================================================================================ Func _Config_Base64_Decode($vData, $iFlag = 0) Local $oXML, $vRet, $err = 0 If StringLeft(@AutoItVersion, 3) = "3.3" Then $oXML = ObjCreate("MSXML2.DOMDocument") $oXML.loadXML("<root/>") $oXML.documentElement.dataType = "bin.base64" $oXML.documentElement.text = $vData $vRet = $oXML.documentElement.NodeTypedValue $err = @error $oXML = 0 If $iFlag Then Return SetError(($err <> 0), $err, BinaryToString($vRet)) Return SetError(($err <> 0), $err, $vRet) EndIf Return SetError(1, 0, "") EndFunc ;==>_Config_Base64_Decode ; #INTERNAL_USE_ONLY# ============================================================ ; Name ..........: __Config_CreateKeyRecursive ; Description ...: Recursive method to create parameter key. ; Syntax ........: __Config_CreateKeyRecursive(ByRef $hConfig, $szParam, $vValue) ; Parameters ....: $hConfig - The config file handle ; $szParam - The name of the parameter to create. ; $vValue - The value of the parameter. ; Return values .: Succes - 1 ; Failure - 0 and @error set to 1 ; Author ........: Stephen Podhajecki {gehossafats at netmdc. com} ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; No ; ================================================================================ Func __Config_CreateKeyRecursive(ByRef $hConfig, $szParam, $vValue) If Not IsObj($hConfig) Then Return SetError(1, 0, 0) Local $aTemp = StringSplit($szParam, "\/") Local $objKey Local $sPath = "/" & $hConfig.documentElement.NodeName For $x = 1 To $aTemp[0] If Not __Config_KeyExists($hConfig, $sPath & "/" & $aTemp[$x]) Then Local $objChild = $hConfig.createNode($NODE_XML_ELEMENT, $aTemp[$x], "") If $x = $aTemp[0] Then $objChild.text = $vValue If $x = 1 Then $hConfig.documentElement.appendChild($objChild) Else $objKey = $hConfig.selectSingleNode($sPath) $objKey.appendChild($objChild) EndIf EndIf $sPath &= "/" & $aTemp[$x] Next Local $szFileName = __Config_GetFileFromHandle($hConfig) If $szFileName <> "" Then $hConfig.save($szFileName) EndIf Return 1 EndFunc ;==>__Config_CreateKeyRecursive ; #INTERNAL_USE_ONLY#============================================================= ; Name ..........: __Config_KeyExists ; Description ...: Check if a node name exists ; Syntax ........: __Config_KeyExists(ByRef $hConfig, $szParam) ; Parameters ....: $hConfig - The config file handle ; $szParam - The name of the parameter to check for. ; Return values .: Success - 1 ; Failure - 0 ; Author ........: Stephen Podhajecki {gehossafats at netmdc. com} ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; no ; ================================================================================ Func __Config_KeyExists(ByRef $hConfig, $szParam) If StringStripWS($szParam, 3) = "" Then Return SetError(1, 0, "") If Not IsObj($hConfig) Then Return SetError(1, 0, 0) Local $node = $hConfig.documentelement.selectSingleNode($szParam) If IsObj($node) Then $node = 1 Else $node = 0 EndIf Return $node EndFunc ;==>__Config_KeyExists ; #INTERNAL_USE_ONLY#============================================================= ; Name ..........: __Config_GetFileFromHandle ; Description ...: ; Syntax ........: __Config_GetFileFromHandle(ByRef $hConfig) ; Parameters ....: $hConfig - The config file handle ; Return values .: Success - The filename and @extended contains the index in the cache ; Failure - 0 and @error set to 1 ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: no ; ================================================================================ Func __Config_GetFileFromHandle(ByRef $hConfig) For $x = 1 To $aCONFIG_FHDS[0][0] If $hConfig = $aCONFIG_FHDS[$x][0] Then Return SetError(0, $x, $aCONFIG_FHDS[$x][1]) Next Return SetError(1, 0, 0) EndFunc ;==>__Config_GetFileFromHandle ; #INTERNAL_USE_ONLY#============================================================= ; Name ..........: __Config_SetFileToHandle ; Description ...: Add or changes the file handle to filename association in the handle cache. ; Syntax ........: __Config_SetFileToHandle(ByRef $hConfig , $szFileName) ; Parameters ....: $hConfig - The config file handle ; $szFileName - The filename to associate with the handle ; Return values .: Success - 1 ; Failure - 0 and @error set to 1 ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: no ; ================================================================================ Func __Config_SetFileToHandle(ByRef $hConfig, $szFileName) If IsObj($hConfig) And $szFileName <> "" Then If __Config_GetFileFromHandle($hConfig) <> "" Then $aCONFIG_FHDS[@extended][1] = $szFileName Else $aCONFIG_FHDS[0][0] += 1 ReDim $aCONFIG_FHDS[$aCONFIG_FHDS[0][0] + 1][2] $aCONFIG_FHDS[$aCONFIG_FHDS[0][0]][0] = $hConfig $aCONFIG_FHDS[$aCONFIG_FHDS[0][0]][1] = $szFileName EndIf Return 1 EndIf Return SetError(1, 0, 0) EndFunc ;==>__Config_SetFileToHandle ; #INTERNAL_USE_ONLY#============================================================= ; Name ..........: __Config_RemoveFileHandle ; Description ...: Removes a file handle and it's associated filename from the cache. ; Syntax ........: __Config_RemoveFileHandle(ByRef $hConfig) ; Parameters ....: $hConfig - The config file handle ; Return values .: Success - The index of the removed item ; Failure - 0 and @error set to 1 ; Author ........: Stephen Podhajecki (eltorro) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: no ; ================================================================================ Func __Config_RemoveFileHandle(ByRef $hConfig) For $x = 1 To $aCONFIG_FHDS[0][0] If $hConfig = $aCONFIG_FHDS[$x][0] Then For $y = $x To $aCONFIG_FHDS[0][0] - 1 $aCONFIG_FHDS[$y][0] = $aCONFIG_FHDS[$y + 1][0] $aCONFIG_FHDS[$y][1] = $aCONFIG_FHDS[$y + 1][1] Next $aCONFIG_FHDS[0][0] -= 1 ReDim $aCONFIG_FHDS[$aCONFIG_FHDS[0][0] + 1][2] Return $x EndIf Next Return SetError(1, 0, 0) EndFunc ;==>__Config_RemoveFileHandle ; #INTERNAL_USE_ONLY#============================================================= ; Name ..........: __Config_COMErr ; Description ...: Sven com error handler ; Syntax ........: __Config_COMErr() ; Parameters ....: None. ; Return values .: @Error set to 1 and @Extended set to the COM error number. ; Author ........: ; Modified.......: ; Remarks .......: Default error handler. ; Related .......: __Config_InitCOMErr ; Link ..........: ; Example .......: no ; ================================================================================ Func __Config_COMErr() Local $HexNumber = Hex($__COM_ERR.number, 8) If @error Then Return SetError(1, 0, 0) Local $msg = "COM Error with DOM!" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $__COM_ERR.description & @CRLF & _ "err.windescription:" & @TAB & $__COM_ERR.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $__COM_ERR.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $__COM_ERR.scriptline & @CRLF & _ "err.source is: " & @TAB & $__COM_ERR.source & @CRLF & _ "err.helpfile is: " & @TAB & $__COM_ERR.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $__COM_ERR.helpcontext ;MsgBox(0, @AutoItExe, $msg) SetError(1, $__COM_ERR.number, $msg) EndFunc ;==>__Config_COMErr ; #INTERNAL_USE_ONLY#============================================================= ; Name ..........: __Config_InitCOMErr ; Description ...: Initialize the COM error event handler. ; Syntax ........: __Config_InitCOMErr([$sFunction]) ; Parameters ....: $sFunction - Function for COM error handler ; Return values .: None. ; Author ........: ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: [yes/no] ; ================================================================================ Func __Config_InitCOMErr($sFunction = "__Config_COMErr") If $__COM_ERR <> "" Then $__COM_ERR = "" $__COM_ERR = ObjEvent("AutoIt.Error", $sFunction) ; ; Initialize SvenP 's error handler EndFunc ;==>__Config_InitCOMErr
  23. Uh, a reproducer Your error is simple, you open the GUI and example you have True, so GUICtrlCreateIcon create an icon. But if you want to change that icon you don't need to apply another GUICtrlCreateIcon, in this case you have 2 control with two different icon, but change the previus one control This work: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $devicemgr Global $iIconDriver = -1 ; <<<<< declare only ONE icon for "Are Drivers Installed" Local $GUI_Start = GUICreate("Final Check", 300, 300, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX)) ;<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>> GUICtrlCreateLabel("Are Drivers Installed", 60, 60, 150, 25) _Settings() ;<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>> ;$iIconDriver = GUICtrlCreateIcon("", 0, 6, 60) <<<<< If you put here is better _Update() ; Update the gui with info ;<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>> Local $RefreshButton = GUICtrlCreateButton(" Refresh List ", 60, 200, 130, 55) _Settings() ;<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>> GUISetState() Local $nMsg = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $RefreshButton Sleep(2000) _Update() EndSwitch WEnd Func _Update() $devicemgr = _DeviceProblems() If $devicemgr = True Then If $iIconDriver = -1 Then $iIconDriver = GUICtrlCreateIcon("", 0, 6, 60) ; <<<<< If the control not exist, create it If $iIconDriver <> -1 Then GUICtrlSetImage($iIconDriver, "shell32.dll", -111) ; <<<<< If the control exist, change the icon ConsoleWrite('Device Manager Is ' & $devicemgr & @CRLF) Else If $iIconDriver = -1 Then $iIconDriver = GUICtrlCreateIcon("", 0, 6, 60) ; <<<<< If the control not exist, create it If $iIconDriver <> -1 Then GUICtrlSetImage($iIconDriver, "shell32.dll", -110) ; <<<<< If the control exist, change the icon ConsoleWrite('Device Manager Is ' & $devicemgr & @CRLF) EndIf EndFunc ;==>_Update Func _Settings() GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ;~ GUICtrlSetDefBkColor(0xFF0000) ; For Checking Label Placements GUICtrlSetFont(-1, 11, 600, "", "Tahoma") EndFunc ;==>_Settings Func _DeviceProblems() Local $Code = "", $codemsg = "", $strComputer = "." #forceref $codemsg Local $bProblemsExist = False, $bDisabledExist = False Local $DEVobjWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") Local $DEVcolItems = $DEVobjWMIService.ExecQuery("Select * from Win32_PnPEntity " & "WHERE ConfigManagerErrorCode <> 0") For $DEVobjItem In $DEVcolItems $Code = $DEVobjItem.name If $DEVobjItem.ConfigManagerErrorcode >= 1 And $DEVobjItem.ConfigManagerErrorcode <= 52 Then $bProblemsExist = True EndIf Return False Next If $bDisabledExist = False And $bProblemsExist = False Then Return True EndIf EndFunc ;==>_DeviceProblems
  24. Chimaera, Next time please post a reproducer script of what you want to do, not necessary the entire code or a part of it but something someone can copy-past on SciTe...so is more easy to understand and less time to make everything. I think that you know how it works here, you have more than 2.000 posts Based on your code-style: ; Johnmcloud test code - 2015 #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Global $lMachine, $lDriver, $lInternet Global $iMachine, $iDriver, $iInteret Global $sMachine, $sDriver, $sInternet Global $hGUI, $dBegin, $dEnd, $iButton $hGUI = GUICreate("Johnmcloud", 220, 180) GUISetFont(Default, 800) $dBegin = GUICtrlCreateDummy() $sMachine = _ActivationStatus(1) ; assuming is true GUICtrlCreateLabel("Is Machine Activated", 40, 16) ;~ $lMachine = GUICtrlCreateLabel($sMachine, 175, 16) If $sMachine = "TRUE" Then $iMachine = GUICtrlCreateIcon("shell32.dll", -111, 6, 6) Else $iMachine = GUICtrlCreateIcon("shell32.dll", -110, 6, 6) EndIf $sInternet = _InternetStatus(0) ; assuming is False GUICtrlCreateLabel("Is Internet Connected", 39, 58) ;~ $lInternet = GUICtrlCreateLabel($sInternet, 175, 104) If $sInternet = "TRUE" Then $iInteret = GUICtrlCreateIcon("shell32.dll", -111, 6, 95) Else $iInteret = GUICtrlCreateIcon("shell32.dll", -110, 6, 95) EndIf $sDriver = _DeviceProblems(0) ; assuming is false GUICtrlCreateLabel("Are Driver Installed", 39, 104) ;~ $lDriver = GUICtrlCreateLabel($sDriver, 175, 58) If $sDriver = "TRUE" Then $iDriver = GUICtrlCreateIcon("shell32.dll", -111, 6, 49) Else $iDriver = GUICtrlCreateIcon("shell32.dll", -110, 6, 49) EndIf $dEnd = GUICtrlCreateDummy() $iButton = GUICtrlCreateButton("Update", 90, 140, 50, 25) GUICtrlSetFont(-1, Default, 400) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $iButton _Update($dBegin, $dEnd) EndSwitch WEnd Func _Update($iStart, $iEnd) Local $iID For $iID = $iStart + 1 To $iEnd - 1 ;~ If GUICtrlRead($iID) = "FALSE" Then ; check only false value, if are the true...are true so skip it Switch GUICtrlRead($iID) ; search for the label, if you use GUICtrlRead($iID) = "FALSE" you need to use Switch GUICtrlRead($iID-1) Case "Is Machine Activated" ; is True, is skipped if you use GUICtrlRead($iID) = "FALSE" but you need to add it in case is False $sMachine = _ActivationStatus(1) ;~ GUICtrlSetData($iID, $sMachine) If $sMachine = "TRUE" Then GUICtrlSetImage($iID + 1, "shell32.dll", -111) Else GUICtrlSetImage($iID + 1, "shell32.dll", -110) EndIf Case "Is Internet Connected" $sInternet = _InternetStatus(1) ; this time return true just for see the change ;~ GUICtrlSetData($iID, $sInternet) If $sInternet = "TRUE" Then GUICtrlSetImage($iID + 1, "shell32.dll", -111) Else GUICtrlSetImage($iID + 1, "shell32.dll", -110) EndIf Case "Are Driver Installed" $sDriver = _InternetStatus(1) ; this time return true just for see the change ;~ GUICtrlSetData($iID, $sDriver) If $sDriver = "TRUE" Then GUICtrlSetImage($iID + 1, "shell32.dll", -111) Else GUICtrlSetImage($iID + 1, "shell32.dll", -110) EndIf EndSwitch ;~ EndIf Next EndFunc ;==>_Update Func _ActivationStatus($sParam) If $sParam = 0 Then Return "FALSE" If $sParam = 1 Then Return "TRUE" EndFunc ;==>_ActivationStatus Func _DeviceProblems($sParam) If $sParam = 0 Then Return "FALSE" If $sParam = 1 Then Return "TRUE" EndFunc ;==>_DeviceProblems Func _InternetStatus($sParam) If $sParam = 0 Then Return "FALSE" If $sParam = 1 Then Return "TRUE" EndFunc ;==>_InternetStatus
  25. ;~ Example made by LarsJ, just some very little change by Johnmcloud - 2015 #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> Opt("MustDeclareVars", 1) Global $hGUI, $hListview, $aHit[2] = [-1, -1] ; $aHit contains row & col of marked cell $hGUI = GUICreate("Mark Cell in Listview", 250, 222) Local $iListview = GUICtrlCreateListView("Column 0|Column 1", 2, 2, 248, 180, $LVS_REPORT, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) $$hListview = GUICtrlGetHandle($iListview) Local $iButton = GUICtrlCreateButton("Value?", 90, 193, 70, 20) For $i = 0 To 50 GUICtrlCreateListViewItem("Item" & $i & "|SubItem " & $i, $iListview) Next GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $iButton MsgBox(0, "Info", "Cell selected: " & _GUICtrlListView_GetItemText($hListview, $aHit[0], $aHit[1]) & @CR, 0, $hGUI) EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListview Switch $iCode Case $LVN_ITEMCHANGED Local $tNMLISTVIEW, $iItem, $aInfo $tNMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam) $iItem = DllStructGetData($tNMLISTVIEW, "Item") _GUICtrlListView_SetItemSelected($hListview, $iItem, False) Local $aInfo = GUIGetCursorInfo($hGUI) If $aInfo[2] Then $aInfo = _GUICtrlListView_SubItemHitTest($hListview, $aInfo[0] - 2, $aInfo[1] - 2) ; Upper left = ( 2, 2 ) If $aInfo[0] > -1 And $aInfo[1] > -1 And $aInfo[0] = $iItem Then If $aHit[0] > -1 Then _GUICtrlListView_RedrawItems($hListview, $aHit[0], $aHit[0]) If $aHit[0] <> $aInfo[0] Or $aHit[1] <> $aInfo[1] Then $aHit[0] = $aInfo[0] ; Row $aHit[1] = $aInfo[1] ; Col Else $aHit[0] = -1 ; Row $aHit[1] = -1 ; Col EndIf _GUICtrlListView_RedrawItems($hListview, $iItem, $iItem) EndIf EndIf Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage") Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any ITEM-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any SUBITEM-related drawing operations Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ; Before painting a subitem Local $dwItemSpec = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index Local $uItemState = DllStructGetData($tNMLVCUSTOMDRAW, "uItemState") ; Item state If $dwItemSpec = $aHit[0] Then ; Marked row Switch $iSubItem Case $aHit[1] ; Marked column DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0xFFFFFF) ; Forecolor white DllStructSetData($tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600) ; Backcolor dark blue, BGR Case Else ; Other columns DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0x000000) ; Forecolor black DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF) ; Backcolor white EndSwitch Else ; Other rows DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0x000000) DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF) EndIf Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY  $LVS_EX_BORDERSELECT works only with icon Listview style, your use is wrong. Rename the thread accordy to the request, so "how to select subitem in listview" or similar.
×
×
  • Create New...