mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Initial megacommit.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
265
Source/Plugins/Plugin_VideoDX9/Src/W32Util/ChunkFile.cpp
Normal file
265
Source/Plugins/Plugin_VideoDX9/Src/W32Util/ChunkFile.cpp
Normal file
@ -0,0 +1,265 @@
|
||||
#include "ChunkFile.h"
|
||||
|
||||
namespace W32Util
|
||||
{
|
||||
ChunkFile::ChunkFile(const TCHAR *filename, bool _read)
|
||||
{
|
||||
data=0;
|
||||
fastMode=false;
|
||||
if (file.Open(filename,_read ? FILE_READ : FILE_WRITE))
|
||||
{
|
||||
didFail=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
didFail=true;
|
||||
return;
|
||||
}
|
||||
|
||||
int fSize = file.GetSize();
|
||||
|
||||
fastMode = _read ? true : false;
|
||||
|
||||
if (fastMode)
|
||||
{
|
||||
data = new char[fSize];
|
||||
file.Read(data,fSize);
|
||||
file.Close();
|
||||
// MessageBox(theApp->getHWND(),TEXT("FILECLOSED"),TEXT("MOSJ"),0);
|
||||
}
|
||||
|
||||
eof=fSize;
|
||||
numLevels=0;
|
||||
read=_read;
|
||||
pos=0;
|
||||
didFail=false;
|
||||
}
|
||||
|
||||
ChunkFile::~ChunkFile()
|
||||
{
|
||||
if (fastMode && data)
|
||||
delete [] data;
|
||||
else
|
||||
file.Close();
|
||||
}
|
||||
|
||||
|
||||
int ChunkFile::ReadInt()
|
||||
{
|
||||
if (pos<eof)
|
||||
{
|
||||
/*
|
||||
int temp = *(int *)(data+pos);
|
||||
pos+=4;
|
||||
*/
|
||||
pos+=4;
|
||||
if (fastMode)
|
||||
return *(int *)(data+pos-4);
|
||||
else
|
||||
return file.ReadInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ChunkFile::WriteInt(int i)
|
||||
{
|
||||
/*
|
||||
*(int *)(data+pos) = i;
|
||||
pos+=4;
|
||||
*/
|
||||
file.WriteInt(i);
|
||||
pos+=4;
|
||||
}
|
||||
|
||||
//let's get into the business
|
||||
bool ChunkFile::Descend(unsigned int id)
|
||||
{
|
||||
id=flipID(id);
|
||||
if (read)
|
||||
{
|
||||
bool found = false;
|
||||
int startPos = pos;
|
||||
ChunkInfo temp = stack[numLevels];
|
||||
|
||||
//save information to restore after the next Ascend
|
||||
stack[numLevels].parentStartLocation = pos;
|
||||
stack[numLevels].parentEOF = eof;
|
||||
|
||||
|
||||
int firstID = 0;
|
||||
//let's search through children..
|
||||
while(pos<eof)
|
||||
{
|
||||
stack[numLevels].ID = ReadInt();
|
||||
if (firstID == 0) firstID=stack[numLevels].ID|1;
|
||||
stack[numLevels].length = ReadInt();
|
||||
stack[numLevels].startLocation = pos;
|
||||
|
||||
if (stack[numLevels].ID == id)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
SeekTo(pos + stack[numLevels].length); //try next block
|
||||
}
|
||||
}
|
||||
|
||||
//if we found nothing, return false so the caller can skip this
|
||||
if (!found)
|
||||
{
|
||||
/*
|
||||
pos = startPos;
|
||||
char temp1[5]; TCHAR temp2[5];
|
||||
temp1[4]=0; temp2[4]=0;
|
||||
*(int *)temp1 =id;
|
||||
TCHAR tempx[256];
|
||||
|
||||
for (int i=0; i<4; i++)
|
||||
temp2[i]=temp1[i];
|
||||
|
||||
_stprintf(tempx,TEXT("Couldn't find chunk \"%s\" in file"),temp2);
|
||||
|
||||
MessageBox(theApp->getHWND(),tempx,0,0);
|
||||
*/
|
||||
stack[numLevels]=temp;
|
||||
SeekTo(stack[numLevels].parentStartLocation);
|
||||
return false;
|
||||
}
|
||||
|
||||
//descend into it
|
||||
//pos was set inside the loop above
|
||||
eof = stack[numLevels].startLocation + stack[numLevels].length;
|
||||
numLevels++;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//write a chunk id, and prepare for filling in length later
|
||||
WriteInt(id);
|
||||
WriteInt(0); //will be filled in by Ascend
|
||||
stack[numLevels].startLocation=pos;
|
||||
numLevels++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void ChunkFile::SeekTo(int _pos)
|
||||
{
|
||||
if (!fastMode)
|
||||
file.SeekBeg(_pos);
|
||||
pos=_pos;
|
||||
}
|
||||
|
||||
//let's Ascend out
|
||||
void ChunkFile::Ascend()
|
||||
{
|
||||
if (read)
|
||||
{
|
||||
//Ascend, and restore information
|
||||
numLevels--;
|
||||
SeekTo(stack[numLevels].parentStartLocation);
|
||||
eof = stack[numLevels].parentEOF;
|
||||
}
|
||||
else
|
||||
{
|
||||
numLevels--;
|
||||
//now fill in the written length automatically
|
||||
int posNow = pos;
|
||||
SeekTo(stack[numLevels].startLocation - 4);
|
||||
WriteInt(posNow-stack[numLevels].startLocation);
|
||||
SeekTo(posNow);
|
||||
}
|
||||
}
|
||||
|
||||
//read a block
|
||||
void ChunkFile::ReadData(void *what, int count)
|
||||
{
|
||||
|
||||
if (fastMode)
|
||||
memcpy(what,data+pos,count);
|
||||
else
|
||||
file.Read(what,count);
|
||||
|
||||
pos+=count;
|
||||
char temp[4]; //discarded
|
||||
count &= 3;
|
||||
if (count)
|
||||
{
|
||||
count=4-count;
|
||||
if (!fastMode)
|
||||
file.Read(temp,count);
|
||||
pos+=count;
|
||||
}
|
||||
}
|
||||
|
||||
//write a block
|
||||
void ChunkFile::WriteData(void *what, int count)
|
||||
{
|
||||
/*
|
||||
memcpy(data+pos,what,count);
|
||||
pos += count;
|
||||
*/
|
||||
file.Write(what,count);
|
||||
pos+=count;
|
||||
char temp[5]={0,0,0,0,0};
|
||||
count &= 3;
|
||||
if (count)
|
||||
{
|
||||
count=4-count;
|
||||
file.Write(temp,count);
|
||||
pos+=count;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void ChunkFile::WriteString(String str)
|
||||
{
|
||||
wchar_t *text;
|
||||
int len=str.length();
|
||||
#ifdef UNICODE
|
||||
text = str.getPointer();
|
||||
#else
|
||||
text=new wchar_t[len+1];
|
||||
str.toUnicode(text);
|
||||
#endif
|
||||
WriteInt(len);
|
||||
WriteData((char *)text,len*sizeof(wchar_t));
|
||||
#ifndef UNICODE
|
||||
delete [] text;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
String ChunkFile::readString()
|
||||
{
|
||||
int len=ReadInt();
|
||||
wchar_t *text = new wchar_t[len+1];
|
||||
ReadData((char *)text,len*sizeof(wchar_t));
|
||||
text[len]=0;
|
||||
#ifdef UNICODE
|
||||
String s(text);
|
||||
delete [] text;
|
||||
return s;
|
||||
#else
|
||||
String temp;
|
||||
temp.fromUnicode(text);
|
||||
delete [] text;
|
||||
return temp;
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
int ChunkFile::GetCurrentChunkSize()
|
||||
{
|
||||
if (numLevels)
|
||||
return stack[numLevels-1].length;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
59
Source/Plugins/Plugin_VideoDX9/Src/W32Util/ChunkFile.h
Normal file
59
Source/Plugins/Plugin_VideoDX9/Src/W32Util/ChunkFile.h
Normal file
@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
//TO REMEMBER WHEN USING:
|
||||
|
||||
//EITHER a chunk contains ONLY data
|
||||
//OR it contains ONLY other chunks
|
||||
//otherwise the scheme breaks...
|
||||
#include "File.h"
|
||||
|
||||
namespace W32Util
|
||||
{
|
||||
inline unsigned int flipID(unsigned int id)
|
||||
{
|
||||
return ((id>>24)&0xFF) | ((id>>8)&0xFF00) | ((id<<8)&0xFF0000) | ((id<<24)&0xFF000000);
|
||||
}
|
||||
|
||||
class ChunkFile
|
||||
{
|
||||
File file;
|
||||
struct ChunkInfo
|
||||
{
|
||||
int startLocation;
|
||||
int parentStartLocation;
|
||||
int parentEOF;
|
||||
unsigned int ID;
|
||||
int length;
|
||||
};
|
||||
ChunkInfo stack[8];
|
||||
int numLevels;
|
||||
|
||||
char *data;
|
||||
int pos,eof;
|
||||
bool fastMode;
|
||||
bool read;
|
||||
bool didFail;
|
||||
|
||||
void SeekTo(int _pos);
|
||||
int GetPos() {return pos;}
|
||||
public:
|
||||
ChunkFile(const TCHAR *filename, bool _read);
|
||||
~ChunkFile();
|
||||
|
||||
bool Descend(unsigned int id);
|
||||
void Ascend();
|
||||
|
||||
int ReadInt();
|
||||
void ReadInt(int &i) {i = ReadInt();}
|
||||
void ReadData(void *data, int count);
|
||||
// String ReadString();
|
||||
|
||||
void WriteInt(int i);
|
||||
//void WriteString(String str);
|
||||
void WriteData(void *data, int count);
|
||||
|
||||
int GetCurrentChunkSize();
|
||||
bool Failed() {return didFail;}
|
||||
};
|
||||
|
||||
}
|
29
Source/Plugins/Plugin_VideoDX9/Src/W32Util/DialogManager.cpp
Normal file
29
Source/Plugins/Plugin_VideoDX9/Src/W32Util/DialogManager.cpp
Normal file
@ -0,0 +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);
|
||||
}
|
12
Source/Plugins/Plugin_VideoDX9/Src/W32Util/DialogManager.h
Normal file
12
Source/Plugins/Plugin_VideoDX9/Src/W32Util/DialogManager.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
class DialogManager
|
||||
{
|
||||
public:
|
||||
static void AddDlg(HWND hDialog);
|
||||
static bool IsDialogMessage(LPMSG message);
|
||||
static void EnableAll(BOOL enable);
|
||||
};
|
||||
|
148
Source/Plugins/Plugin_VideoDX9/Src/W32Util/File.cpp
Normal file
148
Source/Plugins/Plugin_VideoDX9/Src/W32Util/File.cpp
Normal file
@ -0,0 +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));
|
||||
}
|
||||
}
|
61
Source/Plugins/Plugin_VideoDX9/Src/W32Util/File.h
Normal file
61
Source/Plugins/Plugin_VideoDX9/Src/W32Util/File.h
Normal file
@ -0,0 +1,61 @@
|
||||
#ifndef __LAMEFILE_H__
|
||||
#define __LAMEFILE_H__
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
#include <windows.h>
|
||||
|
||||
namespace W32Util
|
||||
{
|
||||
|
||||
enum eFileMode
|
||||
{
|
||||
FILE_READ=5,
|
||||
FILE_WRITE=6,
|
||||
FILE_ERROR=0xff
|
||||
};
|
||||
|
||||
class File
|
||||
{
|
||||
HANDLE fileHandle;
|
||||
eFileMode mode;
|
||||
bool isOpen;
|
||||
public:
|
||||
File();
|
||||
virtual ~File();
|
||||
|
||||
bool Open(const TCHAR *filename, eFileMode mode);
|
||||
void Adopt(HANDLE h) { fileHandle = h;}
|
||||
void Close();
|
||||
|
||||
void WriteInt(int i);
|
||||
void WriteChar(char i);
|
||||
int Write(void *data, int size);
|
||||
|
||||
|
||||
int ReadInt();
|
||||
char ReadChar();
|
||||
int Read(void *data, int size);
|
||||
|
||||
int WR(void *data, int size); //write or read depending on open mode
|
||||
bool MagicCookie(int cookie);
|
||||
|
||||
int GetSize();
|
||||
eFileMode GetMode() {return mode;}
|
||||
void SeekBeg(int pos)
|
||||
{
|
||||
if (isOpen) SetFilePointer(fileHandle,pos,0,FILE_BEGIN);
|
||||
}
|
||||
void SeekEnd(int pos)
|
||||
{
|
||||
if (isOpen) SetFilePointer(fileHandle,pos,0,FILE_END);
|
||||
}
|
||||
void SeekCurrent(int pos)
|
||||
{
|
||||
if (isOpen) SetFilePointer(fileHandle,pos,0,FILE_CURRENT);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif //__LAMEFILE_H__
|
102
Source/Plugins/Plugin_VideoDX9/Src/W32Util/Misc.cpp
Normal file
102
Source/Plugins/Plugin_VideoDX9/Src/W32Util/Misc.cpp
Normal file
@ -0,0 +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;
|
||||
}
|
||||
}
|
9
Source/Plugins/Plugin_VideoDX9/Src/W32Util/Misc.h
Normal file
9
Source/Plugins/Plugin_VideoDX9/Src/W32Util/Misc.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
namespace W32Util
|
||||
{
|
||||
void CenterWindow(HWND hwnd);
|
||||
HBITMAP CreateBitmapFromARGB(HWND someHwnd, DWORD *image, int w, int h);
|
||||
void NiceSizeFormat(size_t size, char *out);
|
||||
BOOL CopyTextToClipboard(HWND hwnd, TCHAR *text);
|
||||
}
|
225
Source/Plugins/Plugin_VideoDX9/Src/W32Util/PropertySheet.cpp
Normal file
225
Source/Plugins/Plugin_VideoDX9/Src/W32Util/PropertySheet.cpp
Normal file
@ -0,0 +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;
|
||||
}
|
||||
}
|
86
Source/Plugins/Plugin_VideoDX9/Src/W32Util/PropertySheet.h
Normal file
86
Source/Plugins/Plugin_VideoDX9/Src/W32Util/PropertySheet.h
Normal file
@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace W32Util
|
||||
{
|
||||
class PropSheet;
|
||||
|
||||
class Tab
|
||||
{
|
||||
public:
|
||||
PropSheet *sheet; //back pointer ..
|
||||
virtual void Init(HWND hDlg) {}
|
||||
virtual void Command(HWND hDlg, WPARAM wParam) {}
|
||||
virtual void Apply(HWND hDlg) {}
|
||||
virtual bool HasPrev() {return true;}
|
||||
virtual bool HasFinish() {return false;}
|
||||
virtual bool HasNext() {return true;}
|
||||
static INT_PTR __stdcall TabDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
};
|
||||
|
||||
|
||||
class WizExteriorPage : public Tab
|
||||
{
|
||||
INT captionID;
|
||||
public:
|
||||
WizExteriorPage(INT caption) {captionID = caption;}
|
||||
void Init(HWND hDlg);
|
||||
};
|
||||
|
||||
|
||||
class WizFirstPage : public WizExteriorPage
|
||||
{
|
||||
public:
|
||||
WizFirstPage(INT caption) : WizExteriorPage(caption) {}
|
||||
bool HasPrev() {return false;}
|
||||
};
|
||||
|
||||
|
||||
class WizLastPage : public WizExteriorPage
|
||||
{
|
||||
public:
|
||||
WizLastPage(INT caption) : WizExteriorPage(caption) {}
|
||||
bool HasNext() {return false;}
|
||||
bool HasFinish() {return true;}
|
||||
};
|
||||
|
||||
|
||||
class WizInteriorPage : public Tab
|
||||
{
|
||||
public:
|
||||
};
|
||||
|
||||
class PropSheet
|
||||
{
|
||||
LPCTSTR watermark;
|
||||
LPCTSTR header;
|
||||
HFONT hTitleFont;
|
||||
HFONT hDialogFont;
|
||||
HICON icon;
|
||||
struct Page
|
||||
{
|
||||
Page(Tab *_tab, LPCTSTR _resource, LPCTSTR _title, LPCTSTR _subtitle = 0)
|
||||
: tab(_tab), resource(_resource), title(_title), hdrSubTitle(_subtitle) {}
|
||||
Tab *tab;
|
||||
LPCTSTR resource;
|
||||
LPCTSTR title;
|
||||
LPCTSTR hdrSubTitle;
|
||||
};
|
||||
public:
|
||||
PropSheet();
|
||||
typedef std::vector<Page> DlgList;
|
||||
DlgList list;
|
||||
void SetWaterMark(LPCTSTR _watermark) {watermark=_watermark;}
|
||||
void SetHeader(LPCTSTR _header) {header=_header;}
|
||||
void SetIcon(HICON _icon) {icon = _icon;}
|
||||
void Add(Tab *tab, LPCTSTR resource, LPCTSTR title, LPCTSTR subtitle = 0);
|
||||
void Show(HINSTANCE hInstance, HWND hParent, std::string title, int startpage=0, bool floating = false, bool wizard = false);
|
||||
HFONT GetTitleFont() {return hTitleFont;}
|
||||
HFONT GetFont() {return hDialogFont;}
|
||||
static int CALLBACK Callback(HWND hwndDlg, UINT uMsg, LPARAM lParam);
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
125
Source/Plugins/Plugin_VideoDX9/Src/W32Util/ShellUtil.cpp
Normal file
125
Source/Plugins/Plugin_VideoDX9/Src/W32Util/ShellUtil.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
#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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
15
Source/Plugins/Plugin_VideoDX9/Src/W32Util/ShellUtil.h
Normal file
15
Source/Plugins/Plugin_VideoDX9/Src/W32Util/ShellUtil.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <xstring>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace W32Util
|
||||
{
|
||||
std::string BrowseForFolder(HWND parent, char *title);
|
||||
bool BrowseForFileName (bool _bLoad, HWND _hParent, const char *_pTitle,
|
||||
const char *_pInitialFolder,const char *_pFilter,const char *_pExtension,
|
||||
std::string& _strFileName);
|
||||
std::vector<std::string> BrowseForFileNameMultiSelect(bool _bLoad, HWND _hParent, const char *_pTitle,
|
||||
const char *_pInitialFolder,const char *_pFilter,const char *_pExtension);
|
||||
}
|
94
Source/Plugins/Plugin_VideoDX9/Src/W32Util/TabControl.cpp
Normal file
94
Source/Plugins/Plugin_VideoDX9/Src/W32Util/TabControl.cpp
Normal file
@ -0,0 +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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
36
Source/Plugins/Plugin_VideoDX9/Src/W32Util/TabControl.h
Normal file
36
Source/Plugins/Plugin_VideoDX9/Src/W32Util/TabControl.h
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
namespace W32Util
|
||||
{
|
||||
#define MAX_WIN_DIALOGS 32
|
||||
|
||||
|
||||
class TabControl
|
||||
{
|
||||
private:
|
||||
|
||||
HINSTANCE m_hInstance;
|
||||
HWND m_hWndParent;
|
||||
HWND m_hTabCtrl;
|
||||
|
||||
HWND m_WinDialogs[MAX_WIN_DIALOGS];
|
||||
int m_numDialogs;
|
||||
|
||||
public:
|
||||
|
||||
TabControl(HINSTANCE _hInstance, HWND _hTabCtrl,DLGPROC _lpDialogFunc);
|
||||
|
||||
~TabControl(void);
|
||||
|
||||
//
|
||||
// --- tools ---
|
||||
//
|
||||
|
||||
HWND AddItem (char* _szText,int _iResource,DLGPROC _lpDialogFunc);
|
||||
|
||||
void SelectDialog (int _nDialogId);
|
||||
|
||||
void MessageHandler(UINT message, WPARAM wParam, LPARAM lParam);
|
||||
};
|
||||
|
||||
}
|
82
Source/Plugins/Plugin_VideoDX9/Src/W32Util/Thread.cpp
Normal file
82
Source/Plugins/Plugin_VideoDX9/Src/W32Util/Thread.cpp
Normal file
@ -0,0 +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);
|
||||
}
|
||||
}
|
36
Source/Plugins/Plugin_VideoDX9/Src/W32Util/Thread.h
Normal file
36
Source/Plugins/Plugin_VideoDX9/Src/W32Util/Thread.h
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
namespace W32Util
|
||||
{
|
||||
class Thread
|
||||
{
|
||||
private:
|
||||
HANDLE _handle;
|
||||
DWORD _tid; // thread id
|
||||
|
||||
public:
|
||||
Thread ( DWORD (WINAPI * pFun) (void* arg), void* pArg);
|
||||
~Thread () ;
|
||||
|
||||
//
|
||||
// --- tools ---
|
||||
//
|
||||
|
||||
void Resume(void);
|
||||
|
||||
void Suspend(void);
|
||||
|
||||
void WaitForDeath(void);
|
||||
|
||||
void Terminate(void);
|
||||
|
||||
void SetPriority(int _nPriority);
|
||||
|
||||
bool IsActive (void);
|
||||
|
||||
HANDLE GetHandle(void) {return _handle;}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
625
Source/Plugins/Plugin_VideoDX9/Src/W32Util/XPTheme.h
Normal file
625
Source/Plugins/Plugin_VideoDX9/Src/W32Util/XPTheme.h
Normal file
@ -0,0 +1,625 @@
|
||||
// Windows Template Library - WTL version 7.0
|
||||
// Copyright (C) 1997-2002 Microsoft Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// This file is a part of the Windows Template Library.
|
||||
// The code and information is provided "as-is" without
|
||||
// warranty of any kind, either expressed or implied.
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tchar.h>
|
||||
//#include <tmschema.h>
|
||||
#include <uxtheme.h>
|
||||
#pragma comment(lib, "uxtheme.lib")
|
||||
|
||||
// Note: To create an application that also runs on older versions of Windows,
|
||||
// use delay load of uxtheme.dll and ensure that no calls to the Theme API are
|
||||
// made if theming is not supported. It is enough to check if m_hTheme is NULL.
|
||||
// Example:
|
||||
// if(m_hTheme != NULL)
|
||||
// {
|
||||
// DrawThemeBackground(dc, BP_PUSHBUTTON, PBS_NORMAL, &rect, NULL);
|
||||
// DrawThemeText(dc, BP_PUSHBUTTON, PBS_NORMAL, L"Button", -1, DT_SINGLELINE | DT_CENTER | DT_VCENTER, 0, &rect);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// dc.DrawFrameControl(&rect, DFC_BUTTON, DFCS_BUTTONPUSH);
|
||||
// dc.DrawText(_T("Button"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
|
||||
// }
|
||||
//
|
||||
// Delay load is NOT AUTOMATIC for VC++ 7, you have to link to delayimp.lib,
|
||||
// and add uxtheme.dll in the Linker.Input.Delay Loaded DLLs section of the
|
||||
// project properties.
|
||||
#if (_MSC_VER < 1300) && !defined(_WTL_NO_THEME_DELAYLOAD)
|
||||
#pragma comment(lib, "delayimp.lib")
|
||||
#pragma comment(linker, "/delayload:uxtheme.dll")
|
||||
#endif //(_MSC_VER < 1300) && !defined(_WTL_NO_THEME_DELAYLOAD)
|
||||
|
||||
|
||||
// Classes in this file
|
||||
//
|
||||
// CTheme
|
||||
// CThemeImpl<T, TBase>
|
||||
|
||||
|
||||
namespace WTL
|
||||
{
|
||||
|
||||
// CTheme - wrapper for theme handle
|
||||
|
||||
class CTheme
|
||||
{
|
||||
public:
|
||||
// Data members
|
||||
HTHEME m_hTheme;
|
||||
static int m_nIsThemingSupported;
|
||||
|
||||
// Constructor
|
||||
CTheme() : m_hTheme(NULL)
|
||||
{
|
||||
IsThemingSupported();
|
||||
}
|
||||
|
||||
// Operators and helpers
|
||||
bool IsThemeNull() const
|
||||
{
|
||||
return (m_hTheme == NULL);
|
||||
}
|
||||
|
||||
CTheme& operator =(HTHEME hTheme)
|
||||
{
|
||||
m_hTheme = hTheme;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator HTHEME() const
|
||||
{
|
||||
return m_hTheme;
|
||||
}
|
||||
|
||||
void Attach(HTHEME hTheme)
|
||||
{
|
||||
m_hTheme = hTheme;
|
||||
}
|
||||
|
||||
HTHEME Detach()
|
||||
{
|
||||
HTHEME hTheme = m_hTheme;
|
||||
m_hTheme = NULL;
|
||||
return hTheme;
|
||||
}
|
||||
|
||||
// Theme support helper
|
||||
static bool IsThemingSupported()
|
||||
{
|
||||
if(m_nIsThemingSupported == -1)
|
||||
{
|
||||
// ::EnterCriticalSection(&_Module.m_csStaticDataInit);
|
||||
if(m_nIsThemingSupported == -1)
|
||||
{
|
||||
HMODULE hThemeDLL = ::LoadLibrary(_T("uxtheme.dll"));
|
||||
m_nIsThemingSupported = (hThemeDLL != NULL) ? 1 : 0;
|
||||
if(hThemeDLL != NULL)
|
||||
::FreeLibrary(hThemeDLL);
|
||||
}
|
||||
// ::LeaveCriticalSection(&_Module.m_csStaticDataInit);
|
||||
}
|
||||
|
||||
//ATLASSERT(m_nIsThemingSupported != -1);
|
||||
return (m_nIsThemingSupported == 1);
|
||||
}
|
||||
|
||||
// Operations and theme properties
|
||||
HTHEME OpenThemeData(HWND hWnd, LPCWSTR pszClassList)
|
||||
{
|
||||
if(!IsThemingSupported())
|
||||
return NULL;
|
||||
|
||||
//ATLASSERT(m_hTheme == NULL);
|
||||
m_hTheme = ::OpenThemeData(hWnd, pszClassList);
|
||||
return m_hTheme;
|
||||
}
|
||||
|
||||
HRESULT CloseThemeData()
|
||||
{
|
||||
HRESULT hRet = S_FALSE;
|
||||
if(m_hTheme != NULL)
|
||||
{
|
||||
hRet = ::CloseThemeData(m_hTheme);
|
||||
if(SUCCEEDED(hRet))
|
||||
m_hTheme = NULL;
|
||||
}
|
||||
return hRet;
|
||||
}
|
||||
|
||||
HRESULT DrawThemeBackground(HDC hDC, int nPartID, int nStateID, LPCRECT pRect, LPCRECT pClipRect = NULL)
|
||||
{
|
||||
return ::DrawThemeBackground(m_hTheme, hDC, nPartID, nStateID, pRect, pClipRect);
|
||||
}
|
||||
|
||||
HRESULT DrawThemeText(HDC hDC, int nPartID, int nStateID, LPCWSTR pszText, int nCharCount, DWORD dwTextFlags, DWORD dwTextFlags2, LPCRECT pRect)
|
||||
{
|
||||
return ::DrawThemeText(m_hTheme, hDC, nPartID, nStateID, pszText, nCharCount, dwTextFlags, dwTextFlags2, pRect);
|
||||
}
|
||||
|
||||
HRESULT GetThemeBackgroundContentRect(HDC hDC, int nPartID, int nStateID, LPCRECT pBoundingRect, LPRECT pContentRect) const
|
||||
{
|
||||
return ::GetThemeBackgroundContentRect(m_hTheme, hDC, nPartID, nStateID, pBoundingRect, pContentRect);
|
||||
}
|
||||
|
||||
HRESULT GetThemeBackgroundExtent(HDC hDC, int nPartID, int nStateID, LPCRECT pContentRect, LPRECT pExtentRect) const
|
||||
{
|
||||
return ::GetThemeBackgroundExtent(m_hTheme, hDC, nPartID, nStateID, pContentRect, pExtentRect);
|
||||
}
|
||||
|
||||
HRESULT GetThemePartSize(HDC hDC, int nPartID, int nStateID, LPRECT pRect, enum THEMESIZE eSize, LPSIZE pSize) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemePartSize(m_hTheme, hDC, nPartID, nStateID, pRect, eSize, pSize);
|
||||
}
|
||||
|
||||
HRESULT GetThemeTextExtent(HDC hDC, int nPartID, int nStateID, LPCWSTR pszText, int nCharCount, DWORD dwTextFlags, LPCRECT pBoundingRect, LPRECT pExtentRect) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeTextExtent(m_hTheme, hDC, nPartID, nStateID, pszText, nCharCount, dwTextFlags, pBoundingRect, pExtentRect);
|
||||
}
|
||||
|
||||
HRESULT GetThemeTextMetrics(HDC hDC, int nPartID, int nStateID, PTEXTMETRIC pTextMetric) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeTextMetrics(m_hTheme, hDC, nPartID, nStateID, pTextMetric);
|
||||
}
|
||||
|
||||
HRESULT GetThemeBackgroundRegion(HDC hDC, int nPartID, int nStateID, LPCRECT pRect, HRGN* pRegion) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeBackgroundRegion(m_hTheme, hDC, nPartID, nStateID, pRect, pRegion);
|
||||
}
|
||||
|
||||
HRESULT HitTestThemeBackground(HDC hDC, int nPartID, int nStateID, DWORD dwOptions, LPCRECT pRect, HRGN hrgn, POINT ptTest, WORD* pwHitTestCode) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::HitTestThemeBackground(m_hTheme, hDC, nPartID, nStateID, dwOptions, pRect, hrgn, ptTest, pwHitTestCode);
|
||||
}
|
||||
|
||||
HRESULT DrawThemeEdge(HDC hDC, int nPartID, int nStateID, LPCRECT pDestRect, UINT uEdge, UINT uFlags, LPRECT pContentRect = NULL)
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::DrawThemeEdge(m_hTheme, hDC, nPartID, nStateID, pDestRect, uEdge, uFlags, pContentRect);
|
||||
}
|
||||
|
||||
HRESULT DrawThemeIcon(HDC hDC, int nPartID, int nStateID, LPCRECT pRect, HIMAGELIST himl, int nImageIndex)
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::DrawThemeIcon(m_hTheme, hDC, nPartID, nStateID, pRect, himl, nImageIndex);
|
||||
}
|
||||
|
||||
BOOL IsThemePartDefined(int nPartID, int nStateID) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::IsThemePartDefined(m_hTheme, nPartID, nStateID);
|
||||
}
|
||||
|
||||
BOOL IsThemeBackgroundPartiallyTransparent(int nPartID, int nStateID) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::IsThemeBackgroundPartiallyTransparent(m_hTheme, nPartID, nStateID);
|
||||
}
|
||||
|
||||
HRESULT GetThemeColor(int nPartID, int nStateID, int nPropID, COLORREF* pColor) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeColor(m_hTheme, nPartID, nStateID, nPropID, pColor);
|
||||
}
|
||||
|
||||
HRESULT GetThemeMetric(HDC hDC, int nPartID, int nStateID, int nPropID, int* pnVal) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeMetric(m_hTheme, hDC, nPartID, nStateID, nPropID, pnVal);
|
||||
}
|
||||
|
||||
HRESULT GetThemeString(int nPartID, int nStateID, int nPropID, LPWSTR pszBuff, int cchMaxBuffChars) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeString(m_hTheme, nPartID, nStateID, nPropID, pszBuff, cchMaxBuffChars);
|
||||
}
|
||||
|
||||
HRESULT GetThemeBool(int nPartID, int nStateID, int nPropID, BOOL* pfVal) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeBool(m_hTheme, nPartID, nStateID, nPropID, pfVal);
|
||||
}
|
||||
|
||||
HRESULT GetThemeInt(int nPartID, int nStateID, int nPropID, int* pnVal) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeInt(m_hTheme, nPartID, nStateID, nPropID, pnVal);
|
||||
}
|
||||
|
||||
HRESULT GetThemeEnumValue(int nPartID, int nStateID, int nPropID, int* pnVal) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeEnumValue(m_hTheme, nPartID, nStateID, nPropID, pnVal);
|
||||
}
|
||||
|
||||
HRESULT GetThemePosition(int nPartID, int nStateID, int nPropID, LPPOINT pPoint) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemePosition(m_hTheme, nPartID, nStateID, nPropID, pPoint);
|
||||
}
|
||||
|
||||
HRESULT GetThemeFont(int nPartID, HDC hDC, int nStateID, int nPropID, LOGFONT* pFont) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeFont(m_hTheme, hDC, nPartID, nStateID, nPropID, pFont);
|
||||
}
|
||||
|
||||
HRESULT GetThemeRect(int nPartID, int nStateID, int nPropID, LPRECT pRect) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeRect(m_hTheme, nPartID, nStateID, nPropID, pRect);
|
||||
}
|
||||
|
||||
HRESULT GetThemeMargins(HDC hDC, int nPartID, int nStateID, int nPropID, LPRECT pRect, PMARGINS pMargins) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeMargins(m_hTheme, hDC, nPartID, nStateID, nPropID, pRect, pMargins);
|
||||
}
|
||||
|
||||
HRESULT GetThemeIntList(int nPartID, int nStateID, int nPropID, INTLIST* pIntList) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeIntList(m_hTheme, nPartID, nStateID, nPropID, pIntList);
|
||||
}
|
||||
|
||||
HRESULT GetThemePropertyOrigin(int nPartID, int nStateID, int nPropID, enum PROPERTYORIGIN* pOrigin) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemePropertyOrigin(m_hTheme, nPartID, nStateID, nPropID, pOrigin);
|
||||
}
|
||||
|
||||
HRESULT GetThemeFilename(int nPartID, int nStateID, int nPropID, LPWSTR pszThemeFileName, int cchMaxBuffChars) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeFilename(m_hTheme, nPartID, nStateID, nPropID, pszThemeFileName, cchMaxBuffChars);
|
||||
}
|
||||
|
||||
COLORREF GetThemeSysColor(int nColorID) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeSysColor(m_hTheme, nColorID);
|
||||
}
|
||||
|
||||
HBRUSH GetThemeSysColorBrush(int nColorID) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeSysColorBrush(m_hTheme, nColorID);
|
||||
}
|
||||
|
||||
int GetThemeSysSize(int nSizeID) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeSysSize(m_hTheme, nSizeID);
|
||||
}
|
||||
|
||||
BOOL GetThemeSysBool(int nBoolID) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeSysBool(m_hTheme, nBoolID);
|
||||
}
|
||||
|
||||
HRESULT GetThemeSysFont(int nFontID, LOGFONT* plf) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeSysFont(m_hTheme, nFontID, plf);
|
||||
}
|
||||
|
||||
HRESULT GetThemeSysString(int nStringID, LPWSTR pszStringBuff, int cchMaxStringChars) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeSysString(m_hTheme, nStringID, pszStringBuff, cchMaxStringChars);
|
||||
}
|
||||
|
||||
HRESULT GetThemeSysInt(int nIntID, int* pnValue) const
|
||||
{
|
||||
//ATLASSERT(m_hTheme != NULL);
|
||||
return ::GetThemeSysInt(m_hTheme, nIntID, pnValue);
|
||||
}
|
||||
};
|
||||
|
||||
__declspec(selectany) int CTheme::m_nIsThemingSupported = -1;
|
||||
|
||||
|
||||
// CThemeImpl - theme support implementation
|
||||
|
||||
// Derive from this class to implement window with theme support.
|
||||
// Example:
|
||||
// class CMyThemeWindow : public CWindowImpl<CMyThemeWindow>, public CThemeImpl<CMyThemeWindow>
|
||||
// {
|
||||
// ...
|
||||
// BEGIN_MSG_MAP(CMyThemeWindow)
|
||||
// CHAIN_MSG_MAP(CThemeImpl<CMyThemeWindow>)
|
||||
// ...
|
||||
// END_MSG_MAP()
|
||||
// ...
|
||||
// };
|
||||
//
|
||||
// If you set theme class list, the class will automaticaly open/close/reopen theme data.
|
||||
|
||||
|
||||
// Helper for drawing theme client edge
|
||||
#if 0
|
||||
inline bool AtlDrawThemeClientEdge(HTHEME hTheme, HWND hWnd, HRGN hRgnUpdate = NULL, HBRUSH hBrush = NULL, int nPartID = 0, int nStateID = 0)
|
||||
{
|
||||
//ATLASSERT(hTheme != NULL);
|
||||
//ATLASSERT(::IsWindow(hWnd));
|
||||
|
||||
CWindowDC dc(hWnd);
|
||||
if(dc.IsNull())
|
||||
return false;
|
||||
|
||||
// Get border size
|
||||
int cxBorder = GetSystemMetrics(SM_CXBORDER);
|
||||
int cyBorder = GetSystemMetrics(SM_CYBORDER);
|
||||
if(SUCCEEDED(::GetThemeInt(hTheme, nPartID, nStateID, TMT_SIZINGBORDERWIDTH, &cxBorder)))
|
||||
cyBorder = cxBorder;
|
||||
|
||||
RECT rect;
|
||||
::GetWindowRect(hWnd, &rect);
|
||||
|
||||
// Remove the client edge from the update region
|
||||
int cxEdge = GetSystemMetrics(SM_CXEDGE);
|
||||
int cyEdge = GetSystemMetrics(SM_CYEDGE);
|
||||
::InflateRect(&rect, -cxEdge, -cyEdge);
|
||||
CRgn rgn;
|
||||
rgn.CreateRectRgnIndirect(&rect);
|
||||
if(rgn.IsNull())
|
||||
return false;
|
||||
|
||||
if(hRgnUpdate != NULL)
|
||||
rgn.CombineRgn(hRgnUpdate, rgn, RGN_AND);
|
||||
|
||||
::OffsetRect(&rect, -rect.left, -rect.top);
|
||||
|
||||
::OffsetRect(&rect, cxEdge, cyEdge);
|
||||
dc.ExcludeClipRect(&rect);
|
||||
::InflateRect(&rect, cxEdge, cyEdge);
|
||||
|
||||
::DrawThemeBackground(hTheme, dc, nPartID, nStateID, &rect, NULL);
|
||||
|
||||
// Use background brush too, since theme border might not cover everything
|
||||
if(cxBorder < cxEdge && cyBorder < cyEdge)
|
||||
{
|
||||
if(hBrush == NULL)
|
||||
// need conditional code because types don't match in winuser.h
|
||||
#ifdef _WIN64
|
||||
hBrush = (HBRUSH)::GetClassLongPtr(hWnd, GCLP_HBRBACKGROUND);
|
||||
#else
|
||||
hBrush = (HBRUSH)UlongToPtr(::GetClassLongPtr(hWnd, GCLP_HBRBACKGROUND));
|
||||
#endif
|
||||
|
||||
::InflateRect(&rect, cxBorder - cxEdge, cyBorder - cyEdge);
|
||||
dc.FillRect(&rect, hBrush);
|
||||
}
|
||||
|
||||
::DefWindowProc(hWnd, WM_NCPAINT, (WPARAM)rgn.m_hRgn, 0L);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Theme extended styles
|
||||
#define THEME_EX_3DCLIENTEDGE 0x00000001
|
||||
#define THEME_EX_THEMECLIENTEDGE 0x00000002
|
||||
|
||||
template <class T, class TBase = CTheme>
|
||||
class CThemeImpl : public TBase
|
||||
{
|
||||
public:
|
||||
// Data members
|
||||
LPWSTR m_lpstrThemeClassList;
|
||||
DWORD m_dwExtendedStyle; // theme specific extended styles
|
||||
|
||||
// Constructor & destructor
|
||||
CThemeImpl() : m_lpstrThemeClassList(NULL), m_dwExtendedStyle(0)
|
||||
{ }
|
||||
|
||||
~CThemeImpl()
|
||||
{
|
||||
delete m_lpstrThemeClassList;
|
||||
}
|
||||
|
||||
// Attributes
|
||||
bool SetThemeClassList(LPCWSTR lpstrThemeClassList)
|
||||
{
|
||||
if(m_lpstrThemeClassList != NULL)
|
||||
{
|
||||
delete m_lpstrThemeClassList;
|
||||
m_lpstrThemeClassList = NULL;
|
||||
}
|
||||
|
||||
if(lpstrThemeClassList == NULL)
|
||||
return true;
|
||||
|
||||
int cchLen = lstrlenW(lpstrThemeClassList) + 1;
|
||||
ATLTRY(m_lpstrThemeClassList = new WCHAR[cchLen]);
|
||||
if(m_lpstrThemeClassList == NULL)
|
||||
return false;
|
||||
|
||||
bool bRet = (lstrcpyW(m_lpstrThemeClassList, lpstrThemeClassList) != NULL);
|
||||
if(!bRet)
|
||||
{
|
||||
delete m_lpstrThemeClassList;
|
||||
m_lpstrThemeClassList = NULL;
|
||||
}
|
||||
return bRet;
|
||||
}
|
||||
|
||||
bool GetThemeClassList(LPWSTR lpstrThemeClassList, int cchListBuffer) const
|
||||
{
|
||||
int cchLen = lstrlenW(m_lpstrThemeClassList) + 1;
|
||||
if(cchListBuffer < cchLen)
|
||||
return false;
|
||||
|
||||
return (lstrcpyW(lpstrThemeClassList, m_lpstrThemeClassList) != NULL);
|
||||
}
|
||||
|
||||
LPCWSTR GetThemeClassList() const
|
||||
{
|
||||
return m_lpstrThemeClassList;
|
||||
}
|
||||
|
||||
DWORD SetThemeExtendedStyle(DWORD dwExtendedStyle, DWORD dwMask = 0)
|
||||
{
|
||||
DWORD dwPrevStyle = m_dwExtendedStyle;
|
||||
if(dwMask == 0)
|
||||
m_dwExtendedStyle = dwExtendedStyle;
|
||||
else
|
||||
m_dwExtendedStyle = (m_dwExtendedStyle & ~dwMask) | (dwExtendedStyle & dwMask);
|
||||
return dwPrevStyle;
|
||||
}
|
||||
|
||||
DWORD GetThemeExtendedStyle() const
|
||||
{
|
||||
return m_dwExtendedStyle;
|
||||
}
|
||||
|
||||
// Operations
|
||||
HTHEME OpenThemeData()
|
||||
{
|
||||
T* pT = static_cast<T*>(this);
|
||||
//ATLASSERT(::IsWindow(pT->m_hWnd));
|
||||
//ATLASSERT(m_lpstrThemeClassList != NULL);
|
||||
if(m_lpstrThemeClassList == NULL)
|
||||
return NULL;
|
||||
CloseThemeData();
|
||||
return TBase::OpenThemeData(pT->m_hWnd, m_lpstrThemeClassList);
|
||||
}
|
||||
|
||||
HTHEME OpenThemeData(LPCWSTR pszClassList)
|
||||
{
|
||||
if(!SetThemeClassList(pszClassList))
|
||||
return NULL;
|
||||
return OpenThemeData();
|
||||
}
|
||||
|
||||
HRESULT SetWindowTheme(LPCWSTR pszSubAppName, LPCWSTR pszSubIDList)
|
||||
{
|
||||
if(!IsThemingSupported())
|
||||
return S_FALSE;
|
||||
|
||||
T* pT = static_cast<T*>(this);
|
||||
//ATLASSERT(::IsWindow(pT->m_hWnd));
|
||||
return ::SetWindowTheme(pT->m_hWnd, pszSubAppName, pszSubIDList);
|
||||
}
|
||||
|
||||
HTHEME GetWindowTheme() const
|
||||
{
|
||||
if(!IsThemingSupported())
|
||||
return NULL;
|
||||
|
||||
const T* pT = static_cast<const T*>(this);
|
||||
//ATLASSERT(::IsWindow(pT->m_hWnd));
|
||||
return ::GetWindowTheme(pT->m_hWnd);
|
||||
}
|
||||
|
||||
HRESULT EnableThemeDialogTexture(BOOL bEnable)
|
||||
{
|
||||
if(!IsThemingSupported())
|
||||
return S_FALSE;
|
||||
|
||||
T* pT = static_cast<T*>(this);
|
||||
//ATLASSERT(::IsWindow(pT->m_hWnd));
|
||||
return ::EnableThemeDialogTexture(pT->m_hWnd, bEnable);
|
||||
}
|
||||
|
||||
BOOL IsThemeDialogTextureEnabled() const
|
||||
{
|
||||
if(!IsThemingSupported())
|
||||
return FALSE;
|
||||
|
||||
const T* pT = static_cast<const T*>(this);
|
||||
//ATLASSERT(::IsWindow(pT->m_hWnd));
|
||||
return ::IsThemeDialogTextureEnabled(pT->m_hWnd);
|
||||
}
|
||||
|
||||
HRESULT DrawThemeParentBackground(HDC hDC, LPRECT pRect = NULL)
|
||||
{
|
||||
if(!IsThemingSupported())
|
||||
return S_FALSE;
|
||||
|
||||
T* pT = static_cast<T*>(this);
|
||||
//ATLASSERT(::IsWindow(pT->m_hWnd));
|
||||
return ::DrawThemeParentBackground(pT->m_hWnd, hDC, pRect);
|
||||
}
|
||||
|
||||
// Message map and handlers
|
||||
// Note: If you handle any of these messages in your derived class,
|
||||
// it is better to put CHAIN_MSG_MAP at the start of your message map.
|
||||
BEGIN_MSG_MAP(CThemeImpl)
|
||||
MESSAGE_HANDLER(WM_CREATE, OnCreate)
|
||||
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
|
||||
MESSAGE_HANDLER(WM_THEMECHANGED, OnThemeChanged)
|
||||
MESSAGE_HANDLER(WM_NCPAINT, OnNcPaint)
|
||||
END_MSG_MAP()
|
||||
|
||||
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
||||
{
|
||||
if(m_lpstrThemeClassList != NULL)
|
||||
OpenThemeData();
|
||||
bHandled = FALSE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
|
||||
{
|
||||
CloseThemeData();
|
||||
bHandled = FALSE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
LRESULT OnThemeChanged(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
|
||||
{
|
||||
CloseThemeData();
|
||||
if(m_lpstrThemeClassList != NULL)
|
||||
OpenThemeData();
|
||||
bHandled = FALSE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
||||
{
|
||||
T* pT = static_cast<T*>(this);
|
||||
//ATLASSERT(::IsWindow(pT->m_hWnd));
|
||||
LRESULT lRet = 0;
|
||||
bHandled = FALSE;
|
||||
if(IsThemingSupported() && ((pT->GetExStyle() & WS_EX_CLIENTEDGE) != 0))
|
||||
{
|
||||
if((m_dwExtendedStyle & THEME_EX_3DCLIENTEDGE) != 0)
|
||||
{
|
||||
lRet = ::DefWindowProc(pT->m_hWnd, uMsg, wParam, lParam);
|
||||
bHandled = TRUE;
|
||||
}
|
||||
else if((m_hTheme != NULL) && ((m_dwExtendedStyle & THEME_EX_THEMECLIENTEDGE) != 0))
|
||||
{
|
||||
HRGN hRgn = (wParam != 1) ? (HRGN)wParam : NULL;
|
||||
if(pT->DrawThemeClientEdge(hRgn))
|
||||
bHandled = TRUE;
|
||||
}
|
||||
}
|
||||
return lRet;
|
||||
}
|
||||
|
||||
// Drawing helper
|
||||
bool DrawThemeClientEdge(HRGN hRgnUpdate)
|
||||
{
|
||||
T* pT = static_cast<T*>(this);
|
||||
return AtlDrawThemeClientEdge(m_hTheme, pT->m_hWnd, hRgnUpdate, NULL, 0, 0);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
}; //namespace WTL
|
||||
|
Reference in New Issue
Block a user