Jump to content
Sign in to follow this  
SlimShady

A favor

Recommended Posts

I have alot of work to do.

I was wondering if someone could make me a UDF that "renames" list box items.

I'll list some information that you'll need.

- GUICtrlRead

- GUICtrlSendMsg with the following messages:

* LB_DELETESTRING message to delete a string in a list box

* LB_ADDSTRING message to add a string to a list box

So:

$oldstring = GUICtrlRead($List_1)

then:

add item $substring + $oldstring

I would really appreciate it.

If not, I'll make it myself when I'm done (4 hours from now).

Edited by SlimShady

Share this post


Link to post
Share on other sites

*busy, busy, busy*

Here's the function:

Func ListItemRename($ListBox, $CurItem, $NewStr)
   Local $LB_DELETESTRING = 0x0182
   Local $LB_INSERTSTRING = 0x0181
   GUICtrlSendMsg($ListBox, $LB_DELETESTRING, $CurItem, 0)
   GUICtrlSendMsg($ListBox, $LB_INSERTSTRING, $CurItem, $NewStr)
EndFunc

Here's a working example:

#include <GUIConstants.au3>
AutoItSetOption("TrayIconDebug", 1)

;Initialize variables
Global $style1
Global $IniFile
Global $GUIWidth
Global $GUIHeight

$GUIWidth = 250
$GUIHeight = 250

GUICreate("New GUI", $GUIWidth, $GUIHeight)

$List_1 = GUICtrlCreateList("", 10, 10, 200, 200)
$Button_1 = GUICtrlCreateButton("OK", 70, 210, 70, 25)

Dim $Items
For $i = 0 To 9
   $Items = $Items & "Item " & $i & "|"
Next
GUICtrlSetData($List_1, $Items)

GUISetState(@SW_SHOW)

While 1
   Sleep(25)
   $msg = GUIGetMsg()
   Select
   
      Case $msg = $GUI_EVENT_CLOSE
         GUIDelete()
         Exit

      Case $msg = $Button_1
         $SelItem = SelectedListItem($List_1)
         If $SelItem Then
            ListItemRename($List_1, $SelItem, "COPIED - " & GUICtrlRead($List_1))
         EndIf
         
   EndSelect

WEnd


Func SelectedListItem($ListBox)
   Local $CurSel
   Local $LB_GETCURSEL = 0x0188
   $CurSel = GUICtrlSendMsg($ListBox, $LB_GETCURSEL, 0, 0)
   If $CurSel < 0 Then $CurSel = 0
   Return $CurSel
EndFunc

Func ListItemRename($ListBox, $CurItem, $NewStr)
   Local $LB_DELETESTRING = 0x0182
   Local $LB_INSERTSTRING = 0x0181
   GUICtrlSendMsg($ListBox, $LB_DELETESTRING, $CurItem, 0)
   GUICtrlSendMsg($ListBox, $LB_INSERTSTRING, $CurItem, $NewStr)
EndFunc

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...