win32 - how can i add 1 flag to messagebox return value?

the messagebox() returns a number between 1 and 11.
my own messagebox have the checkbox. it returns the standard messagebox values. but if i need use another value for tell me if the checkbox is checked, how can i do it?
1
2
3
4
5
6
7
8
9
int a=::MessageBox(parent,text.c_str(),title.c_str(), flags);
    if(blnMessageBoxCheckBox==true)
        a|=16;
//how i test it:
int a = MessageBox("hi","hello world" , MB_OKCANCEL, MB_EX_MODAL| MB_EX_PARENTCENTER | MB_EX_CHECKEDBOX,"check me, please...");
        if(a & 16 )
            MessageBox("UnChecked");
        else
            MessageBox("Checked");

can anyone advice me?
imagine if the user checks the checkedbox and clicks on OK button.... how can i add these values on a for test it?
1
2
3
4
5
6
7
8
// Using magic numbers:
//   (bad because you have to memorize the numerical values, and it makes them
//    extremely difficult to change if you want to change them later)

int a = MessageBox( /*...*/ );

if(a & 0x10)            { /*checked */      }
if((a & 0x0F) == MB_OK) { /* OK pressed */  }


1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Using constants:

enum MbMasks
{
    retcode = 0x0F,     // %00001111
    checked = 0x10      // %00010000
};

// ...

MbMasks a = MessageBox( /*...*/ );

if( a & MbMasks::checked )              { /* checked */     }
if( (a & MbMasks::retcode) == MB_OK )   { /* OK pressed */  }


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Using a data structure

struct MbOut
{
    int retcode;
    bool checked;
};

// ...

MbOut a = MessageBox( /*...*/ );

if( a.checked )             { /* checked */     }
if( a.retcode == MB_OK )    { /* OK pressed */  }


// note you don't always have to create an instance:

if( MessageBox(/*...*/).retcode == MB_OK )
{
    /* OK pressed */
}
Last edited on
thanks. give me another advice see my messagebox header:

int MessageBox(string text, string title="",UINT flags=MB_OK, UINT ExtendedFlags=MB_EX_NONE, string checkedtitle="&Don't show me again!!!")

thinking on what the user can use, on messagebox, and it's order, the checkedtitle is the best for the end of header?
(do¡ng in these way, we can add a checkbox without a text\caption(checkedtitle+ MB_EX_CHECKBOX flag))
Last edited on
Ad it's your own function, with extra parameters, it might be better to return the additional information using an out parameter rather than trying to wedge them through the return code.

This approach would also be more future proof as it could be extended to handle more than one additional control.

It would also make it safer to swap between your MessageBox function and the usual one as they both handle return codes is the same way (no need to mask them or whatever.)

Andy

PS Might be better with a different name?
Last edited on
sorry, if is another name. like think more keywords for be diferent than other languages, so it will be more difulty to learn all :P
Topic archived. No new replies allowed.