John Noa
John Noa

Reputation: 45

Message boxes with Windows 7 look-and-feel

I reared this MSDN article about customizing design of message boxes:

User Interface Text

and native message boxes looks like this:

but my messagebox looks like this:

and here is what I want:

I'm using C++ and here is my code (the one for confirmation of exit message):

int ccm()
{
    int msgbox = MessageBox(
        NULL,
        (LPCWSTR)L"Do you really want to quit?",
        (LPCWSTR)L"Music",
        MB_ICONQUESTION  | MB_YESNO | MB_DEFBUTTON2
    );

    switch (msgbox)
    {
        case IDYES:
            initdw();
            break;
        case IDNO:
            adw();
            break;
    }

    return msgbox;
}

I call the ccm(); when the user want to exit and I detect it like that

case WM_CLOSE:
    ccm();
    return 0;

but I want the code that looks like original windows style I don't want to design custom messages I want native code

Upvotes: 3

Views: 1864

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 595971

The kind of customization you are looking for can be achieved by using TaskDialog() or TaskDialogIndirect(), instead of MessageBox(). They are the preferred message box functions on Vista and later versions of Windows, because they are more flexible and they make more use of standardized Windows UI elements for a more consistent look with other UIs.

For example:

TaskDialog(hMyWnd, hInstance, L"Music", L"You have the latest version of Music", NULL, TDCBF_OK_BUTTON, MAKEINTRESOURCE(MY_MUSIC_ICON_ID), NULL);

int iBtn = IDNO;
if (TaskDialog(hMyWnd, NULL, L"Music", L"Do you really want to quit?", NULL, TDCBF_YES_BUTTON | TDCBF_NO_BUTTON, NULL, &iBtn) == S_OK)
{
    switch (iBtn)
    {
        case IDYES:
            initdw();
            break;
        case IDNO:
            adw();
            break;
    }
}

Upvotes: 6

Related Questions