src/video/windows/SDL_windowsmessagebox.c
changeset 11911 235c5929651c
parent 11910 9947d9f539e8
child 11917 5ce3f8bf8381
     1.1 --- a/src/video/windows/SDL_windowsmessagebox.c	Wed Feb 28 02:14:15 2018 -0500
     1.2 +++ b/src/video/windows/SDL_windowsmessagebox.c	Wed Feb 28 10:39:41 2018 -0500
     1.3 @@ -26,7 +26,7 @@
     1.4  
     1.5  #include "SDL_assert.h"
     1.6  #include "SDL_windowsvideo.h"
     1.7 -#include "SDL_windowstaskdialog.h"
     1.8 +
     1.9  
    1.10  #ifndef SS_EDITCONTROL
    1.11  #define SS_EDITCONTROL  0x2000
    1.12 @@ -341,9 +341,8 @@
    1.13      return dialog;
    1.14  }
    1.15  
    1.16 -/* This function is called if a Task Dialog is unsupported. */
    1.17 -static int
    1.18 -WIN_ShowOldMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
    1.19 +int
    1.20 +WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
    1.21  {
    1.22      WIN_DialogData *dialog;
    1.23      int i, x, y;
    1.24 @@ -492,121 +491,6 @@
    1.25      return 0;
    1.26  }
    1.27  
    1.28 -/* TaskDialogIndirect procedure
    1.29 - * This is because SDL targets Windows XP (0x501), so this is not defined in the platform SDK.
    1.30 - */
    1.31 -typedef HRESULT(FAR WINAPI *TASKDIALOGINDIRECTPROC)(const TASKDIALOGCONFIG *pTaskConfig, int *pnButton, int *pnRadioButton, BOOL *pfVerificationFlagChecked);
    1.32 -
    1.33 -int
    1.34 -WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
    1.35 -{
    1.36 -    HWND ParentWindow = NULL;
    1.37 -    wchar_t *wmessage;
    1.38 -    wchar_t *wtitle;
    1.39 -    TASKDIALOGCONFIG TaskConfig;
    1.40 -    TASKDIALOG_BUTTON *pButtons;
    1.41 -    TASKDIALOG_BUTTON *pButton;
    1.42 -    HMODULE hComctl32;
    1.43 -    TASKDIALOGINDIRECTPROC pfnTaskDialogIndirect;
    1.44 -    HRESULT hr;
    1.45 -    int nButton;
    1.46 -    int nCancelButton;
    1.47 -    int i;
    1.48 -
    1.49 -    /* If we cannot load comctl32.dll use the old messagebox! */
    1.50 -    hComctl32 = LoadLibrary(TEXT("Comctl32.dll"));
    1.51 -    if (hComctl32 == NULL) {
    1.52 -        return WIN_ShowOldMessageBox(messageboxdata,buttonid);
    1.53 -    }
    1.54 -    
    1.55 -    /* If TaskDialogIndirect doesn't exist use the old messagebox!
    1.56 -       This will fail prior to Windows Vista.
    1.57 -       The manifest file in the application may require targeting version 6 of comctl32.dll, even
    1.58 -       when we use LoadLibrary here!
    1.59 -       If you don't want to bother with manifests, put this #pragma in your app's source code somewhere:
    1.60 -       pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0'  processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
    1.61 -     */
    1.62 -    pfnTaskDialogIndirect = (TASKDIALOGINDIRECTPROC) GetProcAddress(hComctl32, "TaskDialogIndirect");
    1.63 -    if (pfnTaskDialogIndirect == NULL) {
    1.64 -        FreeLibrary(hComctl32);
    1.65 -        return WIN_ShowOldMessageBox(messageboxdata, buttonid);
    1.66 -    }
    1.67 -
    1.68 -    /* If we have a parent window, get the Instance and HWND for them
    1.69 -       so that our little dialog gets exclusive focus at all times. */
    1.70 -    if (messageboxdata->window) {
    1.71 -        ParentWindow = ((SDL_WindowData *) messageboxdata->window->driverdata)->hwnd;
    1.72 -    }
    1.73 -
    1.74 -    wmessage = WIN_UTF8ToString(messageboxdata->message);
    1.75 -    wtitle = WIN_UTF8ToString(messageboxdata->title);
    1.76 -
    1.77 -    SDL_zero(TaskConfig);
    1.78 -    TaskConfig.cbSize = sizeof (TASKDIALOGCONFIG);
    1.79 -    TaskConfig.hwndParent = ParentWindow;
    1.80 -    TaskConfig.dwFlags = TDF_SIZE_TO_CONTENT;
    1.81 -    TaskConfig.pszWindowTitle = wtitle;
    1.82 -    if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
    1.83 -        TaskConfig.pszMainIcon = TD_ERROR_ICON;
    1.84 -    } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
    1.85 -        TaskConfig.pszMainIcon = TD_WARNING_ICON;
    1.86 -    } else if (messageboxdata->flags & SDL_MESSAGEBOX_INFORMATION) {
    1.87 -        TaskConfig.pszMainIcon = TD_INFORMATION_ICON;
    1.88 -    } else {
    1.89 -        TaskConfig.pszMainIcon = NULL;
    1.90 -    }
    1.91 -
    1.92 -    TaskConfig.pszContent = wmessage;
    1.93 -    TaskConfig.cButtons = messageboxdata->numbuttons;
    1.94 -    pButtons = SDL_malloc(sizeof (TASKDIALOG_BUTTON) * messageboxdata->numbuttons);
    1.95 -    TaskConfig.nDefaultButton = 0;
    1.96 -    for (i = 0; i < messageboxdata->numbuttons; i++)
    1.97 -    {
    1.98 -        pButton = &pButtons[messageboxdata->numbuttons-1-i];
    1.99 -        if (messageboxdata->buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
   1.100 -            nCancelButton = messageboxdata->buttons[i].buttonid;
   1.101 -            pButton->nButtonID = 2;
   1.102 -        } else {
   1.103 -            pButton->nButtonID = messageboxdata->buttons[i].buttonid + 1;
   1.104 -            if (pButton->nButtonID >= 2) {
   1.105 -                pButton->nButtonID++;
   1.106 -            }
   1.107 -        }
   1.108 -        pButton->pszButtonText = WIN_UTF8ToString(messageboxdata->buttons[i].text);
   1.109 -        if (messageboxdata->buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
   1.110 -            TaskConfig.nDefaultButton = pButton->nButtonID;
   1.111 -        }
   1.112 -    }
   1.113 -    TaskConfig.pButtons = pButtons;
   1.114 -
   1.115 -    /* Show the Task Dialog */
   1.116 -    hr = pfnTaskDialogIndirect(&TaskConfig, &nButton, NULL, NULL);
   1.117 -
   1.118 -    /* Free everything */
   1.119 -    FreeLibrary(hComctl32);
   1.120 -    SDL_free(wmessage);
   1.121 -    SDL_free(wtitle);
   1.122 -    for (i = 0; i < messageboxdata->numbuttons; i++) {
   1.123 -        SDL_free((wchar_t *) pButtons[i].pszButtonText);
   1.124 -    }
   1.125 -    SDL_free(pButtons);
   1.126 -
   1.127 -    /* Check the Task Dialog was successful and give the result */
   1.128 -    if (SUCCEEDED(hr)) {
   1.129 -        if (nButton == 2) {
   1.130 -            *buttonid = nCancelButton;
   1.131 -        } else if (nButton > 2) {
   1.132 -            *buttonid = nButton-1-1;
   1.133 -        } else {
   1.134 -            *buttonid = nButton-1;
   1.135 -        }
   1.136 -        return 0;
   1.137 -    }
   1.138 -
   1.139 -    /* We failed showing the Task Dialog, use the old message box! */
   1.140 -    return WIN_ShowOldMessageBox(messageboxdata, buttonid);
   1.141 -}
   1.142 -
   1.143  #endif /* SDL_VIDEO_DRIVER_WINDOWS */
   1.144  
   1.145  /* vi: set ts=4 sw=4 expandtab: */