Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afsapplib / al_error.cpp
bloba9195d16e64bbf493d8a6d1f595e1ef5dda7b709
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
15 #include <WINNT/afsapplib.h>
18 * PROTOTYPES _________________________________________________________________
22 void cdecl vErrorDialog (BOOL fFatal, DWORD dwStatus, LONG idError, LPTSTR pszFmt, va_list arg);
24 HRESULT CALLBACK Error_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
26 void OnCreateErrorDialog (WPARAM wp, LPARAM lp);
30 * ERROR DIALOGS ______________________________________________________________
34 typedef struct
36 BOOL fFatal;
37 LPTSTR pszError;
38 DWORD dwError;
39 } ERRORPARAMS;
41 void cdecl ErrorDialog (DWORD dwStatus, LPTSTR pszError, LPTSTR pszFmt, ...)
43 va_list arg;
44 va_start (arg, pszFmt);
45 vErrorDialog (FALSE, dwStatus, (LONG)(LONG_PTR)pszError, pszFmt, arg);
48 void cdecl ErrorDialog (DWORD dwStatus, int idsError, LPTSTR pszFmt, ...)
50 va_list arg;
51 va_start (arg, pszFmt);
52 vErrorDialog (FALSE, dwStatus, (LONG)idsError, pszFmt, arg);
55 void cdecl FatalErrorDialog (DWORD dwStatus, LPTSTR pszError, LPTSTR pszFmt, ...)
57 va_list arg;
58 va_start (arg, pszFmt);
59 vErrorDialog (TRUE, dwStatus, (LONG)(LONG_PTR)pszError, pszFmt, arg);
62 void cdecl FatalErrorDialog (DWORD dwStatus, int idsError, LPTSTR pszFmt, ...)
64 va_list arg;
65 va_start (arg, pszFmt);
66 vErrorDialog (TRUE, dwStatus, (LONG)idsError, pszFmt, arg);
70 void cdecl vErrorDialog (BOOL fFatal, DWORD dwStatus, LONG idError, LPTSTR pszFmt, va_list arg)
72 ERRORPARAMS *lpep = New (ERRORPARAMS);
73 lpep->fFatal = fFatal;
74 lpep->pszError = vFormatString (idError, pszFmt, arg);
75 lpep->dwError = dwStatus;
77 if (!AfsAppLib_GetMainWindow())
79 OnCreateErrorDialog (0, (LPARAM)lpep);
81 else
83 PostMessage (AfsAppLib_GetMainWindow(), WM_CREATE_ERROR_DIALOG, 0, (LPARAM)lpep);
88 void ImmediateErrorDialog (DWORD dwStatus, int idsError, LPTSTR pszFmt, ...)
90 va_list arg;
91 va_start (arg, pszFmt);
93 ERRORPARAMS *lpep = New (ERRORPARAMS);
94 lpep->fFatal = FALSE;
95 lpep->pszError = vFormatString (idsError, pszFmt, arg);
96 lpep->dwError = dwStatus;
98 ModalDialogParam (IDD_APPLIB_ERROR, NULL, (DLGPROC)Error_DlgProc, (LPARAM)lpep);
100 FreeString (lpep->pszError);
101 Delete (lpep);
104 void ImmediateErrorDialog (DWORD dwStatus, LPTSTR pszError, LPTSTR pszFmt, ...)
106 va_list arg;
107 va_start (arg, pszFmt);
109 ERRORPARAMS *lpep = New (ERRORPARAMS);
110 lpep->fFatal = FALSE;
111 lpep->pszError = vFormatString (pszError, pszFmt, arg);
112 lpep->dwError = dwStatus;
114 ModalDialogParam (IDD_APPLIB_ERROR, NULL, (DLGPROC)Error_DlgProc, (LPARAM)lpep);
116 FreeString (lpep->pszError);
117 Delete (lpep);
121 void OnCreateErrorDialog (WPARAM wp, LPARAM lp)
123 ERRORPARAMS *lpep = (ERRORPARAMS*)lp;
125 ModalDialogParam (IDD_APPLIB_ERROR, NULL, (DLGPROC)Error_DlgProc, (LPARAM)lpep);
127 if (lpep->fFatal)
129 PostQuitMessage (0);
132 FreeString (lpep->pszError);
133 Delete (lpep);
137 HRESULT CALLBACK Error_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
139 switch (msg)
141 case WM_INITDIALOG:
142 TCHAR szApplication[ cchNAME ];
143 AfsAppLib_GetAppName (szApplication);
144 if (szApplication[0] != TEXT('\0'))
146 TCHAR szTitle[ cchRESOURCE ];
147 GetWindowText (hDlg, szTitle, cchRESOURCE);
148 lstrcat (szTitle, TEXT(" - "));
149 lstrcat (szTitle, szApplication);
150 SetWindowText (hDlg, szTitle);
153 ERRORPARAMS *lpep;
154 if ((lpep = (ERRORPARAMS *)lp) == NULL)
156 TCHAR szError[ cchRESOURCE ];
157 AfsAppLib_TranslateError (szError, ERROR_NOT_ENOUGH_MEMORY);
158 SetDlgItemText (hDlg, IDC_ERROR_STATUS, szError);
160 else
162 SetDlgItemText (hDlg, IDC_ERROR_DESC, lpep->pszError);
164 if (lpep->dwError == 0)
166 RECT rDesc;
167 GetRectInParent (GetDlgItem (hDlg, IDC_ERROR_DESC), &rDesc);
169 RECT rStatus;
170 GetRectInParent (GetDlgItem (hDlg, IDC_ERROR_STATUS), &rStatus);
172 SetWindowPos (GetDlgItem (hDlg, IDC_ERROR_DESC), NULL,
173 0, 0, cxRECT(rDesc), rStatus.bottom -rDesc.top,
174 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
176 ShowWindow (GetDlgItem (hDlg, IDC_ERROR_STATUS), SW_HIDE);
178 else
180 TCHAR szCode[ cchRESOURCE ];
181 GetDlgItemText (hDlg, IDC_ERROR_STATUS, szCode, cchRESOURCE);
183 LPTSTR pszStatus = FormatString (szCode, TEXT("%e"), lpep->dwError);
184 SetDlgItemText (hDlg, IDC_ERROR_STATUS, pszStatus);
185 FreeString (pszStatus);
188 break;
190 case WM_COMMAND:
191 switch (LOWORD(wp))
193 case IDOK:
194 case IDCANCEL:
195 EndDialog (hDlg, LOWORD(wp));
196 break;
198 break;
201 return FALSE;