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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define COM_NO_WINDOWS_H
23 #include "wine/port.h"
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
42 extern HINSTANCE shlwapi_hInstance
; /* in shlwapi_main.c */
44 static const WCHAR szDontShowKey
[] = { 'S','o','f','t','w','a','r','e','\\',
45 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
46 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
47 'E','x','p','l','o','r','e','r','\\','D','o','n','t','S','h','o','w',
48 'M','e','T','h','i','s','D','i','a','l','o','g','A','g','a','i','n','\0'
51 INT_PTR WINAPI
SHMessageBoxCheckExW(HWND
,HINSTANCE
,LPCWSTR
,DLGPROC
,LPARAM
,INT_PTR
,LPCWSTR
);
52 INT_PTR WINAPI
SHMessageBoxCheckW(HWND
,LPCWSTR
,LPCWSTR
,DWORD
,INT_PTR
,LPCWSTR
);
54 /* Data held by each general message boxes */
55 typedef struct tagDLGDATAEX
57 DLGPROC dlgProc
; /* User supplied DlgProc */
58 LPARAM lParam
; /* User supplied LPARAM for dlgProc */
59 LPCWSTR lpszId
; /* Name of reg key holding whether to skip */
62 /* Dialogue procedure for general message boxes */
63 static INT_PTR CALLBACK
SHDlgProcEx(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
65 DLGDATAEX
*d
= (DLGDATAEX
*)GetWindowLongPtrW(hDlg
, DWLP_USER
);
67 TRACE("(%p,%u,%d,%ld) data %p\n", hDlg
, uMsg
, wParam
, lParam
, d
);
73 /* FIXME: Not sure where native stores its lParam */
74 SetWindowLongPtrW(hDlg
, DWLP_USER
, lParam
);
75 d
= (DLGDATAEX
*)lParam
;
76 TRACE("WM_INITDIALOG: %p, %s,%p,%p\n", hDlg
, debugstr_w(d
->lpszId
),
77 d
->dlgProc
, (void*)d
->lParam
);
79 return d
->dlgProc(hDlg
, uMsg
, wParam
, d
->lParam
);
84 switch (LOWORD(wParam
))
87 wParam
= MAKELONG(IDOK
, HIWORD(wParam
));
88 /* Fall through ... */
90 if (LOWORD(wParam
) == IDNO
)
91 wParam
= MAKELONG(IDCANCEL
, HIWORD(wParam
));
92 /* Fall through ... */
96 TRACE("WM_COMMAND: id=%s data=%p\n",
97 LOWORD(wParam
) == IDOK
? "IDOK" : "IDCANCEL", d
);
99 if (SendMessageW(GetDlgItem(hDlg
, IDC_ERR_DONT_SHOW
), BM_GETCHECK
, 0L, 0L))
103 /* The user clicked 'don't show again', so set the key */
104 SHRegSetUSValueW(szDontShowKey
, d
->lpszId
, REG_DWORD
, &dwZero
,
105 sizeof(dwZero
), SHREGSET_DEFAULT
);
107 if (!d
->dlgProc
|| !d
->dlgProc(hDlg
, uMsg
, wParam
, lParam
))
108 EndDialog(hDlg
, wParam
);
118 return d
->dlgProc(hDlg
, uMsg
, wParam
, lParam
);
122 /*************************************************************************
125 * Pop up a 'Don't show this message again' dialogue box.
128 * hWnd [I] Window to be the dialogues' parent
129 * hInst [I] Instance of the module holding the dialogue resource
130 * lpszName [I] Resource Id of the dialogue resource
131 * dlgProc [I] Dialog procedure, or NULL for default handling
132 * lParam [I] LPARAM to pass to dlgProc
133 * iRet [I] Value to return if dialogue is not shown
134 * lpszId [I] Name of registry subkey which determines whether to show the dialog
137 * Success: The value returned from the dialogue procedure.
138 * Failure: iRet, if the dialogue resource could not be loaded or the dialogue
139 * should not be shown.
142 * Both lpszName and lpszId must be less than MAX_PATH in length.
144 INT_PTR WINAPI
SHMessageBoxCheckExA(HWND hWnd
, HINSTANCE hInst
, LPCSTR lpszName
,
145 DLGPROC dlgProc
, LPARAM lParam
, INT_PTR iRet
,
148 WCHAR szNameBuff
[MAX_PATH
], szIdBuff
[MAX_PATH
];
149 LPCWSTR szName
= szNameBuff
;
151 if (HIWORD(lpszName
))
152 MultiByteToWideChar(CP_ACP
, 0, lpszName
, -1, szNameBuff
, MAX_PATH
);
154 szName
= (LPCWSTR
)lpszName
; /* Resource Id or NULL */
156 MultiByteToWideChar(CP_ACP
, 0, lpszId
, -1, szIdBuff
, MAX_PATH
);
158 return SHMessageBoxCheckExW(hWnd
, hInst
, szName
, dlgProc
, lParam
, iRet
, szIdBuff
);
161 /*************************************************************************
164 * Unicode version of SHMessageBoxCheckExW.
166 INT_PTR WINAPI
SHMessageBoxCheckExW(HWND hWnd
, HINSTANCE hInst
, LPCWSTR lpszName
,
167 DLGPROC dlgProc
, LPARAM lParam
, INT_PTR iRet
, LPCWSTR lpszId
)
171 if (!SHRegGetBoolUSValueW(szDontShowKey
, lpszId
, FALSE
, TRUE
))
177 return DialogBoxParamW(hInst
, (LPCWSTR
)lpszName
, hWnd
, SHDlgProcEx
, (LPARAM
)&d
);
180 /* Data held by each shlwapi message box */
181 typedef struct tagDLGDATA
183 LPCWSTR lpszTitle
; /* User supplied message title */
184 LPCWSTR lpszText
; /* User supplied message text */
185 DWORD dwType
; /* Message box type */
188 /* Dialogue procedure for shlwapi message boxes */
189 static INT_PTR CALLBACK
SHDlgProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
191 TRACE("(%p,%u,%d,%ld)\n", hDlg
, uMsg
, wParam
, lParam
);
197 DLGDATA
*d
= (DLGDATA
*)lParam
;
198 TRACE("WM_INITDIALOG: %p, %s,%s,%ld\n", hDlg
, debugstr_w(d
->lpszTitle
),
199 debugstr_w(d
->lpszText
), d
->dwType
);
201 SetWindowTextW(hDlg
, d
->lpszTitle
);
202 SetWindowTextW(GetDlgItem(hDlg
, IDS_ERR_USER_MSG
), d
->lpszText
);
204 /* Set buttons according to dwType */
208 ShowWindow(GetDlgItem(hDlg
, IDCANCEL
), FALSE
);
209 /* FIXME: Move OK button to position of the Cancel button (cosmetic) */
211 ShowWindow(GetDlgItem(hDlg
, IDYES
), FALSE
);
212 ShowWindow(GetDlgItem(hDlg
, IDNO
), FALSE
);
215 ShowWindow(GetDlgItem(hDlg
, IDOK
), FALSE
);
216 ShowWindow(GetDlgItem(hDlg
, IDCANCEL
), FALSE
);
227 /*************************************************************************
230 * Pop up a 'Don't show this message again' dialogue box.
233 * hWnd [I] Window to be the dialogues' parent
234 * lpszText [I] Text of the message to show
235 * lpszTitle [I] Title of the dialogue box
236 * dwType [I] Type of dialogue buttons (See below)
237 * iRet [I] Value to return if dialogue is not shown
238 * lpszId [I] Name of registry subkey which determines whether to show the dialog
241 * Success: The value returned from the dialogue procedure (e.g. IDOK).
242 * Failure: iRet, if the default dialogue resource could not be loaded or the
243 * dialogue should not be shown.
246 * - Both lpszTitle and lpszId must be less than MAX_PATH in length.
247 * - Possible values for dwType are:
254 INT_PTR WINAPI
SHMessageBoxCheckA(HWND hWnd
, LPCSTR lpszText
, LPCSTR lpszTitle
,
255 DWORD dwType
, INT_PTR iRet
, LPCSTR lpszId
)
257 WCHAR szTitleBuff
[MAX_PATH
], szIdBuff
[MAX_PATH
];
258 WCHAR
*szTextBuff
= NULL
;
263 MultiByteToWideChar(CP_ACP
, 0, lpszTitle
, -1, szTitleBuff
, MAX_PATH
);
267 iLen
= MultiByteToWideChar(CP_ACP
, 0, lpszText
, -1, NULL
, 0);
268 szTextBuff
= HeapAlloc(GetProcessHeap(), 0, iLen
* sizeof(WCHAR
));
269 MultiByteToWideChar(CP_ACP
, 0, lpszText
, -1, szTextBuff
, iLen
);
272 MultiByteToWideChar(CP_ACP
, 0, lpszId
, -1, szIdBuff
, MAX_PATH
);
274 iRetVal
= SHMessageBoxCheckW(hWnd
, szTextBuff
, lpszTitle
? szTitleBuff
: NULL
,
275 dwType
, iRet
, szIdBuff
);
276 HeapFree(GetProcessHeap(), 0, szTextBuff
);
280 /*************************************************************************
283 * Unicode version of SHMessageBoxCheckA.
285 INT_PTR WINAPI
SHMessageBoxCheckW(HWND hWnd
, LPCWSTR lpszText
, LPCWSTR lpszTitle
,
286 DWORD dwType
, INT_PTR iRet
, LPCWSTR lpszId
)
290 d
.lpszTitle
= lpszTitle
;
291 d
.lpszText
= lpszText
;
294 return SHMessageBoxCheckExW(hWnd
, shlwapi_hInstance
, (LPCWSTR
)IDD_ERR_DIALOG
,
295 SHDlgProc
, (LPARAM
)&d
, iRet
, lpszId
);