Code archives/Graphics/Mimic Desktop Resolution (Requires "user32.dll")

This code has been declared by its author to be Public Domain code.

Download source code

Mimic Desktop Resolution (Requires "user32.dll") by _PJ_2009
This short function makes use of the GetSystemMetrics functionality of User32.dll

Unless you have a more comprehensive decls file, I have included just the relevant part.

All it does is simply grab the Desktop Resolution (No Bits per Pixel Depth yet, unfortunately - so the BitDepth is kept as a parameter) and sets the Graphics Mode to the same size.
.lib "user32.dll"
GetSystemMetrics% (nIndex%) : "GetSystemMetrics"

_________________________________________________________

Function SetResolution3D(nBit_Depth=32,nWindow_Mode=0)
Graphics3D GetSystemMetrics(16),GetSystemMetrics(1),nBit_Depth,nWindow_Mode
End Function

Function SetResolution(nBit_Depth=32,nWindow_Mode=0)
Graphics GetSystemMetrics(16),GetSystemMetrics(1),nBit_Depth,nWindow_Mode
End Function

Comments

Serpent2010
You might want to consider using GetSystemMetrics(0) instead of GetSystemMetrics(16) for the x-value.

There is a difference. The value 0 in this case is the windows constant 'SM_CXSCREEN'. The value 1 is 'SM_CYSCREEN'. The value 16 'SM_CXFULLSCREEN'.

It is better to use SM_CXSCREEN than SM_CXFULLSCREEN. On the GetSystemMetrics MSDN Page all of the differenct constants are described.
SM_CXSCREEN is "The width of the screen of the primary display monitor, in pixels."
SM_CXFULLSCREEN is "The width of the client area for a full-screen window on the primary display monitor, in pixels."
By fullscreen I think it means maximised.

Try comparing the values of GetSystemMetrics(0) and GetSystemMetrics(16) after moving your taskbar to the side of your screen. SM_CXSCREEN still returns the actual width of the monitor/display. SM_CXFULLSCREEN returns a smaller value because the x size of a maximised window has been decreased.

Although it depends slightly on what you want to do, SM_CXSCREEN is usually a better choice (in the small chance that someone actually has their taskbar on the side of their screen).


_PJ_2010
Yeah thanks for mentioning that here, Serpent.
I only used (16) since I pretty much kludged the function together after testing a bunch of values and seeing which ones worked. Someone later told me about the SystemMetrics(0) but I never updated this, good call in putting a note here.

Thanks for that link. That really helps too, I was actually wondering how to get the bit depth!


Streaksy2010
Very useful =D


Code Archives Forum