robertocm Posted May 23, 2021 Posted May 23, 2021 Trying to get a working example from code by funkey: Added declarations from cited references, but the control looks empty, without returning errors: expandcollapse popup#cs ---------------------------------------------------------------------------- funkey, Feb 8, 2012 https://www.autoitscript.com/forum/topic/137333-ragriddll/?do=findComment&comment=961420 RaGrid download: ;KetilO, 2009 ;http://www.asmcommunity.net/forums/topic/?id=29679 Code examples: https://bcxbasiccoders.com/bcxusers/ian/Miscellaneous%20Code.html bcx_raGridWrappers.inc https://maul-esel.github.io/FormsFramework/files/RaGrid/RaGrid-ahk.html ;https://www.purebasic.fr/english/viewtopic.php?t=47141 #ce ---------------------------------------------------------------------------- #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <Color.au3> ; #CONSTANTS# =================================================================================================================== ;gnozal, Aug 11, 2011 ;https://www.purebasic.fr/english/viewtopic.php?t=47141 ;http://www.pbosl.purearea.net/pbosl_examples.zip [in .\pbosl_examples\PBOSL4\EXAMPLES\PBOSL_CreateGadget\ ] ;Messages Global Const $GM_ADDCOL = $WM_USER + 1 ;wParam=0, lParam=lpCOLUMN Global Const $GM_ADDROW = $WM_USER + 2 ;wParam=0, lParam=lpROWDATA (can be NULL) Global Const $GM_INSROW = $WM_USER + 3 ;wParam=nRow, lParam=lpROWDATA (can be NULL) Global Const $GM_DELROW = $WM_USER + 4 ;wParam=nRow, lParam=0 Global Const $GM_MOVEROW = $WM_USER + 5 ;wParam=nFromRow, lParam=nToRow Global Const $GM_COMBOADDSTRING = $WM_USER + 6 ;wParam=nCol, lParam=lpszString Global Const $GM_COMBOCLEAR = $WM_USER + 7 ;wParam=nCol, lParam=0 Global Const $GM_GETCURSEL = $WM_USER + 8 ;wParam=0, lParam=0 Global Const $GM_SETCURSEL = $WM_USER + 9 ;wParam=nCol, lParam=nRow Global Const $GM_GETCURCOL = $WM_USER + 10 ;wParam=0, lParam=0 Global Const $GM_SETCURCOL = $WM_USER + 11 ;wParam=nCol, lParam=0 Global Const $GM_GETCURROW = $WM_USER + 12 ;wParam=0, lParam=0 Global Const $GM_SETCURROW = $WM_USER + 13 ;wParam=nRow, lParam=0 Global Const $GM_GETCOLCOUNT = $WM_USER + 14 ;wParam=0, lParam=0 Global Const $GM_GETROWCOUNT = $WM_USER + 15 ;wParam=0, lParam=0 Global Const $GM_GETCELLDATA = $WM_USER + 16 ;wParam=nRowCol, lParam=lpData Global Const $GM_SETCELLDATA = $WM_USER + 17 ;wParam=nRowCol, lParam=lpData (can be NULL) Global Const $GM_GETCELLRECT = $WM_USER + 18 ;wParam=nRowCol, lParam=lpRECT Global Const $GM_SCROLLCELL = $WM_USER + 19 ;wParam=0, lParam=0 Global Const $GM_GETBACKCOLOR = $WM_USER + 20 ;wParam=0, lParam=0 Global Const $GM_SETBACKCOLOR = $WM_USER + 21 ;wParam=nColor, lParam=0 Global Const $GM_GETGRIDCOLOR = $WM_USER + 22 ;wParam=0, lParam=0 Global Const $GM_SETGRIDCOLOR = $WM_USER + 23 ;wParam=nColor, lParam=0 Global Const $GM_GETTEXTCOLOR = $WM_USER + 24 ;wParam=0, lParam=0 Global Const $GM_SETTEXTCOLOR = $WM_USER + 25 ;wParam=nColor, lParam=0 Global Const $GM_ENTEREDIT = $WM_USER + 26 ;wParam=nCol, lParam=nRow Global Const $GM_ENDEDIT = $WM_USER + 27 ;wParam=nRowCol, lParam=fCancel Global Const $GM_GETCOLWIDTH = $WM_USER + 28 ;wParam=nCol, lParam=0 Global Const $GM_SETCOLWIDTH = $WM_USER + 29 ;wParam=nCol, lParam=nWidth Global Const $GM_GETHDRHEIGHT = $WM_USER + 30 ;wParam=0, lParam=0 Global Const $GM_SETHDRHEIGHT = $WM_USER + 31 ;wParam=0, lParam=nHeight Global Const $GM_GETROWHEIGHT = $WM_USER + 32 ;wParam=0, lParam=0 Global Const $GM_SETROWHEIGHT = $WM_USER + 33 ;wParam=0, lParam=nHeight Global Const $GM_RESETCONTENT = $WM_USER + 34 ;wParam=0, lParam=0 Global Const $GM_COLUMNSORT = $WM_USER + 35 ;wParam=nCol, lParam=0=Ascending, 1=Descending, 2=Invert Global Const $GM_GETHDRTEXT = $WM_USER + 36 ;wParam=nCol, lParam=lpBuffer Global Const $GM_SETHDRTEXT = $WM_USER + 37 ;wParam=nCol, lParam=lpszText Global Const $GM_GETCOLFORMAT = $WM_USER + 38 ;wParam=nCol, lParam=lpBuffer Global Const $GM_SETCOLFORMAT = $WM_USER + 39 ;wParam=nCol, lParam=lpszText Global Const $GM_CELLCONVERT = $WM_USER + 40 ;wParam=nRowCol, lParam=lpBuffer Global Const $GM_RESETCOLUMNS = $WM_USER + 41 ;wParam=0, lParam=0 Global Const $GM_GETROWCOLOR = $WM_USER + 42 ;wParam=nRow, lParam=lpROWCOLOR Global Const $GM_SETROWCOLOR = $WM_USER + 43 ;wParam=nRow, lParam=lpROWCOLOR Global Const $GM_GETCOLDATA = $WM_USER + 44 ;wParam=nCol, lParam=lpCOLUMN ;Column alignment Global Const $GA_ALIGN_LEFT = 0 Global Const $GA_ALIGN_CENTER = 1 Global Const $GA_ALIGN_RIGHT = 2 ;Column types Global Const $TYPE_EDITTEXT = 0 ;String Global Const $TYPE_EDITLONG = 1 ;Long Global Const $TYPE_CHECKBOX = 2 ;Long Global Const $TYPE_COMBOBOX = 3 ;Long Global Const $TYPE_HOTKEY = 4 ;Long Global Const $TYPE_BUTTON = 5 ;String Global Const $TYPE_IMAGE = 6 ;Long Global Const $TYPE_DATE = 7 ;Long Global Const $TYPE_TIME = 8 ;Long Global Const $TYPE_USER = 9 ;0=String, 1 to 512 bytes binary data Global Const $TYPE_EDITBUTTON = 10 ;String ;Column sorting Global Const $SORT_ASCENDING = 0 Global Const $SORT_DESCENDING = 1 Global Const $SORT_INVERT = 2 ;Window styles Global Const $STYLE_NOSEL = 0x1 Global Const $STYLE_NOFOCUS = 0x2 Global Const $STYLE_HGRIDLINES = 0x4 Global Const $STYLE_VGRIDLINES = 0x8 Global Const $STYLE_GRIDFRAME = 0x10 Global Const $STYLE_NOCOLSIZE = 0x20 Global Const $ODT_GRID = 6 ;~ Global Const $PB_EventType_Grid_HeaderClick = 1 ;User clicked header ;~ Global Const $PB_EventType_Grid_ButtonClick = 2 ;Sendt when user clicks the button in a button cell ;~ Global Const $PB_EventType_Grid_CheckClick = 3 ;Sendt when user double clicks the checkbox in a checkbox cell ;~ Global Const $PB_EventType_Grid_ImageClick = 4 ;Sendt when user double clicks the image in an image cell ;~ Global Const $PB_EventType_Grid_BeforeSelChange = 5 ;Sendt when user request a selection change ;~ Global Const $PB_EventType_Grid_AfterSelChange = 6 ;Sendt after a selection change ;~ Global Const $PB_EventType_Grid_BeforeEdit = 7 ;Sendt before the cell edit control shows ;~ Global Const $PB_EventType_Grid_AfterEdit = 8 ;Sendt when the cell edit control is about to close ;~ Global Const $PB_EventType_Grid_BeforeUpdate = 9 ;Sendt before a cell updates grid data ;~ Global Const $PB_EventType_Grid_AfterUpdate = 10 ;Sendt after grid data has been updated ;~ Global Const $PB_EventType_Grid_UserConvert = 11 ;Sendt when user cell needs to be converted. ;funkey, Feb 8, 2012 ;https://www.autoitscript.com/forum/topic/137333-ragriddll/?do=findComment&comment=961420 Global Const $__RAGRIDCONSTANT_DEFAULT_GUI_FONT = 17 Global Const $GN_HEADERCLICK = 1 ;User clicked header Global Const $GN_BUTTONCLICK = 2 ;Sendt when user clicks the button in a button cell Global Const $GN_CHECKCLICK = 3 ;Sendt when user double clicks the checkbox in a checkbox cell Global Const $GN_IMAGECLICK = 4 ;Sendt when user double clicks the image in an image cell Global Const $GN_BEFORESELCHANGE = 5 ;Sendt when user request a selection change Global Const $GN_AFTERSELCHANGE = 6 ;Sendt after a selection change Global Const $GN_BEFOREEDIT = 7 ;Sendt before the cell edit control shows Global Const $GN_AFTEREDIT = 8 ;Sendt when the cell edit control is about to close Global Const $GN_BEFOREUPDATE = 9 ;Sendt before a cell updates grid data Global Const $GN_AFTERUPDATE = 10 ;Sendt after grid data has been updated Global Const $GN_USERCONVERT = 11 ;Sendt when user cell needs to be converted. Global $Form Global $hGrid Global $hLib Global $hFont Global $lf = DllStructCreate($tagLOGFONT) Global Const $IDC_GRID = 101 Global $hWndSaveFocus = 0 ;take a little time to fill grid on startup with a large number Global Const $iRows = 500 Main() Func Main() FormLoad() If @error = 0 Then ;WinFlash($Form) GUIRegisterMsg($WM_NCACTIVATE, "MY_WM_COMMAND") GUIRegisterMsg($WM_NOTIFY, "MY_WM_COMMAND") GUIRegisterMsg($WM_DESTROY, "MY_WM_COMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop ;Case $IDC_GRID ;WinFlash($Form) EndSwitch WEnd GUIRegisterMsg($WM_NCACTIVATE, "") GUIRegisterMsg($WM_NOTIFY, "") GUIRegisterMsg($WM_DESTROY, "") EndIf $lf =0 EndFunc ;==>Main Func FormLoad() Local $wx = 700 Local $wh = 500 $Form = GUICreate("RAGrid Sample Program", $wx, $wh, 0, 0) $hLib = DllOpen(@ScriptDir & "\RAGrid.dll") If $hLib <> -1 Then Local $style = BitOR($WS_CHILD, $WS_VISIBLE, $STYLE_HGRIDLINES, $STYLE_VGRIDLINES, $STYLE_GRIDFRAME, $STYLE_NOSEL) $hGrid = _WinAPI_CreateWindowEx(0, "RAGRID", "", $style, 10, 10, $wx - 15, $wh - 35, $Form, $IDC_GRID) If $hGrid Then GridSetup($hGrid) ColorTheGrid($hGrid, $iRows) EndIf Else MsgBox(266288, "Error", "RaGrid.dll failed to load") GUIDelete($Form) Return SetError(1, 0, 0) EndIf GUISetState(@SW_SHOW) EndFunc ;==>FormLoad Func MY_WM_COMMAND($hWnd, $CBMSG, $wParam, $lParam) Switch $CBMSG Case $WM_NCACTIVATE If Not $wParam Then ; Save control focus $hWndSaveFocus = _WinAPI_GetFocus() ElseIf $hWndSaveFocus Then ; Restore control focus _WinAPI_SetFocus($hWndSaveFocus) $hWndSaveFocus = 0 EndIf Case $WM_NOTIFY ; Process grid notifications Local $pnmh = DllStructCreate("GRIDNOTIFY", $lParam) If DllStructGetData($pnmh, "hwndFrom") = $hGrid Then Switch DllStructGetData($pnmh, "Code") Case $GN_HEADERCLICK ; Sort the grid by column, invert sorting order _SendMessage($hGrid, $GM_COLUMNSORT, DllStructGetData($pnmh, "col"), $SORT_INVERT) ColorTheGrid($hGrid, $iRows) EndSwitch EndIf Case $WM_DESTROY _WinAPI_DeleteObject($hFont) EndSwitch EndFunc ;==>MY_WM_COMMAND Func GridSetup($hWnd) Local $lpzhdrtext, $lpsz, $r, $c, $z Local $col = DllStructCreate("double;double;double;double;double;double;double;double;double;double;double;double") ;Local $col = DllStructCreate("long;long;long;long;long;long;long;long;long;long;long;long") If @error Then MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), Default, "Error in DllStructCreate, Code: " & @error) EndIf For $i = 1 To 5 ; Create and format 5 columns $lpzhdrtext = DllStructCreate("wchar") DllStructSetData($lpzhdrtext, 1, Chr(64 + $i)) DllStructSetData($col, "colwt", 130) DllStructSetData($col, "lpszhdrtext", DllStructGetPtr($lpzhdrtext)) DllStructSetData($col, "halign", $GA_ALIGN_CENTER) DllStructSetData($col, "calign", $GA_ALIGN_CENTER) DllStructSetData($col, "ctype", $TYPE_EDITTEXT) DllStructSetData($col, "ctextmax", 31) DllStructSetData($col, "lpszformat", 0) DllStructSetData($col, "himl", 0) DllStructSetData($col, "hdrflag", 0) _SendMessage($hWnd, $GM_ADDCOL, 0, DllStructGetPtr($col)) Next DllStructSetData($lf, "Height", -12) ; Our grid will use 10 point Arial font DllStructSetData($lf, "FaceName", "Arial") $hFont = _WinAPI_CreateFontIndirect($lf) _SendMessage($hGrid, $WM_SETFONT, $hFont, 0) For $i = 1 To $iRows ; Create 32,765 blank rows _SendMessage($hGrid, $GM_ADDROW, 0, 0) Next For $r = 0 To $iRows - 1; Fill our grid with some data For $c = 0 To 4 $z = String(Random(0, $iRows)) $lpsz = DllStructCreate("char[" & StringLen($z) + 1 & "]") DllStructSetData($lpsz, 1, $z) _SendMessage($hGrid, $GM_SETCELLDATA, _WinAPI_MakeLong($c, $r), DllStructGetPtr($lpsz)) Next Next EndFunc ;==>GridSetup Func ColorTheGrid($hWnd, $Rows) Local $grc = DllStructCreate("double;double") ;Local $grc = DllStructCreate("long;long") DllStructSetData($grc, "backcolor", _MakeRGB(0, 240, 230)) DllStructSetData($grc, "textcolor", 0) For $i = 0 To $Rows - 1 Step 2 _SendMessage($hWnd, $GM_SETROWCOLOR, $i, DllStructGetPtr($grc)) Next DllStructSetData($grc, "backcolor", _MakeRGB(255, 255, 255)) DllStructSetData($grc, "textcolor", 0) For $i = 1 To $Rows Step 2 _SendMessage($hWnd, $GM_SETROWCOLOR, $i, DllStructGetPtr($grc)) Next $grc = 0 EndFunc ;==>ColorTheGrid Func _MakeRGB($b, $g, $r) Local $aRGB[3] $aRGB[0] = $r $aRGB[1] = $g $aRGB[2] = $b Return _ColorSetRGB($aRGB) EndFunc ;==>_MakeRGB
robertocm Posted May 30, 2021 Author Posted May 30, 2021 (edited) Now i'm more interested in trying to understand these examples in the forum for XPTable grid control: .NET GUI XPTABLE Assembly.au3 .NET CLR Danyfirex Examples.au3 / _Example4() ;XPTable Example  Other references: Using C# and VB Code in AutoIt through .NET Framework https://www.autoitscript.com/forum/topic/190490-dotnetau3-udf-to-access-net-framework-from-autoit/ https://www.codeproject.com/Articles/11596/XPTable-NET-ListView-meets-Java-s-JTable https://github.com/schoetbi/XPTable https://www.codeproject.com/Articles/19289/XPTable-NET-ListView-Update https://www.autoitscript.com/forum/topic/187334-using-net-libary-with-autoit-possible/ Edited June 1, 2021 by robertocm Reference added suggested by LarsJ
LarsJ Posted May 30, 2021 Posted May 30, 2021 You can also add Using C# and VB Code in AutoIt through .NET Framework to the list of references above. However, an approach based on one of the options already mentioned is probably both cumbersome and time consuming. An easier solution is to try to simulate a grid control with a listview: Replace the entire row selection with a single cell selection, make it possible to move the selected cell around the listview with the arrow keys and finally make it possible to edit the selected cell. The listview should be a virtual listview with an array as the data source, so that when you edit a listview cell you store the new value directly in the data source. Earthshine and robertocm 2 Controls,  File Explorer,  ROT objects,  UI Automation,  Windows Message MonitorCompiled code: Accessing AutoIt variables,  DotNet.au3 UDF,  Using C# and VB codeShell menus: The Context menu,  The Favorites menu. Shell related: Control Panel,  System Image ListsGraphics related: Rubik's Cube,  OpenGL without external libraries,  Navigating in an image,  Non-rectangular selectionsListView controls: Colors and fonts,  Multi-line header,  Multi-line items,  Checkboxes and icons,  Incremental searchListView controls: Virtual ListViews,  Editing cells,  Data display functions
robertocm Posted May 30, 2021 Author Posted May 30, 2021 Dear LarsJ, Thanks for your articles!! and thanks for your advice.
argumentum Posted May 30, 2021 Posted May 30, 2021 2 hours ago, LarsJ said: simulate a grid control with a listview: Replace the entire row selection with a single cell selection how ?. Can you show a sample code ?  Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
robertocm Posted May 31, 2021 Author Posted May 31, 2021 (edited) an example of editable, single selection by LarsJ: VirtualKeyboard.au3 Around Dec. 2016 this file was include in the zip (i think): https://www.autoitscript.com/forum/topic/182469-using-controls-to-edit-cells-in-a-listview/ Edited May 31, 2021 by robertocm argumentum 1
argumentum Posted May 31, 2021 Posted May 31, 2021 ..did not find that file by Larsj anywhere, or anything that would show how to merge any 2 cels to show as one as the DLL does. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
robertocm Posted May 31, 2021 Author Posted May 31, 2021 I have this file but doesn't think i can upload without permission from the author argumentum 1
Solution Popular Post LarsJ Posted June 3, 2021 Solution Popular Post Posted June 3, 2021 (edited) tst00.au3 and tst00.vb based on DotNetAll.au3 and the techniques of Using C# and VB Code demonstrates how the example for the .NET DataGridView class can be run in an AutoIt script. The VB code in tst00.vb is slightly modified to run the code in AutoIt. See the comments at top and bottom of tst00.vb. tst00.au3 is the AutoIt code which, using DotNetAll.au3, executes the VB code in tst00.vb. Edit a cell: Left-click to select a row. Left-click again to select a cell. Enter/Escape to accept/cancel the text in the edit control. tst00.vb expandcollapse popupImports System 'This line must be added to run the code in AutoIT. Imports System.Drawing Imports System.Windows.Forms Public Class Form1 Inherits System.Windows.Forms.Form Private buttonPanel As New Panel Private WithEvents songsDataGridView As New DataGridView Private WithEvents addNewRowButton As New Button Private WithEvents deleteRowButton As New Button Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As EventArgs) Handles MyBase.Load SetupLayout() SetupDataGridView() PopulateDataGridView() End Sub Private Sub songsDataGridView_CellFormatting(ByVal sender As Object, _ ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) _ Handles songsDataGridView.CellFormatting If e IsNot Nothing Then If Me.songsDataGridView.Columns(e.ColumnIndex).Name = _ "Release Date" Then If e.Value IsNot Nothing Then Try e.Value = DateTime.Parse(e.Value.ToString()).ToLongDateString() e.FormattingApplied = True Catch ex As FormatException Console.WriteLine("{0} is not a valid date.", e.Value.ToString()) End Try End If End If End If End Sub Private Sub addNewRowButton_Click(ByVal sender As Object, _ ByVal e As EventArgs) Handles addNewRowButton.Click Me.songsDataGridView.Rows.Add() End Sub Private Sub deleteRowButton_Click(ByVal sender As Object, _ ByVal e As EventArgs) Handles deleteRowButton.Click If Me.songsDataGridView.SelectedRows.Count > 0 AndAlso _ Not Me.songsDataGridView.SelectedRows(0).Index = _ Me.songsDataGridView.Rows.Count - 1 Then Me.songsDataGridView.Rows.RemoveAt( _ Me.songsDataGridView.SelectedRows(0).Index) End If End Sub Private Sub SetupLayout() Me.Size = New Size(600, 500) With addNewRowButton .Text = "Add Row" .Location = New Point(10, 10) End With With deleteRowButton .Text = "Delete Row" .Location = New Point(100, 10) End With With buttonPanel .Controls.Add(addNewRowButton) .Controls.Add(deleteRowButton) .Height = 50 .Dock = DockStyle.Bottom End With Me.Controls.Add(Me.buttonPanel) End Sub Private Sub SetupDataGridView() Me.Controls.Add(songsDataGridView) songsDataGridView.ColumnCount = 5 With songsDataGridView.ColumnHeadersDefaultCellStyle .BackColor = Color.Navy .ForeColor = Color.White .Font = New Font(songsDataGridView.Font, FontStyle.Bold) End With With songsDataGridView .Name = "songsDataGridView" .Location = New Point(8, 8) .Size = New Size(500, 250) .AutoSizeRowsMode = _ DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single .CellBorderStyle = DataGridViewCellBorderStyle.Single .GridColor = Color.Black .RowHeadersVisible = False .Columns(0).Name = "Release Date" .Columns(1).Name = "Track" .Columns(2).Name = "Title" .Columns(3).Name = "Artist" .Columns(4).Name = "Album" .Columns(4).DefaultCellStyle.Font = _ New Font(Me.songsDataGridView.DefaultCellStyle.Font, FontStyle.Italic) .SelectionMode = DataGridViewSelectionMode.FullRowSelect .MultiSelect = False .Dock = DockStyle.Fill End With End Sub Private Sub PopulateDataGridView() Dim row0 As String() = {"11/22/1968", "29", "Revolution 9", _ "Beatles", "The Beatles [White Album]"} Dim row1 As String() = {"1960", "6", "Fools Rush In", _ "Frank Sinatra", "Nice 'N' Easy"} Dim row2 As String() = {"11/11/1971", "1", "One of These Days", _ "Pink Floyd", "Meddle"} Dim row3 As String() = {"1988", "7", "Where Is My Mind?", _ "Pixies", "Surfer Rosa"} Dim row4 As String() = {"5/1981", "9", "Can't Find My Mind", _ "Cramps", "Psychedelic Jungle"} Dim row5 As String() = {"6/10/2003", "13", _ "Scatterbrain. (As Dead As Leaves.)", _ "Radiohead", "Hail to the Thief"} Dim row6 As String() = {"6/30/1992", "3", "Dress", "P J Harvey", "Dry"} With Me.songsDataGridView.Rows .Add(row0) .Add(row1) .Add(row2) .Add(row3) .Add(row4) .Add(row5) .Add(row6) End With With Me.songsDataGridView .Columns(0).DisplayIndex = 3 .Columns(1).DisplayIndex = 4 .Columns(2).DisplayIndex = 0 .Columns(3).DisplayIndex = 1 .Columns(4).DisplayIndex = 2 End With End Sub <STAThreadAttribute()> _ Public Shared Sub Main() '<STAThreadAttribute()> and the Shared keyword doesn't work in AutoIt. Application.EnableVisualStyles() 'This means that the Main() function here cannot be executed directly. Application.Run(New Form1()) End Sub Public Sub RunMain() 'Add this function to execute Main() in AutoIt. Main() End Sub End Class tst00.au3 #include "DotNetAll.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() Local $oNetCode = DotNet_LoadVBcode( FileRead( "tst00.vb" ), "System.dll | System.Drawing.dll | System.Windows.Forms.dll" ) Local $oForm1 = DotNet_CreateObject( $oNetCode, "Form1" ) $oForm1.RunMain() EndFunc  But I think the code in FirstTest.au3 and the GuiListViewSCN.au3 UDF works better. The code is an attempt to simulate a grid control with a listview. The selected cell is marked in yellow. It can be selected with left-click and moved with the arrow keys, Page Up/Down and Home/End. A double-click or Enter in the selected cell or a double-click in a non-selected cell will start editing the cell. Enter/Escape accepts/cancels the text in the edit control. The GuiListViewSCN.au3 UDF originates from a larger project and is still under development. Therefore, the UDF contains much more code than is needed for this small example. FirstTest.au3 expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=y Opt( "MustDeclareVars", 1 ) ; Official includes #include <GuiEdit.au3> #include <GuiListView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $iRows = 1000, $iCols = 15 ; Rows, Columns Global $idListView, $hListView ; ListView Global $iListViewWidth ; ListView Global $aData[$iRows][$iCols] ; Data ; Cell editing Global $hEdit, $idEditOpen, $idEditClose, $bEditOpen = False, $aEdit[4] Global $bEditOpenOnEnter = True, $bEditOpenOnSpace = False ; Open Edit control on Enter key and/or Space key Global $bEditOpenOnDoubleClick = True ; Open Edit control on double (True) or single (False) click in cell ; Project includes #include "GuiListViewSCN.au3" ; Single Cell Navigation Example() Func Example() ; Fill data For $i = 0 To $iRows - 1 For $j = 0 To $iCols - 1 $aData[$i][$j] = $i & "/" & $j Next Next ; Create GUI Local $iGuiWidth = $iCols * 90 + 40, $iGuiHeight = 788 + 20 Local $hGui = GUICreate( "Simulate Grid Control With ListView", $iGuiWidth, $iGuiHeight ) GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) ; WM_NOTIFY message handler ; Create ListView Default style Select one row Virtual Border $idListView = GUICtrlCreateListView( "", 10, 10, $iGuiWidth-19, $iGuiHeight-20, $GUI_SS_DEFAULT_LISTVIEW-$LVS_SINGLESEL+$LVS_OWNERDATA, $WS_EX_CLIENTEDGE ) GUICtrlSendMsg( $idListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, 0, $LVS_EX_DOUBLEBUFFER+$LVS_EX_FULLROWSELECT+$LVS_EX_GRIDLINES ) $hListView = GUICtrlGetHandle( $idListView ) ; Reduce flicker Highlight entire row Grid lines $iListViewWidth = $iGuiWidth-19-20 ; Header handle Local $hHeader = GUICtrlSendMsg( $idListView, $LVM_GETHEADER, 0, 0 ) ; In a non-resizable GUI, column widths shouldn't be changeable by dragging header dividers ; _WinAPI_SetWindowLong( $hHeader, $GWL_STYLE, _WinAPI_GetWindowLong( $hHeader, $GWL_STYLE ) + $HDS_NOSIZING ) ; AutoIt 3.3.14.5 issue DllCall( "user32.dll", "long_ptr", @AutoItX64 ? "SetWindowLongPtrW" : "SetWindowLongW", "hwnd", $hHeader, "int", $GWL_STYLE, "long_ptr", _ DllCall( "user32.dll", "long_ptr", @AutoItX64 ? "GetWindowLongPtrW" : "GetWindowLongW", "hwnd", $hHeader, "int", $GWL_STYLE )[0] + $HDS_NOSIZING ) ; Add columns Local $tBuffer = DllStructCreate( "wchar Text[10]" ), $pBuffer = DllStructGetPtr( $tBuffer ) Local $tColumn = DllStructCreate( $tagLVCOLUMN ), $pColumn = DllStructGetPtr( $tColumn ) DllStructSetData( $tColumn, "Mask", BitOR( $LVCF_FMT, $LVCF_WIDTH, $LVCF_TEXT ) ) DllStructSetData( $tColumn, "Text", $pBuffer ) DllStructSetData( $tColumn, "CX", 90 ) For $i = 0 To $iCols - 1 DllStructSetData( $tBuffer, "Text", "Col" & $i ) DllStructSetData( $tColumn, "TextMax", 2 * StringLen( "Col" & $i ) + 2 ) GUICtrlSendMsg( $idListView, $LVM_INSERTCOLUMNW, $i, $pColumn ) Next ; Set number of rows GUICtrlSendMsg( $idListView, $LVM_SETITEMCOUNT, $iRows, 0 ) ; Cell editing ; Edit control open and close events $idEditOpen = GUICtrlCreateDummy() $idEditClose = GUICtrlCreateDummy() ; Message handler for the Edit control Local $pEditHandler = DllCallbackGetPtr( DllCallbackRegister( "EditHandler", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) ) ; Enable single cell navigation SCN_SingleCellNavigationEnable( $hGui, $idListView ) ; Show GUI GUISetState( @SW_SHOW ) Local $iRowsVis = GUICtrlSendMsg( $idListView, $LVM_GETCOUNTPERPAGE, 0, 0 ) ; Number of visible rows in ListView ConsoleWrite( "ListView height to fit " & $iRowsVis & " rows = " & _GUICtrlListViewWr_GetHeightToFitRows( $idListView, $iRowsVis ) & @CRLF ) ; Main loop While 1 Switch GUIGetMsg() ; Edit control open event from ListView Case $idEditOpen ; Create Edit control $hEdit = _GUICtrlEdit_Create( $hListView, "", $aEdit[0], $aEdit[1], $aEdit[2] - $aEdit[0], $aEdit[3] - $aEdit[1], $ES_AUTOHSCROLL ) _GUICtrlEdit_SetText( $hEdit, $aData[$SCN_iRowCur][$SCN_iColCur] ) _GUICtrlEdit_SetSel( $hEdit, 0, -1 ) ; Place mouse cursor in middle of Edit control Local $iMouseCoordMode = Opt( "MouseCoordMode", 2 ), $aPos = ControlGetPos( $hGui, "", $idListView ) MouseMove( $aEdit[0]+$aPos[0]+($aEdit[2]-$aEdit[0])/2, $aEdit[1]+$aPos[1]+($aEdit[3]-$aEdit[1])/2+2, 0 ) Opt( "MouseCoordMode", $iMouseCoordMode ) ; Message handler for the Edit control DllCall( "comctl32.dll", "bool", "SetWindowSubclass", "hwnd", $hEdit, "ptr", $pEditHandler, "uint_ptr", 0, "dword_ptr", 0 ) ; $iSubclassId = 0, $pData = 0 ; Set focus to Edit control _WinAPI_SetFocus( $hEdit ) $bEditOpen = True ; Edit control close event Case $idEditClose If Not $bEditOpen Then ContinueLoop If GUICtrlRead( $idEditClose ) Then _ ; Store Edit text $aData[$SCN_iRowCur][$SCN_iColCur] = _GUICtrlEdit_GetText( $hEdit ) ; Delete Edit control DllCall( "comctl32.dll", "bool", "RemoveWindowSubclass", "hwnd", $hEdit, "ptr", $pEditHandler, "uint_ptr", 0 ) ; $iSubclassId = 0 _GUICtrlEdit_Destroy( $hEdit ) $bEditOpen = False Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup ; Disable single cell navigation SCN_SingleCellNavigationDisable() GUIDelete() EndFunc ; Fill in data in virtual ListView. Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) Local $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) Switch HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) Case $hListView Switch DllStructGetData( $tNMHDR, "Code" ) Case $LVN_GETDISPINFOW Local $tDispInfo = DllStructCreate( $tagNMLVDISPINFO, $lParam ) If Not BitAND( DllStructGetData( $tDispInfo, "Mask" ), $LVIF_TEXT ) Then Return 0 Local Static $tText = DllStructCreate( "wchar[50]" ), $pText = DllStructGetPtr( $tText ) DllStructSetData( $tText, 1, $aData[DllStructGetData($tDispInfo,"Item")][DllStructGetData($tDispInfo,"SubItem")] ) DllStructSetData( $tDispInfo, "Text", $pText ) Return 0 EndSwitch EndSwitch Return $GUI_RUNDEFMSG #forceref $hWnd, $iMsg, $wParam EndFunc  The scripts has been tested on Windows 7. All code is contained in GridControls.7z: GridControls.7z  VirtualKeyboard.au3 is contained in ListViewEditingCells.7z: ListViewEditingCells.7z Edited June 3, 2021 by LarsJ Earthshine, argumentum, mLipok and 2 others 5 Controls,  File Explorer,  ROT objects,  UI Automation,  Windows Message MonitorCompiled code: Accessing AutoIt variables,  DotNet.au3 UDF,  Using C# and VB codeShell menus: The Context menu,  The Favorites menu. Shell related: Control Panel,  System Image ListsGraphics related: Rubik's Cube,  OpenGL without external libraries,  Navigating in an image,  Non-rectangular selectionsListView controls: Colors and fonts,  Multi-line header,  Multi-line items,  Checkboxes and icons,  Incremental searchListView controls: Virtual ListViews,  Editing cells,  Data display functions
robertocm Posted June 6, 2021 Author Posted June 6, 2021 I was trying to simulate multi cell selection (sorry for the approach: copy&paste + try&error) expandcollapse popup#cs ---------------------------------------------------------------------------- References: LarsJ, March 22 '17 https://www.autoitscript.com/forum/topic/187622-listview-scroll-event/?do=findComment&comment=1347555 UEZ, Aug 30 '11 https://www.autoitscript.com/forum/topic/132416-winapi-drawing-on-top/?do=findComment&comment=922661 Malkey, March 9 '12 https://www.autoitscript.com/forum/topic/135728-how-to-i-draw-one-rectangle-on-screen/?do=findComment&comment=969520 Melba23, Dec 17 '11 https://www.autoitscript.com/forum/topic/135728-how-to-i-draw-one-rectangle-on-screen/?do=findComment&comment=947685 Help File GUICreate / Extended Style table / $WS_EX_LAYERED / Example 2 A string grid (like a spread sheet) martin, May 2009 #ce ---------------------------------------------------------------------------- #include <GDIPlus.au3> #include <WinAPIConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <GuiListView.au3> #include <WinAPIShellEx.au3> #Include <Misc.au3> Opt("MustDeclareVars", 1) Opt("TrayIconDebug", 1) Opt("MouseCoordMode", 2) Global $iFire = 0 Global $nMsg Global $GuiSizeX = 350, $GuiSizeY = 450 Global $iLvWith = $GuiSizeX - 4, $iLvHeight = 300 Global $sSel, $iFirstRow, $iFirstCol, $iRowsCount, $iColsCount, $iRowHeight, $iColWith = 100 Global $aColNam[3] = ["A", "B", "C"] Global $iX1, $iY1, $iX2, $iY2 Global $hMainGUI = GUICreate("Listview_scroll_event_subclassing_listview_LarsJ", $GuiSizeX, $GuiSizeY) ;GUISetFont(Default, Default, Default, "Segoe UI") Global $idListview = GUICtrlCreateListView("", 2, 2, $iLvWith, $iLvHeight) Global $hListView = GUICtrlGetHandle($idListview) ;GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50) For $i = 0 To 2 _GUICtrlListView_AddColumn($idListview, $aColNam[$i], $iColWith) Next For $i = 0 To 100 GUICtrlCreateListViewItem("a" & $i + 1 & "|b" & $i + 1 & "|c" & $i + 1, $idListview) Next Global $aRect = _GUICtrlListView_GetSubItemRect($idListview, 0, 0) ;MsgBox($MB_SYSTEMMODAL, "Information", StringFormat("Subitem Rectangle : [%d, %d, %d, %d]", $aRect[0], $aRect[1], $aRect[2], $aRect[3])) $iRowHeight = $aRect[3] - $aRect[1] $sSel = "A1" Global $iLbRangeSel = GUICtrlCreateLabel("", 10, $iLvHeight + 80, $GuiSizeX - 20, 60, $SS_CENTER + $SS_CENTERIMAGE) GUICtrlSetBkColor(-1, 0xD8D8D8) GUICtrlSetColor(-1, 0x439467) GUICtrlSetFont(-1, 16, Default, Default, "Segoe UI Light") ;GUICtrlSetCursor(-1, 0) Global $RangeSel = GUICtrlCreateButton("Multi Cell Selection / Region / Drag Area", 10, $iLvHeight + 10, $GuiSizeX - 20, 60) GUICtrlSetFont(-1, 10, Default, Default, "Segoe UI") GUICtrlSetBkColor(-1, 0xFFFFFF) GUICtrlSetCursor(-1, 0) ;Help File / GUICreate / Extended Style table / $WS_EX_LAYERED: [... ] Note that this cannot be used for child windows. ;But in Example 2: Local $hChild = GUICreate("", 210, 72, 20, 15, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hGUI) Global $hChild = GUICreate("Child", $GuiSizeX, $GuiSizeY, 1, 1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TRANSPARENT, $WS_EX_MDICHILD), $hMainGUI) ;Global $hChild = GUICreate("Child", $GuiSizeX, $GuiSizeY, 1, 1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TRANSPARENT, $WS_EX_MDICHILD, $WS_EX_TOPMOST), $hMainGUI) Global $aPos = WinGetPos($hChild) Global $g_iX = $aPos[0] Global $g_iY = $aPos[1] ;MsgBox($MB_SYSTEMMODAL, "", "X-Pos: " & $aPos[0] & @CRLF & "Y-Pos: " & $aPos[1]) _DrawRect($aRect[0], $aRect[1], $iColWith, $iRowHeight) GUISetState(@SW_SHOW, $hChild) ;LarsJ, March 22 '17 ;https://www.autoitscript.com/forum/topic/187622-listview-scroll-event/?do=findComment&comment=1347555 GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW, $hMainGUI) Global $pListViewCallback = DllCallbackGetPtr( DllCallbackRegister( "ListViewCallback", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) ) _WinAPI_SetWindowSubclass( $hListView, $pListViewCallback, 9999, 0 ) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $RangeSel _RangeSelect() EndSwitch WEnd _WinAPI_RemoveWindowSubclass( $hListView, $pListViewCallback, 9999 ) ;Delete the previous GUIs and all controls. GUIDelete($hMainGUI) GUIDelete($hChild) Func ListViewCallback( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData ) Switch $iMsg Case $WM_VSCROLL ConsoleWrite("ListViewCallback WM_VSCROLL" & @CRLF) EndSwitch ; Call next function in subclass chain Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0] #forceref $iSubclassId, $pData EndFunc Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam ConsoleWrite("WM_VSCROLL" & @CRLF) Return $GUI_RUNDEFMSG EndFunc ;==>WM_EXITSIZEMOVE Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Local $tInfo Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Local $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") Local $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $LVN_BEGINSCROLL $iFire += 1 ConsoleWrite("LVN_BEGINSCROLL " & $iFire & @CRLF) ;GUISetState(@SW_HIDE, $hChild) Case $LVN_ENDSCROLL $iFire += 1 ConsoleWrite("LVN_ENDSCROLL " & $iFire & @CRLF) ;GUISetState(@SW_SHOW, $hChild) Case $LVN_BEGINDRAG ; A drag-and-drop operation involving the left mouse button is being initiated $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) _RangeSelect() EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY ;Malkey, March 9 '12 ;https://www.autoitscript.com/forum/topic/135728-how-to-i-draw-one-rectangle-on-screen/?do=findComment&comment=969520 Func _DrawRect($x, $y, $w, $h) Local $hBitmap, $hGraphic Local $hWnd, $hDC, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend, $hPen Local $iOpacity = 255 _GDIPlus_Startup() $hWnd = _WinAPI_GetDC(0) $hDC = _WinAPI_CreateCompatibleDC($hWnd) $hBitmap = _WinAPI_CreateCompatibleBitmap($hWnd, $GuiSizeX, $GuiSizeY) _WinAPI_SelectObject($hDC, $hBitmap) $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC) $hPen = _GDIPlus_PenCreate(0xFF008000, 2) $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", $iLvWith) DllStructSetData($tSize, "Y", $iLvHeight) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", $iOpacity) DllStructSetData($tBlend, "Format", 1) _GDIPlus_GraphicsDrawRect($hGraphic, $x, $y, $w, $h, $hPen) ; <-- Graphics to layered wimdow. _GDIPlus_GraphicsDrawRect($hGraphic, $x + $w - 1, $y + $h - 1, 2, 2, $hPen) _WinAPI_UpdateLayeredWindow($hChild, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _WinAPI_ReleaseDC(0, $hWnd) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hDC) _GDIPlus_Shutdown() EndFunc ;==>_DrawRect Func _RangeSelect() Mark_Rect() ;MsgBox($MB_SYSTEMMODAL, "", StringFormat("[%d, %d, %d, %d]", $iX1, $iY1, $iX2, $iY2)) ;GUISetState(@SW_SHOW, $hChild) ;GUISetState(@SW_SHOW, $hMainGUI) $iFirstCol = Floor($iX1/$iColWith) $iFirstRow = Floor($iY1/$iRowHeight) $iX1 = $iFirstCol * $iColWith $iY1 = $iFirstRow * $iRowHeight $iColsCount = Ceiling(($iX2 - $iX1) / $iColWith) $iRowsCount = Ceiling(($iY2 - $iY1) / $iRowHeight) _DrawRect($iX1, $iY1, $iColsCount * $iColWith, $iRowsCount * $iRowHeight) $sSel = $aColNam[$iFirstCol] & $iFirstRow & ":" & $aColNam[$iFirstCol + $iColsCount - 1] & $iFirstRow + $iRowsCount - 1 & @TAB & $iRowsCount & "R x " & $iColsCount & "C" ;MsgBox($MB_SYSTEMMODAL, "Selection", $sSel) GUICtrlSetData($iLbRangeSel, $sSel) EndFunc ;Melba23, Dec 17 '11 ;https://www.autoitscript.com/forum/topic/135728-how-to-i-draw-one-rectangle-on-screen/?do=findComment&comment=947685 Func Mark_Rect() Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp Local $UserDLL = DllOpen("user32.dll") ; Create transparent GUI with Cross cursor Local $hCross_GUI = GUICreate("Test", $iLvWith, $iLvHeight, $g_iX, $g_iY, $WS_POPUP, $WS_EX_TOPMOST) ;Local $hCross_GUI = GUICreate("Test", @DesktopWidth, @DesktopHeight - 20, 0, 0, $WS_POPUP, $WS_EX_TOPMOST) WinSetTrans($hCross_GUI, "", 8) GUISetState(@SW_SHOW, $hCross_GUI) GUISetCursor(3, 1, $hCross_GUI) Local $hRectangle_GUI = GUICreate("", $iLvWith, $iLvHeight, $g_iX, $g_iY, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) ;Local $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) GUISetBkColor(0x008000) ; Wait until mouse button pressed While Not _IsPressed("01", $UserDLL) Sleep(10) WEnd ; Get first mouse position $aMouse_Pos = MouseGetPos() $iX1 = $aMouse_Pos[0] $iY1 = $aMouse_Pos[1] ; Draw rectangle while mouse button pressed While _IsPressed("01", $UserDLL) $aMouse_Pos = MouseGetPos() $hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0) $hMask = _WinAPI_CreateRectRgn($iX1, $aMouse_Pos[1], $aMouse_Pos[0], $aMouse_Pos[1] + 1) ; Bottom of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($iX1, $iY1, $iX1 + 1, $aMouse_Pos[1]) ; Left of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($iX1 + 1, $iY1 + 1, $aMouse_Pos[0], $iY1) ; Top of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($aMouse_Pos[0], $iY1, $aMouse_Pos[0] + 1, $aMouse_Pos[1]) ; Right of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) ; Set overall region _WinAPI_SetWindowRgn($hRectangle_GUI, $hMaster_Mask) If WinGetState($hRectangle_GUI) < 15 Then GUISetState() Sleep(10) WEnd ; Get second mouse position $iX2 = $aMouse_Pos[0] $iY2 = $aMouse_Pos[1] ; Set in correct order if required If $iX2 < $iX1 Then $iTemp = $iX1 $iX1 = $iX2 $iX2 = $iTemp EndIf If $iY2 < $iY1 Then $iTemp = $iY1 $iY1 = $iY2 $iY2 = $iTemp EndIf GUIDelete($hRectangle_GUI) GUIDelete($hCross_GUI) DllClose($UserDLL) EndFunc ;==>Mark_Rect Â
LarsJ Posted June 6, 2021 Posted June 6, 2021 Take a look at Rectangular Selection in ListView. robertocm 1 Controls,  File Explorer,  ROT objects,  UI Automation,  Windows Message MonitorCompiled code: Accessing AutoIt variables,  DotNet.au3 UDF,  Using C# and VB codeShell menus: The Context menu,  The Favorites menu. Shell related: Control Panel,  System Image ListsGraphics related: Rubik's Cube,  OpenGL without external libraries,  Navigating in an image,  Non-rectangular selectionsListView controls: Colors and fonts,  Multi-line header,  Multi-line items,  Checkboxes and icons,  Incremental searchListView controls: Virtual ListViews,  Editing cells,  Data display functions
robertocm Posted June 13, 2021 Author Posted June 13, 2021 (edited) After reading this tutorial about Dlls by Andreas Karlsson Seems that below fix code for RAGRID control would be working (tested on Windows XP, AutoIt 3.3.14.5) expandcollapse popup#cs ---------------------------------------------------------------------------- funkey, Feb 8, 2012 https://www.autoitscript.com/forum/topic/137333-ragriddll/?do=findComment&comment=961420 RaGrid download: ;KetilO, 2009 ;http://www.asmcommunity.net/forums/topic/?id=29679 Code examples: http://c--sphinx.narod.ru/exampl_e.htm https://maul-esel.github.io/FormsFramework/files/RaGrid/RaGrid-ahk.html https://www.purebasic.fr/english/viewtopic.php?t=47141 https://bcxbasiccoders.com/bcxusers/ian/Miscellaneous%20Code.html bcx_raGridWrappers.inc #ce ---------------------------------------------------------------------------- #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <Color.au3> ; #CONSTANTS# =================================================================================================================== ;gnozal, Aug 11, 2011 ;https://www.purebasic.fr/english/viewtopic.php?t=47141 ;http://www.pbosl.purearea.net/pbosl_examples.zip [in .\pbosl_examples\PBOSL4\EXAMPLES\PBOSL_CreateGadget\ ] ;Messages Global Const $GM_ADDCOL = $WM_USER + 1 ;wParam=0, lParam=lpCOLUMN Global Const $GM_ADDROW = $WM_USER + 2 ;wParam=0, lParam=lpROWDATA (can be NULL) Global Const $GM_INSROW = $WM_USER + 3 ;wParam=nRow, lParam=lpROWDATA (can be NULL) Global Const $GM_DELROW = $WM_USER + 4 ;wParam=nRow, lParam=0 Global Const $GM_MOVEROW = $WM_USER + 5 ;wParam=nFromRow, lParam=nToRow Global Const $GM_COMBOADDSTRING = $WM_USER + 6 ;wParam=nCol, lParam=lpszString Global Const $GM_COMBOCLEAR = $WM_USER + 7 ;wParam=nCol, lParam=0 Global Const $GM_GETCURSEL = $WM_USER + 8 ;wParam=0, lParam=0 Global Const $GM_SETCURSEL = $WM_USER + 9 ;wParam=nCol, lParam=nRow Global Const $GM_GETCURCOL = $WM_USER + 10 ;wParam=0, lParam=0 Global Const $GM_SETCURCOL = $WM_USER + 11 ;wParam=nCol, lParam=0 Global Const $GM_GETCURROW = $WM_USER + 12 ;wParam=0, lParam=0 Global Const $GM_SETCURROW = $WM_USER + 13 ;wParam=nRow, lParam=0 Global Const $GM_GETCOLCOUNT = $WM_USER + 14 ;wParam=0, lParam=0 Global Const $GM_GETROWCOUNT = $WM_USER + 15 ;wParam=0, lParam=0 Global Const $GM_GETCELLDATA = $WM_USER + 16 ;wParam=nRowCol, lParam=lpData Global Const $GM_SETCELLDATA = $WM_USER + 17 ;wParam=nRowCol, lParam=lpData (can be NULL) Global Const $GM_GETCELLRECT = $WM_USER + 18 ;wParam=nRowCol, lParam=lpRECT Global Const $GM_SCROLLCELL = $WM_USER + 19 ;wParam=0, lParam=0 Global Const $GM_GETBACKCOLOR = $WM_USER + 20 ;wParam=0, lParam=0 Global Const $GM_SETBACKCOLOR = $WM_USER + 21 ;wParam=nColor, lParam=0 Global Const $GM_GETGRIDCOLOR = $WM_USER + 22 ;wParam=0, lParam=0 Global Const $GM_SETGRIDCOLOR = $WM_USER + 23 ;wParam=nColor, lParam=0 Global Const $GM_GETTEXTCOLOR = $WM_USER + 24 ;wParam=0, lParam=0 Global Const $GM_SETTEXTCOLOR = $WM_USER + 25 ;wParam=nColor, lParam=0 Global Const $GM_ENTEREDIT = $WM_USER + 26 ;wParam=nCol, lParam=nRow Global Const $GM_ENDEDIT = $WM_USER + 27 ;wParam=nRowCol, lParam=fCancel Global Const $GM_GETCOLWIDTH = $WM_USER + 28 ;wParam=nCol, lParam=0 Global Const $GM_SETCOLWIDTH = $WM_USER + 29 ;wParam=nCol, lParam=nWidth Global Const $GM_GETHDRHEIGHT = $WM_USER + 30 ;wParam=0, lParam=0 Global Const $GM_SETHDRHEIGHT = $WM_USER + 31 ;wParam=0, lParam=nHeight Global Const $GM_GETROWHEIGHT = $WM_USER + 32 ;wParam=0, lParam=0 Global Const $GM_SETROWHEIGHT = $WM_USER + 33 ;wParam=0, lParam=nHeight Global Const $GM_RESETCONTENT = $WM_USER + 34 ;wParam=0, lParam=0 Global Const $GM_COLUMNSORT = $WM_USER + 35 ;wParam=nCol, lParam=0=Ascending, 1=Descending, 2=Invert Global Const $GM_GETHDRTEXT = $WM_USER + 36 ;wParam=nCol, lParam=lpBuffer Global Const $GM_SETHDRTEXT = $WM_USER + 37 ;wParam=nCol, lParam=lpszText Global Const $GM_GETCOLFORMAT = $WM_USER + 38 ;wParam=nCol, lParam=lpBuffer Global Const $GM_SETCOLFORMAT = $WM_USER + 39 ;wParam=nCol, lParam=lpszText Global Const $GM_CELLCONVERT = $WM_USER + 40 ;wParam=nRowCol, lParam=lpBuffer Global Const $GM_RESETCOLUMNS = $WM_USER + 41 ;wParam=0, lParam=0 Global Const $GM_GETROWCOLOR = $WM_USER + 42 ;wParam=nRow, lParam=lpROWCOLOR Global Const $GM_SETROWCOLOR = $WM_USER + 43 ;wParam=nRow, lParam=lpROWCOLOR Global Const $GM_GETCOLDATA = $WM_USER + 44 ;wParam=nCol, lParam=lpCOLUMN ;Column alignment Global Const $GA_ALIGN_LEFT = 0 Global Const $GA_ALIGN_CENTER = 1 Global Const $GA_ALIGN_RIGHT = 2 ;Column types Global Const $TYPE_EDITTEXT = 0 ;String Global Const $TYPE_EDITLONG = 1 ;Long Global Const $TYPE_CHECKBOX = 2 ;Long Global Const $TYPE_COMBOBOX = 3 ;Long Global Const $TYPE_HOTKEY = 4 ;Long Global Const $TYPE_BUTTON = 5 ;String Global Const $TYPE_IMAGE = 6 ;Long Global Const $TYPE_DATE = 7 ;Long Global Const $TYPE_TIME = 8 ;Long Global Const $TYPE_USER = 9 ;0=String, 1 to 512 bytes binary data Global Const $TYPE_EDITBUTTON = 10 ;String ;Column sorting Global Const $SORT_ASCENDING = 0 Global Const $SORT_DESCENDING = 1 Global Const $SORT_INVERT = 2 ;Window styles Global Const $STYLE_NOSEL = 0x1 Global Const $STYLE_NOFOCUS = 0x2 Global Const $STYLE_HGRIDLINES = 0x4 Global Const $STYLE_VGRIDLINES = 0x8 Global Const $STYLE_GRIDFRAME = 0x10 Global Const $STYLE_NOCOLSIZE = 0x20 Global Const $ODT_GRID = 6 ;~ Global Const $PB_EventType_Grid_HeaderClick = 1 ;User clicked header ;~ Global Const $PB_EventType_Grid_ButtonClick = 2 ;Sendt when user clicks the button in a button cell ;~ Global Const $PB_EventType_Grid_CheckClick = 3 ;Sendt when user double clicks the checkbox in a checkbox cell ;~ Global Const $PB_EventType_Grid_ImageClick = 4 ;Sendt when user double clicks the image in an image cell ;~ Global Const $PB_EventType_Grid_BeforeSelChange = 5 ;Sendt when user request a selection change ;~ Global Const $PB_EventType_Grid_AfterSelChange = 6 ;Sendt after a selection change ;~ Global Const $PB_EventType_Grid_BeforeEdit = 7 ;Sendt before the cell edit control shows ;~ Global Const $PB_EventType_Grid_AfterEdit = 8 ;Sendt when the cell edit control is about to close ;~ Global Const $PB_EventType_Grid_BeforeUpdate = 9 ;Sendt before a cell updates grid data ;~ Global Const $PB_EventType_Grid_AfterUpdate = 10 ;Sendt after grid data has been updated ;~ Global Const $PB_EventType_Grid_UserConvert = 11 ;Sendt when user cell needs to be converted. ;funkey, Feb 8, 2012 ;https://www.autoitscript.com/forum/topic/137333-ragriddll/?do=findComment&comment=961420 Global Const $__RAGRIDCONSTANT_DEFAULT_GUI_FONT = 17 Global Const $GN_HEADERCLICK = 1 ;User clicked header Global Const $GN_BUTTONCLICK = 2 ;Sendt when user clicks the button in a button cell Global Const $GN_CHECKCLICK = 3 ;Sendt when user double clicks the checkbox in a checkbox cell Global Const $GN_IMAGECLICK = 4 ;Sendt when user double clicks the image in an image cell Global Const $GN_BEFORESELCHANGE = 5 ;Sendt when user request a selection change Global Const $GN_AFTERSELCHANGE = 6 ;Sendt after a selection change Global Const $GN_BEFOREEDIT = 7 ;Sendt before the cell edit control shows Global Const $GN_AFTEREDIT = 8 ;Sendt when the cell edit control is about to close Global Const $GN_BEFOREUPDATE = 9 ;Sendt before a cell updates grid data Global Const $GN_AFTERUPDATE = 10 ;Sendt after grid data has been updated Global Const $GN_USERCONVERT = 11 ;Sendt when user cell needs to be converted. Global $Form Global $hGrid Global $hLib Global $hFont Global $lf = DllStructCreate($tagLOGFONT) Global Const $IDC_GRID = 101 Global $hWndSaveFocus = 0 ;take a little time to fill grid on startup with a large number Global Const $iRows = 500 Main() Func Main() FormLoad() If @error = 0 Then ;WinFlash($Form) GUIRegisterMsg($WM_NCACTIVATE, "MY_WM_COMMAND") GUIRegisterMsg($WM_NOTIFY, "MY_WM_COMMAND") GUIRegisterMsg($WM_DESTROY, "MY_WM_COMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop ;Case $IDC_GRID ;WinFlash($Form) EndSwitch WEnd GUIRegisterMsg($WM_NCACTIVATE, "") GUIRegisterMsg($WM_NOTIFY, "") GUIRegisterMsg($WM_DESTROY, "") EndIf $lf = 0 EndFunc ;==>Main Func FormLoad() Local $wx = 700 Local $wh = 500 $Form = GUICreate("RAGrid Sample Program", $wx, $wh, 0, 0) $hLib = DllOpen(@ScriptDir & "\RAGrid.dll") If $hLib <> -1 Then Local $style = BitOR($WS_CHILD, $WS_VISIBLE, $STYLE_HGRIDLINES, $STYLE_VGRIDLINES, $STYLE_GRIDFRAME, $STYLE_NOSEL) $hGrid = _WinAPI_CreateWindowEx($WS_EX_CLIENTEDGE, "RAGrid", "", $style, 10, 10, $wx - 15, $wh - 35, $Form, $IDC_GRID) If $hGrid Then GridSetup($hGrid) ColorTheGrid($hGrid, $iRows) EndIf Else MsgBox(266288, "Error", "RaGrid.dll failed to load") GUIDelete($Form) Return SetError(1, 0, 0) EndIf GUISetState(@SW_SHOW) EndFunc ;==>FormLoad Func MY_WM_COMMAND($hWnd, $CBMSG, $wParam, $lParam) Switch $CBMSG Case $WM_NCACTIVATE If Not $wParam Then ; Save control focus $hWndSaveFocus = _WinAPI_GetFocus() ElseIf $hWndSaveFocus Then ; Restore control focus _WinAPI_SetFocus($hWndSaveFocus) $hWndSaveFocus = 0 EndIf Case $WM_NOTIFY ; Process grid notifications Local $pnmh = DllStructCreate("GRIDNOTIFY", $lParam) If DllStructGetData($pnmh, "hwndFrom") = $hGrid Then Switch DllStructGetData($pnmh, "Code") Case $GN_HEADERCLICK ; Sort the grid by column, invert sorting order _SendMessage($hGrid, $GM_COLUMNSORT, DllStructGetData($pnmh, "col"), $SORT_INVERT) ColorTheGrid($hGrid, $iRows) EndSwitch EndIf Case $WM_DESTROY _WinAPI_DeleteObject($hFont) EndSwitch EndFunc ;==>MY_WM_COMMAND Func GridSetup($hWnd) Local $lpzhdrtext, $lpsz, $r, $c, $z Local $col = DllStructCreate("UINT colwt;UINT lpszhdrtext;UINT halign;UINT calign;UINT ctype;UINT ctextmax;UINT lpszformat;UINT himl;UINT hdrflag") If @error Then MsgBox($MB_SYSTEMMODAL, "ERROR", "Error: " & _WinAPI_GetLastErrorMessage()) MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), Default, "Error in DllStructCreate, Code: " & @error) EndIf For $i = 1 To 5 ; Create and format 5 columns $lpzhdrtext = DllStructCreate("wchar[1]") ;$lpzhdrtext = DllStructCreate("char[1]") DllStructSetData($lpzhdrtext, 1, Chr(64 + $i)) DllStructSetData($col, "colwt", 130) DllStructSetData($col, "lpszhdrtext", DllStructGetPtr($lpzhdrtext)) DllStructSetData($col, "halign", $GA_ALIGN_CENTER) DllStructSetData($col, "calign", $GA_ALIGN_CENTER) DllStructSetData($col, "ctype", $TYPE_EDITTEXT) DllStructSetData($col, "ctextmax", 31) DllStructSetData($col, "lpszformat", 0) DllStructSetData($col, "himl", 0) DllStructSetData($col, "hdrflag", 0) _SendMessage($hWnd, $GM_ADDCOL, 0, DllStructGetPtr($col)) Next DllStructSetData($lf, "Height", -12) ; Our grid will use 10 point Arial font If @error Then MsgBox($MB_SYSTEMMODAL, "ERROR", "Error: " & _WinAPI_GetLastErrorMessage()) MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), Default, "Error in DllStructCreate, Code: " & @error) EndIf DllStructSetData($lf, "FaceName", "SEGOE IU") If @error Then MsgBox($MB_SYSTEMMODAL, "ERROR", "Error: " & _WinAPI_GetLastErrorMessage()) MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), Default, "Error in DllStructCreate, Code: " & @error) EndIf $hFont = _WinAPI_CreateFontIndirect($lf) _SendMessage($hGrid, $WM_SETFONT, $hFont, 0) If @error Then MsgBox($MB_SYSTEMMODAL, "ERROR", "Error: " & _WinAPI_GetLastErrorMessage()) MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), Default, "Error in DllStructCreate, Code: " & @error) EndIf For $i = 1 To $iRows ; Create 32,765 blank rows _SendMessage($hGrid, $GM_ADDROW, 0, 0) Next If @error Then MsgBox($MB_SYSTEMMODAL, "ERROR", "Error: " & _WinAPI_GetLastErrorMessage()) MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), Default, "Error in DllStructCreate, Code: " & @error) EndIf For $r = 0 To $iRows - 1; Fill our grid with some data For $c = 0 To 4 $z = String(Random(0, $iRows)) $lpsz = DllStructCreate("char[" & StringLen($z) + 1 & "]") DllStructSetData($lpsz, 1, $z) _SendMessage($hGrid, $GM_SETCELLDATA, _WinAPI_MakeLong($c, $r), DllStructGetPtr($lpsz)) Next Next EndFunc ;==>GridSetup Func ColorTheGrid($hWnd, $Rows) Local $grc = DllStructCreate("UINT backcolor;UINT textcolor") DllStructSetData($grc, "backcolor", _MakeRGB(0, 240, 230)) DllStructSetData($grc, "textcolor", 0) For $i = 0 To $Rows - 1 Step 2 _SendMessage($hWnd, $GM_SETROWCOLOR, $i, DllStructGetPtr($grc)) Next DllStructSetData($grc, "backcolor", _MakeRGB(255, 255, 255)) DllStructSetData($grc, "textcolor", 0) For $i = 1 To $Rows Step 2 _SendMessage($hWnd, $GM_SETROWCOLOR, $i, DllStructGetPtr($grc)) Next $grc = 0 EndFunc ;==>ColorTheGrid Func _MakeRGB($b, $g, $r) Local $aRGB[3] $aRGB[0] = $r $aRGB[1] = $g $aRGB[2] = $b Return _ColorSetRGB($aRGB) EndFunc ;==>_MakeRGB Â Edited June 13, 2021 by robertocm Gianni and pixelsearch 2
Gianni Posted June 13, 2021 Posted June 13, 2021 nice custom control tried it on win10 and AutoIt 3.3.14.5, i used ragrid.dll 2.0.1.5 downloaded from here:https://web.archive.org/web/20131126104818/http://www.oby.ro/rad_asm/projects/projects.html and also with ragrid.dll 2.0.1.6 downloaded from here:https://www.zhaodll.co/plus/download2.php?aid=150211 and it seems to work with both. it would be interesting to have a list of properties and methods. pixelsearch 1 Â Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
dmob Posted June 13, 2021 Posted June 13, 2021 1 hour ago, Chimp said: it would be interesting to have a list of properties and methods Would this be it? Gianni and pixelsearch 1 1
dmob Posted June 15, 2021 Posted June 15, 2021 I found this GRIDNOTIFY structure defined in the RAGrid.inc file, but have NO idea how to define in AutoIt. GRIDNOTIFY struct nmhdr NMHDR <?> col dd ? ;Column row dd ? ;Row hwnd dd ? ;Handle of column edit control lpdata dd ? ;Pointer to data fcancel dd ? ;Set to TRUE to cancel operation GRIDNOTIFY ends Can anyone help please...
FrancescoDiMuro Posted June 15, 2021 Posted June 15, 2021 @dmob Hope this helps you out a little bit: NMHDR; dd (go to the solution). Cheers robertocm 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Â
dmob Posted June 15, 2021 Posted June 15, 2021 (edited) Thank you @FrancescoDiMuro structures are still over my head, and the 2nd link is greek to me.... Does this mean the NMHDR struct is nested inside the GRIDNOTIFY struct? This snippet, from M23's code: ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam) initially seemed to hold a clue, but my head spun as soon as I tried to wrap around it Edited June 15, 2021 by dmob
Earthshine Posted June 15, 2021 Posted June 15, 2021 (edited) yes structures can contain other structures. https://fresh2refresh.com/c-programming/c-nested-structure/#:~:text=C Nested Structure,-Prev Next&text=Nested structure in C is,variable to access the data.  usually it contains POINTERS to other structures but can contain other structures as well Edited June 15, 2021 by Earthshine My resources are limited. You must ask the right questions Â
Gianni Posted June 19, 2021 Posted June 19, 2021 In the linked listing that you see in the first post of this topic you can see an #include "RAGrid_UDF.au3" appearing in the script published that time by @funkey, does anyone know where to get that "RAGrid_UDF.au3"? ... maybe funkey himself still has it somewhere? i think that udf exposes the functions available in Ragrid to be used by AutoIt, something like this (https://github.com/majkinetor/mm-autohotkey/blob/master/RaGrid/RaGrid.ahk) but for AutoIt, or at least I hope so, If anyone has it, they are welcome Thank you dmob 1 Â Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
dmob Posted June 19, 2021 Posted June 19, 2021 Great find @Chimp, exactly what I been searching for. Thank you Now to find that elusive column format string... Gianni 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now