mirror of
https://github.com/AxioDL/amuse.git
synced 2025-12-10 14:07:48 +00:00
Working Studio implementation
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
#include "FileOpenDialog.hpp"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h> // For common windows data types and function headers
|
||||
#include <windows.h> // For common windows data types and function headers
|
||||
#define STRICT_TYPED_ITEMIDS
|
||||
#include <objbase.h> // For COM headers
|
||||
#include <shobjidl.h> // for IFileDialogEvents and IFileDialogControlEvents
|
||||
#include <objbase.h> // For COM headers
|
||||
#include <shobjidl.h> // for IFileDialogEvents and IFileDialogControlEvents
|
||||
#include <shlwapi.h>
|
||||
#include <knownfolders.h> // for KnownFolder APIs/datatypes/function headers
|
||||
#include <propvarutil.h> // for PROPVAR-related functions
|
||||
@@ -15,26 +15,25 @@
|
||||
#include <new>
|
||||
|
||||
// Controls
|
||||
#define CONTROL_GROUP 2000
|
||||
#define CONTROL_GROUP 2000
|
||||
#define CONTROL_RADIOBUTTONLIST 2
|
||||
#define CONTROL_RADIOBUTTON1 1
|
||||
#define CONTROL_RADIOBUTTON2 2 // It is OK for this to have the same IDas CONTROL_RADIOBUTTONLIST,
|
||||
// because it is a child control under CONTROL_RADIOBUTTONLIST
|
||||
#define CONTROL_RADIOBUTTON1 1
|
||||
#define CONTROL_RADIOBUTTON2 2 // It is OK for this to have the same IDas CONTROL_RADIOBUTTONLIST,
|
||||
// because it is a child control under CONTROL_RADIOBUTTONLIST
|
||||
|
||||
// IDs for the Task Dialog Buttons
|
||||
#define IDC_BASICFILEOPEN 100
|
||||
#define IDC_ADDITEMSTOCUSTOMPLACES 101
|
||||
#define IDC_ADDCUSTOMCONTROLS 102
|
||||
#define IDC_SETDEFAULTVALUESFORPROPERTIES 103
|
||||
#define IDC_WRITEPROPERTIESUSINGHANDLERS 104
|
||||
#define IDC_BASICFILEOPEN 100
|
||||
#define IDC_ADDITEMSTOCUSTOMPLACES 101
|
||||
#define IDC_ADDCUSTOMCONTROLS 102
|
||||
#define IDC_SETDEFAULTVALUESFORPROPERTIES 103
|
||||
#define IDC_WRITEPROPERTIESUSINGHANDLERS 104
|
||||
#define IDC_WRITEPROPERTIESWITHOUTUSINGHANDLERS 105
|
||||
|
||||
HWND ghMainWnd = 0;
|
||||
HINSTANCE ghAppInst = 0;
|
||||
RECT winRect;
|
||||
|
||||
class CDialogEventHandler : public IFileDialogEvents,
|
||||
public IFileDialogControlEvents
|
||||
class CDialogEventHandler : public IFileDialogEvents, public IFileDialogControlEvents
|
||||
{
|
||||
public:
|
||||
// IUnknown methods
|
||||
@@ -43,15 +42,12 @@ public:
|
||||
static const QITAB qit[] = {
|
||||
QITABENT(CDialogEventHandler, IFileDialogEvents),
|
||||
QITABENT(CDialogEventHandler, IFileDialogControlEvents),
|
||||
{ 0 },
|
||||
{0},
|
||||
};
|
||||
return QISearch(this, qit, riid, ppv);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) AddRef()
|
||||
{
|
||||
return InterlockedIncrement(&_cRef);
|
||||
}
|
||||
IFACEMETHODIMP_(ULONG) AddRef() { return InterlockedIncrement(&_cRef); }
|
||||
|
||||
IFACEMETHODIMP_(ULONG) Release()
|
||||
{
|
||||
@@ -62,106 +58,107 @@ public:
|
||||
}
|
||||
|
||||
// IFileDialogEvents methods
|
||||
IFACEMETHODIMP OnFileOk(IFileDialog *) { return S_OK; };
|
||||
IFACEMETHODIMP OnFolderChange(IFileDialog *) { return S_OK; };
|
||||
IFACEMETHODIMP OnFolderChanging(IFileDialog *, IShellItem *) { return S_OK; };
|
||||
IFACEMETHODIMP OnHelp(IFileDialog *) { return S_OK; };
|
||||
IFACEMETHODIMP OnSelectionChange(IFileDialog *) { return S_OK; };
|
||||
IFACEMETHODIMP OnShareViolation(IFileDialog *, IShellItem *, FDE_SHAREVIOLATION_RESPONSE *) { return S_OK; };
|
||||
IFACEMETHODIMP OnTypeChange(IFileDialog *pfd);
|
||||
IFACEMETHODIMP OnOverwrite(IFileDialog *, IShellItem *, FDE_OVERWRITE_RESPONSE *) { return S_OK; };
|
||||
IFACEMETHODIMP OnFileOk(IFileDialog*) { return S_OK; };
|
||||
IFACEMETHODIMP OnFolderChange(IFileDialog*) { return S_OK; };
|
||||
IFACEMETHODIMP OnFolderChanging(IFileDialog*, IShellItem*) { return S_OK; };
|
||||
IFACEMETHODIMP OnHelp(IFileDialog*) { return S_OK; };
|
||||
IFACEMETHODIMP OnSelectionChange(IFileDialog*) { return S_OK; };
|
||||
IFACEMETHODIMP OnShareViolation(IFileDialog*, IShellItem*, FDE_SHAREVIOLATION_RESPONSE*) { return S_OK; };
|
||||
IFACEMETHODIMP OnTypeChange(IFileDialog* pfd);
|
||||
IFACEMETHODIMP OnOverwrite(IFileDialog*, IShellItem*, FDE_OVERWRITE_RESPONSE*) { return S_OK; };
|
||||
|
||||
// IFileDialogControlEvents methods
|
||||
IFACEMETHODIMP OnItemSelected(IFileDialogCustomize *pfdc, DWORD dwIDCtl, DWORD dwIDItem);
|
||||
IFACEMETHODIMP OnButtonClicked(IFileDialogCustomize *, DWORD) { return S_OK; };
|
||||
IFACEMETHODIMP OnCheckButtonToggled(IFileDialogCustomize *, DWORD, BOOL) { return S_OK; };
|
||||
IFACEMETHODIMP OnControlActivating(IFileDialogCustomize *, DWORD) { return S_OK; };
|
||||
IFACEMETHODIMP OnItemSelected(IFileDialogCustomize* pfdc, DWORD dwIDCtl, DWORD dwIDItem);
|
||||
IFACEMETHODIMP OnButtonClicked(IFileDialogCustomize*, DWORD) { return S_OK; };
|
||||
IFACEMETHODIMP OnCheckButtonToggled(IFileDialogCustomize*, DWORD, BOOL) { return S_OK; };
|
||||
IFACEMETHODIMP OnControlActivating(IFileDialogCustomize*, DWORD) { return S_OK; };
|
||||
|
||||
CDialogEventHandler() : _cRef(1){};
|
||||
|
||||
CDialogEventHandler() : _cRef(1) { };
|
||||
private:
|
||||
~CDialogEventHandler() { };
|
||||
~CDialogEventHandler(){};
|
||||
long _cRef;
|
||||
};
|
||||
|
||||
HRESULT CDialogEventHandler_CreateInstance(REFIID riid, void **ppv);
|
||||
HRESULT CDialogEventHandler_CreateInstance(REFIID riid, void** ppv);
|
||||
|
||||
std::wstring openDB()
|
||||
{
|
||||
std::wstring ret;
|
||||
CoInitializeEx(NULL, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
|
||||
|
||||
//Cocreate the file open dialog object
|
||||
IFileDialog *pfd = NULL;
|
||||
// Cocreate the file open dialog object
|
||||
IFileDialog* pfd = NULL;
|
||||
|
||||
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
//Stuff needed for later
|
||||
// Stuff needed for later
|
||||
const COMDLG_FILTERSPEC rgFExt[] = {{L"Audio Group Archive (*.*)", L"*.*"}};
|
||||
|
||||
//Create event handling
|
||||
IFileDialogEvents *pfde = NULL;
|
||||
// Create event handling
|
||||
IFileDialogEvents* pfde = NULL;
|
||||
hr = CDialogEventHandler_CreateInstance(IID_PPV_ARGS(&pfde));
|
||||
|
||||
if(SUCCEEDED(hr))
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
//Hook the event handler
|
||||
// Hook the event handler
|
||||
DWORD dwCookie;
|
||||
|
||||
hr = pfd->Advise(pfde, &dwCookie);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
//Set options for the dialog
|
||||
// Set options for the dialog
|
||||
DWORD dwFlags;
|
||||
|
||||
//Get options first so we do not override
|
||||
// Get options first so we do not override
|
||||
hr = pfd->GetOptions(&dwFlags);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
//Get shell items only
|
||||
// Get shell items only
|
||||
hr = pfd->SetOptions(dwFlags | FOS_FORCEFILESYSTEM);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
//Types of files to display (not default)
|
||||
// Types of files to display (not default)
|
||||
hr = pfd->SetFileTypes(ARRAYSIZE(rgFExt), rgFExt);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
//Set default file type to display
|
||||
//hr = pfd->SetDefaultExtension(L"sqlite");
|
||||
// Set default file type to display
|
||||
// hr = pfd->SetDefaultExtension(L"sqlite");
|
||||
|
||||
//if (SUCCEEDED(hr))
|
||||
// if (SUCCEEDED(hr))
|
||||
//{
|
||||
//Show dialog
|
||||
hr = pfd->Show(NULL);
|
||||
// Show dialog
|
||||
hr = pfd->Show(NULL);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
// Get the result once the user clicks on open
|
||||
IShellItem* result;
|
||||
|
||||
hr = pfd->GetResult(&result);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
//Get the result once the user clicks on open
|
||||
IShellItem *result;
|
||||
// Print out the file name
|
||||
PWSTR fName = NULL;
|
||||
|
||||
hr = pfd->GetResult(&result);
|
||||
hr = result->GetDisplayName(SIGDN_FILESYSPATH, &fName);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
//Print out the file name
|
||||
PWSTR fName = NULL;
|
||||
|
||||
hr = result->GetDisplayName(SIGDN_FILESYSPATH, &fName);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
ret.assign(fName);
|
||||
CoTaskMemFree(fName);
|
||||
}
|
||||
|
||||
result->Release();
|
||||
ret.assign(fName);
|
||||
CoTaskMemFree(fName);
|
||||
}
|
||||
|
||||
result->Release();
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -178,11 +175,10 @@ std::wstring openDB()
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CDialogEventHandler_CreateInstance(REFIID riid, void **ppv)
|
||||
HRESULT CDialogEventHandler_CreateInstance(REFIID riid, void** ppv)
|
||||
{
|
||||
*ppv = NULL;
|
||||
CDialogEventHandler *pDialogEventHandler = new (std::nothrow) CDialogEventHandler();
|
||||
CDialogEventHandler* pDialogEventHandler = new (std::nothrow) CDialogEventHandler();
|
||||
HRESULT hr = pDialogEventHandler ? S_OK : E_OUTOFMEMORY;
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
@@ -192,19 +188,17 @@ HRESULT CDialogEventHandler_CreateInstance(REFIID riid, void **ppv)
|
||||
return hr;
|
||||
}
|
||||
|
||||
HRESULT CDialogEventHandler::OnTypeChange(IFileDialog *pfd)
|
||||
HRESULT CDialogEventHandler::OnTypeChange(IFileDialog* pfd)
|
||||
{
|
||||
IFileSaveDialog *pfsd;
|
||||
IFileSaveDialog* pfsd;
|
||||
HRESULT hr = pfd->QueryInterface(&pfsd);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
UINT uIndex;
|
||||
hr = pfsd->GetFileTypeIndex(&uIndex); // index of current file-type
|
||||
hr = pfsd->GetFileTypeIndex(&uIndex); // index of current file-type
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
IPropertyDescriptionList *pdl = NULL;
|
||||
|
||||
|
||||
IPropertyDescriptionList* pdl = NULL;
|
||||
}
|
||||
pfsd->Release();
|
||||
}
|
||||
@@ -214,9 +208,9 @@ HRESULT CDialogEventHandler::OnTypeChange(IFileDialog *pfd)
|
||||
// IFileDialogControlEvents
|
||||
// This method gets called when an dialog control item selection happens (radio-button selection. etc).
|
||||
// For sample sake, let's react to this event by changing the dialog title.
|
||||
HRESULT CDialogEventHandler::OnItemSelected(IFileDialogCustomize *pfdc, DWORD dwIDCtl, DWORD dwIDItem)
|
||||
HRESULT CDialogEventHandler::OnItemSelected(IFileDialogCustomize* pfdc, DWORD dwIDCtl, DWORD dwIDItem)
|
||||
{
|
||||
IFileDialog *pfd = NULL;
|
||||
IFileDialog* pfd = NULL;
|
||||
HRESULT hr = pfdc->QueryInterface(&pfd);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user