Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing CheckBox Value using USER32 1

Status
Not open for further replies.

dmassey

Programmer
Feb 7, 2003
30
0
0
CA
Hi

I am trying to change the value of a checkbox using the user32 library. I cannot simply use sendkeys to toggle the value of the checkbox because I need to know what the current state is. I tried using sendmessageA from the win32 library, but this only changed the state visually on the screen but does not trigger an event in the program that I am trying to access.

Does anyone know a way of reading the state of a checkbox using user32. I have a handle to the object of type TCheckBox, but I don't know which function to call.

I suspect it is something like
IsDlgButtonChecked(HWND hDlg, int nIDButton);
but I don't know how to get the nIDButton

Thanks
 

dmassey, have you read FAQ222-2244 yet? Especially item 15?

I have used SendMessage to change the value of a check box and it raises the event. Are you using BM_SETSTATE followed by BM_SETCHECK?

Then to retrieve the value I guess you could use BM_GETSTATE, never tried.

Good Luck

 
Thanks, vb5prgrmr

BM_SETSTATE and BM_SETCHECK doesn't work for me, but

I used BM_GETSTATE to get the state and then BM_CLICK to toggle the state if necessary.

Const BM_GETSTATE = &HF2
Const BM_CLICK = &HF5
Const BST_CHECKED = 1
Const BST_UNCHECKED = 0

'set checkbox state to checked
nRtn = SendMessage(HWND, BM_GETSTATE, 0, 0)
If nRtn = BST_UNCHECKED Then
nRtn = SendMessage(HWND, BM_CLICK, 0, 0)
End If

NOTE: Many of the constants are defined in winuser.h
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top