Skip to content

Instantly share code, notes, and snippets.

@lyf-is-coding
Created January 23, 2022 15:07
Show Gist options
  • Save lyf-is-coding/e51efb4faddf67bbad8534734bb0fcf1 to your computer and use it in GitHub Desktop.
Save lyf-is-coding/e51efb4faddf67bbad8534734bb0fcf1 to your computer and use it in GitHub Desktop.
C++ Getting window width and height using GetClientRect
// Below is an example of getting Assault Cube game window width and height
#include <Windows.h>
// ClassName and WindowName of FindWindow() are generated by X-Spy tool: http://www.x-spy.net/
hwndAC = FindWindow(L"SDL_app", L"AssaultCube");
if (hwndAC) // >0 is a valid HWND
{
RECT rctAC;
if (GetClientRect(hwndAC, &rctAC))
{
// rctAC will receives the client coordinates. The left and top members are zero.
// The right and bottom members contain the width and height of the window.
std::cout << std::dec << "Width " << rctAC.right << ", Height " << rctAC.bottom << '\n';
}
else
{
std::cout << "<GetClientRect> Error " << GetLastError() << '\n';
}
}
else
{
std::cout << "<FindWindow> Error " << GetLastError() << '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment