Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/03/2018 in all areas

  1. I've been testing the subclassing technique in recent months and have used ComboBox examples for tests. Here is one of the examples. More examples will be added over the coming weeks. All examples are small and simple. However, all of them are based on the subclassing technique. It's the interesting aspect of the examples. Some are implemented with complete UDFs. Others are made as code examples only. First post becomes a list of examples as well as the first example. ComboBox Examples Color Combo (just below) Checkbox Combo Checkbox Combo slightly modified ListView Combo Other Control Examples Tabs and subtabs on demand My first script in the Examples forum. Well. You have to start somewhere. Windows Explorer address bar Colors and fonts in TreeViews Implementing Virtual TreeViews Hot-Track Enabled Toolbar Menu Simulating a modeless Choose Color Dialog Color Combo The first example is about color selection. It's an owner drawn ComboBox created with the $CBS_OWNERDRAWVARIABLE style so that colors can be displayed directly in the ComboBox by responding to $WM_DRAWITEM messages. There are already many of these examples, but none are implemented through the subclassing technique. The big advantage of subclassing is that a user of the UDF still can use his own $WM_DRAWITEM message handler through GUIRegisterMsg. The same Windows message can be used in both techniques without any conflicts. This is an example with a single ComboBox: #include <GUIConstantsEx.au3> #include "..\Includes\ComboColors.au3" Example() Func Example() ; Create GUI GUICreate( "1 ComboBox", 220, 264 ) ; Create ComboBox for color selection GUICtrlCreateLabel( "Named colors:", 10, 10, 200, 16 ) Local $aInfo = ComboColors_Create( "Tomato", 10, 26, 200, 26, 10, "Colors\NamedColors.txt", 9 ) ; $aInfo = [ $idComboBox, $aColors, $oColors, $sColors, $iColors ] ; $aColors = [ "Color name", 0xBackColor, 0xTextColor, 0xBrush ] ; $oColors dict obj: Key = "Color name", Val = index in $aColors ; $sColors = "Color0|Color1|Color2|..." ; $iColors = Number of colors ; Show GUI GUISetState() ; Message loop While 1 Switch GUIGetMsg() Case $aInfo[0] Local $sColor = GUICtrlRead( $aInfo[0] ) Local $iIndex = $aInfo[2]($sColor) ConsoleWrite( "Color = " & $sColor & @CRLF & _ "Index = " & $iIndex & @CRLF & _ "Back = 0x" & Hex( ($aInfo[1])[$iIndex][1], 6 ) & @CRLF & _ "Fore = 0x" & Hex( ($aInfo[1])[$iIndex][2], 6 ) & @CRLF & _ "Brush = " & ($aInfo[1])[$iIndex][3] & @CRLF & @CRLF ) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup GUIDelete() EndFunc Two different sources can be used to specify colors: An array and a text file. It's demonstrated in examples. ComboColors_Create() is defined this way: ; Create ComboBox for color selection ; ; Error code in @error Return value ; 1 => Invalid color info file/array Success => [ $idComboBox, $aColors, $oColors, $sColors, $iColors ] ; 2 => Error creating ComboBox Failure => 0 ; 3 => Too many ComboBoxes ; Func ComboColors_Create( _ $sColorInit, _ ; Initial ComboBox color $x, $y, $w, $h, _ ; Left, top, width, height $iListRows, _ ; Rows in drop-down ListBox $vColorInfo, _ ; File/array with color info $iFirstRow = 0 ) ; First row with color info There is also a ComboColors_Delete() function. This is a picture of an example with two ComboBoxes: The example above and this example is included in zip-file. Zip-file You need AutoIt 3.3.12 or later. Tested on Windows 7 and Windows 10. Comments are welcome. Let me know if there are any issues. ColorSelection.7z
    1 point
  2. Hi LarsJ, Tested and all works fine Thanks ptrex
    1 point
  3. Scoox

    While 1 WEnd CPU usage?

    Hi all, since I'm totally new to AutoIT, I guess I'm allowed to ask silly questions. Coming from AutoH*tkey, I thought an effective way to learn AutoIT would be to try and port a few of my own AHK scripts to AutoIT. I'm now looking into how to make scripts "permanent", that is, scripts that continue to run indefinitely until execution is explicitly terminated. From what I've read and seen this is done using something like this: While 1 WEnd The above code results in high CPU usage—obviously. Adding a Sleep() to it takes care of the CPU hogging: While 1 Sleep(1000) WEnd I don't understand, however, why the following code doesn't cause high CPU usage, does execution stop at GuiGetMsg() until something happens on the GUI?: While 1 $nMsg = GuiGetMsg() ; ... other code ... WEnd I just want to know what's considered best practice, thanks!
    1 point
  4. Hey @Tersion Almost every ZIP App supports command line parameters to zip/unzip archives. So, can you use one of them, or... ?
    1 point
  5. @Scoox Hi, and welcome to the AutoIt forum Directly from the Help file about GUIGetMsg(): This function automatically idles the CPU when required so that it can be safely used in tight loops without hogging all the CPU.
    1 point
  6. Scoox, GUIGetMsg has its own built-in Sleep of about 15ms (it varies depending on CPU loading) so you do not need a separate command. A Sleep(10) is more than sufficient to keep any other tight loop from frying the CPU - and as any shorter time parameter is automatically extended to 10ms there is no point in going lower, although tests have proved that even few nanoseconds are sufficient to prevent this. All clear? M23
    1 point
  7. Hello, I wrote a script for a game that functions perfectly with mouse clicks. I now changed everything to function with control click so I can minimize the window while the script runs. The clicking and functionality remained except for finding pixels on the game. In the original, I used Pixel Search to search coordinates on the screen for certain colors, but now that the screen is not exactly visible, it isn't detecting the colors at all. I would like to know if its possible to use pixel search on a minimized window or is there another way to search a specific coordinate on minimized window for specific pixels?
    1 point
  8. lol. I'm guessing it was a necro quote of my post that got edited. Since I got an alert I've been quoted but don't directly see it. I'm not here on a regular basis. Just lucky this time. Funny. I still use a modified version of what Melba23 linked to many years later. (well for the non gui scripts anyhow) But not really related to your question since it looks like you have that part figured out. As mentioned above. Yes, thats normal for PixelSearch since its looking at your screen output and not the program output you want to monitor. You can try to use controls to monitor the part of the program in question and see the changing data directly. Those are always active. It does not matter if the program is in the background or minimized. Controls can be hard to use when first learning, I still have to try a few things to figure them completely out when I need to access one. But there is usually more then one way to accomplish what you want. If controls do not work for you in this case then look at the registry or for changes in a file. It depends on what your trying to do and how the monitored app is interacting with your system. Does the program in question have an api? For example, autoit has some great excel functions built in but excel also has a bunch of functions you can call directly to do a lot more then what is in the autoit excel functions. Many programs are built with scripting in mind. If it has functions built in for other languages then its likely autoit can also access them. And welcome to Autoit. I had no idea how deep the rabbit hole was that I fell into when I first started using it many years ago. its an Amazing language and there are lots of very talented and helpful users here in the forums. Post some test code and I'm sure someone will be able to point you in the right direction of what you should be looking at. right then..... Off to do some research on why I dropped by today.
    1 point
  9. odaylton, Amend the _GUICtrlListView_SortItems function as follows: Func _GUICtrlListView_SortItems($hWnd, $iCol) Local $iRet, $iIndex, $pFunction, $hHeader, $iFormat, $iDirn If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) For $x = 1 To $__g_aListViewSortInfo[0][0] If $hWnd = $__g_aListViewSortInfo[$x][1] Then $iIndex = $x ExitLoop EndIf Next $pFunction = DllCallbackGetPtr($__g_aListViewSortInfo[$iIndex][2]) ; get pointer to call back $__g_aListViewSortInfo[$iIndex][3] = $iCol ; $nColumn = column clicked $__g_aListViewSortInfo[$iIndex][7] = 0 ; $bSet $__g_aListViewSortInfo[$iIndex][4] = $__g_aListViewSortInfo[$iIndex][6] ; nCurCol = $nCol $iRet = _SendMessage($hWnd, $LVM_SORTITEMSEX, $hWnd, $pFunction, 0, "hwnd", "ptr") If $iRet <> 0 Then If $__g_aListViewSortInfo[$iIndex][9] Then ; Use arrow in header $hHeader = $__g_aListViewSortInfo[$iIndex][10] For $x = 0 To _GUICtrlHeader_GetItemCount($hHeader) - 1 $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $x) If BitAND($iFormat, $HDF_SORTDOWN) Then _GUICtrlHeader_SetItemFormat($hHeader, $x, BitXOR($iFormat, $HDF_SORTDOWN)) ElseIf BitAND($iFormat, $HDF_SORTUP) Then _GUICtrlHeader_SetItemFormat($hHeader, $x, BitXOR($iFormat, $HDF_SORTUP)) EndIf Next $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $iCol) If $__g_aListViewSortInfo[$iIndex][5] = 1 Then ; ascending _GUICtrlHeader_SetItemFormat($hHeader, $iCol, BitOR($iFormat, $HDF_SORTUP)) $iDirn = 1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<< Else ; descending _GUICtrlHeader_SetItemFormat($hHeader, $iCol, BitOR($iFormat, $HDF_SORTDOWN)) $iDirn = 0 ; <<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf EndIf EndIf SetExtended($iDirn) ; Set the sort direction in @extended <<<<<<<<<<< Return $iRet <> 0 EndFunc ;==>_GUICtrlListView_SortItems Now when you sort a column @extended will give you the direction - as in this modified Help file example: #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView_Mod.au3> ; Standard UDF with the amended _SortItems function <<<<<<<<<<<<<<<<<<<<<<<<<< #include <WindowsConstants.au3> Global $g_idListView Example() Func Example() Local $hImage, $aIcons[3] = [0, 3, 6] Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE) Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER) GUICreate("ListView Sort", 300, 200) $g_idListView = GUICtrlCreateListView("Column1|Col2|Col3", 10, 10, 280, 180, -1, $iExWindowStyle) _GUICtrlListView_SetExtendedListViewStyle($g_idListView, $iExListViewStyle) ; Load images $hImage = _GUIImageList_Create(18, 18, 5, 3) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -7) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -12) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -3) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -4) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -5) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -6) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -9) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -10) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -11) _GUICtrlListView_SetImageList($g_idListView, $hImage, 1) _AddRow($g_idListView, "ABC|000666|10.05.2004", $aIcons) _AddRow($g_idListView, "DEF|444|11.05.2005", $aIcons, 1) _AddRow($g_idListView, "CDE|555|12.05.2004", $aIcons, 2) GUISetState(@SW_SHOW) _GUICtrlListView_RegisterSortCallBack($g_idListView) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $g_idListView ; Kick off the sort callback _GUICtrlListView_SortItems($g_idListView, GUICtrlGetState($g_idListView)) ; Look for direction in @extended <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Switch @extended Case 1 ConsoleWrite("Ascending" & @CRLF) Case Else ConsoleWrite("Descending" & @CRLF) EndSwitch EndSwitch WEnd _GUICtrlListView_UnRegisterSortCallBack($g_idListView) GUIDelete() EndFunc ;==>Example Func _AddRow($hWnd, $sItem, $aIcons, $iPlus = 0) Local $aItem = StringSplit($sItem, "|") Local $iIndex = _GUICtrlListView_AddItem($hWnd, $aItem[1], $aIcons[0] + $iPlus, _GUICtrlListView_GetItemCount($hWnd) + 9999) _GUICtrlListView_SetColumnWidth($hWnd, 0, $LVSCW_AUTOSIZE_USEHEADER) For $x = 2 To $aItem[0] _GUICtrlListView_AddSubItem($hWnd, $iIndex, $aItem[$x], $x - 1, $aIcons[$x - 1] + $iPlus) _GUICtrlListView_SetColumnWidth($hWnd, $x - 1, $LVSCW_AUTOSIZE) Next EndFunc ;==>_AddRow I suggest you open a feature request ticket in Trac (and lick to this thread) as this seems to be a useful addition to the UDF. M23
    1 point
  10. ResNullius

    INItoSQL DB

    Howdy Saint, I had occasion to test your fine project and I'd like to share a two-line speed up tip that took me a while to discover when I first started with SQLite. I tested your script with the additions on the largest ini file I could find on my system and my log reads as follows: Sorry I don't have a "before" log, I got tired of waiting.... The only problem is that it's so fast your Splash progress messages don't show up properly The "secret"? Add this line after you open your db (line 281 in v 1.4 of your code) $DBhandle = _SQLite_Open($DBfile) ; original code opening db _SQLite_Exec($DBhandle, "BEGIN;") ; <<<< Add this line And add the following line before you close your database (line 360 of your version 1.4 code) _SQLite_Exec($DBhandle, "COMMIT;") ; <<< Add this line _SQLite_Close($DBhandle) ; original code closing db PS: I also had to add a check on reading empty ini sections to prevent the script from crashing (line 327 of your v 1.4 code) $keys = IniReadSection($srcfle, $section) ; original code If Not (IsArray($keys)) Then ContinueLoop ; <<< Insert this line to prevent crashing on reading an empty section $entries = $keys[0][0] ; original code Hope these help, Cheers.
    1 point
  11. Using your 2.json try this - it should point you in the right direction. #Include "Json.au3" _Test() Func _Test() Local $Json1 = FileRead(@ScriptDir & "\2.json") Json_Dump($Json1) Local $Data1 = Json_Decode($Json1) Local $temp = json_get($Data1, '.Children[0].Children[0].Children[0].Children[1].Children[0].Value') Local $fs = json_get($Data1, '.Children[0].Children[0].Children[0].Children[2].Children[0].Value') MsgBox(0, "", "Tempature = " & $temp & @CRLF &"Fan Speed = " & $fs) EndFunc
    1 point
  12. Version 1.3.4.0 of the UDF has been released. General code enhancements FIXED BUGS: _OL_PSTAccess: On error 4 Exit was used instead of Return. So this error ended your whole script. CHANGED FUNCTIONS: _OL_PSTAccess: Now works with PST-files on network drives, though it is not recommended by Microsoft. Internal function __OL_PSTConvertUNC added to convert PST filepaths to UNC notation. Please test before using in production! For download please see my signature.
    1 point
  13. ptrex, you can use Ctrl+a to check/uncheck all items. New zip above.
    1 point
  14. Look i tryed to do the same of you. -1) I simply opened my windows info tool. -2) I unfreeze it. -3) I right click on any file -4) going to the sub menu -5) When i am on any wanted control i freeze windows info tool WITHOUT MOUVING MY MOUSE (the sub menu will desapear BUT the information showed wont change if you dont move the mouse. ) -7) My windows info tool is now like this : But i dont got any Class or Instance. So windowsInfo is dead for you i guess. Try somthing else.
    1 point
  15. langthang084, Just reset the accelerator key each time you change the GUI: #include <GUIConstantsEx.au3> Global $hMain = GuiCreate("New AutoIt v3 Script", 228, 130, -1, -1) Global $Button_1 = GuiCtrlCreateButton("Button1", 60, 20, 140, 40) Global $Button_2 = GuiCtrlCreateButton("Button2", 60, 80, 140, 40) GUISetState() $Gui1 = GUICreate("GUI - 1", 200, 100, 0, 0) $ButtonGui1 = GUICtrlCreateButton("Test Gui1", 60, 20, 100, 40) GuiSetState(@SW_HIDE, $Gui1) $Gui2 = GUICreate("GUI - 2", 200, 100, 0, 0) $ButtonGui2 = GUICtrlCreateButton("Test Gui2", 60, 20, 100, 40) GuiSetState(@SW_HIDE, $Gui2) Do Switch GuiGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button_1 GUISetState(@SW_SHOW, $Gui1) GuiSetState(@SW_HIDE, $Gui2) Local $aAccelKeys[1][2] = [["{enter}", $ButtonGui1]] GUISetAccelerators($aAccelKeys, $Gui1) Case $Button_2 GUISetState(@SW_SHOW, $Gui2) GuiSetState(@SW_HIDE, $Gui1) Local $aAccelKeys[1][2] = [["{enter}", $ButtonGui2]] GUISetAccelerators($aAccelKeys, $Gui2) case $ButtonGui1 MsgBox(0, "", "Test GUI 1") case $ButtonGui2 MsgBox(0, "", "Test GUI 2") EndSwitch Until FalseM23
    1 point
  16. "If that were true, you would have seen the many many threads about this, and wouldn't need to ask the question. My guess is that you just cannot be bothered looking and want the link to just click" Yes, I am. Actually if you had bothered to read my post instead of adding to your post count then maybe you'd know that I want an explanation of why. Why can't we? Read before you post. Save us both some time
    1 point
  17. AGsol, You need to look for the $LVN_COLUMNCLICK code within the WM_NOTIFY message. Add: GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")after the GUISetState(@SW_SHOW) line and then use this handler function: Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Switch HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Case $ListView1_Handle Switch DllStructGetData($tNMHDR, "Code") Case $LVN_COLUMNCLICK ; A column was clicked Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) Local $iCol = DllStructGetData($tInfo, "SubItem") ConsoleWrite("Column clicked: " & $iCol & @CRLF) EndSwitch EndSwitch Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFYIf you are unsure about GUIRegisterMsg and Windows message handlers, I recommend the GUIRegisterMsg tutorial in the Wiki. Please ask if you have any questions. M23
    1 point
  18. Thanks Smoke. I was using client coordinates. To Firefox, I actually did search and for a bit too...I gave up and got tired of reading irrelevant post. Thanks anyways, and sorry for re-asking an already answered question.
    1 point
×
×
  • Create New...