2000-08-04 06:21:02 +02:00
|
|
|
/*
|
|
|
|
* USER resource functions
|
|
|
|
*
|
|
|
|
* Copyright 1993 Robert J. Amstadt
|
2009-10-15 17:35:06 +02:00
|
|
|
* Copyright 1995, 2009 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
2022-03-02 15:06:33 +01:00
|
|
|
#include "ntuser.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(resource);
|
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(accel);
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2000-10-13 01:18:55 +02:00
|
|
|
/* this is the 8 byte accel struct used in Win32 resources (internal only) */
|
|
|
|
typedef struct
|
|
|
|
{
|
2004-11-21 16:41:38 +01:00
|
|
|
WORD fVirt;
|
2000-10-13 01:18:55 +02:00
|
|
|
WORD key;
|
|
|
|
WORD cmd;
|
2004-11-21 16:41:38 +01:00
|
|
|
WORD pad;
|
2009-10-15 17:35:06 +02:00
|
|
|
} PE_ACCEL;
|
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
/**********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* LoadAcceleratorsW (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2009-10-15 17:35:06 +02:00
|
|
|
HACCEL WINAPI LoadAcceleratorsW(HINSTANCE instance, LPCWSTR name)
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2022-03-02 15:05:44 +01:00
|
|
|
const PE_ACCEL *pe_table;
|
2022-03-02 15:05:58 +01:00
|
|
|
ACCEL *table;
|
2022-03-02 15:05:44 +01:00
|
|
|
unsigned int i;
|
2009-10-15 17:35:06 +02:00
|
|
|
HRSRC rsrc;
|
|
|
|
HACCEL handle;
|
|
|
|
DWORD count;
|
|
|
|
|
|
|
|
if (!(rsrc = FindResourceW( instance, name, (LPWSTR)RT_ACCELERATOR ))) return 0;
|
2022-03-02 15:05:44 +01:00
|
|
|
pe_table = LoadResource( instance, rsrc );
|
|
|
|
count = SizeofResource( instance, rsrc ) / sizeof(*pe_table);
|
2009-10-15 17:35:06 +02:00
|
|
|
if (!count) return 0;
|
2022-03-02 15:05:58 +01:00
|
|
|
table = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*table) );
|
|
|
|
if (!table) return 0;
|
2022-03-02 15:05:44 +01:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2022-03-02 15:05:58 +01:00
|
|
|
table[i].fVirt = pe_table[i].fVirt;
|
|
|
|
table[i].key = pe_table[i].key;
|
|
|
|
table[i].cmd = pe_table[i].cmd;
|
2022-03-02 15:05:44 +01:00
|
|
|
}
|
2022-03-02 15:06:33 +01:00
|
|
|
handle = NtUserCreateAcceleratorTable( table, count );
|
2022-03-02 15:05:58 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, table );
|
2009-10-15 17:35:06 +02:00
|
|
|
TRACE_(accel)("%p %s returning %p\n", instance, debugstr_w(name), handle );
|
|
|
|
return handle;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* LoadAcceleratorsA (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
|
|
|
HACCEL WINAPI LoadAcceleratorsA(HINSTANCE instance,LPCSTR lpTableName)
|
|
|
|
{
|
2002-01-01 01:24:30 +01:00
|
|
|
INT len;
|
|
|
|
LPWSTR uni;
|
|
|
|
HACCEL result = 0;
|
|
|
|
|
2010-02-03 21:04:27 +01:00
|
|
|
if (IS_INTRESOURCE(lpTableName)) return LoadAcceleratorsW( instance, (LPCWSTR)lpTableName );
|
2002-01-01 01:24:30 +01:00
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpTableName, -1, NULL, 0 );
|
|
|
|
if ((uni = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpTableName, -1, uni, len );
|
|
|
|
result = LoadAcceleratorsW(instance,uni);
|
|
|
|
HeapFree( GetProcessHeap(), 0, uni);
|
|
|
|
}
|
|
|
|
return result;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* CopyAcceleratorTableA (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2009-10-15 17:35:06 +02:00
|
|
|
INT WINAPI CopyAcceleratorTableA(HACCEL src, LPACCEL dst, INT count)
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2009-10-15 17:35:06 +02:00
|
|
|
char ch;
|
2022-03-02 15:06:33 +01:00
|
|
|
int i, ret = NtUserCopyAcceleratorTable( src, dst, count );
|
2009-10-15 17:35:06 +02:00
|
|
|
|
|
|
|
if (ret && dst)
|
|
|
|
{
|
|
|
|
for (i = 0; i < ret; i++)
|
|
|
|
{
|
|
|
|
if (dst[i].fVirt & FVIRTKEY) continue;
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, &dst[i].key, 1, &ch, 1, NULL, NULL );
|
|
|
|
dst[i].key = ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* CreateAcceleratorTableA (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2022-03-02 15:06:17 +01:00
|
|
|
HACCEL WINAPI CreateAcceleratorTableA( ACCEL *accel, INT count )
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2009-10-15 17:35:06 +02:00
|
|
|
HACCEL handle;
|
2022-03-02 15:06:17 +01:00
|
|
|
ACCEL *table;
|
2009-10-15 17:35:06 +02:00
|
|
|
int i;
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2009-10-15 17:35:06 +02:00
|
|
|
if (count < 1)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return 0;
|
|
|
|
}
|
2022-03-02 15:06:17 +01:00
|
|
|
table = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*table) );
|
|
|
|
if (!table) return 0;
|
2009-10-15 17:35:06 +02:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2022-03-02 15:06:17 +01:00
|
|
|
table[i].fVirt = accel[i].fVirt;
|
|
|
|
table[i].cmd = accel[i].cmd;
|
|
|
|
if (!(accel[i].fVirt & FVIRTKEY))
|
2009-10-15 17:35:06 +02:00
|
|
|
{
|
2022-03-02 15:06:17 +01:00
|
|
|
char ch = accel[i].key;
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, &ch, 1, &table[i].key, 1 );
|
2009-10-15 17:35:06 +02:00
|
|
|
}
|
2022-03-02 15:06:17 +01:00
|
|
|
else table[i].key = accel[i].key;
|
2009-10-15 17:35:06 +02:00
|
|
|
}
|
2022-03-02 15:06:33 +01:00
|
|
|
handle = NtUserCreateAcceleratorTable( table, count );
|
2022-03-02 15:06:17 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, table );
|
2009-10-15 17:35:06 +02:00
|
|
|
TRACE_(accel)("returning %p\n", handle );
|
|
|
|
return handle;
|
2000-08-04 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* LoadStringW (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2019-02-12 10:25:09 +01:00
|
|
|
INT WINAPI DECLSPEC_HOTPATCH LoadStringW( HINSTANCE instance, UINT resource_id,
|
2000-08-04 06:21:02 +02:00
|
|
|
LPWSTR buffer, INT buflen )
|
|
|
|
{
|
|
|
|
HGLOBAL hmem;
|
|
|
|
HRSRC hrsrc;
|
|
|
|
WCHAR *p;
|
|
|
|
int string_num;
|
|
|
|
int i;
|
|
|
|
|
2005-09-12 16:12:46 +02:00
|
|
|
TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
|
|
|
|
instance, resource_id, buffer, buflen);
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2008-03-05 21:28:54 +01:00
|
|
|
if(buffer == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2006-09-21 20:47:20 +02:00
|
|
|
/* Use loword (incremented by 1) as resourceid */
|
|
|
|
hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1),
|
2003-09-10 05:56:47 +02:00
|
|
|
(LPWSTR)RT_STRING );
|
2000-08-04 06:21:02 +02:00
|
|
|
if (!hrsrc) return 0;
|
|
|
|
hmem = LoadResource( instance, hrsrc );
|
|
|
|
if (!hmem) return 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
p = LockResource(hmem);
|
|
|
|
string_num = resource_id & 0x000f;
|
|
|
|
for (i = 0; i < string_num; i++)
|
|
|
|
p += *p + 1;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
TRACE("strlen = %d\n", (int)*p );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2008-03-05 21:28:54 +01:00
|
|
|
/*if buflen == 0, then return a read-only pointer to the resource itself in buffer
|
|
|
|
it is assumed that buffer is actually a (LPWSTR *) */
|
|
|
|
if(buflen == 0)
|
|
|
|
{
|
|
|
|
*((LPWSTR *)buffer) = p + 1;
|
|
|
|
return *p;
|
|
|
|
}
|
|
|
|
|
2000-08-04 06:21:02 +02:00
|
|
|
i = min(buflen - 1, *p);
|
|
|
|
if (i > 0) {
|
|
|
|
memcpy(buffer, p + 1, i * sizeof (WCHAR));
|
2008-11-03 22:35:31 +01:00
|
|
|
buffer[i] = 0;
|
2000-08-04 06:21:02 +02:00
|
|
|
} else {
|
|
|
|
if (buflen > 1) {
|
2008-11-03 22:35:31 +01:00
|
|
|
buffer[0] = 0;
|
2000-08-04 06:21:02 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("%s loaded !\n", debugstr_w(buffer));
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-01-25 23:22:21 +01:00
|
|
|
* LoadStringA (USER32.@)
|
2000-08-04 06:21:02 +02:00
|
|
|
*/
|
2019-02-12 10:25:09 +01:00
|
|
|
INT WINAPI DECLSPEC_HOTPATCH LoadStringA( HINSTANCE instance, UINT resource_id, LPSTR buffer, INT buflen )
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2008-03-03 20:06:54 +01:00
|
|
|
HGLOBAL hmem;
|
|
|
|
HRSRC hrsrc;
|
|
|
|
DWORD retval = 0;
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2005-09-12 16:12:46 +02:00
|
|
|
TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
|
|
|
|
instance, resource_id, buffer, buflen);
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2008-03-03 20:06:54 +01:00
|
|
|
if (!buflen) return -1;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2008-03-03 20:06:54 +01:00
|
|
|
/* Use loword (incremented by 1) as resourceid */
|
|
|
|
if ((hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1),
|
|
|
|
(LPWSTR)RT_STRING )) &&
|
|
|
|
(hmem = LoadResource( instance, hrsrc )))
|
2000-08-04 06:21:02 +02:00
|
|
|
{
|
2008-03-03 20:06:54 +01:00
|
|
|
const WCHAR *p = LockResource(hmem);
|
|
|
|
unsigned int id = resource_id & 0x000f;
|
|
|
|
|
|
|
|
while (id--) p += *p + 1;
|
2000-08-04 06:21:02 +02:00
|
|
|
|
2019-12-03 08:53:44 +01:00
|
|
|
RtlUnicodeToMultiByteN( buffer, buflen - 1, &retval, p + 1, *p * sizeof(WCHAR) );
|
2008-03-03 20:06:54 +01:00
|
|
|
}
|
|
|
|
buffer[retval] = 0;
|
|
|
|
TRACE("returning %s\n", debugstr_a(buffer));
|
2000-08-04 06:21:02 +02:00
|
|
|
return retval;
|
|
|
|
}
|
2004-04-07 21:41:21 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* GetGuiResources (USER32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetGuiResources( HANDLE hProcess, DWORD uiFlags )
|
|
|
|
{
|
2008-09-28 20:47:07 +02:00
|
|
|
static BOOL warn = TRUE;
|
|
|
|
|
|
|
|
if (warn) {
|
|
|
|
FIXME("(%p,%x): stub\n",hProcess,uiFlags);
|
|
|
|
warn = FALSE;
|
|
|
|
}
|
|
|
|
|
2004-04-07 21:41:21 +02:00
|
|
|
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
|
|
|
|
return 0;
|
|
|
|
}
|