Jump to content
  • Advertisement
Sign in to follow this  
v0dKA

My GUI looks a bit like Win95 - why?

This topic is 4524 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 starting out a new application, and currently I'm designing the graphical user interface (GUI). I've made a decision to avoid the VS dialog editor for a couple reasons: I've had some problems with it recently (I took too much liberty with editing VS's resouce header file, and almost destroyed my resource from working it all), and also, I'm trying to achieve a bit of syntactic clearity by using as few functions and as little implementation-hiding as possible (to some, I imagine this sounds like an oxymoron; but I'm currently trying to understand the mechanics of everything I'm doing, and dividing it up into functions makes that more difficult). Therefore, I chose to create all of my controls dynamically, in line with the rest of the code, instead of using resource files. However, by so doing, I've made my GUI appear a little... old. It doesn't look like WinXP. Here's how it is currently (not all the controls are in place yet): Observe these (undesirable) characteristics: - The style of the button (not rounded or curved at all, does not get highlighted when the mouse rolls over it, etc). - The style of the static text ("Enter a new message:"), the edit control, and the push button (looks way too bold, does not look like the standard WinXP font at all). I went ahead and created the same window using the resource editor. Here's how it looks (I added all the elements I want in the final version, but pay attention only to the control styles): So now you have the comparison. Here's the source code that I use to create my controls:
// Create and display the main window

	WNDCLASSEX wc;
	wc.cbSize = sizeof( WNDCLASSEX );
	wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wc.lpfnWndProc = WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon =  LoadIcon( NULL, IDI_APPLICATION );
	wc.hCursor = (HCURSOR)LoadCursor( NULL, IDC_ARROW );
	wc.hbrBackground = CreateSolidBrush( RGB( 236, 233, 216 ) );
	wc.lpszMenuName = NULL;
	wc.lpszClassName = "NetworkClient";
	wc.hIconSm = NULL;
	RegisterClassEx( &wc );

	g_hWnd = CreateWindowEx(
		NULL,
		"NetworkClient",
		"Network Client",
		WS_OVERLAPPEDWINDOW,
		100,
		100,
		800,
		700,
		GetDesktopWindow(),
		NULL,
		g_hInstance,
		NULL );

	ShowWindow( g_hWnd, SW_SHOWDEFAULT );
	UpdateWindow( g_hWnd );

	// Create and display the child windows

	// Text box for message entry	
	messageEntryWindow = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", "",
		WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
		50, 50, 600, 75, g_hWnd, (HMENU)IDC_MESSAGE_ENTRY, g_hInstance, NULL );
	ShowWindow( messageEntryWindow, SW_SHOWDEFAULT );
	UpdateWindow( messageEntryWindow );

	// Button to send the message
	sendMessageWindow = CreateWindowEx( WS_EX_WINDOWEDGE, "BUTTON", "Send", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON ,
		675, 50, 100, 75, g_hWnd, (HMENU)IDC_SEND_MESSAGE, g_hInstance, NULL ); 
	ShowWindow( sendMessageWindow, SW_SHOWDEFAULT );
	UpdateWindow( sendMessageWindow );

	// Box to display all outgoing messages to server
	outgoingMessages = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE
		| WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY,
		50, 150, 600, 200, g_hWnd, (HMENU)IDC_OUT, g_hInstance, NULL );
	ShowWindow( outgoingMessages, SW_SHOWDEFAULT );
	UpdateWindow( outgoingMessages );

	// Box to display all ingoing messages from server
	ingoingMessages = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE
		| WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY,
		50, 375, 600, 200, g_hWnd, (HMENU)IDC_IN, g_hInstance, NULL );
	ShowWindow( ingoingMessages, SW_SHOWDEFAULT );
	UpdateWindow( ingoingMessages );

	// A label for the message entry window
	staticMessageEntryWindowLabel = CreateWindowA( "STATIC", "Enter a new message:",
		WS_CHILD | WS_VISIBLE, 50, 30, 200, 20, g_hWnd, (HMENU)IDC_STATIC_MESSAGE_ENTRY,
		g_hInstance, NULL );
	ShowWindow( staticMessageEntryWindowLabel, SW_SHOWNORMAL );
	UpdateWindow( staticMessageEntryWindowLabel );


