Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Checking a Checkbox's State

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
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?

PostPosted: Sat Jan 10, 2009 5:57 pm    Post subject: Checking a Checkbox's State Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Sat Jan 10, 2009 9:44 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Jan 10, 2009 10:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat Jan 10, 2009 10:29 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
b6ooy
Grandmaster Cheater
Reputation: 0

Joined: 21 Sep 2006
Posts: 653

PostPosted: Sun Jan 11, 2009 3:53 am    Post subject: Reply with quote

Use IsDlgButtonChecked esier Confused
http://msdn.microsoft.com/en-us/library/bb761879(VS.85).aspx
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sun Jan 11, 2009 3:02 pm    Post subject: Reply with quote

b6ooy wrote:
Use IsDlgButtonChecked esier Confused
http://msdn.microsoft.com/en-us/library/bb761879(VS.85).aspx


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
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Sun Jan 11, 2009 4:25 pm    Post subject: Reply with quote

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
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sun Jan 11, 2009 4:30 pm    Post subject: Reply with quote

@TraxMate:

That didn't work Confused

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sun Jan 11, 2009 4:49 pm    Post subject: Reply with quote

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
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Jan 11, 2009 8:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sun Jan 11, 2009 9:26 pm    Post subject: Reply with quote

Thank you blankrider! That worked Smile
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Jan 11, 2009 9:32 pm    Post subject: Reply with quote

oib111 wrote:
Thank you blankrider! That worked Smile


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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites