set svn:eol-style=native for Plugins/**.cpp

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1441 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
bushing
2008-12-08 05:25:12 +00:00
parent 9146b9b261
commit 901fe7c00f
142 changed files with 43834 additions and 43834 deletions

View File

@ -1,29 +1,29 @@
#include <windows.h>
#include <vector>
#include "DialogManager.h"
typedef std::vector <HWND> WindowList;
WindowList dialogs;
void DialogManager::AddDlg(HWND hDialog)
{
dialogs.push_back(hDialog);
}
bool DialogManager::IsDialogMessage(LPMSG message)
{
WindowList::iterator iter;
for (iter=dialogs.begin(); iter!=dialogs.end(); iter++)
{
if (::IsDialogMessage(*iter,message))
return true;
}
return false;
}
void DialogManager::EnableAll(BOOL enable)
{
WindowList::iterator iter;
for (iter=dialogs.begin(); iter!=dialogs.end(); iter++)
EnableWindow(*iter,enable);
}
#include <windows.h>
#include <vector>
#include "DialogManager.h"
typedef std::vector <HWND> WindowList;
WindowList dialogs;
void DialogManager::AddDlg(HWND hDialog)
{
dialogs.push_back(hDialog);
}
bool DialogManager::IsDialogMessage(LPMSG message)
{
WindowList::iterator iter;
for (iter=dialogs.begin(); iter!=dialogs.end(); iter++)
{
if (::IsDialogMessage(*iter,message))
return true;
}
return false;
}
void DialogManager::EnableAll(BOOL enable)
{
WindowList::iterator iter;
for (iter=dialogs.begin(); iter!=dialogs.end(); iter++)
EnableWindow(*iter,enable);
}

View File

@ -1,148 +1,148 @@
#include <stdio.h>
#include <stdlib.h>
#include "File.h"
namespace W32Util
{
File::File()
{
fileHandle = INVALID_HANDLE_VALUE;
isOpen=false;
}
File::~File()
{
}
bool File::Open(const TCHAR *filename, eFileMode _mode)
{
mode = _mode;
//it's time to open the file
fileHandle = CreateFile(filename,
mode==FILE_READ ? GENERIC_READ : GENERIC_WRITE, //open mode
mode == FILE_READ ? FILE_SHARE_READ : NULL, //sharemode
NULL, //security
mode==FILE_READ ? OPEN_EXISTING : CREATE_ALWAYS, //create mode
FILE_ATTRIBUTE_NORMAL, //atrributes
NULL); //template
if (fileHandle == INVALID_HANDLE_VALUE)
isOpen=false;
else
isOpen=true;
return isOpen;
}
void File::Close()
{
if (isOpen)
{
//close the file and reset variables
CloseHandle(fileHandle);
fileHandle=INVALID_HANDLE_VALUE;
isOpen=false;
}
}
int File::GetSize()
{
if (!isOpen) //of course
return 0;
else
return GetFileSize(fileHandle,0);
}
int File::Write(void *data, int size) //let's do some writing
{
if (isOpen)
{
DWORD written;
WriteFile(fileHandle, data, size, &written,0);
return written; //we return the number of bytes that actually got written
}
else
{
return 0;
}
}
int File::Read(void *data, int size)
{
if (isOpen)
{
DWORD wasRead;
ReadFile(fileHandle, data, size, &wasRead,0);
return wasRead; //we return the number of bytes that actually was read
}
else
{
return 0;
}
}
int File::WR(void *data, int size)
{
if (mode==FILE_READ)
return Read(data,size);
else
return Write(data,size);
}
bool File::MagicCookie(int cookie)
{
if (mode==FILE_READ)
{
if (ReadInt()!=cookie)
{
char mojs[5],temp[256];
mojs[4]=0;
*(int*)mojs=cookie;
sprintf(temp,"W32Util::File: Magic Cookie %s is bad!",mojs);
MessageBox(0,temp,"Error reading file",MB_ICONERROR);
return false;
}
else
return true;
}
else if (mode==FILE_WRITE)
{
WriteInt(cookie);
return true;
}
return false;
}
int File::ReadInt()
{
int temp;
if (Read(&temp, sizeof(int)))
return temp;
else
return 0;
}
void File::WriteInt(int i)
{
Write(&i,sizeof(int));
}
char File::ReadChar()
{
char temp;
if (Read(&temp, sizeof(char)))
return temp;
else
return 0;
}
void File::WriteChar(char i)
{
Write(&i,sizeof(char));
}
#include <stdio.h>
#include <stdlib.h>
#include "File.h"
namespace W32Util
{
File::File()
{
fileHandle = INVALID_HANDLE_VALUE;
isOpen=false;
}
File::~File()
{
}
bool File::Open(const TCHAR *filename, eFileMode _mode)
{
mode = _mode;
//it's time to open the file
fileHandle = CreateFile(filename,
mode==FILE_READ ? GENERIC_READ : GENERIC_WRITE, //open mode
mode == FILE_READ ? FILE_SHARE_READ : NULL, //sharemode
NULL, //security
mode==FILE_READ ? OPEN_EXISTING : CREATE_ALWAYS, //create mode
FILE_ATTRIBUTE_NORMAL, //atrributes
NULL); //template
if (fileHandle == INVALID_HANDLE_VALUE)
isOpen=false;
else
isOpen=true;
return isOpen;
}
void File::Close()
{
if (isOpen)
{
//close the file and reset variables
CloseHandle(fileHandle);
fileHandle=INVALID_HANDLE_VALUE;
isOpen=false;
}
}
int File::GetSize()
{
if (!isOpen) //of course
return 0;
else
return GetFileSize(fileHandle,0);
}
int File::Write(void *data, int size) //let's do some writing
{
if (isOpen)
{
DWORD written;
WriteFile(fileHandle, data, size, &written,0);
return written; //we return the number of bytes that actually got written
}
else
{
return 0;
}
}
int File::Read(void *data, int size)
{
if (isOpen)
{
DWORD wasRead;
ReadFile(fileHandle, data, size, &wasRead,0);
return wasRead; //we return the number of bytes that actually was read
}
else
{
return 0;
}
}
int File::WR(void *data, int size)
{
if (mode==FILE_READ)
return Read(data,size);
else
return Write(data,size);
}
bool File::MagicCookie(int cookie)
{
if (mode==FILE_READ)
{
if (ReadInt()!=cookie)
{
char mojs[5],temp[256];
mojs[4]=0;
*(int*)mojs=cookie;
sprintf(temp,"W32Util::File: Magic Cookie %s is bad!",mojs);
MessageBox(0,temp,"Error reading file",MB_ICONERROR);
return false;
}
else
return true;
}
else if (mode==FILE_WRITE)
{
WriteInt(cookie);
return true;
}
return false;
}
int File::ReadInt()
{
int temp;
if (Read(&temp, sizeof(int)))
return temp;
else
return 0;
}
void File::WriteInt(int i)
{
Write(&i,sizeof(int));
}
char File::ReadChar()
{
char temp;
if (Read(&temp, sizeof(char)))
return temp;
else
return 0;
}
void File::WriteChar(char i)
{
Write(&i,sizeof(char));
}
}

View File

@ -1,102 +1,102 @@
#include <stdio.h>
#include <stdlib.h>
#include "Misc.h"
namespace W32Util
{
//shamelessly taken from http://www.catch22.org.uk/tuts/tips.asp
void CenterWindow(HWND hwnd)
{
HWND hwndParent;
RECT rect, rectP;
int width, height;
int screenwidth, screenheight;
int x, y;
//make the window relative to its parent
hwndParent = GetParent(hwnd);
if (!hwndParent)
return;
GetWindowRect(hwnd, &rect);
GetWindowRect(hwndParent, &rectP);
width = rect.right - rect.left;
height = rect.bottom - rect.top;
x = ((rectP.right-rectP.left) - width) / 2 + rectP.left;
y = ((rectP.bottom-rectP.top) - height) / 2 + rectP.top;
screenwidth = GetSystemMetrics(SM_CXSCREEN);
screenheight = GetSystemMetrics(SM_CYSCREEN);
//make sure that the dialog box never moves outside of
//the screen
if(x < 0) x = 0;
if(y < 0) y = 0;
if(x + width > screenwidth) x = screenwidth - width;
if(y + height > screenheight) y = screenheight - height;
MoveWindow(hwnd, x, y, width, height, FALSE);
}
HBITMAP CreateBitmapFromARGB(HWND someHwnd, DWORD *image, int w, int h)
{
BITMAPINFO *bitmap_header;
static char bitmapbuffer[sizeof(BITMAPINFO)+16];
memset(bitmapbuffer,0,sizeof(BITMAPINFO)+16);
bitmap_header=(BITMAPINFO *)bitmapbuffer;
bitmap_header->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmap_header->bmiHeader.biPlanes = 1;
bitmap_header->bmiHeader.biBitCount = 32;
bitmap_header->bmiHeader.biCompression = BI_RGB;
bitmap_header->bmiHeader.biWidth = w;
bitmap_header->bmiHeader.biHeight = -h;
((unsigned long *)bitmap_header->bmiColors)[0] = 0x00FF0000;
((unsigned long *)bitmap_header->bmiColors)[1] = 0x0000FF00;
((unsigned long *)bitmap_header->bmiColors)[2] = 0x000000FF;
HDC dc = GetDC(someHwnd);
HBITMAP bitmap = CreateDIBitmap(dc,&bitmap_header->bmiHeader,CBM_INIT,image,bitmap_header,DIB_RGB_COLORS);
ReleaseDC(someHwnd,dc);
return bitmap;
}
void NiceSizeFormat(size_t size, char *out)
{
char *sizes[] = {"b","KB","MB","GB","TB","PB","EB"};
int s = 0;
int frac = 0;
while (size>1024)
{
s++;
frac = (int)size & 1023;
size /= 1024;
}
float f = (float)size + ((float)frac / 1024.0f);
sprintf(out,"%3.1f %s",f,sizes[s]);
}
BOOL CopyTextToClipboard(HWND hwnd, TCHAR *text)
{
OpenClipboard(hwnd);
EmptyClipboard();
HANDLE hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (strlen(text) + 1) * sizeof(TCHAR));
if (hglbCopy == NULL)
{
CloseClipboard();
return FALSE;
}
// Lock the handle and copy the text to the buffer.
TCHAR *lptstrCopy = (TCHAR *)GlobalLock(hglbCopy);
strcpy(lptstrCopy, text);
lptstrCopy[strlen(text)] = (TCHAR) 0; // null character
GlobalUnlock(hglbCopy);
SetClipboardData(CF_TEXT,hglbCopy);
CloseClipboard();
return TRUE;
}
#include <stdio.h>
#include <stdlib.h>
#include "Misc.h"
namespace W32Util
{
//shamelessly taken from http://www.catch22.org.uk/tuts/tips.asp
void CenterWindow(HWND hwnd)
{
HWND hwndParent;
RECT rect, rectP;
int width, height;
int screenwidth, screenheight;
int x, y;
//make the window relative to its parent
hwndParent = GetParent(hwnd);
if (!hwndParent)
return;
GetWindowRect(hwnd, &rect);
GetWindowRect(hwndParent, &rectP);
width = rect.right - rect.left;
height = rect.bottom - rect.top;
x = ((rectP.right-rectP.left) - width) / 2 + rectP.left;
y = ((rectP.bottom-rectP.top) - height) / 2 + rectP.top;
screenwidth = GetSystemMetrics(SM_CXSCREEN);
screenheight = GetSystemMetrics(SM_CYSCREEN);
//make sure that the dialog box never moves outside of
//the screen
if(x < 0) x = 0;
if(y < 0) y = 0;
if(x + width > screenwidth) x = screenwidth - width;
if(y + height > screenheight) y = screenheight - height;
MoveWindow(hwnd, x, y, width, height, FALSE);
}
HBITMAP CreateBitmapFromARGB(HWND someHwnd, DWORD *image, int w, int h)
{
BITMAPINFO *bitmap_header;
static char bitmapbuffer[sizeof(BITMAPINFO)+16];
memset(bitmapbuffer,0,sizeof(BITMAPINFO)+16);
bitmap_header=(BITMAPINFO *)bitmapbuffer;
bitmap_header->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmap_header->bmiHeader.biPlanes = 1;
bitmap_header->bmiHeader.biBitCount = 32;
bitmap_header->bmiHeader.biCompression = BI_RGB;
bitmap_header->bmiHeader.biWidth = w;
bitmap_header->bmiHeader.biHeight = -h;
((unsigned long *)bitmap_header->bmiColors)[0] = 0x00FF0000;
((unsigned long *)bitmap_header->bmiColors)[1] = 0x0000FF00;
((unsigned long *)bitmap_header->bmiColors)[2] = 0x000000FF;
HDC dc = GetDC(someHwnd);
HBITMAP bitmap = CreateDIBitmap(dc,&bitmap_header->bmiHeader,CBM_INIT,image,bitmap_header,DIB_RGB_COLORS);
ReleaseDC(someHwnd,dc);
return bitmap;
}
void NiceSizeFormat(size_t size, char *out)
{
char *sizes[] = {"b","KB","MB","GB","TB","PB","EB"};
int s = 0;
int frac = 0;
while (size>1024)
{
s++;
frac = (int)size & 1023;
size /= 1024;
}
float f = (float)size + ((float)frac / 1024.0f);
sprintf(out,"%3.1f %s",f,sizes[s]);
}
BOOL CopyTextToClipboard(HWND hwnd, TCHAR *text)
{
OpenClipboard(hwnd);
EmptyClipboard();
HANDLE hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (strlen(text) + 1) * sizeof(TCHAR));
if (hglbCopy == NULL)
{
CloseClipboard();
return FALSE;
}
// Lock the handle and copy the text to the buffer.
TCHAR *lptstrCopy = (TCHAR *)GlobalLock(hglbCopy);
strcpy(lptstrCopy, text);
lptstrCopy[strlen(text)] = (TCHAR) 0; // null character
GlobalUnlock(hglbCopy);
SetClipboardData(CF_TEXT,hglbCopy);
CloseClipboard();
return TRUE;
}
}

View File

@ -1,225 +1,225 @@
#include "Misc.h"
#include "PropertySheet.h"
namespace W32Util
{
bool centered;
PropSheet::PropSheet()
{
watermark = 0;
header = 0;
icon = 0;
}
int CALLBACK PropSheet::Callback(HWND hwndDlg, UINT uMsg, LPARAM lParam)
{
switch (uMsg) {
case PSCB_PRECREATE:
{
if (uMsg == PSCB_PRECREATE)
{
/*
if (lParam)
{
DLGTEMPLATE *pDlgTemplate;
DLGTEMPLATEEX *pDlgTemplateEx;
pDlgTemplateEx = (DLGTEMPLATEEX *)lParam;
if (pDlgTemplateEx->signature == 0xFFFF)
{
// pDlgTemplateEx points to an extended
// dialog template structure.
//pDlgTemplate->style |= DS_SETFONT;
u8 *tmp1 = (u8*)&pDlgTemplateEx + sizeof(DLGTEMPLATEEX);
u16 *tmp = (u16*)tmp1;
tmp++; //skip menu
tmp++; //skip dlg class
//Crash();
//Here we should bash in Segoe UI
//It turns out to be way complicated though
//Not worth it
}
else
{
// This is a standard dialog template
// structure.
pDlgTemplate = (DLGTEMPLATE *)lParam;
}
} */
}
}
break;
case PSCB_INITIALIZED:
{
}
return 0;
}
return 0;
}
void PropSheet::Show(HINSTANCE hInstance, HWND hParent, std::string title, int startpage, bool floating, bool wizard)
{
HPROPSHEETPAGE *pages = new HPROPSHEETPAGE[list.size()];
PROPSHEETPAGE page;
//common settings
memset((void*)&page,0,sizeof(PROPSHEETPAGE));
page.dwSize = sizeof(PROPSHEETPAGE);
page.hInstance = hInstance;
int i=0;
for (DlgList::iterator iter = list.begin(); iter != list.end(); iter++, i++)
{
if (wizard)
{
if (i == 0 || i == list.size()-1)
page.dwFlags = PSP_HIDEHEADER;
else
page.dwFlags = PSP_USEHEADERTITLE|PSP_USEHEADERSUBTITLE;
}
else
{
page.dwFlags = PSP_USETITLE;
}
page.pszTemplate = iter->resource;
page.pfnDlgProc = Tab::TabDlgProc;
page.pszTitle = iter->title;
page.pszHeaderTitle = wizard?iter->title:0;
page.pszHeaderSubTitle = wizard?iter->hdrSubTitle:0;
page.lParam = (LPARAM)iter->tab;
pages[i] = CreatePropertySheetPage(&page);
}
PROPSHEETHEADER sheet;
memset(&sheet,0,sizeof(sheet));
sheet.dwSize = sizeof(PROPSHEETHEADER);
sheet.hInstance = hInstance;
sheet.hwndParent = hParent;
sheet.pszbmWatermark = watermark;
sheet.pszbmHeader = header;
if (icon)
sheet.hIcon = icon;
if (wizard)
sheet.dwFlags = PSH_USECALLBACK | PSH_WIZARD97 | (watermark?PSH_WATERMARK:0) | (header?PSH_HEADER:0);
else
sheet.dwFlags = PSH_USECALLBACK | PSH_PROPTITLE;
sheet.dwFlags |= PSH_NOCONTEXTHELP;
if (floating)
sheet.dwFlags |= PSH_MODELESS;
//else
// sheet.dwFlags |= PSH_NOAPPLYNOW;
if (icon)
sheet.dwFlags |= PSH_USEHICON;
sheet.pszCaption = title.c_str();
sheet.nPages = (UINT)list.size();
sheet.phpage = pages;
sheet.nStartPage = startpage;
sheet.pfnCallback = (PFNPROPSHEETCALLBACK)Callback;
NONCLIENTMETRICS ncm = {0};
ncm.cbSize = sizeof(ncm);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
hDialogFont = CreateFontIndirect(&ncm.lfMessageFont);
if (wizard)
{
//Create the intro/end title font
LOGFONT TitleLogFont = ncm.lfMessageFont;
TitleLogFont.lfWeight = FW_BOLD;
lstrcpy(TitleLogFont.lfFaceName, TEXT("Verdana Bold"));
//StringCchCopy(TitleLogFont.lfFaceName, 32, TEXT("Verdana Bold"));
HDC hdc = GetDC(NULL); //gets the screen DC
int FontSize = 12;
TitleLogFont.lfHeight = 0 - GetDeviceCaps(hdc, LOGPIXELSY) * FontSize / 72;
hTitleFont = CreateFontIndirect(&TitleLogFont);
ReleaseDC(NULL, hdc);
}
else
hTitleFont = 0;
centered=false;
PropertySheet(&sheet);
if (!floating)
{
for (DlgList::iterator iter = list.begin(); iter != list.end(); iter++)
{
delete iter->tab;
}
DeleteObject(hTitleFont);
}
DeleteObject(hDialogFont);
delete [] pages;
}
void PropSheet::Add(Tab *tab, LPCTSTR resource, LPCTSTR title, LPCTSTR subtitle)
{
tab->sheet = this;
list.push_back(Page(tab,resource,title,subtitle));
}
void WizExteriorPage::Init(HWND hDlg)
{
HWND hwndControl = GetDlgItem(hDlg, captionID);
//SetWindowFont(hwndControl, sheet->GetTitleFont(), TRUE);
SendMessage(hwndControl,WM_SETFONT,(WPARAM)sheet->GetTitleFont(),0);
}
INT_PTR Tab::TabDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
Tab *tab = (Tab *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
switch(message)
{
case WM_INITDIALOG:
{
if (!centered) //HACK
{
CenterWindow(GetParent(hDlg));
centered=true;
}
LPARAM l = ((LPPROPSHEETPAGE)lParam)->lParam;
tab = (Tab *)l;
SetWindowLongPtr(hDlg, GWLP_USERDATA, (DWORD_PTR)l);
tab->Init(hDlg);
}
break;
case WM_COMMAND:
tab->Command(hDlg,wParam);
break;
case WM_NOTIFY:
{
LPPSHNOTIFY lppsn = (LPPSHNOTIFY) lParam;
HWND sheet = lppsn->hdr.hwndFrom;
switch(lppsn->hdr.code) {
case PSN_APPLY:
tab->Apply(hDlg);
break;
case PSN_SETACTIVE:
PropSheet_SetWizButtons(GetParent(hDlg),
(tab->HasPrev()?PSWIZB_BACK:0) |
(tab->HasNext()?PSWIZB_NEXT:0) |
(tab->HasFinish()?PSWIZB_FINISH:0));
break;
case PSN_WIZNEXT:
tab->Apply(hDlg); //maybe not always good
break;
case PSN_WIZBACK:
case PSN_RESET: //cancel
break;
}
}
break;
}
return 0;
}
#include "Misc.h"
#include "PropertySheet.h"
namespace W32Util
{
bool centered;
PropSheet::PropSheet()
{
watermark = 0;
header = 0;
icon = 0;
}
int CALLBACK PropSheet::Callback(HWND hwndDlg, UINT uMsg, LPARAM lParam)
{
switch (uMsg) {
case PSCB_PRECREATE:
{
if (uMsg == PSCB_PRECREATE)
{
/*
if (lParam)
{
DLGTEMPLATE *pDlgTemplate;
DLGTEMPLATEEX *pDlgTemplateEx;
pDlgTemplateEx = (DLGTEMPLATEEX *)lParam;
if (pDlgTemplateEx->signature == 0xFFFF)
{
// pDlgTemplateEx points to an extended
// dialog template structure.
//pDlgTemplate->style |= DS_SETFONT;
u8 *tmp1 = (u8*)&pDlgTemplateEx + sizeof(DLGTEMPLATEEX);
u16 *tmp = (u16*)tmp1;
tmp++; //skip menu
tmp++; //skip dlg class
//Crash();
//Here we should bash in Segoe UI
//It turns out to be way complicated though
//Not worth it
}
else
{
// This is a standard dialog template
// structure.
pDlgTemplate = (DLGTEMPLATE *)lParam;
}
} */
}
}
break;
case PSCB_INITIALIZED:
{
}
return 0;
}
return 0;
}
void PropSheet::Show(HINSTANCE hInstance, HWND hParent, std::string title, int startpage, bool floating, bool wizard)
{
HPROPSHEETPAGE *pages = new HPROPSHEETPAGE[list.size()];
PROPSHEETPAGE page;
//common settings
memset((void*)&page,0,sizeof(PROPSHEETPAGE));
page.dwSize = sizeof(PROPSHEETPAGE);
page.hInstance = hInstance;
int i=0;
for (DlgList::iterator iter = list.begin(); iter != list.end(); iter++, i++)
{
if (wizard)
{
if (i == 0 || i == list.size()-1)
page.dwFlags = PSP_HIDEHEADER;
else
page.dwFlags = PSP_USEHEADERTITLE|PSP_USEHEADERSUBTITLE;
}
else
{
page.dwFlags = PSP_USETITLE;
}
page.pszTemplate = iter->resource;
page.pfnDlgProc = Tab::TabDlgProc;
page.pszTitle = iter->title;
page.pszHeaderTitle = wizard?iter->title:0;
page.pszHeaderSubTitle = wizard?iter->hdrSubTitle:0;
page.lParam = (LPARAM)iter->tab;
pages[i] = CreatePropertySheetPage(&page);
}
PROPSHEETHEADER sheet;
memset(&sheet,0,sizeof(sheet));
sheet.dwSize = sizeof(PROPSHEETHEADER);
sheet.hInstance = hInstance;
sheet.hwndParent = hParent;
sheet.pszbmWatermark = watermark;
sheet.pszbmHeader = header;
if (icon)
sheet.hIcon = icon;
if (wizard)
sheet.dwFlags = PSH_USECALLBACK | PSH_WIZARD97 | (watermark?PSH_WATERMARK:0) | (header?PSH_HEADER:0);
else
sheet.dwFlags = PSH_USECALLBACK | PSH_PROPTITLE;
sheet.dwFlags |= PSH_NOCONTEXTHELP;
if (floating)
sheet.dwFlags |= PSH_MODELESS;
//else
// sheet.dwFlags |= PSH_NOAPPLYNOW;
if (icon)
sheet.dwFlags |= PSH_USEHICON;
sheet.pszCaption = title.c_str();
sheet.nPages = (UINT)list.size();
sheet.phpage = pages;
sheet.nStartPage = startpage;
sheet.pfnCallback = (PFNPROPSHEETCALLBACK)Callback;
NONCLIENTMETRICS ncm = {0};
ncm.cbSize = sizeof(ncm);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
hDialogFont = CreateFontIndirect(&ncm.lfMessageFont);
if (wizard)
{
//Create the intro/end title font
LOGFONT TitleLogFont = ncm.lfMessageFont;
TitleLogFont.lfWeight = FW_BOLD;
lstrcpy(TitleLogFont.lfFaceName, TEXT("Verdana Bold"));
//StringCchCopy(TitleLogFont.lfFaceName, 32, TEXT("Verdana Bold"));
HDC hdc = GetDC(NULL); //gets the screen DC
int FontSize = 12;
TitleLogFont.lfHeight = 0 - GetDeviceCaps(hdc, LOGPIXELSY) * FontSize / 72;
hTitleFont = CreateFontIndirect(&TitleLogFont);
ReleaseDC(NULL, hdc);
}
else
hTitleFont = 0;
centered=false;
PropertySheet(&sheet);
if (!floating)
{
for (DlgList::iterator iter = list.begin(); iter != list.end(); iter++)
{
delete iter->tab;
}
DeleteObject(hTitleFont);
}
DeleteObject(hDialogFont);
delete [] pages;
}
void PropSheet::Add(Tab *tab, LPCTSTR resource, LPCTSTR title, LPCTSTR subtitle)
{
tab->sheet = this;
list.push_back(Page(tab,resource,title,subtitle));
}
void WizExteriorPage::Init(HWND hDlg)
{
HWND hwndControl = GetDlgItem(hDlg, captionID);
//SetWindowFont(hwndControl, sheet->GetTitleFont(), TRUE);
SendMessage(hwndControl,WM_SETFONT,(WPARAM)sheet->GetTitleFont(),0);
}
INT_PTR Tab::TabDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
Tab *tab = (Tab *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
switch(message)
{
case WM_INITDIALOG:
{
if (!centered) //HACK
{
CenterWindow(GetParent(hDlg));
centered=true;
}
LPARAM l = ((LPPROPSHEETPAGE)lParam)->lParam;
tab = (Tab *)l;
SetWindowLongPtr(hDlg, GWLP_USERDATA, (DWORD_PTR)l);
tab->Init(hDlg);
}
break;
case WM_COMMAND:
tab->Command(hDlg,wParam);
break;
case WM_NOTIFY:
{
LPPSHNOTIFY lppsn = (LPPSHNOTIFY) lParam;
HWND sheet = lppsn->hdr.hwndFrom;
switch(lppsn->hdr.code) {
case PSN_APPLY:
tab->Apply(hDlg);
break;
case PSN_SETACTIVE:
PropSheet_SetWizButtons(GetParent(hDlg),
(tab->HasPrev()?PSWIZB_BACK:0) |
(tab->HasNext()?PSWIZB_NEXT:0) |
(tab->HasFinish()?PSWIZB_FINISH:0));
break;
case PSN_WIZNEXT:
tab->Apply(hDlg); //maybe not always good
break;
case PSN_WIZBACK:
case PSN_RESET: //cancel
break;
}
}
break;
}
return 0;
}
}

View File

@ -1,124 +1,124 @@
#include <shlobj.h>
#include <xstring>
#include <string>
#include "ShellUtil.h"
namespace W32Util
{
std::string BrowseForFolder(HWND parent, char *title)
{
BROWSEINFO info;
memset(&info,0,sizeof(info));
info.hwndOwner = parent;
info.lpszTitle = title;
info.ulFlags = BIF_EDITBOX | BIF_RETURNONLYFSDIRS;
//info.pszDisplayName
LPCITEMIDLIST idList = SHBrowseForFolder(&info);
char temp[MAX_PATH];
SHGetPathFromIDList(idList, temp);
if (strlen(temp))
{
return temp;
}
else
return "";
}
//---------------------------------------------------------------------------------------------------
// function WinBrowseForFileName
//---------------------------------------------------------------------------------------------------
bool BrowseForFileName (bool _bLoad, HWND _hParent, const char *_pTitle,
const char *_pInitialFolder,const char *_pFilter,const char *_pExtension,
std::string& _strFileName)
{
char szFile [MAX_PATH+1];
char szFileTitle [MAX_PATH+1];
strcpy (szFile,"");
strcpy (szFileTitle,"");
OPENFILENAME ofn;
ZeroMemory (&ofn,sizeof (ofn));
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.lpstrInitialDir = _pInitialFolder;
ofn.lpstrFilter = _pFilter;
ofn.nMaxFile = sizeof (szFile);
ofn.lpstrFile = szFile;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = sizeof (szFileTitle);
ofn.lpstrDefExt = _pExtension;
ofn.hwndOwner = _hParent;
ofn.Flags = OFN_NOCHANGEDIR | OFN_EXPLORER | OFN_HIDEREADONLY;
if (_strFileName.size () != 0)
ofn.lpstrFile = (char *)_strFileName.c_str();
if (((_bLoad)?GetOpenFileName (&ofn):GetSaveFileName (&ofn)))
{
_strFileName = ofn.lpstrFile;
return true;
}
else
return false;
}
std::vector<std::string> BrowseForFileNameMultiSelect(bool _bLoad, HWND _hParent, const char *_pTitle,
const char *_pInitialFolder,const char *_pFilter,const char *_pExtension)
{
char szFile [MAX_PATH+1+2048*2];
char szFileTitle [MAX_PATH+1];
strcpy (szFile,"");
strcpy (szFileTitle,"");
OPENFILENAME ofn;
ZeroMemory (&ofn,sizeof (ofn));
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.lpstrInitialDir = _pInitialFolder;
ofn.lpstrFilter = _pFilter;
ofn.nMaxFile = sizeof (szFile);
ofn.lpstrFile = szFile;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = sizeof (szFileTitle);
ofn.lpstrDefExt = _pExtension;
ofn.hwndOwner = _hParent;
ofn.Flags = OFN_NOCHANGEDIR | OFN_EXPLORER | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT ;
std::vector<std::string> files;
if (((_bLoad)?GetOpenFileName (&ofn):GetSaveFileName (&ofn)))
{
std::string directory = ofn.lpstrFile;
char *temp = ofn.lpstrFile;
char *oldtemp = temp;
temp+=strlen(temp)+1;
if (*temp==0)
{
//we only got one file
files.push_back(std::string(oldtemp));
}
else
{
while (*temp)
{
files.push_back(directory+"\\"+std::string(temp));
temp+=strlen(temp)+1;
}
}
return files;
}
else
return std::vector<std::string>(); // empty vector;
}
#include <shlobj.h>
#include <xstring>
#include <string>
#include "ShellUtil.h"
namespace W32Util
{
std::string BrowseForFolder(HWND parent, char *title)
{
BROWSEINFO info;
memset(&info,0,sizeof(info));
info.hwndOwner = parent;
info.lpszTitle = title;
info.ulFlags = BIF_EDITBOX | BIF_RETURNONLYFSDIRS;
//info.pszDisplayName
LPCITEMIDLIST idList = SHBrowseForFolder(&info);
char temp[MAX_PATH];
SHGetPathFromIDList(idList, temp);
if (strlen(temp))
{
return temp;
}
else
return "";
}
//---------------------------------------------------------------------------------------------------
// function WinBrowseForFileName
//---------------------------------------------------------------------------------------------------
bool BrowseForFileName (bool _bLoad, HWND _hParent, const char *_pTitle,
const char *_pInitialFolder,const char *_pFilter,const char *_pExtension,
std::string& _strFileName)
{
char szFile [MAX_PATH+1];
char szFileTitle [MAX_PATH+1];
strcpy (szFile,"");
strcpy (szFileTitle,"");
OPENFILENAME ofn;
ZeroMemory (&ofn,sizeof (ofn));
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.lpstrInitialDir = _pInitialFolder;
ofn.lpstrFilter = _pFilter;
ofn.nMaxFile = sizeof (szFile);
ofn.lpstrFile = szFile;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = sizeof (szFileTitle);
ofn.lpstrDefExt = _pExtension;
ofn.hwndOwner = _hParent;
ofn.Flags = OFN_NOCHANGEDIR | OFN_EXPLORER | OFN_HIDEREADONLY;
if (_strFileName.size () != 0)
ofn.lpstrFile = (char *)_strFileName.c_str();
if (((_bLoad)?GetOpenFileName (&ofn):GetSaveFileName (&ofn)))
{
_strFileName = ofn.lpstrFile;
return true;
}
else
return false;
}
std::vector<std::string> BrowseForFileNameMultiSelect(bool _bLoad, HWND _hParent, const char *_pTitle,
const char *_pInitialFolder,const char *_pFilter,const char *_pExtension)
{
char szFile [MAX_PATH+1+2048*2];
char szFileTitle [MAX_PATH+1];
strcpy (szFile,"");
strcpy (szFileTitle,"");
OPENFILENAME ofn;
ZeroMemory (&ofn,sizeof (ofn));
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.lpstrInitialDir = _pInitialFolder;
ofn.lpstrFilter = _pFilter;
ofn.nMaxFile = sizeof (szFile);
ofn.lpstrFile = szFile;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = sizeof (szFileTitle);
ofn.lpstrDefExt = _pExtension;
ofn.hwndOwner = _hParent;
ofn.Flags = OFN_NOCHANGEDIR | OFN_EXPLORER | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT ;
std::vector<std::string> files;
if (((_bLoad)?GetOpenFileName (&ofn):GetSaveFileName (&ofn)))
{
std::string directory = ofn.lpstrFile;
char *temp = ofn.lpstrFile;
char *oldtemp = temp;
temp+=strlen(temp)+1;
if (*temp==0)
{
//we only got one file
files.push_back(std::string(oldtemp));
}
else
{
while (*temp)
{
files.push_back(directory+"\\"+std::string(temp));
temp+=strlen(temp)+1;
}
}
return files;
}
else
return std::vector<std::string>(); // empty vector;
}
}

View File

@ -1,94 +1,94 @@
#include <commctrl.h>
#include "TabControl.h"
namespace W32Util
{
// __________________________________________________________________________________________________
// constructor
//
TabControl::TabControl(HINSTANCE _hInstance, HWND _hTabCtrl,DLGPROC _lpDialogFunc) :
m_hInstance(_hInstance),
m_hTabCtrl(_hTabCtrl),
m_numDialogs(0)
{
for (int i=0; i<MAX_WIN_DIALOGS; i++)
m_WinDialogs[i] = NULL;
}
// __________________________________________________________________________________________________
// destructor
//
TabControl::~TabControl(void)
{}
// __________________________________________________________________________________________________
// AddItem
//
HWND TabControl::AddItem (char* _szText,int _iResource,DLGPROC _lpDialogFunc)
{
TCITEM tcItem;
ZeroMemory (&tcItem,sizeof (tcItem));
tcItem.mask = TCIF_TEXT | TCIF_IMAGE;
tcItem.dwState = 0;
tcItem.pszText = _szText;
tcItem.cchTextMax = sizeof (_szText);
tcItem.iImage = -1;
int nResult = TabCtrl_InsertItem (m_hTabCtrl,TabCtrl_GetItemCount (m_hTabCtrl),&tcItem);
HWND hDialog = CreateDialog(m_hInstance,(LPCSTR)_iResource,m_hTabCtrl,_lpDialogFunc);
RECT rectInnerWindow = {0,0,0,0};
GetWindowRect (m_hTabCtrl,&rectInnerWindow);
TabCtrl_AdjustRect (m_hTabCtrl,FALSE,&rectInnerWindow);
POINT pntPosition = {rectInnerWindow.left,rectInnerWindow.top};
ScreenToClient(m_hTabCtrl, &pntPosition);
SetWindowPos(hDialog, 0,
pntPosition.x, pntPosition.y,
rectInnerWindow.right - rectInnerWindow.left,rectInnerWindow.bottom - rectInnerWindow.top,0);
ShowWindow(hDialog,SW_NORMAL);
m_WinDialogs[m_numDialogs] = hDialog;
m_numDialogs++;
SelectDialog (0);
return hDialog;
}
// __________________________________________________________________________________________________
// SelectDialog
//
void TabControl::SelectDialog (int _nDialogId)
{
for (int i = 0 ; i < m_numDialogs ; i ++)
if (m_WinDialogs[i] != NULL)
ShowWindow(m_WinDialogs[i],i == _nDialogId ? SW_NORMAL : SW_HIDE);
}
// __________________________________________________________________________________________________
// MessageHandler
//
void TabControl::MessageHandler(UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_NOTIFY)
{
NMHDR* pNotifyMessage = NULL;
pNotifyMessage = (LPNMHDR)lParam;
if (pNotifyMessage->hwndFrom == m_hTabCtrl)
{
int iPage = TabCtrl_GetCurSel (m_hTabCtrl);
SelectDialog (iPage);
}
}
}
}
#include <commctrl.h>
#include "TabControl.h"
namespace W32Util
{
// __________________________________________________________________________________________________
// constructor
//
TabControl::TabControl(HINSTANCE _hInstance, HWND _hTabCtrl,DLGPROC _lpDialogFunc) :
m_hInstance(_hInstance),
m_hTabCtrl(_hTabCtrl),
m_numDialogs(0)
{
for (int i=0; i<MAX_WIN_DIALOGS; i++)
m_WinDialogs[i] = NULL;
}
// __________________________________________________________________________________________________
// destructor
//
TabControl::~TabControl(void)
{}
// __________________________________________________________________________________________________
// AddItem
//
HWND TabControl::AddItem (char* _szText,int _iResource,DLGPROC _lpDialogFunc)
{
TCITEM tcItem;
ZeroMemory (&tcItem,sizeof (tcItem));
tcItem.mask = TCIF_TEXT | TCIF_IMAGE;
tcItem.dwState = 0;
tcItem.pszText = _szText;
tcItem.cchTextMax = sizeof (_szText);
tcItem.iImage = -1;
int nResult = TabCtrl_InsertItem (m_hTabCtrl,TabCtrl_GetItemCount (m_hTabCtrl),&tcItem);
HWND hDialog = CreateDialog(m_hInstance,(LPCSTR)_iResource,m_hTabCtrl,_lpDialogFunc);
RECT rectInnerWindow = {0,0,0,0};
GetWindowRect (m_hTabCtrl,&rectInnerWindow);
TabCtrl_AdjustRect (m_hTabCtrl,FALSE,&rectInnerWindow);
POINT pntPosition = {rectInnerWindow.left,rectInnerWindow.top};
ScreenToClient(m_hTabCtrl, &pntPosition);
SetWindowPos(hDialog, 0,
pntPosition.x, pntPosition.y,
rectInnerWindow.right - rectInnerWindow.left,rectInnerWindow.bottom - rectInnerWindow.top,0);
ShowWindow(hDialog,SW_NORMAL);
m_WinDialogs[m_numDialogs] = hDialog;
m_numDialogs++;
SelectDialog (0);
return hDialog;
}
// __________________________________________________________________________________________________
// SelectDialog
//
void TabControl::SelectDialog (int _nDialogId)
{
for (int i = 0 ; i < m_numDialogs ; i ++)
if (m_WinDialogs[i] != NULL)
ShowWindow(m_WinDialogs[i],i == _nDialogId ? SW_NORMAL : SW_HIDE);
}
// __________________________________________________________________________________________________
// MessageHandler
//
void TabControl::MessageHandler(UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_NOTIFY)
{
NMHDR* pNotifyMessage = NULL;
pNotifyMessage = (LPNMHDR)lParam;
if (pNotifyMessage->hwndFrom == m_hTabCtrl)
{
int iPage = TabCtrl_GetCurSel (m_hTabCtrl);
SelectDialog (iPage);
}
}
}
}