If you want to take my program and play around with it, here's the complete source in one file: complete source (.cpp) I suspect that the reason my GUI looks the way it does is because of the window styles I pass to CreateWindow() and CreateWindowEx(). So here's a quick reference of all the styles available. I'm not sure which to use to fix my problems, but perhaps someone here will know. Window styles (normal and extended):
/*
 * Window Styles
 */
#define WS_OVERLAPPED       0x00000000L
#define WS_POPUP            0x80000000L
#define WS_CHILD            0x40000000L
#define WS_MINIMIZE         0x20000000L
#define WS_VISIBLE          0x10000000L
#define WS_DISABLED         0x08000000L
#define WS_CLIPSIBLINGS     0x04000000L
#define WS_CLIPCHILDREN     0x02000000L
#define WS_MAXIMIZE         0x01000000L
#define WS_CAPTION          0x00C00000L     /* WS_BORDER | WS_DLGFRAME  */
#define WS_BORDER           0x00800000L
#define WS_DLGFRAME         0x00400000L
#define WS_VSCROLL          0x00200000L
#define WS_HSCROLL          0x00100000L
#define WS_SYSMENU          0x00080000L
#define WS_THICKFRAME       0x00040000L
#define WS_GROUP            0x00020000L
#define WS_TABSTOP          0x00010000L

#define WS_MINIMIZEBOX      0x00020000L
#define WS_MAXIMIZEBOX      0x00010000L


#define WS_TILED            WS_OVERLAPPED
#define WS_ICONIC           WS_MINIMIZE
#define WS_SIZEBOX          WS_THICKFRAME
#define WS_TILEDWINDOW      WS_OVERLAPPEDWINDOW

/*
 * Common Window Styles
 */
#define WS_OVERLAPPEDWINDOW (WS_OVERLAPPED     |                              WS_CAPTION        |                              WS_SYSMENU        |                              WS_THICKFRAME     |                              WS_MINIMIZEBOX    |                              WS_MAXIMIZEBOX)

#define WS_POPUPWINDOW      (WS_POPUP          |                              WS_BORDER         |                              WS_SYSMENU)

#define WS_CHILDWINDOW      (WS_CHILD)

/*
 * Extended Window Styles
 */
#define WS_EX_DLGMODALFRAME     0x00000001L
#define WS_EX_NOPARENTNOTIFY    0x00000004L
#define WS_EX_TOPMOST           0x00000008L
#define WS_EX_ACCEPTFILES       0x00000010L
#define WS_EX_TRANSPARENT       0x00000020L
#if(WINVER >= 0x0400)
#define WS_EX_MDICHILD          0x00000040L
#define WS_EX_TOOLWINDOW        0x00000080L
#define WS_EX_WINDOWEDGE        0x00000100L
#define WS_EX_CLIENTEDGE        0x00000200L
#define WS_EX_CONTEXTHELP       0x00000400L

#endif /* WINVER >= 0x0400 */
#if(WINVER >= 0x0400)

#define WS_EX_RIGHT             0x00001000L
#define WS_EX_LEFT              0x00000000L
#define WS_EX_RTLREADING        0x00002000L
#define WS_EX_LTRREADING        0x00000000L
#define WS_EX_LEFTSCROLLBAR     0x00004000L
#define WS_EX_RIGHTSCROLLBAR    0x00000000L

#define WS_EX_CONTROLPARENT     0x00010000L
#define WS_EX_STATICEDGE        0x00020000L
#define WS_EX_APPWINDOW         0x00040000L


#define WS_EX_OVERLAPPEDWINDOW  (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE)
#define WS_EX_PALETTEWINDOW     (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST)

#endif /* WINVER >= 0x0400 */

#if(_WIN32_WINNT >= 0x0500)
#define WS_EX_LAYERED           0x00080000

