News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Do i understand this function right?

Started by gavin, July 16, 2005, 02:04:27 PM

Previous topic - Next topic

gavin


invoke SendMessage,hWnd,LB_GETSEL,ecx,0

Will ecx hold the number of the item selected like.
If i clicked item 2 ecx will hold number 2?
Thanks.

hutch--

gavin,

I think you have missed something here, SendMessage() is a general purpose function in Windows to send messages through the system to a window. The window in turn processes the message and responds to it IF it was designed to do so.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

gavin

Hi Hutch.

How would i find which number was selected?
Like so far i'm doing this.


invoke SendMessage,hWnd,LB_GETSEL,ecx,0                                  ;see what was selected
looptop:                                 
cmp ecx,7 ;number of items in listbox
je found
inc ecx
jmp looptop

found:
;code here


Thanks.

Mark Jones

Hi Gavin, the SendMessage API is designed to send a Windows Message with lParam and wParam parameters. Typically this is only used for manipulating the window itself, such as instructing it to close or minimize. If you want to get data from specific controls in that window, that depends on what kind of controls are used but typically SendDlgItemMessage is used. If you want to get the text from a text box, invoke GetDlgItemText. To read checkbox status, try:


    Invoke SendDlgItemMessage, hWnd, IDC_CHK1, BM_GETCHECK, 0, 0
    .if eax == BST_CHECKED


To get make a dropdown list and get it's choice, try this:


.data
    szFirstChoice   db  'First Choice',0
    szSecondChoice  db  'Second Choice',0
    iChoice         db  0
   
.code
; create choices available in combobox
    invoke SendDlgItemMessage, hWnd, IDC_COMBO1, CB_ADDSTRING, 0, addr szFirstChoice
    invoke SendDlgItemMessage, hWnd, IDC_COMBO1, CB_ADDSTRING, 0, addr szSecondChoice
; set default choice
    invoke SendDlgItemMessage, hWnd, IDC_COMBO1, CB_SETCURSEL, 0, 0

; get current (numeric) choice of combobox
    invoke SendDlgItemMessage, hWnd, IDC_COMBO1, CB_GETCURSEL, 0, 0
    mov [iChoice], al
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

gavin

Hi Mark.
Thanks for your detailed reply i will use this information for my next program.

My listbox holds the names of the servers.
But the way i'm doing it is i would click on the first name in the listbox and then it would correspond to my ip address in the data section of my code .

Like

chuckiesserver = 213.40.190.1:22222
otherserver = 213.40.190.1:3333

etc

If you want me to post my code ,beware its a bit long.

Also would the way im doing it ever work?

farrier

gavin,

I would be suspect of your use of hWnd in your SendMessage.  You must use the handle of the ListBox itself not the Hwnd obtained for the program instance!  For instance, hList returned by GetDlgItem for the ListBox item in a Dialog.

Mark Jones suggested the LB_GETCURSEL message to obtain the currently selected item in the ListBox; that is what I would also use.  Remember that the first item will be returned as ecx == 0.

Also, you can watch for LBN_SELCHANGE notification under WM_COMMAND messages when the user chooses an item from the ListBox.  Then use LB_GETCURSEL to check the item selected.  Then if appropriate, close the ListBox and do your thing.

hth,

farrier
It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)

raymond

QuoteMark Jones suggested the LB_GETCURSEL message to obtain the currently selected item in the ListBox; that is what I would also use.  Remember that the first item will be returned as ecx == 0.

According to my interpretation of the APIs, the return value would be in EAX and not in ecx.

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

hutch--

gavin,

Have a look at the early example code in the masm32 samples as there are a number of list box examples.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

gavin

Hey guys thanks to all of you.

My code works now  :U

I use the  LB_GETCURSEL and a few if else statements with ecx .
Thanks

farrier

raymond,

Yes, a stupid mistake!  I had gavin's use of ecx on my mind.

gavin,

The return value from  LB_GETCURSEL--in EAX--should tell exactly what item was selected.  Why do you need "a few if else statements with ecx"?

farrier
It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)

gavin

Hi their.


.elseif uMsg == WM_LBUTTONDBLCLK
           
looptop:       
invoke SendMessage,hWnd,LB_GETCURSEL,0,0




mov eax,OFFSET command             ; pointer as eax
    add eax, 40                     ; increment to the last two zeroes
   
.IF ecx == 0
     mov word ptr [eax], "51"

.ELSEIF ecx == 1
     mov word ptr [eax], "02"
   
.ELSEIF ecx == 2
     mov word ptr [eax], "52"

.ELSEIF ecx == 3
     mov word ptr [eax], "03"

.ELSEIF ecx == 4
     mov word ptr [eax], "53"

.ELSEIF ecx == 5
     mov word ptr [eax], "04"

.ELSEIF ecx == 6
     mov word ptr [eax], "54"
           
.ELSEIF ecx == 7
     mov word ptr [eax], "05"

.ENDIF
Invoke PlaySound, ADDR sound, NULL, SND_FILENAME or SND_ASYNC or SND_LOOP

   
invoke ShellExecute,0,0,ADDR FileName,ADDR command, NULL, SW_SHOWNORMAL

I'm using them to change the last few digits in the  command db "-applaunch 10 +connect 213.40.198.1:2700 ",0

You see my listbox has the names of the servers so i declared the ip's corresponding to them in my data section.
I know where your comming from tho , if the ip's where in the listbox their would be no need.

I hope i'm correct.
Thanks.

Eóin

There is one dodgy bit of that code, you seem to be relying on a value in ecx after the SendMessage call, unfortunately you shouldn't do this because SendMessage is allowed to alter ecx and while it might not appear to be doing so at the moment it might at some future time.

You should either

  • push/pop ecx before/after SendMessage
  • use a memory variable
  • use a reg that won't be modified like ebx

gavin

Ah good point their Eoin.

I'll change this part as soon as possible thanks for the correction.
:U

raymond

gavin

Once more, the return value of
invoke SendMessage,hWnd,LB_GETCURSEL,0,0
is in EAX. If you insist on using ecx in your code it should be as follows:
mov ecx,OFFSET command             ; pointer as ecx
    add ecx, 40                     ; increment to the last two zeroes
   
.IF eax == 0
     mov word ptr [ecx], "51"
.ELSEIF eax == 1
     mov word ptr [ecx], "02"
.....


Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

gavin