1 /* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
2  *
3  * This is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This software is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this software; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
16  * USA.
17  */
18 
19 #ifndef __RFB_WIN32_MSGBOX_H__
20 #define __RFB_WIN32_MSGBOX_H__
21 
22 #include <windows.h>
23 #include <rfb_win32/TCharArray.h>
24 
25 namespace rfb {
26   namespace win32 {
27 
28     // Define rfb::win32::AppName somewhere in the application.
29     // The MsgBox function will use the specified application name
30     // as the prefix for the message box title.
31     // Message box titles are based on the (standard Win32) flags
32     // passed to the MsgBox helper function.
33 
34     extern TStr AppName;
35 
36     // Wrapper around Win32 MessageBox()
MsgBox(HWND parent,const TCHAR * msg,UINT flags)37     static int MsgBox(HWND parent, const TCHAR* msg, UINT flags) {
38       const TCHAR* msgType = 0;
39       UINT tflags = flags & 0x70;
40       if (tflags == MB_ICONHAND)
41         msgType = _T("Error");
42       else if (tflags == MB_ICONQUESTION)
43         msgType = _T("Question");
44       else if (tflags == MB_ICONEXCLAMATION)
45         msgType = _T("Warning");
46       else if (tflags == MB_ICONASTERISK)
47         msgType = _T("Information");
48       flags |= MB_TOPMOST | MB_SETFOREGROUND;
49       int len = _tcslen(AppName.buf) + 1;
50       if (msgType) len += _tcslen(msgType) + 3;
51       TCharArray title(new TCHAR[len]);
52       _tcscpy(title.buf, AppName.buf);
53       if (msgType) {
54         _tcscat(title.buf, _T(" : "));
55         _tcscat(title.buf, msgType);
56       }
57       return MessageBox(parent, msg, title.buf, flags);
58     }
59 
60   };
61 };
62 
63 #endif
64