Jump to content

Trouble with DllStruct and LVM_SETITEMTEXT

Recommended Posts

I am pretty sure I have done something wrong, but I can't seem to see what it is. Can anyone point me in the right direction?

$LVITEM = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;char")
$str = DllStructCreate("char[" & StringLen($txt) + 1 & "]")
$ret = dllcall("user32.dll", "int", "SendMessage", "hWnd", $hwnd, "int", $LVM_SETITEMTEXT, "int", $x, "long", DllStructGetPtr($LVITEM))

Just so you know, I do have the right hwnd and item number.

Who else would I be?
Link to comment
Share on other sites

Maybe you aren't setting the correct data in the struct, it seems like you are calling everything using the correct syntax.

Seems like XP and everything before use different structs.

typedef struct _LVITEM { 
    UINT mask; 
    int iItem; 
    int iSubItem; 
    UINT state; 
    UINT stateMask; 
    LPTSTR pszText; 
    int cchTextMax; 
    int iImage; 
    LPARAM lParam;
#if (_WIN32_IE >= 0x0300)
    int iIndent;
#if (_WIN32_IE >= 0x560)
    int iGroupId;
    UINT cColumns; // tile view columns
    PUINT puColumns;

maybe gafrost knows better

Edited by Ejoc
Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Link to comment
Share on other sites

I saw that, but where is _WIN32_IE defined? Where can I find the value for _WIN32_IE?


I think you need a tenth member in your struct

$LVITEM = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int")

LPARAM is a long or int and not char.

Link to comment
Share on other sites

Run this after your dllcall

_GetLastErrorMessage("After DLLCall")

;   _GetLastErrorMessage($DisplayMsgBox="")
;   Format the last windows error as a string and return it
;   if $DisplayMsgBox <> "" Then it will display a message box w/ the error
;   Return      Window's error as a string
Func _GetLastErrorMessage($DisplayMsgBox="")
    Local $ret,$s
    Local $p    = DllStructCreate("char[4096]")
    Local Const $FORMAT_MESSAGE_FROM_SYSTEM     = 0x00001000

    If @error Then Return ""

    $ret    = DllCall("Kernel32.dll","int","GetLastError")

    $ret    = DllCall("kernel32.dll","int","FormatMessage",_
    $s  = DllStructGetData($p,1)
    If $DisplayMsgBox <> "" Then MsgBox(0,"_GetLastErrorMessage",$DisplayMsgBox & @CRLF & $s)
    return $s
Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Link to comment
Share on other sites

#include <GuiConstants.au3>

Global Const $LVM_FIRST = 0x1000
Global Const $LVM_SETITEMTEXTA = ($LVM_FIRST + 46)
Global Const $LVIF_TEXT = 0x1
Global Const $LV_ERR = -1
Global Const $LVS_EX_GRIDLINES = 0x1
Global Const $LVS_EX_REGIONAL = 0x200

opt('MustDeclareVars', 1)
Dim $listview, $Btn_SetItem0, $Btn_Exit, $msg, $Status, $ret, $Btn_SetSub1
GUICreate("ListView Set Item Text", 392, 322)

$listview = GUICtrlCreateListView("col1|col2|col3", 40, 30, 310, 149, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER), BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_REGIONAL))
GUICtrlCreateListViewItem("index 0|data1|more1", $listview)
GUICtrlCreateListViewItem("index 1|data2|more2", $listview)
GUICtrlCreateListViewItem("index 2|data3|more3", $listview)
GUICtrlCreateListViewItem("index 3|data4|more4", $listview)
GUICtrlCreateListViewItem("index 4|data5|more5", $listview)
$Btn_SetItem0 = GUICtrlCreateButton("Set 2 Item", 150, 200, 120, 40)
$Btn_SetSub1 = GUICtrlCreateButton("Set 2 SubItem", 150, 250, 120, 40)
$Btn_Exit = GUICtrlCreateButton("Exit", 300, 260, 70, 30)
$Status = GUICtrlCreateLabel("", 0, 302, 392, 20, BitOR($SS_SUNKEN, $SS_CENTER))

While 1
    $msg = GUIGetMsg()
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
        Case $msg = $Btn_SetItem0
            _GUICtrlListViewSetItemText (ControlGetHandle("ListView Set Item Text","",$listview), 2, 0, "Testing")
        Case $msg = $Btn_SetSub1
            _GUICtrlListViewSetItemText (ControlGetHandle("ListView Set Item Text","",$listview), 2, 1, "Sub")

; Description:          _GUICtrlListViewSetItemText
; Parameter(s):     $h_listview - controlID
;                           $i_index - Zero based index of the item
;                           $i_subitem - Index of the subitem, or it can be zero to set the item label.
;                           $s_text - String containing the new text
; Requirement:          None
; Return Value(s):  1 if successful, 0 if not
;                           If error then $LV_ERR is returned
; User CallTip:     _GUICtrlListViewSetItemText($h_listview, $i_index, $i_subitem, $s_text) Changes the text of a list-view item or subitem. (required: <GuiListView.au3>)
; Author(s):            Gary Frost (custompcs@charter.net)
; Note(s):
Func _GUICtrlListViewSetItemText($h_listview, $i_index, $i_SubItem, $s_text)
    Local $struct = "int;int;int;int;int;ptr;int;int;int;int;int;ptr", $ret
    Local $p = DllStructCreate ($struct)
    If @error Then
        Return $LV_ERR
    Local $sp = DllStructCreate ("char[" & StringLen($s_text) + 1 & "]")
    If @error Then
        DllStructDelete ($p)
        Return $LV_ERR
    DllStructSetData ($sp, 1, $s_text)
    DllStructSetData ($p, 1, $LVIF_TEXT)
    DllStructSetData ($p, 2, $i_index)
    DllStructSetData ($p, 3, $i_SubItem)
    DllStructSetData ($p, 6, DllStructGetPtr ($sp))
    $ret = DllCall("user32.dll","int","SendMessage","hwnd",$h_listview,"int",$LVM_SETITEMTEXTA, "int",$i_index, "ptr", DllStructGetPtr ($p))
    DllStructDelete ($p)
    DllStructDelete ($sp)
    Return $ret[0]
EndFunc ;==>_GUICtrlListViewSetItemText

Cleaned it up

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs


Don't argue with an idiot; people watching may not be able to tell the difference.


Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...