2 * Copyright 2000, International Business Machines Corporation and others.
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
11 #include <afs/param.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 ______________________________________________________________
41 void cdecl ErrorDialog (DWORD dwStatus
, LPTSTR pszError
, LPTSTR pszFmt
, ...)
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
, ...)
51 va_start (arg
, pszFmt
);
52 vErrorDialog (FALSE
, dwStatus
, (LONG
)idsError
, pszFmt
, arg
);
55 void cdecl FatalErrorDialog (DWORD dwStatus
, LPTSTR pszError
, LPTSTR pszFmt
, ...)
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
, ...)
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
);
83 PostMessage (AfsAppLib_GetMainWindow(), WM_CREATE_ERROR_DIALOG
, 0, (LPARAM
)lpep
);
88 void ImmediateErrorDialog (DWORD dwStatus
, int idsError
, LPTSTR pszFmt
, ...)
91 va_start (arg
, pszFmt
);
93 ERRORPARAMS
*lpep
= New (ERRORPARAMS
);
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
);
104 void ImmediateErrorDialog (DWORD dwStatus
, LPTSTR pszError
, LPTSTR pszFmt
, ...)
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
);
121 void OnCreateErrorDialog (WPARAM wp
, LPARAM lp
)
123 ERRORPARAMS
*lpep
= (ERRORPARAMS
*)lp
;
125 ModalDialogParam (IDD_APPLIB_ERROR
, NULL
, (DLGPROC
)Error_DlgProc
, (LPARAM
)lpep
);
132 FreeString (lpep
->pszError
);
137 HRESULT CALLBACK
Error_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
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
);
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
);
162 SetDlgItemText (hDlg
, IDC_ERROR_DESC
, lpep
->pszError
);
164 if (lpep
->dwError
== 0)
167 GetRectInParent (GetDlgItem (hDlg
, IDC_ERROR_DESC
), &rDesc
);
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
);
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
);
195 EndDialog (hDlg
, LOWORD(wp
));