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
)
57 wndPtr
= WIN_FindWndPtr(hWnd
);
61 printf("MessageBox(NULL, '%s', '%s', %04X)\n", str
, title
, type
);
65 hInst
= wndPtr
->hInstance
;
67 printf("MessageBox(%04X, '%s', '%s', %04X)\n", hWnd
, str
, title
, type
);
70 lpmb
= (LPMSGBOX
) malloc(sizeof(MSGBOX
));
71 memset(lpmb
, 0, sizeof(MSGBOX
));
72 /* lpmb->Title = title;*/
73 lpmb
->Title
= (LPSTR
) malloc(strlen(title
) + 1);
74 strcpy(lpmb
->Title
, title
);
76 lpmb
->Str
= (LPSTR
) malloc(strlen(str
) + 1);
77 strcpy(lpmb
->Str
, str
);
79 lpmb
->ActiveFlg
= TRUE
;
80 wndClass
.style
= CS_HREDRAW
| CS_VREDRAW
;
81 wndClass
.lpfnWndProc
= (WNDPROC
)SystemMessageBoxProc
;
82 wndClass
.cbClsExtra
= 0;
83 wndClass
.cbWndExtra
= 0;
84 wndClass
.hInstance
= hInst
;
85 wndClass
.hIcon
= (HICON
)NULL
;
86 wndClass
.hCursor
= LoadCursor((HANDLE
)NULL
, IDC_ARROW
);
87 wndClass
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
88 wndClass
.lpszMenuName
= NULL
;
89 wndClass
.lpszClassName
= "MESSAGEBOX";
91 printf( "MessageBox // before RegisterClass, '%s' '%s' !\n", str
, title
);
93 if (!RegisterClass(&wndClass
)) {
94 printf("Unable to Register class 'MESSAGEBOX' !\n");
95 if (lpmb
!= NULL
) free(lpmb
);
98 dwStyle
= WS_POPUP
| WS_DLGFRAME
| WS_VISIBLE
;
99 if ((type
& (MB_SYSTEMMODAL
| MB_TASKMODAL
)) == 0) dwStyle
|= WS_CAPTION
;
100 hWndOld
= GetFocus();
101 hDlg
= CreateWindow("MESSAGEBOX", lpmb
->Title
, dwStyle
, 100, 150, 400, 160,
102 (HWND
)NULL
, (HMENU
)NULL
, hInst
, (LPSTR
)lpmb
);
104 printf("Unable to create 'MESSAGEBOX' window !\n");
105 if (lpmb
!= NULL
) free(lpmb
);
109 printf( "MessageBox // before Msg Loop !\n");
112 if (!lpmb
->ActiveFlg
) break;
113 if (!GetMessage(&msg
, (HWND
)NULL
, 0, 0)) break;
114 TranslateMessage(&msg
);
115 if ((type
& (MB_SYSTEMMODAL
| MB_TASKMODAL
)) != 0 &&
117 switch(msg
.message
) {
126 DispatchMessage(&msg
);
129 nRet
= lpmb
->wRetVal
;
130 if (lpmb
!= NULL
) free(lpmb
);
131 if (!UnregisterClass("MESSAGEBOX", hInst
)) return 0;
133 printf( "MessageBox return %04X !\n", nRet
);
139 LPMSGBOX
MsgBoxGetStorageHeader(HWND hwnd
)
143 wndPtr
= WIN_FindWndPtr(hwnd
);
145 printf("Bad Window handle on MessageBox !\n");
148 lpmb
= *((LPMSGBOX
*)&wndPtr
->wExtra
[1]);
155 LONG
SystemMessageBoxProc(HWND hWnd
, WORD message
, WORD wParam
, LONG lParam
)
158 CREATESTRUCT
*createStruct
;
173 printf("MessageBox WM_CREATE !\n");
175 wndPtr
= WIN_FindWndPtr(hWnd
);
176 createStruct
= (CREATESTRUCT
*)lParam
;
177 lpmb
= (LPMSGBOX
)createStruct
->lpCreateParams
;
178 if (lpmb
== NULL
) break;
179 *((LPMSGBOX
*)&wndPtr
->wExtra
[1]) = lpmb
;
181 printf("MessageBox WM_CREATE title='%s' str='%s' !\n",
182 lpmb
->Title
, lpmb
->Str
);
184 GetClientRect(hWnd
, &rect
);
185 CopyRect(&lpmb
->rectStr
, &rect
);
186 lpmb
->rectStr
.bottom
-= 32;
187 switch(lpmb
->wType
& MB_TYPEMASK
) {
189 lpmb
->hWndYes
= CreateWindow("BUTTON", "&Ok",
190 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
191 rect
.right
/ 2 - 30, rect
.bottom
- 25,
192 60, 18, hWnd
, IDOK
, wndPtr
->hInstance
, 0L);
195 lpmb
->hWndYes
= CreateWindow("BUTTON", "&Ok",
196 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
197 rect
.right
/ 2 - 65, rect
.bottom
- 25,
198 60, 18, hWnd
, IDOK
, wndPtr
->hInstance
, 0L);
199 lpmb
->hWndCancel
= CreateWindow("BUTTON", "&Cancel",
200 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
201 rect
.right
/ 2 + 5, rect
.bottom
- 25,
202 60, 18, hWnd
, IDCANCEL
, wndPtr
->hInstance
, 0L);
204 case MB_ABORTRETRYIGNORE
:
205 lpmb
->hWndYes
= CreateWindow("BUTTON", "&Retry",
206 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
207 rect
.right
/ 2 - 100, rect
.bottom
- 25,
208 60, 18, hWnd
, IDRETRY
, wndPtr
->hInstance
, 0L);
209 lpmb
->hWndNo
= CreateWindow("BUTTON", "&Ignore",
210 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
211 rect
.right
/ 2 - 30, rect
.bottom
- 25,
212 60, 18, hWnd
, IDIGNORE
, wndPtr
->hInstance
, 0L);
213 lpmb
->hWndCancel
= CreateWindow("BUTTON", "&Abort",
214 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
215 rect
.right
/ 2 + 40, rect
.bottom
- 25,
216 60, 18, hWnd
, IDABORT
, wndPtr
->hInstance
, 0L);
219 lpmb
->hWndYes
= CreateWindow("BUTTON", "&Yes",
220 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
221 rect
.right
/ 2 - 65, rect
.bottom
- 25,
222 60, 18, hWnd
, IDYES
, wndPtr
->hInstance
, 0L);
223 lpmb
->hWndNo
= CreateWindow("BUTTON", "&No",
224 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
225 rect
.right
/ 2 + 5, rect
.bottom
- 25,
226 60, 18, hWnd
, IDNO
, wndPtr
->hInstance
, 0L);
228 case MB_YESNOCANCEL
:
229 lpmb
->hWndYes
= CreateWindow("BUTTON", "&Yes",
230 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
231 rect
.right
/ 2 - 100, rect
.bottom
- 25,
232 60, 18, hWnd
, IDYES
, wndPtr
->hInstance
, 0L);
233 lpmb
->hWndNo
= CreateWindow("BUTTON", "&No",
234 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
235 rect
.right
/ 2 - 30, rect
.bottom
- 25,
236 60, 18, hWnd
, IDNO
, wndPtr
->hInstance
, 0L);
237 lpmb
->hWndCancel
= CreateWindow("BUTTON", "&Cancel",
238 WS_CHILD
| WS_CLIPCHILDREN
| WS_VISIBLE
| BS_PUSHBUTTON
,
239 rect
.right
/ 2 + 40, rect
.bottom
- 25,
240 60, 18, hWnd
, IDCANCEL
, wndPtr
->hInstance
, 0L);
243 switch(lpmb
->wType
& MB_ICONMASK
) {
244 case MB_ICONEXCLAMATION
:
245 printf("MsgBox LoadIcon Exclamation !\n");
246 lpmb
->hIcon
= LoadIcon((HINSTANCE
)NULL
, IDI_EXCLAMATION
);
248 case MB_ICONQUESTION
:
249 printf("MsgBox LoadIcon Question !\n");
250 lpmb
->hIcon
= LoadIcon((HINSTANCE
)NULL
, IDI_QUESTION
);
252 case MB_ICONASTERISK
:
253 printf("MsgBox LoadIcon Asterisk !\n");
254 lpmb
->hIcon
= LoadIcon((HINSTANCE
)NULL
, IDI_ASTERISK
);
257 printf("MsgBox LoadIcon Hand !\n");
258 lpmb
->hIcon
= LoadIcon((HINSTANCE
)NULL
, IDI_HAND
);
261 if (lpmb
->hIcon
!= (HICON
)NULL
) {
262 SetRect(&lpmb
->rectIcon
, 16,
263 lpmb
->rectStr
.bottom
/ 2 - 16, 48,
264 lpmb
->rectStr
.bottom
/ 2 + 16);
265 lpmb
->rectStr
.left
+= 64;
270 printf("MessageBox WM_PAINT !\n");
272 lpmb
= MsgBoxGetStorageHeader(hWnd
);
273 if (lpmb
== NULL
) break;
274 CopyRect(&rect
, &lpmb
->rectStr
);
275 hDC
= BeginPaint(hWnd
, &ps
);
276 OldTextColor
= SetTextColor(hDC
, 0x00000000);
278 DrawIcon(hDC
, lpmb
->rectIcon
.left
,
279 lpmb
->rectIcon
.top
, lpmb
->hIcon
);
280 DrawText(hDC
, lpmb
->Str
, -1, &rect
,
281 DT_CALCRECT
| DT_CENTER
| DT_WORDBREAK
);
282 rect
.top
= lpmb
->rectStr
.bottom
/ 2 - rect
.bottom
/ 2;
283 rect
.bottom
= lpmb
->rectStr
.bottom
/ 2 + rect
.bottom
/ 2;
284 DrawText(hDC
, lpmb
->Str
, -1, &rect
, DT_CENTER
| DT_WORDBREAK
);
285 SetTextColor(hDC
, OldTextColor
);
288 printf("MessageBox End of WM_PAINT !\n");
293 printf("MessageBox WM_DESTROY !\n");
296 lpmb
= MsgBoxGetStorageHeader(hWnd
);
297 if (lpmb
== NULL
) break;
298 lpmb
->ActiveFlg
= FALSE
;
299 if (lpmb
->hIcon
) DestroyIcon(lpmb
->hIcon
);
300 if (lpmb
->hWndYes
) DestroyWindow(lpmb
->hWndYes
);
301 if (lpmb
->hWndNo
) DestroyWindow(lpmb
->hWndNo
);
302 if (lpmb
->hWndCancel
) DestroyWindow(lpmb
->hWndCancel
);
304 printf("MessageBox WM_DESTROY end !\n");
308 lpmb
= MsgBoxGetStorageHeader(hWnd
);
309 if (lpmb
== NULL
) break;
310 if (wParam
< IDOK
|| wParam
> IDNO
) return(0);
311 lpmb
->wRetVal
= wParam
;
313 printf("MessageBox sending WM_CLOSE !\n");
315 PostMessage(hWnd
, WM_CLOSE
, 0, 0L);
318 lpmb
= MsgBoxGetStorageHeader(hWnd
);
319 if (lpmb
== NULL
) break;
320 if (wParam
>= 'a' || wParam
<= 'z') wParam
-= 'a' - 'A';
323 lpmb
->wRetVal
= IDYES
;
326 lpmb
->wRetVal
= IDOK
;
329 lpmb
->wRetVal
= IDRETRY
;
332 lpmb
->wRetVal
= IDABORT
;
335 lpmb
->wRetVal
= IDNO
;
338 lpmb
->wRetVal
= IDIGNORE
;
342 lpmb
->wRetVal
= IDCANCEL
;
347 PostMessage(hWnd
, WM_CLOSE
, 0, 0L);
350 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
357 /*************************************************************************
358 * "About Wine..." Dialog Box
360 BOOL FAR PASCAL
AboutWine_Proc(HWND hDlg
, WORD msg
, WORD wParam
, LONG lParam
)
372 static char str
[256];
373 static HBITMAP hBitMap
= 0;
374 static BOOL CreditMode
;
375 static HANDLE hFile
= 0;
379 strcpy(str
, "WINELOGO");
380 hBitMap
= LoadBitmap((HINSTANCE
)NULL
, (LPSTR
)str
);
382 strcpy(str
, "PROPOSED_LICENSE");
383 printf("str = '%s'\n", str
);
384 hFile
= OpenFile((LPSTR
)str
, &ofstruct
, OF_READ
);
385 ptr
= (LPSTR
)malloc(2048);
386 lseek(hFile
, 0L, SEEK_SET
);
387 _lread(hFile
, ptr
, 2000L);
391 hDC
= BeginPaint(hDlg
, &ps
);
392 GetClientRect(hDlg
, &rect
);
394 FillRect(hDC
, &rect
, GetStockObject(WHITE_BRUSH
));
395 InflateRect(&rect
, -8, -8);
396 DrawText(hDC
, ptr
, -1, &rect
, DT_LEFT
| DT_WORDBREAK
);
400 FillRect(hDC
, &rect
, GetStockObject(GRAY_BRUSH
));
401 InflateRect(&rect
, -3, -3);
402 FrameRect(hDC
, &rect
, GetStockObject(BLACK_BRUSH
));
403 InflateRect(&rect
, -10, -10);
404 hMemDC
= CreateCompatibleDC(hDC
);
405 SelectObject(hMemDC
, hBitMap
);
406 GetObject(hBitMap
, sizeof(BITMAP
), (LPSTR
)&bm
);
407 BitBlt(hDC
, rect
.left
, rect
.top
, bm
.bmWidth
, bm
.bmHeight
,
408 hMemDC
, 0, 0, SRCCOPY
);
417 SetWindowPos(hDlg
, (HWND
)NULL
, 0, 0, 640, 480,
418 SWP_NOMOVE
| SWP_NOZORDER
);
421 SetWindowPos(hDlg
, (HWND
)NULL
, 0, 0, 320, 250,
422 SWP_NOMOVE
| SWP_NOZORDER
);
424 CreditMode
= !CreditMode
;
425 ShowWindow(GetDlgItem(hDlg
, IDYES
), CreditMode
? SW_HIDE
: SW_SHOW
);
426 ShowWindow(GetDlgItem(hDlg
, IDOK
), CreditMode
? SW_HIDE
: SW_SHOW
);
427 InvalidateRect(hDlg
, (LPRECT
)NULL
, TRUE
);
432 CloseDLG
: if (hBitMap
!= 0 ) DeleteObject(hBitMap
);
433 if (ptr
!= NULL
) free(ptr
);
434 EndDialog(hDlg
, TRUE
);
444 /**************************************************************************
445 * FatalAppExit [USER.137]
448 void FatalAppExit(WORD wAction
, LPSTR str
)
450 MessageBox((HWND
)NULL
, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);