Click here to Skip to main content
Click here to Skip to main content

Using Skins Without MFC

By , 17 Jul 2001
 

Sample Image - SkinStyle.jpg

Introduction

SkinStyle is a picture based skin system written in Visual C++/Win32 and loosely based on Cuneyt Elibol's MFC/SkinSys. The major difference is SkinStyle is written without any MFC. Much of the functionality found in SkinSys is not found in this version of SkinStyle.

Contents

  • SkinStyle Source
  • A Simple Example

Download Directories

Once you download and extract the files, you'll see several new folders. Here is what each are used for.

  • Root : The SkinStyle Code
  • SkinTest : An Example Project And Skin

Example

Create a class that inherits from SkinDialog

class KSkinTest : public SkinDialog
{
public:
	// here we are overriding the OnKeyDown member of SkinDialog
	// so the app will exit on ESC
	virtual void OnKeyDown(WPARAM wParam, LPARAM lParam)
	{
		if ( wParam == VK_ESCAPE )
			::PostMessage(m_hWnd, WM_CLOSE, 0, 0);
	}
	// we also override the OnButtonPressed member of SkinDialog
	// to catch the user pushing one of the buttons
	virtual BOOL OnButtonPressed(char *ButtonName);

};

Now lets look at how to handle buttons being pressed...

//
// This member function is called with the name of the button being pressed
//
BOOL KSkinTest::OnButtonPressed(char *ButtonName)
{
	if(strcmp(ButtonName, "BUTTON_EXIT") == 0)
		::PostMessage(m_hWnd, WM_CLOSE, 0, 0);

	else if(strcmp(ButtonName, "BUTTON_MINIMIZE") == 0)
		::ShowWindow(m_hWnd, SW_MINIMIZE);

	else if(strcmp(ButtonName, "YOUR_DEFINED_BUTTON") == 0)
	{
		//
		// Do Something...
		//
	}
	return FALSE;
}

Once you have defined your new dialog class it can be used in WinMain like this

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR lpCmd, int nShow)
{
	KSkinTest win;

	HWND hParent;

	// GetFile is a user defined function that returns a file with the full path...

	char *SkinFile = GetFile(NULL);

	if(SkinFile[0] == 0) 
	{
		GlobalFree(SkinFile);
		return 0;
	}

	// here we create the dialog
	hParent = win.CreateEx("SkinTest", 	// Text in caption
				CW_USEDEFAULT, 	// x coord
				CW_USEDEFAULT, 	// y coord
				hInst, 		// HINSTANCE
				SkinFile);	// full path of skin file

	GlobalFree(SkinFile);
	
	win.SetSticky(true);	// make the dialog sticky

	win.ShowWindow(nShow);	// Show the new dialog
	win.UpdateWindow();	// Update it

	return win.MessageLoop();	// Enter the message loop
}

Skin file format

A Skin file consists of three parts (more to come later)

  • [SCREEN] : This section contains the image files to display
    • Mask : This specifies the mask image for the dialog
    • Main : This specifies the main image for the dialog
    • Down : This specifies the image displayed when a widget is pressed
    • Over : This specifies the image displayed when the mouse is over a sensitive widget
    • Disabled : This specifies the image displayed when the dialog is inactive

  • [BUTTONINFO] : This section contains a numbered list of buttons to display
    • #=BUTTON_NAME,x,y,width,height,TOOL_TIP,FALSE

  • [TEXTINFO] : This section contains a numbered list of labels to display
    • #=TEXT_NAME,FONT,BOLD(TRUE/FALSE),ITALIC(TRUE/FALSE),SIZE,COLOR(long),x,y,width,height,TOOL_TIP

For example:

[SCREEN]
Mask=Mask.bmp
Main=Main.bmp
Down=Selected.bmp
Over=Selected.bmp
Disabled=Main.bmp

[BUTTONINFO]
1=BUTTON_MINIMIZE,4,1,7,8,Minimize,FALSE
2=BUTTON_BABEL,12,425,43,19,Babel Preferences,FALSE
3=BUTTON_EXIT,196,1,7,8,Exit,FALSE
4=BUTTON_STATUS,119,425,25,19,User Status,FALSE

[TEXTINFO]
1=TEXT_STATUS,Courier New,FALSE,TRUE,-8,3496550,136,424,64,6,Offline,User Status

Problems/Bugs

At this stage I am unable to reload skins at run time? This is apparent in the sample app.

Additional Notes

This is by no means a finished product! This is my first attempt at writing a terribly complicated Win32 application library. I wanted something similar to SkinSys in functionality but without the overhead of MFC. There will be bugs and errors! I hope that you find this code useful. If you have any improvements/suggestions, comments/flames, or questions please e-mail me or post here.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

About the Author

John Roark
Software Developer (Senior)
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralImprovementsmembersk8er_boy2874 Oct '06 - 4:37 
This is very good, but you can improve most of the parts. For example, the transparency mask can be converted to a black-and-white bitmap (unless you use any blending techniques other than the XOR/AND BitBlt). I'm telling you this without even looking at the code. The mask can also be completely removed by using a color key. A good alternative to color keying is using alpha blending for more transparency effects, although this would only work on Windows XP. Btw, the guy talking about selling this *WAS* advertising. He appears to be as dumb as an ox to me. I am trying to do something similar in assembly language and that's why I had to mention this. (Basically, the entire code could be improved by porting it to assembly language Smile | :) ). Also, I noticed you're not really "skinning" the entire window, just it's client area. The non client area can also be skinned separately. Although MSDN says to avoid this, it's the way it's done in every big skinning project. The bad thing is there aren't any tutorials on skinning the non client area of a window or skinning the common controls and MSDN doesn't say how to do this. The skinning projects are all just improvised hacks. But as long as they look and feel good noone will ever say anything if it crashes Smile | :) Anyways... I'm now waiting on Windows Vista which promises a lot more support for skinning windows.
GeneralRe: Improvementsmembermau.deg22 Oct '06 - 22:52 
How can I do to create transparency effect? I would like to have the skinny dialog box 80% transparent over the desktop.
Could you help me?
 
thanks a lot
Mauri

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 18 Jul 2001
Article Copyright 2001 by John Roark
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid