0
votes

I am getting this warning "warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)" on below line of code :

if (g_objConfigurationDetails.bAutoScan !=  m_objScanNASBtn.GetCheck())
        {
            g_objConfigurationDetails.bAutoScan = m_objScanNASBtn.GetCheck();
}

both the lines are giving the same warning. where bAutoScan = bool m_objScanNASBtn = CButton

3

3 Answers

0
votes

The reason is that MFC's GetCheck doesn't return a bool:

The return value from a button control created with the BS_AUTOCHECKBOX, BS_AUTORADIOBUTTON, BS_AUTO3STATE, BS_CHECKBOX, BS_RADIOBUTTON, or BS_3STATE style is one of the following values:
- BST_UNCHECKED - Button state is unchecked.
- BST_CHECKED - Button state is checked.
- BST_INDETERMINATE - Button state is indeterminate (applies only if the button has the BS_3STATE or BS_AUTO3STATE style).

So you probably want

if (g_objConfigurationDetails.bAutoScan
      != (m_objScanNASBtn.GetCheck() == BST_CHECKED))

or

bool bNASBtnChecked = (m_objScanNASBtn.GetCheck() == BST_CHECKED);
if (g_objConfigurationDetails.bAutoScan != bNASBtnChecked)
{
    g_objConfigurationDetails.bAutoScan = bNASBtnChecked;
}
0
votes

The following:

g_objConfigurationDetails.bAutoScan = m_objScanNASBtn.GetCheck();

should be

g_objConfigurationDetails.bAutoScan = m_objScanNASBtn.GetCheck() == BST_CHECKED;

The problem is GetCheck() doesn't return bool so you have to write a comparison - at least in the form of != 0.

0
votes

GetCheck returns an integer and you're comparing it to a boolean. Try comparing GetCheck to BST_UNCHECKED or BST_CHECKED depending on your boolean value, or just cast it to boolean since the 2 values match true and false numerically.