📄 filedlg16.c
字号:
/*
* COMMDLG - File Dialogs
*
* Copyright 1994 Martin Ayotte
* Copyright 1996 Albrecht Kleine
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wine/winbase16.h"
#include "winuser.h"
#include "wine/winuser16.h"
#include "wine/debug.h"
#include "cderr.h"
#include "commdlg.h"
WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
#include "cdlg.h"
#include "cdlg16.h"
#include "filedlg31.h"
typedef struct tagFD16_PRIVATE
{
HANDLE16 hDlgTmpl16; /* handle for resource 16 */
HANDLE16 hResource16; /* handle for allocated resource 16 */
HANDLE16 hGlobal16; /* 16 bits mem block (resources) */
OPENFILENAME16 *ofn16; /* original structure if 16 bits dialog */
} FD16_PRIVATE, *PFD16_PRIVATE;
/************************************************************************
* FD16_MapOfnStruct16 [internal]
* map a 16 bits structure to an Unicode one
*/
static void FD16_MapOfnStruct16(const OPENFILENAME16 *ofn16, LPOPENFILENAMEW ofnW, BOOL open)
{
OPENFILENAMEA ofnA;
/* first convert to linear pointers */
memset(&ofnA, 0, sizeof(OPENFILENAMEA));
ofnA.lStructSize = sizeof(OPENFILENAMEA);
ofnA.hwndOwner = HWND_32(ofn16->hwndOwner);
ofnA.hInstance = HINSTANCE_32(ofn16->hInstance);
if (ofn16->lpstrFilter)
ofnA.lpstrFilter = MapSL(ofn16->lpstrFilter);
if (ofn16->lpstrCustomFilter)
ofnA.lpstrCustomFilter = MapSL(ofn16->lpstrCustomFilter);
ofnA.nMaxCustFilter = ofn16->nMaxCustFilter;
ofnA.nFilterIndex = ofn16->nFilterIndex;
ofnA.lpstrFile = MapSL(ofn16->lpstrFile);
ofnA.nMaxFile = ofn16->nMaxFile;
ofnA.lpstrFileTitle = MapSL(ofn16->lpstrFileTitle);
ofnA.nMaxFileTitle = ofn16->nMaxFileTitle;
ofnA.lpstrInitialDir = MapSL(ofn16->lpstrInitialDir);
ofnA.lpstrTitle = MapSL(ofn16->lpstrTitle);
ofnA.Flags = ofn16->Flags;
ofnA.nFileOffset = ofn16->nFileOffset;
ofnA.nFileExtension = ofn16->nFileExtension;
ofnA.lpstrDefExt = MapSL(ofn16->lpstrDefExt);
if (HIWORD(ofn16->lpTemplateName))
ofnA.lpTemplateName = MapSL(ofn16->lpTemplateName);
else
ofnA.lpTemplateName = (LPSTR) ofn16->lpTemplateName; /* ressource number */
/* now calls the 32 bits Ansi to Unicode version to complete the job */
FD31_MapOfnStructA(&ofnA, ofnW, open);
}
/***********************************************************************
* FD16_GetTemplate [internal]
*
* Get a template (FALSE if failure) when 16 bits dialogs are used
* by a 16 bits application
*
*/
static BOOL FD16_GetTemplate(const FD31_DATA *lfs)
{
PFD16_PRIVATE priv = (PFD16_PRIVATE) lfs->private1632;
LPOPENFILENAME16 ofn16 = priv->ofn16;
LPVOID template;
HGLOBAL16 hGlobal16 = 0;
if (ofn16->Flags & OFN_ENABLETEMPLATEHANDLE)
priv->hDlgTmpl16 = ofn16->hInstance;
else if (ofn16->Flags & OFN_ENABLETEMPLATE)
{
HANDLE16 hResInfo;
if (!(hResInfo = FindResource16(ofn16->hInstance,
MapSL(ofn16->lpTemplateName),
(LPSTR)RT_DIALOG)))
{
COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
return FALSE;
}
if (!(priv->hDlgTmpl16 = LoadResource16( ofn16->hInstance, hResInfo )))
{
COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
return FALSE;
}
priv->hResource16 = priv->hDlgTmpl16;
}
else
{ /* get resource from (32 bits) own Wine resource; convert it to 16 */
HRSRC hResInfo;
HGLOBAL hDlgTmpl32;
LPCVOID template32;
DWORD size;
if (!(hResInfo = FindResourceA(COMDLG32_hInstance,
lfs->open ? "OPEN_FILE":"SAVE_FILE", (LPSTR)RT_DIALOG)))
{
COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
return FALSE;
}
if (!(hDlgTmpl32 = LoadResource(COMDLG32_hInstance, hResInfo )) ||
!(template32 = LockResource( hDlgTmpl32 )))
{
COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
return FALSE;
}
size = SizeofResource(COMDLG32_hInstance, hResInfo);
hGlobal16 = GlobalAlloc16(0, size);
if (!hGlobal16)
{
COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
ERR("alloc failure for %d bytes\n", size);
return FALSE;
}
template = GlobalLock16(hGlobal16);
if (!template)
{
COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
ERR("global lock failure for %x handle\n", hGlobal16);
GlobalFree16(hGlobal16);
return FALSE;
}
ConvertDialog32To16(template32, size, template);
priv->hDlgTmpl16 = hGlobal16;
priv->hGlobal16 = hGlobal16;
}
return TRUE;
}
/************************************************************************
* FD16_Init [internal]
* called from the common 16/32 code to initialize 16 bit data
*/
static BOOL CALLBACK FD16_Init(LPARAM lParam, PFD31_DATA lfs, DWORD data)
{
PFD16_PRIVATE priv;
priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FD16_PRIVATE));
lfs->private1632 = priv;
if (NULL == lfs->private1632) return FALSE;
priv->ofn16 = MapSL(lParam);
if (priv->ofn16->Flags & OFN_ENABLEHOOK)
if (priv->ofn16->lpfnHook)
lfs->hook = TRUE;
lfs->ofnW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*lfs->ofnW));
FD16_MapOfnStruct16(priv->ofn16, lfs->ofnW, lfs->open);
if (! FD16_GetTemplate(lfs)) return FALSE;
return TRUE;
}
/***********************************************************************
* FD16_CallWindowProc [internal]
*
* called from the common 16/32 code to call the appropriate hook
*/
static BOOL CALLBACK FD16_CallWindowProc(const FD31_DATA *lfs, UINT wMsg, WPARAM wParam,
LPARAM lParam)
{
PFD16_PRIVATE priv = (PFD16_PRIVATE) lfs->private1632;
if (priv->ofn16)
{
return (BOOL16) CallWindowProc16(
(WNDPROC16)priv->ofn16->lpfnHook, HWND_16(lfs->hwnd),
(UINT16)wMsg, (WPARAM16)wParam, lParam);
}
return FALSE;
}
/***********************************************************************
* FD31_UpdateResult [internal]
* update the real client structures
*/
static void CALLBACK FD16_UpdateResult(const FD31_DATA *lfs)
{
PFD16_PRIVATE priv = (PFD16_PRIVATE) lfs->private1632;
LPOPENFILENAMEW ofnW = lfs->ofnW;
if (priv->ofn16)
{ /* we have to convert to short (8.3) path */
char tmp[1024]; /* MAX_PATHNAME_LEN */
LPOPENFILENAME16 ofn16 = priv->ofn16;
char *dest = MapSL(ofn16->lpstrFile);
char *bs16;
if (!WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFile, -1,
tmp, sizeof(tmp), NULL, NULL ))
tmp[sizeof(tmp)-1] = 0;
GetShortPathNameA(tmp, dest, ofn16->nMaxFile);
/* the same procedure as every year... */
if((bs16 = strrchr(dest, '\\')) != NULL)
ofn16->nFileOffset = bs16 - dest +1;
else
ofn16->nFileOffset = 0;
ofn16->nFileExtension = 0;
while(dest[ofn16->nFileExtension] != '.' && dest[ofn16->nFileExtension] != '\0')
ofn16->nFileExtension++;
if (dest[ofn16->nFileExtension] == '\0')
ofn16->nFileExtension = 0;
else
ofn16->nFileExtension++;
}
}
/***********************************************************************
* FD16_UpdateFileTitle [internal]
* update the real client structures
*/
static void CALLBACK FD16_UpdateFileTitle(const FD31_DATA *lfs)
{
PFD16_PRIVATE priv = (PFD16_PRIVATE) lfs->private1632;
LPOPENFILENAMEW ofnW = lfs->ofnW;
if (priv->ofn16)
{
char *dest = MapSL(priv->ofn16->lpstrFileTitle);
if (!WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFileTitle, -1,
dest, ofnW->nMaxFileTitle, NULL, NULL ))
dest[ofnW->nMaxFileTitle-1] = 0;
}
}
/***********************************************************************
* FD16_SendLbGetCurSel [internal]
* retrieve selected listbox item
*/
static LRESULT CALLBACK FD16_SendLbGetCurSel(const FD31_DATA *lfs)
{
return SendDlgItemMessageW(lfs->hwnd, lst1, LB_GETCURSEL16, 0, 0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -