[MSPAINT] Simplify OFNHookProc and FileExtFromFilter

... by using PathFindExtension and PathFindFileName.
CORE-18867
This commit is contained in:
Katayama Hirofumi MZ 2023-03-22 10:42:21 +09:00
parent be518f9f5a
commit 5c8d578a15

View file

@ -57,7 +57,7 @@ CTextEditWindow textEditWindow;
// get file name extension from filter string // get file name extension from filter string
static BOOL static BOOL
FileExtFromFilter(LPTSTR pExt, LPCTSTR pTitle, OPENFILENAME *pOFN) FileExtFromFilter(LPTSTR pExt, OPENFILENAME *pOFN)
{ {
LPTSTR pchExt = pExt; LPTSTR pchExt = pExt;
*pchExt = 0; *pchExt = 0;
@ -96,19 +96,9 @@ OFNHookProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
hParent = GetParent(hwnd); hParent = GetParent(hwnd);
TCHAR Path[MAX_PATH]; TCHAR Path[MAX_PATH];
SendMessage(hParent, CDM_GETFILEPATH, _countof(Path), (LPARAM)Path); SendMessage(hParent, CDM_GETFILEPATH, _countof(Path), (LPARAM)Path);
LPTSTR pchTitle = _tcsrchr(Path, _T('\\')); FileExtFromFilter(PathFindExtension(Path), pon->lpOFN);
if (pchTitle == NULL) SendMessage(hParent, CDM_SETCONTROLTEXT, 0x047c, (LPARAM)PathFindFileName(Path));
pchTitle = _tcsrchr(Path, _T('/')); lstrcpyn(pon->lpOFN->lpstrFile, Path, pon->lpOFN->nMaxFile);
LPTSTR pch = _tcsrchr((pchTitle ? pchTitle : Path), _T('.'));
if (pch && pchTitle)
{
pchTitle++;
*pch = 0;
FileExtFromFilter(pch, pchTitle, pon->lpOFN);
SendMessage(hParent, CDM_SETCONTROLTEXT, 0x047c, (LPARAM)pchTitle);
lstrcpyn(pon->lpOFN->lpstrFile, Path, pon->lpOFN->nMaxFile);
}
} }
break; break;
} }