Jump to content
  • Advertisement
Sign in to follow this  
Kija

Windowed, always on top?

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I have a boolean variable called APP_FULLSCREEN that defines wheter the app should start in windowed or fullscreen mode (same resolution). This works just like it should. I can start in either windowed or fullscreen by changing that variable and both modes works just as intended. Alt tabbing works etc etc. However, when I switch _from_ fullscreen to windowed I get a funny problem. The window is always on top. I can alt tab from it to get focus on another window but the window is still there. The only thing I do when I switch is to change the presentParameters, free resources, reset and reload resources. I only allow resizing in windowed mode, not in fullscreen since it should never change size. The really strange thing is that the windowed mode works great if I start in window mode, if I change from fullscreen to windowed, then it's always on top. Maybe I need to change something more than the presentParameters? My presentParameters:
	if (APP_FULLSCREEN)
	{
		d3dpp.Windowed = FALSE;
		d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
	}
	else
	{
		d3dpp.Windowed = TRUE;
		d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
	}
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.EnableAutoDepthStencil = TRUE;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
	d3dpp.BackBufferCount = 1;
	d3dpp.BackBufferWidth = APP_WIDTH;
	d3dpp.BackBufferHeight = APP_HEIGHT;
	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
	d3dpp.Flags = 0;
	d3dpp.hDeviceWindow = hWnd;
	d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
	d3dpp.MultiSampleQuality = 0;

Share this post


Link to post
Share on other sites
Advertisement
What is the code you are using to create the window. It is probably not a problem with your presentation parameters, but whatever you passed to create window. Here is how I toggle between fullscreen and windowed.


bool PXWindow::ToggleFullscreen(void)
{
if(Windowed())
{
if(::SetWindowLongPtrA(m_hWnd,GWL_STYLE,
m_FullscreenStyle))
{
m_type = PXWNDTYPE_FULLSCREEN;
m_curWidth = ::GetSystemMetrics(SM_CXSCREEN);
m_curHeight = ::GetSystemMetrics(SM_CYSCREEN);

// going fullscreen, so make it topmost
if(!::SetWindowPos(m_hWnd,HWND_TOPMOST,0,0,
m_curWidth,m_curHeight,SWP_FRAMECHANGED))
{
PXApplication::DebugLog("PXWindow::ToggleFullscreen(): Failed changing to fullscreen window");
return false;
}
PXApplication::DebugLog("PXWindow::ToggleFullscreen(): Changed to fullscreen window");
return true;
}
}
else
{
if(::SetWindowLongPtrA(m_hWnd,GWL_STYLE,m_WindowedStyle))
{
m_type = PXWNDTYPE_WINDOWED;
m_curWidth = m_WindowedWidth;
m_curHeight = m_WindowedHeight;

// going windowed, don't make topmost
if(!::SetWindowPos(m_hWnd,HWND_NOTOPMOST,0,0,
m_curWidth,m_curHeight,
SWP_NOMOVE | // ignore parameters
SWP_FRAMECHANGED))
{
PXApplication::DebugLog("PXWindow::ToggleFullscreen(): Failed changing to windowed window");
return false;
}
PXApplication::DebugLog("PXWindow::ToggleFullscreen(): Changed to windowed window");
return true;
}
}
return false;
}



And of course I change the present parameters to reflect the change as well.

Share this post


Link to post
Share on other sites
Thanks for the replies, but I don't think the problem is the CreateWindow call since the application works perfectly when I start with the APP_FULLSCREEN boolean set to false. With other words, when I start in windowed mode, everything is fine. Then if I change to fullscreen and then back to windowed, then it's always on top. Otherwise its working just as intended. Same thing if I start in fullscreen and change to windowed, then it's always on top.

So to summarize: If started in windowed, it works perfectly. Fullscreen always works perfectly. When I change _to_ windowed from fullscreen within the application the window is always on top.

Here's my CreateWindow call though:

hWnd = CreateWindow("Testing", "Testing", WS_OVERLAPPEDWINDOW, 0, 0, 1280, 1024, GetDesktopWindow(), NULL, windowClass.hInstance, NULL);

Share this post


Link to post
Share on other sites
I'm not certain what's causing your problem. You want to examine the window using spyxx to make certain it's not set to be topmost. You can clear the topmost status be using SetWindowPost() if I remember correctly.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
While it took a while for me to realise that you mistyped SetWindowPos to SetWindowPost :) I searched the net and found almost nothing. As soon as I realised the typo it was a snap and the problem is solved. Now I do this call:

SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 1024, 768, 0);

everytime I change into windowed mode from fullscreen. And it works perfectly, it's just one thing that keeps buggering me. I can't understand why I need this when others don't need it. But this solution will work, no performance loss or so. Just a bit irritating not to understand the problem :)

Thanks for the help btw :)

Share this post


Link to post
Share on other sites
When you use Direct3D in fullscreen, it automatically makes the window topmost so that windows from other applications cannot interfere with it. When you switch back to windowed mode, you have to undo the change manually.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!