You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #ifndef __RFB_WIN32_MSGBOX_H__
  19. #define __RFB_WIN32_MSGBOX_H__
  20. #include <windows.h>
  21. #include <rfb_win32/TCharArray.h>
  22. namespace rfb {
  23. namespace win32 {
  24. // Define rfb::win32::AppName somewhere in the application.
  25. // The MsgBox function will use the specified application name
  26. // as the prefix for the message box title.
  27. // Message box titles are based on the (standard Win32) flags
  28. // passed to the MsgBox helper function.
  29. extern TStr AppName;
  30. // Wrapper around Win32 MessageBox()
  31. static int MsgBox(HWND parent, const TCHAR* msg, UINT flags) {
  32. const TCHAR* msgType = 0;
  33. UINT tflags = flags & 0x70;
  34. if (tflags == MB_ICONHAND)
  35. msgType = _T("Error");
  36. else if (tflags == MB_ICONQUESTION)
  37. msgType = _T("Question");
  38. else if (tflags == MB_ICONEXCLAMATION)
  39. msgType = _T("Warning");
  40. else if (tflags == MB_ICONASTERISK)
  41. msgType = _T("Information");
  42. flags |= MB_TOPMOST | MB_SETFOREGROUND;
  43. int len = _tcslen(AppName.buf) + 1;
  44. if (msgType) len += _tcslen(msgType) + 3;
  45. TCharArray title(new TCHAR[len]);
  46. _tcscpy(title.buf, AppName.buf);
  47. if (msgType) {
  48. _tcscat(title.buf, _T(" : "));
  49. _tcscat(title.buf, msgType);
  50. }
  51. return MessageBox(parent, msg, title.buf, flags);
  52. }
  53. };
  54. };
  55. #endif