Пример #1
0
void MusPlayer_WinAPI::on_open_clicked()
{
    OPENFILENAMEW open;
    memset(&open, 0, sizeof(open));

    wchar_t flnm[MAX_PATH];
    flnm[0]=L'\0';
    open.lStructSize = sizeof(OPENFILENAMEW);
    open.hInstance = m_hInstance;
    open.hwndOwner = m_hWnd;
    open.lpstrFilter = L"All files (*.*)\0*.*";
    open.lpstrDefExt = L"\0";
    open.lpstrFile = flnm;
    open.nMaxFile = MAX_PATH;
    open.lpstrTitle = L"Open music file to play...";
    open.Flags = OFN_FILEMUSTEXIST;
    if(GetOpenFileNameW(&open)==TRUE)
    {
        currentMusic = Wstr2Str(open.lpstrFile);
    } else {
        return;
    }

    Mix_HaltMusic();
    on_play_clicked();
}
Пример #2
0
Файл: common.c Проект: gpg/gpgol
/* Return the path to a file that should be worked with.
   Returns a malloced string (UTF-8) on success.
   HWND is the current Window.
   Title is a UTF-8 encoded string containing the
   dialog title and may be NULL.
   On error (i.e. cancel) NULL is returned. */
char *
get_open_filename (HWND root, const char *title)
{
  OPENFILENAMEW ofn;
  wchar_t fname[MAX_PATH+1];
  wchar_t *wTitle = NULL;

  if (title)
    {
      wTitle = utf8_to_wchar2 (title, strlen(title));
    }
  memset (fname, 0, sizeof (fname));

  /* Set up the ofn structure */
  memset (&ofn, 0, sizeof (ofn));
  ofn.lStructSize = sizeof (ofn);
  ofn.hwndOwner = root;
  ofn.lpstrFile = fname;
  ofn.nMaxFile = MAX_PATH;
  ofn.lpstrTitle = wTitle;
  ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;

  if (GetOpenFileNameW (&ofn))
    {
      xfree (wTitle);
      return wchar_to_utf8_2 (fname, MAX_PATH);
    }
  xfree (wTitle);
  return NULL;
}
Пример #3
0
bool openlist(HWND hwnd)
{
    OPENFILENAMEW fn;

    memset(&fn,0,sizeof(fn));
    fn.lStructSize=sizeof(fn);
    fn.lpstrFilter=WTB_FILE_FILTER_TDL;
    fn.nMaxFile=MAX_PATH;
    fn.nFilterIndex=0;
    fn.lpstrFileTitle=NULL;
    fn.nMaxFileTitle=0;
    fn.lpstrInitialDir=EWIN_TXT_CDIR;
    fn.lpstrFile=(wchar_t *)malloc((MAX_PATH+1)*sizeof(wchar_t));
    fn.lpstrFile[0]=0;
    fn.lpstrDefExt=L"";
    fn.Flags=OFN_EXPLORER | OFN_ENABLESIZING | OFN_HIDEREADONLY;
    fn.lpstrTitle=WTB_FILE_TEXT_STD_OPEN;
    if(GetOpenFileNameW(&fn))
    {
        if(DOC_FILENAME==0)
        {
            DOC_FILENAME=(wchar_t *)malloc((wcslen(fn.lpstrFile)+1)*sizeof(wchar_t));
        }
        else
        {
            DOC_FILENAME=(wchar_t *)realloc(DOC_FILENAME,(wcslen(fn.lpstrFile)+1)*sizeof(wchar_t));
        }
        wcscpy(DOC_FILENAME,fn.lpstrFile);

        //Laden
        //loadlist(DOC_FILENAME);
        return true;
    }
    return false;
}
Пример #4
0
BOOL CAshaD2D::OpenFile(HWND hWnd,LPWSTR lpwFileName,unsigned int fileSize)
{
	//Initialize file name
	lpwFileName[0]=L'\0';

	OPENFILENAME ofn;
	memset(&ofn,0,sizeof(ofn));

	ofn.lStructSize=sizeof(ofn);
	ofn.hwndOwner=hWnd;
	ofn.lpstrFilter=L"All image files.\0"
		L"*.bmp;*.dib;*.wdp;*.mdp;*.hdp;*.gif;*.png;*.jpg;*.jpeg;*.tif;*.ico\0"
		L"Windows Bitmap\0"               L"*.bmp;*.dib\0"
		L"High Definition Photo\0"        L"*.wdp;*.mdp;*.hdp\0"
		L"Graphics Interchange Format\0"  L"*.gif\0"
		L"Portable Network Graphics\0"    L"*.png\0"
		L"JPEG File Interchange Format\0" L"*.jpg;*.jpeg\0"
		L"Tiff File\0"                    L"*.tif\0"
		L"Icon\0"                         L"*.ico\0"
		L"All Files\0"                    L"*.*\0"
		L"\0";
	ofn.lpstrFile       = lpwFileName;
	ofn.nMaxFile        = fileSize;
	ofn.lpstrTitle      = L"Open File";
	ofn.Flags           = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;

	//Open file dialog
	return GetOpenFileNameW(&ofn);
}
Пример #5
0
static void LoadClipboardFromFile(void)
{
    OPENFILENAMEW ofn;
    LPWSTR c;
    WCHAR szFileName[MAX_PATH];
    WCHAR szFilterMask[MAX_STRING_LEN + 10];

    ZeroMemory(&szFilterMask, sizeof(szFilterMask));
    c = szFilterMask + LoadStringW(Globals.hInstance, STRING_FORMAT_GEN, szFilterMask, MAX_STRING_LEN) + 1;
    wcscpy(c, L"*.clp");

    ZeroMemory(&szFileName, sizeof(szFileName));
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = Globals.hMainWnd;
    ofn.hInstance = Globals.hInstance;
    ofn.lpstrFilter = szFilterMask;
    ofn.lpstrFile = szFileName;
    ofn.nMaxFile = ARRAYSIZE(szFileName);
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;

    if (!GetOpenFileNameW(&ofn))
        return;

    LoadClipboardDataFromFile(szFileName);
}
Пример #6
0
wchar_t *askfilenamesW(const wchar_t *title, const wchar_t *default_name,
		       int multi,
		       const wchar_t *filters, int filterindex,
		       const wchar_t *dir)
{
    int i;
    OPENFILENAMEW ofn;
    char cwd[MAX_PATH];
    wchar_t wcod[MAX_PATH];
    HWND prev = GetFocus();

    if (!default_name) default_name = L"";
    memset(wcsbuf, 0, sizeof(wcsbuf));
    wcscpy(wcsbuf, default_name);
    GetCurrentDirectory(MAX_PATH, cwd);
    if (!strcmp(cod, "")) {
	if (!dir) GetCurrentDirectoryW(MAX_PATH, wcod); else wcscpy(wcod, dir);
    } else
	mbstowcs(wcod, cod, MAX_PATH);

    ofn.lStructSize     = sizeof(OPENFILENAME);
    ofn.hwndOwner       = current_window ? current_window->handle : 0;
    ofn.hInstance       = 0;
    ofn.lpstrFilter     = filters;
    ofn.lpstrCustomFilter = NULL;
    ofn.nMaxCustFilter  = 0;
    ofn.nFilterIndex    = filterindex;
    ofn.lpstrFile       = wcsbuf;
    ofn.nMaxFile        = 65520; /* precaution against overflow */
    ofn.lpstrFileTitle  = NULL;
    ofn.nMaxFileTitle   = _MAX_FNAME + _MAX_EXT;
    ofn.lpstrInitialDir = wcod;
    ofn.lpstrTitle      = title;
    ofn.Flags           = OFN_CREATEPROMPT | OFN_HIDEREADONLY | OFN_EXPLORER;
    if (multi) ofn.Flags |= OFN_ALLOWMULTISELECT;
    ofn.nFileOffset     = 0;
    ofn.nFileExtension  = 0;
    ofn.lpstrDefExt     = L"*";
    ofn.lCustData       = 0L;
    ofn.lpfnHook        = NULL;
    ofn.lpTemplateName  = NULL;

    if (GetOpenFileNameW(&ofn) == 0) {
	/* This could fail if the Unicode name is not a native name */
	DWORD res = GetCurrentDirectory(MAX_PATH, cod);
	if(res) strcpy(cod, cwd);
	SetCurrentDirectory(cwd);
	wcsbuf[0] = 0;
	wcsbuf[1] = 0;
    } else {
	DWORD res = GetCurrentDirectory(MAX_PATH, cod);
	if(res) strcpy(cod, cwd);
	SetCurrentDirectory(cwd);
	for (i = 0; i <  10; i++) if (peekevent()) doevent();
    }
    SetFocus(prev);
    return wcsbuf;
}
Пример #7
0
VOID MountFloppy(IN ULONG DiskNumber)
{
// FIXME: This should be present in PSDK commdlg.h
//
// FlagsEx Values
#if (_WIN32_WINNT >= 0x0500)
#define  OFN_EX_NOPLACESBAR         0x00000001
#endif // (_WIN32_WINNT >= 0x0500)

    BOOLEAN Success;
    OPENFILENAMEW ofn;
    WCHAR szFile[MAX_PATH] = L"";

    ASSERT(DiskNumber < ARRAYSIZE(GlobalSettings.FloppyDisks));

    RtlZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize  = sizeof(ofn);
    ofn.hwndOwner    = hConsoleWnd;
    ofn.lpstrTitle   = L"Select a virtual floppy image";
    ofn.Flags        = OFN_EXPLORER | OFN_ENABLESIZING | OFN_LONGNAMES | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
//  ofn.FlagsEx      = OFN_EX_NOPLACESBAR;
    ofn.lpstrFilter  = L"Virtual floppy images (*.vfd;*.img;*.ima;*.dsk)\0*.vfd;*.img;*.ima;*.dsk\0All files (*.*)\0*.*\0\0";
    ofn.lpstrDefExt  = L"vfd";
    ofn.nFilterIndex = 0;
    ofn.lpstrFile    = szFile;
    ofn.nMaxFile     = ARRAYSIZE(szFile);

    if (!GetOpenFileNameW(&ofn))
    {
        DPRINT1("CommDlgExtendedError = %d\n", CommDlgExtendedError());
        return;
    }

    /* Free the old string */
    if (GlobalSettings.FloppyDisks[DiskNumber].Buffer)
        RtlFreeUnicodeString(&GlobalSettings.FloppyDisks[DiskNumber]);

    /* Reinitialize the string */
    Success = RtlCreateUnicodeString(&GlobalSettings.FloppyDisks[DiskNumber], szFile);
    ASSERT(Success);

    /* Mount the disk */
    if (!MountDisk(FLOPPY_DISK, DiskNumber, GlobalSettings.FloppyDisks[DiskNumber].Buffer, !!(ofn.Flags & OFN_READONLY)))
    {
        DisplayMessage(L"An error happened when mounting disk %d", DiskNumber);
        RtlFreeUnicodeString(&GlobalSettings.FloppyDisks[DiskNumber]);
        RtlInitEmptyUnicodeString(&GlobalSettings.FloppyDisks[DiskNumber], NULL, 0);
        return;
    }

    /* Refresh the menu state */
    UpdateVdmMenuDisks();
}
Пример #8
0
void NSudoBrowseDialog(HWND hWnd, wchar_t* szPath)
{
	OPENFILENAME ofn = { 0 };

	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = hWnd;
	ofn.nMaxFile = MAX_PATH;
	ofn.nMaxFileTitle = MAX_PATH;
	ofn.lpstrFile = szPath;
	ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT;

	GetOpenFileNameW(&ofn);
}
Пример #9
0
int winfilename(wchar_t *buf, int len)
{
	OPENFILENAME ofn;
	buf[0] = 0;
	memset(&ofn, 0, sizeof(OPENFILENAME));
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = hwndframe;
	ofn.lpstrFile = buf;
	ofn.nMaxFile = len;
	ofn.lpstrInitialDir = NULL;
	ofn.lpstrTitle = L"MuPDF: Open PDF file";
	ofn.lpstrFilter = L"Documents (*.pdf;*.xps;*.cbz;*.zip)\0*.zip;*.cbz;*.xps;*.pdf\0PDF Files (*.pdf)\0*.pdf\0XPS Files (*.xps)\0*.xps\0CBZ Files (*.cbz;*.zip)\0*.zip;*.cbz\0All Files\0*\0\0";
	ofn.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
	return GetOpenFileNameW(&ofn);
}
Пример #10
0
static BOOL FileOpen(HWND hWnd, WCHAR *fn, int fnsz)
{
  static const WCHAR filter[] = {'M','e','t','a','f','i','l','e','s','\0','*','.','w','m','f',';','*','.','e','m','f','\0',0};
  OPENFILENAMEW ofn = { sizeof(OPENFILENAMEW),
                        0, 0, NULL, NULL, 0, 0, NULL,
                        fnsz, NULL, 0, NULL, NULL,
                        OFN_SHOWHELP, 0, 0, NULL, 0, NULL };
  ofn.lpstrFilter = filter;
  ofn.hwndOwner = hWnd;
  ofn.lpstrFile = fn;
  if( fnsz < 1 )
    return FALSE;
  *fn = 0;
  return GetOpenFileNameW(&ofn);
}
Пример #11
0
std::string FileOpenDialog_t::Browse( std::string title, std::string filter )
{
    OPENFILENAMEW openFileName;
	   
    TCHAR sfile[ MAX_PATH ];
    
    ZeroMemory( &openFileName, sizeof( openFileName ) );
    ZeroMemory( sfile, sizeof( TCHAR ) * MAX_PATH );

    openFileName.lStructSize = sizeof(openFileName);
    openFileName.hwndOwner   = NULL;
    openFileName.lpstrFile   = (LPWSTR)sfile;
    openFileName.nMaxFile    = MAX_PATH;
    
    
    std::wstring wstrTitle = std::wstring( title.begin(), title.end() );
    //std::wstring wstrFilter = std::wstring( filter.begin(), filter.end() );
	
    openFileName.nFilterIndex       = 1;
    openFileName.lpstrTitle         = wstrTitle.c_str();
    openFileName.lpstrFilter        = L"ROM images\0*.nes\0";
    openFileName.lpstrInitialDir    = NULL;
    openFileName.lpstrCustomFilter  = NULL;
    openFileName.nMaxCustFilter     = 0;
    openFileName.lpstrFileTitle     = NULL;
    openFileName.nMaxFileTitle      = 0;
    openFileName.nFileOffset        = 0;
    openFileName.nFileExtension     = 0;
    openFileName.lpstrDefExt        = NULL;
    openFileName.lCustData          = 0;
    openFileName.lpfnHook           = 0;
    openFileName.lpTemplateName     = 0;
    openFileName.Flags              = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
 
    GetOpenFileNameW(&openFileName);

    uint32_t error = GetLastError();
        
    if( 0 != error )
    {
    }
	
    char filePathBuffer[ 256 ];
    memset( filePathBuffer, 0, sizeof( filePathBuffer) );
    wcstombs( filePathBuffer, openFileName.lpstrFile, sizeof( filePathBuffer) );

    return filePathBuffer;
 }
Пример #12
0
void fileOpen()
{
	wchar_t temp[_MAX_FNAME + 1];
	temp[0] = L'\0'; // clear string

	OPENFILENAMEW ofn;
	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.lpstrFile = temp;
	ofn.nMaxFile = _MAX_FNAME;
	ofn.lpstrDefExt = L"rocket";
	ofn.lpstrFilter = L"ROCKET File (*.rocket)\0*.rocket\0All Files (*.*)\0*.*\0\0";
	ofn.Flags = OFN_SHOWHELP | OFN_FILEMUSTEXIST;
	if (GetOpenFileNameW(&ofn))
	{
		loadDocument(temp);
	}
}
Пример #13
0
static BOOL
PxImageView_OpenFileDialog(PxImageViewObject* self)
{
	OPENFILENAME ofn;
	wchar_t szFilter[] = L"Bitmap (*.BMP)\0*.bmp\0";
	wchar_t szOpenFileNamePath[MAX_PATH];

	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = g.hWin;
	ofn.hInstance = NULL;
	ofn.lpstrFilter = szFilter;
	ofn.lpstrCustomFilter = NULL;
	ofn.nMaxCustFilter = 0;
	ofn.nFilterIndex = 0;
	ofn.lpstrFile = szOpenFileNamePath;
	ofn.nMaxFile = MAX_PATH;
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = MAX_PATH;
	ofn.lpstrInitialDir = NULL;
	ofn.lpstrTitle = NULL; //L"Select File"
	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; //OFN_HIDEREADONLY | OFN_CREATEPROMPT ;
	ofn.nFileOffset = 0;
	ofn.nFileExtension = 0;
	ofn.lpstrDefExt = L"bmp";
	ofn.lCustData = 0L;
	ofn.lpfnHook = NULL;
	ofn.lpTemplateName = NULL;

	OutputDebugString(L"PxImageView_OpenFileDialog\n");
	if (GetOpenFileNameW(&ofn)) {
		OutputDebugString(L"iv4!\n");
		LPCSTR sOpenFileNamePath = toU8(szOpenFileNamePath);
		MessageBoxA(NULL, sOpenFileNamePath, "jj", NULL);
		PyObject* pyArgs = Py_BuildValue("s", sOpenFileNamePath);
		PyObject* pyImage;
		PxASSIGN(pyImage = PyObject_CallObject((PyObject*)&PxImageType, pyArgs));
		XX(pyImage);
		Py_DECREF(pyArgs);
		PyMem_RawFree(sOpenFileNamePath);
		PxImageView_SetData(self, pyImage);
		Py_DECREF(pyImage);
	}
	return TRUE;
}
Пример #14
0
LRESULT CMainDlg::OnFileOpen(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	BOOL b_ret;

	OPENFILENAMEW ofn = {};
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = m_hWnd;
	ofn.lpstrFilter = L"XML Files\0*.xml\0\0";
	ofn.lpstrFile = config_path;
	ofn.nMaxFile = MAX_PATH;

	b_ret = GetOpenFileNameW(&ofn);
	if (b_ret)
	{
		gdipp::init_config();
		b_ret = gdipp::load_config(config_path);
	}

	return 0;
}
/* When the user clicks the browse button in SetupPromptForDisk dialog
 * it copies the path of the selected file to the dialog path field
 */
