| View previous topic :: View next topic |
| Author |
Message |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sat Jan 10, 2009 5:57 pm Post subject: Checking a Checkbox's State |
|
|
I'm trying to check a checkbox's state, but it's not working. My code is supposed to recognize when the user clicks on hAuto, and then checks if hSave is set to BST_UNCHECKED. If it is it sets it to BST_CHECKED. Here's my code:
| Code: |
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDC_AUTO_BOX:
switch(HIWORD(wParam)) {
case BN_CLICKED:
UINT ret = SendMessage(hSave, BM_GETCHECK, NULL, NULL);
if(ret == BST_UNCHECKED) {
SendMessage(hSave, BM_SETCHECK,(WPARAM)BST_CHECKED, NULL);
}
break;
}
break;
}
break;
|
So I tested if it was SendMessage so I put in:
| Code: |
MessageBox(NULL, "UNCHECKED", "UNCHECKED", MB_OK);
|
And commented out SendMessage, except the message box comes even if hSave is set to BST_CHECKED. _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Sat Jan 10, 2009 9:44 pm Post subject: |
|
|
made sure that the checkbox...
| Quote: | | BS_AUTOCHECKBOX, BS_AUTORADIOBUTTON, BS_AUTO3STATE, BS_CHECKBOX, BS_RADIOBUTTON, or BS_3STATE style? |
That the hSave is the proper HWND? GetDlgItem (hWnd, ID)? _________________
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat Jan 10, 2009 10:19 pm Post subject: |
|
|
Well for one, take out the switch for BN_CLICKED.
Next I'm pretty sure you should get a compiling error if thats not your last case in the WndProc (except for default) for initiating a variable without braces.
And like kitterz pointed out all the different styles.
Use BS_AUTOCHECKBOX so you don't have to worry about checking them yourself (Unless you are looking to do that manually). _________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sat Jan 10, 2009 10:29 pm Post subject: |
|
|
| lurc wrote: | Well for one, take out the switch for BN_CLICKED.
Next I'm pretty sure you should get a compiling error if thats not your last case in the WndProc (except for default) for initiating a variable without braces.
And like kitterz pointed out all the different styles.
Use BS_AUTOCHECKBOX so you don't have to worry about checking them yourself (Unless you are looking to do that manually). |
I thought I would get a compiling error too, but I didn't so yay lol. And all three of my check boxes are set to BS_AUTOCHECKBOX. I just need to make sure if someone sets the state of hAuto to BST_CHECKED that hSave is also set BST_CHECKED, and if not I have to set it. And may I ask why get rid of the case for BN_CLICKED? _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
b6ooy Grandmaster Cheater
Reputation: 0
Joined: 21 Sep 2006 Posts: 653
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jan 11, 2009 3:02 pm Post subject: |
|
|
IsDlgButtonChecked just uses SendMessage anyway lol. And even if I use IsDlgButtonChecked it stiill fails. _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Sun Jan 11, 2009 4:25 pm Post subject: |
|
|
This should work
| Code: | case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_AUTO_BOX:
if(SendMessage(hSave, BM_GETCHECK, 0, 0) == BST_UNCHECKED)
SendMessage(hSave, BM_SETCHECK, 0, 0);
break;
}
break; |
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jan 11, 2009 4:30 pm Post subject: |
|
|
@TraxMate:
That didn't work  _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Jan 11, 2009 4:49 pm Post subject: |
|
|
If that didn't work then hSave isn't the proper handle.
Make sure you have the proper handle or just use GetDlgItem/SendDlgItemMessage _________________
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sun Jan 11, 2009 8:36 pm Post subject: |
|
|
| lurc wrote: | If that didn't work then hSave isn't the proper handle.
Make sure you have the proper handle or just use GetDlgItem/SendDlgItemMessage |
hSave is completely NULL. I'm assuming that he declared hSave as local and not global, then it's null except when he declares it in WM_CREATE.
He has to use GetDlgItem within the WM_COMMAND
Just do
| Code: | case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_AUTO_BOX:
hSave = GetDlgItem(hwnd, IDC_AUTO_BOX);
if(SendMessage(hSave, BM_GETCHECK, 0, 0) == BST_UNCHECKED)
SendMessage(hSave, BM_SETCHECK, 0, 0);
break;
}
break;
|
_________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jan 11, 2009 9:26 pm Post subject: |
|
|
Thank you blankrider! That worked  _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sun Jan 11, 2009 9:32 pm Post subject: |
|
|
| oib111 wrote: | Thank you blankrider! That worked  |
Just remember that when dealing with messages to windows and controls, you have to use GetDlgItem. Also know that the local variable (in WndProc) will only be declared in that call to the function. Idk if making hSave a global would keep a valid handle, try it? _________________
|
|
| Back to top |
|
 |
|