Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <iostream>
- void SetVisible(HWND WindowHWND, bool WindowVisible) {
- int WindowState = 0;
- if (WindowVisible == true) {
- WindowState = SW_SHOW;
- }
- else {
- WindowState = SW_HIDE;
- }
- ShowWindowAsync(WindowHWND, WindowState);
- }
- bool CheckArg(const char* ArgumentName, int CurrentIndex, int Expected, int TotalArguments, char** Arguments) {
- return (_strcmpi(Arguments[CurrentIndex], ArgumentName) == 0 && ((CurrentIndex + Expected) < TotalArguments));
- }
- int main(int argc, char** argv)
- {
- char* ClassName = nullptr;
- char* Caption = nullptr;
- int KeyCode = 0;
- if (argc == 1) {
- std::cout << "No arguments specified!\r\n\r\n";
- std::cout << "/classname ""Window Classname""\r\n";
- std::cout << "/caption ""Window Caption""\r\n";
- std::cout << "/simulatekey 0xKeyCode - ie ESC=0x1B\r\n";
- return 1;
- }
- else {
- for (int i = 1; i < argc; i++) {
- if (CheckArg("/classname", i, 1, argc, argv)) {
- ClassName = argv[++i];
- continue;
- } else if (CheckArg("/caption", i, 1, argc, argv)) {
- Caption = argv[++i];
- continue;
- }
- else if (CheckArg("/simulatekey", i, 1, argc, argv)) {
- KeyCode = strtol(argv[++i], NULL, 16);
- continue;
- }
- }
- }
- HWND TargetHWND = FindWindowA(ClassName, Caption);
- if (TargetHWND != nullptr) {
- printf("Target Window: 0x%p\r\n", TargetHWND);
- SetVisible(TargetHWND, false);
- SetVisible(TargetHWND, true);
- if (KeyCode != 0) {
- //Simulate pressing ESC
- printf("Simulating keypress\r\n");
- SendMessage(TargetHWND, WM_KEYDOWN, KeyCode, 0);
- SendMessage(TargetHWND, WM_KEYUP, KeyCode, 0);
- }
- }
- else {
- printf("Unable to find window - classname: %s, caption: %s", ClassName, Caption);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment