Sign in to follow this  
Trillian

[win32] GetDisplaySettings?

Recommended Posts

Trillian    410
Hello! I'm currently making a game engine and I need to attach a direct3d renderingdevice to a window. For the moment, I'm only calling ::GetActiveWindow() and attaching the device to this window handle. However, I want to support fullscreen, but I still want to use my ::GetActiveWindow() thing (for the moment). So I need to know if there's a win32 function that would detect if a window has toggled to fullscreen using ::ChangeDisplaySetting() (something like ::GetDisplaySetting()) and return the DEVMODE structure used in the operation so I can set my direct3d options using it. In a few words : How can I get the DEVMODE structure associated to an HWND?

Share this post


Link to post
Share on other sites
Trillian    410
Ok, I think I found it :
::EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devmode);

But now that I have the current display setting, how can I be sure it applies to the active window (::GetActiveWindow()) ? And how can I know if it is fullscreen or not?

Share this post


Link to post
Share on other sites
Endurion    5408
ChangeDisplaySettings is associated with the whole system, not a specific window.

Therefor you won't be able to retrieve information if a certain HWND is inside a process who did call ChangeDisplaySettings.

In a few words: You can't.

Share this post


Link to post
Share on other sites
Trillian    410
Ok... I thought that may happen.

If I can get to know a window is in "fullscreen" mode, then I can get the fullscreen parameters using EnumDisplaySettings, is that right? So I only need to know if my window is "fullscreen".

Would it be possible to do this by checking it's window style using GetWindowLong ? There must be a way to do determine if the window takes the whole screen?

Share this post


Link to post
Share on other sites
Evil Steve    2017
Isn't a fullscreen window is just a window with the WS_POPUP style taking up the full screen, with HWND_TOPMOST as its position in the Z order?

Why do you need to do this? The best way I can think of is using WindowFromPoint() and then using GetWindowRect() to determine if the window covers the whole screen. And you'll probably want to check it's position in the Z order or something too

Share this post


Link to post
Share on other sites
Endurion    5408
You could do that by calling GetWindowRect and comparing the result with the window rect of the desktop (use GetDesktopWindow).

Also, usually the window that is really fullscreen ought to be the focused window (use GetForegroundWindow).

Share this post


Link to post
Share on other sites
Trillian    410
What about this :


D3DPRESENT_PARAMETERS pp;
ZeroMemory(&pp, sizeof(pp));
pp.Windowed = TRUE;
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
pp.BackBufferCount = 1;
pp.hDeviceWindow = GetForegroundWindow();

// Make a quick style check for fullscreen (kind of early out)
LONG_PTR windowstyle = ::GetWindowLongPtrA(pp.hDeviceWindow, GWL_STYLE);
if((windowstyle & WS_POPUP) != 0 && (windowstyle & WS_CAPTION) == 0) // No caption COULD mean fullscreen
{
// Get the display mode and the window rect
DEVMODE dm;
RECT rect;
if(::EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm) == TRUE && GetWindowRect(pp.hDeviceWindow, &rect) == TRUE)
{
// If the window takes all the screen
if(rect.top == 0 && rect.left == 0 && rect.right == dm.dmPelsWidth && rect.bottom == dm.dmPelsHeight)
{
pp.Windowed = FALSE;
pp.BackBufferWidth = dm.dmPelsWidth;
pp.BackBufferHeight = dm.dmPelsHeight;
pp.BackBufferFormat = D3DFMT_X8R8G8B8;
pp.FullScreen_RefreshRateInHz = dm.dmDisplayFrequency == 1 ? 0 : dm.dmDisplayFrequency;
}
}
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this