18 Kasım 2019 Pazartesi

GetWindowLong metodu

Örnek
Şöyle yaparız.
HWND g_hwndTarget;

BOOL CALLBACK  EnumCallback(HWND hwnd, LPARAM lParam)
{
    wchar_t szText[MAX_PATH] = {};
    GetWindowTextW(hwnd, szText, MAX_PATH);

    std::wstring strTitle = szText;
    if (strTitle.find(L"cmd.exe") != std::string::npos)
    {
        g_hwndTarget = hwnd;
        return FALSE;
    }
    return TRUE;
}


int main()
{
  EnumDesktopWindows(NULL, EnumCallback, 0);

  RECT rect = {};
  SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);

  if (g_hwndTarget)
  {
    LONG style = GetWindowLong(g_hwndTarget, GWL_STYLE);
    style &= ~WS_BORDER;
    style &= ~WS_OVERLAPPEDWINDOW;
    SetWindowLong(g_hwndTarget, GWL_STYLE, style);
    SetWindowPos(g_hwndTarget, HWND_BOTTOM, 0, 0, rect.right, rect.bottom, 0);
  }

  return 0;
}

EnumDesktopWindows metodu

Giriş
Callback FALSE dönünce durur.

Örnek
Şöyle yaparız.
HWND g_hwndTarget;

BOOL CALLBACK  EnumCallback(HWND hwnd, LPARAM lParam)
{
  wchar_t szText[MAX_PATH] = {};
  GetWindowTextW(hwnd, szText, MAX_PATH);

  std::wstring strTitle = szText;
  if (strTitle.find(L"cmd.exe") != std::string::npos)
  {
    g_hwndTarget = hwnd;
    return FALSE;
  }
  return TRUE;
}


EnumDesktopWindows(NULL, EnumCallback, 0);

SystemParametersInfo metodu

Örnek
Şöyle yaparız
RECT rect = {};
SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);

GetWindowText metodu

Giriş
Şu satırı dahil ederiz.
#include <windows.h>
Örnek
Şöyle yaparız.
QString getActiveWndTitle()
{
  char buff[256];
  HWND hwnd = GetForegroundWindow();
  GetWindowText(hwnd, (LPWSTR) buff, 254);
  QString title = QString::fromWCharArray((const wchar_t *)buff);
  return title;
}
Örnek
Şöyle yaparız
HWND hwnd = ...
wchar_t szText[MAX_PATH] = {};
GetWindowTextW(hwnd, szText, MAX_PATH);