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?
// 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 */ }
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))
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.)