windows-64-bit-type-safety-20051105
[openafs.git] / src / WINNT / talocale / tal_dialog.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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  */
9
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
13 }
14
15 #include <WINNT/talocale.h>
16
17
18 /*
19  * DEFINITIONS ________________________________________________________________
20  *
21  */
22
23
24 /*
25  * PROTOTYPES _________________________________________________________________
26  *
27  */
28
29 int cdecl vMessage (UINT, LONG, LONG, LPCTSTR, va_list);
30 DWORD WINAPI Message_ThreadProc (PVOID lp);
31
32
33 /*
34  * ROUTINES ___________________________________________________________________
35  *
36  */
37
38 HWND ModelessDialog (int idd, HWND hWndParent, DLGPROC lpDialogFunc)
39 {
40    return ModelessDialogParam (idd, hWndParent, lpDialogFunc, 0);
41 }
42
43
44 HWND ModelessDialogParam (int idd, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
45 {
46    HINSTANCE hInstFound;
47    LPCDLGTEMPLATE pTemplate;
48    if ((pTemplate = TaLocale_GetDialogResource (idd, &hInstFound)) == NULL)
49       return NULL;
50
51    return CreateDialogIndirectParam (hInstFound, pTemplate, hWndParent, lpDialogFunc, dwInitParam);
52 }
53
54
55 INT_PTR ModalDialog (int idd, HWND hWndParent, DLGPROC lpDialogFunc)
56 {
57    return ModalDialogParam (idd, hWndParent, lpDialogFunc, 0);
58 }
59
60
61 INT_PTR ModalDialogParam (int idd, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
62 {
63    HINSTANCE hInstFound;
64    LPCDLGTEMPLATE pTemplate;
65    if ((pTemplate = TaLocale_GetDialogResource (idd, &hInstFound)) == NULL)
66       return NULL;
67
68    return DialogBoxIndirectParam (hInstFound, pTemplate, hWndParent, lpDialogFunc, dwInitParam);
69 }
70
71
72 /*** Message() - generic-text dialog box
73  *
74  */
75
76 int cdecl Message (UINT type, LPCTSTR title, LPCTSTR text, LPCTSTR fmt, ...)
77 {
78    va_list  arg;
79    // if (fmt != NULL)
80       va_start (arg, fmt);
81    return vMessage (type, PtrToLong(title), PtrToLong(text), fmt, arg);
82 }
83
84
85 int cdecl Message (UINT type, LPCTSTR title, int text, LPCTSTR fmt, ...)
86 {
87    va_list  arg;
88    // if (fmt != NULL)
89       va_start (arg, fmt);
90    return vMessage (type, PtrToLong(title), (LONG)text, fmt, arg);
91 }
92
93
94 int cdecl Message (UINT type, int title, LPCTSTR text, LPCTSTR fmt, ...)
95 {
96    va_list  arg;
97    // if (fmt != NULL)
98       va_start (arg, fmt);
99    return vMessage (type, (LONG)title, PtrToLong(text), fmt, arg);
100 }
101
102
103 int cdecl Message (UINT type, int title, int text, LPCTSTR fmt, ...)
104 {
105    va_list  arg;
106    // if (fmt != NULL)
107       va_start (arg, fmt);
108    return vMessage (type, (LONG)title, (LONG)text, fmt, arg);
109 }
110
111
112 int cdecl vMessage (UINT type, LPCTSTR title, LPCTSTR text, LPCTSTR fmt, va_list arg)
113 {
114    return vMessage (type, PtrToLong(title), PtrToLong(text), fmt, arg);
115 }
116
117
118 int cdecl vMessage (UINT type, LPCTSTR title, int text, LPCTSTR fmt, va_list arg)
119 {
120    return vMessage (type, PtrToLong(title), (LONG)text, fmt, arg);
121 }
122
123
124 int cdecl vMessage (UINT type, int title, LPCTSTR text, LPCTSTR fmt, va_list arg)
125 {
126    return vMessage (type, (LONG)title, PtrToLong(text), fmt, arg);
127 }
128
129
130 int cdecl vMessage (UINT type, int title, int text, LPCTSTR fmt, va_list arg)
131 {
132    return vMessage (type, (LONG)title, (LONG)text, fmt, arg);
133 }
134
135
136 typedef struct
137    {
138    UINT dwType;
139    LPTSTR pszTitle;
140    LPTSTR pszText;
141    } MESSAGE_PARAMS, *LPMESSAGE_PARAMS;
142
143 int cdecl vMessage (UINT type, LONG title, LONG text, LPCTSTR fmt, va_list arg)
144 {
145    LPMESSAGE_PARAMS pmp = New(MESSAGE_PARAMS);
146
147    pmp->dwType = type;
148
149    if ((pmp->pszTitle = FormatString (title, fmt, arg)) == NULL)
150       {
151       Delete(pmp);
152       return IDCANCEL;
153       }
154
155    if ((pmp->pszText = vFormatString (text, fmt, arg)) == NULL)
156       {
157       FreeString (pmp->pszTitle);
158       Delete(pmp);
159       return IDCANCEL;
160       }
161
162    if (!( pmp->dwType & 0xF0 )) // no icon requested?  pick one.
163       {
164       pmp->dwType |= ((pmp->dwType & 0x0F) ? MB_ICONQUESTION : MB_ICONASTERISK);
165       }
166
167    if (pmp->dwType & MB_MODELESS)
168       {
169       pmp->dwType &= ~MB_MODELESS;
170
171       HANDLE hThread;
172       if ((hThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)Message_ThreadProc, pmp, 0, NULL)) != NULL)
173          SetThreadPriority (hThread, THREAD_PRIORITY_BELOW_NORMAL);
174
175       return -1; // threaded--who knows what button was hit.
176       }
177
178    return Message_ThreadProc (pmp);
179 }
180
181
182 DWORD WINAPI Message_ThreadProc (PVOID lp)
183 {
184    LPMESSAGE_PARAMS pmp = (LPMESSAGE_PARAMS)lp;
185
186    DWORD rc = MessageBox (NULL, pmp->pszText, pmp->pszTitle, pmp->dwType);
187
188    FreeString (pmp->pszText);
189    FreeString (pmp->pszTitle);
190    Delete(pmp);
191
192    return rc;
193 }
194