johnmcloud
Active Members-
Posts
739 -
Joined
-
Last visited
Profile Information
-
Member Title
Not an AutoIt MVPs (MVP)
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
johnmcloud's Achievements
-
guner7 reacted to a post in a topic: Wait until done typing in input field
-
Leo1906 reacted to a post in a topic: Avoid Parent from losing focus
-
Exit silently on error and save message to file?
johnmcloud replied to kadanefewi's topic in AutoIt General Help and Support
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.: -
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.
-
Disable button style but still able to use button?
johnmcloud replied to Chimaera's topic in AutoIt GUI Help and Support
; 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! -
Wait until done typing in input field
johnmcloud replied to scriptjunkie's topic in AutoIt General Help and Support
; 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 -
Trong reacted to a post in a topic: Turn off warnings and errors on AutoIt
-
Turn off warnings and errors on AutoIt
johnmcloud replied to Trong's topic in AutoIt General Help and Support
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 ################################################ -
Compute the last day of the current month
johnmcloud replied to Skysnake's topic in AutoIt Example Scripts
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. -
Compute the last day of the current month
johnmcloud replied to Skysnake's topic in AutoIt Example Scripts
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... -
Compute the last day of the current month
johnmcloud replied to Skysnake's topic in AutoIt Example Scripts
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, -
Compute the last day of the current month
johnmcloud replied to Skysnake's topic in AutoIt Example Scripts
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. -
Compute the last day of the current month
johnmcloud replied to Skysnake's topic in AutoIt Example Scripts
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. -
Compute the last day of the current month
johnmcloud replied to Skysnake's topic in AutoIt Example Scripts
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 -
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
-
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.
-
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
-
WinGetTrans not always working?
johnmcloud replied to SlowCoder74's topic in AutoIt General Help and Support
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