Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Skins for GUI applications

Status
Not open for further replies.

Wings

Programmer
Feb 14, 2002
247
US
Hi,

I am attempting to create a Borland C++ GUI application that makes use of images as skins on the forms, in much the same way as Winamp does.
If any one has any ideas on how to even begin this or knows of any sites to send me in the right direction, I would appreciate the help.

Thank You
 
Place an image component on the form and place a *.jpg picture in it, this will be the default skin.
Place an OpenDialog on the form.
In the header of the *.cpp file place:
#include <vcl.h>
#include <string.h>
#include <alloc.h>
#include <jpeg.hpp>
#include <dir.h>

Under TForm1 *Form1 place:
char lpFilename[256];
char IniFile[256];
char *s;
char drive[MAXDRIVE];
char dir[MAXDIR];
char file1[MAXFILE];
char ext[MAXEXT];
char DefaultSkin[256];

In the FormCreate handler place:
void __fastcall TForm1::FormCreate(TObject *Sender)
{
GetModuleFileName(NULL,lpFilename, sizeof(lpFilename));
s = lpFilename;
fnsplit(s,drive,dir,file1,ext);
sprintf(DefaultSkin, &quot;%s%sdefaultskin.jpg&quot;, drive, dir);
sprintf(IniFile, &quot;%s%s%s.INI&quot;, drive, dir, file1);
//get skin to use
char szGetSkin[256];
if(GetPrivateProfileString(&quot;SKIN&quot;, &quot;1&quot;,
&quot;&quot;, szGetSkin, sizeof(szGetSkin), IniFile) > 2)
{
Image1->Picture->LoadFromFiele(szGetSkin);
}
else
{
if(FileExists(DefaultSkin))
{
Image1->Picture->LoadFromFile(DefaultSkin);
}
}
}
//-------------------------------------------------------
In a Menu Item place this:
void __fastcall TForm1::GetSkinClick(TObject *Sender)
{
if(OpenDialog1->Execute())
{
Image1->Picture->SaveToFile(DefaultSkin);
Image1->Picture->LoadFromFiele(OpenDialog1->FileName);
WritePrivateProfileString(&quot;SKIN&quot;, &quot;1&quot;, OpenDialog1->FileName.c_str(), IniFile);
}
}
//--------------------------------------------------------
In a Menu Item place this:
void __fastcall TForm1::DefaultSkinClick(TObject *Sender)
{
WritePrivateProfileString(&quot;SKIN&quot;, &quot;1&quot;, &quot;&quot;, IniFile);
Image1->Picture->LoadFromFile(DefaultSkin);
}
 
It should be like this so you do not get an error if the DefaultSkin file has not be created:
In a Menu Item place this:
void __fastcall TForm1::DefaultSkinClick(TObject *Sender)
{
if(FileExists(DefaultSkin))
{
WritePrivateProfileString(&quot;SKIN&quot;, &quot;1&quot;, &quot;&quot;, IniFile);
Image1->Picture->LoadFromFile(DefaultSkin);
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top