static void promptdisk_browse(HWND hwnd, struct promptdisk_params *params)
{
    OPENFILENAMEW ofn;
    ZeroMemory(&ofn, sizeof(ofn));

    ofn.lStructSize = sizeof(ofn);
    ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
    ofn.hwndOwner = hwnd;
    ofn.nMaxFile = MAX_PATH;
    ofn.lpstrFile = HeapAlloc(GetProcessHeap(), 0, MAX_PATH*sizeof(WCHAR));
    strcpyW(ofn.lpstrFile, params->FileSought);

    if(GetOpenFileNameW(&ofn))
    {
        WCHAR* last_slash = strrchrW(ofn.lpstrFile, '\\');
        if (last_slash) *last_slash = 0;
        SetDlgItemTextW(hwnd, IDC_PATH, ofn.lpstrFile);
    }
    HeapFree(GetProcessHeap(), 0, ofn.lpstrFile);
}
Пример #16
0
/**
 * Display an "open file" dialog
 */
void GD_EXTENSION_API ShowOpenFile( RuntimeScene & scene, gd::Variable & variable, const gd::String & title, gd::String filters )
{
    sf::Clock timeSpent;

    gd::String result;

    //Display the dialog
    #if defined(WINDOWS)
    //Process filters to match windows dialogs filters style.
    filters.Raw() = filters.Raw()+'\0';
    std::replace(filters.Raw().begin(), filters.Raw().end(), '|', '\0');

    OPENFILENAMEW toGetFileName; //Struct for the dialog
    wchar_t filePath[MAX_PATH];
    _wgetcwd(filePath, MAX_PATH);

    ZeroMemory(&toGetFileName, sizeof(OPENFILENAMEW));
    toGetFileName.lStructSize = sizeof(OPENFILENAMEW);
    toGetFileName.hwndOwner = NULL;
    toGetFileName.lpstrFile = filePath;
    toGetFileName.nMaxFile = MAX_PATH;
    toGetFileName.lpstrFilter = filters == "\0" ? NULL : filters.ToWide().c_str();
    toGetFileName.nFilterIndex = 1;
    toGetFileName.Flags = OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR;;

    if(GetOpenFileNameW(&toGetFileName) == TRUE)
        result = gd::String::FromWide(filePath);
    #endif
    #if defined(LINUX) || defined(MACOS)
    std::string strResult;
    nw::OpenFile * dialog = new nw::OpenFile(title.ToLocale(), true, strResult);
    dialog->wait_until_closed();
    result = gd::String::FromLocale(strResult);
    #endif

    scene.GetTimeManager().NotifyPauseWasMade(timeSpent.getElapsedTime().asMicroseconds());//Don't take the time spent in this function in account.

    //Update the variable
    variable.SetString(result);
}
void CSkeletonActionExpDlg::LoadActionList(bool FilterByFile)
{
    m_XmlFile[0] = 0;
    OPENFILENAMEW ofn; 
    ZeroMemory(&ofn, sizeof(OPENFILENAMEW));
    ofn.lStructSize = sizeof(OPENFILENAMEW);
    ofn.hwndOwner = ::GetActiveWindow();
    ofn.lpstrFile = m_XmlFile;
    ofn.nMaxFile = 1024;
    ofn.lpstrFilter = L"动作列表(*.xml)\0*.xml\0所有文件(*.*)\0*.*\0";
    ofn.nFilterIndex = 1;
    ofn.lpstrFileTitle = NULL;
    ofn.lpstrDefExt = L"xml";
    ofn.nMaxFileTitle = 0;
    ofn.lpstrInitialDir = NULL;
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
    if(GetOpenFileNameW(&ofn) == FALSE)
    {
        return;
    }
    return LoadActionList(m_XmlFile , FilterByFile);
}
Пример #18
0
wstring Win32CallstackResolver::pdbBrowse(wstring startingPoint)
{
	OPENFILENAMEW ofn;
	RDCEraseMem(&ofn, sizeof(ofn));

	wchar_t outBuf[MAX_PATH*2];
	wcscpy_s(outBuf, startingPoint.c_str());

	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.lpstrTitle = L"Locate PDB File";
	ofn.lpstrFilter = L"PDB File\0*.pdb\0";
	ofn.lpstrFile = outBuf;
	ofn.nMaxFile = MAX_PATH*2-1;
	ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST; // | OFN_ENABLEINCLUDENOTIFY | OFN_ENABLEHOOK

	BOOL ret = GetOpenFileNameW(&ofn);

	if(ret == FALSE)
		return L"";

	return outBuf;
}
Пример #19
0
void ChromeClient::runOpenPanel(WebCore::Frame*, PassRefPtr<WebCore::FileChooser> chooser)
{
    //cexer 实现文件选择
    wchar_t* pathList = new wchar_t[10 * MAX_PATH];
    memset(pathList, 0, 10 * MAX_PATH * sizeof(wchar_t));

    OPENFILENAMEW ofn = { 0 };
    ofn.Flags = OFN_DONTADDTORECENT|OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_NONETWORKBUTTON|OFN_PATHMUSTEXIST;
    if (chooser->settings().allowsMultipleFiles)
        ofn.Flags |= OFN_ALLOWMULTISELECT;

    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = NULL;
    ofn.lpstrFilter = L"*.*\0*.*\0\0";
    ofn.lpstrFile = pathList;
    ofn.nMaxFile = 10 * MAX_PATH;
    ofn.lpstrInitialDir = NULL;
    ofn.lpstrTitle = NULL;
    if (0 != GetOpenFileNameW(&ofn))
    {
        Vector<String> chosenFiles;

        wchar_t* path = pathList;
        while (*path)
        {
            size_t pathLen = wcslen(path);

            String pathString((const UChar*)path, pathLen);
            chosenFiles.append(pathString);

            path += pathLen + 1;
        }

        if (!chosenFiles.isEmpty())
            chooser->chooseFiles(chosenFiles);
    }

    delete [] pathList;
}
Пример #20
0
/// <summary>
/// Invoke Open/Save file dialog
/// </summary>
/// <param name="filter">File filter</param>
/// <param name="defIndex">Default filter index</param>
/// <param name="selectedPath">Target file path</param>
/// <param name="bSave">true to Save file, false to open</param>
/// <param name="defExt">Default file extension for file save</param>
/// <returns>true on success, false if operation was canceled by user</returns>
bool MainDlg::OpenSaveDialog( 
    const wchar_t* filter, 
    int defIndex, 
    std::wstring& selectedPath,
    bool bSave /*= false*/, 
    const std::wstring& defExt /*= L""*/
    )
{
    OPENFILENAMEW ofn = { 0 };
    wchar_t path[MAX_PATH] = { 0 };

    ofn.lStructSize = sizeof( ofn );
    ofn.hwndOwner = NULL;
    ofn.lpstrFile = path;
    ofn.lpstrFile[0] = '\0';
    ofn.nMaxFile = MAX_PATH;
    ofn.lpstrFilter = filter;
    ofn.nFilterIndex = defIndex;
    ofn.lpstrFileTitle = NULL;
    ofn.nMaxFileTitle = 0;
    ofn.lpstrInitialDir = NULL;
    if (!bSave)
    {
        ofn.Flags = OFN_PATHMUSTEXIST;
    }
    else
    {
        ofn.Flags = OFN_OVERWRITEPROMPT;
        ofn.lpstrDefExt = defExt.c_str();
    }

    auto res = bSave ? GetSaveFileNameW( &ofn ) : GetOpenFileNameW( &ofn );
    if (res)
        selectedPath = path;

    return res != FALSE;
}
Пример #21
0
LRESULT CDVRMVPlayerProp::OnBnClickedButtonBrowse(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	OPENFILENAMEW ofn;
	ZeroMemory(&ofn, sizeof(ofn));

	WCHAR szFileName[MAX_PATH];
	szFileName[0] = L'\0';
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = m_hWnd;
	ofn.lpstrFilter = L"MP4 Files\0*.mp4\0All Files\0*.*\0";
	ofn.nFilterIndex = 1 ;
	ofn.lpstrFile = szFileName;
	ofn.nMaxFile = MAX_PATH;
	ofn.lpstrTitle = L"Open MP4 moive\0";
	ofn.Flags = OFN_FILEMUSTEXIST;

	if (GetOpenFileNameW(&ofn))
	{
		SetDlgItemText(IDC_EDIT_URL,szFileName);
		SetDirty(TRUE);
	}

	return 0;
}
Пример #22
0
static VOID
DoOpenFile(PINFO pInfo)
{
    OPENFILENAMEW ofn;
    WCHAR szFileName[MAX_PATH] = L"Default.rdp";
    static WCHAR szFilter[] = L"Remote Desktop Files (*.RDP)\0*.rdp\0";

    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize   = sizeof(OPENFILENAMEW);
    ofn.hwndOwner     = pInfo->hGeneralPage;
    ofn.nMaxFile      = MAX_PATH;
    ofn.nMaxFileTitle = MAX_PATH;
    ofn.lpstrDefExt   = L"RDP";
    ofn.lpstrFilter   = szFilter;
    ofn.lpstrFile     = szFileName;
    ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST;

    if (GetOpenFileNameW(&ofn))
    {
        LoadRdpSettingsFromFile(pInfo->pRdpSettings, szFileName);
        ReLoadGeneralPage(pInfo);
        ReLoadDisplayPage(pInfo);
    }
}
Пример #23
0
static BOOL GetOpenSaveFileNameUTF8(LPOPENFILENAME lpofn, BOOL save)
{

  OPENFILENAMEW tmp={sizeof(tmp),lpofn->hwndOwner,lpofn->hInstance,};
  BOOL ret;

  // allocate, convert input
  if (lpofn->lpstrFilter) tmp.lpstrFilter = WDL_UTF8ToWC(lpofn->lpstrFilter,TRUE,0,0);
  tmp.nFilterIndex = lpofn->nFilterIndex ;

  if (lpofn->lpstrFile) tmp.lpstrFile = WDL_UTF8ToWC(lpofn->lpstrFile,FALSE,lpofn->nMaxFile,&tmp.nMaxFile);
  if (lpofn->lpstrFileTitle) tmp.lpstrFileTitle = WDL_UTF8ToWC(lpofn->lpstrFileTitle,FALSE,lpofn->nMaxFileTitle,&tmp.nMaxFileTitle);
  if (lpofn->lpstrInitialDir) tmp.lpstrInitialDir = WDL_UTF8ToWC(lpofn->lpstrInitialDir,0,0,0);
  if (lpofn->lpstrTitle) tmp.lpstrTitle = WDL_UTF8ToWC(lpofn->lpstrTitle,0,0,0);
  if (lpofn->lpstrDefExt) tmp.lpstrDefExt = WDL_UTF8ToWC(lpofn->lpstrDefExt,0,0,0);
  tmp.Flags = lpofn->Flags;
  tmp.lCustData = lpofn->lCustData;
  tmp.lpfnHook = lpofn->lpfnHook;
  tmp.lpTemplateName  = (const WCHAR *)lpofn->lpTemplateName ;
 
  ret=save ? GetSaveFileNameW(&tmp) : GetOpenFileNameW(&tmp);

  // free, convert output
  if (ret && lpofn->lpstrFile && tmp.lpstrFile)
  {
    if ((tmp.Flags & OFN_ALLOWMULTISELECT) && tmp.lpstrFile[wcslen(tmp.lpstrFile)+1])
    {
      char *op = lpofn->lpstrFile;
      WCHAR *ip = tmp.lpstrFile;
      while (*ip)
      {
        const int bcount = WideCharToMultiByte(CP_UTF8,0,ip,-1,NULL,0,NULL,NULL);

        const int maxout=lpofn->nMaxFile - 2 - (int)(op - lpofn->lpstrFile);
        if (maxout < 2+bcount) break;
        op += WideCharToMultiByte(CP_UTF8,0,ip,-1,op,maxout,NULL,NULL);
        ip += wcslen(ip)+1;
      }
      *op=0;
    }
    else
    {
      int len = WideCharToMultiByte(CP_UTF8,0,tmp.lpstrFile,-1,lpofn->lpstrFile,lpofn->nMaxFile-1,NULL,NULL);
      if (len == 0 && GetLastError()==ERROR_INSUFFICIENT_BUFFER) len = lpofn->nMaxFile-2;
      lpofn->lpstrFile[len]=0;
      if (!len) 
      {
        lpofn->lpstrFile[len+1]=0;
        ret=0;
      }
    }
    // convert 
  }

  lpofn->nFileOffset  = tmp.nFileOffset ;
  lpofn->nFileExtension  = tmp.nFileExtension;
  lpofn->lCustData = tmp.lCustData;

  free((WCHAR *)tmp.lpstrFilter);
  free((WCHAR *)tmp.lpstrFile);
  free((WCHAR *)tmp.lpstrFileTitle);
  free((WCHAR *)tmp.lpstrInitialDir);
  free((WCHAR *)tmp.lpstrTitle);
  free((WCHAR *)tmp.lpstrDefExt );

  lpofn->nFilterIndex  = tmp.nFilterIndex ;
  return ret;
}
Пример #24
0
int file_open_dialog(Value *vret, const char *title, RefArray *filter, WndHandle parent, int type)
{
    enum {
        RETBUF_MAX = 32 * 1024,
    };
    int ret = FALSE;
    wchar_t *title_p = cstr_to_utf16(title, -1);
    wchar_t *filter_p = NULL;
    wchar_t *wbuf = malloc(RETBUF_MAX);
    int offset = 0;

    memset(wbuf, 0, RETBUF_MAX);

    if (type == FILEOPEN_DIR) {
        BROWSEINFOW bi;
        LPMALLOC pm = NULL;

        if (SHGetMalloc(&pm) != E_FAIL) {
            ITEMIDLIST *id;

            memset(&bi, 0, sizeof(bi));
            bi.hwndOwner = parent;
            bi.ulFlags = BIF_RETURNONLYFSDIRS;
            bi.lpszTitle = title_p;

            id = SHBrowseForFolderW(&bi);
            if (id != NULL){
                SHGetPathFromIDListW(id, wbuf);
                pm->lpVtbl->Free(pm, id);
                pm->lpVtbl->Release(pm);
                ret = TRUE;
            }
        }
    } else {
        OPENFILENAMEW of;
        memset(&of, 0, sizeof(of));
        of.hwndOwner = parent;
        of.lpstrFile = wbuf;
        of.nMaxFile = RETBUF_MAX - 16;
        of.hInstance = GetModuleHandle(NULL);
        of.lStructSize = sizeof(of);
        of.Flags = OFN_NOCHANGEDIR | OFN_CREATEPROMPT;
        of.lpstrTitle = title_p;

        if (filter != NULL) {
            filter_p = make_filter_string(filter);
            of.lpstrFilter = filter_p;
        }

        switch (type) {
        case FILEOPEN_OPEN:
            of.Flags |= OFN_HIDEREADONLY;
            ret = (GetOpenFileNameW(&of) != 0);
            break;
        case FILEOPEN_OPEN_MULTI:
            of.Flags |= OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT | OFN_EXPLORER;
            ret = (GetOpenFileNameW(&of) != 0);
            offset = of.nFileOffset;
            break;
        case FILEOPEN_SAVE:
            of.Flags |= OFN_OVERWRITEPROMPT | OFN_EXTENSIONDIFFERENT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
            ret = (GetSaveFileNameW(&of) != 0);
            break;
        }
    }

    if (ret) {
        if (type == FILEOPEN_OPEN_MULTI) {
            RefArray *aret = fs->refarray_new(0);
            wchar_t *p = wbuf;
            int dlen = wcslen(p);
            *vret = vp_Value(aret);

            if (offset <= dlen) {
                array_add_file(aret, p);
            } else {
                wchar_t *dir_part = p;
                p = &p[offset];

                while (*p != L'\0'){
                    wchar_t *filename = concat_filename(dir_part, p);
                    array_add_file(aret, filename);
                    free(filename);
                    p += wcslen(p) + 1;
                }
            }
        } else {
            *vret = utf16_file_Value(wbuf);
        }
    }

    free(title_p);
    free(wbuf);
    free(filter_p);

    return ret;
}
Пример #25
0
int WINAPI
WinMain (HINSTANCE hThisInstance,
         HINSTANCE hPrevInstance,
         LPSTR lpCmdLine,
         int nCmdShow)
{
	int argc;
	WCHAR** argv;
	WCHAR szFileName[MAX_PATH] = L"";
	DWORD dwSize;
	HWND hMainWnd;
	MSG msg;
	WNDCLASSEXW wincl;
	LPCWSTR fileName;

    switch (GetUserDefaultUILanguage())
    {
    case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT):
      SetProcessDefaultLayout(LAYOUT_RTL);
      break;

    default:
      break;
    }

	g_hInstance = hThisInstance;

	/* Get unicode command line */
	argv = CommandLineToArgvW(GetCommandLineW(), &argc);
	if (argc < 2)
	{
		OPENFILENAMEW fontOpen;
        WCHAR filter[MAX_PATH], dialogTitle[MAX_PATH];

		LoadStringW(NULL, IDS_OPEN, dialogTitle, MAX_PATH);
		LoadStringW(NULL, IDS_FILTER_LIST, filter, MAX_PATH);

		/* Clears out any values of fontOpen before we use it */
		ZeroMemory(&fontOpen, sizeof(fontOpen));

		/* Sets up the open dialog box */
		fontOpen.lStructSize = sizeof(fontOpen);
		fontOpen.hwndOwner = NULL;
		fontOpen.lpstrFilter = filter;
		fontOpen.lpstrFile = szFileName;
		fontOpen.lpstrTitle = dialogTitle;
		fontOpen.nMaxFile = MAX_PATH;
		fontOpen.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
		fontOpen.lpstrDefExt = L"ttf";

		/* Opens up the Open File dialog box in order to chose a font file. */
		if(GetOpenFileNameW(&fontOpen))
		{
			fileName = fontOpen.lpstrFile;
			g_fileName = fileName;
		} else {
			/* If the user decides to close out of the open dialog effectively
			exiting the program altogether */
			return 0;
		}
	}
	else
	{
		/* Try to add the font resource from command line */
		fileName = argv[1];
		g_fileName = fileName;
	}

	if (!AddFontResourceW(fileName))
	{
		ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName);
		return -1;
	}

	/* Get the font name */
	dwSize = sizeof(g_ExtLogFontW.elfFullName);
	if (!GetFontResourceInfoW(fileName, &dwSize, g_ExtLogFontW.elfFullName, 1))
	{
		ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName);
		return -1;
	}

	dwSize = sizeof(LOGFONTW);
	if (!GetFontResourceInfoW(fileName, &dwSize, &g_ExtLogFontW.elfLogFont, 2))
	{
		ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName);
		return -1;
	}

	if (!Display_InitClass(hThisInstance))
	{
		ErrorMsgBox(0, IDS_ERROR_NOCLASS);
		return -1;
	}

	/* The main window class */
	wincl.cbSize = sizeof (WNDCLASSEXW);
	wincl.style = CS_DBLCLKS;
	wincl.lpfnWndProc = MainWndProc;
	wincl.cbClsExtra = 0;
	wincl.cbWndExtra = 0;
	wincl.hInstance = hThisInstance;
	wincl.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_TT));
	wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
	wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
	wincl.lpszMenuName = NULL;
	wincl.lpszClassName = g_szFontViewClassName;
	wincl.hIconSm = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_TT));

	/* Register the window class, and if it fails quit the program */
	if (!RegisterClassExW (&wincl))
	{
		ErrorMsgBox(0, IDS_ERROR_NOCLASS);
		return 0;
	}

	/* The class is registered, let's create the main window */
	hMainWnd = CreateWindowExW(
				0,						/* Extended possibilites for variation */
				g_szFontViewClassName,	/* Classname */
				g_ExtLogFontW.elfFullName,/* Title Text */
				WS_OVERLAPPEDWINDOW,	/* default window */
				CW_USEDEFAULT,			/* Windows decides the position */
				CW_USEDEFAULT,			/* where the window ends up on the screen */
				544,					/* The programs width */
				375,					/* and height in pixels */
				HWND_DESKTOP,			/* The window is a child-window to desktop */
				NULL,					/* No menu */
				hThisInstance,			/* Program Instance handler */
				NULL					/* No Window Creation data */
			);
	ShowWindow(hMainWnd, nCmdShow);

	/* Main message loop */
	while (GetMessage (&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	RemoveFontResourceW(argv[1]);

	return (int)msg.wParam;
}
Пример #26
0
int main()
{
	std::wstring excelFile  = _XEVOL_ABSPATH_(L"动作列表.xls");
	std::wstring excelFilex = _XEVOL_ABSPATH_(L"动作列表.xlsx");
	IExcelWriter* pExcel = createExcelWriter();
    XEVOL_LOG_REDIR(_XEVOL_ABSPATH_(L"动作列表.log.txt"));
	if(pExcel->init(excelFile.c_str() , false ) == false)
	{
         pExcel->ReleaseObject();
		 pExcel = NULL;
	}

    pExcel = createExcelWriter();
    if(pExcel->init(excelFilex.c_str() , false ) == false)
    {
        pExcel->ReleaseObject();
        pExcel = NULL;
    }

    if(pExcel == NULL)
	{
		wchar_t file_name[512]={0};
		OPENFILENAMEW ofn; 
		ZeroMemory(&ofn, sizeof(OPENFILENAMEW));
		ofn.lStructSize = sizeof(OPENFILENAMEW);
		ofn.hwndOwner = ::GetActiveWindow();
		ofn.lpstrFile = file_name;
		ofn.nMaxFile = 512;
		ofn.lpstrFilter = L"Excel文件(*.xlsx;xls)\0*.xlsx;xls\0所有文件(*.*)\0*.*\0";
		ofn.nFilterIndex = 1;
		ofn.lpstrFileTitle = NULL;
		ofn.lpstrDefExt = L"xlsx";
		ofn.nMaxFileTitle = 0;
		ofn.lpstrInitialDir = NULL;
		ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
		if(GetOpenFileNameW(&ofn) == FALSE)
		{
			return 1;
		}

		excelFilex = file_name;
		pExcel = createExcelWriter();
		if(pExcel->init(excelFilex.c_str() , false ) == false)
		{
			pExcel->ReleaseObject();
			pExcel = NULL;
		}
	}


    IExcelSheet* pActioListSheet = NULL;
    pActioListSheet = pExcel->get_Sheet((int)1);
    if(pActioListSheet == NULL)
    {
        XSAFE_RELEASEOBJECT(pExcel);
        return 1;
    }

    xXmlDocument doc;
	doc.load(_XEVOL_ABSPATH_(L".\\动作列表.xml"));
    xXmlNode* pRootNode =doc.root();
    if(pRootNode == NULL)
    {
        pRootNode = doc.insertNode(L"所有动作");
    }
    int nBlankLine  = 0;
    int iLine = 2;
    std::wstring lastMaxFile = L"";
    while(1)
    {
        wchar_t startFrame[256] = {0};
        wchar_t endFrame  [256] = {0};
        wchar_t actionName[256] = {0};
        wchar_t maxFile   [256] = {0};
        wchar_t actionTime[256] = {0};
        pActioListSheet->get_Value(1 , iLine , startFrame, 256);
        pActioListSheet->get_Value(2 , iLine , endFrame  , 256);
        pActioListSheet->get_Value(3 , iLine , actionName, 256);
        pActioListSheet->get_Value(4 , iLine , maxFile   , 256);
        pActioListSheet->get_Value(5 , iLine , actionTime, 256);
        iLine ++;
        nBlankLine ++;
        if(wcslen_x(startFrame) > 0 )
        {
            nBlankLine = 0;
        }
        if(nBlankLine > 10)
            break;

        if(wcslen_x(maxFile) != 0)
        {
            lastMaxFile = maxFile;
        }

        if( wcslen_x(startFrame) == 0 || wcslen_x(endFrame)  == 0  || wcslen_x(actionName) == 0  )
        {
            continue;
        }

        std::wstring _actionName  = TrimSpace(actionName);
        std::wstring _maxFileName = TrimSpace(lastMaxFile.c_str() );
		if(_maxFileName.find(L".max") == std::wstring::npos &&
           _maxFileName.find(L".Max") == std::wstring::npos &&
           _maxFileName.find(L".MAX") == std::wstring::npos)
		{
			_maxFileName += L".max";
		}

        for(int i = 0 ; i < pRootNode->countNode() ; i ++)
        {
            xXmlNode* pActionNode = pRootNode->findNode(i);
            if(pActionNode->value(L"ActionName") == _actionName )
            {
                XEVOL_LOG(eXL_ERROR_FALT , L"动作名重复 name=%s " , _actionName.c_str() );
                XEVOL_LOG(eXL_ERROR_FALT , L"原始[%s , %d-%d] "   , pActionNode->value(L"MaxFile") , pActionNode->int_value(L"StartFrame"), pActionNode->int_value(L"EndFrame") );
                XEVOL_LOG(eXL_ERROR_FALT , L"重复[%s , %d-%d] \n"   , _maxFileName.c_str() , startFrame , endFrame );
                continue;
            }
        }

        xXmlNode* pActionNode = pRootNode->insertNode(L"动作");
        pActionNode->setValue(L"StartFrame" , startFrame);
        pActionNode->setValue(L"EndFrame"   , endFrame  );
        pActionNode->setValue(L"ActionName" , _actionName.c_str() );
        pActionNode->setValue(L"MaxFile"    , _maxFileName.c_str() );

        if(wcslen_x(actionTime) > 0)
        {
            pActionNode->setValue(L"DurTime" , actionTime);
        }
         

    }

    system("PAUSE");
	
    doc.save(_XEVOL_ABSPATH_(L".\\动作列表.xml"));
    XSAFE_RELEASEOBJECT(pActioListSheet);
	pExcel->close();
    XSAFE_RELEASEOBJECT(pExcel);
    
    XEVOL_LOG_CLOSE();
    return 0;

}
Пример #27
0
/*
	ANT_CANVAS::LOAD_FILE()
	-----------------------
*/
long long ANT_canvas::load_file(void)
{
long long lines;
IFileDialog *pfd = NULL;
IShellItem *psiResult;
DWORD dwFlags;
PWSTR pszFilePath = NULL;
char chosen_filter[1024];
char chosen_filename[MAX_PATH];
OPENFILENAME parameters;

/*
	Create the Open Dialg object IFileDialog
*/
if ((CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd)) == S_OK))
	{
	/*
		we're on VISTA / Windows 7 or later
	*/
	const COMDLG_FILTERSPEC c_rgSaveTypes[] =
	{
	{L"C/C++ files",		L"*.c;*.cxx;*.cpp;*.h;*.hpp.*.hxx;*.mak;makefile"},
	{L"All Documents (*.*)",		L"*.*"}
	};

	pfd->GetOptions(&dwFlags);
	pfd->SetOptions(dwFlags | FOS_FORCEFILESYSTEM);					// we want to see a file
	pfd->SetFileTypes(ARRAYSIZE(c_rgSaveTypes), c_rgSaveTypes);
	pfd->SetFileTypeIndex(1);										// first item in the list is the default
	pfd->SetDefaultExtension(L"doc;docx");
	if (pfd->Show(NULL) == S_OK)
		{
		if (pfd->GetResult(&psiResult) == S_OK)						// get the result object if the user clicks "Open"
			{
			psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);

			lines = file->read_file((char *)pszFilePath);

			CoTaskMemFree(pszFilePath);
			psiResult->Release();
			}
		}
	pfd->Release();

	return lines;
	}
