Created
January 23, 2022 15:07
-
-
Save lyf-is-coding/e51efb4faddf67bbad8534734bb0fcf1 to your computer and use it in GitHub Desktop.
C++ Getting window width and height using GetClientRect
This file contains hidden or 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
// 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