flat assembler
Message board for the users of flat assembler.

Index > Windows > Combobox how change text on sel item ?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 2129
Roman 05 Sep 2026, 18:43
I created combobox and do couple CB_ADDSTRING "name1".
I get three items with text "name1".

I want select some item and rename.
How do this ?
Post 05 Sep 2026, 18:43
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4602
Location: vpcmpistri
bitRAKE 05 Sep 2026, 20:31
Code:
    ; 1. Get the currently selected index
    invoke  SendMessage, [hComboBox], CB_GETCURSEL, 0, 0
    cmp     eax, CB_ERR
    je      .no_selection   ; Exit if nothing is selected
    mov     ebx, eax        ; Save the index in ebx (ensure ebx is preserved if in a stdcall proc)

    ; [Optional] Retrieve item data to preserve it across the recreation
    ; invoke  SendMessage, [hComboBox], CB_GETITEMDATA, ebx, 0
    ; push    eax             ; Temporarily save data on the stack

    ; 2. Delete the old item
    invoke  SendMessage, [hComboBox], CB_DELETESTRING, ebx, 0

    ; 3. Insert the new string at the exact same position
    ; Unlike CB_ADDSTRING, CB_INSERTSTRING bypasses the CBS_SORT style and forces the exact index.
    invoke  SendMessage, [hComboBox], CB_INSERTSTRING, ebx, szNewName

    ; [Optional] Restore the item data to the newly created string
    ; pop     eax
    ; invoke  SendMessage, [hComboBox], CB_SETITEMDATA, ebx, eax

    ; 4. Reselect the item at the index
    invoke  SendMessage, [hComboBox], CB_SETCURSEL, ebx, 0

.no_selection:    
Post 05 Sep 2026, 20:31
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 2129
Roman 06 Sep 2026, 02:57
bitRAKE thanks.
Main goal get name from another combobox or edit.
Code:
;this work good
tmpBufr db 80 dup(0)


macro comboRenameTxt c { local .jj

invoke SendMessage,[c],CB_GETCURSEL,dword 0,0
    cmp     eax, CB_ERR
    je      .jj
mov ebx,eax
invoke SendMessage,[ComboName], WM_GETTEXT,64 ,tmpBufr
invoke SendMessage,[c],CB_DELETESTRING,ebx,0


invoke SendMessage,[c],CB_INSERTSTRING,ebx,tmpBufr
invoke  SendMessage, [c], CB_SETCURSEL, ebx, 0
.jj:
} 
    
Post 06 Sep 2026, 02:57
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 2129
Roman 06 Sep 2026, 04:27
How get CB_DIR ?
And i not found DDL_READONLY value.
Post 06 Sep 2026, 04:27
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4602
Location: vpcmpistri
bitRAKE 06 Sep 2026, 05:24
Code:
CB_DIR        = 0x0145

; Directory Drop List (DDL_) flags used by CB_DIR (ComboBox), LB_DIR (ListBox)
DDL_READWRITE = 0x0000 ; includes files with no additional attributes
DDL_READONLY  = 0x0001
DDL_HIDDEN    = 0x0002
DDL_SYSTEM    = 0x0004
DDL_DIRECTORY = 0x0010
DDL_ARCHIVE   = 0x0020
DDL_DRIVES    = 0x4000 ; includes mapped drives
DDL_EXCLUSIVE = 0x8000 ; only includes files with the specified attributes

section '.data' data readable writeable
    szSearchPattern db 'C:\Windows\*.dll', 0

section '.text' code readable executable
    ; ...
    
    ; Populate combobox with read-only files and archives matching the pattern
    invoke  SendMessage, [hComboBox], CB_DIR, DDL_READONLY or DDL_ARCHIVE, szSearchPattern
    cmp     eax, CB_ERR
    je      .error_invalid_path     ; -1, path was invalid or no files were found
    cmp     eax, CB_ERRSPACE
    je      .error_out_of_memory    ; -2, insufficient memory to store the strings
; if successful, eax contains the zero-based index of the last item added.    
Post 06 Sep 2026, 05:24
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 2129
Roman 06 Sep 2026, 05:47
Thanks.
Post 06 Sep 2026, 05:47
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.