Pick an application by dragging onto its highlighted window
This commit is contained in:
1 parent
5d96abb83e
commit
a0e1de40ef
3 files changed
+181
-16
No files matched your search
@@ -279,6 +279,35 @@ int main()
|
||||
require(SendDlgItemMessageW(dialog, 722, LB_GETSELCOUNT, 0, 0) == 1, "legacy languages displayed");
|
||||
SendDlgItemMessageW(dialog, 722, LB_SETSEL, TRUE, -1);
|
||||
SendMessageW(dialog, WM_COMMAND, MAKEWPARAM(722, LBN_SELCHANGE), 0);
|
||||
HWND picker = GetDlgItem(dialog, 728);
|
||||
RECT dialogBounds{};
|
||||
GetWindowRect(dialog, &dialogBounds);
|
||||
HWND target = CreateWindowExW(WS_EX_TOPMOST | WS_EX_NOACTIVATE, L"EDIT", L"Picker fixture",
|
||||
WS_POPUP | WS_VISIBLE, dialogBounds.left + 32, dialogBounds.top + 100, 120, 48,
|
||||
nullptr, nullptr, GetModuleHandleW(nullptr), nullptr);
|
||||
require(picker && target, "window picker and target available");
|
||||
POINT drop{dialogBounds.left + 33, dialogBounds.top + 101};
|
||||
require(GetAncestor(WindowFromPoint(drop), GA_ROOT) == target, "fixture window is under the drop point");
|
||||
ScreenToClient(picker, &drop);
|
||||
SendMessageW(picker, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(8, 8));
|
||||
require(GetCapture() == picker, "window picker captures drag");
|
||||
SendMessageW(picker, WM_MOUSEMOVE, MK_LBUTTON, MAKELPARAM(drop.x, drop.y));
|
||||
HWND outline = findTestWindow(L"KSwitcher.AppPickerOutline", nullptr);
|
||||
RECT outlineBounds{}, targetBounds{};
|
||||
require(IsWindowVisible(outline) && GetWindowRect(outline, &outlineBounds) &&
|
||||
GetWindowRect(target, &targetBounds) && EqualRect(&outlineBounds, &targetBounds), "drag highlights the target window");
|
||||
SendMessageW(picker, WM_KEYDOWN, VK_ESCAPE, 0);
|
||||
require(!IsWindow(outline) && GetCapture() != picker, "Escape clears the outline and releases capture");
|
||||
SendMessageW(picker, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(8, 8));
|
||||
SendMessageW(picker, WM_MOUSEMOVE, MK_LBUTTON, MAKELPARAM(drop.x, drop.y));
|
||||
outline = findTestWindow(L"KSwitcher.AppPickerOutline", nullptr);
|
||||
SendMessageW(picker, WM_LBUTTONUP, 0, MAKELPARAM(drop.x, drop.y));
|
||||
require(!IsWindow(outline), "dropping clears the outline");
|
||||
auto pickedApp = ks::applicationName(ks::processName(target));
|
||||
DestroyWindow(target);
|
||||
auto pickedRow = SendDlgItemMessageW(dialog, 720, LB_FINDSTRINGEXACT, -1, (LPARAM)pickedApp.c_str());
|
||||
require(GetCapture() != picker && pickedRow >= 0 &&
|
||||
SendDlgItemMessageW(dialog, 720, LB_GETCURSEL, 0, 0) == pickedRow, "dropping on a window selects its executable");
|
||||
selectApp(L"notepad");
|
||||
require(SendDlgItemMessageW(dialog, 722, LB_GETSELCOUNT, 0, 0) == 1, "editing one app leaves formerly shared app unchanged");
|
||||
selectApp(L"codex");
|
||||
|
||||
Reference in new issue
Block a user