Created
July 18, 2016 04:52
-
-
Save turanegaku/fdb71894c9b2d35bbeee760e96d349ba to your computer and use it in GitHub Desktop.
foreground window script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<queue> | |
#include<cstdio> | |
#include<windows.h> | |
using namespace std; | |
HWND findWindow(const char* name) { | |
queue<HWND> que; | |
que.push(GetDesktopWindow()); | |
while(!que.empty()) { | |
HWND p = que.front(); que.pop(); | |
int l = GetWindowTextLength(p); | |
char title[l]; | |
GetWindowTextA(p, title, l); | |
if (strstr(title, name) ) { | |
return p; | |
} | |
for(HWND child = FindWindowEx(p, NULL, NULL, NULL); child != NULL; | |
child = FindWindowEx(p, child, NULL, NULL)){ | |
que.push(child); | |
} | |
} | |
return NULL; | |
} | |
int main(int argv, char **args) { | |
if (argv < 2) { | |
printf("Usage: %s [name]\n", args[0]); | |
return 2; | |
} | |
HWND id = findWindow(args[1]); | |
if (id == NULL) | |
return 3; | |
return !SetForegroundWindow(id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment