Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <Windows.h>
  2.  
  3. #include <memory>
  4. #include <string>
  5.  
  6. int main()
  7. {
  8.     auto titleToFind = L"Developer tools";
  9.  
  10.     EnumWindows([](HWND hwnd, LPARAM lParam) {
  11.         auto titleToFind = reinterpret_cast<LPTSTR>(lParam);
  12.  
  13.         int size = GetWindowTextLength(hwnd) + 1;
  14.         auto buffer = std::make_unique<wchar_t []>(size);
  15.         GetWindowText(hwnd, buffer.get(), size);
  16.  
  17.         auto title = std::wstring{ buffer.get() };
  18.  
  19.         if (IsWindowVisible(hwnd) && title.find(titleToFind) != std::wstring::npos) {
  20.             SendMessage(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
  21.         }
  22.  
  23.         return TRUE;
  24.     }, reinterpret_cast<LPARAM>(titleToFind));
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement