ReactOS 0.4.17-dev-439-g3d86d5e
msgbox.c
Go to the documentation of this file.
1/*
2 * SHLWAPI message box functions
3 *
4 * Copyright 2004 Jon Griffiths
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include <stdarg.h>
22#include <string.h>
23
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"
31
32
34
35extern HINSTANCE shlwapi_hInstance; /* in shlwapi_main.c */
36
37static 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'
42};
43
46
47/* Data held by each general message boxes */
48typedef struct tagDLGDATAEX
49{
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 */
54
55/* Dialogue procedure for general message boxes */
57{
59
60 TRACE("(%p,%u,%Id,%Id) data %p\n", hDlg, uMsg, wParam, lParam, d);
61
62 switch (uMsg)
63 {
64 case WM_INITDIALOG:
65 {
66 /* FIXME: Not sure where native stores its 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;
74 }
75
76 case WM_COMMAND:
77 switch (LOWORD(wParam))
78 {
79 case IDYES:
81 /* Fall through ... */
82 case IDNO:
83 if (LOWORD(wParam) == IDNO)
85 /* Fall through ... */
86 case IDOK:
87 case IDCANCEL:
88
89 TRACE("WM_COMMAND: id=%s data=%p\n",
90 LOWORD(wParam) == IDOK ? "IDOK" : "IDCANCEL", d);
91
93 {
94 DWORD dwZero = 0;
95
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);
99 }
100 if (!d->dlgProc || !d->dlgProc(hDlg, uMsg, wParam, lParam))
101 EndDialog(hDlg, wParam);
102 return TRUE;
103 }
104 break;
105
106 default:
107 break;
108 }
109
110 if (d && d->dlgProc)
111 return d->dlgProc(hDlg, uMsg, wParam, lParam);
112 return FALSE;
113}
114
115/*************************************************************************
116 * @ [SHLWAPI.291]
117 *
118 * Pop up a 'Don't show this message again' dialogue box.
119 *
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
128 *
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.
133 *
134 * NOTES
135 * Both lpszName and lpszId must be less than MAX_PATH in length.
136 */
138 DLGPROC dlgProc, LPARAM lParam, INT_PTR iRet,
139 LPCSTR lpszId)
140{
141 WCHAR szNameBuff[MAX_PATH], szIdBuff[MAX_PATH];
142 LPCWSTR szName = szNameBuff;
143
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);
148
149 MultiByteToWideChar(CP_ACP, 0, lpszId, -1, szIdBuff, MAX_PATH);
150
151 return SHMessageBoxCheckExW(hWnd, hInst, szName, dlgProc, lParam, iRet, szIdBuff);
152}
153
154/*************************************************************************
155 * @ [SHLWAPI.292]
156 *
157 * Unicode version of SHMessageBoxCheckExW.
158 */
160 DLGPROC dlgProc, LPARAM lParam, INT_PTR iRet, LPCWSTR lpszId)
161{
162 DLGDATAEX d;
163
165 return iRet;
166
167 d.dlgProc = dlgProc;
168 d.lParam = lParam;
169 d.lpszId = lpszId;
170 return DialogBoxParamW(hInst, lpszName, hWnd, SHDlgProcEx, (LPARAM)&d);
171}
172
173/* Data held by each shlwapi message box */
174typedef struct tagDLGDATA
175{
176 LPCWSTR lpszTitle; /* User supplied message title */
177 LPCWSTR lpszText; /* User supplied message text */
178 DWORD dwType; /* Message box type */
180
181/* Dialogue procedure for shlwapi message boxes */
183{
184 TRACE("(%p,%u,%Id,%Id)\n", hDlg, uMsg, wParam, lParam);
185
186 switch (uMsg)
187 {
188 case WM_INITDIALOG:
189 {
190 DLGDATA *d = (DLGDATA *)lParam;
191 TRACE("WM_INITDIALOG: %p, %s,%s,%ld\n", hDlg, debugstr_w(d->lpszTitle),
192 debugstr_w(d->lpszText), d->dwType);
193
194 SetWindowTextW(hDlg, d->lpszTitle);
195 SetWindowTextW(GetDlgItem(hDlg, IDS_ERR_USER_MSG), d->lpszText);
196
197 /* Set buttons according to dwType */
198 switch (d->dwType)
199 {
200 case 0:
202 /* FIXME: Move OK button to position of the Cancel button (cosmetic) */
203 case 1:
206 break;
207 default:
210 break;
211 }
212 return TRUE;
213 }
214 default:
215 break;
216 }
217 return FALSE;
218}
219
220/*************************************************************************
221 * @ [SHLWAPI.185]
222 *
223 * Pop up a 'Don't show this message again' dialogue box.
224 *
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
232 *
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.
237 *
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
246 */
248 DWORD dwType, INT_PTR iRet, LPCSTR lpszId)
249{
250 WCHAR szTitleBuff[MAX_PATH], szIdBuff[MAX_PATH];
251 WCHAR *szTextBuff = NULL;
252 int iLen;
253 INT_PTR iRetVal;
254
255 if (lpszTitle)
256 MultiByteToWideChar(CP_ACP, 0, lpszTitle, -1, szTitleBuff, MAX_PATH);
257
258 if (lpszText)
259 {
260 iLen = MultiByteToWideChar(CP_ACP, 0, lpszText, -1, NULL, 0);
261 szTextBuff = malloc(iLen * sizeof(WCHAR));
262 MultiByteToWideChar(CP_ACP, 0, lpszText, -1, szTextBuff, iLen);
263 }
264
265 MultiByteToWideChar(CP_ACP, 0, lpszId, -1, szIdBuff, MAX_PATH);
266
267 iRetVal = SHMessageBoxCheckW(hWnd, szTextBuff, lpszTitle ? szTitleBuff : NULL,
268 dwType, iRet, szIdBuff);
269 free(szTextBuff);
270 return iRetVal;
271}
272
273/*************************************************************************
274 * @ [SHLWAPI.191]
275 *
276 * Unicode version of SHMessageBoxCheckA.
277 */
279 DWORD dwType, INT_PTR iRet, LPCWSTR lpszId)
280{
281 DLGDATA d;
282
283 d.lpszTitle = lpszTitle;
284 d.lpszText = lpszText;
285 d.dwType = dwType;
286
288 SHDlgProc, (LPARAM)&d, iRet, lpszId);
289}
HWND hWnd
Definition: settings.c:17
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define DLGPROC
Definition: maze.c:62
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CP_ACP
Definition: compat.h:109
#define MAX_PATH
Definition: compat.h:34
#define CALLBACK
Definition: compat.h:35
#define MultiByteToWideChar
Definition: compat.h:110
#define IS_INTRESOURCE(x)
Definition: loader.c:613
LONG WINAPI SHRegSetUSValueW(const WCHAR *subkey, const WCHAR *value, DWORD type, void *data, DWORD data_len, DWORD flags)
Definition: registry.c:3912
BOOL WINAPI SHRegGetBoolUSValueW(const WCHAR *subkey, const WCHAR *value, BOOL ignore_hkcu, BOOL default_value)
Definition: registry.c:4139
INT_PTR WINAPI SHMessageBoxCheckW(HWND, LPCWSTR, LPCWSTR, DWORD, INT_PTR, LPCWSTR)
Definition: msgbox.c:278
struct tagDLGDATAEX DLGDATAEX
static INT_PTR CALLBACK SHDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: msgbox.c:182
static INT_PTR CALLBACK SHDlgProcEx(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: msgbox.c:56
static const WCHAR szDontShowKey[]
Definition: msgbox.c:37
INT_PTR WINAPI SHMessageBoxCheckA(HWND hWnd, LPCSTR lpszText, LPCSTR lpszTitle, DWORD dwType, INT_PTR iRet, LPCSTR lpszId)
Definition: msgbox.c:247
HINSTANCE shlwapi_hInstance
Definition: shlwapi_main.c:33
INT_PTR WINAPI SHMessageBoxCheckExW(HWND, HINSTANCE, LPCWSTR, DLGPROC, LPARAM, INT_PTR, LPCWSTR)
Definition: msgbox.c:159
INT_PTR WINAPI SHMessageBoxCheckExA(HWND hWnd, HINSTANCE hInst, LPCSTR lpszName, DLGPROC dlgProc, LPARAM lParam, INT_PTR iRet, LPCSTR lpszId)
Definition: msgbox.c:137
struct tagDLGDATA DLGDATA
#define IDC_ERR_DONT_SHOW
Definition: resource.h:48
#define IDS_ERR_USER_MSG
Definition: resource.h:47
#define IDD_ERR_DIALOG
Definition: resource.h:46
#define L(x)
Definition: resources.c:13
HINSTANCE hInst
Definition: dxdiag.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned int UINT
Definition: sysinfo.c:13
#define d
Definition: ke_i.h:81
#define debugstr_w
Definition: kernel32.h:32
LONG_PTR LPARAM
Definition: minwindef.h:175
UINT_PTR WPARAM
Definition: minwindef.h:174
#define LOWORD(l)
Definition: pedump.c:82
short WCHAR
Definition: pedump.c:58
static const WCHAR szName[]
Definition: powrprof.c:45
#define SHREGSET_DEFAULT
Definition: shlwapi.h:723
#define REG_DWORD
Definition: sdbapi.c:615
#define TRACE(s)
Definition: solgame.cpp:4
DLGPROC dlgProc
Definition: msgbox.c:50
LPCWSTR lpszId
Definition: msgbox.c:52
LPARAM lParam
Definition: msgbox.c:51
LPCWSTR lpszText
Definition: msgbox.c:177
DWORD dwType
Definition: msgbox.c:178
LPCWSTR lpszTitle
Definition: msgbox.c:176
const char * LPCSTR
Definition: typedefs.h:52
int32_t INT_PTR
Definition: typedefs.h:64
const uint16_t * LPCWSTR
Definition: typedefs.h:57
#define MAKELONG(a, b)
Definition: typedefs.h:249
#define HIWORD(l)
Definition: typedefs.h:247
#define WINAPI
Definition: msvc.h:6
#define SW_HIDE
Definition: winuser.h:779
#define DWLP_USER
Definition: winuser.h:883
#define GetWindowLongPtrW
Definition: winuser.h:4983
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define IDCANCEL
Definition: winuser.h:842
#define WM_COMMAND
Definition: winuser.h:1768
#define WM_INITDIALOG
Definition: winuser.h:1767
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:841
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
#define IDNO
Definition: winuser.h:847
#define IDYES
Definition: winuser.h:846
#define SetWindowLongPtrW
Definition: winuser.h:5512
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
#define BM_GETCHECK
Definition: winuser.h:1947
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)