Leaderboard
Popular Content
Showing content with the highest reputation on 06/16/2020 in all areas
-
50 is the number of characters but in addition, make sure there is room for a terminating zero character. Replace this line Local $tText = DllStructCreate( "wchar[" & StringLen($sItem) & "]" ) with this line Local $tText = DllStructCreate( "wchar[" & StringLen($sItem)+1 & "]" ) To optimize the code for speed, the fastest thing you can do is to define $tText and $pText at the top of the code as global variables in this way (the AutoIt code interpreter will not spend a single nano second on that line in the WM_NOTIFY function): Global $tText = DllStructCreate( "wchar[1024]" ), $pText = DllStructGetPtr( $tText ) Make sure the $tText buffer is sufficiently large. The second fastest thing you can do is to define $tText and $pText as local static variables in the WM_NOTIFY function (the AutoIt code interpreter will not spend much time on the line when the variables are initialized): Local Static $tText = DllStructCreate( "wchar[1024]" ), $pText = DllStructGetPtr( $tText ) The slowest thing you can do is to create the variables dynamically every time you need them (the AutoIt code interpreter must interpret and execute these 3 commands (DllStructCreate, StringLen, DllStructGetPtr) each time a single cell in the listview needs to be updated).3 points
-
So I am trying to implement an archive system of sorts for my (SQLite) DB app. I wrote a function to attach a separate (archive) DB and sync the columns with main DB. If archive DB file does not exist, create file with _SQLiteOpen then close the file (and thus connection) with SQLite_Close. This works as intended, however, after the create operation, all subsequent _SQLite_* functions returned a "Library misuse error". After a little digging I found the problem in the _SQLite_Close function: it clears the "last opened database" handle even when there still is a live DB connection open. All other functions then "think" there is no DB connection active. I hacked two functions in the UDF for a quick fix: In _SQLite_Close: Change ... $__g_hDB_SQLite = 0 __SQLite_hDel($__g_ahDBs_SQLite, $hDB) Return $iRval[0] to: $__g_hDB_SQLite = __SQLite_hDel($__g_ahDBs_SQLite, $hDB) Return $iRval[0] and in Func __SQLite_hDel changed Func __SQLite_hDel(ByRef $ahLists, $hGeneric) Local $iElement = _ArraySearch($ahLists, $hGeneric) If $iElement > 0 Then _ArrayDelete($ahLists, $iElement) EndFunc ;==>__SQLite_hDel to: Func __SQLite_hDel(ByRef $ahLists, $hGeneric) Local $iElement = _ArraySearch($ahLists, $hGeneric) If $iElement > 0 Then _ArrayDelete($ahLists, $iElement) Return $ahLists[UBound($ahLists)-1] ; Return last opened db EndIf Return 0 EndFunc ;==>__SQLite_hDel so it preserves last opened DB again. My archive function now works great I'm not sure if this should be classified as a bug, but I believe so... Hope this helps someone before2 points
-
Send Key Does Not Work
Sidley and one other reacted to JLogan3o13 for a topic
@PrexCoder what part of this rule: are you finding difficult to comprehend? Do not post this question again.2 points -
@ScriptLineNumber knows the #include
FrancescoDiMuro reacted to argumentum for a topic
@ScriptLineNumber knows the #include. I can write Func this($var = @ScriptLineNumber) and it knows, just knows, now, somewhere ( in AutoIt ) is kept\noted. @ScriptFullPath and @ScriptName are that of the executed script and is the same if called in an included script. As it should and should not be otherwise. Hence there are missing macros, call them @IncludeScriptFullPath and @IncludeScriptName. Once compiled, the @IncludeScriptName and @ScriptName would obviously have the same value but while coding, these would come in handy. I came up with the inspiration and that is perfectly possible to do, while writing the "register almost all 219 messages (UDF/tool)". Not that is a great achievement as a tool but the ConsoleWrite("Script.au3"(@ScriptLineNumber) : note.. ) shows to know where to jump to. All that was missing was the @IncludeScriptName, to not hardcode the script name. And since @ScriptLineNumber knows the #include, where is my macro !!! I hope ( and honestly believe ), that is a useful macro, and a motion to add these be taken to the Overlord for immediate implementation. PS: I understand that there are more pressing things to do but, this may be just there, without much to do to the AutoIt code, other than add the macro. I'll add it to the trac, see where it goes. Added ticket # 3766.1 point -
How to send a key in window
Sidley reacted to JLogan3o13 for a topic
Third time is the charm. Take 7 days of not being able to post to consider how far you're going to get trying to bypass the forum rules (about this far).1 point -
Bad luck bud .... that's the Universe(s) for you. I've had a word with Miss Universe, and she now promises to leave you alone (bad luck). However, Mr. Universe might not be so obliging .... especially if he thinks you have been paying undue attention to his daughter. And bud ...... he's got arms of steel .... so be careful when you are thinking of swearing at the Universe. Anyway bud, good to see you are making at least some forward progress ... all sounds quite promising ... all this work on ImagineIt.1 point
-
What do you get when you try: $o_Excel.Worksheets(2).Range("F42:H51").NumberFormat = "#.##0,00"1 point
-
Indexing search engine
TheDcoder reacted to argumentum for a topic
I use everything for everything. ( https://www.autoitscript.com/forum/topic/184771-voidtools-everything-file-search-engine-ipc/ ) But I've got ppl that use it to search for text from within the documents and other than making my own indexer ( with fts3 ), I rather use the one from the OS that already does that. ..and setting to "Index Properties and File Contents", it's just perfect. Now, getting the data from into an array takes a knowing I just don't have. And don't mean read explorer.1 point -
Enumerating Fonts
argumentum reacted to DrJohn for a topic
Sure thing. I don't think it's rocket science, but if it would be helpful ... Here's a sample script that creates a Font Family/Style/Size chooser GUI. EnumFontTree() uses _WinAPI_EnumFontFamilies() to gather a list of all installed font families (this particular version leaves out those beginning with "@"), and organizes it into a tree of families and associated sub-families. The funny business happens on lines 130-131 -- any font families in the initial return list that start with the same 'stem' (prefix) get grouped together as associated 'sub-families' Then when EnumFontStyles() enumerates the styles for a given family, it includes both those obtained by calling _WinAPI_EnumFontFamilies() on that family, plus any 'sub-families' that were collected in the initial pass. (The rest of the code is just dedicated to creating and managing the three combo boxes). The result is similar to _ChooseFont(), but not identical. Note, for example, that if you select Cambria from the Family list, the Styles list populates with Cambria, Cambria Bold, Cambria Bold Italic, Cambria Italic ... and Cambria Math. _ChooseFont() doesn't do this. My code groups Cambria Math together with the others because the name begins with the same 'stem'. _ChooseFont() doesn't because ... I don't know why. #include <GuiConstantsEx.au3> #include <WinAPIGdi.au3> #include <FontConstants.au3> #include <WindowsConstants.au3> #include <GuiComboBox.au3> #include <Array.au3> Main() ; -------------------------------------------------------------------------- func Main() $gui = GUICreate("FontEnum", 800, 600) GUISetState(@SW_SHOW, $gui) $cur_font = "Arial Bold" $cur_size = 12 $family_combo = GUICtrlCreateCombo _ ( _ "", _ 10, 10, _ 250, 300, _ BitOR($CBS_SIMPLE, $WS_VSCROLL) _ ) $style_combo = GUICtrlCreateCombo _ ( _ "", _ 270, 10, _ 250, 200, _ BitOR($CBS_SIMPLE, $WS_VSCROLL) _ ) $size_combo = GUICtrlCreateCombo("", 530, 10, 100, 20) GUICtrlSetData _ ( _ $size_combo, _ "8|9|10|11|12|13|14|16|18|20|22|24|26|28|30|32|36|42|48", _ $cur_size _ ) $sample_label = GUICtrlCreateLabel($cur_font, 10, 320, 780, 100) GUICtrlSetFont($sample_label, $cur_size, $FW_DONTCARE, $GUI_FONTNORMAL, $cur_font) $font_tree = EnumFontTree() PopulateComboBoxes($font_tree, $family_combo, $style_combo, $cur_font) while True $msg = GUIGetMsg() switch $msg case $family_combo, $style_combo, $size_combo if ($msg = $family_combo) then PopulateStylesComboBox($font_tree, $family_combo, $style_combo, "") endif $cur_font = GUICtrlRead($style_combo) $cur_size = GUICtrlRead($size_combo) GUICtrlSetFont _ ( _ $sample_label, _ $cur_size, _ $FW_DONTCARE, _ $GUI_FONTNORMAL, _ $cur_font _ ) GUICtrlSetData($sample_label, $cur_font) case $GUI_EVENT_CLOSE Exit endswitch wend endfunc ; -------------------------------------------------------------------------- func PopulateComboBoxes($ft, $f, $st, $sel) for $i from 0 to ubound($ft) - 1 $family = $ft[$i][0] _GUICtrlComboBox_AddString($f, $family) if (($sel <> "") and (StringLeft($sel, StringLen($family)) = $family)) then _GUICtrlComboBox_SetCurSel($f, $i) PopulateStylesComboBox($ft, $f, $st, $sel) endif next endfunc ; -------------------------------------------------------------------------- func PopulateStylesComboBox($ft, $f, $st, $sel) _GUICtrlComboBox_ResetContent($st) $styles = EnumFontStyles($ft, GUICtrlRead($f)) for $i from 0 to ubound($styles) - 1 $style = $styles[$i] _GUICtrlComboBox_AddString($st, $style) if (($sel <> "") and ($style = $sel)) then _GUICtrlComboBox_SetCurSel($st, $i) else _GUICtrlComboBox_SetCurSel($st, 0) endif next endfunc ; -------------------------------------------------------------------------- func EnumFontTree() local $font_list = _WinAPI_EnumFontFamilies(0, "", $ANSI_CHARSET, -1, "@*", True) _ArraySort($font_list, 0, 1, 0, 0) local $font_tree[0][2] $i = 1 while ($i <= $font_list[0][0]) $stem = $font_list[$i][0] _ArrayAdd($font_tree, $stem) local $sub[0] do $i += 1 if ($i > $font_list[0][0]) then ExitLoop $st = $font_list[$i][0] if (StringLeft($st, StringLen($stem)) <> $stem) then ExitLoop _ArrayAdd($sub, $st) until False $font_tree[ubound($font_tree)-1][1] = $sub wend return $font_tree endfunc ; -------------------------------------------------------------------------- func EnumFontStyles($font_tree, $family) local $styles[0] $idx = _ArrayBinarySearch($font_tree, $family) if ($idx >= 0) then ; Get base family styles $a = _WinAPI_EnumFontFamilies(0, $family, $ANSI_CHARSET, -1) for $i = 1 to $a[0][0] _ArrayAdd($styles, $a[$i][2]) next ; Get subfamily styles $sub = $font_tree[$idx][1] for $i in $sub _ArrayAdd($styles, $i) next endif _ArraySort($styles) return _ArrayUnique($styles, Default, Default, Default, $ARRAYUNIQUE_NOCOUNT) endfunc /John1 point -
NM_CUSTOMDRAW not firing when run as 64bit
argumentum reacted to Melba23 for a topic
VAN0, We discovered this same problem in my GUIListViewEx thread - LarsJ explains it in detail here. Not a lot you can do about it I am afraid, other then forcing to x86. M231 point -
A cross-platform implementation of the AutoIt language
seadoggie01 reacted to TheDcoder for a topic
I am working on a tokensizer which will be the first stage in parsing, some call it the scanner phase. It is basically taking the raw text and converting it into tokens (variable, string, number, operator, keyword etc.), which are much easier to work with in code, the next step would be syntactic analysis, which is just a fancy word to describe to process of checking if the tokens are in the right order (e.x. checking if 123 = $number is in the right order... spoiler alert: it is not in the right order). As usual, not much work code wise but I have a plan in my mind now, and I spent most of my time today researching how enumerators work in C and if linked-lists are really the best way to store dynamically allocated data. Another nice thing is that I have finally created a repository with the code: https://github.com/DcodingTheWeb/EasyCodeIt The code is very basic right now, it just prints the contents of the script to the standard output, I will update it as I work on features. Don't forget to give the repository a 🌟 star if you like what I am doing1 point -
GUIListViewEx - BugFix Version 6 Apr 24
argumentum reacted to LarsJ for a topic
I've tested the header color example as 64 bit code on both Windows 7 and Windows 10. In both cases, it fails. There are no colors in the header. Then I've made a much smaller example that only contains header colors: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=y Opt( "MustDeclareVars", 1 ) #include <GUIConstants.au3> #include <GuiListView.au3> Global $hHeader, $aHdrTexts[8] Example() Func Example() ; Create GUI GUICreate( "ListView Header Colors - GUIRegisterMsg", 840, 420 ) ; Create ListView Local $idListView = GUICtrlCreateListView( "", 10, 10, 820, 400 ) _GUICtrlListView_SetExtendedListViewStyle ( $idListView, $LVS_EX_FULLROWSELECT ) ; Add columns to ListView For $i = 0 To 7 _GUICtrlListView_AddColumn( $idListView, "Column " & $i, 99 ) $aHdrTexts[$i] = "Column " & $i Next ; Fill ListView For $i = 0 To 99 GUICtrlCreateListViewItem( $i & "/0|" & $i & "/1|" & $i & "/2|" & $i & "/3|" & _ $i & "/4|" & $i & "/5|" & $i & "/6|" & $i & "/7|", $idListView ) Next ; Header control $hHeader = _GUICtrlListView_GetHeader( $idListView ) ; Register WM_NOTIFY message handler GUIRegisterMsg( 0x004E, "WM_NOTIFY" ) ; 0x004E = $WM_NOTIFY ; Show GUI GUISetState( @SW_SHOW ) ; Message loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup GUIDelete() EndFunc ; WM_NOTIFY message handler Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) Local Static $hHdrBrush = _WinAPI_CreateSolidBrush( 0xCCFFFF ) ; Yellow, BGR Local $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ), $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ), $iCode = DllStructGetData( $tNMHDR, "Code" ) Switch $hWndFrom Case $hHeader Switch $iCode Case $NM_CUSTOMDRAW Local $tNMCustomDraw = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam ) Local $dwDrawStage = DllStructGetData( $tNMCustomDraw, "dwDrawStage" ) Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins ConsoleWrite( "CDDS_PREPAINT" & @CRLF ) Return $CDRF_NOTIFYITEMDRAW ; Notify parent window of any item related drawing operations Case $CDDS_ITEMPREPAINT ; Before an item is drawn: Default painting (frames and background) ConsoleWrite( "CDDS_ITEMPREPAINT" & @CRLF ) Return $CDRF_NOTIFYPOSTPAINT ; Notify parent window of any post item related drawing operations Case $CDDS_ITEMPOSTPAINT ; After an item is drawn: Custom painting (item texts) ConsoleWrite( "CDDS_ITEMPOSTPAINT" & @CRLF ) Local $iIndex = DllStructGetData( $tNMCustomDraw, "dwItemSpec" ) ; Item index Local $hDC = DllStructGetData( $tNMCustomDraw, "hdc" ) ; Device context _WinAPI_SetBkMode( $hDC, $TRANSPARENT ) ; Transparent background Local $tRECT = DllStructCreate( $tagRECT ) DllStructSetData( $tRECT, 1, DllStructGetData( $tNMCustomDraw, 6 ) + 1 ) DllStructSetData( $tRECT, 2, DllStructGetData( $tNMCustomDraw, 7 ) + 1 ) DllStructSetData( $tRECT, 3, DllStructGetData( $tNMCustomDraw, 8 ) - 2 ) DllStructSetData( $tRECT, 4, DllStructGetData( $tNMCustomDraw, 9 ) - 2 ) _WinAPI_FillRect( $hDC, $tRECT, $hHdrBrush ) ; Background color DllStructSetData( $tNMCustomDraw, "Left", DllStructGetData( $tNMCustomDraw, "Left" ) + 4 ) ; Left margin DllStructSetData( $tNMCustomDraw, "Right", DllStructGetData( $tNMCustomDraw, "Right" ) - 4 ) ; Right margin DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $aHdrTexts[$iIndex], "int", StringLen( $aHdrTexts[$iIndex] ), "struct*", DllStructGetPtr( $tNMCustomDraw, "Left" ), "uint", $DT_LEFT+$DT_SINGLELINE+$DT_VCENTER ) ; _WinAPI_DrawText Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG #forceref $hWnd, $iMsg, $wParam EndFunc It fails the same way. Then I've replaced the GUIRegisterMsg technique with the Subclassing technique: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=y Opt( "MustDeclareVars", 1 ) #include <GUIConstants.au3> #include <GuiListView.au3> Global $hHeader, $aHdrTexts[8] Example() Func Example() ; Create GUI GUICreate( "ListView Header Colors - Subclassing", 840, 420 ) ; Create ListView Local $idListView = GUICtrlCreateListView( "", 10, 10, 820, 400 ) _GUICtrlListView_SetExtendedListViewStyle ( $idListView, $LVS_EX_FULLROWSELECT ) Local $hListView = GUICtrlGetHandle( $idListView ) ; Add columns to ListView For $i = 0 To 7 _GUICtrlListView_AddColumn( $idListView, "Column " & $i, 99 ) $aHdrTexts[$i] = "Column " & $i Next ; Fill ListView For $i = 0 To 99 GUICtrlCreateListViewItem( $i & "/0|" & $i & "/1|" & $i & "/2|" & $i & "/3|" & _ $i & "/4|" & $i & "/5|" & $i & "/6|" & $i & "/7|", $idListView ) Next ; Header control $hHeader = _GUICtrlListView_GetHeader( $idListView ) ; Register ListView WM_NOTIFY message handler Local $pLV_WM_NOTIFY = DllCallbackGetPtr( DllCallbackRegister( "LV_WM_NOTIFY", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) ) DllCall( "comctl32.dll", "bool", "SetWindowSubclass", "hwnd", $hListView, "ptr", $pLV_WM_NOTIFY, "uint_ptr", 0, "dword_ptr", 0 ) ; $iSubclassId = 0, $pData = 0 ;_WinAPI_SetWindowSubclass( $hListView, $pLV_WM_NOTIFY, 0, 0 ) ; $iSubclassId = 0, $pData = 0 ; Show GUI GUISetState( @SW_SHOW ) ; Message loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup DllCall( "comctl32.dll", "bool", "RemoveWindowSubclass", "hwnd", $hListView, "ptr", $pLV_WM_NOTIFY, "uint_ptr", 0 ) ; $iSubclassId = 0 ;_WinAPI_RemoveWindowSubclass( $hListView, $pLV_WM_NOTIFY, 0 ) ; $iSubclassId = 0 GUIDelete() EndFunc ; ListView WM_NOTIFY message handler Func LV_WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData ) If $iMsg <> 0x004E Then Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0] ; 0x004E = $WM_NOTIFY Local Static $hHdrBrush = _WinAPI_CreateSolidBrush( 0xCCFFFF ) ; Yellow, BGR Local $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ), $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ), $iCode = DllStructGetData( $tNMHDR, "Code" ) Switch $hWndFrom Case $hHeader Switch $iCode Case $NM_CUSTOMDRAW Local $tNMCustomDraw = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam ) Local $dwDrawStage = DllStructGetData( $tNMCustomDraw, "dwDrawStage" ) Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins ConsoleWrite( "CDDS_PREPAINT" & @CRLF ) Return $CDRF_NOTIFYITEMDRAW ; Notify parent window of any item related drawing operations Case $CDDS_ITEMPREPAINT ; Before an item is drawn: Default painting (frames and background) ConsoleWrite( "CDDS_ITEMPREPAINT" & @CRLF ) Return $CDRF_NOTIFYPOSTPAINT ; Notify parent window of any post item related drawing operations Case $CDDS_ITEMPOSTPAINT ; After an item is drawn: Custom painting (item texts) ConsoleWrite( "CDDS_ITEMPOSTPAINT" & @CRLF ) Local $iIndex = DllStructGetData( $tNMCustomDraw, "dwItemSpec" ) ; Item index Local $hDC = DllStructGetData( $tNMCustomDraw, "hdc" ) ; Device context _WinAPI_SetBkMode( $hDC, $TRANSPARENT ) ; Transparent background Local $tRECT = DllStructCreate( $tagRECT ) DllStructSetData( $tRECT, 1, DllStructGetData( $tNMCustomDraw, 6 ) + 1 ) DllStructSetData( $tRECT, 2, DllStructGetData( $tNMCustomDraw, 7 ) + 1 ) DllStructSetData( $tRECT, 3, DllStructGetData( $tNMCustomDraw, 8 ) - 2 ) DllStructSetData( $tRECT, 4, DllStructGetData( $tNMCustomDraw, 9 ) - 2 ) _WinAPI_FillRect( $hDC, $tRECT, $hHdrBrush ) ; Background color DllStructSetData( $tNMCustomDraw, "Left", DllStructGetData( $tNMCustomDraw, "Left" ) + 4 ) ; Left margin DllStructSetData( $tNMCustomDraw, "Right", DllStructGetData( $tNMCustomDraw, "Right" ) - 4 ) ; Right margin DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $aHdrTexts[$iIndex], "int", StringLen( $aHdrTexts[$iIndex] ), "struct*", DllStructGetPtr( $tNMCustomDraw, "Left" ), "uint", $DT_LEFT+$DT_SINGLELINE+$DT_VCENTER ) ; _WinAPI_DrawText Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch EndSwitch ; Call next function in subclass chain Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0] #forceref $iSubclassId, $pData EndFunc Here the code works in all 4 situations: Windows 7/10, 32/64 bit. In the GUIRegisterMsg example, only CDDS_PREPAINT notifications are displayed in SciTE console. The problem seems to be that the CDRF_NOTIFYITEMDRAW return values are not received by the operating system. Therefore, the operating system does not generate CDDS_ITEMPREPAINT or CDDS_ITEMPOSTPAINT notifications and the header items are not colored. Because the Subclassing example works, it excludes errors in the $tagNMLVCUSTOMDRAW structure. It seems like there is an error in the internal AutoIt code associated with the GUIRegisterMsg function when the code is run as 64 bit code. The return values from the WM_NOTIFY message handler are not properly forwarded to the operating system. The error seems also to be related to the fact that the header control is a second level child in relation to the GUI. Colors does work for a listview control which is a first level child. Solution: Implement the WM_NOTIFY message handler in GUIListViewEx.au3 using the Subclassing technique. This is not necessarily completely trivial. In my example above, it looks easy. But this is also a very small example. Lars.1 point -
voidtools' everything file search engine IPC
TheDcoder reacted to argumentum for a topic
The nice ppl of voidtools created Everything Search Engine ( " Locate files and folders by name instantly. " ) And made a CLI program to search from the command line. They also gave the source code, and reading it, I see the IPC quite familiar. // // // source for CLI.H // Everything IPC test // revision 2: // fixed command line interpreting '-' as a switch inside text. // revision 3: // convert unicode to same code page as console. // revision 4: // removed write console because it has no support for piping. // revision 5: // added ChangeWindowMessageFilterEx (if available) for admin/user support. // compiler options #pragma warning(disable : 4311) // type cast void * to unsigned int #pragma warning(disable : 4312) // type cast unsigned int to void * #pragma warning(disable : 4244) // warning C4244: 'argument' : conversion from 'LONG_PTR' to 'LONG', possible loss of data #pragma warning(disable : 4996) // deprecation #include <windows.h> #include <stdio.h> #include "everything_ipc.h" #define COPYDATA_IPCTEST_QUERYCOMPLETEW 0 #define MSGFLT_RESET 0 #define MSGFLT_ALLOW 1 #define MSGFLT_DISALLOW 2 typedef struct tagCHANGEFILTERSTRUCT { DWORD cbSize; DWORD ExtStatus; } CHANGEFILTERSTRUCT, *PCHANGEFILTERSTRUCT; static void write(wchar_t *text); static void write_DWORD(DWORD value); static int wstring_to_int(const wchar_t *s); int sort = 0; EVERYTHING_IPC_LIST *sort_list; HMODULE user32_hdll = 0; BOOL (WINAPI *pChangeWindowMessageFilterEx)(HWND hWnd,UINT message,DWORD action,PCHANGEFILTERSTRUCT pChangeFilterStruct) = 0; int wstring_length(const wchar_t *s) { const wchar_t *p; p = s; while(*p) { p++; } return (int)(p - s); } // query everything with search string int sendquery(HWND hwnd,DWORD num,WCHAR *search_string,int regex,int match_case,int match_whole_word,int match_path) { EVERYTHING_IPC_QUERY *query; int len; int size; HWND everything_hwnd; COPYDATASTRUCT cds; everything_hwnd = FindWindow(EVERYTHING_IPC_WNDCLASS,0); if (everything_hwnd) { len = wstring_length(search_string); size = sizeof(EVERYTHING_IPC_QUERY) - sizeof(WCHAR) + len*sizeof(WCHAR) + sizeof(WCHAR); query = (EVERYTHING_IPC_QUERY *)HeapAlloc(GetProcessHeap(),0,size); if (query) { query->max_results = num; query->offset = 0; query->reply_copydata_message = COPYDATA_IPCTEST_QUERYCOMPLETEW; query->search_flags = (regex?EVERYTHING_IPC_REGEX:0) | (match_case?EVERYTHING_IPC_MATCHCASE:0) | (match_whole_word?EVERYTHING_IPC_MATCHWHOLEWORD:0) | (match_path?EVERYTHING_IPC_MATCHPATH:0); query->reply_hwnd = hwnd; CopyMemory(query->search_string,search_string,(len+1)*sizeof(WCHAR)); cds.cbData = size; cds.dwData = EVERYTHING_IPC_COPYDATAQUERY; cds.lpData = query; if (SendMessage(everything_hwnd,WM_COPYDATA,(WPARAM)hwnd,(LPARAM)&cds) == TRUE) { HeapFree(GetProcessHeap(),0,query); return 1; } else { write(L"Everything IPC service not running.\n"); } HeapFree(GetProcessHeap(),0,query); } else { write(L"failed to allocate "); write_DWORD(size); write(L" bytes for IPC query.\n"); } } else { // the everything window was not found. // we can optionally RegisterWindowMessage("EVERYTHING_IPC_CREATED") and // wait for Everything to post this message to all top level windows when its up and running. write(L"Everything IPC window not found, IPC unavailable.\n"); } return 0; } int compare_list_items(const void *a,const void *b) { int i; i = wcsicmp(EVERYTHING_IPC_ITEMPATH(sort_list,a),EVERYTHING_IPC_ITEMPATH(sort_list,b)); if (!i) { return wcsicmp(EVERYTHING_IPC_ITEMFILENAME(sort_list,a),EVERYTHING_IPC_ITEMFILENAME(sort_list,b)); } else if (i > 0) { return 1; } else { return -1; } } static void write(wchar_t *text) { DWORD mode; int wlen; DWORD numwritten; HANDLE output_handle; output_handle = GetStdHandle(STD_OUTPUT_HANDLE); wlen = wstring_length(text); if (GetConsoleMode(output_handle,&mode)) { WriteConsoleW(output_handle,text,wlen,&numwritten,0); } else { char *buf; int len; len = WideCharToMultiByte(GetConsoleCP(),0,text,wlen,0,0,0,0); if (len) { buf = HeapAlloc(GetProcessHeap(),0,len); if (buf) { WideCharToMultiByte(GetConsoleCP(),0,text,wlen,buf,len,0,0); WriteFile(output_handle,buf,len,&numwritten,0); HeapFree(GetProcessHeap(),0,buf); } } } } static void write_DWORD(DWORD value) { wchar_t buf[256]; wchar_t *d; d = buf + 256; *--d = 0; if (value) { DWORD i; i = value; while(i) { *--d = '0' + (i % 10); i /= 10; } } else { *--d = '0'; } write(d); } void listresultsW(EVERYTHING_IPC_LIST *list) { DWORD i; if (sort) { sort_list = list; qsort(list->items,list->numitems,sizeof(EVERYTHING_IPC_ITEM),compare_list_items); } for(i=0;i<list->numitems;i++) { if (list->items[i].flags & EVERYTHING_IPC_DRIVE) { write(EVERYTHING_IPC_ITEMFILENAME(list,&list->items[i])); write(L"\r\n"); } else { write(EVERYTHING_IPC_ITEMPATH(list,&list->items[i])); write(L"\\"); write(EVERYTHING_IPC_ITEMFILENAME(list,&list->items[i])); write(L"\r\n"); } } PostQuitMessage(0); } // custom window proc LRESULT __stdcall window_proc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) { switch(msg) { case WM_COPYDATA: { COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lParam; switch(cds->dwData) { case COPYDATA_IPCTEST_QUERYCOMPLETEW: listresultsW((EVERYTHING_IPC_LIST *)cds->lpData); return TRUE; } break; } } return DefWindowProc(hwnd,msg,wParam,lParam); } void help(void) { write(L"-r Search the database using a basic POSIX regular expression.\n"); write(L"-i Does a case sensitive search.\n"); write(L"-w Does a whole word search.\n"); write(L"-p Does a full path search.\n"); write(L"-h --help Display this help.\n"); write(L"-n <num> Limit the amount of results shown to <num>.\n"); write(L"-s Sort by full path.\n"); } // main entry int main(int argc,char **argv) { WNDCLASSEX wcex; HWND hwnd; MSG msg; int ret; int q; wchar_t *search; wchar_t *d; wchar_t *e; wchar_t *s; int match_whole_word = 0; int match_path = 0; int regex = 0; int match_case = 0; int wasexename = 0; int matchpath = 0; int i; int wargc; wchar_t **wargv; DWORD num = EVERYTHING_IPC_ALLRESULTS; ZeroMemory(&wcex,sizeof(wcex)); wcex.cbSize = sizeof(wcex); if (!GetClassInfoEx(GetModuleHandle(0),TEXT("IPCTEST"),&wcex)) { ZeroMemory(&wcex,sizeof(wcex)); wcex.cbSize = sizeof(wcex); wcex.hInstance = GetModuleHandle(0); wcex.lpfnWndProc = window_proc; wcex.lpszClassName = TEXT("IPCTEST"); if (!RegisterClassEx(&wcex)) { write(L"failed to register IPCTEST window class\n"); return 1; } } if (!(hwnd = CreateWindow( TEXT("IPCTEST"), TEXT(""), 0, 0,0,0,0, 0,0,GetModuleHandle(0),0))) { write(L"failed to create IPCTEST window\n"); return 1; } // allow the everything window to send a reply. user32_hdll = LoadLibrary(L"user32.dll"); if (user32_hdll) { pChangeWindowMessageFilterEx = (BOOL (WINAPI *)(HWND hWnd,UINT message,DWORD action,PCHANGEFILTERSTRUCT pChangeFilterStruct))GetProcAddress(user32_hdll,"ChangeWindowMessageFilterEx"); if (pChangeWindowMessageFilterEx) { pChangeWindowMessageFilterEx(hwnd,WM_COPYDATA,MSGFLT_ALLOW,0); } } wargv = CommandLineToArgvW(GetCommandLineW(),&wargc); search = HeapAlloc(GetProcessHeap(),0,65536); if (!search) { write(L"failed to allocate "); write_DWORD(65536); write(L" bytes for search buffer.\n"); if (user32_hdll) { FreeLibrary(user32_hdll); } return 1; } d = search; // allow room for null terminator e = search + (65536 / sizeof(wchar_t)) - 1; wargc--; i = 0; for(;;) { if (i >= wargc) break; if (wcsicmp(wargv[i+1],L"-r") == 0) { regex = 1; } else if (wcsicmp(wargv[i+1],L"-i") == 0) { match_case = 1; } else if (wcsicmp(wargv[i+1],L"-w") == 0) { match_whole_word = 1; } else if (wcsicmp(wargv[i+1],L"-p") == 0) { match_path = 1; } else if (wcsicmp(wargv[i+1],L"-s") == 0) { sort = 1; } else if ((wcsicmp(wargv[i+1],L"-n") == 0) && (i + 1 < wargc)) { i++; num = wstring_to_int(wargv[i+1]); } else if (wargv[i+1][0] == '-') { // unknwon command help(); HeapFree(GetProcessHeap(),0,search); if (user32_hdll) { FreeLibrary(user32_hdll); } return 1; } else { // keep quotes ? q = 0; s = wargv[i+1]; while(*s) { if ((*s == ' ') || (*s == '\t') || (*s == '\r') || (*s == '\n')) { q = 1; break; } s++; } if ((d != search) && (d < e)) *d++ = ' '; if (q) { if (d < e) *d++ = '"'; } // copy append to search s = wargv[i+1]; while(*s) { if (d < e) *d++ = *s; s++; } if (q) { if (d < e) *d++ = '"'; } } i++; } // null terminate *d = 0; if (!sendquery(hwnd,num,search,regex,match_case,match_whole_word,match_path)) { // send query reports error HeapFree(GetProcessHeap(),0,search); if (user32_hdll) { FreeLibrary(user32_hdll); } return 1; } HeapFree(GetProcessHeap(),0,search); // message pump loop: // update windows if (PeekMessage(&msg,NULL,0,0,0)) { ret = (int)GetMessage(&msg,0,0,0); if (ret <= 0) goto exit; // let windows handle it. TranslateMessage(&msg); DispatchMessage(&msg); } else { WaitMessage(); } goto loop; exit: if (user32_hdll) { FreeLibrary(user32_hdll); } return 0; } static int wstring_to_int(const wchar_t *s) { const wchar_t *p; int value; p = s; value = 0; while(*p) { if (!((*p >= '0') && (*p <= '9'))) { break; } value *= 10; value += *p - '0'; p++; } return value; } // // // source for everything_ipc.h // Everything IPC #ifndef _EVERYTHING_IPC_H_ #define _EVERYTHING_IPC_H_ // C #ifdef __cplusplus extern "C" { #endif // 1 byte packing for our varible sized structs #pragma pack(push, 1) // WM_USER (send to the taskbar notification window) // SendMessage(FindWindow(EVERYTHING_IPC_WNDCLASS,0),WM_USER,EVERYTHING_IPC_*,lParam) // version format: major.minor.revision.build // example: 1.1.4.309 #define EVERYTHING_IPC_GET_MAJOR_VERSION 0 // int major_version = (int)SendMessage(hwnd,WM_USER,EVERYTHING_IPC_GET_MAJOR_VERSION,0); #define EVERYTHING_IPC_GET_MINOR_VERSION 1 // int minor_version = (int)SendMessage(hwnd,WM_USER,EVERYTHING_IPC_GET_MINOR_VERSION,0); #define EVERYTHING_IPC_GET_REVISION 2 // int revision = (int)SendMessage(hwnd,WM_USER,EVERYTHING_IPC_GET_REVISION,0); #define EVERYTHING_IPC_GET_BUILD_NUMBER 3 // int build = (int)SendMessage(hwnd,WM_USER,EVERYTHING_IPC_GET_BUILD,0); // find the everything window #define EVERYTHING_IPC_WNDCLASS TEXT("EVERYTHING_TASKBAR_NOTIFICATION") // find a everything search window #define EVERYTHING_IPC_SEARCH_WNDCLASS TEXT("EVERYTHING") // this global window message is sent to all top level windows when everything starts. #define EVERYTHING_IPC_CREATED TEXT("EVERYTHING_IPC_CREATED") // search flags for querys #define EVERYTHING_IPC_MATCHCASE 0x00000001 // match case #define EVERYTHING_IPC_MATCHWHOLEWORD 0x00000002 // match whole word #define EVERYTHING_IPC_MATCHPATH 0x00000004 // include paths in search #define EVERYTHING_IPC_REGEX 0x00000008 // enable regex // item flags #define EVERYTHING_IPC_FOLDER 0x00000001 // The item is a folder. (its a file if not set) #define EVERYTHING_IPC_DRIVE 0x00000002 // The folder is a drive. Path will be an empty string. // (will also have the folder bit set) // the WM_COPYDATA message for a query. #define EVERYTHING_IPC_COPYDATAQUERYA 1 #define EVERYTHING_IPC_COPYDATAQUERYW 2 // all results #define EVERYTHING_IPC_ALLRESULTS 0xFFFFFFFF // all results // macro to get the filename of an item #define EVERYTHING_IPC_ITEMFILENAMEA(list,item) (CHAR *)((CHAR *)(list) + ((EVERYTHING_IPC_ITEMA *)(item))->filename_offset) #define EVERYTHING_IPC_ITEMFILENAMEW(list,item) (WCHAR *)((CHAR *)(list) + ((EVERYTHING_IPC_ITEMW *)(item))->filename_offset) // macro to get the path of an item #define EVERYTHING_IPC_ITEMPATHA(list,item) (CHAR *)((CHAR *)(list) + ((EVERYTHING_IPC_ITEMW *)(item))->path_offset) #define EVERYTHING_IPC_ITEMPATHW(list,item) (WCHAR *)((CHAR *)(list) + ((EVERYTHING_IPC_ITEMW *)(item))->path_offset) // // Varible sized query struct sent to everything. // // sent in the form of a WM_COPYDAYA message with EVERYTHING_IPC_COPYDATAQUERY as the // dwData member in the COPYDATASTRUCT struct. // set the lpData member of the COPYDATASTRUCT struct to point to your EVERYTHING_IPC_QUERY struct. // set the cbData member of the COPYDATASTRUCT struct to the size of the // EVERYTHING_IPC_QUERY struct minus the size of a CHAR plus the length of the search string in bytes plus // one CHAR for the null terminator. // // NOTE: to determine the size of this structure use // ASCII: sizeof(EVERYTHING_IPC_QUERYA) - sizeof(CHAR) + strlen(search_string)*sizeof(CHAR) + sizeof(CHAR) // UNICODE: sizeof(EVERYTHING_IPC_QUERYW) - sizeof(WCHAR) + wcslen(search_string)*sizeof(WCHAR) + sizeof(WCHAR) // // NOTE: Everything will only do one query per window. // Sending another query when a query has not completed // will cancel the old query and start the new one. // // Everything will send the results to the reply_hwnd in the form of a // WM_COPYDAYA message with the dwData value you specify. // // Everything will return TRUE if successful. // returns FALSE if not supported. // // If you query with EVERYTHING_IPC_COPYDATAQUERYW, the results sent from Everything will be Unicode. // typedef struct EVERYTHING_IPC_QUERYW { // the window that will receive the new results. HWND reply_hwnd; // the value to set the dwData member in the COPYDATASTRUCT struct // sent by Everything when the query is complete. ULONG_PTR reply_copydata_message; // search flags (see EVERYTHING_MATCHCASE | EVERYTHING_MATCHWHOLEWORD | EVERYTHING_MATCHPATH) DWORD search_flags; // only return results after 'offset' results (0 to return the first result) // useful for scrollable lists DWORD offset; // the number of results to return // zero to return no results // EVERYTHING_IPC_ALLRESULTS to return ALL results DWORD max_results; // null terminated string. arbitrary sized search_string buffer. WCHAR search_string[1]; }EVERYTHING_IPC_QUERYW; // ASCII version typedef struct EVERYTHING_IPC_QUERYA { // the window that will receive the new results. HWND reply_hwnd; // the value to set the dwData member in the COPYDATASTRUCT struct // sent by Everything when the query is complete. ULONG_PTR reply_copydata_message; // search flags (see EVERYTHING_MATCHCASE | EVERYTHING_MATCHWHOLEWORD | EVERYTHING_MATCHPATH) DWORD search_flags; // only return results after 'offset' results (0 to return the first result) // useful for scrollable lists DWORD offset; // the number of results to return // zero to return no results // EVERYTHING_IPC_ALLRESULTS to return ALL results DWORD max_results; // null terminated string. arbitrary sized search_string buffer. CHAR search_string[1]; }EVERYTHING_IPC_QUERYA; // // Varible sized result list struct received from Everything. // // Sent in the form of a WM_COPYDATA message to the hwnd specifed in the // EVERYTHING_IPC_QUERY struct. // the dwData member of the COPYDATASTRUCT struct will match the sent // reply_copydata_message member in the EVERYTHING_IPC_QUERY struct. // // make a copy of the data before returning. // // return TRUE if you processed the WM_COPYDATA message. // typedef struct EVERYTHING_IPC_ITEMW { // item flags DWORD flags; // The offset of the filename from the beginning of the list structure. // (wchar_t *)((char *)everything_list + everythinglist->name_offset) DWORD filename_offset; // The offset of the filename from the beginning of the list structure. // (wchar_t *)((char *)everything_list + everythinglist->path_offset) DWORD path_offset; }EVERYTHING_IPC_ITEMW; typedef struct EVERYTHING_IPC_ITEMA { // item flags DWORD flags; // The offset of the filename from the beginning of the list structure. // (char *)((char *)everything_list + everythinglist->name_offset) DWORD filename_offset; // The offset of the filename from the beginning of the list structure. // (char *)((char *)everything_list + everythinglist->path_offset) DWORD path_offset; }EVERYTHING_IPC_ITEMA; typedef struct EVERYTHING_IPC_LISTW { // the total number of folders found. DWORD totfolders; // the total number of files found. DWORD totfiles; // totfolders + totfiles DWORD totitems; // the number of folders available. DWORD numfolders; // the number of files available. DWORD numfiles; // the number of items available. DWORD numitems; // index offset of the first result in the item list. DWORD offset; // arbitrary sized item list. // use numitems to determine the actual number of items available. EVERYTHING_IPC_ITEMW items[1]; }EVERYTHING_IPC_LISTW; typedef struct EVERYTHING_IPC_LISTA { // the total number of folders found. DWORD totfolders; // the total number of files found. DWORD totfiles; // totfolders + totfiles DWORD totitems; // the number of folders available. DWORD numfolders; // the number of files available. DWORD numfiles; // the number of items available. DWORD numitems; // index offset of the first result in the item list. DWORD offset; // arbitrary sized item list. // use numitems to determine the actual number of items available. EVERYTHING_IPC_ITEMA items[1]; }EVERYTHING_IPC_LISTA; #ifdef UNICODE #define EVERYTHING_IPC_COPYDATAQUERY EVERYTHING_IPC_COPYDATAQUERYW #define EVERYTHING_IPC_ITEMFILENAME EVERYTHING_IPC_ITEMFILENAMEW #define EVERYTHING_IPC_ITEMPATH EVERYTHING_IPC_ITEMPATHW #define EVERYTHING_IPC_QUERY EVERYTHING_IPC_QUERYW #define EVERYTHING_IPC_ITEM EVERYTHING_IPC_ITEMW #define EVERYTHING_IPC_LIST EVERYTHING_IPC_LISTW #else #define EVERYTHING_IPC_COPYDATAQUERY EVERYTHING_IPC_COPYDATAQUERYA #define EVERYTHING_IPC_ITEMFILENAME EVERYTHING_IPC_ITEMFILENAMEA #define EVERYTHING_IPC_ITEMPATH EVERYTHING_IPC_ITEMPATHA #define EVERYTHING_IPC_QUERY EVERYTHING_IPC_QUERYA #define EVERYTHING_IPC_ITEM EVERYTHING_IPC_ITEMA #define EVERYTHING_IPC_LIST EVERYTHING_IPC_LISTA #endif // restore packing #pragma pack(pop) // end extern C #ifdef __cplusplus } #endif #endif // _EVERYTHING_H_ so, the reason for this posting is: it can be implemented in AutoIt3 I personally can run es.exe and get the results from the command line, that is I, with my knowing, now, some of you can make a beautiful UDF ( and I say some of you, because, I would not know where to start ) I use everything for everything, very handy tool. If you ever get to see it work, you'll see how handy it is, mostly if you have many terabytes of files ( or just plain can't remember where a file is at )1 point -
Explorer like search in SQLite
argumentum reacted to jchd for a topic
https://www.sqlite.org/fts3.html Support for FTS4 is build in sqlite3.dll distributed thru AutoIt.1 point -
Sorry guys, it was kind of a bad day today, the day started with a power outage which lasted for a good 4 hours, which left me muggy and irritated. After that I got busy with lunch, catching up with other stuff, watching videos etc. So couldn't really take out time for coding. I did make some minor progress, wrote a structure for storing tokens and a skeleton function. I now have to figure out how to deal with white-space, which should be relatively easy. Hope to have something working by tomorrow0 points