Jump to content
  • Advertisement
Sign in to follow this  
Smit

Toggle Window Styles

This topic is 4440 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

I'm using this code to toggle the window style when the window it made fullscreen/windowed:
bool CRenderWindow::ToggleFullscreen( bool bFlag )
{
	long lStyle;
	long lExStyle;

	GetWindowLongPtrA( this->m_hWnd, GWL_STYLE );
	GetWindowLongPtrA( this->m_hWnd, GWL_EXSTYLE );

	if( bFlag == true )
	{
		// Add.
		lStyle |= WS_POPUP;

		// Remove.
		lStyle &= ~WS_OVERLAPPEDWINDOW;
		lExStyle &= ~WS_EX_WINDOWEDGE;
	}
	else
	{
		// Add.
		lStyle |= WS_OVERLAPPEDWINDOW;
		lExStyle |= WS_EX_WINDOWEDGE;

		// Remove.
		lStyle &= ~WS_POPUP;
	}

	SetWindowPos( this->m_hWnd, HWND_TOP, 0, 0, this->m_nWidth, this->m_nHeight, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED );		

	return false;
}

When in windowed mode it should use: WS_EX_APPWINDOW WS_EX_WINDOWEDGE WS_OVERLAPPEDWINDOW When in fullscreen mode it should use: WS_APPWINDOW WS_POPUP However nothing seems to change when calling, am I doing something wrong with changing the styles? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
You are not retreiving the LONG_PTR values from GetWindowLongPtrA() in your code. Do not enforce the use of ANSI-functions explicitly in your code; use GetWindowLongPtr() instead and let the preprocessor flags determine if the code should be compiled for ANSI or unicode.

long *lstyle;
long *lExstyle;

lstyle = GetWindowLongPtr( this->m_hWnd, GWL_style );
lExstyle = GetWindowLongPtr( this->m_hWnd, GWL_EXstyle );

...

Remember that lstyle and lExstyle are pointers in this code. If this doesn't work try to explicitly set the new updated styles with two calls to SetWindowLongPtr() before redrawing the window.

Share this post


Link to post
Share on other sites
Thanks the reply, I completly forgot to call SetWindowLongPtr() to set them back. Now I have a different problem though, after setting the window to the fullscreen style (no border etc.) it keeps the border but then doesn't react to events anymore. Moving the mouse over the window actually draws whatever is underneath (like toolbar button heighlights) until the window disappears.

I think its something to do with the flags I am setting. I'm not sure which though.

Share this post


Link to post
Share on other sites
GetWindowLongPtr does not get the styles inside a pointer. It merely reflects the modification of the LONG typedef to LONG_PTR which implies that a pointer can be stored inside. This has been added in the latter platform SDKs for Win64 compatibility. You have to use SetWindowLong(Ptr) to set your styles again, modifying the pointees doesn't do anything:

LONG_PTR dwstyle = GetWindowLongPtr( hWnd, GWL_style );
LONG_PTR dwExstyle = GetWindowLongPtr( hWnd, GWL_EXstyle );

// Modify styles

SetWindowLongPtr( hWnd, GWL_style, dwstyle );
SetWindowLongPtr( hWnd, GWL_style, dwExstyle );

// call SetWindowPos with SWP_FRAMECHANGED set


The LONG_PTR typedef has been added to make it clearer for programmers that the variable is big enough to store a pointer inside (important for the userdata).

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!