else
	{
	/*
		we're on something prior to VISTA (NT through to XP) so use the old-style common control
	*/
	memset(chosen_filename, 0, sizeof(chosen_filename));

	parameters.lStructSize = sizeof(parameters);
	parameters.hwndOwner = window;
	parameters.hInstance = hInstance;
	parameters.lpstrFilter = L"C/C++ files\0*.c;*.cxx;*.cpp;*.h;*.hpp.*.hxx\0\0\0";
	parameters.lpstrCustomFilter = (LPWSTR)chosen_filter;
	parameters.nMaxCustFilter = sizeof(chosen_filter) - 1;
	parameters.nFilterIndex = 1;
	parameters.lpstrFile = (LPWSTR)chosen_filename;
	parameters.nMaxFile = sizeof(chosen_filename) - 1;
	parameters.lpstrFileTitle = NULL;
	parameters.nMaxFileTitle = 0;
	parameters.lpstrInitialDir = NULL;
	parameters.lpstrTitle = L"Open...";
	parameters.Flags = OFN_LONGNAMES;
	parameters.nFileOffset = 0;
	parameters.nFileExtension = 0;
	parameters.lpstrDefExt = NULL;
	parameters.lCustData = 0;
	parameters.lpfnHook = NULL;
	parameters.lpTemplateName = 0;
	#if (_WIN32_WINNT >= 0x0500)
		parameters.pvReserved = NULL;
		parameters.dwReserved = 0;
		parameters.FlagsEx = 0;
	#endif

	if ((GetOpenFileNameW(&parameters)) != 0)
		return file->read_file((char *)parameters.lpstrFile);
	}

