Need a reliable error system for win32 gui application

I have a code that looks like this:

void MyClass::OnButtonClick()
{
    int retVal = SomeDialog.DoModal();
    if(retVal == MYCLASS_ERROR)
    {
        MessageBox("Error"...blah ...blah);
    }
    else if(retVal == IDOK)   // IDOK is returned on clicking the 'OK' button
    {
        MessageBox("All is well"...blah ...blah);
    }
}
  • SomeDialogshows only a progress bar. If any error occurs, the progress bar is automatically closed by the call EndDialog(MYCLASS_ERROR). Only upon successful completion will the user be allowed to click OK.
  • MYCLASS_ERROR- value in enum, which contains all types of returned types and statuses.

I found that when I click "OK" in SomeDialogthe error message is still displayed! I went deeper and found that MYCLASS_ERROR= IDOK= 1.

, : , - ? , , any ( ).

, , TRUE FALSE. . .

, !

+5
3

, .

, , , Win32, Win32 ID, , ( , ). , nResult, EndDialog, .

. (, , , , -1 , ).


- , . IDOK. ( ) - IDCANCEL. OnButtonClick , IDOK IDCANCEL. IDCANCEL, -, , .

, . , , (, m_errStatus - -, CDialog):

void MyClass::OnButtonClick()
{
    if (SomeDialog.DoModal() == IDOK)
    {
        // Success!
        // The OK button was clicked, so IDOK was returned.
        MessageBox("All is well"...blah ...blah);
    }
    else
    {
        // Failure!
        // Some error occurred, so IDCANCEL (or any other value) was returned.
        // Determine what to do now, based on additional information that the
        // dialog set upon failure.
        switch (SomeDialog.m_errStatus)
        {
            case MYCLASS_ERROR_1:
                MessageBox("Error 1 occurred.");
                break;
            case MYCLASS_ERROR_2:
                MessageBox("Error 2 occurred.");
                break;
            // etc.
        }
    }
}
+3

, "" Windows. , , Microsoft , .

- :

enum MYERR
{
    MYERR_FIRST_ERROR   = 0x0F000000, /* large and unlikely to be used */
    MYERR_SECOND_ERROR,
    MYERR_THIRD_ERROR,
    /* and so on */
};

, Cody Gray , , DoModal, IDABORT, , , . , , "" .

+1

, . :

namespace boost { namespace math { namespace policies {

enum error_policy_type
{
   throw_on_error = 0, // throw an exception.
   errno_on_error = 1, // set ::errno & return 0, NaN, infinity or best guess.
   ignore_error = 2, // return 0, NaN, infinity or best guess.
   user_error = 3  // call a user-defined error handler.
};

}}} // namespaces
0
source

All Articles