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.

MsgBox.h 2.0KB

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 <string>
  21. #include <windows.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 const char* AppName;
  30. // Wrapper around Win32 MessageBox()
  31. static int MsgBox(HWND parent, const char* msg, UINT flags) {
  32. const char* msgType = 0;
  33. UINT tflags = flags & 0x70;
  34. if (tflags == MB_ICONHAND)
  35. msgType = "Error";
  36. else if (tflags == MB_ICONQUESTION)
  37. msgType = "Question";
  38. else if (tflags == MB_ICONEXCLAMATION)
  39. msgType = "Warning";
  40. else if (tflags == MB_ICONASTERISK)
  41. msgType = "Information";
  42. flags |= MB_TOPMOST | MB_SETFOREGROUND;
  43. int len = strlen(AppName) + 1;
  44. if (msgType) len += strlen(msgType) + 3;
  45. std::string title = AppName;
  46. if (msgType) {
  47. title += " : ";
  48. title += msgType;
  49. }
  50. return MessageBox(parent, msg, title.c_str(), flags);
  51. }
  52. };
  53. };
  54. #endif