I'm attempting to use the following to get the height & width of the main display:
#include <winuser.h>
size_t width = (size_t)GetSystemMetrics(SM_CXBORDER);
size_t height = (size_t)GetSystemMetrics(SM_CYBORDER);
However, it's failing on an unresolved externals link error (LNK1120
). I've tried linking to user32.lib (as documented here), and received the same error, as well as linking to wmbase.lib (as documented here), and received the error that wmbase.lib does not exist! What am I doing wrong?
Note that I am only using plain-ol' C — not C++. Is this the right function to use to get the screen resolution (in pixels) of the main display?
I am attempting to compile this on MSVC at the moment, but would prefer a solution portable to other compilers.
Thanks.
Edit
So it looks like the parameters I was looking for were SM_CXSCREEN
and SM_CYSCREEN
, not SM_CXBORDER
and SM_CYBORDER
. However, I still can't manage to get this to compile.
Here is the actual error if that clarifies anything (when linked to user32.lib):
screen.obj : error LNK2019: unresolved external symbol __imp__GetSystemMetrics@4 referenced in function _getMainDisplaySize
build\lib.win32-2.6\foomodule\bitmap.pyd : fatal error LNK1120: 1 unresolved externals
error: command '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.exe"' failed with exit status 1120
(I am attempting to compile a Python/C module so that's why you see the weird directories)