ntdll: Use cpu_info to check for AVX availability.
[wine.git] / dlls / shlwapi / msgbox.c
bloba03cf411c72734070a8d0cb4898dfdfc17f86797
1 /*
2 * SHLWAPI message box functions
4 * Copyright 2004 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <string.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "winreg.h"
28 #include "shlwapi.h"
29 #include "wine/debug.h"
30 #include "resource.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(shell);
35 extern HINSTANCE shlwapi_hInstance; /* in shlwapi_main.c */
37 static const WCHAR szDontShowKey[] = { 'S','o','f','t','w','a','r','e','\\',
38 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
39 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
40 'E','x','p','l','o','r','e','r','\\','D','o','n','t','S','h','o','w',
41 'M','e','T','h','i','s','D','i','a','l','o','g','A','g','a','i','n','\0'
44 INT_PTR WINAPI SHMessageBoxCheckExW(HWND,HINSTANCE,LPCWSTR,DLGPROC,LPARAM,INT_PTR,LPCWSTR);
45 INT_PTR WINAPI SHMessageBoxCheckW(HWND,LPCWSTR,LPCWSTR,DWORD,INT_PTR,LPCWSTR);
47 /* Data held by each general message boxes */
48 typedef struct tagDLGDATAEX
50 DLGPROC dlgProc; /* User supplied DlgProc */
51 LPARAM lParam; /* User supplied LPARAM for dlgProc */
52 LPCWSTR lpszId; /* Name of reg key holding whether to skip */
53 } DLGDATAEX;
55 /* Dialogue procedure for general message boxes */
56 static INT_PTR CALLBACK SHDlgProcEx(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
58 DLGDATAEX *d = (DLGDATAEX *)GetWindowLongPtrW(hDlg, DWLP_USER);
60 TRACE("(%p,%u,%ld,%ld) data %p\n", hDlg, uMsg, wParam, lParam, d);
62 switch (uMsg)
64 case WM_INITDIALOG:
66 /* FIXME: Not sure where native stores its lParam */
67 SetWindowLongPtrW(hDlg, DWLP_USER, lParam);
68 d = (DLGDATAEX *)lParam;
69 TRACE("WM_INITDIALOG: %p, %s,%p,%p\n", hDlg, debugstr_w(d->lpszId),
70 d->dlgProc, (void*)d->lParam);
71 if (d->dlgProc)
72 return d->dlgProc(hDlg, uMsg, wParam, d->lParam);
73 return TRUE;
76 case WM_COMMAND:
77 switch (LOWORD(wParam))
79 case IDYES:
80 wParam = MAKELONG(IDOK, HIWORD(wParam));
81 /* Fall through ... */
82 case IDNO:
83 if (LOWORD(wParam) == IDNO)
84 wParam = MAKELONG(IDCANCEL, HIWORD(wParam));
85 /* Fall through ... */
86 case IDOK:
87 case IDCANCEL:
89 TRACE("WM_COMMAND: id=%s data=%p\n",
90 LOWORD(wParam) == IDOK ? "IDOK" : "IDCANCEL", d);
92 if (SendMessageW(GetDlgItem(hDlg, IDC_ERR_DONT_SHOW), BM_GETCHECK, 0L, 0L))
94 DWORD dwZero = 0;
96 /* The user clicked 'don't show again', so set the key */
97 SHRegSetUSValueW(szDontShowKey, d->lpszId, REG_DWORD, &dwZero,
98 sizeof(dwZero), SHREGSET_DEFAULT);
100 if (!d->dlgProc || !d->dlgProc(hDlg, uMsg, wParam, lParam))
101 EndDialog(hDlg, wParam);
102 return TRUE;
104 break;
106 default:
107 break;
110 if (d && d->dlgProc)
111 return d->dlgProc(hDlg, uMsg, wParam, lParam);
112 return FALSE;
115 /*************************************************************************
116 * @ [SHLWAPI.291]
118 * Pop up a 'Don't show this message again' dialogue box.
120 * PARAMS
121 * hWnd [I] Window to be the dialogues' parent
122 * hInst [I] Instance of the module holding the dialogue resource
123 * lpszName [I] Resource Id of the dialogue resource
124 * dlgProc [I] Dialog procedure, or NULL for default handling
125 * lParam [I] LPARAM to pass to dlgProc
126 * iRet [I] Value to return if dialogue is not shown
127 * lpszId [I] Name of registry subkey which determines whether to show the dialog
129 * RETURNS
130 * Success: The value returned from the dialogue procedure.
131 * Failure: iRet, if the dialogue resource could not be loaded or the dialogue
132 * should not be shown.
134 * NOTES
135 * Both lpszName and lpszId must be less than MAX_PATH in length.
137 INT_PTR WINAPI SHMessageBoxCheckExA(HWND hWnd, HINSTANCE hInst, LPCSTR lpszName,
138 DLGPROC dlgProc, LPARAM lParam, INT_PTR iRet,
139 LPCSTR lpszId)
141 WCHAR szNameBuff[MAX_PATH], szIdBuff[MAX_PATH];
142 LPCWSTR szName = szNameBuff;
144 if (IS_INTRESOURCE(lpszName))
145 szName = (LPCWSTR)lpszName; /* Resource Id or NULL */
146 else
147 MultiByteToWideChar(CP_ACP, 0, lpszName, -1, szNameBuff, MAX_PATH);
149 MultiByteToWideChar(CP_ACP, 0, lpszId, -1, szIdBuff, MAX_PATH);
151 return SHMessageBoxCheckExW(hWnd, hInst, szName, dlgProc, lParam, iRet, szIdBuff);
154 /*************************************************************************
155 * @ [SHLWAPI.292]
157 * Unicode version of SHMessageBoxCheckExW.
159 INT_PTR WINAPI SHMessageBoxCheckExW(HWND hWnd, HINSTANCE hInst, LPCWSTR lpszName,
160 DLGPROC dlgProc, LPARAM lParam, INT_PTR iRet, LPCWSTR lpszId)
162 DLGDATAEX d;
164 if (!SHRegGetBoolUSValueW(szDontShowKey, lpszId, FALSE, TRUE))
165 return iRet;
167 d.dlgProc = dlgProc;
168 d.lParam = lParam;
169 d.lpszId = lpszId;
170 return DialogBoxParamW(hInst, lpszName, hWnd, SHDlgProcEx, (LPARAM)&d);
173 /* Data held by each shlwapi message box */
174 typedef struct tagDLGDATA
176 LPCWSTR lpszTitle; /* User supplied message title */
177 LPCWSTR lpszText; /* User supplied message text */
178 DWORD dwType; /* Message box type */
179 } DLGDATA;
181 /* Dialogue procedure for shlwapi message boxes */
182 static INT_PTR CALLBACK SHDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
184 TRACE("(%p,%u,%ld,%ld)\n", hDlg, uMsg, wParam, lParam);
186 switch (uMsg)
188 case WM_INITDIALOG:
190 DLGDATA *d = (DLGDATA *)lParam;
191 TRACE("WM_INITDIALOG: %p, %s,%s,%d\n", hDlg, debugstr_w(d->lpszTitle),
192 debugstr_w(d->lpszText), d->dwType);
194 SetWindowTextW(hDlg, d->lpszTitle);
195 SetWindowTextW(GetDlgItem(hDlg, IDS_ERR_USER_MSG), d->lpszText);
197 /* Set buttons according to dwType */
198 switch (d->dwType)
200 case 0:
201 ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_HIDE);
202 /* FIXME: Move OK button to position of the Cancel button (cosmetic) */
203 case 1:
204 ShowWindow(GetDlgItem(hDlg, IDYES), SW_HIDE);
205 ShowWindow(GetDlgItem(hDlg, IDNO), SW_HIDE);
206 break;
207 default:
208 ShowWindow(GetDlgItem(hDlg, IDOK), SW_HIDE);
209 ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_HIDE);
210 break;
212 return TRUE;
214 default:
215 break;
217 return FALSE;
220 /*************************************************************************
221 * @ [SHLWAPI.185]
223 * Pop up a 'Don't show this message again' dialogue box.
225 * PARAMS
226 * hWnd [I] Window to be the dialogues' parent
227 * lpszText [I] Text of the message to show
228 * lpszTitle [I] Title of the dialogue box
229 * dwType [I] Type of dialogue buttons (See below)
230 * iRet [I] Value to return if dialogue is not shown
231 * lpszId [I] Name of registry subkey which determines whether to show the dialog
233 * RETURNS
234 * Success: The value returned from the dialogue procedure (e.g. IDOK).
235 * Failure: iRet, if the default dialogue resource could not be loaded or the
236 * dialogue should not be shown.
238 * NOTES
239 * - Both lpszTitle and lpszId must be less than MAX_PATH in length.
240 * - Possible values for dwType are:
241 *| Value Buttons
242 *| ----- -------
243 *| 0 OK
244 *| 1 OK/Cancel
245 *| 2 Yes/No
247 INT_PTR WINAPI SHMessageBoxCheckA(HWND hWnd, LPCSTR lpszText, LPCSTR lpszTitle,
248 DWORD dwType, INT_PTR iRet, LPCSTR lpszId)
250 WCHAR szTitleBuff[MAX_PATH], szIdBuff[MAX_PATH];
251 WCHAR *szTextBuff = NULL;
252 int iLen;
253 INT_PTR iRetVal;
255 if (lpszTitle)
256 MultiByteToWideChar(CP_ACP, 0, lpszTitle, -1, szTitleBuff, MAX_PATH);
258 if (lpszText)
260 iLen = MultiByteToWideChar(CP_ACP, 0, lpszText, -1, NULL, 0);
261 szTextBuff = HeapAlloc(GetProcessHeap(), 0, iLen * sizeof(WCHAR));
262 MultiByteToWideChar(CP_ACP, 0, lpszText, -1, szTextBuff, iLen);
265 MultiByteToWideChar(CP_ACP, 0, lpszId, -1, szIdBuff, MAX_PATH);
267 iRetVal = SHMessageBoxCheckW(hWnd, szTextBuff, lpszTitle ? szTitleBuff : NULL,
268 dwType, iRet, szIdBuff);
269 HeapFree(GetProcessHeap(), 0, szTextBuff);
270 return iRetVal;
273 /*************************************************************************
274 * @ [SHLWAPI.191]
276 * Unicode version of SHMessageBoxCheckA.
278 INT_PTR WINAPI SHMessageBoxCheckW(HWND hWnd, LPCWSTR lpszText, LPCWSTR lpszTitle,
279 DWORD dwType, INT_PTR iRet, LPCWSTR lpszId)
281 DLGDATA d;
283 d.lpszTitle = lpszTitle;
284 d.lpszText = lpszText;
285 d.dwType = dwType;
287 return SHMessageBoxCheckExW(hWnd, shlwapi_hInstance, (LPCWSTR)IDD_ERR_DIALOG,
288 SHDlgProc, (LPARAM)&d, iRet, lpszId);