Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - Issue With CB_GETCURSEL | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
beneficii

Lakitu
Level: 36

Posts: 188/567
EXP: 299656
For next: 8454

Since: 06-27-04
From: Cordova, TN, USA

Since last post: 14 hours
Last activity: 6 hours
Posted on 06-23-05 09:44 PM Link | Quote



(edited by beneficii on 06-23-05 12:45 PM)
(edited by beneficii on 06-23-05 05:58 PM)
sloat

Level: 16

Posts: 63/85
EXP: 18044
For next: 2212

Since: 05-21-04
From: South Central Delaware

Since last post: 19 days
Last activity: 5 hours
Posted on 06-23-05 11:40 PM Link | Quote
you're not wrong. it returns the zero based index. the only reason i can see it would fail is 'combohwnd' isn't valid, but if it was failing, it would return CB_ERR. can you post more of the code?
beneficii

Lakitu
Level: 36

Posts: 192/567
EXP: 299656
For next: 8454

Since: 06-27-04
From: Cordova, TN, USA

Since last post: 14 hours
Last activity: 6 hours
Posted on 06-24-05 04:02 AM Link | Quote
(My posts got deleted. Let me rewrite this one.)

Well, here's the code:

combohwnd is valid, it is the HWND of the combobox in question.

When I send CB_GETCURSEL to it via SendMessage, it always returns zero, zilch, nada, the number 0, regardless of the item currently selected in the combobox. I'm under the impression that it is supposed to return the zero-based index of the currently selected item, but have yet to see any evidence that that is what it does.

The combobox has the styles CB_DROPDOWNLIST | CB_HASSTRINGS | WS_CHILD | WS_VISIBLE.

Also, here is how I write SendMessage:

int index = (int) SendMessage(combohwnd, CB_GETCURSEL, 0, 0);

Is there like a specific place I should put this in the code to make it work? For example, does it only work in certain notifications? Or what is that little detail I'm missing?

EDIT: Well, I figured it out. No declarations should go into the main area of the WndProc! It keeps redeclaring them every time it goes through, deleting all the old values!


(edited by beneficii on 06-23-05 07:04 PM)
(edited by beneficii on 06-23-05 07:34 PM)
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 5216/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 06-24-05 05:20 AM Link | Quote
Yeah, I think you'd have to declare them as static (if you can even do that in C?) or just globally. Local variables don't retain their values.
beneficii

Lakitu
Level: 36

Posts: 193/567
EXP: 299656
For next: 8454

Since: 06-27-04
From: Cordova, TN, USA

Since last post: 14 hours
Last activity: 6 hours
Posted on 06-24-05 06:23 PM Link | Quote
Originally posted by HyperHacker
Yeah, I think you'd have to declare them as static (if you can even do that in C?) or just globally. Local variables don't retain their values.


Yeah, but I can't really declare an HWND static when I need to get its value from under the WM_CREATE notification returned from a CreateWindowEx function. I just hope to be able to remember not to declare my dynamic variables at the beginning of the WndProc, because Windows keeps calling that function.

You can declare variables static in C, but in C it's called declaring them const. To declare, say, a const char array (i.e. string static), you do:

const char mystring[] = "watashino sutoriinguwa kawaii da!";

Because it's const, you don't have to specify the number of characters in the array (plus the null character), as the compiler does that for you. In C, strings are always char arrays.


(edited by beneficii on 06-24-05 09:29 AM)
(edited by beneficii on 06-24-05 09:29 AM)
sloat

Level: 16

Posts: 64/85
EXP: 18044
For next: 2212

Since: 05-21-04
From: South Central Delaware

Since last post: 19 days
Last activity: 5 hours
Posted on 06-24-05 11:11 PM Link | Quote
static and const aren't the same thing. static variables are essentially global variables with a local scope. and yes, C does support the static keyword.

You could keep the variable in WndProc if you create all of your child windows under the WM_CREATE message of the parent.

Another way you could keep track of the child windows would be to specify a control id. Pass a unique number in the hMenu param of CreateWindowEx, and then you can reference that control like a control on a Dialog -- via GetDlgItem, SendDlgItemMessage, etc.
beneficii

Lakitu
Level: 36

Posts: 195/567
EXP: 299656
For next: 8454

Since: 06-27-04
From: Cordova, TN, USA

Since last post: 14 hours
Last activity: 6 hours
Posted on 06-24-05 11:38 PM Link | Quote
Originally posted by sloat
static and const aren't the same thing. static variables are essentially global variables with a local scope. and yes, C does support the static keyword.

You could keep the variable in WndProc if you create all of your child windows under the WM_CREATE message of the parent.

Another way you could keep track of the child windows would be to specify a control id. Pass a unique number in the hMenu param of CreateWindowEx, and then you can reference that control like a control on a Dialog -- via GetDlgItem, SendDlgItemMessage, etc.


Right, I know about that, but I prefer to do the HWND check (by comparing the HWND to the lParam), since the HWND is already there.

I never worked with static variables before. Thanks for the explanation!


(edited by beneficii on 06-24-05 02:39 PM)
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Programming - Issue With CB_GETCURSEL | |


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.006 seconds.