1
0
Fork 0
mirror of synced 2025-03-07 03:53:26 +01:00
wine/loader/resource.c
Alexandre Julliard fa68b75bad Release 950403
Sun Apr  2 18:31:12 1995  Alexandre Julliard  (julliard@sunsite.unc.edu)

	* [Configure] [if1632/Imakefile]
	Removed new build and short names options.

	* [if1632/*.c] [tools/build.c]
	Implemented compiled call-back functions for better performance;
	all the relay code is now done in assembly code generated by the
	build program.
	Relay code is no longer dependent on being loaded below 64K.

	* [loader/resource.c]
	Fixed memory leak in LoadString(). A fix will also be needed for
	other resources.

	* [memory/global.c]
	Implemented global heap arenas, so we can store informations about
	global blocks, like lock counts or owner handle.
	Implemented FarGetOwner() and FarSetOwner().
	Implemented global heap TOOLHELP functions.

	* [memory/selector.c]
	Bug fix: it was not possible to re-use a free selector.

Sun Apr 2 01:34:52 1995 Constantine Sapuntzakis  (csapuntz@mit.edu)

	*  [controls/listbox.c]
	Major work on listbox code
         - Many bugs fixed (still many bugs)
         - More messages supported
         - Code simplified

Fri Mar 31 03:27:16 EST 1995 William Magro (wmagro@tc.cornell.edu)

	* [controls/edit.c]
	Lots of bug fixes related to diappearing text, lost carets,
	highlighting, segmentation faults, occurance of random
	characters, insertion of characters over selection, misplaced
	caret location, display corruption, end of line behavior, etc.

	* [controls/widgets.c]
	EDIT class doesn't want to use CS_PARENTDC flag.

Thu Mar 30 20:58:25 1995   Bernd Schmidt <crux@pool.informatik.rwth-aachen.de>
        
	* [loader/selector.c]
	  FixupFunctionPrologs() should also handle multiple data modules.
	  (this bug only became visible because MakeProcInstance() was fixed
	  in 950319)
	
	* [misc/dosfs.c]
	  Simplified DOS_SimplifyPath.
	  Small fix to DOS_opendir to reuse an entry if an open directory
	  is opened again, to prevent "too many open directories" messages.

Thu Mar 30 12:05:05 1995 Martin von Loewis  <loewis@informatik.hu-berlin.de>

	* [if1632/compobj.spec][include/compobj.h][misc/compobj.c]
	CoDisconnectObject: new stub function

	* [include/msdos.h]
	fix DOSVERSION

	* [loader/ne_image.c]
	NE_FixupSegment: Be more generous on additive fixups

	* [if1632/user.spec][misc/network.c]
	Add more WNet* stubs

Wed Mar 29 11:47:22 1995   Bernd Schmidt <crux@pool.informatik.rwth-aachen.de>

        * [controls/listbox.c]
	  DlgDirList(): send segptr instead of linear pointer 
	  in message to static control
	* [controls/menu.c]
	  Tried to implement ownerdrawn menuitems. Doesn't work.
	* [if1632/gdi.spec] [include/windows.h] [objects/font.c]
	  Provide a stub for GetRasterizerCaps()
	* [loader/selector.c]
	  Pass end address instead of length to LocalInit() in 
	  CreateSelectors()
	* [memory/local.c]
	  LocalInit(): If there's already a local heap in the segment, do
	  nothing and return TRUE
	* [objects/linedda.c]
	  Replaced buggy LineDDA() with a Bresenham algorithm. Should work
	  now.
	* [windows/cursor.c]
	  LoadCursor()/CreateCursor(): Cleaned up the mess. Needs some
	  more work still.

Tue Mar 21 17:54:43 1995   Bernd Schmidt <crux@pool.informatik.rwth-aachen.de>

        * [if1632/relay.c] [if1632/callback.c] [include/dlls.h]
	  [if1632/winprocs.spec] [if1632/winprocs.c] [include/winprocs.h]
	  [controls/widgets.c] [misc/shell.c] [misc/commdlg.c]
	  [windows/nonclient.c] [misc/message.c]
	  Added a new builtin DLL that provides 16 bit entry points for all
	  the Def*Procs (DefDlgProc, ButtonProc etc.). OWL programs work
	  again.
	* [misc/shell.c]
	  RegOpenKey()/RegCreateKey() bugs fixed.
        * [loader/ne_image.c]
	  Skipping the initialization of a DLL when CS == 0 was broken.
1995-04-03 16:55:37 +00:00

741 lines
20 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
static char RCSId[] = "$Id: resource.c,v 1.4 1993/07/04 04:04:21 root Exp root $";
static char Copyright[] = "Copyright Robert J. Amstadt, 1993";
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "arch.h"
#include "windows.h"
#include "gdi.h"
#include "bitmap.h"
#include "neexe.h"
#include "icon.h"
#include "menu.h"
#include "accel.h"
#include "dlls.h"
#include "resource.h"
#include "library.h"
#include "stddebug.h"
#include "debug.h"
#define MIN(a,b) ((a) < (b) ? (a) : (b))
RESOURCE *Top = NULL;
extern int NE_FindResource(HANDLE, SEGPTR, SEGPTR, RESOURCE *);
extern int PE_FindResource(HANDLE, SEGPTR, SEGPTR, RESOURCE *);
#define PrintId(name) \
if (HIWORD((DWORD)name)) \
printf(", '%s'", (char *)PTR_SEG_TO_LIN(name)); \
else \
printf(", #%d", LOWORD(name));
/**********************************************************************
* FindResource [KERNEL.60]
*/
HANDLE FindResource(HANDLE instance, SEGPTR name, SEGPTR type)
{
int status;
RESOURCE *r;
HANDLE rh;
if(debugging_resource){
printf("FindResource(%04X", instance);
PrintId(name);
PrintId(type);
printf(")\n");
}
/* FIXME: did we already find this one ? */
if ((rh = GlobalAlloc(GMEM_MOVEABLE, sizeof(RESOURCE))) == 0)
return 0;
r = (RESOURCE *)GlobalLock(rh);
r->next = Top;
Top = r;
r->info_mem = rh;
r->rsc_mem = 0;
r->count = 0;
if (HIWORD((DWORD)name))
r->name = strdup(PTR_SEG_TO_LIN(name));
else
r->name = (LPSTR)name;
if (HIWORD((DWORD)type))
r->type = strdup(PTR_SEG_TO_LIN(type));
else
r->type = (LPSTR)type;
r->wpnt = GetFileInfo(instance);
r->fd = dup(r->wpnt->fd);
if (r->wpnt->ne)
status = NE_FindResource(instance, name, type, r);
else
status = PE_FindResource(instance, name, type, r);
if (!status) {
if (HIWORD((DWORD)r->name))
free(r->name);
if (HIWORD((DWORD)r->type))
free(r->type);
close(r->fd);
Top = r->next;
GlobalUnlock(rh);
return 0;
} else
return rh;
}
/**********************************************************************
* AllocResource [KERNEL.66]
*/
HANDLE AllocResource(HANDLE instance, HANDLE hResInfo, DWORD dwSize)
{
RESOURCE *r;
int image_size;
dprintf_resource(stddeb, "AllocResource(%04X, %04X, %08X);\n",
instance, hResInfo, (int) dwSize);
if ((r = (RESOURCE *)GlobalLock(hResInfo)) == NULL)
return 0;
image_size = r->size;
if (dwSize == 0)
r->rsc_mem = GlobalAlloc(GMEM_MOVEABLE, image_size);
else
r->rsc_mem = GlobalAlloc(GMEM_MOVEABLE, dwSize);
GlobalUnlock(hResInfo);
return r->rsc_mem;
}
/**********************************************************************
* AccessResource [KERNEL.64]
*/
int AccessResource(HANDLE instance, HANDLE hResInfo)
{
int fd;
RESOURCE *r;
dprintf_resource(stddeb, "AccessResource(%04X, %04X);\n",
instance, hResInfo);
if ((r = (RESOURCE *)GlobalLock(hResInfo)) == NULL)
return -1;
fd = r->fd;
lseek(fd, r->offset, SEEK_SET);
GlobalUnlock(hResInfo);
return fd;
}
/**********************************************************************
* SizeofResource [KERNEL.65]
*/
WORD SizeofResource(HANDLE instance, HANDLE hResInfo)
{
RESOURCE *r;
int size;
dprintf_resource(stddeb, "SizeofResource(%04X, %04X);\n",
instance, hResInfo);
if ((r = (RESOURCE *)GlobalLock(hResInfo)) == NULL)
return 0;
size = r->size;
GlobalUnlock(hResInfo);
return size;
}
/**********************************************************************
* LoadResource [KERNEL.61]
*/
HANDLE LoadResource(HANDLE instance, HANDLE hResInfo)
{
RESOURCE *r;
int image_size, fd;
void *image;
HANDLE h;
dprintf_resource(stddeb, "LoadResource(%04X, %04X);\n", instance, hResInfo);
if ((r = (RESOURCE *)GlobalLock(hResInfo)) == NULL)
return 0;
h = r->rsc_mem = AllocResource(instance, hResInfo, 0);
image = GlobalLock(h);
image_size = r->size;
fd = AccessResource(instance, hResInfo);
if (image == NULL || read(fd, image, image_size) != image_size) {
GlobalFree(h);
GlobalUnlock(hResInfo);
return 0;
}
r->count++;
close(fd);
GlobalUnlock(h);
GlobalUnlock(hResInfo);
return h;
}
/**********************************************************************
* LockResource [KERNEL.62]
*/
/* 16-bit version */
SEGPTR WIN16_LockResource(HANDLE hResData)
{
return WIN16_GlobalLock(hResData);
}
/* 32-bit version */
LPSTR LockResource(HANDLE hResData)
{
return GlobalLock(hResData);
}
/**********************************************************************
* FreeResource [KERNEL.63]
*/
HANDLE FreeResource(HANDLE hResData)
{
RESOURCE *r, *rp;
dprintf_resource(stddeb, "FreeResource: handle %04x\n", hResData);
for (r = rp = Top; r ; r = r->next) {
if (r->rsc_mem == hResData) {
if (r->count == 0) {
if (rp != r)
rp->next = r->next;
else
Top = r->next;
if (HIWORD((DWORD)r->name))
free(r->name);
if (HIWORD((DWORD)r->type))
free(r->type);
GlobalFree(r->rsc_mem);
GlobalFree(r->info_mem);
return 0;
} else
r->count--;
}
rp = r;
}
return hResData;
}
/**********************************************************************
* ConvertCoreBitmap
*/
HBITMAP ConvertCoreBitmap( HDC hdc, BITMAPCOREHEADER * image )
{
BITMAPINFO * bmpInfo;
HBITMAP hbitmap;
char * bits;
int i, size, n_colors;
n_colors = 1 << image->bcBitCount;
if (image->bcBitCount < 24)
{
size = sizeof(BITMAPINFOHEADER) + n_colors * sizeof(RGBQUAD);
bits = (char *) (image + 1) + (n_colors * sizeof(RGBTRIPLE));
}
else
{
size = sizeof(BITMAPINFOHEADER);
bits = (char *) (image + 1);
}
bmpInfo = (BITMAPINFO *) malloc( size );
bmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo->bmiHeader.biWidth = image->bcWidth;
bmpInfo->bmiHeader.biHeight = image->bcHeight;
bmpInfo->bmiHeader.biPlanes = image->bcPlanes;
bmpInfo->bmiHeader.biBitCount = image->bcBitCount;
bmpInfo->bmiHeader.biCompression = 0;
bmpInfo->bmiHeader.biSizeImage = 0;
bmpInfo->bmiHeader.biXPelsPerMeter = 0;
bmpInfo->bmiHeader.biYPelsPerMeter = 0;
bmpInfo->bmiHeader.biClrUsed = 0;
bmpInfo->bmiHeader.biClrImportant = 0;
if (image->bcBitCount < 24)
{
RGBTRIPLE * oldMap = (RGBTRIPLE *)(image + 1);
RGBQUAD * newMap = bmpInfo->bmiColors;
for (i = 0; i < n_colors; i++, oldMap++, newMap++)
{
newMap->rgbRed = oldMap->rgbtRed;
newMap->rgbGreen = oldMap->rgbtGreen;
newMap->rgbBlue = oldMap->rgbtBlue;
newMap->rgbReserved = 0;
}
}
hbitmap = CreateDIBitmap( hdc, &bmpInfo->bmiHeader, CBM_INIT,
bits, bmpInfo, DIB_RGB_COLORS );
free( bmpInfo );
return hbitmap;
}
/**********************************************************************
* ConvertInfoBitmap
*/
HBITMAP ConvertInfoBitmap( HDC hdc, BITMAPINFO * image )
{
char * bits = ((char *)image) + DIB_BitmapInfoSize(image, DIB_RGB_COLORS);
return CreateDIBitmap( hdc, &image->bmiHeader, CBM_INIT,
bits, image, DIB_RGB_COLORS );
}
/**********************************************************************
* RSC_LoadResource
*/
HANDLE
RSC_LoadResource(int instance, SEGPTR rsc_name, SEGPTR type, int *image_size_ret)
{
HANDLE hResInfo;
RESOURCE *r;
dprintf_resource(stddeb, "RSC_LoadResource: instance = %04x, name = %08lx, type = %08lx\n",
instance, rsc_name, type);
if ((hResInfo = FindResource(instance, rsc_name, type)) == (HANDLE) NULL) {
return (HANDLE)NULL;
}
r = (RESOURCE *)GlobalLock(hResInfo);
if (image_size_ret)
*image_size_ret = r->size;
r->count++;
GlobalUnlock(hResInfo);
return LoadResource(instance, hResInfo);
}
/**********************************************************************
* LoadIcon [USER.174]
*/
HICON LoadIcon( HANDLE instance, SEGPTR icon_name )
{
HICON hIcon;
HANDLE rsc_mem;
WORD *lp;
ICONDESCRIP *lpicodesc;
ICONALLOC *lpico;
int width, height;
BITMAPINFO *bmi;
BITMAPINFOHEADER *bih;
RGBQUAD *rgbq;
HDC hdc;
int image_size;
if (HIWORD(icon_name))
dprintf_resource( stddeb, "LoadIcon: %04x '%s'\n",
instance, (char *)PTR_SEG_TO_LIN( icon_name ) );
else
dprintf_resource( stddeb, "LoadIcon: %04x %04x\n",
instance, LOWORD(icon_name) );
if (!instance)
{
if (HIWORD((int)icon_name)) return 0; /* FIXME: should handle '#xxx' */
return OBM_LoadIcon( LOWORD((int)icon_name) );
}
if (!(hdc = GetDC(GetDesktopWindow()))) return 0;
rsc_mem = RSC_LoadResource(instance, icon_name,
(SEGPTR) NE_RSCTYPE_GROUP_ICON, &image_size);
if (rsc_mem == (HANDLE)NULL) {
printf("LoadIcon / Icon %08x not Found !\n", (int) icon_name);
ReleaseDC(GetDesktopWindow(), hdc);
return 0;
}
lp = (WORD *)GlobalLock(rsc_mem);
if (lp == NULL) {
GlobalFree(rsc_mem);
ReleaseDC(GetDesktopWindow(), hdc);
return 0;
}
lpicodesc = (ICONDESCRIP *)(lp + 3);
hIcon = GlobalAlloc(GMEM_MOVEABLE, sizeof(ICONALLOC) + 1024);
if (hIcon == (HICON)NULL) {
GlobalFree(rsc_mem);
ReleaseDC(GetDesktopWindow(), hdc);
return 0;
}
lpico = (ICONALLOC *)GlobalLock(hIcon);
lpico->descriptor = *lpicodesc;
width = lpicodesc->Width;
height = lpicodesc->Height;
GlobalUnlock(rsc_mem);
GlobalFree(rsc_mem);
rsc_mem = RSC_LoadResource( instance,
MAKEINTRESOURCE(lpicodesc->icoDIBOffset),
(SEGPTR) NE_RSCTYPE_ICON, &image_size );
if (rsc_mem == (HANDLE)NULL) {
printf("LoadIcon / Icon %08lx Bitmaps not Found !\n", icon_name );
ReleaseDC(GetDesktopWindow(), hdc);
return 0;
}
lp = (WORD *)GlobalLock(rsc_mem);
if (lp == NULL) {
GlobalFree(rsc_mem);
ReleaseDC(GetDesktopWindow(), hdc);
return 0;
}
bmi = (BITMAPINFO *)lp;
bih = (BITMAPINFOHEADER *)lp;
rgbq = &bmi->bmiColors[0];
bih->biHeight = bih->biHeight / 2;
/*
printf("LoadIcon / image_size=%d width=%d height=%d bih->biBitCount=%d bih->biSizeImage=%ld\n",
image_size, width, height, bih->biBitCount, bih->biSizeImage);
*/
if (bih->biSize == sizeof(BITMAPINFOHEADER))
lpico->hBitmap = ConvertInfoBitmap(hdc, (BITMAPINFO *)bih);
else
lpico->hBitmap = 0;
bih->biBitCount = 1;
bih->biClrUsed = bih->biClrImportant = 2;
rgbq[0].rgbBlue = rgbq[0].rgbGreen = rgbq[0].rgbRed = 0x00;
rgbq[1].rgbBlue = rgbq[1].rgbGreen = rgbq[1].rgbRed = 0xff;
rgbq[0].rgbReserved = rgbq[1].rgbReserved = 0;
if (bih->biSizeImage == 0) {
if (bih->biCompression != BI_RGB) {
fprintf(stderr,"Unknown size for compressed Icon bitmap.\n");
GlobalFree(rsc_mem);
ReleaseDC(GetDesktopWindow(), hdc);
return 0;
}
bih->biSizeImage = (bih->biWidth * bih->biHeight * bih->biBitCount
+ 7) / 8;
}
lpico->hBitMask = CreateDIBitmap(hdc, bih, CBM_INIT,
(LPSTR)lp + bih->biSizeImage - sizeof(BITMAPINFOHEADER) / 2 - 4,
(BITMAPINFO *)bih, DIB_RGB_COLORS );
GlobalUnlock(rsc_mem);
GlobalFree(rsc_mem);
ReleaseDC(GetDesktopWindow(), hdc);
GlobalUnlock(hIcon);
dprintf_resource(stddeb,"LoadIcon Alloc hIcon=%X\n", hIcon);
return hIcon;
}
/**********************************************************************
* CreateIcon [USER.407]
*/
HICON CreateIcon(HANDLE hInstance, int nWidth, int nHeight,
BYTE nPlanes, BYTE nBitsPixel, LPSTR lpANDbits,
LPSTR lpXORbits)
{
HICON hIcon;
ICONALLOC *lpico;
dprintf_resource(stddeb, "CreateIcon: hInstance = %04x, nWidth = %08x, nHeight = %08x \n",
hInstance, nWidth, nHeight);
dprintf_resource(stddeb, " nPlanes = %04x, nBitsPixel = %04x,",nPlanes, nBitsPixel);
dprintf_resource(stddeb, " lpANDbits= %04x, lpXORbits = %04x, \n", (int)lpANDbits,
(int)lpXORbits);
if (hInstance == (HANDLE)NULL) {
printf("CreateIcon / hInstance %04x not Found!\n",hInstance);
return 0;
}
hIcon = GlobalAlloc(GMEM_MOVEABLE, sizeof(ICONALLOC) + 1024);
if (hIcon == (HICON)NULL) {
printf("Can't allocate memory for Icon in CreateIcon\n");
return 0;
}
lpico= (ICONALLOC *)GlobalLock(hIcon);
lpico->descriptor.Width=nWidth;
lpico->descriptor.Height=nHeight;
lpico->descriptor.ColorCount=16; /* Dummy Value */
lpico->descriptor.Reserved1=0;
lpico->descriptor.Reserved2=nPlanes;
lpico->descriptor.Reserved3=nWidth*nHeight;
/* either nPlanes and/or nBitCount is set to one */
lpico->descriptor.icoDIBSize=nWidth*nHeight*nPlanes*nBitsPixel;
lpico->descriptor.icoDIBOffset=0;
if( !(lpico->hBitmap=CreateBitmap(nWidth, nHeight, nPlanes, nBitsPixel,
lpXORbits)) ) {
printf("CreateIcon: couldn't create the XOR bitmap\n");
return(0);
}
/* the AND BitMask is always monochrome */
if( !(lpico->hBitMask=CreateBitmap(nWidth, nHeight, 1, 1, lpANDbits)) ) {
printf("CreateIcon: couldn't create the AND bitmap\n");
return(0);
}
GlobalUnlock(hIcon);
dprintf_resource(stddeb, "CreateIcon Alloc hIcon=%X\n", hIcon);
return hIcon;
}
/**********************************************************************
* DestroyIcon [USER.457]
*/
BOOL DestroyIcon(HICON hIcon)
{
ICONALLOC *lpico;
if (hIcon == (HICON)NULL)
return FALSE;
lpico = (ICONALLOC *)GlobalLock(hIcon);
if (lpico->hBitmap != (HBITMAP)NULL)
DeleteObject(lpico->hBitmap);
GlobalFree(hIcon);
return TRUE;
}
/**********************************************************************
* LoadAccelerators [USER.177]
*/
HANDLE LoadAccelerators(HANDLE instance, SEGPTR lpTableName)
{
HANDLE hAccel;
HANDLE rsc_mem;
BYTE *lp;
ACCELHEADER *lpAccelTbl;
int i, image_size, n;
if (HIWORD(lpTableName))
dprintf_accel( stddeb, "LoadAccelerators: %04x '%s'\n",
instance, (char *)PTR_SEG_TO_LIN( lpTableName ) );
else
dprintf_accel( stddeb, "LoadAccelerators: %04x %04x\n",
instance, LOWORD(lpTableName) );
rsc_mem = RSC_LoadResource( instance, lpTableName,
(SEGPTR) NE_RSCTYPE_ACCELERATOR, &image_size );
if (rsc_mem == (HANDLE)NULL) {
printf("LoadAccelerators(%08lx) not found!\n", lpTableName );
return 0;
}
lp = (BYTE *)GlobalLock(rsc_mem);
if (lp == NULL) {
GlobalFree(rsc_mem);
return 0;
}
dprintf_accel(stddeb,"LoadAccelerators / image_size=%d\n", image_size);
n = image_size/5;
hAccel = GlobalAlloc(GMEM_MOVEABLE,
sizeof(ACCELHEADER) + (n + 1)*sizeof(ACCELENTRY));
lpAccelTbl = (LPACCELHEADER)GlobalLock(hAccel);
lpAccelTbl->wCount = 0;
for (i = 0; i < n; i++) {
lpAccelTbl->tbl[i].type = *(lp++);
lpAccelTbl->tbl[i].wEvent = *((WORD *)lp);
lp += 2;
lpAccelTbl->tbl[i].wIDval = *((WORD *)lp);
lp += 2;
if (lpAccelTbl->tbl[i].wEvent == 0) break;
dprintf_accel(stddeb,
"Accelerator #%u / event=%04X id=%04X type=%02X \n",
i, lpAccelTbl->tbl[i].wEvent, lpAccelTbl->tbl[i].wIDval,
lpAccelTbl->tbl[i].type);
lpAccelTbl->wCount++;
}
GlobalUnlock(hAccel);
GlobalUnlock(rsc_mem);
GlobalFree(rsc_mem);
return hAccel;
}
/**********************************************************************
* TranslateAccelerator [USER.178]
*/
int TranslateAccelerator(HWND hWnd, HANDLE hAccel, LPMSG msg)
{
ACCELHEADER *lpAccelTbl;
int i;
if (hAccel == 0 || msg == NULL) return 0;
if (msg->message != WM_KEYDOWN &&
msg->message != WM_KEYUP &&
msg->message != WM_CHAR) return 0;
dprintf_accel(stddeb, "TranslateAccelerators hAccel=%04X !\n", hAccel);
lpAccelTbl = (LPACCELHEADER)GlobalLock(hAccel);
for (i = 0; i < lpAccelTbl->wCount; i++) {
if (lpAccelTbl->tbl[i].type & VIRTKEY_ACCEL) {
if (msg->wParam == lpAccelTbl->tbl[i].wEvent &&
msg->message == WM_KEYDOWN) {
if ((lpAccelTbl->tbl[i].type & SHIFT_ACCEL) &&
!(GetKeyState(VK_SHIFT) & 0xf)) {
GlobalUnlock(hAccel);
return 0;
}
if ((lpAccelTbl->tbl[i].type & CONTROL_ACCEL) &&
!(GetKeyState(VK_CONTROL) & 0xf)) {
GlobalUnlock(hAccel);
return 0;
}
if ((lpAccelTbl->tbl[i].type & ALT_ACCEL) &&
!(GetKeyState(VK_MENU) & 0xf)) {
GlobalUnlock(hAccel);
return 0;
}
SendMessage(hWnd, WM_COMMAND, lpAccelTbl->tbl[i].wIDval, 0x00010000L);
GlobalUnlock(hAccel);
return 1;
}
if (msg->message == WM_KEYUP) return 1;
}
else {
if (msg->wParam == lpAccelTbl->tbl[i].wEvent &&
msg->message == WM_CHAR) {
SendMessage(hWnd, WM_COMMAND, lpAccelTbl->tbl[i].wIDval, 0x00010000L);
GlobalUnlock(hAccel);
return 1;
}
}
}
GlobalUnlock(hAccel);
return 0;
}
/**********************************************************************
* LoadString
*/
int
LoadString(HANDLE instance, WORD resource_id, LPSTR buffer, int buflen)
{
HANDLE hmem, hrsrc;
unsigned char *p;
int string_num;
int i;
dprintf_resource(stddeb, "LoadString: instance = %04x, id = %d, buffer = %08x, "
"length = %d\n", instance, resource_id, (int) buffer, buflen);
hrsrc = FindResource( instance, (SEGPTR)((resource_id >> 4) + 1),
(SEGPTR) NE_RSCTYPE_STRING );
if (!hrsrc) return 0;
hmem = LoadResource( instance, hrsrc );
if (!hmem) return 0;
p = GlobalLock(hmem);
string_num = resource_id & 0x000f;
for (i = 0; i < string_num; i++)
p += *p + 1;
i = MIN(buflen - 1, *p);
if (i > 0) {
memcpy(buffer, p + 1, i);
buffer[i] = '\0';
}
else {
if (buflen > 1) {
buffer[0] = '\0';
return 0;
}
fprintf(stderr,"LoadString // I dont know why , but caller give buflen=%d *p=%d !\n", buflen, *p);
fprintf(stderr,"LoadString // and try to obtain string '%s'\n", p + 1);
}
FreeResource( hrsrc );
dprintf_resource(stddeb,"LoadString // '%s' copied !\n", buffer);
return i;
}
/**********************************************************************
* LoadMenu [USER.150]
*/
HMENU LoadMenu( HINSTANCE instance, SEGPTR menu_name )
{
HMENU hMenu;
HANDLE hMenu_desc;
MENU_HEADER *menu_desc;
if (HIWORD(menu_name))
dprintf_resource( stddeb, "LoadMenu(%04x,'%s')\n",
instance, (char *)PTR_SEG_TO_LIN( menu_name ) );
else
dprintf_resource( stddeb, "LoadMenu(%04x,%04x)\n",
instance, LOWORD(menu_name) );
if (!menu_name) return 0;
if (!(hMenu_desc = RSC_LoadResource( instance, menu_name,
(SEGPTR) NE_RSCTYPE_MENU, NULL )))
return 0;
menu_desc = (MENU_HEADER *) GlobalLock(hMenu_desc);
hMenu = LoadMenuIndirect((LPSTR)menu_desc);
return hMenu;
}
/**********************************************************************
* LoadBitmap
*/
HBITMAP LoadBitmap( HANDLE instance, SEGPTR bmp_name )
{
HBITMAP hbitmap;
HANDLE rsc_mem;
HDC hdc;
long *lp;
int image_size;
int size;
if (HIWORD(bmp_name))
dprintf_resource( stddeb, "LoadBitmap(%04x,'%s')\n",
instance, (char *)PTR_SEG_TO_LIN( bmp_name ) );
else
dprintf_resource( stddeb, "LoadBitmap(%04x,%04x)\n",
instance, LOWORD( bmp_name ) );
if (!instance)
{
if (HIWORD((int)bmp_name)) return 0; /* FIXME: should handle '#xxx' */
return OBM_LoadBitmap( LOWORD((int)bmp_name) );
}
rsc_mem = RSC_LoadResource(instance, bmp_name, (SEGPTR) NE_RSCTYPE_BITMAP,
&image_size);
if (rsc_mem == (HANDLE)NULL) {
printf("LoadBitmap(%04x,%08lx)\n", instance, bmp_name);
return 0;
}
lp = (long *) GlobalLock(rsc_mem);
if (lp == NULL)
{
GlobalFree(rsc_mem);
return 0;
}
if (!(hdc = GetDC(0))) lp = NULL;
size = CONV_LONG (*lp);
if (size == sizeof(BITMAPCOREHEADER)){
CONV_BITMAPCOREHEADER (lp);
hbitmap = ConvertCoreBitmap( hdc, (BITMAPCOREHEADER *) lp );
} else if (size == sizeof(BITMAPINFOHEADER)){
CONV_BITMAPINFO (lp);
hbitmap = ConvertInfoBitmap( hdc, (BITMAPINFO *) lp );
} else hbitmap = 0;
GlobalFree(rsc_mem);
ReleaseDC( 0, hdc );
return hbitmap;
}