Jump to content
  • Advertisement
Sign in to follow this  
Funkymunky

Unity Windows Dialog Background Color

This topic is 1410 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 recently downloaded the Visual Studio 2013 Community Edition after years of using Express editions.  This means I can finally use the built-in resource editor again for things like Icons and Dialog Boxes!

 

Which is awesome, but now I'm trying to do it and I'm struggling to just set the background color of the dialog box.  I created it, I set "Use MFC" to False, and I assigned the same Class Name that I set in my WNDCLASS structure (that I then pass to RegisterClassW).  This has the desired effect of using the icon I wanted for the dialog!  But no matter what I try, I can't get the thing to draw with a default background color.  It's always white.  From everything I've read, I should just have to set "wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1);"

 

But it doesn't work.  Nothing I set in wc.hbrBackground seems to have any effect.  The only thing that does anything is when I override WM_ERASEBKGND and do a FillRect with a brush from GetSysColorBrush, but I don't want to really do all that.  I want to just get the default erase mechanism to paint my window the default gray color of a regular dialog window.

 

What am I missing...?

Share this post


Link to post
Share on other sites
Advertisement

Huh.  Well, it is a dialog, so that explains why hbrBackground doesn't do anything.  On that page for WM_CTLCOLORDLG it says:

 

"By default, the DefWindowProc function selects the default system colors for the dialog box."

 

Which is exactly what I want!  My current DlgProc is like this:

LRESULT CALLBACK WindowClass::DlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
		case WM_INITDIALOG:
			break;

		case WM_CLOSE:
			DestroyWindow(hwnd);
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			break;
	}

	return FALSE;
}

and I create the (unicode) dialog with one of these:

ZeroMemory(&wc, sizeof(wc));
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbWndExtra = DLGWINDOWEXTRA;
wc.hIcon = LoadIconW(hInstance, MAKEINTRESOURCE(IDI_APP));
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
wc.lpfnWndProc = DefDlgProcW;
wc.lpszClassName = L"WindowClassName";
 
if(!RegisterClassW(&wc))
return 0;
 
HWND hWndApp = CreateDialogParamW(NULL, MAKEINTRESOURCE(IDD_APP), NULL, (DLGPROC)MessageRouter, reinterpret_cast<LPARAM>(this));

Share this post


Link to post
Share on other sites
The default system color is usually white. Just because most dialogs you see use the BTNFACE brush doesn't mean it's actually the default ;-) This is a throwback to 16-bit Windows IIRC.

Share this post


Link to post
Share on other sites

Okay, but then how do I get it to draw a "default" gray background?  Handling the WM_ERASEBKGND and WM_CTLCOLORDLG messages doesn't seem to do anything...

Share this post


Link to post
Share on other sites

I don't know about the rest of the code, but the DlgProc in what you posted above seems wrong.

 

http://msdn.microsoft.com/en-us/library/windows/desktop/ms645469(v=vs.85).aspx

 

 

Return value

...

Typically, the dialog box procedure should return TRUE if it processed the message, and FALSE if it did not. If the dialog box procedure returns FALSE, the dialog manager performs the default dialog operation in response to the message.

 

You seem to always return FALSE, which doesn't look good to me.

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!