return 0;
}
Пример #28
0
INT_PTR CALLBACK PickIconProc(HWND hwndDlg,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam
)
{
    LPMEASUREITEMSTRUCT lpmis; 
    LPDRAWITEMSTRUCT lpdis; 
    HICON hIcon;
    INT index, count;
    WCHAR szText[MAX_PATH], szTitle[100], szFilter[100];
    OPENFILENAMEW ofn = {0};

    PPICK_ICON_CONTEXT pIconContext = (PPICK_ICON_CONTEXT)GetWindowLongPtr(hwndDlg, DWLP_USER);

    switch(uMsg)
    {
    case WM_INITDIALOG:
        pIconContext = (PPICK_ICON_CONTEXT)lParam;
        SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG)pIconContext);
        pIconContext->hDlgCtrl = GetDlgItem(hwndDlg, IDC_PICKICON_LIST);
        EnumResourceNamesW(pIconContext->hLibrary, RT_ICON, EnumPickIconResourceProc, (LPARAM)pIconContext);
        if (PathUnExpandEnvStringsW(pIconContext->szName, szText, MAX_PATH))
            SetDlgItemTextW(hwndDlg, IDC_EDIT_PATH, szText);
        else
            SetDlgItemTextW(hwndDlg, IDC_EDIT_PATH, pIconContext->szName);

        count = SendMessage(pIconContext->hDlgCtrl, LB_GETCOUNT, 0, 0);
        if (count != LB_ERR)
        {
            if (count > pIconContext->Index)
                SendMessageW(pIconContext->hDlgCtrl, LB_SETCURSEL, pIconContext->Index, 0);
            else
                SendMessageW(pIconContext->hDlgCtrl, LB_SETCURSEL, 0, 0);
        }
        return TRUE;
    case WM_COMMAND:
        switch(LOWORD(wParam))
        {
        case IDOK:
            index = SendMessageW(pIconContext->hDlgCtrl, LB_GETCURSEL, 0, 0);
            pIconContext->Index = index;
            GetDlgItemTextW(hwndDlg, IDC_EDIT_PATH, pIconContext->szName, MAX_PATH);
            DestroyIconList(pIconContext->hDlgCtrl);
            EndDialog(hwndDlg, 1);
            break;
        case IDCANCEL:
            DestroyIconList(pIconContext->hDlgCtrl);
            EndDialog(hwndDlg, 0);
            break;
        case IDC_PICKICON_LIST:
            if (HIWORD(wParam) == LBN_SELCHANGE)
                InvalidateRect((HWND)lParam, NULL, TRUE); // FIXME USE UPDATE RECT
            break;
        case IDC_BUTTON_PATH:
            szText[0] = 0;
            szTitle[0] = 0;
            szFilter[0] = 0;
            ofn.lStructSize = sizeof(ofn);
            ofn.hwndOwner = hwndDlg;
            ofn.lpstrFile = szText;
            ofn.nMaxFile = MAX_PATH;
            LoadStringW(shell32_hInstance, IDS_PICK_ICON_TITLE, szTitle, sizeof(szTitle) / sizeof(WCHAR));
            ofn.lpstrTitle = szTitle;
            LoadStringW(shell32_hInstance, IDS_PICK_ICON_FILTER, szFilter, sizeof(szFilter) / sizeof(WCHAR));
            ofn.lpstrFilter = szFilter;
            if (GetOpenFileNameW(&ofn))
            {
                HMODULE hLibrary;

                if (!wcsicmp(pIconContext->szName, szText))
                    break;

                DestroyIconList(pIconContext->hDlgCtrl);

                hLibrary = LoadLibraryExW(szText, NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE);
                if (hLibrary == NULL)
                    break;
                FreeLibrary(pIconContext->hLibrary);
                pIconContext->hLibrary = hLibrary;
                wcscpy(pIconContext->szName, szText);
                EnumResourceNamesW(pIconContext->hLibrary, RT_ICON, EnumPickIconResourceProc, (LPARAM)pIconContext);
                if (PathUnExpandEnvStringsW(pIconContext->szName, szText, MAX_PATH))
                    SetDlgItemTextW(hwndDlg, IDC_EDIT_PATH, szText);
                else
                    SetDlgItemTextW(hwndDlg, IDC_EDIT_PATH, pIconContext->szName);

                SendMessageW(pIconContext->hDlgCtrl, LB_SETCURSEL, 0, 0);
            }
            break;
        }
        break;
        case WM_MEASUREITEM:
            lpmis = (LPMEASUREITEMSTRUCT) lParam; 
            lpmis->itemHeight = 32;
            lpmis->itemWidth = 64;
            return TRUE; 
        case WM_DRAWITEM: 
            lpdis = (LPDRAWITEMSTRUCT) lParam; 
           if (lpdis->itemID == (UINT)-1) 
            { 
                break; 
            } 
            switch (lpdis->itemAction) 
            { 
                case ODA_SELECT: 
                case ODA_DRAWENTIRE:
                    index = SendMessageW(pIconContext->hDlgCtrl, LB_GETCURSEL, 0, 0);
                    hIcon =(HICON)SendMessage(lpdis->hwndItem, LB_GETITEMDATA, lpdis->itemID, (LPARAM) 0);

                    if (lpdis->itemID == (UINT)index)
                    {
                        HBRUSH hBrush;
                        hBrush = CreateSolidBrush(RGB(0, 0, 255));
                        FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
                        DeleteObject(hBrush);
                    }
                    else
                    {
                        HBRUSH hBrush;
                        hBrush = CreateSolidBrush(RGB(255, 255, 255));
                        FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
                        DeleteObject(hBrush);
                    }
                    DrawIconEx(lpdis->hDC, lpdis->rcItem.left,lpdis->rcItem.top, hIcon, 
                                0,
                                0,
                                0,
                                NULL,
                                DI_NORMAL);
                    break;
            }
            break;
    }

    return FALSE;
}
Пример #29
0
/* bug 6829 */
static void test_DialogCancel(void)
{
    OPENFILENAMEA ofn;
    BOOL result;
    char szFileName[MAX_PATH] = "";
    char szInitialDir[MAX_PATH];

    GetWindowsDirectory(szInitialDir, MAX_PATH);

    ZeroMemory(&ofn, sizeof(ofn));

    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = NULL;
    ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
    ofn.lpstrFile = szFileName;
    ofn.nMaxFile = MAX_PATH;
    ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLEHOOK;
    ofn.lpstrDefExt = "txt";
    ofn.lpfnHook = OFNHookProc;
    ofn.lpstrInitialDir = szInitialDir;

    PrintDlgA(NULL);
    ok(CDERR_INITIALIZATION == CommDlgExtendedError(),
       "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());

    result = GetOpenFileNameA(&ofn);
    ok(0 == result, "expected 0, got %d\n", result);
    ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
       CommDlgExtendedError());

    PrintDlgA(NULL);
    ok(CDERR_INITIALIZATION == CommDlgExtendedError(),
       "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());

    result = GetSaveFileNameA(&ofn);
    ok(0 == result, "expected 0, got %d\n", result);
    ok(0 == CommDlgExtendedError(), "expected 0, got %d\n",
       CommDlgExtendedError());

    PrintDlgA(NULL);
    ok(CDERR_INITIALIZATION == CommDlgExtendedError(),
       "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());

    /* Before passing the ofn to Unicode functions, remove the ANSI strings */
    ofn.lpstrFilter = NULL;
    ofn.lpstrInitialDir = NULL;
    ofn.lpstrDefExt = NULL;

    PrintDlgA(NULL);
    ok(CDERR_INITIALIZATION == CommDlgExtendedError(),
       "expected CDERR_INITIALIZATION, got %d\n", CommDlgExtendedError());

    SetLastError(0xdeadbeef);
    result = GetOpenFileNameW((LPOPENFILENAMEW) &ofn);
    if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
        win_skip("GetOpenFileNameW is not implemented\n");
    else
    {
        ok(0 == result, "expected 0, got %d\n", result);
        ok(0 == CommDlgExtendedError() ||
           broken(CDERR_INITIALIZATION == CommDlgExtendedError()), /* win9x */
           "expected 0, got %d\n", CommDlgExtendedError());
    }

    SetLastError(0xdeadbeef);
    result = GetSaveFileNameW((LPOPENFILENAMEW) &ofn);
    if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
        win_skip("GetSaveFileNameW is not implemented\n");
    else
    {
        ok(0 == result, "expected 0, got %d\n", result);
        ok(0 == CommDlgExtendedError() ||
           broken(CDERR_INITIALIZATION == CommDlgExtendedError()), /* win9x */
           "expected 0, got %d\n", CommDlgExtendedError());
    }
}
Пример #30
0
static int MenuCommand(WPARAM wParam, HWND hWnd)
{
    BOOL vis;
    HTREEITEM hSelect;
    WCHAR wszAbout[MAX_LOAD_STRING];
    WCHAR wszAboutVer[MAX_LOAD_STRING];

    switch(wParam)
    {
        case IDM_ABOUT:
            LoadStringW(globals.hMainInst, IDS_ABOUT, wszAbout,
                    sizeof(wszAbout)/sizeof(wszAbout[0]));
            LoadStringW(globals.hMainInst, IDS_ABOUTVER, wszAboutVer,
                    sizeof(wszAboutVer)/sizeof(wszAboutVer[0]));
            ShellAboutW(hWnd, wszAbout, wszAboutVer, NULL);
            break;
        case IDM_COPYCLSID:
            hSelect = (HTREEITEM)SendMessageW(globals.hTree,
                    TVM_GETNEXTITEM, TVGN_CARET, 0);
            CopyClsid(hSelect);
            break;
        case IDM_HTMLTAG:
            hSelect = (HTREEITEM)SendMessageW(globals.hTree,
                    TVM_GETNEXTITEM, TVGN_CARET, 0);
            CopyHTMLTag(hSelect);
            break;
        case IDM_CREATEINST:
            hSelect = (HTREEITEM)SendMessageW(globals.hTree,
                    TVM_GETNEXTITEM, TVGN_CARET, 0);
            CreateInst(hSelect, NULL);
            SendMessageW(globals.hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)hSelect);
            break;
        case IDM_CREATEINSTON:
            if(DialogBoxW(0, MAKEINTRESOURCEW(DLG_CREATEINSTON),
                        hWnd, CreateInstOnProc) == IDCANCEL) break;
            hSelect = (HTREEITEM)SendMessageW(globals.hTree,
                    TVM_GETNEXTITEM, TVGN_CARET, 0);
            CreateInst(hSelect, globals.wszMachineName);
            SendMessageW(globals.hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)hSelect);
            break;
        case IDM_RELEASEINST:
            hSelect = (HTREEITEM)SendMessageW(globals.hTree,
                    TVM_GETNEXTITEM, TVGN_CARET, 0);
            ReleaseInst(hSelect);
            RefreshMenu(hSelect);
            RefreshDetails(hSelect);
            break;
        case IDM_EXPERT:
            globals.bExpert = !globals.bExpert;
            CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
                    globals.bExpert ? MF_CHECKED : MF_UNCHECKED);
            EmptyTree();
            if(globals.bExpert) AddTreeEx();
            else AddTree();
            hSelect = (HTREEITEM)SendMessageW(globals.hTree,
                    TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)TVI_ROOT);
            SendMessageW(globals.hTree, TVM_SELECTITEM, 0, (LPARAM)hSelect);
            RefreshMenu(hSelect);
            break;
        case IDM_FLAG_INSERV:
            vis = globals.dwClsCtx&CLSCTX_INPROC_SERVER;
            globals.dwClsCtx = globals.dwClsCtx&(~CLSCTX_INPROC_SERVER);
            globals.dwClsCtx = globals.dwClsCtx|((~vis)&CLSCTX_INPROC_SERVER);
            if(!globals.dwClsCtx) globals.dwClsCtx = vis;
            else CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
                    vis ? MF_UNCHECKED : MF_CHECKED);
            break;
        case IDM_FLAG_INHANDL:
            vis = globals.dwClsCtx&CLSCTX_INPROC_HANDLER;
            globals.dwClsCtx = globals.dwClsCtx&(~CLSCTX_INPROC_HANDLER);
            globals.dwClsCtx = globals.dwClsCtx|((~vis)&CLSCTX_INPROC_HANDLER);
            if(!globals.dwClsCtx) globals.dwClsCtx = vis;
            else CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
                    vis ? MF_UNCHECKED : MF_CHECKED);
            break;
        case IDM_FLAG_LOCSERV:
            vis = globals.dwClsCtx&CLSCTX_LOCAL_SERVER;
            globals.dwClsCtx = globals.dwClsCtx&(~CLSCTX_LOCAL_SERVER);
            globals.dwClsCtx = globals.dwClsCtx|((~vis)&CLSCTX_LOCAL_SERVER);
            if(!globals.dwClsCtx) globals.dwClsCtx = vis;
            else CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
                    vis ? MF_UNCHECKED : MF_CHECKED);
            break;
        case IDM_FLAG_REMSERV:
            vis = globals.dwClsCtx&CLSCTX_REMOTE_SERVER;
            globals.dwClsCtx = globals.dwClsCtx&(~CLSCTX_REMOTE_SERVER);
            globals.dwClsCtx = globals.dwClsCtx|((~vis)&CLSCTX_REMOTE_SERVER);
            if(!globals.dwClsCtx) globals.dwClsCtx = vis;
            else CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
                    vis ? MF_UNCHECKED : MF_CHECKED);
            break;
        case IDM_REFRESH:
            EmptyTree();
            if(globals.bExpert) AddTreeEx();
            else AddTree();
            hSelect = (HTREEITEM)SendMessageW(globals.hTree,
                    TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)TVI_ROOT);
            SendMessageW(globals.hTree, TVM_SELECTITEM, 0, (LPARAM)hSelect);
            RefreshMenu(hSelect);
            break;
        case IDM_REGEDIT:
        {
            STARTUPINFOW si;
            PROCESS_INFORMATION pi;
            WCHAR app[MAX_PATH];

            GetWindowsDirectoryW( app, MAX_PATH - sizeof(wszRegEdit)/sizeof(WCHAR) );
            lstrcatW( app, wszRegEdit );
            memset(&si, 0, sizeof(si));
            si.cb = sizeof(si);
            if (CreateProcessW(app, app, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
            {
                CloseHandle(pi.hProcess);
                CloseHandle(pi.hThread);
            }
            break;
        }
        case IDM_STATUSBAR:
            vis = IsWindowVisible(globals.hStatusBar);
            ShowWindow(globals.hStatusBar, vis ? SW_HIDE : SW_SHOW);
            CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
                    vis ? MF_UNCHECKED : MF_CHECKED);
            ResizeChild();
            break;
        case IDM_SYSCONF:
            DialogBoxW(0, MAKEINTRESOURCEW(DLG_SYSCONF), hWnd, SysConfProc);
            break;
        case IDM_TOOLBAR:
            vis = IsWindowVisible(globals.hToolBar);
            ShowWindow(globals.hToolBar, vis ? SW_HIDE : SW_SHOW);
            CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
                    vis ? MF_UNCHECKED : MF_CHECKED);
            ResizeChild();
            break;
        case IDM_TYPELIB:
            {
            static const WCHAR filterW[] = {'%','s','%','c','*','.','t','l','b',';','*','.','o','l','b',';','*','.','d','l','l',';','*','.','o','c','x',';','*','.','e','x','e','%','c','%','s','%','c','*','.','*','%','c',0};
            OPENFILENAMEW ofn;
            static WCHAR wszTitle[MAX_LOAD_STRING];
            static WCHAR wszName[MAX_LOAD_STRING];
            WCHAR filter_typelib[MAX_LOAD_STRING], filter_all[MAX_LOAD_STRING], filter[MAX_PATH];

            LoadStringW(globals.hMainInst, IDS_OPEN, wszTitle, sizeof(wszTitle)/sizeof(wszTitle[0]));
            LoadStringW(globals.hMainInst, IDS_OPEN_FILTER_TYPELIB, filter_typelib, sizeof(filter_typelib)/sizeof(WCHAR));
            LoadStringW(globals.hMainInst, IDS_OPEN_FILTER_ALL, filter_all, sizeof(filter_all)/sizeof(WCHAR));
            snprintfW( filter, MAX_PATH, filterW, filter_typelib, 0, 0, filter_all, 0, 0 );
            InitOpenFileName(hWnd, &ofn, filter, wszTitle, wszName);
            if(GetOpenFileNameW(&ofn)) CreateTypeLibWindow(globals.hMainInst, wszName);
            break;
            }
        case IDM_VIEW:
            hSelect = (HTREEITEM)SendMessageW(globals.hTree,
                    TVM_GETNEXTITEM, TVGN_CARET, 0);
            if(IsInterface(hSelect)) InterfaceViewer(hSelect);
            else CreateTypeLibWindow(globals.hMainInst, NULL);
            break;
        case IDM_EXIT:
            DestroyWindow(hWnd);
            break;
    }
    return 0;
}