Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,971 questions

51,913 answers

573 users

How to detect the current screen resolution in C++ Win32 API

1 Answer

0 votes
#include <Windows.h> 
#include <sstream>

bool GetScreenResolution(unsigned int* pwidth, unsigned int* pheigth) {
    const HWND desktopWindow = GetDesktopWindow();

    RECT desktopRectangle;

    if (desktopWindow && GetWindowRect(desktopWindow, &desktopRectangle)) {
        *pwidth = desktopRectangle.right;
        *pheigth = desktopRectangle.bottom;

        return true;
    }

    return false;
}


int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    unsigned int width = 0, heigth = 0;
    std::string s;

    if (GetScreenResolution(&width, &heigth)) {

        std::ostringstream oss;
        
        oss << width;
        oss << " x ";
        oss << heigth;
        oss << " pixels";

        s = oss.str();
    }

    MessageBoxA(0, s.c_str(), "info", MB_OK);
    
}


/*
run:

2560 x 1440 pixels

*/

 



answered Dec 6, 2024 by avibootz
...