#endif /* _WIN32_WINNT >= 0x0500 */


#if(WINVER >= 0x0500)
#define WS_EX_NOINHERITLAYOUT   0x00100000L // Disable inheritence of mirroring by children
#define WS_EX_LAYOUTRTL         0x00400000L // Right to left mirroring
#endif /* WINVER >= 0x0500 */


MSDN window style reference MSDN - contains info about extended window styles Edit control styles:
/*
 * Edit Control Styles
 */
#define ES_LEFT             0x0000L
#define ES_CENTER           0x0001L
#define ES_RIGHT            0x0002L
#define ES_MULTILINE        0x0004L
#define ES_UPPERCASE        0x0008L
#define ES_LOWERCASE        0x0010L
#define ES_PASSWORD         0x0020L
#define ES_AUTOVSCROLL      0x0040L
#define ES_AUTOHSCROLL      0x0080L
#define ES_NOHIDESEL        0x0100L
#define ES_OEMCONVERT       0x0400L
#define ES_READONLY         0x0800L
#define ES_WANTRETURN       0x1000L
#if(WINVER >= 0x0400)
#define ES_NUMBER           0x2000L
#endif /* WINVER >= 0x0400 */


MSDN edit control style reference Button control styles:
/*
 * Button Control Styles
 */
#define BS_PUSHBUTTON       0x00000000L
#define BS_DEFPUSHBUTTON    0x00000001L
#define BS_CHECKBOX         0x00000002L
#define BS_AUTOCHECKBOX     0x00000003L
#define BS_RADIOBUTTON      0x00000004L
#define BS_3STATE           0x00000005L
#define BS_AUTO3STATE       0x00000006L
#define BS_GROUPBOX         0x00000007L
#define BS_USERBUTTON       0x00000008L
#define BS_AUTORADIOBUTTON  0x00000009L
#define BS_PUSHBOX          0x0000000AL
#define BS_OWNERDRAW        0x0000000BL
#define BS_TYPEMASK         0x0000000FL
#define BS_LEFTTEXT         0x00000020L
#if(WINVER >= 0x0400)
#define BS_TEXT             0x00000000L
#define BS_ICON             0x00000040L
#define BS_BITMAP           0x00000080L
#define BS_LEFT             0x00000100L
#define BS_RIGHT            0x00000200L
#define BS_CENTER           0x00000300L
#define BS_TOP              0x00000400L
#define BS_BOTTOM           0x00000800L
#define BS_VCENTER          0x00000C00L
#define BS_PUSHLIKE         0x00001000L
#define BS_MULTILINE        0x00002000L
#define BS_NOTIFY           0x00004000L
#define BS_FLAT             0x00008000L
#define BS_RIGHTBUTTON      BS_LEFTTEXT
#endif /* WINVER >= 0x0400 */


MSDN button style reference Hopefully, I gave enough info for someone to help me here.

Share this post


Link to post
Share on other sites
Advertisement
I ran into that problem a while ago as well. Basically, when writing pure win32 applications the style of controls will default to the old windows 95 style. I'm not sure why, possibly for compatibility with older windows versions? Anyway, I found the solution as well.

This article describes how to make use of windows XP's visual styles in your program. It has been a great help for me :)

Share this post


Link to post
Share on other sites
It's got nothing to do with the window styles, it's just that your resource editor obviously adds to the resources the manifest file that is needed to enable the XP theme in your app. That file is on xml format and it looks something like this:


<PRE lang=xml><?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="CompanyName.ProductName.YourApp"
type="win32"
/>

<description>Your application description here.</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly></PRE>



You can either add it yourself in your resources (read this) or you can save it as MyApp.exe.manifest and put it in the same folder as your application.

Share this post


Link to post
Share on other sites
You should look into using a resource editor and creating the window using the resource editor if you don't want that type of apperance. It is much easier and is one solution to fix its apperance. You could also experiment with overriding the controls to make your own GUI system. This way it won't look all Win95ish.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!