Sweden-Number/dlls/user32/resource.c

247 lines
7.0 KiB
C
Raw Normal View History

/*
* USER resource functions
*
* Copyright 1993 Robert J. Amstadt
* Copyright 1995, 2009 Alexandre Julliard
*
* 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 "winnls.h"
#include "ntuser.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(resource);
WINE_DECLARE_DEBUG_CHANNEL(accel);
/* this is the 8 byte accel struct used in Win32 resources (internal only) */
typedef struct
{
WORD fVirt;
WORD key;
WORD cmd;
WORD pad;
} PE_ACCEL;
/**********************************************************************
2001-01-25 23:22:21 +01:00
* LoadAcceleratorsW (USER32.@)
*/
HACCEL WINAPI LoadAcceleratorsW(HINSTANCE instance, LPCWSTR name)
{
const PE_ACCEL *pe_table;
ACCEL *table;
unsigned int i;
HRSRC rsrc;
HACCEL handle;
DWORD count;
if (!(rsrc = FindResourceW( instance, name, (LPWSTR)RT_ACCELERATOR ))) return 0;
pe_table = LoadResource( instance, rsrc );
count = SizeofResource( instance, rsrc ) / sizeof(*pe_table);
if (!count) return 0;
table = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*table) );
if (!table) return 0;
for (i = 0; i < count; i++)
{
table[i].fVirt = pe_table[i].fVirt;
table[i].key = pe_table[i].key;
table[i].cmd = pe_table[i].cmd;
}
handle = NtUserCreateAcceleratorTable( table, count );
HeapFree( GetProcessHeap(), 0, table );
TRACE_(accel)("%p %s returning %p\n", instance, debugstr_w(name), handle );
return handle;
}
/***********************************************************************
2001-01-25 23:22:21 +01:00
* LoadAcceleratorsA (USER32.@)
*/
HACCEL WINAPI LoadAcceleratorsA(HINSTANCE instance,LPCSTR lpTableName)
{
INT len;
LPWSTR uni;
HACCEL result = 0;
if (IS_INTRESOURCE(lpTableName)) return LoadAcceleratorsW( instance, (LPCWSTR)lpTableName );
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;
}
/**********************************************************************
2001-01-25 23:22:21 +01:00
* CopyAcceleratorTableA (USER32.@)
*/
INT WINAPI CopyAcceleratorTableA(HACCEL src, LPACCEL dst, INT count)
{
char ch;
int i, ret = NtUserCopyAcceleratorTable( src, dst, count );
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;
}
/*********************************************************************
2001-01-25 23:22:21 +01:00
* CreateAcceleratorTableA (USER32.@)
*/
HACCEL WINAPI CreateAcceleratorTableA( ACCEL *accel, INT count )
{
HACCEL handle;
ACCEL *table;
int i;
if (count < 1)
{
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
table = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*table) );
if (!table) return 0;
for (i = 0; i < count; i++)
{
table[i].fVirt = accel[i].fVirt;
table[i].cmd = accel[i].cmd;
if (!(accel[i].fVirt & FVIRTKEY))
{
char ch = accel[i].key;
MultiByteToWideChar( CP_ACP, 0, &ch, 1, &table[i].key, 1 );
}
else table[i].key = accel[i].key;
}
handle = NtUserCreateAcceleratorTable( table, count );
HeapFree( GetProcessHeap(), 0, table );
TRACE_(accel)("returning %p\n", handle );
return handle;
}
/**********************************************************************
2001-01-25 23:22:21 +01:00
* LoadStringW (USER32.@)
*/
INT WINAPI DECLSPEC_HOTPATCH LoadStringW( HINSTANCE instance, UINT resource_id,
LPWSTR buffer, INT buflen )
{
HGLOBAL hmem;
HRSRC hrsrc;
WCHAR *p;
int string_num;
int i;
TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
instance, resource_id, buffer, buflen);
2008-03-05 21:28:54 +01:00
if(buffer == NULL)
return 0;
/* Use loword (incremented by 1) as resourceid */
hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1),
(LPWSTR)RT_STRING );
if (!hrsrc) return 0;
hmem = LoadResource( instance, hrsrc );
if (!hmem) return 0;
2002-06-01 01:06:46 +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
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;
}
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;
} else {
if (buflen > 1) {
2008-11-03 22:35:31 +01:00
buffer[0] = 0;
return 0;
}
}
TRACE("%s loaded !\n", debugstr_w(buffer));
return i;
}
/**********************************************************************
2001-01-25 23:22:21 +01:00
* LoadStringA (USER32.@)
*/
INT WINAPI DECLSPEC_HOTPATCH LoadStringA( HINSTANCE instance, UINT resource_id, LPSTR buffer, INT buflen )
{
HGLOBAL hmem;
HRSRC hrsrc;
DWORD retval = 0;
TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
instance, resource_id, buffer, buflen);
if (!buflen) return -1;
2002-06-01 01:06:46 +02: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 )))
{
const WCHAR *p = LockResource(hmem);
unsigned int id = resource_id & 0x000f;
while (id--) p += *p + 1;
RtlUnicodeToMultiByteN( buffer, buflen - 1, &retval, p + 1, *p * sizeof(WCHAR) );
}
buffer[retval] = 0;
TRACE("returning %s\n", debugstr_a(buffer));
return retval;
}
/**********************************************************************
* 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;
}
SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
return 0;
}