NativeEventFilter.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "NativeEventFilter.h"
  2. #include "FluTheme.h"
  3. #include "FluApp.h"
  4. #ifdef Q_OS_WIN
  5. #pragma comment(lib, "Dwmapi.lib")
  6. #pragma comment(lib, "User32.lib")
  7. #include <Windows.h>
  8. #include <windowsx.h>
  9. #endif
  10. bool NativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result)
  11. {
  12. #ifdef Q_OS_WIN
  13. if (eventType == "windows_generic_MSG" && FluApp::fluTheme->frameless()) {
  14. MSG* msg = static_cast<MSG *>(message);
  15. if (msg == Q_NULLPTR)
  16. return false;
  17. if(!FluApp::fluApp->wnds.contains((WId)msg->hwnd)){
  18. return false;
  19. }
  20. switch(msg->message) {
  21. case WM_NCCALCSIZE:{
  22. NCCALCSIZE_PARAMS& params = *reinterpret_cast<NCCALCSIZE_PARAMS*>(msg->lParam);
  23. if (params.rgrc[0].top != 0)
  24. params.rgrc[0].top -= 1;
  25. *result = WVR_REDRAW;
  26. return true;
  27. }
  28. case WM_NCHITTEST: {
  29. auto view = FluApp::fluApp->wnds[(WId)msg->hwnd];
  30. bool isResize = !(view->maximumWidth()==view->minimumWidth()&&view->maximumHeight()==view->minimumHeight());
  31. const LONG borderWidth = 8;
  32. RECT winrect;
  33. GetWindowRect(msg->hwnd, &winrect);
  34. long x = GET_X_LPARAM(msg->lParam);
  35. long y = GET_Y_LPARAM(msg->lParam);
  36. if (x >= winrect.left && x < winrect.left + borderWidth &&
  37. y < winrect.bottom && y >= winrect.bottom - borderWidth && isResize) {
  38. *result = HTBOTTOMLEFT;
  39. return true;
  40. }
  41. if (x < winrect.right && x >= winrect.right - borderWidth &&
  42. y < winrect.bottom && y >= winrect.bottom - borderWidth && isResize) {
  43. *result = HTBOTTOMRIGHT;
  44. return true;
  45. }
  46. if (x >= winrect.left && x < winrect.left + borderWidth &&
  47. y >= winrect.top && y < winrect.top + borderWidth && isResize) {
  48. *result = HTTOPLEFT;
  49. return true;
  50. }
  51. if (x < winrect.right && x >= winrect.right - borderWidth &&
  52. y >= winrect.top && y < winrect.top + borderWidth && isResize) {
  53. *result = HTTOPRIGHT;
  54. return true;
  55. }
  56. if (x >= winrect.left && x < winrect.left + borderWidth && isResize) {
  57. *result = HTLEFT;
  58. return true;
  59. }
  60. if (x < winrect.right && x >= winrect.right - borderWidth && isResize) {
  61. *result = HTRIGHT;
  62. return true;
  63. }
  64. if (y < winrect.bottom && y >= winrect.bottom - borderWidth && isResize) {
  65. *result = HTBOTTOM;
  66. return true;
  67. }
  68. if (y >= winrect.top && y < winrect.top + borderWidth && isResize) {
  69. *result = HTTOP;
  70. return true;
  71. }
  72. return false;
  73. }
  74. default:
  75. break;
  76. }
  77. }
  78. #endif
  79. return false;
  80. }