jacQues
Active Members-
Posts
63 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
jacQues's Achievements
Wayfarer (2/7)
0
Reputation
-
jacQues reacted to a post in a topic:
How can i close all apps that are running with autoit?
-
I want to randomize a list
jacQues replied to computergroove's topic in AutoIt General Help and Support
Nice alternative! This is possible, but has some implications. For example, when all numbers but 1 and 100 have been picked, a Random(1,100,1) could easily be repeated 500 times before a 'match' is found. Not very efficient. Also, be aware that Random(1,1,1) is not syntaxically (is that a word?) correct and will return 0, so work the min/max in a quicksort manner. The code would be very small, much smaller then any of the alternatives mentioned in this thread and still produce a truly random result. -
Thanks so much for your answers. Really appreciate it!
-
I want to randomize a list
jacQues replied to computergroove's topic in AutoIt General Help and Support
Without having done the maths, I believe that ArrayShuffle isn't fully random. If there are ten lines, then the first line in your file will be played first only once every twenty or so times. ; Assuming $iLines is already decleared and filled with the number of lines... local _ $sLine, _ $aLottery, _ $iLottery, _ $iPos do $aLottery = Lottery(1,$iLines) for $iLottery = 1 to $aLottery[0] $sLine = FileReadLine("database.txt",$aLottery[$iLottery]) $iPos = StringInStr($sLine,";",1) if $iPos then ShellExecuteWait(StringMid($sLine,$iPos+1)) next until false ; Lottery([<iMin>],[<iMax>],[<iDraws>]) --> <aDraws> ; <iMin> = lowest number that can be drawn; default 1 ; <iMax> = highest number that can be drawn; default <iMin>+9 ; <iDraws> = number of draws to take; default draw all numbers ; <aDraws> = array with the draws, where <iDraws> is stored in [0] func Lottery($iMin = default,$iMax = default,$iDraws = default) local _ $iDraw, _ $aDraws[1] = [0], _ $iNumber, _ $aNumbers[1] = [0], _ $iNumbers, _ $iRandom if (not IsInt($iMin)) then $iMin = 1 if (not IsInt($iMax)) then $iMax = $iMin+9 $iNumbers = $iMax-$iMin+1 if (not IsInt($iDraws)) or $iDraws>$iNumbers then $iDraws = $iNumbers if $iMin<=$iMax and $iDraws>=1 then redim $aNumbers[$iNumbers+1] $aNumbers[0] = $iNumbers for $iNumber = 1 to $iNumbers $aNumbers[$iNumber] = $iMin+$iNumber-1 next redim $aDraws[$iDraws+1] $aDraws[0] = $iDraws for $iDraw = 1 to $iDraws if $iNumbers=1 then $iRandom = 1 ;endif else $iRandom = Random(1,$iNumbers,1) endif $iNumber = 0 do $iNumber += 1 if IsInt($aNumbers[$iNumber]) then $iRandom -= 1 until $iRandom=0 $aDraws[$iDraw] = $aNumbers[$iNumber] $aNumbers[$iNumber] = default $iNumbers -= 1 next endif return $aDraws endfunc ; Lottery Edit: I just did a quick test and my assumption was correct. Values have less chance than the general odds to be selected as the pick where they came from using ArrayShuffle. So if randomness matters, don't use ArrayShuffle. -
Copy and rename a working MP3 file to X:Test.mp3. Here, X: is the drive letter (J:, K etc.) of an USB stick formatted in either FAT32 or exFAT. From a DOS prompt, type the following: X: start Test.mp3 If the assigned music player doesn't starts, then it won't from AutoIt either. Fix this via your music player (file extension associations). Assuming this works, we can try the same via an AutoIt script: ShellExecute("X:Test.mp3") I bet this will work for you. If not, then your antivirus software is keeping AutoIt in a sandbox or something. In such cases, it could even be that a compiled script works whereas an .AU3 doesn't, or the other way around. In any case, add AutoIt3.exe and/or your compiled .exe file to the trused file list. If everything works like expected, move the file to "C:Test.mp3" and then try: ShellExecute("C:Test.mp3") If if works, then it seems that there's no problem and you probably made a typo in your script. If this doesn't work, you now know that the problem is somehow NTFS-related.
-
Quick question for something I cannot test. My ISP is considering moving from IPv4 to IPv6. Does the function InetGet() work properly with IPv6? If not, what can I do? Use TCP*() functions instead? jacQues P.S. Could this site maybe consider Bitcoin for donations?
-
$GUI_DEFBUTTON seens to stick after GUICtrlDelete()
jacQues replied to jacQues's topic in AutoIt GUI Help and Support
Thanks so much for the very quick replies! So now I know why this is happening. But how can I 'reset' this behaviour neatly? For now, I made the following 'dirty' workaround: ; Use after building the GUI and before looping for user interaction: GUICtrlCreateButton("",0,0) GUICtrlSetState(-1,$GUI_DEFBUTTON) GUICtrlDelete(-1) This does seem like a bug to me, but Melba23 seems to suggest that it is expected operation. I guess the thing I'm missing is either GUICtrlSetState($control,$GUI_NODEFBUTTON) or even GUISetState(@SW_NODEFBUTTON), since there can only be one control with DEFBUTTON... jacQues -
In the example below I use $GUI_DEFBUTTON once. As expected, the first time an Enter won't press any button and the second time it will press button 2. But the third time it continues to press button 2. What am I missing/doing wrong?? #include <GUIConstantsEx.au3> global $aButton[4] = [0] local $iMsg GUICreate("test") GUICtrlCreateLabel("Test...",10,10) GUISetState() MakeButtons(110) Wait4Click() DeleteButtons() MakeButtons(210) GUICtrlSetState($aButton[2],$GUI_DEFBUTTON) Wait4Click() DeleteButtons() MakeButtons(310) Wait4Click() func Wait4Click() while true $iMsg = GUIGetMsg() if $iMsg>0 then for $i = 1 to $aButton[0] if $iMsg=$aButton[$i] then MsgBox(0,"test","Button "&String($i)&"...") return endif next ;endif elseif $iMsg=$GUI_EVENT_CLOSE then MsgBox(0,"test","Close...") return endif wend endfunc func DeleteButtons() for $i = 1 to $aButton[0] GUICtrlDelete($aButton[$i]) next $aButton[0] = 0 endfunc func MakeButtons($iX) $aButton[0] = 3 $aButton[1] = GUICtrlCreateButton("button 1",$iX,110) $aButton[2] = GUICtrlCreateButton("button 2",$iX,210) $aButton[3] = GUICtrlCreateButton("button 3",$iX,310) endfunc
-
Thank you thank you!! DllStructCreate("wchar Text[" & (2*StringLen($sText)+1) & "]") Then, instead of "InsertMenuItem" use "InsertMenuItemW" and everything works... W007 jacQues
-
Possible to delete a lot of controls in one command?
jacQues replied to Spiff59's topic in AutoIt GUI Help and Support
Correct, each update will be drawn. Use GUISetState(@SW_LOCK) before starting and GUISetState(@SW_UNLOCK) after finishing. This will remove the flicker and also make your code run much faster. jacQues -
This week I was writing an application in AutoIt, using all kinds of fancy things. And everything works perfect; AutoIt rocks! Just one thing is nagging me. The application is multi-lingual and some of them I cannot read. lol Fancy symbols all over the place using UniCode except when using _GUICtrlMenu_AddMenuItem() and _GUICtrlMenu_TrackPopupMenu(). I looked at the source in GuiMenu.au3 but cannot find anything to adjust this. In English and most other languages the menu is fine... The strings passed to _GUICtrlMenu_AddMenuItem() are the exact same as that are passed to other GUI functions, which are collected from a database and stored in an array. So I know for sure its not the encoding or anything. So, is this a known issue? Maybe there is already a fix? Or is this a Windows limitation? (I am using XP) jacQues
-
How to copy an image file to the clipboard?
jacQues replied to jacQues's topic in AutoIt General Help and Support
BTW, one thing I did find is this: Func _GDIPlus_ImageCreateGDICompatibleHBITMAP($hImg) Local $hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImg) Local $hBitmap = _WinAPI_CopyImage($hBitmap2,0,0,0,$LR_COPYDELETEORG+$LR_COPYRETURNORG) _WinAPI_DeleteObject($hBitmap2) <=- fails, is already deleted? Return $hBitmap EndFunc -
How to copy an image file to the clipboard?
jacQues replied to jacQues's topic in AutoIt General Help and Support
...I never knew HBITMAP != HBITMAP... lol YOU ROCK! Thank you so much! -
I'm pretty sure that I am very close here, but it isn't working yet. The calls to user32.dll all seem to work (no MsgBox poping up), but when pasting nothing happens. Can anyone point me as to what I'm doing wrong please? #Include <GDIPlus.au3> _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile("C:\Documents and Settings\All Users\Application Data\Microsoft\User Account Pictures\guest.bmp") $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _GDIPlus_ImageDispose($hImage) $hDll = DllOpen("User32.dll") $aRet = DllCall($hDll,"int","OpenClipboard","hwnd",0); also tried GUICreate("test")) if $aRet[0]=0 then exit(msgbox(0,"error","OpenClipboard")) $aRet = DllCall($hDll,"int","EmptyClipboard") if $aRet[0]=0 then exit(msgbox(0,"error","EmptyClipboard")) $aRet = DllCall($hDll,"int","SetClipboardData","int",2,"hwnd",$hBitmap); also tried "ptr" if $aRet[0]=0 then msgbox(0,"error","SetClipboardData") $aRet = DllCall($hDll,"int","CloseClipboard") if $aRet[0]=0 then exit(msgbox(0,"error","CloseClipboard")) DllClose($hDll) _WinAPI_DeleteObject($hBitmap) _GDIPlus_ShutDown()
-
How to add an arrow for a menu item without GDIPlus?
jacQues replied to jacQues's topic in AutoIt GUI Help and Support
Got it fixed now, so no more need for help. Numerous issues with Dll*functions geez, they didn't make it easy. In addition, _GUICtrlMenu_SetItemBmp() doesn't do the trick, gotto use _GUICtrlMenu_SetItemBitmaps() instead. -
I'm using _GUICtrlMenu_AddMenuItem() and it works great! But I want to add a simple arrow to the menu item. Now the problem is that special characters aren't allowed, at least, ChrW(<code>) doesn't do the job for me (using Windows XP). So I decided to use _GUICtrlMenu_SetItemBmp() as well, but I'm having trouble using this. But I do not want to use GDIPlus just for a simple arrow. I just want a single colour very simple 11 by 11 bitmap, no other advanced stuff. Amongst other things, I tried the following to create the bitmap: $tAsc = DllStructCreate($tagBITMAPINFO) DllStructSetData($tAsc,"Size",DllStructGetSize($tAsc)-4) DllStructSetData($tAsc,"Width",11) DllStructSetData($tAsc,"Height",11) DllStructSetData($tAsc,"Planes",1) DllStructSetData($tAsc,"BitCount",24) ; also tried 16 DIM $aAsc[11] = ; tried various things like strings and binary values $hDC = _WinAPI_CreateCompatibleDC(0) $hAsc = _WinAPI_CreateCompatibleBitmap($hDC,11,11) _WinAPI_SelectObject($hDC,$hAsc) ; also tried omitting whole line _WinAPI_SetDIBits($hDC,$hAsc,0,11,$aAsc,$tAsc,1) ; also tried omitting last parameter The menu shows either with a full block or no bitmap at all. What am I doing wrong?