2 * 'Wine' MessageBox function handling
4 * Copyright 1993 Martin Ayotte
7 static char Copyright
[] = "Copyright Martin Ayotte, 1993";
14 #include <sys/types.h>
19 #include "prototypes.h"
24 /* #define DEBUG_MSGBOX */
25 /* #undef DEBUG_MSGBOX */
30 * Defaults for button-texts
33 ButtonTexts ButtonText
= {
43 extern HINSTANCE hSysRes
;
44 extern HBITMAP hUpArrow
;
46 typedef struct tagMSGBOX
{
59 typedef MSGBOX FAR
* LPMSGBOX
;
61 LONG
SystemMessageBoxProc(HWND hwnd
, WORD message
, WORD wParam
, LONG lParam
);
63 /**************************************************************************
67 int MessageBox(HWND hWnd
, LPSTR str
, LPSTR title
, WORD type
)
80 wndPtr
= WIN_FindWndPtr(hWnd
);
83 dprintf_msgbox(stddeb
,"MessageBox(NULL, %08X='%s', %08X='%s', %04X)\n",
84 str
, str
, title
, title
, type
);
87 hInst
= wndPtr
->hInstance
;
88 dprintf_msgbox(stddeb
,"MessageBox(%04X, %08X='%s', %08X='%s', %04X)\n",
89 hWnd
, str
, str
, title
, title
, type
);
91 lpmb
= (LPMSGBOX
) malloc(sizeof(MSGBOX
));
92 memset(lpmb
, 0, sizeof(MSGBOX
));
93 /* lpmb->Title = title;*/
94 lpmb
->Title
= (LPSTR
) malloc(strlen(title
) + 1);
95 strcpy(lpmb
->Title
, title
);
99 lpmb
->Str
= (LPSTR
) malloc(strlen(str
) + 1);
100 strcpy(lpmb
->Str
, str
);
104 lpmb
->Str
= (LPSTR
) malloc(8);
105 strcpy(lpmb
->Str
, "Message");
108 lpmb
->ActiveFlg
= TRUE
;
109 wndClass
.style
= CS_HREDRAW
| CS_VREDRAW
;
110 wndClass
.lpfnWndProc
= (WNDPROC
)SystemMessageBoxProc
;
111 wndClass
.cbClsExtra
= 0;
112 wndClass
.cbWndExtra
= 0;
113 wndClass
.hInstance
= hInst
;
114 wndClass
.hIcon
= (HICON
)NULL
;
115 wndClass
.hCursor
= LoadCursor((HANDLE
)NULL
, IDC_ARROW
);
116 wndClass
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
117 wndClass
.lpszMenuName
= NULL
;
118 wndClass
.lpszClassName
= "MESSAGEBOX";
119 dprintf_msgbox(stddeb
, "MessageBox // before RegisterClass, '%s' '%s' !\n", str
, title
);
120 if (!RegisterClass(&wndClass
)) {
121 printf("Unable to Register class 'MESSAGEBOX' !\n");
122 if (lpmb
!= NULL
) free(lpmb
);
125 dwStyle
= WS_POPUP
| WS_DLGFRAME
| WS_VISIBLE
;
126 if ((type
& (MB_SYSTEMMODAL
| MB_TASKMODAL
)) == 0) dwStyle
|= WS_CAPTION
;
127 hWndOld
= GetFocus();
128 hDlg
= CreateWindow("MESSAGEBOX", lpmb
->Title
, dwStyle
, 100, 150, 400, 160,
129 (HWND
)NULL
, (HMENU
)NULL
, hInst
, (LPSTR
)lpmb
);
131 printf("Unable to create 'MESSAGEBOX' window !\n");
132 if (lpmb
!= NULL
) free(lpmb
);
135 dprintf_msgbox(stddeb
, "MessageBox // before Msg Loop !\n");
137 if (!lpmb
->ActiveFlg
) break;
138 if (!GetMessage(&msg
, (HWND
)NULL
, 0, 0)) break;
139 TranslateMessage(&msg
);
140 if ((type
& (MB_SYSTEMMODAL
| MB_TASKMODAL
)) != 0 &&
142 switch(msg
.message
) {
151 DispatchMessage(&msg
);
154 nRet
= lpmb
->wRetVal
;
155 if (lpmb
!= NULL
) free(lpmb
);
156 if (!UnregisterClass("MESSAGEBOX", hInst
)) return 0;
157 dprintf_msgbox(stddeb
, "MessageBox return %04X !\n", nRet
);
162 LPMSGBOX
MsgBoxGetStorageHeader(HWND hwnd
)
166 wndPtr
= WIN_FindWndPtr(hwnd
);
168 printf("Bad Window handle on MessageBox !\n");
171 lpmb
= *((LPMSGBOX
*)&wndPtr
->wExtra
[1]);
178 LONG
SystemMessageBoxProc(HWND hWnd
, WORD message
, WORD wParam
, LONG lParam
)
181 CREATESTRUCT
*createStruct
;
190 dprintf_msgbox(stddeb
, "MessageBox WM_CREATE hWnd=%04X !\n", hWnd
);
191 wndPtr
= WIN_FindWndPtr(hWnd
);
192 createStruct
= (CREATESTRUCT
*)lParam
;
193 lpmb
= (LPMSGBOX
)createStruct
->lpCreateParams
;
194 if (lpmb
== NULL
) break;
195 *((LPMSGBOX
*)&wndPtr
->wExtra
[1]) = lpmb
;
196 dprintf_msgbox(stddeb
, "MessageBox WM_CREATE title='%s' str='%s' !\n",
197 lpmb
->Title
, lpmb
->Str
);
198 GetClientRect(hWnd
, &rect
);
199 CopyRect(&lpmb
->rectStr
, &rect
);
200 lpmb
->rectStr
.bottom
-= 32;
201 switch(lpmb
->wType
& MB_TYPEMASK
) {
203 lpmb
->hWndYes
= CreateWindow("BUTTON", ButtonText
.Ok
.Label
,
204 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
205 rect
.right
/ 2 - 30, rect
.bottom
- 25,
206 60, 18, hWnd
, IDOK
, wndPtr
->hInstance
, 0L);
209 lpmb
->hWndYes
= CreateWindow("BUTTON", ButtonText
.Ok
.Label
,
210 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
211 rect
.right
/ 2 - 65, rect
.bottom
- 25,
212 60, 18, hWnd
, IDOK
, wndPtr
->hInstance
, 0L);
213 lpmb
->hWndCancel
= CreateWindow("BUTTON", ButtonText
.Cancel
.Label
,
214 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
215 rect
.right
/ 2 + 5, rect
.bottom
- 25,
216 60, 18, hWnd
, IDCANCEL
, wndPtr
->hInstance
, 0L);
218 case MB_ABORTRETRYIGNORE
:
219 lpmb
->hWndYes
= CreateWindow("BUTTON", ButtonText
.Retry
.Label
,
220 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
221 rect
.right
/ 2 - 100, rect
.bottom
- 25,
222 60, 18, hWnd
, IDRETRY
, wndPtr
->hInstance
, 0L);
223 lpmb
->hWndNo
= CreateWindow("BUTTON", ButtonText
.Ignore
.Label
,
224 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
225 rect
.right
/ 2 - 30, rect
.bottom
- 25,
226 60, 18, hWnd
, IDIGNORE
, wndPtr
->hInstance
, 0L);
227 lpmb
->hWndCancel
= CreateWindow("BUTTON", ButtonText
.Abort
.Label
,
228 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
229 rect
.right
/ 2 + 40, rect
.bottom
- 25,
230 60, 18, hWnd
, IDABORT
, wndPtr
->hInstance
, 0L);
233 lpmb
->hWndYes
= CreateWindow("BUTTON", ButtonText
.Yes
.Label
,
234 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
235 rect
.right
/ 2 - 65, rect
.bottom
- 25,
236 60, 18, hWnd
, IDYES
, wndPtr
->hInstance
, 0L);
237 lpmb
->hWndNo
= CreateWindow("BUTTON", ButtonText
.No
.Label
,
238 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
239 rect
.right
/ 2 + 5, rect
.bottom
- 25,
240 60, 18, hWnd
, IDNO
, wndPtr
->hInstance
, 0L);
242 case MB_YESNOCANCEL
:
243 lpmb
->hWndYes
= CreateWindow("BUTTON", ButtonText
.Yes
.Label
,
244 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
245 rect
.right
/ 2 - 100, rect
.bottom
- 25,
246 60, 18, hWnd
, IDYES
, wndPtr
->hInstance
, 0L);
247 lpmb
->hWndNo
= CreateWindow("BUTTON", ButtonText
.No
.Label
,
248 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
249 rect
.right
/ 2 - 30, rect
.bottom
- 25,
250 60, 18, hWnd
, IDNO
, wndPtr
->hInstance
, 0L);
251 lpmb
->hWndCancel
= CreateWindow("BUTTON", ButtonText
.Cancel
.Label
,
252 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
253 rect
.right
/ 2 + 40, rect
.bottom
- 25,
254 60, 18, hWnd
, IDCANCEL
, wndPtr
->hInstance
, 0L);
257 switch(lpmb
->wType
& MB_ICONMASK
) {
258 case MB_ICONEXCLAMATION
:
259 printf("MsgBox LoadIcon Exclamation !\n");
260 lpmb
->hIcon
= LoadIcon((HINSTANCE
)NULL
, IDI_EXCLAMATION
);
262 case MB_ICONQUESTION
:
263 printf("MsgBox LoadIcon Question !\n");
264 lpmb
->hIcon
= LoadIcon((HINSTANCE
)NULL
, IDI_QUESTION
);
266 case MB_ICONASTERISK
:
267 printf("MsgBox LoadIcon Asterisk !\n");
268 lpmb
->hIcon
= LoadIcon((HINSTANCE
)NULL
, IDI_ASTERISK
);
271 printf("MsgBox LoadIcon Hand !\n");
272 lpmb
->hIcon
= LoadIcon((HINSTANCE
)NULL
, IDI_HAND
);
275 if (lpmb
->hIcon
!= (HICON
)NULL
) {
276 SetRect(&lpmb
->rectIcon
, 16,
277 lpmb
->rectStr
.bottom
/ 2 - 16, 48,
278 lpmb
->rectStr
.bottom
/ 2 + 16);
279 lpmb
->rectStr
.left
+= 64;
283 dprintf_msgbox(stddeb
, "MessageBox WM_SHOWWINDOW hWnd=%04X !\n", hWnd
);
284 if (!(wParam
== 0 && lParam
== 0L)) {
285 InvalidateRect(hWnd
, NULL
, TRUE
);
289 dprintf_msgbox(stddeb
, "MessageBox WM_PAINT hWnd=%04X !\n", hWnd
);
290 lpmb
= MsgBoxGetStorageHeader(hWnd
);
291 if (lpmb
== NULL
) break;
292 if (!lpmb
->ActiveFlg
) break;
293 hDC
= BeginPaint(hWnd
, &ps
);
295 printf("MessageBox WM_PAINT // BeginPaint returned BAD hDC !\n");
298 GetClientRect(hWnd
, &rect
);
299 FillRect(hDC
, &rect
, GetStockObject(WHITE_BRUSH
));
300 CopyRect(&rect
, &lpmb
->rectStr
);
301 OldTextColor
= SetTextColor(hDC
, 0x00000000);
303 DrawIcon(hDC
, lpmb
->rectIcon
.left
,
304 lpmb
->rectIcon
.top
, lpmb
->hIcon
);
305 DrawText(hDC
, lpmb
->Str
, -1, &rect
,
306 DT_CALCRECT
| DT_CENTER
| DT_WORDBREAK
);
307 rect
.top
= lpmb
->rectStr
.bottom
/ 2 - rect
.bottom
/ 2;
308 rect
.bottom
= lpmb
->rectStr
.bottom
/ 2 + rect
.bottom
/ 2;
309 DrawText(hDC
, lpmb
->Str
, -1, &rect
, DT_CENTER
| DT_WORDBREAK
);
310 SetTextColor(hDC
, OldTextColor
);
312 dprintf_msgbox(stddeb
, "MessageBox End of WM_PAINT !\n");
315 dprintf_msgbox(stddeb
, "MessageBox WM_DESTROY !\n");
317 lpmb
= MsgBoxGetStorageHeader(hWnd
);
318 if (lpmb
== NULL
) break;
319 if (lpmb
->hIcon
) DestroyIcon(lpmb
->hIcon
);
320 if (lpmb
->hWndYes
) DestroyWindow(lpmb
->hWndYes
);
321 if (lpmb
->hWndNo
) DestroyWindow(lpmb
->hWndNo
);
322 if (lpmb
->hWndCancel
) DestroyWindow(lpmb
->hWndCancel
);
323 dprintf_msgbox(stddeb
, "MessageBox WM_DESTROY end !\n");
324 lpmb
->ActiveFlg
= FALSE
;
327 lpmb
= MsgBoxGetStorageHeader(hWnd
);
328 if (lpmb
== NULL
) break;
329 if (wParam
< IDOK
|| wParam
> IDNO
) return(0);
330 lpmb
->wRetVal
= wParam
;
331 dprintf_msgbox(stddeb
, "MessageBox sending WM_CLOSE !\n");
332 PostMessage(hWnd
, WM_CLOSE
, 0, 0L);
335 lpmb
= MsgBoxGetStorageHeader(hWnd
);
336 /* if (wParam >= 'a' || wParam <= 'z') wParam -= 'a' - 'A'; */
337 wParam
= toupper(wParam
);
338 if (wParam
== ButtonText
.Yes
.Hotkey
)
339 lpmb
->wRetVal
= IDYES
;
340 else if (wParam
== ButtonText
.Ok
.Hotkey
)
341 lpmb
->wRetVal
= IDOK
;
342 else if (wParam
== ButtonText
.Retry
.Hotkey
)
343 lpmb
->wRetVal
= IDRETRY
;
344 else if (wParam
== ButtonText
.Abort
.Hotkey
)
345 lpmb
->wRetVal
= IDABORT
;
346 else if (wParam
== ButtonText
.No
.Hotkey
)
347 lpmb
->wRetVal
= IDNO
;
348 else if (wParam
== ButtonText
.Ignore
.Hotkey
)
349 lpmb
->wRetVal
= IDIGNORE
;
350 else if ((wParam
== ButtonText
.Ok
.Hotkey
) || (wParam
== VK_ESCAPE
))
351 lpmb
->wRetVal
= IDCANCEL
;
354 if (lpmb
== NULL
) break;
355 ShowWindow(hWnd
, SW_HIDE
);
356 PostMessage(hWnd
, WM_CLOSE
, 0, 0L);
359 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
366 /*************************************************************************
367 * "About Wine..." Dialog Box
369 BOOL FAR PASCAL
AboutWine_Proc(HWND hDlg
, WORD msg
, WORD wParam
, LONG lParam
)
379 static char str
[256];
380 static HBITMAP hBitMap
= 0;
381 static BOOL CreditMode
;
382 static HANDLE hFile
= 0;
386 strcpy(str
, "WINELOGO");
387 hBitMap
= LoadBitmap((HINSTANCE
)NULL
, (LPSTR
)str
);
389 strcpy(str
, "LICENSE");
390 printf("str = '%s'\n", str
);
391 hFile
= OpenFile((LPSTR
)str
, &ofstruct
, OF_READ
);
392 ptr
= (LPSTR
)malloc(2048);
393 lseek(hFile
, 0L, SEEK_SET
);
394 _lread(hFile
, ptr
, 2000L);
398 hDC
= BeginPaint(hDlg
, &ps
);
399 GetClientRect(hDlg
, &rect
);
401 FillRect(hDC
, &rect
, GetStockObject(WHITE_BRUSH
));
402 InflateRect(&rect
, -8, -8);
403 DrawText(hDC
, ptr
, -1, &rect
, DT_LEFT
| DT_WORDBREAK
);
407 FillRect(hDC
, &rect
, GetStockObject(GRAY_BRUSH
));
408 InflateRect(&rect
, -3, -3);
409 FrameRect(hDC
, &rect
, GetStockObject(BLACK_BRUSH
));
410 InflateRect(&rect
, -10, -10);
411 hMemDC
= CreateCompatibleDC(hDC
);
412 hbmpOld
= SelectObject(hMemDC
, hBitMap
);
413 GetObject(hBitMap
, sizeof(BITMAP
), (LPSTR
)&bm
);
414 BitBlt(hDC
, rect
.left
, rect
.top
, bm
.bmWidth
, bm
.bmHeight
,
415 hMemDC
, 0, 0, SRCCOPY
);
416 SelectObject( hMemDC
, hbmpOld
);
425 SetWindowPos(hDlg
, (HWND
)NULL
, 0, 0, 640, 480,
426 SWP_NOMOVE
| SWP_NOZORDER
);
429 SetWindowPos(hDlg
, (HWND
)NULL
, 0, 0, 320, 250,
430 SWP_NOMOVE
| SWP_NOZORDER
);
432 CreditMode
= !CreditMode
;
433 ShowWindow(GetDlgItem(hDlg
, IDYES
), CreditMode
? SW_HIDE
: SW_SHOW
);
434 ShowWindow(GetDlgItem(hDlg
, IDOK
), CreditMode
? SW_HIDE
: SW_SHOW
);
435 InvalidateRect(hDlg
, (LPRECT
)NULL
, TRUE
);
440 if (hBitMap
!= 0 ) DeleteObject(hBitMap
);
441 if (ptr
!= NULL
) free(ptr
);
442 EndDialog(hDlg
, TRUE
);
452 /**************************************************************************
453 * FatalAppExit [USER.137]
456 void FatalAppExit(WORD wAction
, LPSTR str
)
458 MessageBox((HWND
)NULL
, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);