Leaderboard
Popular Content
Showing content with the highest reputation on 10/30/2018 in all areas
-
This one is almost the regex version of iamtheky's code : local $aURLs[4] = ["http://autoitscript.com/blabla1", _ "http://autoitscript.com/blabla2/bla", _ "http://autoitscript.com/blabla3/blabla/", _ "http://autoitscript.com/bla-bla-bla4/"] For $i = 0 To 3 $s = StringRegExp($aURLs[$i] , '[^/]+', 3)[2] If not @error Then ConsoleWrite($s & @CRLF) Next2 points
-
Could RegExp be used here ?
caramen and one other reacted to FrancescoDiMuro for a topic
@pixelsearch @TheXman Sorry for stepping in this thread, but, every single post that @pixelsearch posted was really kind and he never asked for a piece of code. From what I could see, @pixelsearch always tried to help ( and helped "concretely" ) a lot of people, always in a gentle way, without "attacking" or judging someone for asking something. From this post, I see that @pixelsearch is not trying to let others write code for him, but, instead, he just would like to let experts answer to his question: "Could SRE do what my script actually does?". I don't see him asking for any code, or asking for anything else except for ask to his question. And, @TheXman, please, don't feel like I am judging you, since I am no one to say who is who. From a 2 Cent. who a wise person gave us few days ago on here, it would probably be a misunderstanding, since here on the Forum the "feelings" cannot be interpreted, and because everyone write and read text, which is devoid of "feelings". So, please, don't argue for a thing like that. @pixelsearch didn't ask for a piece of code, but for a single question, and that's all the misunderstanding. Have a good day both of you2 points -
In Fast subclassing through compiled code a WM_NOTIFY message handler is implemented in C/C++. Is it possible to implement the entire window procedure (main message handler) in compiled code and thus avoid the overhead associated with the subclassing technique? AutoIt code This is a slightly modified version of _WinAPI_RegisterClassEx example, and a listview is created in the window (ListView0.au3): #include <WinAPIRes.au3> #include <WinAPISys.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> Global $bExit = False Global $iRows = 100, $iCols = 8 Example() Func Example() Local Const $sClass = "MyWindowClass" Local Const $sName = "Ordinary ListView" ; Get module handle for the current process Local $hInstance = _WinAPI_GetModuleHandle( 0 ) ; Create a class cursor Local $hCursor = _WinAPI_LoadCursor( 0, 32512 ) ; IDC_ARROW ; Create a class icons (large and small) Local $tIcons = DllStructCreate( "ptr;ptr" ) _WinAPI_ExtractIconEx( @SystemDir & "\shell32.dll", 130, DllStructGetPtr( $tIcons, 1 ), DllStructGetPtr( $tIcons, 2 ), 1 ) Local $hIcon = DllStructGetData( $tIcons, 1 ) Local $hIconSm = DllStructGetData( $tIcons, 2 ) ; Create DLL callback function (window procedure) Local $pWinProc = DllCallbackGetPtr( DllCallbackRegister( "WinProc", "lresult", "hwnd;uint;wparam;lparam" ) ) ; Create and fill $tagWNDCLASSEX structure Local $tWCEX = DllStructCreate( $tagWNDCLASSEX & ";wchar szClassName[" & ( StringLen( $sClass ) + 1 ) & "]" ) DllStructSetData( $tWCEX, "Size", DllStructGetPtr( $tWCEX, "szClassName" ) - DllStructGetPtr( $tWCEX ) ) DllStructSetData( $tWCEX, "Style", 0 ) DllStructSetData( $tWCEX, "hWndProc", $pWinProc ) DllStructSetData( $tWCEX, "ClsExtra", 0 ) DllStructSetData( $tWCEX, "WndExtra", 0 ) DllStructSetData( $tWCEX, "hInstance", $hInstance ) DllStructSetData( $tWCEX, "hIcon", $hIcon ) DllStructSetData( $tWCEX, "hCursor", $hCursor ) DllStructSetData( $tWCEX, "hBackground", _WinAPI_CreateSolidBrush( _WinAPI_GetSysColor( $COLOR_3DFACE ) ) ) DllStructSetData( $tWCEX, "MenuName", 0 ) DllStructSetData( $tWCEX, "ClassName", DllStructGetPtr( $tWCEX, "szClassName" ) ) DllStructSetData( $tWCEX, "hIconSm", $hIconSm ) DllStructSetData( $tWCEX, "szClassName", $sClass ) ; Register a window class _WinAPI_RegisterClassEx( $tWCEX ) ; Create a window Local $hWnd = _WinAPI_CreateWindowEx( 0, $sClass, $sName, BitOR( $WS_CAPTION, $WS_POPUPWINDOW, $WS_VISIBLE ), ( @DesktopWidth - 826 ) / 2, ( @DesktopHeight - 584 ) / 2, 826, 584, 0 ) ; Create listview Local $hListView = _GUICtrlListView_Create( $hWnd, "", 10, 10, 800, 538, $LVS_DEFAULT-$LVS_SINGLESEL, $WS_EX_CLIENTEDGE ) _GUICtrlListView_SetExtendedListViewStyle( $hListView, $LVS_EX_DOUBLEBUFFER+$LVS_EX_FULLROWSELECT ) ; Add columns For $i = 0 To $iCols - 1 _GUICtrlListView_AddColumn( $hListView, "Col " & $i, 96, 2 ) ; 2 = Centered text Next ; ListView items For $i = 0 To $iRows - 1 _GUICtrlListView_AddItem( $hListView, "Row " & $i ) For $j = 1 To $iCols - 1 _GUICtrlListView_AddSubItem( $hListView, $i, "Col " & $j, $j ) Next Next ; Main loop While Sleep(10) If $bExit Then ExitLoop WEnd ; Unregister window class and release unnecessary resources _WinAPI_UnregisterClass( $sClass, $hInstance ) _WinAPI_DestroyCursor( $hCursor ) _WinAPI_DestroyIcon( $hIcon ) _WinAPI_DestroyIcon( $hIconSm ) EndFunc Func WinProc( $hWnd, $iMsg, $wParam, $lParam ) Switch $iMsg Case $WM_CLOSE $bExit = True EndSwitch Return _WinAPI_DefWindowProcW( $hWnd, $iMsg, $wParam, $lParam ) EndFunc It's left for Windows to handle all listview messages. No new code is added to WinProc() function. In the next example the listview is replaced by a virtual and custom drawn listview. Now it's necessary to handle LVN_GETDISPINFO and NM_CUSTOMDRAW notifications in WinProc() function (ListView1.au3): ; Create listview $hListView = _GUICtrlListView_Create( $hWnd, "", 10, 10, 800, 538, $LVS_DEFAULT+$LVS_OWNERDATA-$LVS_SINGLESEL, $WS_EX_CLIENTEDGE ) _GUICtrlListView_SetExtendedListViewStyle( $hListView, $LVS_EX_DOUBLEBUFFER+$LVS_EX_FULLROWSELECT ) ; Add columns For $i = 0 To $iCols - 1 _GUICtrlListView_AddColumn( $hListView, "Col " & $i, 96, 2 ) ; 2 = Centered text Next ; ListView items For $i = 0 To $iRows - 1 For $j = 0 To $iCols - 1 $aItems[$i][$j] = $i & "/" & $j Next Next ; ListView colors Local $aLVColors = [ 0xCCCCFF, 0xCCFFFF, 0xCCFFCC, 0xFFFFCC, 0xFFCCCC, 0xFFCCFF ] ; BGR For $i = 0 To $iRows - 1 For $j = 0 To $iCols - 1 $aColors[$i][$j] = $aLVColors[Random( 0,5,1 )] Next Next ; Set number of rows in virtual ListView DllCall( "user32.dll", "lresult", "SendMessageW", "hwnd", $hListView, "uint", $LVM_SETITEMCOUNT, "wparam", $iRows, "lparam", 0 ) WinProc() function: Func WinProc( $hWnd, $iMsg, $wParam, $lParam ) Local Static $tText = DllStructCreate( "wchar[100]" ), $pText = DllStructGetPtr( $tText ) Local Static $tRect = DllStructCreate( $tagRECT ), $pRect = DllStructGetPtr( $tRect ) Switch $iMsg Case $WM_NOTIFY Switch DllStructGetData( DllStructCreate( $tagNMHDR, $lParam ), "Code" ) Case $LVN_GETDISPINFOW ; Fill virtual listview Local $tNMLVDISPINFO = DllStructCreate( $tagNMLVDISPINFO, $lParam ) If Not BitAND( DllStructGetData( $tNMLVDISPINFO, "Mask" ), $LVIF_TEXT ) Then Return Local $sItem = $aItems[DllStructGetData($tNMLVDISPINFO,"Item")][DllStructGetData($tNMLVDISPINFO,"SubItem")] DllStructSetData( $tText, 1, $sItem ) DllStructSetData( $tNMLVDISPINFO, "TextMax", StringLen( $sItem ) ) DllStructSetData( $tNMLVDISPINFO, "Text", $pText ) Return Case $NM_CUSTOMDRAW ; Draw back colors Local $tNMLVCUSTOMDRAW = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam ) Local $dwDrawStage = DllStructGetData( $tNMLVCUSTOMDRAW, "dwDrawStage" ), $iItem Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any subitem-related drawing operations Case $CDDS_ITEMPREPAINT + $CDDS_SUBITEM ; Before painting a subitem $iItem = DllStructGetData( $tNMLVCUSTOMDRAW, "dwItemSpec" ) If DllCall( "user32.dll", "lresult", "SendMessageW", "hwnd", $hListView, "uint", $LVM_GETITEMSTATE, "wparam", $iItem, "lparam", $LVIS_SELECTED )[0] Then Return $CDRF_NOTIFYPOSTPAINT ; Selected item DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", $aColors[$iItem][DllStructGetData($tNMLVCUSTOMDRAW,"iSubItem")] ) ; Normal item Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors Case $CDDS_ITEMPOSTPAINT + $CDDS_SUBITEM ; After painting a subitem Local $hDC = DllStructGetData( $tNMLVCUSTOMDRAW, "hdc" ) ; Subitem rectangle $iItem = DllStructGetData( $tNMLVCUSTOMDRAW, "dwItemSpec" ) Local $iSubItem = DllStructGetData( $tNMLVCUSTOMDRAW, "iSubItem" ) DllStructSetData( $tRect, "Left", $LVIR_LABEL ) DllStructSetData( $tRect, "Top", $iSubItem ) DllCall( "user32.dll", "lresult", "SendMessageW", "hwnd", $hListView, "uint", $LVM_GETSUBITEMRECT, "wparam", $iItem, "lparam", $pRect ) DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Left" ) + 2 ) DllStructSetData( $tRect, "Top", DllStructGetData( $tRect, "Top" ) + 1 ) DllStructSetData( $tRect, "Right", DllStructGetData( $tRect, "Right" ) - 2 ) DllStructSetData( $tRect, "Bottom", DllStructGetData( $tRect, "Bottom" ) - 1 ) ; Subitem back color Local $hBrush = DllCall( "gdi32.dll", "handle", "CreateSolidBrush", "int", $aColors[$iItem][$iSubItem] )[0] ; _WinAPI_CreateSolidBrush DllCall( "user32.dll", "int", "FillRect", "handle", $hDC, "struct*", $tRect, "handle", $hBrush ) ; _WinAPI_FillRect DllCall( "gdi32.dll", "bool", "DeleteObject", "handle", $hBrush ) ; _WinAPI_DeleteObject ; Draw subitem text DllStructSetData( $tRect, "Top", DllStructGetData( $tRect, "Top" ) + 1 ) DllCall( "gdi32.dll", "int", "SetTextColor", "handle", $hDC, "int", 0 ) ; _WinAPI_SetTextColor DllCall( "gdi32.dll", "int", "SetBkMode", "handle", $hDC, "int", $TRANSPARENT ) ; _WinAPI_SetBkMode DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $aItems[$iItem][$iSubItem], "int", -1, "struct*", $tRect, "uint", $DT_CENTER ) ; _WinAPI_DrawText Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch Case $WM_CLOSE $bExit = True EndSwitch Return _WinAPI_DefWindowProcW( $hWnd, $iMsg, $wParam, $lParam ) EndFunc Also in this example there is a problem with the speed of the WM_NOTIFY code. You can provoke an error this way: Click a row in the listview (not one of the very top rows). Press Shift+Down arrow to select multiple rows. The problem will arise after just a few rows. Press Ctrl+Break in SciTE to stop the code. Note that since the window isn't created with GUICreate(), it's not possible to use any of the native functions in the GUI Management section of the help file. But all the UDFs in the GUI Reference section can be used. C/C++ code The window procedure above is defined this way: ; Create DLL callback function (window procedure) Local $pWinProc = DllCallbackGetPtr( DllCallbackRegister( "WinProc", "lresult", "hwnd;uint;wparam;lparam" ) ) DllStructSetData( $tWCEX, "hWndProc", $pWinProc ) The C/C++ definition of a window procedure in a dll-file looks like this: LRESULT CALLBACK __stdcall WinProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) We can get a pointer to the window procedure this way: Local $hModule = _WinAPI_LoadLibrary( "WinProc.dll" ) Local $pWinProc = _WinAPI_GetProcAddress( $hModule, "WinProc" ) Now we can use this pointer in $tWCEX struct. We also need to pass $aItems and $aColors arrays to the compiled code in the dll-file. But we already know how to do that. Note that because $pWinProc is used directly in $tWCEX struct, we can avoid both the DllCall and DllCallAddress commands. Thus, we avoid a severe overhead in relation to these commands (that the AutoIt code interpreter should interpret a code line for each message (for a huge number of messages), and that DllCall and DllCallAddress are complicated and time-consuming commands). AutoIt code in ListView2.au3: #include <WinAPIRes.au3> #include <WinAPISys.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include "AccArrays.au3" Global $aData[3] ; $psaItems, $psaColors, $pExit Example() Func Example() Local Const $sClass = "MyWindowClass", $sName = "Virtual and Custom Drawn ListView" Local $iRows = 10000, $iCols = 8, $aItems[$iRows][$iCols], $aColors[$iRows][$iCols] ; Get module handle for the current process Local $hInstance = _WinAPI_GetModuleHandle( 0 ) ; Create a class cursor Local $hCursor = _WinAPI_LoadCursor( 0, 32512 ) ; IDC_ARROW ; Create a class icons (large and small) Local $tIcons = DllStructCreate( "ptr;ptr" ) _WinAPI_ExtractIconEx( @SystemDir & "\shell32.dll", 130, DllStructGetPtr( $tIcons, 1 ), DllStructGetPtr( $tIcons, 2 ), 1 ) Local $hIcon = DllStructGetData( $tIcons, 1 ) Local $hIconSm = DllStructGetData( $tIcons, 2 ) ; Create DLL callback function (window procedure) Local $hModule = _WinAPI_LoadLibrary( @AutoItX64 ? "WinProc_x64.dll" : "WinProc.dll" ) Local $pWinProc = _WinAPI_GetProcAddress( $hModule, "WinProc" ) ; Create and fill $tagWNDCLASSEX structure Local $tWCEX = DllStructCreate( $tagWNDCLASSEX & ";wchar szClassName[" & ( StringLen( $sClass ) + 1 ) & "]" ) DllStructSetData( $tWCEX, "Size", DllStructGetPtr( $tWCEX, "szClassName" ) - DllStructGetPtr( $tWCEX ) ) DllStructSetData( $tWCEX, "Style", 0 ) DllStructSetData( $tWCEX, "hWndProc", $pWinProc ) DllStructSetData( $tWCEX, "ClsExtra", 0 ) DllStructSetData( $tWCEX, "WndExtra", 0 ) DllStructSetData( $tWCEX, "hInstance", $hInstance ) DllStructSetData( $tWCEX, "hIcon", $hIcon ) DllStructSetData( $tWCEX, "hCursor", $hCursor ) DllStructSetData( $tWCEX, "hBackground", _WinAPI_CreateSolidBrush( _WinAPI_GetSysColor( $COLOR_3DFACE ) ) ) DllStructSetData( $tWCEX, "MenuName", 0 ) DllStructSetData( $tWCEX, "ClassName", DllStructGetPtr( $tWCEX, "szClassName" ) ) DllStructSetData( $tWCEX, "hIconSm", $hIconSm ) DllStructSetData( $tWCEX, "szClassName", $sClass ) ; Register a window class _WinAPI_RegisterClassEx( $tWCEX ) ; Create a window Local $hWnd = _WinAPI_CreateWindowEx( 0, $sClass, $sName, BitOR( $WS_CAPTION, $WS_POPUPWINDOW, $WS_VISIBLE ), ( @DesktopWidth - 826 ) / 2, ( @DesktopHeight - 584 ) / 2, 826, 584, 0 ) ; Create listview Local $hListView = _GUICtrlListView_Create( $hWnd, "", 10, 10, 800, 538, $LVS_DEFAULT+$LVS_OWNERDATA-$LVS_SINGLESEL, $WS_EX_CLIENTEDGE ) _GUICtrlListView_SetExtendedListViewStyle( $hListView, $LVS_EX_DOUBLEBUFFER+$LVS_EX_FULLROWSELECT ) ; Add columns For $i = 0 To $iCols - 1 _GUICtrlListView_AddColumn( $hListView, "Col " & $i, 96, 2 ) ; 2 = Centered text Next ; ListView items For $i = 0 To $iRows - 1 For $j = 0 To $iCols - 1 $aItems[$i][$j] = $i & "/" & $j Next Next ; ListView colors Local $aLVColors = [ 0xCCCCFF, 0xCCFFFF, 0xCCFFCC, 0xFFFFCC, 0xFFCCCC, 0xFFCCFF ] ; BGR For $i = 0 To $iRows - 1 For $j = 0 To $iCols - 1 $aColors[$i][$j] = $aLVColors[Random( 0,5,1 )] Next Next ; Load dll-file Local $hDll = DllOpen( @AutoItX64 ? "WinProc_x64.dll" : "WinProc.dll" ) ; $aItems, $aColors and $bExit Local $psaItemsData, $psaColorsData, $bExit = False $aData[2] = DllStructGetPtr( DllStructCreate( $tagVARIANT ) ) AccArrays03( Copy, $aItems, $aColors, $bExit ) SafeArrayAccessData( $aData[0], $psaItemsData ) SafeArrayAccessData( $aData[1], $psaColorsData ) ; Pass data to compiled code DllCall( $hDll, "none", "PassData", "hwnd", $hListView, "int", $iCols, "ptr", $psaItemsData, "ptr", $psaColorsData, "ptr", $aData[2] ) ; Set number of rows in virtual ListView DllCall( "user32.dll", "lresult", "SendMessageW", "hwnd", $hListView, "uint", $LVM_SETITEMCOUNT, "wparam", $iRows, "lparam", 0 ) ; Main loop While Sleep(10) If DllStructGetData( DllStructCreate( "short", $aData[2] + 8 ), 1 ) Then ExitLoop WEnd ; Unregister window class and release unnecessary resources _WinAPI_UnregisterClass( $sClass, $hInstance ) _WinAPI_DestroyCursor( $hCursor ) _WinAPI_DestroyIcon( $hIcon ) _WinAPI_DestroyIcon( $hIconSm ) SafeArrayUnaccessData( $aData[0] ) SafeArrayUnaccessData( $aData[1] ) _WinAPI_FreeLibrary( $hModule ) DllClose( $hDLL ) EndFunc ; Copy internal AutoIt variants (variables) to real Windows ; variants, that can be accessed from both AutoIt and C/C++. Func Copy( $pvItems, $pvColors, $pvExit ) SafeArrayCopy( DllStructGetData( DllStructCreate( "ptr", $pvItems + 8 ), 1 ), $aData[0] ) SafeArrayCopy( DllStructGetData( DllStructCreate( "ptr", $pvColors + 8 ), 1 ), $aData[1] ) VariantCopy( $aData[2], $pvExit ) EndFunc C/C++ code: #include <Windows.h> #include <CommCtrl.h> #include <OleAuto.h> // Globals HWND g_hListView; int g_iColumns; VARIANT* g_psaItems; VARIANT* g_psaColors; VARIANT* g_pExit; void __stdcall PassData( HWND hListView, int iColumns, VARIANT* psaItems, VARIANT* psaColors, VARIANT* pExit ) { g_hListView = hListView; g_iColumns = iColumns; g_psaItems = psaItems; g_psaColors = psaColors; g_pExit = pExit; } LRESULT CALLBACK __stdcall WinProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { NMLVDISPINFOW* plvdi; NMLVCUSTOMDRAW* plvcd; BSTR pBstr; DWORD_PTR iItem; RECT r; HBRUSH hBrush; switch ( uMsg ) { case WM_NOTIFY: switch ( ((LPNMHDR)lParam)->code ) { case LVN_GETDISPINFOW: // Fill virtual listview plvdi = (NMLVDISPINFOW*)lParam; if ( ( plvdi->item.mask & LVIF_TEXT ) == 0 ) return TRUE; pBstr = g_psaItems[plvdi->item.iItem*g_iColumns+plvdi->item.iSubItem].bstrVal; plvdi->item.pszText = pBstr; plvdi->item.cchTextMax = SysStringLen( pBstr ); return TRUE; case NM_CUSTOMDRAW: // Draw back colors plvcd = (NMLVCUSTOMDRAW*)lParam; switch ( plvcd->nmcd.dwDrawStage ) { case CDDS_PREPAINT: return CDRF_NOTIFYITEMDRAW; case CDDS_ITEMPREPAINT: return CDRF_NOTIFYSUBITEMDRAW; case CDDS_ITEMPREPAINT | CDDS_SUBITEM: iItem = plvcd->nmcd.dwItemSpec; if ( SendMessageW( g_hListView, LVM_GETITEMSTATE, iItem, LVIS_SELECTED ) ) return CDRF_NOTIFYPOSTPAINT; plvcd->clrTextBk = g_psaColors[iItem*g_iColumns+plvcd->iSubItem].intVal; return CDRF_NEWFONT; case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM: // Subitem rectangle iItem = plvcd->nmcd.dwItemSpec; r.left = LVIR_LABEL; r.top = plvcd->iSubItem; SendMessageW( g_hListView, LVM_GETSUBITEMRECT, iItem, (LPARAM)&r ); r.left += 2; r.right -= 2; r.top += 1; r.bottom -= 1; // Subitem back color hBrush = CreateSolidBrush( g_psaColors[iItem*g_iColumns+plvcd->iSubItem].intVal ); FillRect( plvcd->nmcd.hdc, &r, hBrush ); DeleteObject( hBrush ); // Draw subitem text SetTextColor( plvcd->nmcd.hdc, 0 ); SetBkMode( plvcd->nmcd.hdc, TRANSPARENT ); pBstr = g_psaItems[iItem*g_iColumns+plvcd->iSubItem].bstrVal; r.top += 1; DrawTextW( plvcd->nmcd.hdc, pBstr, SysStringLen( pBstr ), &r, DT_CENTER ); return CDRF_NEWFONT; } default: return DefWindowProcW( hWnd, uMsg, wParam, lParam ); } case WM_CLOSE: g_pExit->boolVal = 1; default: return DefWindowProcW( hWnd, uMsg, wParam, lParam ); } return 0; } Zip-file ListView0.au3 and ListView1.au3 is pure AutoIt code. In ListView2.au3 the window procedure is replaced with compiled code. Note that the zip-file contains two small dll-files. If you are using Microsoft SmartScreen or Microsoft Windows Defender, there is a likelihood of fake virus detection, even if the dll-files are created with Microsoft Visual Studio. Most other antivirus products will not detect fake viruses. 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. WinProc.7z1 point
-
Have you tried using _WinAPI_CloseHandle to close the handle to the file after you've created it?1 point
-
Sleep function optimization
FrancescoDiMuro reacted to Jos for a topic
So you basically are asking to optimise something you do not know whether it needs any optimization.... curious to say the least!1 point -
So you mean there are really people reading it?1 point
-
[SOLVED] Radio Button long text
WilliamasKumeliukas reacted to Melba23 for a topic
WilliamasKumeliukas, Limiting the size of the GUI was something I was going to suggest - so good for you! I do indeed understand the question - but I would counsel against increasing the size of the GUI just to fit long unbroken text strings. Best to make sure you do not have any in the text you wish to display! If you insist on resizing the GUI when text does not fit, then you are going to have to increase the size of the GUI and then rerun the text sizing code to see if the control is now large enough to display the text. It all sounds horribly recursive and, quite frankly, I am not prepared to continue helping if you do decide to go this way. If you are prepared to arbitrarily change the GUI size for the user when the text does not fit, why not go for a non-resizeable GUI to begin with? That way you can test the various strings to display before you release them and the user will not have a problem. M231 point -
How to automate button click in a GUI?
FrancescoDiMuro reacted to Earthshine for a topic
only option it to try IUIAutomation. let me try it. it is not made with windows controls. IUIAutomation works, this clicks the Wizard button, then clicks it. Works! I used the portable Dolomites, and it correctly highlights everything it's looking for, in pretty good time too. do I win a badge? lol ;~ *** Standard code maintainable *** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) _UIA_setVar("oP1","Title:=Dolomites;controltype:=UIA_WindowControlTypeId;class:=Qt5QWindowIcon") ;Dolomites _UIA_setVar("oP2","Title:=;controltype:=UIA_CustomControlTypeId;class:=") ; _UIA_setVar("oP3","Title:=;controltype:=UIA_SplitButtonControlTypeId;class:=") ; _UIA_setVar("oP4","Title:=;controltype:=UIA_CustomControlTypeId;class:=") ; _UIA_setVar("oP5","Title:=;controltype:=UIA_CustomControlTypeId;class:=") ; _UIA_setVar("oP6","Title:=;controltype:=UIA_SplitButtonControlTypeId;class:=") ; _UIA_setVar("oP7","Title:=;controltype:=UIA_SplitButtonControlTypeId;class:=") ; _UIA_setVar("oP8","Title:=;controltype:=UIA_CustomControlTypeId;class:=") ; ;~ $oUIElement=_UIA_getObjectByFindAll("Wizard....mainwindow", "title:=Wizard...;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree) _UIA_setVar("oUIElement","Title:=Wizard...;controltype:=UIA_ButtonControlTypeId;class:=") ;ControlType:=UIA_ButtonControlTypeId;classname:=") ;~ Actions split away from logical/technical definition above can come from configfiles ;~_UIA_Action("oP1","highlight") _UIA_Action("oP1","setfocus") ;~_UIA_Action("oP2","highlight") _UIA_Action("oP2","setfocus") ;~_UIA_Action("oP3","highlight") _UIA_Action("oP3","setfocus") ;~_UIA_Action("oP4","highlight") _UIA_Action("oP4","setfocus") ;~_UIA_Action("oP5","highlight") _UIA_Action("oP5","setfocus") ;~_UIA_Action("oP6","highlight") _UIA_Action("oP6","setfocus") ;~_UIA_Action("oP7","highlight") _UIA_Action("oP7","setfocus") ;~_UIA_Action("oP8","highlight") _UIA_Action("oP8","setfocus") _UIA_action("oUIElement","highlight") _UIA_action("oUIElement","click")1 point -
oemript, There should be no interaction between the 2 loops unless you code it to happen - errors within the "inner" function will not be transmitted to the "outer" code unless you use Return SetError as I mentioned above. I am afraid I cannot be more specific without more details. M231 point
-
Here's another way it can be done: #include <Array.au3> #include <Constants.au3> example() Func example() Local $aData = [ _ "http://autoitscript.com/blabla1/", _ "http://autoitscript.com/blabla2/blabla/", _ "http://autoitscript.com/bla-bla-bla3/", _ "http://autoitscript.com", _ "http://autoitscript.com/" _ ] Local $sData = _ArrayToString($aData, @CRLF) Local $aResult = StringRegExp($sData, "https?://[^/]+/([^/]+)", $STR_REGEXPARRAYGLOBALMATCH) If IsArray($aResult) Then _ArrayDisplay($aResult) EndFunc1 point
-
[SOLVED] Radio Button long text
WilliamasKumeliukas reacted to Melba23 for a topic
WilliamasKumeliukas, That is because one of the strings to display includes "_GetFontSize($sText," which has no spaces - and so will not be broken by the StringSize UDF. I have added some errorchecking to the various functions - if the text will not fit with the smallest usable font size (8pt) the script now tells the user that the GUI is too small: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <ButtonConstants.au3> #include "StringSize.au3" Opt("GUIResizeMode", $GUI_DOCKAUTO) Global $q1 = "Welcome, I am glad you're willing to help me so I hope" & @CRLF & "everytime this GUI is resized while in qloop function, the script is crashing with following error: " & @CRLF & @CRLF & _ '"C:\Users\wk\Desktop\williamas kumeliukas\test quiz example.au3" (213) : ==> Subscript used on non-accessible variable.:' & @CRLF & @CRLF & _ "If $aRect[3] <= $aPos[3] Then" & @CRLF & @CRLF & _ "If $aRect^ ERROR" Global $_width = @DesktopWidth / 1.20 Global $_height = @DesktopHeight / 1.30 #Region Var Global $iGuiWidth = $_width, $iGuiHeight = $_height, $iGuiXPos = (@DesktopWidth / 2) - $iGuiWidth / 2, $iGuiYpos = (@DesktopHeight / 2) - $iGuiHeight / 2 Global $file = @ScriptDir & "\1.txt" Global $msg, $iIndex = 0, $qf, $gui ; Redefine the $iIndex variable to be the current index value within the file <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Global $GUI_InitWidth = 800, $GUI_InitHeight = 600 #EndRegion Var Main() Func Main() #Region GUI Global $gui = GUICreate("Example", $GUI_InitWidth, $GUI_InitHeight, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX)) Global $info = GUICtrlCreateLabel($q1, 110, 10, 560, 180, BitOR($WS_BORDER, $SS_CENTER)) Global $a = GUICtrlCreateRadio("A)", 20, 200, 320, 150, BitOR($BS_MULTILINE, $BS_TOP, $WS_EX_TOPMOST)) Global $b = GUICtrlCreateRadio("B)", 20, 360, 320, 150, BitOR($BS_MULTILINE, $BS_TOP, $WS_EX_TOPMOST)) Global $c = GUICtrlCreateRadio("C)", 460, 200, 330, 150, BitOR($BS_MULTILINE, $BS_TOP, $WS_EX_TOPMOST)) Global $d = GUICtrlCreateRadio("D)", 460, 360, 330, 150, BitOR($BS_MULTILINE, $BS_TOP, $WS_EX_TOPMOST)) Global $start = GUICtrlCreateButton("Start", 340, 450, 120, 30, $WS_EX_TOPMOST) Global $valid = GUICtrlCreateButton("Confirm", 340, 470, 120, 30, $WS_EX_TOPMOST) GUICtrlSetState($valid, 32) GUISetState(@SW_SHOW) #EndRegion GUI If $iGuiHeight < $GUI_InitHeight Then Global $calc = Int($GUI_InitHeight - $iGuiHeight) $iGuiHeight = $GUI_InitHeight WinMove($gui, "", $iGuiXPos, $iGuiYpos - $calc - 5, $iGuiWidth, $iGuiHeight) Else WinMove($gui, "", $iGuiXPos, $iGuiYpos, $iGuiWidth, $iGuiHeight) EndIf $aPos = ControlGetPos($gui, "", $info) $sText = $q1 $sFormattedText = _GetFontSize($q1, $aPos) GUICtrlSetFont($info, @extended) GUICtrlSetData($info, $sFormattedText) adjustfont($iIndex) ; This time the function gets 0 as an index so it knows it is the start point <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE, $GUI_EVENT_RESIZED adjustfont($iIndex) ; Here the function gets the current index <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Case $start Global $qf = StringSplit(StringStripWS(FileRead($file), 6), @CRLF, 0) GUICtrlSetState($start, 32) qloop($file) EndSwitch WEnd EndFunc ;==>Main Func _GetFontSize($sText, $aPos) For $iSize = 24 To 8 Step -1 ; 8pt is probably the lowest you want to go Local $aRect = _StringSize($sText, $iSize, Default, Default, Default, $aPos[2] - 25) ; Save @ & @extendederror $iError = @error $iExtended = @extended Switch $iError ; Do nothing Case 0 ; If single word in text too large to fit in the rectangle - continue to reduce size Case 3 ContinueLoop ; Any other error is likely to be fatal so set return error flag Case Else Return SetError($iError, 0, "") EndSwitch ; Check if text fits If $aRect[3] <= $aPos[3] Then ; Return font size ExitLoop EndIf Next ; If even smallest font size will not fit If $iError = 3 Then Return SetError(1, 0, "") EndIf Return SetError(0, $iSize, $aRect[0]) EndFunc ;==>_GetFontSize Func qloop($file) For $i = 1 To $qf[0] Step 8 $iIndex = $i ; Set the Global variable to the current index <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< adjustfont($iIndex) ; And use it here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Do Switch GUIGetMsg() Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE, $GUI_EVENT_RESIZED adjustfont($iIndex) ; and here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Case $GUI_EVENT_CLOSE Exit Case $valid $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit EndIf EndSwitch If $msg = -3 Then Exit Until 0 Next EndFunc ;==>qloop Func adjustfont($iIndex) If $iIndex = 0 Then ; It is the initial run <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $aPos = ControlGetPos($gui, "", $info) $sText = $q1 $sFormattedText = _GetFontSize($sText, $aPos) ; If error then <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If @error Then ; Tell user $sFormattedText = "GUI too small" Else GUICtrlSetFont($info, @extended) EndIf GUICtrlSetData($info, $sFormattedText) Else ; There is a valid index to use <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $aPos = ControlGetPos($gui, "", $info) $sText = $qf[$iIndex] $sFormattedText = _GetFontSize($sText, $aPos) If @error = 1 Then $sFormattedText = "GUI too small" Else GUICtrlSetFont($info, @extended) EndIf GUICtrlSetData($info, $sFormattedText) $aPos = ControlGetPos($gui, "", $a) $sText = $qf[$iIndex + 1] $sFormattedText = _GetFontSize($sText, $aPos) If @error = 1 Then $sFormattedText = "GUI too small" Else GUICtrlSetFont($a, @extended) EndIf GUICtrlSetData($a, $sFormattedText) $sText = $qf[$iIndex + 2] $sFormattedText = _GetFontSize($sText, $aPos) If @error = 1 Then $sFormattedText = "GUI too small" Else GUICtrlSetFont($b, @extended) EndIf GUICtrlSetData($b, $sFormattedText) $sText = $qf[$iIndex + 3] $sFormattedText = _GetFontSize($sText, $aPos) If @extended = 0 Then $sFormattedText = "GUI too small" Else GUICtrlSetFont($c, @extended) EndIf GUICtrlSetData($c, $sFormattedText) $sText = $qf[$iIndex + 4] $sFormattedText = _GetFontSize($sText, $aPos) If @error = 1 Then $sFormattedText = "GUI too small" Else GUICtrlSetFont($d, @extended) EndIf GUICtrlSetData($d, $sFormattedText) EndIf EndFunc ;==>adjustfont M231 point -
1 point
-
Your expression is too complex, think simple, try this : https://regex101.com/r/WjCbT1/21 point
-
;~ $str = 'http://autoitscript.com/blabla1/' $str = 'http://autoitscript.com/blabla2/blabla/' ;~ $str = 'http://autoitscript.com/bla-bla-bla3/' msgbox(0 , '' , stringsplit($str , "/" , 2)[3])1 point
-
Look i got an avatar that no one have :0.1 point
-
@youtuber Ironically the first character after the first slash in your example URLs is a slash itself... (https://)1 point
-
Could RegExp be used here ?
pixelsearch reacted to mikell for a topic
Yes you can For example, there is a common way to do that using a character class : [^"]+? which means : "one or more non-quote characters, lazy" So the expression looks like this : #include <Array.au3> $url = "https://www.autoitscript.com/site/autoit-script-editor/" $s = BinaryToString(InetRead($url)) $a = StringRegExp($s, '(?i)(?:https|/autoit3)[^"]+?\.png', 3) $a = _ArrayUnique($a) _ArrayDisplay($a) But there are many ways to skin this cat1 point -
I loaded one of the found examples with this UDF and added this to use the Error lexer: SendMessage($Sci, $SCI_SETLEXER, $SCLEX_ERRORLIST, 0) I believe that is working but have not looked any further, so please share some sort of runnable script that you want to work on that I can play with and modify as required. Jos1 point
-
How to automate button click in a GUI?
Xandy reacted to FrancescoDiMuro for a topic
Hi @Iulia_Vascan, and welcome to the AutoIt Forums First of all, when you call your Control* functions, you don't have to write the square brackets, because the only mean that they are optional parameters. Then, you have to see the Control tab in the AutoItWindowsInfoTool instead of Mouse tab; from there, you can see the Control class, ID, and so on, which you can use in your Control* functions. So, run once again the AutoItWindowInfoTool and look at the Control button, in which there are all the information needed to use ControlClick() function Once you have finished, post again your code, replacing all the information you got1 point -
I did not have the chance to thank you. This solved the issue!1 point
-
Could RegExp be used here ?
FrancescoDiMuro reacted to pixelsearch for a topic
@FrancescoDiMuro : it's like you're reading my mind, that's a bit scaring Because my one and only thought, when opening the thread, was exactly what you wrote, let me please quote you : And many thanks for your appreciations concerning my posts, it means a lot. @Marc : you did it ! I was just curious to know if it was possible, because it seems so complicated, an endless text file with so many double quotes in it. It was like some kind of challenge sent to the RegExp community and you solved it so easily, bravo. Have a great day both of you1 point -
Could RegExp be used here ?
pixelsearch reacted to Marc for a topic
The answer is "yes" As an example: #include <Array.au3> #include <File.au3> $sFileInput = FileRead(@ScriptDir & "\default.htm") $aHits = StringRegExp($sFileInput, '(?is)"([^"]*?\.png)"', 3) _ArrayDisplay($aHits) In theory, the Regex $aHits = StringRegExp($sFileInput, '(?is)"(.*?\.png)"', 3) should do the same thing (in my eyes) but it captures the "og:image" tags, too. Best regards, Marc1 point -
Will that fix searching for a single row in general? 1x5 for example. Honestly I never even thought of that or a single vertical row. All three I think would fail with my code because im looking for 4 corners as a pre-check1 point
-
Help me to continue my autoit script
Xandy reacted to JLogan3o13 for a topic
_Word_DocSaveAs ( $oDoc [, $sFileName = Default [, $iFileFormat = $WdFormatDocument [, $bReadOnlyRecommended = False [, $bAddToRecentFiles = True [, $sPassword = "" [, $sWritePassword = ""]]]]]] ) Is not how it is shown in the example in the help file: _Word_DocSaveAs($oDoc, @TempDir & "\_Word_Test2.doc") You need to think through what you are trying to do here: ;From you script above ; Script Start - Add your code below here $input = InputBox ("filnamn", "Vad ska dokumentet heta?") $FILNAMN = $input #include <MsgBoxConstants.au3> #include <Word.au3> Local $oWord = _Word_Create() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocAdd Example", _ "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; Add a new empty document _Word_DocAdd($oWord) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocAdd Example", "Error creating a new Word document." _ & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocAdd Example", "A new empty document has successfully been added.") #include <Word.au3> _Word_DocSaveAs ( $oDoc [, $sFileName = Default [, $iFileFormat = $WdFormatDocument [, $bReadOnlyRecommended = False [, $bAddToRecentFiles = True [, $sPassword = "" [, $sWritePassword = ""]]]]]] ) Line 14: _Word_DocAdd($oWord) - You don't specify a Variable for this, so how can you reference it later???? Line 18: #include <Word.au3> - You already included this at the top of your script, why are you doing it again??? Line 19: _Word_DocSaveAs ( $oDoc [, $sFileName = Default [, $iFileFormat = $WdFormatDocument [, $bReadOnlyRecommended = False [, $bAddToRecentFiles = True [, $sPassword = "" [, $sWritePassword = ""]]]]]] ) You do not specify a $oDoc variable in your script, so no big surprise why _Word_DocSaveAs is failing. You don't specify a filename, so _Word_DocSaveAs doesn't know where to save it, even if you DID have a variable to reference. If you aren't changing the $iFileFormat, $bReadOnlyRecommended, $bAddToRecentFiles, $sPassword, or $sWritePassword variables, which I would suggest you do not until you figure out the basics, just omit them. As was mentioned, remove the brackets So, your line 19 should really look exactly like what the example script shows, you just need to set your _Word_DocAdd to a variable. We know you want to get your first script done, but you need to slow down and actually read the help file rather than just copying and pasting a bunch of lines you do not understand and then posting when it doesn't work.1 point -
NOTE: TOPIC HAS BEEN MERGED TO HERE: MapIt Quest Special thanks: AdmiralAlkex, Melba23, MrCrearoR, Dragon Warrior 3, SDL MapIt is a tile world editor. MapIt was built around the concept of reversing Dragon Warrior map images. MapIt can take image input and produce a tile and world array. Changing and replacing tile / world data is easy. B/c tile world editor. CTRL+R in image above to signal replace tile action and I use "G" to Get the tile under mouse. A full list of hotkeys can be assigned in the: Help Menu\Hotkeys MapParser is a C++ project that scans images for unique tiles. MapIt can be downloaded without MapParser. MapParser can be toggled off in the Scan_Image dialog. Without MapParser, MapIt will use the Scan_Tiles() function written in AutoIt ; which is 100 * slower Idk. If MapParser.exe will not run for you: Installing Visual C++ Redistributable for Visual Studio 2015 should fix it: https://www.microsoft.com/en-us/download/details.aspx?id=48145 You can start with example world and tiles. Example world was made following these steps: Started with a tile map image of DragonWarrior3 town of: Reeve From MapIt World Menu \ New \ Scan_Image dialog, I set the area to exclude the key legend to the far right of image. After scanning the map image to world and tile array. I removed a few of the map artifacts. More work could be done on this world; removing unwanted tiles, but it is fine for now. I saved my world to disk. This creates folder: Worldname: Containing folder of Tiles and a Worldname.txt. Using The Gimp, I edited some tiles to have a transparent color: Stairs, Trees, Desk Tables, Chest-of-drawers, Chairs, Signs, Doors, Beds. I changed the world layers to 2: World Menu \ Properties. F9 Finds all selected tile on current layer and changes to a new selected tile on new layer. I used F9 to change all Trees on layer: 0 to Trees on layer: 1. Then I used F9 to change all Trees on layer: 0 to Grass on layer: 0 In this video you can see how I used the Tile Menu \ Replace From Disk option to remap tile images to my custom tiles. Conveniently my tiles already have a transparent pixel. See video for how that was done: To use the example world: First unzip the world save file: http://songersoft.com/programming/mapit/worlds/Reeve_Swapped.zip From the World Menu: choose \Load Navigate to the Reeve_Swapped.txt located in the extracted zip. Or you can scan any image. The map images I used are here: http://www.realmofdarkness.net/dq/games/nes/dw3/maps/world For download, videos, and example of created world file data; please visit the MapIt webpage: http://songersoft.com/programming/mapit/mapit_about.phtml1 point
-
I improved the function written by funkey by expanding the range of accented charachters it can replace. $stest = "á|â|à|å|ä ð|é|ê|è|ë í|î|ì|ï ó|ô|ò|ø|õ|ö ú|û|ù|ü æ ç ß abc ABC 123" $stest = _StringReplaceAccend($stest) ConsoleWrite(@LF & @LF & "+>" & $stest & @LF & @LF) Func _StringReplaceAccend($sString) Local $exp, $rep Local $pattern[27][2] = [ _ ["[ÀÁÂÃÅÆ]", "A"],["[àáâãå]", "a"],["Ä", "Ae"],["[æä]", "ae"], _ ["Þ", "B"],["þ", "b"], _ ["Ç", "C"],["ç", "c"], _ ["[ÈÉÊË]", "E"],["[èéêë]", "e"], _ ["[ÌÍÎÏ]", "I"],["[ìíîï]", "i"], _ ["Ñ", "N"],["ñ", "n"], _ ["[ÒÓÔÕÖØ]", "O"],["[ðòóôõöø]", "o"], _ ["[Š]", "S"],["[š]", "s"], _ ["ß", "Ss"], _ ["[ÙÚÛ]", "U"],["[ùúû]", "u"],["Ü", "Ue"],["ü", "ue"], _ ["Ý", "Y"],["[ýýÿ]", "y"], _ ["Ž", "Z"],["ž", "z"]] For $i = 0 To (UBound($pattern) - 1) $exp = $pattern[$i][0] If $exp = "" Then ContinueLoop $rep = $pattern[$i][1] $sString = StringRegExpReplace($sString, $exp, $rep) If @error == 0 And @extended > 0 Then ConsoleWrite($sString & @LF & "--> " & $exp & @LF) EndIf Next Return $sString EndFunc ;==>_StringReplaceAccend1 point
-
I have converted THIS example to autoit, hope it helps someone. It is an example to color lines based on first character of the line (like the console in Scite): #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <_SciLexer.au3> Opt("GUIOnEventMode", 1) ;Create some constants for styling: Global $SCE_STYLE_BLACK = 10 Global $SCE_STYLE_ORANGE = 11 Global $SCE_STYLE_PURPLE = 12 Global $SCE_STYLE_BLUE = 13 Global $SCE_STYLE_DIFBGCOLOR = 14 ;Colors (Scilexer uses BGR colors): Global $black = 0x000000 Global $white = 0xFFFFFF Global $blue = 0xFF0000 Global $purple = 0x94005E Global $orange = 0x00A8FF ;Create a Gui: Global $GUI = GUICreate("Test coloring lines of text", 600, 600) Global $SCI = Sci_CreateEditor($GUI, 0, 0, 600, 400) Global $INPUT = GUICtrlCreateInput("", 0, 420, 600, 170) GUICtrlSetState($INPUT, $GUI_FOCUS) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit", $GUI) $DUMMYSEND = GUICtrlCreateDummy() GUICtrlSetOnEvent($DUMMYSEND, "_Send") Global $AccelKeys[1][2] = [["{ENTER}", $DUMMYSEND]] GUISetAccelerators($AccelKeys) GUISetState() ;Register MY_WM_NOTIFY because WM_NOTIFY is already registered in _SciLexer.au3 GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY") ;Set Lexer Type: SendMessage($SCI, $SCI_SETLEXER, $SCLEX_CONTAINER, 0) ;Set the default colors and such: SendMessage($SCI, $SCI_STYLESETFORE, $STYLE_DEFAULT, $black) ;Default FG color SendMessage($SCI, $SCI_STYLESETBACK, $STYLE_DEFAULT, $white) ;Default BG color SendMessage($SCI, $SCI_STYLECLEARALL, 0, 0) ;Reset the styles to the default ;Set the colors for our styling types: (here we only define what will be different from the default style) SendMessage($SCI, $SCI_STYLESETFORE, $SCE_STYLE_BLACK, $black) SendMessage($SCI, $SCI_STYLESETFORE, $SCE_STYLE_ORANGE, $orange) SendMessage($SCI, $SCI_STYLESETFORE, $SCE_STYLE_PURPLE, $purple) SendMessage($SCI, $SCI_STYLESETFORE, $SCE_STYLE_BLUE, $blue) ;create one more style which have a different bg color, simple as this: SendMessage($SCI, $SCI_STYLESETFORE, $SCE_STYLE_DIFBGCOLOR, $white) SendMessage($SCI, $SCI_STYLESETBACK, $SCE_STYLE_DIFBGCOLOR, $blue) ;append some lines which should be colored according to first character: SciAppendText($SCI, "/ Purple line because begins with /" & @CRLF) SciAppendText($SCI, "* Purple line because begins with *" & @CRLF) SciAppendText($SCI, "- orange line because begins with -" & @CRLF) SciAppendText($SCI, "black line, uses $SCE_STYLE_BLACK style because not using any defined characters" & @CRLF) SciAppendText($SCI, "+ this line uses the style $SCE_STYLE_DIFBGCOLOR because begins with +" & @CRLF & @CRLF) SciAppendText($SCI, "- try to type some other lines" & @CRLF) SciAppendText($SCI, "- and press [ENTER] to send them." & @CRLF) While 1 Sleep(250) WEnd Func _Exit() Exit EndFunc ;==>_Exit Func _Send() SciAppendText($SCI, GUICtrlRead($INPUT) & @CRLF) GUICtrlSetData($INPUT, "") EndFunc ;==>_Send Func MY_WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam) Local $tagNMHDR = DllStructCreate("int;int;int;int;int;int;int;ptr;int;int;int;int;int;int;int;int;int;int;int", $lParam) $hWndFrom = DllStructGetData($tagNMHDR, 1) $IdFrom = DllStructGetData($tagNMHDR, 2) $Event = DllStructGetData($tagNMHDR, 3) Switch $hWndFrom Case $SCI Switch $Event Case $SCN_STYLENEEDED Local $line_number = SendMessage($SCI, $SCI_LINEFROMPOSITION, SendMessage($SCI, $SCI_GETENDSTYLED, 0, 0), 0) Local $start_pos = SendMessage($SCI, $SCI_POSITIONFROMLINE, $line_number, 0) Local $line_length = SendMessage($SCI, $SCI_LINELENGTH, $line_number, 0) If ($line_length > 0) Then Local $first_char = SendMessage($SCI, $SCI_GETCHARAT, $start_pos, 0) ;The SCI_STARTSTYLING here is important SendMessage($SCI, $SCI_STARTSTYLING, $start_pos, 0x1f) ;Set the colouring based on the first character: Switch Chr($first_char) Case "-" SendMessage($SCI, $SCI_SETSTYLING, $line_length, $SCE_STYLE_ORANGE) Case "/" SendMessage($SCI, $SCI_SETSTYLING, $line_length, $SCE_STYLE_PURPLE) Case "*" SendMessage($SCI, $SCI_SETSTYLING, $line_length, $SCE_STYLE_BLUE) Case "+" SendMessage($SCI, $SCI_SETSTYLING, $line_length, $SCE_STYLE_DIFBGCOLOR) Case Else SendMessage($SCI, $SCI_SETSTYLING, $line_length, $SCE_STYLE_BLACK) EndSwitch EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>MY_WM_NOTIFY Func SciAppendText($hwnd, $text) SendMessageString($hwnd, $SCI_APPENDTEXT, StringLen($text), $text) ;Append the Text Local $iLen = Sci_GetLenght($hwnd) SendMessage($hwnd, $SCI_SETANCHOR, $iLen, 0) ;set caret position SendMessage($hwnd, $SCI_SETCURRENTPOS, $iLen, 0) ;set caret position SendMessage($hwnd, $SCI_SCROLLCARET, 0, 0) ;make caret visible EndFunc ;==>SciAppendText Ps: also , if someone can help me with the previous post, I would be very grateful1 point
-
$sResult = _StringReplaceAccend("áéíóúãõâêîôû") ConsoleWrite($sResult & @CRLF) Func _StringReplaceAccend($sString) Local $Pattern[5][2] = [["[áãâ]", "a"], ["[éê]", "e"], ["[íî]", "i"], ["[óõô]", "o"], ["[úû]", "u"]] For $i = 0 To 4 $sString = StringRegExpReplace($sString, $Pattern[$i][0], $Pattern[$i][1]) Next Return $sString EndFunc1 point