Advertisement
Tarferi

For SI - Recalculating wnd

Jul 16th, 2019
1,744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #define SIZES_DATA_SIZE 8
  3. struct SIZES_DATA {
  4.     HWND wnd;
  5.     RECT wndBase;
  6.     RECT bases[SIZES_DATA_SIZE];
  7.     RECT defaults[SIZES_DATA_SIZE];
  8.     HWND handles[SIZES_DATA_SIZE];
  9.     bool moveL[SIZES_DATA_SIZE];
  10.     bool moveR[SIZES_DATA_SIZE];
  11.     bool moveT[SIZES_DATA_SIZE];
  12.     bool moveB[SIZES_DATA_SIZE];
  13. };
  14.  
  15. SIZES_DATA pos_data = { 0 };
  16.  
  17. #define COLLECT_MAIN {\
  18.     GetWindowRect(pos_data.wnd, &(pos_data.wndBase));\
  19.     COLLECT_HANDLE(0, IDC_GROUPLIST, false, true, false, false);\
  20.     COLLECT_HANDLE(1, IDC_MAPLIST, false, true, false, true);\
  21.     COLLECT_HANDLE(2, IDC_STATIC, false, true, false, false);\
  22.     COLLECT_HANDLE(3, IDC_STATIC2, false, true, false, true);\
  23.     COLLECT_HANDLE(4, IDC_RESTOREFILE, false, false, true, true);\
  24.     COLLECT_HANDLE(5, IDC_DELETEMAP, true, true, true, true);\
  25.     COLLECT_HANDLE(6, IDC_DELETEGROUP, true, true, false, false);\
  26.     COLLECT_HANDLE(7, IDC_CLEARALL, false, false, false, false);\
  27. }
  28.  
  29. #define COLLECT_HANDLE(index, item, _moveL, _moveR, _moveT, _moveB) {\
  30.     pos_data.moveL[index] = _moveL;\
  31.     pos_data.moveR[index] = _moveR;\
  32.     pos_data.moveT[index] = _moveT;\
  33.     pos_data.moveB[index] = _moveB;\
  34.     pos_data.handles[index] = GetDlgItem(pos_data.wnd, item);\
  35.     GetWindowRect(pos_data.handles[index], &(pos_data.defaults[index]));\
  36.     GetWindowRect(GetParent(pos_data.handles[index]), &(pos_data.bases[index]));\
  37.     pos_data.defaults[index].left -= (pos_data.bases[index].right - pos_data.bases[index].left);\
  38.     pos_data.defaults[index].right -= pos_data.bases[index].right;\
  39.     pos_data.defaults[index].top -= (pos_data.bases[index].bottom - pos_data.bases[index].top);\
  40.     pos_data.defaults[index].bottom -= pos_data.bases[index].bottom;\
  41. }
  42.  
  43. #define MOVE_ALL \
  44.     if (pos_data.wnd == 0) {\
  45.         pos_data.wnd = hDlg;\
  46.         COLLECT_MAIN\
  47.     }\
  48.     MOVE(0);\
  49.     MOVE(1);\
  50.     MOVE(2);\
  51.     MOVE(3);\
  52.     MOVE(4);\
  53.     MOVE(5);\
  54.     MOVE(6);\
  55.     MOVE(7);\
  56.  
  57. #define MOVE(index) {\
  58. RECT currentBase;\
  59. RECT currentWndBase;\
  60. GetWindowRect(pos_data.wnd, &currentWndBase);\
  61. GetWindowRect(GetParent(pos_data.handles[index]), &currentBase);\
  62. RECT rect;\
  63. int diffX =  currentWndBase.left - pos_data.wndBase.left;\
  64. int diffY =  currentWndBase.top - pos_data.wndBase.top;\
  65. rect.left = pos_data.defaults[index].left + (pos_data.moveL[index] ?  (currentBase.right - currentBase.left) + diffX: (pos_data.bases[index].right - pos_data.bases[index].left) + diffX);\
  66. rect.right = pos_data.defaults[index].right + (pos_data.moveR[index] ? currentBase.right : pos_data.bases[index].right + diffX);\
  67. rect.top = pos_data.defaults[index].top + (pos_data.moveT[index] ?  (currentBase.bottom - currentBase.top) + diffY :  (pos_data.bases[index].bottom - pos_data.bases[index].top) + diffY);\
  68. rect.bottom = pos_data.defaults[index].bottom + (pos_data.moveB[index] ? currentBase.bottom : pos_data.bases[index].bottom + diffY);\
  69. POINT p;\
  70. p.x = rect.left;p.y = rect.top;ScreenToClient(GetParent(pos_data.handles[index]), &p);rect.left = p.x;rect.top = p.y;\
  71. p.x = rect.right;p.y = rect.bottom;ScreenToClient(GetParent(pos_data.handles[index]), &p);rect.right = p.x;rect.bottom = p.y;\
  72. MoveWindow(pos_data.handles[index], rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, true);\
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement