Skip to content

Instantly share code, notes, and snippets.

@croepha
Last active May 2, 2017 19:21
Show Gist options
  • Save croepha/97e355963b6ab7d5c26f11fe8bd78f3a to your computer and use it in GitHub Desktop.
Save croepha/97e355963b6ab7d5c26f11fe8bd78f3a to your computer and use it in GitHub Desktop.
Stops the visual studio debugger, useful for putting in your build scripts and avoid the exe file in use issues
#include <stdio.h>
#include <Windows.h>
BOOL EnumWindowsProc_(HWND hwnd, LPARAM lParam ) {
char text_buff[1024] = "";
GetWindowTextA(hwnd, text_buff, sizeof(text_buff));
if (strstr(text_buff, "Microsoft Visual Studio")) {
printf("%p\n", hwnd);
printf("%s\n", text_buff);
auto r1 = SetForegroundWindow( hwnd );
assert(r1);
INPUT i[] = {
{.type = INPUT_KEYBOARD, .ki = {.wVk = VK_SHIFT } },
{.type = INPUT_KEYBOARD, .ki = {.wVk = VK_F5 } },
{.type = INPUT_KEYBOARD, .ki = {.wVk = VK_SHIFT, .dwFlags = KEYEVENTF_KEYUP} },
{.type = INPUT_KEYBOARD, .ki = {.wVk = VK_F5, .dwFlags = KEYEVENTF_KEYUP} },
};
SendInput( COUNT_OF(i), i , sizeof( i[0] ) );
}
return true;
}
int main () {
setvbuf(stdout, (char*)NULL, _IONBF, 0); // force flushing of stdout
auto r2 = EnumWindows(EnumWindowsProc_, NULL);
assert(r2);
// auto app_handle = FindWindowA("HwndWrapper[DefaultDomain;;e6ffaefa-5db7-4618-aee2-2a504f638874]", NULL);
// assert(app_handle != NULL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment