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
  
User name:
Password:
Reply:
 

UserPost
beneficii
Posts: 195/567
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!
sloat
Posts: 64/85
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
Posts: 193/567
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.
HyperLamer
Posts: 5216/8210
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
Posts: 192/567
(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!
sloat
Posts: 63/85
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
Posts: 188/567
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.011 seconds.