?
Solved

Problem with comparing variables

Posted on 2006-04-20
5
Medium Priority
?
195 Views
Last Modified: 2010-08-05
I have a STRUCT that looks like this:

      struct ckBoxes
      {
            bool      left;
            bool      right;
            bool      middle;
            bool      none;

      };

one of my variables is:

expected.left = true;

and ...

I need to compare that to a checkbox control:

long lLeft = SendDlgItemMessage( hWndDlg, IDC_CK_LEFT, BM_GETCHECK, 0, 0 );

Question is, how do I see if expected.left = my IDC_CK_LEFT ??

Thanks!
0
Comment
Question by:edvinson
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 16500338
Test the returned value:

if (BST_CHECKED == lLeft && expected.left) {

  // ...
}
0
 
LVL 1

Author Comment

by:edvinson
ID: 16500379
Great! That gets the points, but could you help me with something else real quick...

How would I check lRight lMiddle and lNone too?

Like in one line would be good,

Would this do it:

if (BST_CHECKED == lLeft && expected.left && lRight && expected.right && ....) {

some may be false, like expected.none is almost always false.

0
 
LVL 86

Expert Comment

by:jkr
ID: 16500439
For that you'll neex to query the individual controls, e.g.

if (BST_CHECKED SendDlgItemMessage( hWndDlg, IDC_CK_RIGHT, BM_GETCHECK, 0, 0 ) == && expected.right) {

  // ...
}

if (BST_CHECKED SendDlgItemMessage( hWndDlg, IDC_CK_MIDDLE, BM_GETCHECK, 0, 0 ) == && expected.middle) {

  // ...
}

If none of the three above applies, 'expected.none' is 'true'
0
 
LVL 1

Author Comment

by:edvinson
ID: 16500609
terrific, thanks jkr. top notch answers, as always.
0
 
LVL 86

Expert Comment

by:jkr
ID: 16500768
Except that I forgot the '==' in

if (BST_CHECKED == SendDlgItemMessage( hWndDlg, IDC_CK_RIGHT, BM_GETCHECK, 0, 0 ) == && expected.right) {

  // ...
}

*grmpf*
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question