View File

@ -1,82 +1,82 @@
#include "Thread.h"
namespace W32Util
{
// __________________________________________________________________________________________________
// Constructor
//
Thread::Thread ( DWORD (WINAPI * pFun) (void* arg), void* pArg)
{
_handle = CreateThread (
0, // Security attributes
0, // Stack size
pFun,
pArg,
CREATE_SUSPENDED,
&_tid);
}
// __________________________________________________________________________________________________
// Destructor
//
Thread::~Thread (void)
{
if (_handle != NULL)
{
if (CloseHandle (_handle) == FALSE)
{
Terminate();
}
}
}
// __________________________________________________________________________________________________
// Resume
//
void
Thread::Resume (void)
{
if (_handle != NULL)
ResumeThread (_handle);
}
// __________________________________________________________________________________________________
// WaitForDeath
//
void
Thread::WaitForDeath (void)
{
if (_handle != NULL)
WaitForSingleObject (_handle, 100);
}
// __________________________________________________________________________________________________
// Terminate
//
void
Thread::Terminate (void)
{
if (_handle != NULL)
TerminateThread (_handle, 0);
_handle = NULL;
}
// __________________________________________________________________________________________________
// SetPriority
//
void
Thread::SetPriority (int _nPriority)
{
if (_handle != NULL)
SetThreadPriority(_handle, _nPriority);
}
// __________________________________________________________________________________________________
// Suspend
//
void
Thread::Suspend (void)
{
if (_handle != NULL)
SuspendThread(_handle);
}
#include "Thread.h"
namespace W32Util
{
// __________________________________________________________________________________________________
// Constructor
//
Thread::Thread ( DWORD (WINAPI * pFun) (void* arg), void* pArg)
{
_handle = CreateThread (
0, // Security attributes
0, // Stack size
pFun,
pArg,
CREATE_SUSPENDED,
&_tid);
}
// __________________________________________________________________________________________________
// Destructor
//
Thread::~Thread (void)
{
if (_handle != NULL)
{
if (CloseHandle (_handle) == FALSE)
{
Terminate();
}
}
}
// __________________________________________________________________________________________________
// Resume
//
void
Thread::Resume (void)
{
if (_handle != NULL)
ResumeThread (_handle);
}
// __________________________________________________________________________________________________
// WaitForDeath
//
void
Thread::WaitForDeath (void)
{
if (_handle != NULL)
WaitForSingleObject (_handle, 100);
}
// __________________________________________________________________________________________________
// Terminate
//
void
Thread::Terminate (void)
{
if (_handle != NULL)
TerminateThread (_handle, 0);
_handle = NULL;
}
// __________________________________________________________________________________________________
// SetPriority
//
void
Thread::SetPriority (int _nPriority)
{
if (_handle != NULL)
SetThreadPriority(_handle, _nPriority);
}
// __________________________________________________________________________________________________
// Suspend
//
void
Thread::Suspend (void)
{
if (_handle != NULL)
SuspendThread(_handle);
}
}