Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/02/2021 in all areas

  1. Latest update just released. See below for change log. Note: Changes to _WD_WaitElement may break your script so plan accordingly 😉 Edit: @mLipok pointed out an issue with _WD_SetElementValue where I left a reference to $iMethod. This has been changed on Github to the corrrect variable ($iStyle), and this correction will be included in the next release.
    3 points
  2. UDF versionsThe last section planned in this example about virtual treeviews is UDF versions of the code. The functional requirements in the example were in order of priority: An external data source needed to implement a virtual treeview Virtual treeviews to speed up the creation of large treeviews Multi-line treeview items to avoid overly long text lines Other visual functionality supported by virtual treeviews An external data source is fundamental to any virtual control. First post is about creating a virtual treeview based on an external data source. Because the Microsoft documentation on virtual treeviews is very brief, the easiest approach is to start with a conventional treeview, then reduced and optimized code where the TVITEM structures are filled in directly, a semi-virtual treeview where only the item texts are virtual but not the tree structure itself, and finally a true virtual treeview where also the tree structure is virtual except for root items. The second post is about multi-line treeview items that are supported by all treeviews through the iIntegral field in the TVITEM structure and custom draw code. In the post just above, it's demonstrated that multi-line items are also useful in conventional treeviews. Other visual functionality that can be implemented in a true virtual treeview is limited to what can be handled through default drawing code, TVN_GETDISPINFO notifications and custom draw code. Fourth post about Item images shows that images are supported by default drawing code when the index in the image list is set through TVN_GETDISPINFO notifications. Checkboxes are fully supported by default drawing code. However, for multi-line items, the rectangle containing all lines must be shifted to the right to make room for images and checkboxes. In Custom drawn TreeViews, it's demonstrated how to set text and background color as well as font properties through custom draw code. This example is also valid for virtual treeviews. Features in a UDFThe features that will be implemented in a UDF will be limited to treeviews created solely on the basis of an external data source. Other than that features are likely to be coded for all four types of tree views (conventional, optimized, semi-virtual, and virtual). The fact that multi-line items work in a conventional treeview is a reasonably good reason to include a few functions for conventional treeviews. Another reason to include conventional treeviews in a UDF is that all treeview features only work in a conventional treeview. All features also work in a treeview based on optimized code. That type is interesting in a UDF because of the speed. A semi-virtual treeview is required if the entire treeview structure is to be created in advance so that only item texts and images can be virtual. Therefore, this type should be included in a UDF. A true virtual treeview is the Formula One version of the treeviews. This is the version the whole example is about. And it's the absolutely essential version of a UDF. So far, not a single line has been coded in a UDF. So a UDF isn't just around the corner. A UDF will be presented when it's ready.
    3 points
  3. EasyCodeIt A cross-platform implementation of AutoIt Introduction: EasyCodeIt is an attempt at implementing a programming language which is backward compatible with a sub-set of AutoIt which would work across multiple platforms with many aspects being agnostic to the platform-specific differences. Currently the primarily targeted platforms are Linux and Windows, more platforms may be supported in the future as per popular demand. For example it should be easy enough to port to Unix-like platforms such as BSD and Mac with the help of maintainers who are familiar with them. The main motivation behind the creation of this project is the lack of a proper easy-to-use scripting language in Linux, while there are numerous scripting languages which natively support it, none of them are as user-friendly and easy to use as AutoIt. (The "Easy" in "EasyCodeIt" reflects this) There was a previous thread in which the project was originally started, but it got too big and the discussion is too cluttered and hard to follow for any new readers, here is the thread for those who are interested in reading it: Progress: Frontend ✅ Tokenizer 🚧 Parser (work in progress) ✅ Expressions 👷‍♂️ Statements (current priority) Backend ⏰ Interpreter (scheduled) I am currently working on expression parsing and syntax tree building. -- This section will be updated in the future with new progress. To stay notified 🔔 follow this thread to get update notifications (by using the "Follow" button on the top-right corner of this page) and 👁️ watch the GitHub repository to get any new activity on your feed. Code: The code is available on GitHub, please 🌟 star the project if you like it and would like to show your support, it motivates me a lot! (Also don't forget to 👍 Like this post ) Chat: I created a room in Matrix (an open-source federated chat system) for EasyCodeIt, you can join it to chat with me and others who are in the room, it might be a good way to get the latest status updates from me You can preview the room without joining, and you don't need to be connected to it 24/7 like IRC. It works a bit like Slack for those who are familiar with it. Forum: I have created a dedicated forum to post more frequent updates, possibly in their own threads to better organize the discussion. Please sign-up and follow the blog section to get updates. By the way, you can also post pretty much anything there, both technical and non-technical stuff, it is intended to be a hangout for techies but not only for them. So casual discussions, funny cat videos etc. are allowed!
    1 point
  4. Source: https://forum.dtw.tools/d/5-easycodeit-progress-parsing-statements/14
    1 point
  5. I figured out the answer to my own question, word wrap can be "enabled" by removing the "horizontal scroll" ($WS_HSCROLL) setting from the _GUICtrlRichEdit_Create inside of your function __CreateLogGUI on (or near) line 902 in Loga.au3: Local $hRitchEdit = _GUICtrlRichEdit_Create($hGUI, "", 0, 0, $iWidth, $iHeight, $ES_READONLY + $ES_MULTILINE + $WS_VSCROLL + $ES_AUTOVSCROLL) Also I noticed that the Console kept printing out the font name on the line right after the log message. Not sure if this was intentional or an oversight/bug, but that can be fixed by commenting out the: ConsoleWrite($iFontName & @CRLF) on (or near) line 724
    1 point
  6. Maybe by using resize : #include <GUIConstants.au3> #include <GDIPlus.au3> #include <WinAPI.au3> Const $URL = "https://www.autoitscript.com/forum/uploads/monthly_2021_04/image.png.552f1c90192fed33bad1e8748f470c71.png" _GDIPlus_Startup() Local $hGUI = GUICreate("Example Resize") Local $hImage = _GDIPlus_BitmapCreateFromMemory(InetRead($URL)) Local $iWidth = Int(_GDIPlus_ImageGetWidth($hImage) * 0.75) ; New size Local $iHeight = Int(_GDIPlus_ImageGetHeight($hImage) * 0.75) Local $hImageResized = _GDIPlus_ImageResize($hImage, $iWidth, $iHeight) _GDIPlus_ImageDispose($hImage) Local $idPic = GUICtrlCreatePic("", 10, 10, $iWidth, $iHeight) Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageResized) _GDIPlus_ImageDispose($hImageResized) GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap) GUISetState() While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd _WinAPI_DeleteObject($hBitmap) _GDIPlus_Shutdown()
    1 point
  7. lol, funny presentation. At least you are bound to learn something.
    1 point
  8. After looking at the code more closely, I realized that it was kind of old code. So I couldn't resist to "refresh" it with a more recent coding approach. I may have solve at the same time your loading problem. So there you go : #include <IE.au3> #include <WinAPI.au3> #include <ScreenCapture.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", True) Local $ChatID = '<My ID Chat>' ;Your ChatID here (take this from @MyTelegramID_bot) Local $Token = '<TOKENBOT>' ;Token here Local $fileName1 = "media/APM ELK - CMS.png" Local $fileName2 = "media/Discover ELK.png" If FileExists($fileName1) Then FileDelete($fileName1) If FileExists($fileName2) Then FileDelete($fileName2) If $ChatID = '' Or $Token = '' Then Exit MsgBox($MB_SYSTEMMODAL, "Warning", "ChatID or Token not specified!") WebCaptureTest("https://www.google.ca", $fileName1) ElementCaptureTest("https://www.google.ca", $fileName2) Func WebCaptureTest($Url, $ImageName) Local $hBmp = WebCapture($Url) _ScreenCapture_SaveImage($ImageName, $hBmp, True) EndFunc ;==>WebCaptureTest Func ElementCaptureTest($Url, $ImageName) Local $WebWidth = 1200 Local $oIE = ObjCreate("Shell.Explorer.2") Local $hGUI = GUICreate("", $WebWidth, 800, -1, -1) GUICtrlCreateObj($oIE, 0, 0, $WebWidth, 800) _IENavigate($oIE, $Url) _IELoadWait($oIE) Local $oElement = $oIE.document.documentElement If $oElement.clientWidth = 0 Then $oElement = $oIE.document.body Local $hBmp = ElementCapture($oElement) _ScreenCapture_SaveImage($ImageName, $hBmp, True) GUIDelete($hGUI) EndFunc ;==>ElementCaptureTest Func WebCapture($Url, $WebWidth = 1200) Local $oIE = ObjCreate("Shell.Explorer.2") Local $hGUI = GUICreate("", $WebWidth, 800, -5000, -5000) GUICtrlCreateObj($oIE, 0, 0, $WebWidth, 800) _IENavigate($oIE, $Url) _IELoadWait($oIE) Local $oDocument = $oIE.document Local $oBody = $oIE.document.body Local $oHtml = $oIE.document.documentElement $oBody.scroll = "no" $oBody.style.borderStyle = "none" $oHtml.style.overflow = 'hidden' $oBody.style.overflow = 'hidden' Local $BodyWidth = $oBody.scrollWidth Local $BodyHeight = $oBody.scrollHeight Local $RootWidth = $oHtml.scrollWidth Local $RootHeight = $oHtml.scrollHeight Local $Width = $BodyWidth Local $Height = $RootHeight If $BodyHeight > $Height Then $Height = $BodyHeight $oIE.width = $Width $oIE.height = $Height GUISetState() Local $hBmp = Capture_Window($hGUI, 0, 0, $Width, $Height) GUIDelete($hGUI) Return $hBmp EndFunc ;==>WebCapture Func Capture_Window($hWnd, $l, $t, $r, $b) Local $hDC_Capture = _WinAPI_GetDC($hWnd) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture) Local $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $r, $b) Local $hObject = _WinAPI_SelectObject($hMemDC, $hHBitmap) _WinAPI_PrintWindow($hWnd, $hMemDC) _WinAPI_DeleteDC($hMemDC) _WinAPI_ReleaseDC($hWnd, $hDC_Capture) Return $hHBitmap EndFunc ;==>Capture_Window Func ElementCapture($oElement, $Border = 2) If Not IsObj($oElement) Then Return SetError(1, 0, 0) If $oElement.clientWidth = 0 Or $oElement.clientHeight = 0 Then Return SetError(1, 0, 0) Local $PageHeight = $oElement.scrollHeight - $Border Local $PageWidth = $oElement.scrollWidth - $Border Local $oIHTMLElementRender = ObjCreateInterface($oElement, "{3050F669-98B5-11CF-BB82-00AA00BDCE0B}", "DrawToDC hresult(hwnd);") Local $hDC = _WinAPI_GetDC(0) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateSolidBitmap(0, 0xffffff, $oElement.clientWidth, $oElement.clientHeight) Local $hMemDcFull = _WinAPI_CreateCompatibleDC($hDC) Local $hBmpFull = _WinAPI_CreateSolidBitmap(0, 0xffffff, $PageWidth, $PageHeight) _WinAPI_SelectObject($hMemDC, $hBmp) _WinAPI_SelectObject($hMemDcFull, $hBmpFull) Local $DrawWidth = $oElement.clientWidth - $Border Local $DrawHeight = $oElement.clientHeight - $Border Local $CurrentX = 0 Local $CurrentY = 0 While $CurrentX < $PageWidth While $CurrentY < $PageHeight $oElement.scrollLeft = $CurrentX $oElement.scrollTop = $CurrentY $oIHTMLElementRender.DrawToDC(Number($hMemDC)) _WinAPI_BitBlt($hMemDcFull, $oElement.scrollLeft, $oElement.scrollTop, $DrawWidth, $DrawHeight, $hMemDC, $Border, $Border, $SRCCOPY) $CurrentY += $DrawHeight WEnd $CurrentY = 0 $CurrentX += $DrawWidth WEnd _WinAPI_DeleteDC($hMemDC) _WinAPI_DeleteDC($hMemDcFull) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_DeleteObject($hBmp) Return $hBmpFull EndFunc ;==>ElementCapture IDK, but I'm not even sure you need Func ElementCapture anymore. Let me know how it goes...
    1 point
  9. Try this quick & dirty fix. Add this line Sleep(20*1000) after _IENavigate($oIE, $url). You need to do this at 2 places. If that solves your immediate problem, we can think of a better solution later.
    1 point
  10. Multi-line treeview itemsMulti-line treeview items are supported through the iIntegral field in the TVITEM structure and custom draw code. The iIntegral value handles multi-line items in the treeview structure. Custom draw code draws the entire item rectangle, the dotted focus rectangle and the individual multi-line texts. Multi-line treeview items are supported by all treeviews and not just semi-virtual or virtual treeviews. To add a multi-line item with 2, 3 or 4 lines, simply set the value of iIntegral to 2, 3 or 4. Both the width and height of a rectangle that can accommodate all the lines must be calculated in the custom draw code. The height is just 2, 3 or 4 times the height of a single-line item. The width must be set to the width of the widest text string in pixels of the 2, 3, or 4 substrings. The width of a text string in pixels is calculated using the GetTextExtentPoint32W() function. The left position of the rectangle is calculated with _GUICtrlTreeView_GetIndent() and the item level. You'll also need to consider that the width of the entire treeview control may not be large enough to accommodate the longest text strings. Data source for multi-line items (Multiline.txt) 0|0 0|1 0|2 1|3 1|This|Line 2 1|is 2|6 2|a 2|very 2|nice|Line 2|Line 3 3|10 3|TreeView 0|, (comma) 1|13 1|indeed. 0|15 Code in a semi-virtual treeview to create and draw multi-line items (1) Multiline Items.au3) ; Create TreeView structure Func CreateTreeView( $aItems ) ; TreeView item information Local $aItem, $iItem ; TreeView level information Local $aLevels[100][2], $iLevel = 0, $iLevelPrev = 0 ; $aLevels[$iLevel][0]/[1] contains the last item/parent of that level ; TreeView insert structure Local $tInsert = DllStructCreate( $tagTVINSERTSTRUCT ), $pInsert = DllStructGetPtr( $tInsert ) DllStructSetData( $tInsert, "InsertAfter", $TVI_LAST ) DllStructSetData( $tInsert, "Mask", $TVIF_HANDLE+$TVIF_PARAM+$TVIF_TEXT+$TVIF_INTEGRAL ) DllStructSetData( $tInsert, "Text", -1 ) ; $LPSTR_TEXTCALLBACK ; Add TreeView root $aItem = StringSplit( $aItems[0], "|", 2 ) $iItem = UBound( $aItem ) $aLevels[$iLevel][1] = NULL DllStructSetData( $tInsert, "Param", 0 ) DllStructSetData( $tInsert, "Parent", $aLevels[$iLevel][1] ) DllStructSetData( $tInsert, "Integral", $iItem > 2 ? $iItem - 1 : 1 ) $aLevels[$iLevel][0] = GUICtrlSendMsg( $idTreeView, $TVM_INSERTITEMW, 0, $pInsert ) ; Add TreeView items For $i = 1 To UBound( $aItems ) - 1 $aItem = StringSplit( $aItems[$i], "|", 2 ) $iItem = UBound( $aItem ) $iLevel = $aItem[0] If $iLevel <> $iLevelPrev Then $aLevels[$iLevel][1] = $iLevel > $iLevelPrev ? $aLevels[$iLevelPrev][0] _ ; A child of the previous level : GUICtrlSendMsg( $idTreeView, $TVM_GETNEXTITEM, $TVGN_PARENT, $aLevels[$iLevel][0] ) ; A sibling of the level $iLevelPrev = $iLevel EndIf DllStructSetData( $tInsert, "Param", $i ) DllStructSetData( $tInsert, "Parent", $aLevels[$iLevel][1] ) DllStructSetData( $tInsert, "Integral", $iItem > 2 ? $iItem - 1 : 1 ) $aLevels[$iLevel][0] = GUICtrlSendMsg( $idTreeView, $TVM_INSERTITEMW, 0, $pInsert ) Next ; $aLevels[$iLevel][0]/[1] contains the last item/parent of that level EndFunc Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) Local $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) Switch HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) Case $hTreeView Switch DllStructGetData( $tNMHDR, "Code" ) Case $TVN_GETDISPINFOW ; Display TreeView item text Local Static $tBuffer = DllStructCreate( "wchar Text[50]" ), $pBuffer = DllStructGetPtr( $tBuffer ) Local $tDispInfo = DllStructCreate( $tagNMTVDISPINFO, $lParam ), $sText = StringSplit( $aItems[DllStructGetData($tDispInfo,"Param")], "|", 2 )[1] DllStructSetData( $tBuffer, "Text", $sText ) DllStructSetData( $tDispInfo, "Text", $pBuffer ) DllStructSetData( $tDispInfo, "TextMax", 2 * StringLen( $sText ) + 2 ) Case $NM_CUSTOMDRAW Local $tCustomDraw = DllStructCreate( $tagNMTVCUSTOMDRAW, $lParam ) Switch DllStructGetData( $tCustomDraw, "DrawStage" ) ; The current drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent before painting an item Case $CDDS_ITEMPREPAINT ; Before painting an item If UBound( StringSplit( $aItems[DllStructGetData($tCustomDraw,"ItemParam")], "|", 2 ) ) > 2 Then _ Return $CDRF_NOTIFYPOSTPAINT ; Notify the parent after painting an item ; Draw multiline item texts Case $CDDS_ITEMPOSTPAINT ; After painting an item Local Static $iTVIndent = _GUICtrlTreeView_GetIndent( $hTreeView ), $tSize = DllStructCreate( $tagSIZE ), $hBrushHighLight = _WinAPI_GetSysColorBrush( $COLOR_HIGHLIGHT ), $hBrushButtonFace = _WinAPI_GetSysColorBrush( $COLOR_BTNFACE ), $hBrushWhite = _WinAPI_CreateSolidBrush( 0xFFFFFF ) Local $hDC = DllStructGetData( $tCustomDraw, "HDC" ), $tRect = DllStructCreate( $tagRECT, DllStructGetPtr( $tCustomDraw, "Left" ) ), $aItem = StringSplit( $aItems[DllStructGetData($tCustomDraw,"ItemParam")], "|", 2 ), $iItem = UBound( $aItem ), $iMaxTextLen = 0, $iLeft = $iTVIndent * ( $aItem[0] + 1 ) + 3, $iRectWidth = DllStructGetData( $tCustomDraw, "Right" ) - $iLeft, $iTop = DllStructGetData( $tRect, "Top" ), $iItemState = DllStructGetData( $tCustomDraw, "ItemState" ) ; Longest text in pixels of all item texts For $i = 1 To $iItem - 1 DllCall( "gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $aItem[$i], "int", StringLen( $aItem[$i] ), "struct*", $tSize ) ; _WinAPI_GetTextExtentPoint32 If DllStructGetData( $tSize, "X" ) + 1 > $iMaxTextLen Then $iMaxTextLen = DllStructGetData( $tSize, "X" ) + 1 Next ; Rectangle that includes all item texts If $iMaxTextLen + 4 > $iRectWidth Then _ $iMaxTextLen = $iRectWidth - 4 DllStructSetData( $tRect, "Left", $iLeft ) DllStructSetData( $tRect, "Right", $iLeft + $iMaxTextLen + 4 ) DllStructSetData( $tRect, "Bottom", $iTop + 18 * ( $iItem - 1 ) ) DllCall( "gdi32.dll", "int", "SetBkMode", "handle", $hDC, "int", $TRANSPARENT ) ; _WinAPI_SetBkMode() Switch BitAND( $iItemState, $CDIS_SELECTED + $CDIS_FOCUS ) Case $CDIS_SELECTED + $CDIS_FOCUS DllCall( "user32.dll", "int", "FillRect", "handle", $hDC, "struct*", $tRect, "handle", $hBrushHighLight ) ; _WinAPI_FillRect() DllCall( "user32.dll", "bool", "DrawFocusRect", "handle", $hDC, "struct*", $tRect ) ; _WinAPI_DrawFocusRect() DllCall( "gdi32.dll", "INT", "SetTextColor", "handle", $hDC, "INT", 0xFFFFFF ) ; _WinAPI_SetTextColor() Case $CDIS_SELECTED DllCall( "user32.dll", "int", "FillRect", "handle", $hDC, "struct*", $tRect, "handle", $hBrushButtonFace ) ; _WinAPI_FillRect() Case $CDIS_FOCUS Case Else DllCall( "user32.dll", "int", "FillRect", "handle", $hDC, "struct*", $tRect, "handle", $hBrushWhite ) ; _WinAPI_FillRect() EndSwitch ; Left start position for item texts DllStructSetData( $tRect, "Left", $iLeft + 2 ) ; Draw all item texts For $i = 1 To UBound( $aItem ) - 1 DllStructSetData( $tRect, "Top", $iTop + 18 * ( $i - 1 ) + 1 ) DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $aItem[$i], "int", -1, "struct*", $tRect, "uint", $DT_LEFT+$DT_WORD_ELLIPSIS ) ; _WinAPI_DrawText() Next EndSwitch EndSwitch EndSwitch #forceref $hWnd, $iMsg, $wParam EndFunc Store MaxTextLen in data sourceBecause the width of the longest text string in pixels ($iMaxTextLen) must be calculated each time a multi-line item needs to be redrawn, it can be an advantage to store this width directly in the data source. Multiline-2.txt: 0|000|0 0|000|1 0|000|2 1|000|3 1|000|This|Line 2 1|000|is 2|000|6 2|000|a|A somewhat long new line 2|000|very 2|000|nice|A TreeView item with three lines|Line 3 3|000|10 3|000|TreeView 0|000|, (comma) 1|000|13 1|000|indeed. 0|000|15 2) Store MaxTextLen.au3: ; Cleanup GUIDelete( $hGui ) If $bSaveItems Then _FileWriteFromArray( "Multiline-2.txt", $aItems ) $aItem = StringSplit( $aItems[DllStructGetData($tCustomDraw,"ItemParam")], "|", 2 ) $iMaxTextLen = $aItem[1]+0 ; Longest text in pixels of all item texts If Not $iMaxTextLen Then For $i = 2 To $iItem - 1 DllCall( "gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $aItem[$i], "int", StringLen( $aItem[$i] ), "struct*", $tSize ) ; _WinAPI_GetTextExtentPoint32 If DllStructGetData( $tSize, "X" ) + 1 > $iMaxTextLen Then $iMaxTextLen = DllStructGetData( $tSize, "X" ) + 1 Next $bSaveItems = True $iIndex = DllStructGetData( $tCustomDraw, "ItemParam" ) $aItems[$iIndex] = StringReplace( $aItems[$iIndex], 3, StringFormat( "%03i", $iMaxTextLen ) ) EndIf Too narrow treeview control3) Store MaxTextLen.au3 is similar to the example above except that the treeview control is too narrow for the longest text strings. New 7z-file at bottom of first post. The first set of examples in 1) Virtual TreeView\ has all been updated with some very minor changes.
    1 point
  11. Danyfirex

    Array of Structures

    Hi. Local $aArray[2]=[DllStructCreate("dword TokType;wchar Token[100]"),DllStructCreate("dword TokType;wchar Token[100]")] $aArray[0].TokType=1 $aArray[0].Token="Hola" $aArray[1].TokType=2 $aArray[1].Token="Mundo" ConsoleWrite($aArray[0].TokType() & " " & $aArray[0].Token() & @CRLF) ConsoleWrite($aArray[1].TokType() & " " & $aArray[1].Token() & @CRLF) Saludos
    1 point
×
×
  • Create New...