MFC fetching value
-
Hi, I have placed a Check Box on 1st property page. The propertysheet containing this property page is on the form view of my MDI MFC Appwizaerd Application. I have placed a push button on form view of the application. In its(push buton's) member function, named OnPress, I want to fetch the value of the checkbox of that propertypage. ID of Check Box is IDC_CHECK_SUBFOLDER If I place the code as follows in OnPress member function, I get an access violation error when I run it. (((CButton *)GetDlgItem(IDC_CHECK_SUBFOLDER))->GetCheck() == 1); Please Help me to fetch the value. Drushti
-
Hi, I have placed a Check Box on 1st property page. The propertysheet containing this property page is on the form view of my MDI MFC Appwizaerd Application. I have placed a push button on form view of the application. In its(push buton's) member function, named OnPress, I want to fetch the value of the checkbox of that propertypage. ID of Check Box is IDC_CHECK_SUBFOLDER If I place the code as follows in OnPress member function, I get an access violation error when I run it. (((CButton *)GetDlgItem(IDC_CHECK_SUBFOLDER))->GetCheck() == 1); Please Help me to fetch the value. Drushti
missnazar wrote: (((CButton *)GetDlgItem(IDC_CHECK_SUBFOLDER))->GetCheck() == 1); It's never a good idea to use hard-coded values like this. Compare against
BST_CHECKED
instead. That's not the cause of the access violation, however. Rather than lump all that into one convoluted statement that makes debugging rather difficult, how about breaking it up into something like:CButton *pButton = (CButton *) GetDlgItem(IDC_CHECK_SUBFOLDER);
if (NULL != pButton)
{
if (pButton->GetCheck() == BST_CHECKED)
;
}Now you can get a better idea as to where it's failing.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
-
missnazar wrote: (((CButton *)GetDlgItem(IDC_CHECK_SUBFOLDER))->GetCheck() == 1); It's never a good idea to use hard-coded values like this. Compare against
BST_CHECKED
instead. That's not the cause of the access violation, however. Rather than lump all that into one convoluted statement that makes debugging rather difficult, how about breaking it up into something like:CButton *pButton = (CButton *) GetDlgItem(IDC_CHECK_SUBFOLDER);
if (NULL != pButton)
{
if (pButton->GetCheck() == BST_CHECKED)
;
}Now you can get a better idea as to where it's failing.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
DavidCrow wrote: Rather than lump all that into one convoluted statement that makes debugging rather difficult, how about breaking it up into something like: Once the problem is fixed, would you put the code back to a single line? Whilst it is not as 'nice' to read I imagine it would execute quicker, not that the difference in speed will amount to much anyway. I just wondered what other people thought - more convulated, easier to read/maintain code, or 'many commands nested on one line'. Cheers Angel *********************************************************** The sooner you fall behind, the longer you have to catch up
-
DavidCrow wrote: Rather than lump all that into one convoluted statement that makes debugging rather difficult, how about breaking it up into something like: Once the problem is fixed, would you put the code back to a single line? Whilst it is not as 'nice' to read I imagine it would execute quicker, not that the difference in speed will amount to much anyway. I just wondered what other people thought - more convulated, easier to read/maintain code, or 'many commands nested on one line'. Cheers Angel *********************************************************** The sooner you fall behind, the longer you have to catch up
Angel1058 wrote: Once the problem is fixed, would you put the code back to a single line? I personally would not. Angel1058 wrote: ...I imagine it would execute quicker... True, assuming your stopwatch can measure things in nanoseconds.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow