123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- #include "DateiDialog.h"
- #include "Text.h"
- #include <ShObjIdl.h>
- #pragma comment( lib, "Ole32.lib" )
- #pragma comment( linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"" )
- void Framework::InitDialog()
- {
- CoInitialize( 0 );
- }
- using namespace Framework;
- // Inhalt der DateiDialog Klasse aus DateiDialog.h
- // Konstruktor
- DateiDialog::DateiDialog()
- : ReferenceCounter()
- {
- typeName = new RCArray< Text >();
- type = new RCArray< Text >();
- fileIndex = 1;
- }
- // Destruktor
- DateiDialog::~DateiDialog()
- {
- typeName->release();
- type->release();
- }
- // nicht constant
- void DateiDialog::removeDateiTypen()
- {
- typeName->leeren();
- type->leeren();
- }
- void DateiDialog::addDateiTyp( const char* name, const char* typ )
- {
- addDateiTyp( new Text( name ), new Text( typ ) );
- }
- void DateiDialog::addDateiTyp( Text* name, Text* typ )
- {
- typeName->add( name );
- type->add( typ );
- }
- void DateiDialog::setDateiTypAuswahl( int i )
- {
- fileIndex = i + 1;
- }
- // constant
- Text* DateiDialog::anzeigen( bool open ) const
- {
- IFileDialog* pfd = NULL;
- CoInitialize( NULL );
- HRESULT hr = 0;
- if( open )
- {
- CoCreateInstance( CLSID_FileOpenDialog,
- NULL,
- CLSCTX_INPROC_SERVER,
- IID_PPV_ARGS( &pfd ) );
- }
- else
- {
- CoCreateInstance( CLSID_FileSaveDialog,
- NULL,
- CLSCTX_INPROC_SERVER,
- IID_PPV_ARGS( &pfd ) );
- }
- if( SUCCEEDED( hr ) )
- {
- DWORD dwFlags;
- hr = pfd->GetOptions( &dwFlags );
- if( SUCCEEDED( hr ) )
- {
- hr = pfd->SetOptions( dwFlags | FOS_FORCEFILESYSTEM );
- if( SUCCEEDED( hr ) )
- {
- int anz = type->getEintragAnzahl();
- COMDLG_FILTERSPEC* c_rgSaveTypes = 0;
- if( !anz )
- {
- c_rgSaveTypes = new COMDLG_FILTERSPEC[ 1 ];
- c_rgSaveTypes[ 0 ] = { L"Alle Dateien", L"*.*" };
- anz = 1;
- }
- else
- {
- c_rgSaveTypes = new COMDLG_FILTERSPEC[ anz ];
- for( int i = 0; i < anz; i++ )
- {
- wchar_t* n = new wchar_t[ typeName->z( i )->getLength() + 1 ];
- #pragma warning( disable : 4996 )
- mbstowcs( n, typeName->z( i )->getText(), typeName->z( i )->getLength() + 1 );
- wchar_t* t = new wchar_t[ type->z( i )->getLength() + 1 ];
- #pragma warning( disable : 4996 )
- mbstowcs( t, type->z( i )->getText(), type->z( i )->getLength() + 1 );
- c_rgSaveTypes[ i ].pszName = n;
- c_rgSaveTypes[ i ].pszSpec = t;
- }
- }
- hr = pfd->SetFileTypes( anz, c_rgSaveTypes );
- if( SUCCEEDED( hr ) )
- {
- hr = pfd->SetFileTypeIndex( fileIndex );
- if( SUCCEEDED( hr ) )
- {
- Text txt = "";
- for( int i = 0; i < anz; i++ )
- {
- if( !type->z( i )->hat( ".*" ) )
- {
- txt.append( type->z( i )->getTeilText( type->z( i )->positionVon( "." ) + 1 ) );
- txt += ";";
- }
- }
- if( txt.getLength() > 0 )
- txt.remove( txt.getLength() - 1 );
- wchar_t* defEnd = new wchar_t[ txt.getLength() + 1 ];
- #pragma warning( disable : 4996 )
- mbstowcs( defEnd, txt, txt.getLength() + 1 );
- hr = pfd->SetDefaultExtension( defEnd );
- if( SUCCEEDED( hr ) )
- {
- hr = pfd->Show( NULL );
- if( SUCCEEDED( hr ) )
- {
- IShellItem* psiResult;
- hr = pfd->GetResult( &psiResult );
- if( SUCCEEDED( hr ) )
- {
- PWSTR pszFilePath = NULL;
- hr = psiResult->GetDisplayName( SIGDN_FILESYSPATH,
- &pszFilePath );
- if( SUCCEEDED( hr ) )
- {
- char* txt = new char[ wcslen( pszFilePath ) + 1 ];
- #pragma warning( disable : 4996 )
- wcstombs( txt, pszFilePath, wcslen( pszFilePath ) + 1 );
- Text* ret = new Text( txt );
- delete[] txt;
- psiResult->Release();
- delete[] defEnd;
- for( int i = 0; i < anz; i++ )
- {
- delete[] c_rgSaveTypes[ i ].pszName;
- delete[] c_rgSaveTypes[ i ].pszSpec;
- }
- delete[] c_rgSaveTypes;
- pfd->Release();
- return ret;
- }
- psiResult->Release();
- }
- }
- }
- delete[] defEnd;
- }
- }
- for( int i = 0; i < anz; i++ )
- {
- delete[] c_rgSaveTypes[ i ].pszName;
- delete[] c_rgSaveTypes[ i ].pszSpec;
- }
- delete[] c_rgSaveTypes;
- }
- }
- pfd->Release();
- }
- return 0;
- }
- // Inhalt der DateiDialogTh Klasse aus DateiDialog.h
- // Konstruktor
- DateiDialogTh::DateiDialogTh()
- : Thread()
- {
- dialog = new DateiDialog();
- ret = 0;
- open = 0;
- }
- // Destruktor
- DateiDialogTh::~DateiDialogTh()
- {
- warteAufThread( 5000 );
- if( run )
- ende();
- dialog->release();
- if( ret )
- ret->release();
- }
- // nicht constant
- void DateiDialogTh::setOpen( bool b )
- {
- open = b;
- }
- void DateiDialogTh::removeDateiTypen()
- {
- dialog->removeDateiTypen();
- }
- void DateiDialogTh::addDateiTyp( const char* name, const char* typ )
- {
- dialog->addDateiTyp( name, typ );
- }
- void DateiDialogTh::addDateiTyp( Text* name, Text* typ )
- {
- dialog->addDateiTyp( name, typ );
- }
- void DateiDialogTh::setDateiTypAuswahl( int i )
- {
- dialog->setDateiTypAuswahl( i );
- }
- void DateiDialogTh::thread()
- {
- if( ret )
- ret = (Text*)ret->release();
- ret = dialog->anzeigen( open );
- }
- // constant
- Text* DateiDialogTh::getPfad() const
- {
- return ret ? dynamic_cast<Text*>(ret->getThis()) : 0;
- }
- Text* DateiDialogTh::zPfad() const
- {
- return ret;
- }
|