Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/21/2020 in all areas

  1. This example is about implementing Rectangular Selection in a listview with mouse and keyboard. By default, listviews only supports selection of entire rows. Either a single row or multiple rows. The purpose of this UDF is also to support selection of a rectangular group of cells. Either a single rectangular group of cells or multiple rectangular groups of cells. The UDF supports all four types of listviews: The conventional (all examples in the help file), virtual (includes the $LVS_OWNERDATA style), ownerdrawn (includes the $LVS_OWNERDRAWFIXED style) and ownerdrawn+virtual listview. The examples are all about virtual listviews to verify that the code still works with a large number of additional WM_NOTIFY messages needed to populate a virtual listview. One additional message per cell for all cells visible on a listview page. If a page shows 40 rows and 15 columns, this means 600 additional messages to fill the page with data. The first post here is about selecting a single rectangular group of cells. The next post is about selecting multiple rectangular groups of cells. Single selectionSelecting a single rectangular group of cells forming a rectangular selection can be performed by selecting the first corner cell of the rectangle as a fixed starting cell and then selecting the opposite corner cell of the rectangle based on the Single Cell Navigation technique. The technique of creating a single rectangular selection in this post and of creating multiple rectangular selections in the next post is heavily based on the Single Cell Navigation (SCN) UDF. The ideas in code to implement resizable GUIs and listviews and the use of multiple listviews are exactly the same in terms of Rectangular Selections as they are in terms of Single Cell Navigation. And the requirements for a listview to implement Rectangular Selections are the same as the requirements for implementing Single Cell Navigation: The $LVS_EX_HEADERDRAGDROP style (drag/drop reordering of columns) is not supported. Zero-width columns are not supported. In the code it's checked that columns are not narrower than 10 pixels. ExampleThis is the Virtual-SRS.au3 example. The example demonstrates the use of the pure UDF. The rectangle selection is not used in user code. Run the example in SciTE with F5. Right-click listview and select "Single rectangle selection". You should try to create a selection using all four methods described below: The yellow cell is the active cell that is subject of keyboard navigation. There are four ways to create a rectangle selection. Click and drag a selection with the mouse. Releasing the mouse button completes the selection. The advantage of this method is that it's simple, fast and intuitive. The disadvantage is that it can only be used to make a selection on the current visible page in the listview. When using the mouse to create the selection, you cannot use the mouse on the scrollbars at the same time. The other three ways uses the Shift key to create the selection. This allows you to continue a selection by pressing the Shift key and performing single cell navigation on the yellow active cell in one of the corners of the current selection. You can also continue a selection started with the Click and drag method above. The ability to continue a selection allows you to create large selections that span multiple listview pages and navigate the listview with the scrollbars in between each subselection. The three methods with the Shift key are fully integrated. You can start a selection with one method and continue with another method. The yellow active cell is the fixed start cell in the selection rectangle. Press the Shift key and Use keyboard navigation to create the selection rectangle. Click the opposite corner of the selection rectangle with the mouse. Using the scrollbars, you can navigate around the listview before clicking the opposite corner. Click and drag a selection with the mouse. Releasing Shift key and mouse button temporarily completes the selection. Since only a single rectangle selection is supported, a click of the mouse, a movement of the yellow active cell with the keyboard or starting a new selection will immediately delete the current selection. The codeSingle Rectangle Selection (SRS) is implemented as a UDF in Includes\GuiListViewSRS.au3. GuiListViewSRS.au3 was started as a direct copy of GuiListViewSCN.au3. The UDF contains two functions to enable and disable SRS functionality. The functions starts and stops two message handlers implemented through the subclassing technique that takes care of the actual Single Rectangle Selection. One message handler, SRS_GuiHandler(), takes care of WM_NOTIFY messages (listview and header notifications and messages) sent to the main GUI. The other message handler, SRS_ListViewHandler(), takes care of mouse and keyboard messages sent directly to the listview. ExamplesRun examples in SciTE with F5. There are only two examples of single rectangle selections. Virtual-SRS.au3 is the example shown above. Virtual-SRS-Ex.au3 is a very simple example of using the rectangle selection in the user code. It's used to draw a corresponding rectangle in the user code. Right-click listview and select "Single rectangle selection" to switch to UDF code. Create a rectangle selection. Right-click listview and select "Default row selection" to switch back to user code. Because the UDF only supports single selections, the rectangle is passed to the user code as item/subitem (row/column) coordinates (indexes) of two opposite corner cells in the rectangle. This means that even a very large rectangle is passed instantly. You should see the rectangel in the user code. 7z-fileThe 7z-file contains source code for UDFs and examples. 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. RectangularSelection.7z
    4 points
  2. This example is about Single Cell Navigation in a listview with mouse and keyboard. By default, listviews only supports navigation through the rows. The purpose of this UDF is also to support navigation through the cells. The UDF supports all four types of listviews: The conventional (all examples in the help file), virtual (includes the $LVS_OWNERDATA style), ownerdrawn (includes the $LVS_OWNERDRAWFIXED style) and ownerdrawn+virtual listview. However, the 7z-file at bottom of post only contains examples for conventional and virtual listviews. ExampleThis is the Virtual\Resizable2.au3 example. Run the example in SciTE with F5. Right-click listview and select "Single cell navigation": The yellow cell is the active cell that is subject of keyboard navigation. Mouse navigation: Click a listview cell. Vertical keyboard navigation: Up, Down, PageUp, PageDown, Home and End. Horizontal keyboard navigation: Left, Right, CapsLock + PageUp, PageDown, Home or End. If the yellow active cell is located outside the visible page in the listview (if eg. a scrollbar has been used), using a navigation key will again place the active cell on the visible page. CapsLock is used for horizontal navigation because both Shift and Ctrl are used for standard multiple row selection. CapsLock + PageUp, PageDown, Home or End is especially interesting for ownerdrawn+virtual listviews that supports many columns. Horizontal or vertical navigation one page at a time can generate a lot of flicker. To prevent excessive flicker, automatic repeat of the PageUp/PageDown keys is disabled. A large amount of code is used to ensure that when a cell in a only partially visible (or not visible at all) column along a listview edge becomes the active cell, then the entire column and thus the cell becomes fully visible. Both in the UDF and in the examples, a large amount of code has also been used on the topic of GUI and listview resizing. ResizingFor a large control like a listview, it's usually valuable that both the GUI and the listview are resizable. And for a listview, it's nice if the height always fits an integer number of rows. If a column is made wider or narrower by dragging the header divider so that the horizontal scrollbar appears or disappears, then the height of the listview must be adjusted a little so that it again corresponds to an integer number of rows. The UDF to some extent support resizing in relation to these assumptions. But only for a single listview. If you need multiple listviews in the same GUI that all offers single cell navigation, then disable resizing in single cell navigation mode (remove resizing in GUI style and remove column resizing in listview header style (Virtual\Resizable4.au3)). Then you can handle resizing completely in your own code. RequirementsImplementing the functionality described above already requires quite a lot of code. In order not to use too much code, the following requirements for a listview must be met in order to use the UDF: The $LVS_EX_HEADERDRAGDROP style (drag/drop reordering of columns) is not supported. Zero-width columns are not supported. In the code it's checked that columns are not narrower than 10 pixels. The codeThe code is based on the KeyboardNavigation and MarkCurrentCell examples in the multi-column listviews thread. And these examples are again based on this old example of cell editing. In the new thread here, the Single Cell Navigation (SCN) functionality is implemented as a UDF in Includes\GuiListViewSCN.au3. The UDF contains two functions to enable and disable SCN functionality. In addition to the usual housekeeping code, the functions starts and stops two message handlers implemented through the subclassing technique that takes care of the actual Single Cell Navigation. One message handler, SCN_GuiHandler(), takes care of WM_NOTIFY messages (listview and header notifications and messages) sent to the main GUI. The other message handler, SCN_ListViewHandler(), takes care of mouse and keyboard messages sent directly to the listview. Because the code is very much about message handling, Windows Message Monitor has been an important tool for developing the UDF. ExamplesRun all examples in SciTE with F5. Virtual listviews FirstTest.au3, Incompatible.au3, MultipleLists.au3 and Non-Resizable.au3 are all non-resizable. And it's not possible to change column widths. FirstTest.au3 is a very simple example that immediately starts up in single cell navigation mode. Non-Resizable.au3 is similar to FirstTest.au3, but single cell navigation can be enabled/disabled dynamically through the listview context menu. Incompatible.au3 is incompatible with single cell navigation due to the $LVS_EX_HEADERDRAGDROP style. An error is generated when you right-click to enable single cell navigation. MultipleLists.au3 demonstrates how to use single cell navigation in multiple listviews. Right-click listviews to enable/disable single cell navigation. In Resizable1.au3, the width of GUI and listview corresponds to the width of the columns. If you increase/decrease the width of a column or the width of the GUI a little bit, the horizontal scrollbar will appear/disappear. Resizable2.au3 is the example shown above. It's used to test horizontal navigation. Resizable3.au3 demonstrates how to handle resizing when the GUI contains more controls than just the listview. Resizable4.au3 shows how to disable resizing in single cell navigation mode. Then you can handle all resizing in your own code. Conventional listviews The examples for conventional listviews are similar to the examples for virtual listviews with the same names. UsageSingle cell navigation can be used for many different purposes. Here it'll be used to implement Rectangular Selection in ListView. 7z-fileThe 7z-file contains source code for UDFs and examples. 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. CellNavigation.7z
    2 points
  3. HotStrings are similar to AutoIts HotKey function but they trigger on a string of characters, instead of a key or key combination. This has been built because of popular requested from the community. Instructions for use: Download the HotString.au3 (from the GitHub link) and put it in the same directory as your script. Then try out the code example below, or use the library in your own application. Please visit https://github.com/jvanegmond/hotstrings for the download (download zip in bottom right). Or get it directly from master. Example #include <HotString.au3> HotStringSet("callme{enter}", examplefunction) While 1 Sleep(10) WEnd Func examplefunction() MsgBox(0,"","You typed callme! :)") EndFunc
    1 point
  4. @Siwa A few things I notice -- By default, _WD_WaitElement doesn't return an element. You will have to pass the True for optional $lReturnElement parameter if you want it to return an element instead of 0/1. You should get in the habit of checking @error following each call to the webdriver UDF. Not sure why you need the Do...Until loop. You should be able to do everything with a single call to _WD_WaitElement. Once you have the element, you could then loop if really needed. Not sure why none of your attempts have worked. It would likely help if you posted the results from the Scite output panel so that we can understand what's happening.
    1 point
  5. If you have the control on the HTML source of the page you set in the BrowserControl try to set the following directive as the first line of the <head> session. <head> <meta http-equiv="X-UA-Compatible" content="IE=edge"> </head> This will set the BrowserControl to work in the latest version of the IE browser you have installed on your PC, (IE11 ?) otherwise it will work by default as an IE7 and this can give you problems on some newer functionality of the HTML5 and CSS3. for example, at this link (https://caniuse.com/?search=querySelector) you can verify what commands are supported by what browsers versions .... Hope it can be of help P.S. also this link can be of help ... https://www.autoitscript.com/forum/topic/189843-iecreateembedded-issue/
    1 point
  6. 1 point
  7. You should take look to this both topics:
    1 point
  8. Nine

    Execute Code In A String

    Maybe something like this ? #include <Constants.au3> #include "wd_core.au3" #include "wd_helper.au3" ;$_WD_DEBUG = $_WD_DEBUG_None ; to hide ChromeDriver console Local $sDesiredCapabilities = SetupChrome() _WD_Startup() Sleep(2000) _WD_ConsoleVisible() Local $sSession = _WD_CreateSession($sDesiredCapabilities) Const $Line1 = '_WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@class=''gb_g'']")' Const $Line2 = "_WD_ElementAction($sSession, $sElement, 'text')" _WD_Navigate($sSession, "http://google.ca") Local $sElement = Execute($Line1) ConsoleWrite ("$sElement = " & $sElement & @CRLF) Local $sText = Execute ($Line2) ConsoleWrite ("$sText = " & $sText & @CRLF) Sleep(6000) _WD_DeleteSession($sSession) _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"') Return '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}' EndFunc ;==>SetupChrome
    1 point
  9. Maybe you would prefer this approach, where only the precise controls trigger the WindowProc : #include <GuiConstants.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <WinAPI.au3> #include <EditConstants.au3> Local $hGUI = GUICreate("No Button GUI", 600, 400) Local $input1 = GUICtrlCreateInput("1", 8, 8, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER)) Local $input2 = GUICtrlCreateInput("1", 8, 32, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER)) Local $input3 = GUICtrlCreateInput("0", 8, 56, -1, -1, BitOR($ES_RIGHT, $ES_NUMBER)) $wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam") $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($input1), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle)) _WinAPI_SetWindowLong(GUICtrlGetHandle($input2), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle)) GUISetState() While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($hGUI) DllCallbackFree($wProcHandle) Func _WindowProc($hWnd, $Msg, $wParam, $lParam) ; hwnd = GUICtrlGetHandle($idControl) If $Msg = $WM_KILLFOCUS Then GUICtrlSetData($input3, GUICtrlRead($input1) + GUICtrlRead($input2)) Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $Msg, $wParam, $lParam) EndFunc ;==>_WindowProc
    1 point
  10. _WinAPI_ClearConsole Clear console screen buffer, six options to set cursor and clear or overwrite text _WinAPI_CursorShowConsole Show or hide cursor and set cursor size NOTE: for scripts compiled as console apps with wrapper directive: #AutoIt3Wrapper_Change2CUI=y some console related links: Overwriting StdOut in CUI compiled app http://www.autoitscript.com/forum/index.php?showtopic=66486 set text colour attributes http://www.autoitscript.com/forum/index.ph...st&p=493255 CMD.au3 http://www.autoit.de/index.php?page=Thread...44881#post44881 How To Performing [sic] Clear Screen (CLS) in a Console Application http://support.microsoft.com/kb/99261 Clearing the Screen (Windows) http://msdn.microsoft.com/en-us/library/ms682022.aspx Screen_Scrape.au3 http://www.autoitscript.com/forum/index.ph...st&p=527810 Edit 1 second example added - DOS character set frame around multiple data displays and mid line progress bar Edit 2 corrected error in parameter range check on X Y coordinates - Thanks Authenticity Example 1: Console line editing and data display updating on a row [autoit]#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** If Not @Compiled Then Exit MsgBox(262144 + 16, "_WinAPI_ClearConsole() Test", "Script must be compiled as a console app to run") Opt('MustDeclareVars', 1) ;clear screen - clears prompt if run from command line Local $hStdOut = _WinAPI_ClearConsole() ;save previous cursor, hide cursor Local $iPrevSize = _WinAPI_CursorShowConsole($hStdOut, False) #Region - Console line editing example ;////////////////////////////////////////////////////////////////////////////////////// ;Example demonstrating console line editing ;////////////////////////////////////////////////////////////////////////////////////// Local $aArray = StringSplit("4D7900204B61726D61002072756E00206F76657200206D790020446F676D61", "00", 1) Local $iCnt ; sequentially append text to end of row 0 ($iCnt is character column position on row) For $i = 1 To $aArray[0] ConsoleWrite(BinaryToString("0x" & $aArray[$i])) Sleep(750) $iCnt += (StringLen($aArray[$i]) / 2) _WinAPI_ClearConsole(-1, $iCnt, 0) Next ConsoleWrite(@CRLF) ;add a block of rows For $i = 1 To 6 ConsoleWrite("Jackdaws love my big sphinx of quartz" & @CRLF) Next Sleep(1000) ; set cursor size to a block _WinAPI_CursorShowConsole($hStdOut, True, 100) ; clear then write single rows with new text For $i = 1 To 3 _WinAPI_ClearConsole(-1, Default, $i) Sleep(1000) ConsoleWrite("New row " & $i) Next Sleep(2000) _WinAPI_ClearConsole(-1, -2, -1) ; clear a block of 2 rows starting on row 1 ConsoleWrite("correcting 'Typo' in row 0") Sleep(2000) _WinAPI_ClearConsole(-1, -10, 0) ; change letter in first row of text ConsoleWrite("a") Sleep(2000) _WinAPI_ClearConsole(-1, Default, 1) ; clear row 1 ConsoleWrite("Done") Sleep(1000) _WinAPI_ClearConsole(-1, 0, 0) ; set cursor on character column 0 and row 0 Sleep(1000) _WinAPI_ClearConsole(-1, 0, Default) ; set cursor on character column 0 and bottom row Sleep(1000) _WinAPI_ClearConsole(-1, Default, -1) ; clear all rows starting at second row Sleep(1000) _WinAPI_ClearConsole() ; clear screen (set cursor on character column 0 and row 0) ;////////////////////////////////////////////////////////////////////////////////////// #EndRegion - Console line editing example #Region - Console label and data updating on a row ;////////////////////////////////////////////////////////////////////////////////////// ;Example demonstrating label and data updating on a row ;////////////////////////////////////////////////////////////////////////////////////// ;Overwriting StdOut in CUI compiled app, for use with progress indicator ;http://www.autoitscript.com/forum/index.php?showtopic=66486 ;hide cursor _WinAPI_CursorShowConsole($hStdOut, False) Local $progress, $buffer, $ClearProgress ConsoleWrite("Milliseconds: " & @CRLF) ConsoleWrite("Seconds : " & @CRLF) ConsoleWrite("Progress" & @CRLF) For $i = 0 To 500 Sleep(10) _WinAPI_ClearConsole(-1, 14, 0) ConsoleWrite(@MSEC) _WinAPI_ClearConsole(-1, 14, 1) ConsoleWrite(@SEC) If @SEC <> $buffer Then _WinAPI_ClearConsole(-1, 8, 2) $buffer = @SEC $progress &= "." ConsoleWrite($progress) $ClearProgress += 1 If $ClearProgress = 25 Then $ClearProgress = 0 $progress = "" EndIf EndIf Next ;////////////////////////////////////////////////////////////////////////////////////// #EndRegion - Console label and data updating on a row ;restore and show cursor, clear console _WinAPI_CursorShowConsole($hStdOut, True, $iPrevSize) _WinAPI_ClearConsole() Sleep(1000) Exit ; #FUNCTION# ======================================================= ; Name...........: _WinAPI_ClearConsole ; Description ...: Clears console screen buffer /w six options to clear rows & characters & set cursor position ; Syntax.........: _WinAPI_ClearConsole($hConsole = -1, $iX = Default, $iY = Default) ; Parameters ....: $hConsole - (Optional) Handle to standard output device ; $iX - (Optional) zero based character column position of cursor ; Default or 0 to screen buffer max width (negative values for some modes) ; $iY - (Optional) zero based row position of cursor ; Default or 0 to screen buffer max height (negative values for some modes) ; ;No params ; clear screen (-1, Default, Default) ;(-1, Default, 0) ; clear single row: $iY = row number (0 is row 1) ;(-1, -2, -3) ; clear block of rows: -$iX = number of rows, -$iY = starting row (minimum $iX = -1, $iY = -1) ;(-1, Default, -1) ; clear all rows from start row: -$iY = starting row (minimum $iY = -1) ;(-1, 20, 2) ; clear characters to end of row: $iX = start character column, $iY = row number ;(-1, -20, 2) ; set cursor at coordinates: -$iX = start character column, $iY = row number (minimum $iX = -1) ;(-1, 0, Default) ; set cursor on bottom row of console window: $iX = start character column ; Return values .: Success - return handle to standard output device (does not have to be closed) ; Failure - return 0, set error and extended ; Author ........: rover ; Modified.......: ; Remarks .......: ; Related .......: ; ; Link ..........; @@MsdnLink@@ FillConsoleOutputCharacter ; Example .......; Yes ; ================================================================== Func _WinAPI_ClearConsole($hConsole = -1, $iX = Default, $iY = Default) Local $dwCoord, $fFlag = False Local $bChar = 0x20, $iErr ; fill character: 0x20 (Space) Local Const $STD_OUTPUT_HANDLE = -11 Local Const $INVALID_HANDLE_VALUE = -1 Local Const $tagCONSOLE_SCREEN_BUFFER_INFO = "short dwSizeX; short dwSizeY;short dwCursorPositionX;" & _ "short dwCursorPositionY; short wAttributes;short Left; short Top; short Right; short Bottom;" & _ "short dwMaximumWindowSizeX; short dwMaximumWindowSizeY" ;// get handle to standard output device (handle does not have to be closed on return) Local $hDLLK32 = DllOpen("Kernel32.dll"), $aRet If $hConsole = -1 Then $aRet = DllCall($hDLLK32, "hwnd", "GetStdHandle", "dword", $STD_OUTPUT_HANDLE) $iErr = @error If @error Or UBound($aRet) <> 2 Or $aRet[0] = $INVALID_HANDLE_VALUE Then Return SetError($iErr, 1, $INVALID_HANDLE_VALUE) EndIf $hConsole = $aRet[0] EndIf ;// create console screen buffer struct, get buffer Local $tCONSOLE_SCREEN_BUFFER_INFO = DllStructCreate($tagCONSOLE_SCREEN_BUFFER_INFO) If @error Then Return SetError(@error, 2, 0) Local $pConsoleScreenBufferInfo = DllStructGetPtr($tCONSOLE_SCREEN_BUFFER_INFO) If @error Then Return SetError(@error, 3, 0) $aRet = DllCall($hDLLK32, "int", "GetConsoleScreenBufferInfo", "hwnd", _ $hConsole, "ptr", $pConsoleScreenBufferInfo) $iErr = @error If @error Or UBound($aRet) <> 3 Or Not $aRet[0] Then Return SetError($iErr, 4, 0) ;// Get the screen buffer max width (character columns) and height (rows) Local $dwSizeX = DllStructGetData($tCONSOLE_SCREEN_BUFFER_INFO, "dwSizeX") Local $dwSizeY = DllStructGetData($tCONSOLE_SCREEN_BUFFER_INFO, "dwSizeY") Local $dwConSize ;// input coordinates range check If IsNumber($iX) And (Abs($iX) > ($dwSizeX -1)) Then $iX = $dwSizeX -1 If IsNumber($iY) And (Abs($iY) > ($dwSizeY -1)) Then $iY = $dwSizeY -1 Select ;// clear screen (Default) - max screen buffer width multiplied by height Case IsNumber($iX) = 0 And IsNumber($iY) = 0 ; handles Default keyword and strings in params $dwConSize = ($dwSizeX * $dwSizeY) $iX = 0 $iY = 0 ;// overwrite or clear any single row - cursor now set to start of that row Case IsKeyword($iX) = 1 And IsKeyword($iY) = 0 And $iY >= 0 $dwConSize = $dwSizeX $iX = 0 ;// overwrite or clear a number of rows from starting row ;(-$iX parameter is number of rows to overwrite, second row minimum) Case $iX < 0 And $iY < 0 $iY = Abs($iY) $dwConSize = ($dwSizeX * Abs($iX)) $iX = 0 ;// overwrite or clear all rows from starting row to last row, second row minimum) Case IsKeyword($iX) = 1 And $iY < 0 $iY = Abs($iY) $dwConSize = ($dwSizeX * $dwSizeY) - ($dwSizeX * $iY) $iX = 0 ;// overwrite or clear text from character position on row to end of row Case $iX >= 0 And IsKeyword($iY) = 0 And $iY >= 0 $dwConSize = ($dwSizeX - $iX) If $iX = 0 And $iY = 0 Then $fFlag = True ContinueCase EndIf ;// place cursor at last row of console window Case $iX >= 0 And IsKeyword($iY) = 1 If Not $fFlag Then $iY = DllStructGetData($tCONSOLE_SCREEN_BUFFER_INFO, "Bottom") ContinueCase ;// places cursor at coordinates for overwriting Case $iX < 0 And $iY >= 0 $dwCoord = BitOR($iY * 0x10000, BitAND(Abs($iX), 0xFFFF)) $aRet = DllCall($hDLLK32, "int", "SetConsoleCursorPosition", "hwnd", _ $hConsole, "dword", $dwCoord) $iErr = @error If @error Or UBound($aRet) <> 3 Or Not $aRet[0] Then Return SetError($iErr, 5, 0) DllClose($hDLLK32) Return SetError(0, 0, $hConsole) Case Else Return SetError(@error, 6, 0) EndSelect ;// Cursor position: make DWord of X,Y coordinates) $dwCoord = BitOR($iY * 0x10000, BitAND($iX, 0xFFFF)) ;// Fill selected rows with blanks $aRet = DllCall($hDLLK32, "int", "FillConsoleOutputCharacterW", "hwnd", $hConsole, _ "byte", $bChar, "dword", $dwConSize, "dword", $dwCoord, "int*", 0) $iErr = @error If @error Or UBound($aRet) <> 6 Or $aRet[5] <> $dwConSize Then Return SetError($iErr, 7, 0) ;// Get the current text attributes $aRet = DllCall($hDLLK32, "int", "GetConsoleScreenBufferInfo", "hwnd", _ $hConsole, "dword", $pConsoleScreenBufferInfo) $iErr = @error If @error Or UBound($aRet) <> 3 Or Not $aRet[0] Then Return SetError($iErr, 8, 0) Local $wAttribute = DllStructGetData($tCONSOLE_SCREEN_BUFFER_INFO, "wAttributes") ;// Set the buffer's attributes $aRet = DllCall($hDLLK32, "int", "FillConsoleOutputAttribute", "hwnd", $hConsole, _ "short", $wAttribute, "dword", $dwConSize, "dword", $dwCoord, "int*", 0) $iErr = @error If @error Or UBound($aRet) <> 6 Or $aRet[5] <> $dwConSize Then Return SetError($iErr, 9, 0) ;// Put the cursor at 0,0 or supplied coordinates $aRet = DllCall($hDLLK32, "int", "SetConsoleCursorPosition", "hwnd", _ $hConsole, "dword", $dwCoord) $iErr = @error If @error Or UBound($aRet) <> 3 Or Not $aRet[0] Then Return SetError($iErr, 10, 0) DllClose($hDLLK32) Return SetError(@error, 0, $hConsole) EndFunc ;==>_WinAPI_ClearConsole ; #FUNCTION# ======================================================= ; Name...........: _WinAPI_CursorShowConsole ; Description ...: Show or Hide console cursor, set cursor size ; Syntax.........: _WinAPI_CursorShowConsole($hConsole, $fShow = True, $iSize = Default) ; Parameters ....: $hConsole - Handle to standard output device ; $fShow - Boolean: True - show cursor, False - hide cursor ; $iSize - (Optional) set cursor size 1-100 ; ; Return values .: Success - return previous cursor size ; Failure - return 0, set error and extended ; Author ........: rover ; Modified.......: ; Remarks .......: ; ; Related .......: ; Link ..........; @@MsdnLink@@ SetConsoleCursorInfo / GetConsoleCursorInfo ; Example .......; Yes ; ================================================================== Func _WinAPI_CursorShowConsole($hConsole = -1, $fShow = True, $iSize = Default) If $hConsole = -1 Then Return SetError(1, 1, 0) ;// create console cursor info struct Local $aRet, $iErr Local Const $tagCONSOLE_CURSOR_INFO = "dword dwSize;int bVisible" Local $tCONSOLE_CURSOR_INFO = DllStructCreate($tagCONSOLE_CURSOR_INFO) If @error Then Return SetError(@error, 2, 0) Local $pCONSOLE_CURSOR_INFO = DllStructGetPtr($tCONSOLE_CURSOR_INFO) If @error Then Return SetError(@error, 3, 0) $aRet = DllCall("Kernel32.dll", "int", "GetConsoleCursorInfo", _ "hwnd", $hConsole, "ptr", $pCONSOLE_CURSOR_INFO) $iErr = @error If @error Or UBound($aRet) <> 3 Or Not $aRet[0] Then Return SetError($iErr, 4, 0) Local $iPrevSize = DllStructGetData($tCONSOLE_CURSOR_INFO, "dwSize") If @error Then Return SetError(@error, 5, 0) DllStructSetData($tCONSOLE_CURSOR_INFO, "bVisible", $fShow) If @error Then Return SetError(@error, 6, 0) If Not IsKeyword($iSize) And IsNumber($iSize) Then DllStructSetData($tCONSOLE_CURSOR_INFO, "dwSize", $iSize) If @error Then Return SetError(@error, 7, 0) EndIf DllCall("Kernel32.dll", "int", "SetConsoleCursorInfo", _ "hwnd", $hConsole, "ptr", $pCONSOLE_CURSOR_INFO) $iErr = @error If @error Or UBound($aRet) <> 3 Or Not $aRet[0] Then Return SetError($iErr, 8, 0) Return SetError(@error, 0, $iPrevSize) EndFunc ;==>_WinAPI_CursorShowConsole
    1 point
  11. Scopinho

    AddImageToMenu

    Another DLLCALL.... ENJOY! #include <GUIConstants.au3> Global Const $MF_BYCOMMAND = 0x00000000 Global Const $MF_BYPOSITION = 0x00000400 Global Const $IMAGE_BITMAP = 0 Global Const $LR_LOADMAP3DCOLORS = 0x00001000 Global Const $LR_LOADFROMFILE = 0x0010 GUICreate("AddImageToMenu",100,100,-1,-1,$WS_OVERLAPPEDWINDOW) $trackmenu = GuiCtrlCreateContextMenu() GuiCtrlCreateMenuItem("Item 1",$trackmenu) GuiCtrlCreateMenuItem("Item 2",$trackmenu) GuiCtrlCreateMenuItem("Item 3",$trackmenu) AddImageToMenu($trackmenu, $MF_BYPOSITION, 1, ".\AddImageToMenu.bmp") GUISetState() While GUIGetMsg() <> -3 WEnd Func AddImageToMenu($ParentMenu, $IndexType, $MenuIndex, $BitmapMenu) $hBmpMenu = DllCall("user32.dll", "hwnd", "LoadImage", "hwnd", 0, _ "str", $BitmapMenu, _ "int", $IMAGE_BITMAP, _ "int", 0, _ "int", 0, _ "int", BitOR($LR_LOADFROMFILE, $LR_LOADMAP3DCOLORS)) $hBmpMenu = $hBmpMenu[0] DllCall("user32.dll", "int", "SetMenuItemBitmaps", "hwnd", GUICtrlGetHandle($ParentMenu), _ "int", $MenuIndex, _ "int", $IndexType, _ "hwnd", $hBmpMenu, _ "hwnd", $hBmpMenu) EndFuncAddImageToMenu.au3 AddImageToMenu.bmp
    1 point
×
×
  • Create New...