Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3670
Number of posts: 9122

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Combo-box data... what am I missing ??? Posted by chick80 on 16 Nov 2003 at 4:48 AM
I want to add some data to the items of a combobox.

I use:

SendDlgItemMessage(hDlg, IDC_ANILIST, CB_SETITEMDATA, (WPARAM)num, (LPARAM)i);


where num is the index of the item and i is a value I want to attach to it.

This seems not to work, because when I use CB_GETITEMDATA I always obtain 0, everything I put in i.

Pheraphs I have to set some combo-box style to use user data??? (it's a normal combo-box, no owner-drawn or things like that).

nICO



How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.
JOHN KEATS

Report
Re: Combo-box data... what am I missing ??? Posted by pingpong on 16 Nov 2003 at 5:44 AM
It should work fine. You dont need to set any styles.

Show us some code.

: I want to add some data to the items of a combobox.
:
: I use:
:
:
: SendDlgItemMessage(hDlg, IDC_ANILIST, CB_SETITEMDATA, (WPARAM)num, (LPARAM)i);
: 

:
: where num is the index of the item and i is a value I want to attach to it.
:
: This seems not to work, because when I use CB_GETITEMDATA I always obtain 0, everything I put in i.
:
: Pheraphs I have to set some combo-box style to use user data??? (it's a normal combo-box, no owner-drawn or things like that).
:
: nICO
:
:

: How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.
: JOHN KEATS
:
:

Report
Re: Combo-box data... what am I missing ??? Posted by chick80 on 16 Nov 2003 at 6:08 AM
This message was edited by chick80 at 2003-11-16 6:9:21

: It should work fine. You dont need to set any styles.
:
: Show us some code.
:

There's not much to show... here it is:

SendDlgItemMessage(hDlg, IDC_ANILIST, CB_ADDSTRING, 0, (LPARAM)"X Position");
int num = (int)SendDlgItemMessage(hDlg, IDC_ANILIST, CB_GETCOUNT, 0, 0);
SendDlgItemMessage(hDlg, IDC_ANILIST, CB_SETITEMDATA, (WPARAM) num, 5);

SendDlgItemMessage(hDlg, IDC_ANILIST, CB_SETCURSEL, 0, 0);

sel = (int)SendDlgItemMessage(hDlg, IDC_ANILIST, CB_GETITEMDATA, 0, 0);
// sel should be 5, but it is 0... I cannot understand why.




How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.
JOHN KEATS

Report
Re: Combo-box data... what am I missing ??? Posted by chick80 on 16 Nov 2003 at 6:23 AM
Ok, I found the error myself... it was really a stupid thing.
:
: SendDlgItemMessage(hDlg, IDC_ANILIST, CB_ADDSTRING, 0, (LPARAM)"X Position");
: int num = (int)SendDlgItemMessage(hDlg, IDC_ANILIST, CB_GETCOUNT, 0, 0)-1;
: SendDlgItemMessage(hDlg, IDC_ANILIST, CB_SETITEMDATA, (WPARAM) num, 5);
: 
: SendDlgItemMessage(hDlg, IDC_ANILIST, CB_SETCURSEL, 0, 0);
: 
: sel = (int)SendDlgItemMessage(hDlg, IDC_ANILIST, CB_GETITEMDATA, 0, 0);
: // sel should be 5, but it is 0... I cannot understand why.
: 

:
:

: How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.
: JOHN KEATS
:
:




How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.
JOHN KEATS


Report
Re: Combo-box data... what am I missing ??? Posted by AsmGuru62 on 17 Nov 2003 at 7:30 AM
: Ok, I found the error myself... it was really a stupid thing.
: :
: : SendDlgItemMessage(hDlg, IDC_ANILIST, CB_ADDSTRING, 0, (LPARAM)"X Position");
: : int num = (int)SendDlgItemMessage(hDlg, IDC_ANILIST, CB_GETCOUNT, 0, 0)-1;
: : SendDlgItemMessage(hDlg, IDC_ANILIST, CB_SETITEMDATA, (WPARAM) num, 5);
: : 
: : SendDlgItemMessage(hDlg, IDC_ANILIST, CB_SETCURSEL, 0, 0);
: : 
: : sel = (int)SendDlgItemMessage(hDlg, IDC_ANILIST, CB_GETITEMDATA, 0, 0);
: : // sel should be 5, but it is 0... I cannot understand why.
: : 

: :
: :

: : How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.
: : JOHN KEATS
: :
: :
:
:
:

: How beautiful, if Sorrow had not made sorrow more beautiful than Beauty itself.
: JOHN KEATS
:
:
:
This will work only on combo-lists which are not sortable, but sortable list items will contain incorrect values. The better way to do it is to use the index returned by CB_ADDSTRING message and use it as WPARAM inside CB_SETITEMDATA. It is also faster, because you do not need the CB_GETCOUNT now. This technique also applies to a list box.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.