Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/09/2021 in all areas

  1. Just in case someone needs similar companion functions for base conversion: Func _IntToString($i, $base) Return DllCall("msvcrt.dll", "wstr:cdecl", "_i64tow", "int64", $i, "wstr", "", "int", $base)[0] Return $aRes[0] EndFunc ;==>_IntToString Func _UintToString($i, $base) Return DllCall("msvcrt.dll", "wstr:cdecl", "_ui64tow", "uint64", $i, "wstr", "", "int", $base)[0] Return $aRes[0] EndFunc ;==>_UintToString Func _StringToUint($s, $base) Return DllCall("msvcrt.dll", "uint64:cdecl", "_wcstoui64", "wstr", $s, "ptr*", 0, "int", $base)[0] EndFunc ;==>_StringToUint Func _StringToInt($s, $base) Return DllCall("msvcrt.dll", "int64:cdecl", "_wcstoi64", "wstr", $s, "ptr*", 0, "int", $base)[0] EndFunc ;==>_StringToInt
    2 points
  2. Also: Local $input = InputBox("Message", "bin", "10101010") Local $bin = _StringToInt($input, 2) MsgBox($MB_SYSTEMMODAL, "Result", Hex($bin) & @LF & $bin) Func _StringToInt($s, $base) Return DllCall("msvcrt.dll", "int64:cdecl", "_wcstoi64", "wstr", $s, "ptr*", 0, "int", $base)[0] EndFunc ;==>_StringToInt Works for $base in [2,36]
    2 points
  3. Try this : #include <MsgBoxConstants.au3> Local $input = InputBox("Message", "bin", "10101010") Local $iInt = _BitsToInt($input) MsgBox($MB_SYSTEMMODAL, Hex($iInt), $iInt) Func _BitsToInt($bin) Local $aArr = StringSplit($bin, "", 2) Local $dec = 0 For $i = UBound($aArr) - 1 To 0 Step -1 If $aArr[$i] = "1" Then $dec = BitXOR($dec, BitShift(1, -(UBound($aArr) - 1 - $i))) EndIf Next Return $dec EndFunc ;==>_BitsToInt
    2 points
  4. Incremental search is usually implemented by drawing the background of the substrings that matches the search string with a specific color eg. yellow. Incremental in this context means that the search is performed dynamically after each character while the search string is typed. In a listview this can be implemented by owner drawing through the LVS_OWNERDRAWFIXED flag and WM_DRAWITEM messages. (A custom drawn listview supports coloring of fields. However, the coloring works best for whole fields. This doesn't make it applicable to incremental search.) Inspiration for the example is found in these two questions: Search box for names and Search In ListView (Redraw with matching string). Examples The zip file below contains three examples. Listview items are strings of random characters with different lengths. In all examples a global $iItems = 1000 in top of script specifies the number of rows. There are no performance issues up till 10,000 rows. Note that the search is performed in an array and not directly in the listview. A regular expression can be entered in the search box. Search strings like "m........." with a varying number of dots will result in a varying number of matches. To keep it simple only one occurrence of the search string in each item is tested. As soon as one occurrence is found the search loop moves on to next item. 1) Incremental text search.au3 The first example is a simple demonstration of basic functionality: F3 and Shift+F3 can be used instead of Next and Prev buttons. 2) Show matching rows only.au3 An owner drawn listview can easily be combined with a virtual listview to extend the functionality of the incremental search. A virtual listview is especially interesting if you want to dynamically update the listview to only display the rows that matches the search string. Such an update is very fast in a virtual listview. This example is useful if the listview contains a set of file names and you are searching for a specific file eg. to open the file. In this situation you are probably not interested in the files that doesn't match. Because the listview only contains matching rows "Next match" and "Prev match" buttons are disabled. Clear the search field to display all items. 3) Standard search dialog.au3 The last example is a demonstration of a standard search dialog as the search box in Notepad. FindText function in comdlg32.dll creates the standard search box. The function is implemented as _WinAPI_FindTextDlg in WinAPIDlg.au3. In the Microsoft documentation you can read: Note that the FINDREPLACE structure and the buffer for the search string should be a global or static variable so it does not go out of scope before the dialog box closes. Because the FINDREPLACE structure is created as a local variable in _WinAPI_FindTextDlg it goes out of scope as soon as the function returns. This implementation of FindText is used in the example: ;Func _WinAPI_FindTextDlg($hOwner, $sFindWhat = '', $iFlags = 0, $pFindProc = 0, $lParam = 0) Func _WinAPI_FindTextDlgEx(ByRef $tFR, $hOwner, $sFindWhat = '', $iFlags = 0, $pFindProc = 0, $lParam = 0) $__g_pFRBuffer = __HeapReAlloc($__g_pFRBuffer, 2 * $__g_iFRBufferSize) If @error Then Return SetError(@error + 20, @extended, 0) DllStructSetData(DllStructCreate('wchar[' & $__g_iFRBufferSize & ']', $__g_pFRBuffer), 1, StringLeft($sFindWhat, $__g_iFRBufferSize - 1)) ;Local $tFR = DllStructCreate($tagFINDREPLACE) $tFR = DllStructCreate($tagFINDREPLACE) DllStructSetData($tFR, 'Size', DllStructGetSize($tFR)) DllStructSetData($tFR, 'hOwner', $hOwner) DllStructSetData($tFR, 'hInstance', 0) DllStructSetData($tFR, 'Flags', $iFlags) DllStructSetData($tFR, 'FindWhat', $__g_pFRBuffer) DllStructSetData($tFR, 'ReplaceWith', 0) DllStructSetData($tFR, 'FindWhatLen', $__g_iFRBufferSize * 2) DllStructSetData($tFR, 'ReplaceWithLen', 0) DllStructSetData($tFR, 'lParam', $lParam) DllStructSetData($tFR, 'Hook', $pFindProc) DllStructSetData($tFR, 'TemplateName', 0) Local $Ret = DllCall('comdlg32.dll', 'hwnd', 'FindTextW', 'struct*', $tFR) If @error Or Not $Ret[0] Then Local $Error = @error + 30 __HeapFree($__g_pFRBuffer) If IsArray($Ret) Then Return SetError(10, _WinAPI_CommDlgExtendedErrorEx(), 0) Else Return SetError($Error, @extended, 0) EndIf EndIf Return $Ret[0] EndFunc Then it's ensured that the local variable that is used for $tFR in the script, does not go out of scope, while the search box is open. ListviewIncrSearch.7z 1) Incremental text search.au3 2) Show matching rows only.au3 3) Standard Find text dialog.au3 DrawItem.au3 GuiListViewEx.au3 WinAPIDlgEx.au3 You need AutoIt 3.3.14 or later. Tested on Windows 7 32/64 bit and Windows XP 32 bit. Comments are welcome. Let me know if there are any issues. (Set tab width = 2 in SciTE to line up comments by column.) ListviewIncrSearch.7z
    1 point
  5. @Deye The nice thing about using WMI, it is very simple to replace @ComputerName with a remote system hostname. Sure, you can do it with SC as well, but extra parsing is involved. @youtuber If you want to continue using WMI, you can optimize the WMI query to return faster. $ServicesUp.ExecQuery("SELECT Name, State FROM Win32_Service Where Name = '" & $ServiceName & "'") I also agree with Deye's approach of moving the GUICtrlSetData functions into the CheckService function.
    1 point
  6. Try it like so (using a shorter function ..) #include <GUIConstantsEx.au3> #include <constants.au3> $Form1 = GUICreate("Form1", 512, 223, 192, 124) $InstantWinupControl = GUICtrlCreateLabel("", 104, 104, 332, 17) GUISetState(@SW_SHOW) CheckService() AdlibRegister("CheckService", 5000) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func CheckService() $pid = Run(@ComSpec & ' /c sc query wuauserv | findstr STATE', '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $data Do $data &= StdoutRead($pid) Until @error If StringInStr($data, 'RUNNING') Then GUICtrlSetData($InstantWinupControl, "Win update service opened") Else GUICtrlSetData($InstantWinupControl, "Win update service is turned off") EndIf EndFunc ;==>CheckService
    1 point
  7. update the controls from adlib with a reasonable delay Stating it like so: CheckService() AdlibRegister("CheckService", 5000)
    1 point
  8. Simple. Fast.* Short. No dlls and no loops: Local $sbyte="10101010", $arr[1112] $arr[0]="0" $arr[1]="1" $arr[10]="2" $arr[11]="3" $arr[100]="4" $arr[101]="5" $arr[110]="6" $arr[111]="7" $arr[1000]="8" $arr[1001]="9" $arr[1010]="A" $arr[1011]="B" $arr[1100]="C" $arr[1101]="D" $arr[1110]="E" $arr[1111]="F" $sHex=$arr[StringLeft($sByte,4)] & $arr[StringRight($sByte,4)] ConsoleWrite($sHex &" "& Dec($sHex)) *Assuming multiple invocations
    1 point
  9. Just to confuse matters more when running it via psexec it works fine as well...
    1 point
  10. I don't have the option to have a closer look at this today, maybe tomorrow when I have my LT available again. Jos
    1 point
  11. Some people will be honoured, others will be adored. (I hope this pun will not get lost in translation)
    1 point
  12. Shark007, Thanks for your help too. Here is my amended file: Now to look at my other GUI-based UDFs to see if I can do the same thing with them too. Stand by for some more testing! M23
    1 point
  13. Since you haven't read the PM I sent you yet, I will put the gist of it here. The 3 reasons why I ignored you: If someone volunteers their time and expertise to help you, the first thing you should do is show some semblance of appreciation -- especially if you want (or might want) further assistance. Something as simple as thanks will usually suffice. Not doing so, will get you ignored. My name on this forum is TheXman, not "dude". Referring to me as "dude", "bro", "homie", or anything else other than my name, will most likely get you ignored. Since you never know who you are speaking with, it is always better to err on the side of being too formal than too casual. If I can help it, I no longer shoot at moving targets. So I don't play that "But another thing came up" or "one more thing" game. Usually that's just a lazy person's way to try to get others to write their script for them piece-by-piece, step-by-step. Or, it's a sign that the person hasn't fully thought out what it is they want and is trying to do it on the fly. Either way. I'm not going to allow you to waste my time. There are plenty of people on the forum that'll write your scripts for you or play that game, but I'm not one of them. I'm only interested in helping people learn how to help themselves, not to do it for them. If you have a larger goal in mind, then explain what you are trying to accomplish in detail, show what you've tried, and ask for help with whatever is giving you problems. Then, take the time to learn from the advice you are given and continue making progress towards you goal. If you hit another obstacle, then repeat the previous process until you reach your goal. You probably could also benefit by reading the 2 links in my signature that refer to how to get better answers to your technical questions.
    1 point
  14. MyEarth, I would do it this way: #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <HeaderConstants.au3> $hGUI = GUICreate("ListView Fix Column Width", 500, 500) $cLV = GUICtrlCreateListView("Column 0|Column 1|Column 2|Column 3", 10, 10, 420, 300) For $i = 0 To 3 _GUICtrlListView_SetColumnWidth($cLV, $i, 100) Next GUISetState() ; Prevent resizing of a specific column (0-based) Global $aFix_Col[][] = [[1, 100]] GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) ; Get details of message Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam) ; Look for header resize code $iCode = DllStructGetData($tNMHEADER, "Code") ; Get column Local $iCol = DllStructGetData($tNMHEADER, "Item") Switch $iCode Case $HDN_DIVIDERDBLCLICK, $HDN_DIVIDERDBLCLICKW ; Divider double click For $i = 0 To UBound($aFix_Col) - 1 If $iCol = $aFix_Col[$i][0] Then _GUICtrlListView_SetColumnWidth($cLV, $iCol, $aFix_Col[$i][1]) ExitLoop EndIf Next Case $HDN_BEGINTRACK, $HDN_BEGINTRACKW ; Divider drag For $i = 0 To UBound($aFix_Col) - 1 If $iCol = $aFix_Col[$i][0] Then Return True ExitLoop EndIf Next Return False EndSwitch EndFunc You do need to know the fixed column width you require, but then is that not why you want it fixed? M23 Edit: And thanks for showing me that the header could be resized by a double-click on the divider - I have just been modifying my GUIListViewEx UDF to prevent this using the same trick as above.
    1 point
  15. Hello. #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <HeaderConstants.au3> $hGUI = GUICreate("ListView Fix Column Width", 400, 300) $hListView = GUICtrlCreateListView("Column 0|Column 1|Column 2|Column 3", 2, 2, 394, 268) GUISetState() ; Prevent resizing of a specific column (0-based) Global $iFix_Col = 1 GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) ; Get details of message Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam) ; Look for header resize code $iCode = DllStructGetData($tNMHEADER, "Code") Switch $iCode Case $HDN_BEGINTRACK, $HDN_BEGINTRACKW,$HDN_ITEMCHANGINGW ; Now get column being resized Local $iCol = DllStructGetData($tNMHEADER, "Item") If $iCol = $iFix_Col Then ; Prevent resizing Return True Else ; Allow resizing Return False EndIf EndSwitch EndFunc Saludos
    1 point
×
×
  • Create New...