MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / ControlMove

Method ControlMove

source/script_gui.cpp:1167–1220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1165
1166
1167ResultType GuiType::ControlMove(GuiControlType &aControl, int xpos, int ypos, int width, int height)
1168{
1169 RECT rect;
1170 GetWindowRect(aControl.hwnd, &rect); // Failure seems too rare to check for.
1171 POINT dest_pt = {rect.left, rect.top};
1172 ScreenToClient(GetParent(aControl.hwnd), &dest_pt); // Set default x/y target position, to be possibly overridden below.
1173 if (xpos != COORD_UNSPECIFIED)
1174 dest_pt.x = Scale(xpos);
1175 if (ypos != COORD_UNSPECIFIED)
1176 dest_pt.y = Scale(ypos);
1177
1178 if (!MoveWindow(aControl.hwnd, dest_pt.x, dest_pt.y
1179 , width == COORD_UNSPECIFIED ? rect.right - rect.left : Scale(width)
1180 , height == COORD_UNSPECIFIED ? rect.bottom - rect.top : Scale(height)
1181 , TRUE)) // Do repaint.
1182 return g_script.RuntimeError(_T("Can't move control.")); // Short msg since so rare.
1183
1184 // Note that GUI_CONTROL_UPDOWN has no special handling here. This is because unlike slider buddies,
1185 // whose only purpose is to label the control, an up-down's is also content-linked to it, so the
1186 // inability to move the up-down to separate it from its buddy would be a loss of flexibility. For
1187 // this reason and also to reduce code size, the control is not re-buddied to snap them together.
1188 if (aControl.type == GUI_CONTROL_SLIDER) // It seems buddies don't move automatically, so trigger the move.
1189 {
1190 HWND buddy1 = (HWND)SendMessage(aControl.hwnd, TBM_GETBUDDY, TRUE, 0);
1191 HWND buddy2 = (HWND)SendMessage(aControl.hwnd, TBM_GETBUDDY, FALSE, 0);
1192 if (buddy1)
1193 {
1194 SendMessage(aControl.hwnd, TBM_SETBUDDY, TRUE, (LPARAM)buddy1);
1195 // It doesn't always redraw the buddies correctly, at least on XP, so do it manually:
1196 InvalidateRect(buddy1, NULL, TRUE);
1197 }
1198 if (buddy2)
1199 {
1200 SendMessage(aControl.hwnd, TBM_SETBUDDY, FALSE, (LPARAM)buddy2);
1201 InvalidateRect(buddy2, NULL, TRUE);
1202 }
1203 }
1204 else if (aControl.type == GUI_CONTROL_TAB)
1205 {
1206 // Check for autosizing flags on this Tab control.
1207 int mask = (width == COORD_UNSPECIFIED ? 0 : TAB3_AUTOWIDTH)
1208 | (height == COORD_UNSPECIFIED ? 0 : TAB3_AUTOHEIGHT);
1209 int autosize = (int)(INT_PTR)GetProp(aControl.hwnd, _T("ahk_autosize"));
1210 if (autosize & mask) // There are autosize flags to unset (implies this is a Tab3 control).
1211 {
1212 autosize &= ~mask; // Unset the flags corresponding to dimensions we've just set.
1213 if (autosize)
1214 SetProp(aControl.hwnd, _T("ahk_autosize"), (HANDLE)(INT_PTR)autosize);
1215 else
1216 RemoveProp(aControl.hwnd, _T("ahk_autosize"));
1217 }
1218 }
1219 return OK;
1220}
1221
1222
1223ResultType GuiType::ControlSetFont(GuiControlType &aControl, LPTSTR aOptions, LPTSTR aFontName)

Callers 1

InvokeMethod · 0.80

Calls 1

RuntimeErrorMethod · 0.80

Tested by

no test coverage detected