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.

WMCursor.cxx 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright (C) 2002-2003 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. // -=- WMCursor.cxx
  19. // *** DOESN'T SEEM TO WORK WITH GetCursorInfo POS CODE BUILT-IN UNDER NT4SP6
  20. // *** INSTEAD, WE LOOK FOR Win2000/Win98 OR ABOVE
  21. #define WINVER 0x0500
  22. #include <rfb_win32/WMCursor.h>
  23. #include <rfb_win32/OSVersion.h>
  24. #include <rfb_win32/Win32Util.h>
  25. #include <rfb/Exception.h>
  26. #include <rfb/LogWriter.h>
  27. using namespace rdr;
  28. using namespace rfb;
  29. using namespace rfb::win32;
  30. static LogWriter vlog("WMCursor");
  31. typedef BOOL (WINAPI *_GetCursorInfo_proto)(PCURSORINFO pci);
  32. DynamicFn<_GetCursorInfo_proto> _GetCursorInfo(_T("user32.dll"), "GetCursorInfo");
  33. WMCursor::WMCursor() : hooks(0), library(0), use_getCursorInfo(false), cursor(0) {
  34. #if (WINVER >= 0x0500)
  35. // Check the OS version
  36. bool is_win98 = (osVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) &&
  37. (osVersion.dwMajorVersion > 4) || ((osVersion.dwMajorVersion == 4) && (osVersion.dwMinorVersion > 0));
  38. bool is_win2K = (osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) && (osVersion.dwMajorVersion >= 5);
  39. // Use GetCursorInfo if OS version is sufficient
  40. use_getCursorInfo = (is_win98 || is_win2K) && _GetCursorInfo.isValid();
  41. #else
  42. #pragma message ("not building in GetCursorInfo support")
  43. #endif
  44. if (!use_getCursorInfo) {
  45. hooks = new WMCursorHooks();
  46. if (hooks && hooks->start()) {
  47. vlog.info("falling back to cursor hooking");
  48. } else {
  49. delete hooks;
  50. hooks = 0;
  51. vlog.error("unable to monitor cursor shape");
  52. }
  53. } else {
  54. vlog.info("using GetCursorInfo");
  55. }
  56. cursor = (HCURSOR)LoadImage(0, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
  57. }
  58. WMCursor::~WMCursor() {
  59. if (hooks) delete hooks;
  60. if (library) FreeLibrary(library);
  61. }
  62. WMCursor::Info
  63. WMCursor::getCursorInfo() {
  64. Info result;
  65. #if (WINVER >= 0x0500)
  66. if (use_getCursorInfo) {
  67. CURSORINFO info;
  68. info.cbSize = sizeof(CURSORINFO);
  69. if ((*_GetCursorInfo)(&info)) {
  70. result.cursor = info.hCursor;
  71. result.position = Point(info.ptScreenPos.x, info.ptScreenPos.y);
  72. result.visible = info.flags & CURSOR_SHOWING;
  73. return result;
  74. }
  75. }
  76. #endif
  77. // Fall back to the old way of doing things
  78. POINT pos;
  79. if (hooks) cursor = hooks->getCursor();
  80. result.cursor = cursor;
  81. result.visible = cursor != 0;
  82. GetCursorPos(&pos);
  83. result.position.x = pos.x;
  84. result.position.y = pos.y;
  85. return result;
  86. }