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
22 #include "wine/port.h"
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
39 extern HINSTANCE shlwapi_hInstance
; /* in shlwapi_main.c */
41 static const WCHAR szDontShowKey
[] = { 'S','o','f','t','w','a','r','e','\\',
42 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
43 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
44 'E','x','p','l','o','r','e','r','\\','D','o','n','t','S','h','o','w',
45 'M','e','T','h','i','s','D','i','a','l','o','g','A','g','a','i','n','\0'
48 INT_PTR WINAPI
SHMessageBoxCheckExW(HWND
,HINSTANCE
,LPCWSTR
,DLGPROC
,LPARAM
,INT_PTR
,LPCWSTR
);
49 INT_PTR WINAPI
SHMessageBoxCheckW(HWND
,LPCWSTR
,LPCWSTR
,DWORD
,INT_PTR
,LPCWSTR
);
51 /* Data held by each general message boxes */
52 typedef struct tagDLGDATAEX
54 DLGPROC dlgProc
; /* User supplied DlgProc */
55 LPARAM lParam
; /* User supplied LPARAM for dlgProc */
56 LPCWSTR lpszId
; /* Name of reg key holding whether to skip */
59 /* Dialogue procedure for general message boxes */
60 static INT_PTR CALLBACK
SHDlgProcEx(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
62 DLGDATAEX
*d
= (DLGDATAEX
*)GetWindowLongPtrW(hDlg
, DWLP_USER
);
64 TRACE("(%p,%u,%ld,%ld) data %p\n", hDlg
, uMsg
, wParam
, lParam
, d
);
70 /* FIXME: Not sure where native stores its lParam */
71 SetWindowLongPtrW(hDlg
, DWLP_USER
, lParam
);
72 d
= (DLGDATAEX
*)lParam
;
73 TRACE("WM_INITDIALOG: %p, %s,%p,%p\n", hDlg
, debugstr_w(d
->lpszId
),
74 d
->dlgProc
, (void*)d
->lParam
);
76 return d
->dlgProc(hDlg
, uMsg
, wParam
, d
->lParam
);
81 switch (LOWORD(wParam
))
84 wParam
= MAKELONG(IDOK
, HIWORD(wParam
));
85 /* Fall through ... */
87 if (LOWORD(wParam
) == IDNO
)
88 wParam
= MAKELONG(IDCANCEL
, HIWORD(wParam
));
89 /* Fall through ... */
93 TRACE("WM_COMMAND: id=%s data=%p\n",
94 LOWORD(wParam
) == IDOK
? "IDOK" : "IDCANCEL", d
);
96 if (SendMessageW(GetDlgItem(hDlg
, IDC_ERR_DONT_SHOW
), BM_GETCHECK
, 0L, 0L))
100 /* The user clicked 'don't show again', so set the key */
101 SHRegSetUSValueW(szDontShowKey
, d
->lpszId
, REG_DWORD
, &dwZero
,
102 sizeof(dwZero
), SHREGSET_DEFAULT
);
104 if (!d
->dlgProc
|| !d
->dlgProc(hDlg
, uMsg
, wParam
, lParam
))
105 EndDialog(hDlg
, wParam
);
115 return d
->dlgProc(hDlg
, uMsg
, wParam
, lParam
);
119 /*************************************************************************
122 * Pop up a 'Don't show this message again' dialogue box.
125 * hWnd [I] Window to be the dialogues' parent
126 * hInst [I] Instance of the module holding the dialogue resource
127 * lpszName [I] Resource Id of the dialogue resource
128 * dlgProc [I] Dialog procedure, or NULL for default handling
129 * lParam [I] LPARAM to pass to dlgProc
130 * iRet [I] Value to return if dialogue is not shown
131 * lpszId [I] Name of registry subkey which determines whether to show the dialog
134 * Success: The value returned from the dialogue procedure.
135 * Failure: iRet, if the dialogue resource could not be loaded or the dialogue
136 * should not be shown.
139 * Both lpszName and lpszId must be less than MAX_PATH in length.
141 INT_PTR WINAPI
SHMessageBoxCheckExA(HWND hWnd
, HINSTANCE hInst
, LPCSTR lpszName
,
142 DLGPROC dlgProc
, LPARAM lParam
, INT_PTR iRet
,
145 WCHAR szNameBuff
[MAX_PATH
], szIdBuff
[MAX_PATH
];
146 LPCWSTR szName
= szNameBuff
;
148 if (IS_INTRESOURCE(lpszName
))
149 szName
= (LPCWSTR
)lpszName
; /* Resource Id or NULL */
151 MultiByteToWideChar(CP_ACP
, 0, lpszName
, -1, szNameBuff
, MAX_PATH
);
153 MultiByteToWideChar(CP_ACP
, 0, lpszId
, -1, szIdBuff
, MAX_PATH
);
155 return SHMessageBoxCheckExW(hWnd
, hInst
, szName
, dlgProc
, lParam
, iRet
, szIdBuff
);
158 /*************************************************************************
161 * Unicode version of SHMessageBoxCheckExW.
163 INT_PTR WINAPI
SHMessageBoxCheckExW(HWND hWnd
, HINSTANCE hInst
, LPCWSTR lpszName
,
164 DLGPROC dlgProc
, LPARAM lParam
, INT_PTR iRet
, LPCWSTR lpszId
)
168 if (!SHRegGetBoolUSValueW(szDontShowKey
, lpszId
, FALSE
, TRUE
))
174 return DialogBoxParamW(hInst
, lpszName
, hWnd
, SHDlgProcEx
, (LPARAM
)&d
);
177 /* Data held by each shlwapi message box */
178 typedef struct tagDLGDATA
180 LPCWSTR lpszTitle
; /* User supplied message title */
181 LPCWSTR lpszText
; /* User supplied message text */
182 DWORD dwType
; /* Message box type */
185 /* Dialogue procedure for shlwapi message boxes */
186 static INT_PTR CALLBACK
SHDlgProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
188 TRACE("(%p,%u,%ld,%ld)\n", hDlg
, uMsg
, wParam
, lParam
);
194 DLGDATA
*d
= (DLGDATA
*)lParam
;
195 TRACE("WM_INITDIALOG: %p, %s,%s,%d\n", hDlg
, debugstr_w(d
->lpszTitle
),
196 debugstr_w(d
->lpszText
), d
->dwType
);
198 SetWindowTextW(hDlg
, d
->lpszTitle
);
199 SetWindowTextW(GetDlgItem(hDlg
, IDS_ERR_USER_MSG
), d
->lpszText
);
201 /* Set buttons according to dwType */
205 ShowWindow(GetDlgItem(hDlg
, IDCANCEL
), SW_HIDE
);
206 /* FIXME: Move OK button to position of the Cancel button (cosmetic) */
208 ShowWindow(GetDlgItem(hDlg
, IDYES
), SW_HIDE
);
209 ShowWindow(GetDlgItem(hDlg
, IDNO
), SW_HIDE
);
212 ShowWindow(GetDlgItem(hDlg
, IDOK
), SW_HIDE
);
213 ShowWindow(GetDlgItem(hDlg
, IDCANCEL
), SW_HIDE
);
224 /*************************************************************************
227 * Pop up a 'Don't show this message again' dialogue box.
230 * hWnd [I] Window to be the dialogues' parent
231 * lpszText [I] Text of the message to show
232 * lpszTitle [I] Title of the dialogue box
233 * dwType [I] Type of dialogue buttons (See below)
234 * iRet [I] Value to return if dialogue is not shown
235 * lpszId [I] Name of registry subkey which determines whether to show the dialog
238 * Success: The value returned from the dialogue procedure (e.g. IDOK).
239 * Failure: iRet, if the default dialogue resource could not be loaded or the
240 * dialogue should not be shown.
243 * - Both lpszTitle and lpszId must be less than MAX_PATH in length.
244 * - Possible values for dwType are:
251 INT_PTR WINAPI
SHMessageBoxCheckA(HWND hWnd
, LPCSTR lpszText
, LPCSTR lpszTitle
,
252 DWORD dwType
, INT_PTR iRet
, LPCSTR lpszId
)
254 WCHAR szTitleBuff
[MAX_PATH
], szIdBuff
[MAX_PATH
];
255 WCHAR
*szTextBuff
= NULL
;
260 MultiByteToWideChar(CP_ACP
, 0, lpszTitle
, -1, szTitleBuff
, MAX_PATH
);
264 iLen
= MultiByteToWideChar(CP_ACP
, 0, lpszText
, -1, NULL
, 0);
265 szTextBuff
= HeapAlloc(GetProcessHeap(), 0, iLen
* sizeof(WCHAR
));
266 MultiByteToWideChar(CP_ACP
, 0, lpszText
, -1, szTextBuff
, iLen
);
269 MultiByteToWideChar(CP_ACP
, 0, lpszId
, -1, szIdBuff
, MAX_PATH
);
271 iRetVal
= SHMessageBoxCheckW(hWnd
, szTextBuff
, lpszTitle
? szTitleBuff
: NULL
,
272 dwType
, iRet
, szIdBuff
);
273 HeapFree(GetProcessHeap(), 0, szTextBuff
);
277 /*************************************************************************
280 * Unicode version of SHMessageBoxCheckA.
282 INT_PTR WINAPI
SHMessageBoxCheckW(HWND hWnd
, LPCWSTR lpszText
, LPCWSTR lpszTitle
,
283 DWORD dwType
, INT_PTR iRet
, LPCWSTR lpszId
)
287 d
.lpszTitle
= lpszTitle
;
288 d
.lpszText
= lpszText
;
291 return SHMessageBoxCheckExW(hWnd
, shlwapi_hInstance
, (LPCWSTR
)IDD_ERR_DIALOG
,
292 SHDlgProc
, (LPARAM
)&d
, iRet
, lpszId
);