# Windowed, always on top?

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

## 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.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 on other sites
Did you specify WS_EX_TOPMOST in the CreateWindow() function? If that is the case then just remove it.

##### Share on other sites
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 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 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 on other sites
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 on other sites
I needed it too, so don't worry about it.

##### Share on other sites
Sorry about the typo _and_ the busted link! What I had originally intended was a link to MSDN such as: SetWindowPos()

##### 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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015432
×