📄 filedlg31.c
字号:
else
GetCurrentDirectoryW(BUFFILE, tmpstr2);
lenstr2 = strlenW(tmpstr2);
if (lenstr2 > 3)
tmpstr2[lenstr2++]='\\';
lstrcpynW(tmpstr2+lenstr2, tmpstr, BUFFILE-lenstr2);
if (ofnW->lpstrFile)
lstrcpynW(ofnW->lpstrFile, tmpstr2, ofnW->nMaxFile);
/* set filename offset */
p = PathFindFileNameW(ofnW->lpstrFile);
ofnW->nFileOffset = (p - ofnW->lpstrFile);
/* set extension offset */
p = PathFindExtensionW(ofnW->lpstrFile);
ofnW->nFileExtension = (*p) ? (p - ofnW->lpstrFile) + 1 : 0;
TRACE("file %s, file offset %d, ext offset %d\n",
debugstr_w(ofnW->lpstrFile), ofnW->nFileOffset, ofnW->nFileExtension);
/* update the real client structures if any */
lfs->callbacks->UpdateResult(lfs);
}
/***********************************************************************
* FD31_UpdateFileTitle [internal]
* update the displayed file name (without path)
*/
static void FD31_UpdateFileTitle(const FD31_DATA *lfs)
{
LONG lRet;
LPOPENFILENAMEW ofnW = lfs->ofnW;
if (ofnW->lpstrFileTitle != NULL)
{
lRet = SendDlgItemMessageW(lfs->hwnd, lst1, LB_GETCURSEL, 0, 0);
SendDlgItemMessageW(lfs->hwnd, lst1, LB_GETTEXT, lRet,
(LPARAM)ofnW->lpstrFileTitle );
lfs->callbacks->UpdateFileTitle(lfs);
}
}
/***********************************************************************
* FD31_DirListDblClick [internal]
*/
static LRESULT FD31_DirListDblClick( const FD31_DATA *lfs )
{
LONG lRet;
HWND hWnd = lfs->hwnd;
LPWSTR pstr;
WCHAR tmpstr[BUFFILE];
/* get the raw string (with brackets) */
lRet = SendDlgItemMessageW(hWnd, lst2, LB_GETCURSEL, 0, 0);
if (lRet == LB_ERR) return TRUE;
pstr = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC);
SendDlgItemMessageW(hWnd, lst2, LB_GETTEXT, lRet,
(LPARAM)pstr);
strcpyW( tmpstr, pstr );
HeapFree(GetProcessHeap(), 0, pstr);
/* get the selected directory in tmpstr */
if (tmpstr[0] == '[')
{
tmpstr[lstrlenW(tmpstr) - 1] = 0;
strcpyW(tmpstr,tmpstr+1);
}
strcatW(tmpstr, FILE_bslash);
FD31_ScanDir(hWnd, tmpstr);
/* notify the app */
if (lfs->hook)
{
if (FD31_CallWindowProc(lfs, lfs->lbselchstring, lst2,
MAKELONG(lRet,CD_LBSELCHANGE)))
return TRUE;
}
return TRUE;
}
/***********************************************************************
* FD31_FileListSelect [internal]
* called when a new item is picked in the file list
*/
static LRESULT FD31_FileListSelect( const FD31_DATA *lfs )
{
LONG lRet;
HWND hWnd = lfs->hwnd;
LPWSTR pstr;
lRet = lfs->callbacks->SendLbGetCurSel(lfs);
if (lRet == LB_ERR)
return TRUE;
/* set the edit control to the choosen file */
if ((pstr = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC)))
{
SendDlgItemMessageW(hWnd, lst1, LB_GETTEXT, lRet,
(LPARAM)pstr);
SetDlgItemTextW( hWnd, edt1, pstr );
HeapFree(GetProcessHeap(), 0, pstr);
}
if (lfs->hook)
{
FD31_CallWindowProc(lfs, lfs->lbselchstring, lst1,
MAKELONG(lRet,CD_LBSELCHANGE));
}
/* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD,
CD_LBSELNOITEMS */
return TRUE;
}
/***********************************************************************
* FD31_TestPath [internal]
* before accepting the file name, test if it includes wild cards
* tries to scan the directory and returns TRUE if no error.
*/
static LRESULT FD31_TestPath( const FD31_DATA *lfs, LPWSTR path )
{
HWND hWnd = lfs->hwnd;
LPWSTR pBeginFileName, pstr2;
WCHAR tmpstr2[BUFFILE];
pBeginFileName = strrchrW(path, '\\');
if (pBeginFileName == NULL)
pBeginFileName = strrchrW(path, ':');
if (strchrW(path,'*') != NULL || strchrW(path,'?') != NULL)
{
/* edit control contains wildcards */
if (pBeginFileName != NULL)
{
lstrcpynW(tmpstr2, pBeginFileName + 1, BUFFILE);
*(pBeginFileName + 1) = 0;
}
else
{
strcpyW(tmpstr2, path);
if(!(lfs->ofnW->Flags & OFN_NOVALIDATE))
*path = 0;
}
TRACE("path=%s, tmpstr2=%s\n", debugstr_w(path), debugstr_w(tmpstr2));
SetDlgItemTextW( hWnd, edt1, tmpstr2 );
FD31_ScanDir(hWnd, path);
return (lfs->ofnW->Flags & OFN_NOVALIDATE) ? TRUE : FALSE;
}
/* no wildcards, we might have a directory or a filename */
/* try appending a wildcard and reading the directory */
pstr2 = path + lstrlenW(path);
if (pBeginFileName == NULL || *(pBeginFileName + 1) != 0)
strcatW(path, FILE_bslash);
/* if ScanDir succeeds, we have changed the directory */
if (FD31_ScanDir(hWnd, path))
return FALSE; /* and path is not a valid file name */
/* if not, this must be a filename */
*pstr2 = 0; /* remove the wildcard added before */
if (pBeginFileName != NULL)
{
/* strip off the pathname */
*pBeginFileName = 0;
SetDlgItemTextW( hWnd, edt1, pBeginFileName + 1 );
lstrcpynW(tmpstr2, pBeginFileName + 1, sizeof(tmpstr2)/sizeof(WCHAR) );
/* Should we MessageBox() if this fails? */
if (!FD31_ScanDir(hWnd, path))
{
return FALSE;
}
strcpyW(path, tmpstr2);
}
else
SetDlgItemTextW( hWnd, edt1, path );
return TRUE;
}
/***********************************************************************
* FD31_Validate [internal]
* called on: click Ok button, Enter in edit, DoubleClick in file list
*/
static LRESULT FD31_Validate( const FD31_DATA *lfs, LPCWSTR path, UINT control, INT itemIndex,
BOOL internalUse )
{
LONG lRet;
HWND hWnd = lfs->hwnd;
OPENFILENAMEW ofnsav;
LPOPENFILENAMEW ofnW = lfs->ofnW;
WCHAR filename[BUFFILE];
ofnsav = *ofnW; /* for later restoring */
/* get current file name */
if (path)
lstrcpynW(filename, path, sizeof(filename)/sizeof(WCHAR));
else
GetDlgItemTextW( hWnd, edt1, filename, sizeof(filename)/sizeof(WCHAR));
TRACE("got filename = %s\n", debugstr_w(filename));
/* if we did not click in file list to get there */
if (control != lst1)
{
if (!FD31_TestPath( lfs, filename) )
return FALSE;
}
FD31_UpdateResult(lfs, filename);
if (internalUse)
{ /* called internally after a change in a combo */
if (lfs->hook)
{
FD31_CallWindowProc(lfs, lfs->lbselchstring, control,
MAKELONG(itemIndex,CD_LBSELCHANGE));
}
return TRUE;
}
FD31_UpdateFileTitle(lfs);
if (lfs->hook)
{
lRet = (BOOL)FD31_CallWindowProc(lfs, lfs->fileokstring,
0, lfs->lParam );
if (lRet)
{
*ofnW = ofnsav; /* restore old state */
return FALSE;
}
}
if ((ofnW->Flags & OFN_ALLOWMULTISELECT) && (ofnW->Flags & OFN_EXPLORER))
{
if (ofnW->lpstrFile)
{
LPWSTR str = (LPWSTR)ofnW->lpstrFile;
LPWSTR ptr = strrchrW(str, '\\');
str[lstrlenW(str) + 1] = '\0';
*ptr = 0;
}
}
return TRUE;
}
/***********************************************************************
* FD31_DiskChange [internal]
* called when a new item is picked in the disk selection combo
*/
static LRESULT FD31_DiskChange( const FD31_DATA *lfs )
{
LONG lRet;
HWND hWnd = lfs->hwnd;
LPWSTR pstr;
WCHAR diskname[BUFFILE];
FD31_StripEditControl(hWnd);
lRet = SendDlgItemMessageW(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
if (lRet == LB_ERR)
return 0;
pstr = HeapAlloc(GetProcessHeap(), 0, BUFFILEALLOC);
SendDlgItemMessageW(hWnd, cmb2, CB_GETLBTEXT, lRet,
(LPARAM)pstr);
wsprintfW(diskname, FILE_specc, pstr[2]);
HeapFree(GetProcessHeap(), 0, pstr);
return FD31_Validate( lfs, diskname, cmb2, lRet, TRUE );
}
/***********************************************************************
* FD31_FileTypeChange [internal]
* called when a new item is picked in the file type combo
*/
static LRESULT FD31_FileTypeChange( const FD31_DATA *lfs )
{
LONG lRet;
LPWSTR pstr;
lRet = SendDlgItemMessageW(lfs->hwnd, cmb1, CB_GETCURSEL, 0, 0);
if (lRet == LB_ERR)
return TRUE;
pstr = (LPWSTR)SendDlgItemMessageW(lfs->hwnd, cmb1, CB_GETITEMDATA, lRet, 0);
TRACE("Selected filter : %s\n", debugstr_w(pstr));
SetDlgItemTextW( lfs->hwnd, edt1, pstr );
return FD31_Validate( lfs, NULL, cmb1, lRet, TRUE );
}
/***********************************************************************
* FD31_WMCommand [internal]
*/
LRESULT FD31_WMCommand(HWND hWnd, LPARAM lParam, UINT notification,
UINT control, const FD31_DATA *lfs )
{
switch (control)
{
case lst1: /* file list */
FD31_StripEditControl(hWnd);
if (notification == LBN_DBLCLK)
{
return SendMessageW(hWnd, WM_COMMAND, IDOK, 0);
}
else if (notification == LBN_SELCHANGE)
return FD31_FileListSelect( lfs );
break;
case lst2: /* directory list */
FD31_StripEditControl(hWnd);
if (notification == LBN_DBLCLK)
return FD31_DirListDblClick( lfs );
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -