/* This partial library from WGCL only works with Dev-Cpp, may not work with any other compiler */
/*
* This source code/file is part of the WGCL C++ Compiler Library.
*
* WGCL: Windows GUI Compiler Library
* Version: 1.2
* Original Mod date: 10/11/2008
* Partial Product Release Date: 5/31/2009
* Author: Michael Brandon Miller
* Original FileName: Dialogs.h
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* * * * * BEGIN COLORDIALOG CLASS * * * * */
typedef class ColorDialog
{
public:
HWND _Parent;
bool AllowAnyColor;
void ShowDialog();
COLORREF Color(void);
private:
COLORREF DefaultColor;
COLORREF Result;
bool Success;
bool Opened;
};
void ColorDialog::ShowDialog()
{
CHOOSECOLOR color;
Result = DefaultColor;
ZeroMemory(&color, sizeof(color));
color.hwndOwner = _Parent;
color.lStructSize = sizeof(color);
if (AllowAnyColor)
color.Flags = CC_RGBINIT | CC_FULLOPEN | CC_ANYCOLOR;
else
color.Flags = CC_RGBINIT | CC_FULLOPEN;
color.rgbResult = Result;
Success = ChooseColor(&color);
Opened = true;
}
COLORREF ColorDialog::Color(void)
{
if(Opened)
{
if(Success)
return Result;
else
return NULL;
}
}
/* * * * * END COLORDIALOG CLASS * * * * */
/* * * * * BEGIN OPENFILEDIALOG CLASS * * * * */
typedef class OpenFileDialog
{
public:
HWND _Parent;
LPCTSTR DefaultExt;
LPSTR InitialDir;
bool AllowMultiSelect;
WORD SelFilterIndex;
LPSTR Filter;
LPSTR Title;
void ShowDialog();
char* File(void);
private:
char FileName[MAX_PATH];
DWORD flags;
bool Success;
bool Opened;
};
void OpenFileDialog::ShowDialog()
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
FileName[0] = 0;
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = _Parent;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = Filter;
ofn.lpstrFile = FileName;
ofn.lpstrTitle = Title;
ofn.nFilterIndex = SelFilterIndex;
ofn.lpstrDefExt = DefaultExt;
if(AllowMultiSelect == true)
flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT;
else
flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
ofn.Flags = flags;
Success = GetOpenFileName(&ofn);
Opened = true;
}
char* OpenFileDialog::File(void)
{
if(Opened)
{
if(Success)
return FileName;
else
return NULL;
}
}
/* * * * * END OPENFILEDIALOG CLASS * * * * */
/* * * * * BEGIN SAVEFILEDIALOG CLASS * * * * */
typedef class SaveFileDialog
{
public:
HWND _Parent;
LPCTSTR DefaultExt;
LPSTR InitialDir;
bool AllowMultiSelect;
WORD SelFilterIndex;
LPSTR Filter;
LPSTR Title;
void ShowDialog();
char* File(void);
private:
char FileName[MAX_PATH];
bool Success;
bool Opened;
};
void SaveFileDialog::ShowDialog()
{
OPENFILENAME sfn;
ZeroMemory(&sfn, sizeof(sfn));
FileName[0] = 0;
sfn.lStructSize = sizeof(sfn);
sfn.hwndOwner = _Parent;
sfn.nMaxFile = MAX_PATH;
sfn.lpstrFilter = Filter;
sfn.lpstrFile = FileName;
sfn.lpstrTitle = Title;
sfn.nFilterIndex = SelFilterIndex;
sfn.lpstrDefExt = DefaultExt;
sfn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
Success = GetSaveFileName(&sfn);
Opened = true;
}
char* SaveFileDialog::File(void)
{
if(Opened)
{
if(Success)
return FileName;
else
return NULL;
}
}
/* * * * * END SAVEFILEDIALOG CLASS * * * * */
/* * * * * BEGIN FONTDIALOG CLASS * * * * */
typedef class FontDialog
{
public:
HWND _Parent;
int MaxSize, MinSize;
bool TrueTypesOnly, LimitSize;
void ShowDialog();
HFONT Font(void);
private:
bool Success;
bool Opened;
LOGFONT lgFont;
HFONT hFont, PrevFont;
DWORD CurRGB, PrevRGB;
HDC hDC;
};
void FontDialog::ShowDialog()
{
CHOOSEFONT CF;
ZeroMemory(&CF, sizeof(CF));
CF.lStructSize = sizeof (CHOOSEFONT);
CF.hwndOwner = _Parent;
CF.lpLogFont = &lgFont;
CF.rgbColors = CurRGB;
if(LimitSize)
{
CF.nSizeMin = MinSize;
CF.nSizeMax = MaxSize;
}
if(TrueTypesOnly)
{
if(LimitSize)
CF.Flags = CF_SCREENFONTS | CF_TTONLY | CF_LIMITSIZE;
else
CF.Flags = CF_SCREENFONTS | CF_TTONLY;
} else {
if(LimitSize)
CF.Flags = CF_SCREENFONTS | CF_LIMITSIZE;
else
CF.Flags = CF_SCREENFONTS;
}
Success = ChooseFont(&CF);
Opened = true;
}
HFONT FontDialog::Font(void)
{
if(Opened)
{
hFont = CreateFontIndirect(&lgFont);
if(Success)
return hFont;
else
return NULL;
}
}
/* * * * * END FONTDIALOG CLASS * * * * */