2 * 'Wine' MessageBox function handling
4 * Copyright 1993 Martin Ayotte
7 static char Copyright
[] = "Copyright Martin Ayotte, 1993";
15 #include <sys/types.h>
19 #include "prototypes.h"
23 extern HINSTANCE hSysRes
;
24 extern HBITMAP hUpArrow
;
26 typedef struct tagMSGBOX
{
39 typedef MSGBOX FAR
* LPMSGBOX
;
41 LONG
SystemMessageBoxProc(HWND hwnd
, WORD message
, WORD wParam
, LONG lParam
);
43 /**************************************************************************
47 int MessageBox(HWND hWnd
, LPSTR str
, LPSTR title
, WORD type
)
56 wndPtr
= WIN_FindWndPtr(hWnd
);
60 printf("MessageBox(NULL, '%s', '%s', %04X)\n", str
, title
, type
);
64 hInst
= wndPtr
->hInstance
;
66 printf("MessageBox(%04X, '%s', '%s', %04X)\n", hWnd
, str
, title
, type
);
69 wndClass
.style
= CS_HREDRAW
| CS_VREDRAW
;
70 wndClass
.lpfnWndProc
= (WNDPROC
)SystemMessageBoxProc
;
71 wndClass
.cbClsExtra
= 0;
72 wndClass
.cbWndExtra
= 0;
73 wndClass
.hInstance
= hInst
;
74 wndClass
.hIcon
= (HICON
)NULL
;
75 wndClass
.hCursor
= LoadCursor((HANDLE
)NULL
, IDC_ARROW
);
76 wndClass
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
77 wndClass
.lpszMenuName
= NULL
;
78 wndClass
.lpszClassName
= "MESSAGEBOX";
79 if (!RegisterClass(&wndClass
)) {
80 printf("Unable to Register class 'MESSAGEBOX' !\n");
83 memset(&mb
, 0, sizeof(MSGBOX
));
88 dwStyle
= WS_POPUP
| WS_DLGFRAME
| WS_VISIBLE
;
89 if ((type
& (MB_SYSTEMMODAL
| MB_TASKMODAL
)) == 0) dwStyle
|= WS_CAPTION
;
91 hDlg
= CreateWindow("MESSAGEBOX", title
, dwStyle
, 100, 150, 400, 120,
92 (HWND
)NULL
, (HMENU
)NULL
, hInst
, (LPSTR
)&mb
);
94 printf("Unable to create 'MESSAGEBOX' window !\n");
98 printf( "MessageBox // before Msg Loop !\n");
101 if (!mb
.ActiveFlg
) break;
102 if (!GetMessage(&msg
, (HWND
)NULL
, 0, 0)) break;
103 TranslateMessage(&msg
);
104 if ((type
& (MB_SYSTEMMODAL
| MB_TASKMODAL
)) != 0 &&
106 switch(msg
.message
) {
115 DispatchMessage(&msg
);
118 if (!UnregisterClass("MESSAGEBOX", hInst
)) return 0;
120 printf( "MessageBox return %04X !\n", mb
.wRetVal
);
126 LPMSGBOX
MsgBoxGetStorageHeader(HWND hwnd
)
130 wndPtr
= WIN_FindWndPtr(hwnd
);
132 printf("Bad Window handle on MessageBox !\n");
135 lpmb
= *((LPMSGBOX
*)&wndPtr
->wExtra
[1]);
142 LONG
SystemMessageBoxProc(HWND hWnd
, WORD message
, WORD wParam
, LONG lParam
)
145 CREATESTRUCT
*createStruct
;
161 printf("MessageBox WM_CREATE !\n");
163 wndPtr
= WIN_FindWndPtr(hWnd
);
164 createStruct
= (CREATESTRUCT
*)lParam
;
165 lpmbInit
= (LPMSGBOX
)createStruct
->lpCreateParams
;
166 if (lpmbInit
== 0) break;
167 *((LPMSGBOX
*)&wndPtr
->wExtra
[1]) = lpmbInit
;
168 lpmb
= MsgBoxGetStorageHeader(hWnd
);
169 GetClientRect(hWnd
, &rect
);
170 CopyRect(&lpmb
->rectStr
, &rect
);
171 lpmb
->rectStr
.bottom
-= 32;
172 switch(lpmb
->wType
& MB_TYPEMASK
) {
174 lpmb
->hWndYes
= CreateWindow("BUTTON", "&Ok",
175 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
176 rect
.right
/ 2 - 30, rect
.bottom
- 25,
177 60, 18, hWnd
, IDOK
, wndPtr
->hInstance
, 0L);
180 lpmb
->hWndYes
= CreateWindow("BUTTON", "&Ok",
181 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
182 rect
.right
/ 2 - 65, rect
.bottom
- 25,
183 60, 18, hWnd
, IDOK
, wndPtr
->hInstance
, 0L);
184 lpmb
->hWndCancel
= CreateWindow("BUTTON", "&Cancel",
185 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
186 rect
.right
/ 2 + 5, rect
.bottom
- 25,
187 60, 18, hWnd
, IDCANCEL
, wndPtr
->hInstance
, 0L);
189 case MB_ABORTRETRYIGNORE
:
190 lpmb
->hWndYes
= CreateWindow("BUTTON", "&Retry",
191 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
192 rect
.right
/ 2 - 100, rect
.bottom
- 25,
193 60, 18, hWnd
, IDRETRY
, wndPtr
->hInstance
, 0L);
194 lpmb
->hWndNo
= CreateWindow("BUTTON", "&Ignore",
195 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
196 rect
.right
/ 2 - 30, rect
.bottom
- 25,
197 60, 18, hWnd
, IDIGNORE
, wndPtr
->hInstance
, 0L);
198 lpmb
->hWndCancel
= CreateWindow("BUTTON", "&Abort",
199 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
200 rect
.right
/ 2 + 40, rect
.bottom
- 25,
201 60, 18, hWnd
, IDABORT
, wndPtr
->hInstance
, 0L);
204 lpmb
->hWndYes
= CreateWindow("BUTTON", "&Yes",
205 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
206 rect
.right
/ 2 - 65, rect
.bottom
- 25,
207 60, 18, hWnd
, IDYES
, wndPtr
->hInstance
, 0L);
208 lpmb
->hWndNo
= CreateWindow("BUTTON", "&No",
209 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
210 rect
.right
/ 2 + 5, rect
.bottom
- 25,
211 60, 18, hWnd
, IDNO
, wndPtr
->hInstance
, 0L);
213 case MB_YESNOCANCEL
:
214 lpmb
->hWndYes
= CreateWindow("BUTTON", "&Yes",
215 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
216 rect
.right
/ 2 - 100, rect
.bottom
- 25,
217 60, 18, hWnd
, IDYES
, wndPtr
->hInstance
, 0L);
218 lpmb
->hWndNo
= CreateWindow("BUTTON", "&No",
219 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
220 rect
.right
/ 2 - 30, rect
.bottom
- 25,
221 60, 18, hWnd
, IDNO
, wndPtr
->hInstance
, 0L);
222 lpmb
->hWndCancel
= CreateWindow("BUTTON", "&Cancel",
223 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
224 rect
.right
/ 2 + 40, rect
.bottom
- 25,
225 60, 18, hWnd
, IDCANCEL
, wndPtr
->hInstance
, 0L);
228 switch(lpmb
->wType
& MB_ICONMASK
) {
229 case MB_ICONEXCLAMATION
:
230 printf("MsgBox LoadIcon Exclamation !\n");
231 lpmb
->hIcon
= LoadIcon((HINSTANCE
)NULL
, IDI_EXCLAMATION
);
233 case MB_ICONQUESTION
:
234 printf("MsgBox LoadIcon Question !\n");
235 lpmb
->hIcon
= LoadIcon((HINSTANCE
)NULL
, IDI_QUESTION
);
237 case MB_ICONASTERISK
:
238 printf("MsgBox LoadIcon Asterisk !\n");
239 lpmb
->hIcon
= LoadIcon((HINSTANCE
)NULL
, IDI_ASTERISK
);
242 printf("MsgBox LoadIcon Hand !\n");
243 lpmb
->hIcon
= LoadIcon((HINSTANCE
)NULL
, IDI_HAND
);
246 if (lpmb
->hIcon
!= (HICON
)NULL
) {
247 SetRect(&lpmb
->rectIcon
, 16,
248 lpmb
->rectStr
.bottom
/ 2 - 16, 48,
249 lpmb
->rectStr
.bottom
/ 2 + 16);
250 lpmb
->rectStr
.left
+= 64;
255 printf("MessageBox WM_PAINT !\n");
257 lpmb
= MsgBoxGetStorageHeader(hWnd
);
258 CopyRect(&rect
, &lpmb
->rectStr
);
259 hDC
= BeginPaint(hWnd
, &ps
);
260 OldTextColor
= SetTextColor(hDC
, 0x00000000);
262 DrawIcon(hDC
, lpmb
->rectIcon
.left
,
263 lpmb
->rectIcon
.top
, lpmb
->hIcon
);
264 DrawText(hDC
, lpmb
->Str
, -1, &rect
,
265 DT_CALCRECT
| DT_CENTER
| DT_WORDBREAK
);
266 rect
.top
= lpmb
->rectStr
.bottom
/ 2 - rect
.bottom
/ 2;
267 rect
.bottom
= lpmb
->rectStr
.bottom
/ 2 + rect
.bottom
/ 2;
268 DrawText(hDC
, lpmb
->Str
, -1, &rect
, DT_CENTER
| DT_WORDBREAK
);
269 SetTextColor(hDC
, OldTextColor
);
272 printf("MessageBox End of WM_PAINT !\n");
277 printf("MessageBox WM_DESTROY !\n");
280 lpmb
= MsgBoxGetStorageHeader(hWnd
);
281 lpmb
->ActiveFlg
= FALSE
;
282 if (lpmb
->hIcon
) DestroyIcon(lpmb
->hIcon
);
283 if (lpmb
->hWndYes
) DestroyWindow(lpmb
->hWndYes
);
284 if (lpmb
->hWndNo
) DestroyWindow(lpmb
->hWndNo
);
285 if (lpmb
->hWndCancel
) DestroyWindow(lpmb
->hWndCancel
);
287 printf("MessageBox WM_DESTROY end !\n");
291 lpmb
= MsgBoxGetStorageHeader(hWnd
);
292 if (wParam
< IDOK
|| wParam
> IDNO
) return(0);
293 lpmb
->wRetVal
= wParam
;
295 printf("MessageBox sending WM_CLOSE !\n");
297 PostMessage(hWnd
, WM_CLOSE
, 0, 0L);
300 lpmb
= MsgBoxGetStorageHeader(hWnd
);
301 if (wParam
>= 'a' || wParam
<= 'z') wParam
-= 'a' - 'A';
304 lpmb
->wRetVal
= IDYES
;
307 lpmb
->wRetVal
= IDOK
;
310 lpmb
->wRetVal
= IDRETRY
;
313 lpmb
->wRetVal
= IDABORT
;
316 lpmb
->wRetVal
= IDNO
;
319 lpmb
->wRetVal
= IDIGNORE
;
323 lpmb
->wRetVal
= IDCANCEL
;
328 PostMessage(hWnd
, WM_CLOSE
, 0, 0L);
331 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
338 /*************************************************************************
339 * "About Wine..." Dialog Box
341 BOOL FAR PASCAL
AboutWine_Proc(HWND hDlg
, WORD msg
, WORD wParam
, LONG lParam
)
353 static char str
[256];
354 static HBITMAP hBitMap
= 0;
355 static BOOL CreditMode
;
356 static HANDLE hFile
= 0;
360 strcpy(str
, "WINELOGO");
361 hBitMap
= LoadBitmap((HINSTANCE
)NULL
, (LPSTR
)str
);
363 strcpy(str
, "PROPOSED_LICENSE");
364 printf("str = '%s'\n", str
);
365 hFile
= OpenFile((LPSTR
)str
, &ofstruct
, OF_READ
);
366 ptr
= (LPSTR
)malloc(2048);
367 lseek(hFile
, 0L, SEEK_SET
);
368 _lread(hFile
, ptr
, 2000L);
372 hDC
= BeginPaint(hDlg
, &ps
);
373 GetClientRect(hDlg
, &rect
);
375 FillRect(hDC
, &rect
, GetStockObject(WHITE_BRUSH
));
376 InflateRect(&rect
, -8, -8);
377 DrawText(hDC
, ptr
, -1, &rect
, DT_LEFT
| DT_WORDBREAK
);
381 FillRect(hDC
, &rect
, GetStockObject(GRAY_BRUSH
));
382 InflateRect(&rect
, -3, -3);
383 FrameRect(hDC
, &rect
, GetStockObject(BLACK_BRUSH
));
384 InflateRect(&rect
, -10, -10);
385 hMemDC
= CreateCompatibleDC(hDC
);
386 SelectObject(hMemDC
, hBitMap
);
387 GetObject(hBitMap
, sizeof(BITMAP
), (LPSTR
)&bm
);
388 BitBlt(hDC
, rect
.left
, rect
.top
, bm
.bmWidth
, bm
.bmHeight
,
389 hMemDC
, 0, 0, SRCCOPY
);
398 SetWindowPos(hDlg
, (HWND
)NULL
, 0, 0, 640, 480,
399 SWP_NOMOVE
| SWP_NOZORDER
);
402 SetWindowPos(hDlg
, (HWND
)NULL
, 0, 0, 320, 250,
403 SWP_NOMOVE
| SWP_NOZORDER
);
405 CreditMode
= !CreditMode
;
406 ShowWindow(GetDlgItem(hDlg
, IDYES
), CreditMode
? SW_HIDE
: SW_SHOW
);
407 ShowWindow(GetDlgItem(hDlg
, IDOK
), CreditMode
? SW_HIDE
: SW_SHOW
);
408 InvalidateRect(hDlg
, (LPRECT
)NULL
, TRUE
);
413 CloseDLG
: if (hBitMap
!= 0 ) DeleteObject(hBitMap
);
414 if (ptr
!= NULL
) free(ptr
);
415 EndDialog(hDlg
, TRUE
);
425 /**************************************************************************
426 * FatalAppExit [USER.137]
429 void FatalAppExit(WORD wAction
, LPSTR str
)
431 MessageBox((HWND
)NULL
, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);