Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmsgbox.c
Go to the documentation of this file.
00001 /* 00002 * SHLWAPI message box functions 00003 * 00004 * Copyright 2004 Jon Griffiths 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00019 */ 00020 00021 #include "config.h" 00022 #include "wine/port.h" 00023 00024 #include <stdarg.h> 00025 #include <string.h> 00026 00027 #define NONAMELESSUNION 00028 #define NONAMELESSSTRUCT 00029 #include "windef.h" 00030 #include "winbase.h" 00031 #include "winuser.h" 00032 #include "winreg.h" 00033 #include "shlwapi.h" 00034 #include "wine/unicode.h" 00035 #include "wine/debug.h" 00036 #include "resource.h" 00037 00038 00039 WINE_DEFAULT_DEBUG_CHANNEL(shell); 00040 00041 extern HINSTANCE shlwapi_hInstance; /* in shlwapi_main.c */ 00042 00043 static const WCHAR szDontShowKey[] = { 'S','o','f','t','w','a','r','e','\\', 00044 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\', 00045 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\', 00046 'E','x','p','l','o','r','e','r','\\','D','o','n','t','S','h','o','w', 00047 'M','e','T','h','i','s','D','i','a','l','o','g','A','g','a','i','n','\0' 00048 }; 00049 00050 INT_PTR WINAPI SHMessageBoxCheckExW(HWND,HINSTANCE,LPCWSTR,DLGPROC,LPARAM,INT_PTR,LPCWSTR); 00051 INT_PTR WINAPI SHMessageBoxCheckW(HWND,LPCWSTR,LPCWSTR,DWORD,INT_PTR,LPCWSTR); 00052 00053 /* Data held by each general message boxes */ 00054 typedef struct tagDLGDATAEX 00055 { 00056 DLGPROC dlgProc; /* User supplied DlgProc */ 00057 LPARAM lParam; /* User supplied LPARAM for dlgProc */ 00058 LPCWSTR lpszId; /* Name of reg key holding whether to skip */ 00059 } DLGDATAEX; 00060 00061 /* Dialogue procedure for general message boxes */ 00062 static INT_PTR CALLBACK SHDlgProcEx(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 00063 { 00064 DLGDATAEX *d = (DLGDATAEX *)GetWindowLongPtrW(hDlg, DWLP_USER); 00065 00066 TRACE("(%p,%u,%ld,%ld) data %p\n", hDlg, uMsg, wParam, lParam, d); 00067 00068 switch (uMsg) 00069 { 00070 case WM_INITDIALOG: 00071 { 00072 /* FIXME: Not sure where native stores its lParam */ 00073 SetWindowLongPtrW(hDlg, DWLP_USER, lParam); 00074 d = (DLGDATAEX *)lParam; 00075 TRACE("WM_INITDIALOG: %p, %s,%p,%p\n", hDlg, debugstr_w(d->lpszId), 00076 d->dlgProc, (void*)d->lParam); 00077 if (d->dlgProc) 00078 return d->dlgProc(hDlg, uMsg, wParam, d->lParam); 00079 return TRUE; 00080 } 00081 00082 case WM_COMMAND: 00083 switch (LOWORD(wParam)) 00084 { 00085 case IDYES: 00086 wParam = MAKELONG(IDOK, HIWORD(wParam)); 00087 /* Fall through ... */ 00088 case IDNO: 00089 if (LOWORD(wParam) == IDNO) 00090 wParam = MAKELONG(IDCANCEL, HIWORD(wParam)); 00091 /* Fall through ... */ 00092 case IDOK: 00093 case IDCANCEL: 00094 00095 TRACE("WM_COMMAND: id=%s data=%p\n", 00096 LOWORD(wParam) == IDOK ? "IDOK" : "IDCANCEL", d); 00097 00098 if (SendMessageW(GetDlgItem(hDlg, IDC_ERR_DONT_SHOW), BM_GETCHECK, 0L, 0L)) 00099 { 00100 DWORD dwZero = 0; 00101 00102 /* The user clicked 'don't show again', so set the key */ 00103 SHRegSetUSValueW(szDontShowKey, d->lpszId, REG_DWORD, &dwZero, 00104 sizeof(dwZero), SHREGSET_DEFAULT); 00105 } 00106 if (!d->dlgProc || !d->dlgProc(hDlg, uMsg, wParam, lParam)) 00107 EndDialog(hDlg, wParam); 00108 return TRUE; 00109 } 00110 break; 00111 00112 default: 00113 break; 00114 } 00115 00116 if (d && d->dlgProc) 00117 return d->dlgProc(hDlg, uMsg, wParam, lParam); 00118 return FALSE; 00119 } 00120 00121 /************************************************************************* 00122 * @ [SHLWAPI.291] 00123 * 00124 * Pop up a 'Don't show this message again' dialogue box. 00125 * 00126 * PARAMS 00127 * hWnd [I] Window to be the dialogues' parent 00128 * hInst [I] Instance of the module holding the dialogue resource 00129 * lpszName [I] Resource Id of the dialogue resource 00130 * dlgProc [I] Dialog procedure, or NULL for default handling 00131 * lParam [I] LPARAM to pass to dlgProc 00132 * iRet [I] Value to return if dialogue is not shown 00133 * lpszId [I] Name of registry subkey which determines whether to show the dialog 00134 * 00135 * RETURNS 00136 * Success: The value returned from the dialogue procedure. 00137 * Failure: iRet, if the dialogue resource could not be loaded or the dialogue 00138 * should not be shown. 00139 * 00140 * NOTES 00141 * Both lpszName and lpszId must be less than MAX_PATH in length. 00142 */ 00143 INT_PTR WINAPI SHMessageBoxCheckExA(HWND hWnd, HINSTANCE hInst, LPCSTR lpszName, 00144 DLGPROC dlgProc, LPARAM lParam, INT_PTR iRet, 00145 LPCSTR lpszId) 00146 { 00147 WCHAR szNameBuff[MAX_PATH], szIdBuff[MAX_PATH]; 00148 LPCWSTR szName = szNameBuff; 00149 00150 if (IS_INTRESOURCE(lpszName)) 00151 szName = (LPCWSTR)lpszName; /* Resource Id or NULL */ 00152 else 00153 MultiByteToWideChar(CP_ACP, 0, lpszName, -1, szNameBuff, MAX_PATH); 00154 00155 MultiByteToWideChar(CP_ACP, 0, lpszId, -1, szIdBuff, MAX_PATH); 00156 00157 return SHMessageBoxCheckExW(hWnd, hInst, szName, dlgProc, lParam, iRet, szIdBuff); 00158 } 00159 00160 /************************************************************************* 00161 * @ [SHLWAPI.292] 00162 * 00163 * Unicode version of SHMessageBoxCheckExW. 00164 */ 00165 INT_PTR WINAPI SHMessageBoxCheckExW(HWND hWnd, HINSTANCE hInst, LPCWSTR lpszName, 00166 DLGPROC dlgProc, LPARAM lParam, INT_PTR iRet, LPCWSTR lpszId) 00167 { 00168 DLGDATAEX d; 00169 00170 if (!SHRegGetBoolUSValueW(szDontShowKey, lpszId, FALSE, TRUE)) 00171 return iRet; 00172 00173 d.dlgProc = dlgProc; 00174 d.lParam = lParam; 00175 d.lpszId = lpszId; 00176 return DialogBoxParamW(hInst, lpszName, hWnd, SHDlgProcEx, (LPARAM)&d); 00177 } 00178 00179 /* Data held by each shlwapi message box */ 00180 typedef struct tagDLGDATA 00181 { 00182 LPCWSTR lpszTitle; /* User supplied message title */ 00183 LPCWSTR lpszText; /* User supplied message text */ 00184 DWORD dwType; /* Message box type */ 00185 } DLGDATA; 00186 00187 /* Dialogue procedure for shlwapi message boxes */ 00188 static INT_PTR CALLBACK SHDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 00189 { 00190 TRACE("(%p,%u,%ld,%ld)\n", hDlg, uMsg, wParam, lParam); 00191 00192 switch (uMsg) 00193 { 00194 case WM_INITDIALOG: 00195 { 00196 DLGDATA *d = (DLGDATA *)lParam; 00197 TRACE("WM_INITDIALOG: %p, %s,%s,%d\n", hDlg, debugstr_w(d->lpszTitle), 00198 debugstr_w(d->lpszText), d->dwType); 00199 00200 SetWindowTextW(hDlg, d->lpszTitle); 00201 SetWindowTextW(GetDlgItem(hDlg, IDS_ERR_USER_MSG), d->lpszText); 00202 00203 /* Set buttons according to dwType */ 00204 switch (d->dwType) 00205 { 00206 case 0: 00207 ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_HIDE); 00208 /* FIXME: Move OK button to position of the Cancel button (cosmetic) */ 00209 case 1: 00210 ShowWindow(GetDlgItem(hDlg, IDYES), SW_HIDE); 00211 ShowWindow(GetDlgItem(hDlg, IDNO), SW_HIDE); 00212 break; 00213 default: 00214 ShowWindow(GetDlgItem(hDlg, IDOK), SW_HIDE); 00215 ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_HIDE); 00216 break; 00217 } 00218 return TRUE; 00219 } 00220 default: 00221 break; 00222 } 00223 return FALSE; 00224 } 00225 00226 /************************************************************************* 00227 * @ [SHLWAPI.185] 00228 * 00229 * Pop up a 'Don't show this message again' dialogue box. 00230 * 00231 * PARAMS 00232 * hWnd [I] Window to be the dialogues' parent 00233 * lpszText [I] Text of the message to show 00234 * lpszTitle [I] Title of the dialogue box 00235 * dwType [I] Type of dialogue buttons (See below) 00236 * iRet [I] Value to return if dialogue is not shown 00237 * lpszId [I] Name of registry subkey which determines whether to show the dialog 00238 * 00239 * RETURNS 00240 * Success: The value returned from the dialogue procedure (e.g. IDOK). 00241 * Failure: iRet, if the default dialogue resource could not be loaded or the 00242 * dialogue should not be shown. 00243 * 00244 * NOTES 00245 * - Both lpszTitle and lpszId must be less than MAX_PATH in length. 00246 * - Possible values for dwType are: 00247 *| Value Buttons 00248 *| ----- ------- 00249 *| 0 OK 00250 *| 1 OK/Cancel 00251 *| 2 Yes/No 00252 */ 00253 INT_PTR WINAPI SHMessageBoxCheckA(HWND hWnd, LPCSTR lpszText, LPCSTR lpszTitle, 00254 DWORD dwType, INT_PTR iRet, LPCSTR lpszId) 00255 { 00256 WCHAR szTitleBuff[MAX_PATH], szIdBuff[MAX_PATH]; 00257 WCHAR *szTextBuff = NULL; 00258 int iLen; 00259 INT_PTR iRetVal; 00260 00261 if (lpszTitle) 00262 MultiByteToWideChar(CP_ACP, 0, lpszTitle, -1, szTitleBuff, MAX_PATH); 00263 00264 if (lpszText) 00265 { 00266 iLen = MultiByteToWideChar(CP_ACP, 0, lpszText, -1, NULL, 0); 00267 szTextBuff = HeapAlloc(GetProcessHeap(), 0, iLen * sizeof(WCHAR)); 00268 MultiByteToWideChar(CP_ACP, 0, lpszText, -1, szTextBuff, iLen); 00269 } 00270 00271 MultiByteToWideChar(CP_ACP, 0, lpszId, -1, szIdBuff, MAX_PATH); 00272 00273 iRetVal = SHMessageBoxCheckW(hWnd, szTextBuff, lpszTitle ? szTitleBuff : NULL, 00274 dwType, iRet, szIdBuff); 00275 HeapFree(GetProcessHeap(), 0, szTextBuff); 00276 return iRetVal; 00277 } 00278 00279 /************************************************************************* 00280 * @ [SHLWAPI.191] 00281 * 00282 * Unicode version of SHMessageBoxCheckA. 00283 */ 00284 INT_PTR WINAPI SHMessageBoxCheckW(HWND hWnd, LPCWSTR lpszText, LPCWSTR lpszTitle, 00285 DWORD dwType, INT_PTR iRet, LPCWSTR lpszId) 00286 { 00287 DLGDATA d; 00288 00289 d.lpszTitle = lpszTitle; 00290 d.lpszText = lpszText; 00291 d.dwType = dwType; 00292 00293 return SHMessageBoxCheckExW(hWnd, shlwapi_hInstance, (LPCWSTR)IDD_ERR_DIALOG, 00294 SHDlgProc, (LPARAM)&d, iRet, lpszId); 00295 } Generated on Sun May 27 2012 04:18:13 for ReactOS by
1.7.6.1
|