示例#1
0
/****************************************************************************
*
*     FUNCTION: GetIconFromInstance
*
*     PURPOSE:  Callback for enumerating resources in a DLL/EXE
*
*     PARAMS:   HINSTANCE hInstance - Instance handle for this module
*               LPTSTR    nIndex    - Resource index
*
*     RETURNS:  HICON - Handle to the icon, NULL for failure
*
* History:
*                July '95 - Created
*
\****************************************************************************/
HICON GetIconFromInstance( HINSTANCE hInstance, LPTSTR nIndex )
{
    HICON	hIcon = NULL;
    HRSRC	hRsrc = NULL;
    HGLOBAL	hGlobal = NULL;
    LPVOID	lpRes = NULL;
    int    	nID;

    // Find the group icon
    if( (hRsrc = FindResource( hInstance, nIndex, RT_GROUP_ICON )) == NULL )
        return NULL;
    if( (hGlobal = LoadResource( hInstance, hRsrc )) == NULL )
        return NULL;
    if( (lpRes = LockResource(hGlobal)) == NULL )
        return NULL;

    // Find this particular image
    nID = LookupIconIdFromDirectory( lpRes, TRUE );
    if( (hRsrc = FindResource( hInstance, MAKEINTRESOURCE(nID), RT_ICON )) == NULL )
        return NULL;
    if( (hGlobal = LoadResource( hInstance, hRsrc )) == NULL )
        return NULL;
    if( (lpRes = LockResource(hGlobal)) == NULL )
        return NULL;
    // Let the OS make us an icon
    hIcon = CreateIconFromResource( lpRes, SizeofResource(hInstance,hRsrc), TRUE, 0x00030000 );
    return hIcon;
}
示例#2
0
HICON
LoadLocalizedIcon(const UINT iconId)
{
    LANGID langId = GetGUILanguage();

    /* find group icon resource */
    HRSRC res = FindResourceLang(RT_GROUP_ICON, MAKEINTRESOURCE(iconId), langId);
    if (res == NULL)
        return NULL;

    HGLOBAL resInfo = LoadResource(o.hInstance, res);
    if (resInfo == NULL)
        return NULL;

    int id = LookupIconIdFromDirectory(resInfo, TRUE);
    if (id == 0)
        return NULL;

    /* find the actual icon */
    res = FindResourceLang(RT_ICON, MAKEINTRESOURCE(id), langId);
    if (res == NULL)
        return NULL;

    resInfo = LoadResource(o.hInstance, res);
    if (resInfo == NULL)
        return NULL;

    DWORD resSize = SizeofResource(o.hInstance, res);
    if (resSize == 0)
        return NULL;

    return CreateIconFromResource(resInfo, resSize, TRUE, 0x30000);
}
示例#3
0
void
WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
{
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
    HICON hicon = NULL;
    BYTE *icon_bmp;
    int icon_len;
    SDL_RWops *dst;
    SDL_Surface *surface;

    /* Create temporary bitmap buffer */
    icon_len = 40 + icon->h * icon->w * 4;
    icon_bmp = SDL_stack_alloc(BYTE, icon_len);
    dst = SDL_RWFromMem(icon_bmp, icon_len);
    if (!dst) {
        SDL_stack_free(icon_bmp);
        return;
    }

    /* Write the BITMAPINFO header */
    SDL_WriteLE32(dst, 40);
    SDL_WriteLE32(dst, icon->w);
    SDL_WriteLE32(dst, icon->h * 2);
    SDL_WriteLE16(dst, 1);
    SDL_WriteLE16(dst, 32);
    SDL_WriteLE32(dst, BI_RGB);
    SDL_WriteLE32(dst, icon->h * icon->w * 4);
    SDL_WriteLE32(dst, 0);
    SDL_WriteLE32(dst, 0);
    SDL_WriteLE32(dst, 0);
    SDL_WriteLE32(dst, 0);

    /* Convert the icon to a 32-bit surface with alpha channel */
    surface = SDL_ConvertSurfaceFormat(icon, SDL_PIXELFORMAT_ARGB8888, 0);
    if (surface) {
        /* Write the pixels upside down into the bitmap buffer */
        int y = surface->h;
        while (y--) {
            Uint8 *src = (Uint8 *) surface->pixels + y * surface->pitch;
            SDL_RWwrite(dst, src, surface->pitch, 1);
        }
        SDL_FreeSurface(surface);

/* TODO: create the icon in WinCE (CreateIconFromResource isn't available) */
#ifndef _WIN32_WCE
        hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
#endif
    }
    SDL_RWclose(dst);
    SDL_stack_free(icon_bmp);

    /* Set the icon for the window */
    SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);

    /* Set the icon in the task manager (should we do this?) */
    SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
}
示例#4
0
void
WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
{
    HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
    HICON hicon = NULL;
    BYTE *icon_bmp;
    int icon_len, mask_len, y;
    SDL_RWops *dst;

    /* Create temporary buffer for ICONIMAGE structure */
    mask_len = (icon->h * (icon->w + 7)/8);
    icon_len = 40 + icon->h * icon->w * sizeof(Uint32) + mask_len;
    icon_bmp = SDL_stack_alloc(BYTE, icon_len);
    dst = SDL_RWFromMem(icon_bmp, icon_len);
    if (!dst) {
        SDL_stack_free(icon_bmp);
        return;
    }

    /* Write the BITMAPINFO header */
    SDL_WriteLE32(dst, 40);
    SDL_WriteLE32(dst, icon->w);
    SDL_WriteLE32(dst, icon->h * 2);
    SDL_WriteLE16(dst, 1);
    SDL_WriteLE16(dst, 32);
    SDL_WriteLE32(dst, BI_RGB);
    SDL_WriteLE32(dst, icon->h * icon->w * sizeof(Uint32));
    SDL_WriteLE32(dst, 0);
    SDL_WriteLE32(dst, 0);
    SDL_WriteLE32(dst, 0);
    SDL_WriteLE32(dst, 0);

    /* Write the pixels upside down into the bitmap buffer */
    SDL_assert(icon->format->format == SDL_PIXELFORMAT_ARGB8888);
    y = icon->h;
    while (y--) {
        Uint8 *src = (Uint8 *) icon->pixels + y * icon->pitch;
        SDL_RWwrite(dst, src, icon->w * sizeof(Uint32), 1);
    }

    /* Write the mask */
    SDL_memset(icon_bmp + icon_len - mask_len, 0xFF, mask_len);

    hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);

    SDL_RWclose(dst);
    SDL_stack_free(icon_bmp);

    /* Set the icon for the window */
    SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);

    /* Set the icon in the task manager (should we do this?) */
    SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
}
示例#5
0
//
// 从资源中加载动画光标
// 如果动画光标是 256 色的,CreateIconFromResource() 就会失败返回 NULL,但 GetLastError() 返回 0
//
HCURSOR
LoadAniCursor(
	const char *pResourceType,  // 资源类型
	UINT        uID )           // 资源 ID
{
	HINSTANCE hInst = _Module.GetResourceInstance();
	HRSRC hRes = FindResource( hInst, MAKEINTRESOURCE( uID ), pResourceType );
	if( hRes )
	{
		DWORD   dwSize = SizeofResource( hInst, hRes );
		HGLOBAL hGlob  = LoadResource( hInst, hRes );
		if( hGlob )
		{
			LPBYTE pBytes = (LPBYTE)LockResource( hGlob ); 
			if( pBytes )
				return( (HCURSOR)CreateIconFromResource( pBytes, dwSize, FALSE, 0x00030000 ) );
		}
	}

	return( NULL );
}
示例#6
0
HICON CURSORICON_LoadFromBuf(const BYTE * bits,DWORD filesize,INT width, INT height,BOOL fCursor, UINT loadflags)
{
	const CURSORICONFILEDIRENTRY *entry;
	const CURSORICONFILEDIR *dir;
	POINT hotspot;
	INT depth=1;

	/* Check for .ani. */
	if (memcmp( bits, "RIFF", 4 ) == 0)
	{//not support
        return  (HCURSOR)CreateIconFromResource((PBYTE)bits,filesize,FALSE,0x00030000);
	}

	dir = (const CURSORICONFILEDIR*) bits;
	if ( filesize < FIELD_OFFSET( CURSORICONFILEDIR, idEntries[dir->idCount] ))
		return 0;

	if(!(loadflags & LR_MONOCHROME))
	{
		HDC hdc=GetDC(NULL);
		depth=GetDeviceCaps(hdc,BITSPIXEL);
		ReleaseDC(NULL,hdc);
	}
	if ( fCursor )
		entry = CURSORICON_FindBestCursorFile( dir, filesize, width, height, depth, loadflags );
	else
		entry = CURSORICON_FindBestIconFile( dir, filesize, width, height, depth, loadflags );

	/* check that we don't run off the end of the file */
	if ( !entry || entry->dwDIBOffset > filesize || entry->dwDIBOffset + entry->dwDIBSize > filesize )
		return 0;

	hotspot.x = entry->xHotspot;
	hotspot.y = entry->yHotspot;
	return create_icon_from_bmi( (const BITMAPINFO *)&bits[entry->dwDIBOffset], filesize - entry->dwDIBOffset,
		NULL, NULL, NULL, hotspot, !fCursor, width, height, loadflags );
}
示例#7
0
/****************************************************************************
*
*     FUNCTION: MakeIconFromResource
*
*     PURPOSE:  Makes an HICON from an icon resource
*
*     PARAMS:   LPICONIMAGE	lpIcon - pointer to the icon resource
*
*     RETURNS:  HICON - handle to the new icon, NULL for failure
*
* History:
*                July '95 - Created
*
\****************************************************************************/
HICON MakeIconFromResource( LPICONIMAGE lpIcon )
{
    HICON        	hIcon = NULL;

    // Sanity Check
    if( lpIcon == NULL )
        return NULL;
    if( lpIcon->lpBits == NULL )
        return NULL;
    // Let the OS do the real work :)
    hIcon = CreateIconFromResourceEx( lpIcon->lpBits, lpIcon->dwNumBytes, TRUE, 0x00030000, 
            (*(LPBITMAPINFOHEADER)(lpIcon->lpBits)).biWidth, (*(LPBITMAPINFOHEADER)(lpIcon->lpBits)).biHeight/2, 0 );
    
    // It failed, odds are good we're on NT so try the non-Ex way
    if( hIcon == NULL )
    {
        // We would break on NT if we try with a 16bpp image
        if(lpIcon->lpbi->bmiHeader.biBitCount != 16)
        {	
            hIcon = CreateIconFromResource( lpIcon->lpBits, lpIcon->dwNumBytes, TRUE, 0x00030000 );
        }
    }
    return hIcon;
}
示例#8
0
bool GraphicsHelps::setWindowIcon(SDL_Window *window, FIBITMAP *img, int iconSize)
{
#ifdef _WIN32
    struct SDL_SysWMinfo wmInfo;
    SDL_VERSION(&wmInfo.version);

    if(-1 == SDL_GetWindowWMInfo(window, &wmInfo))
        return false;

    if(wmInfo.subsystem != SDL_SYSWM_WINDOWS)
        return false;

    HWND windowH = wmInfo.info.win.window;
    HICON hicon = NULL;
    BYTE *icon_bmp;
    unsigned int icon_len, y;
    SDL_RWops *dst;
    unsigned int w = FreeImage_GetWidth(img);
    unsigned int h = FreeImage_GetWidth(img);
    Uint8 *bits = (Uint8 *)FreeImage_GetBits(img);
    unsigned int pitch = FreeImage_GetPitch(img);
    /* Create temporary bitmap buffer */
    icon_len = 40 + h * w * 4;
    icon_bmp = SDL_stack_alloc(BYTE, icon_len);
    dst = SDL_RWFromMem(icon_bmp, icon_len);

    if(!dst)
    {
        SDL_stack_free(icon_bmp);
        return false;
    }

    /* Write the BITMAPINFO header */
    SDL_WriteLE32(dst, 40);
    SDL_WriteLE32(dst, w);
    SDL_WriteLE32(dst, h * 2);
    SDL_WriteLE16(dst, 1);
    SDL_WriteLE16(dst, 32);
    SDL_WriteLE32(dst, BI_RGB);
    SDL_WriteLE32(dst, h * w * 4);
    SDL_WriteLE32(dst, 0);
    SDL_WriteLE32(dst, 0);
    SDL_WriteLE32(dst, 0);
    SDL_WriteLE32(dst, 0);
    y = 0;

    do
    {
        Uint8 *src = bits + y * pitch;
        SDL_RWwrite(dst, src, pitch, 1);
    }
    while(++y < h);

    hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
    SDL_RWclose(dst);
    SDL_stack_free(icon_bmp);
    /* Set the icon for the window */
    SendMessage(windowH, WM_SETICON, (iconSize < 32) ? ICON_SMALL : ICON_BIG, (LPARAM) hicon);
#else
    (void)iconSize;
    SDL_Surface *sicon = GraphicsHelps::fi2sdl(img);
    SDL_SetWindowIcon(window, sicon);
    SDL_FreeSurface(sicon);
    const char *error = SDL_GetError();

    if(*error != '\0')
        return false;

#endif
    return true;
}
bool windows_tray_notification::create_tray_icon()
{
	// getting handle to a 32x32 icon, contained in "WESNOTH_ICON" icon group of wesnoth.exe resources
	const HMODULE wesnoth_exe = GetModuleHandle(NULL);
	if (wesnoth_exe == NULL) {
		return false;
	}

	const HRSRC group_icon_info = FindResource(wesnoth_exe, L"WESNOTH_ICON", RT_GROUP_ICON);
	if (group_icon_info == NULL) {
		return false;
	}

	HGLOBAL hGlobal = LoadResource(wesnoth_exe, group_icon_info);
	if (hGlobal == NULL) {
		return false;
	}

	const PBYTE group_icon_res = static_cast<PBYTE>(LockResource(hGlobal));
	if (group_icon_res == NULL) {
		return false;
	}

	const int nID = LookupIconIdFromDirectoryEx(group_icon_res, TRUE, 32, 32, LR_DEFAULTCOLOR);
	if (nID == 0) {
		return false;
	}

	const HRSRC icon_info = FindResource(wesnoth_exe, MAKEINTRESOURCE(nID), MAKEINTRESOURCE(3));
	if (icon_info == NULL) {
		return false;
	}

	hGlobal = LoadResource(wesnoth_exe, icon_info);
	if (hGlobal == NULL) {
		return false;
	}

	const PBYTE icon_res = static_cast<PBYTE>(LockResource(hGlobal));
	if (icon_res == NULL) {
		return false;
	}

	const HICON icon = CreateIconFromResource(icon_res, SizeofResource(wesnoth_exe, icon_info), TRUE, 0x00030000);
	if (icon == NULL) {
		return false;
	}

	const HWND window = get_window_hanlde();
	if (window == NULL) {
		return false;
	}

	// filling notification structure
	nid = new NOTIFYICONDATA;
	memset(nid, 0, sizeof(&nid));
	nid->cbSize = NOTIFYICONDATA_V2_SIZE;
	nid->hWnd = window;
	nid->uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
	nid->dwInfoFlags = NIIF_USER;
	nid->uVersion = NOTIFYICON_VERSION;
	nid->uCallbackMessage = WM_TRAYNOTIFY;
	nid->uID = ICON_ID;
	nid->hIcon = icon;
#if _WIN32_WINNT >= 0x600
	nid->hBalloonIcon = icon;
#endif
	lstrcpy(nid->szTip, L"The Battle For Wesnoth");

	// creating icon notification
	return Shell_NotifyIcon(NIM_ADD, nid) != FALSE;
}
示例#10
0
//
/// Creates an icon object of the given size from the bits found in the resBits
/// buffer.
//
TIcon::TIcon(const void* resBits, uint32 resSize)
{
  Handle = CreateIconFromResource((PBYTE)resBits, resSize, true, 0x00030000);
  CheckValid();
}
示例#11
0
static HWND 	SearchResource(LPCSTR lpName,
					   int type,
					 DLGPROC pDialogProc,
					 LPARAM param,
					 char *lpFileBase,
					 int TotalFileSize,
					 HWND parentWnd)
{
	char *pResAll = lpFileBase + TotalFileSize;
	PRES pRes = (PRES)lpFileBase;
	char pszSearchedName[256];
	char *pszType = ResourceType(pRes);
	char *pszName;
	int size = ResourceSize(pRes);	
	char Name[512],*bb;
	PDIALOGBOXHEADER pdbh;
	HWND result;
	UINT_PTR ul;

	ul = (UINT_PTR)lpName;
	if (HIWORD(ul) == 0) {
		sprintf(pszSearchedName,"%d",LOWORD(ul));
	}
	else
	if (IsOrd((char *)lpName)) {
		sprintf(pszSearchedName,"%d",OrdID(lpName));
	}
	else if (lpName[1] == 0 && lpName[3] == 0) {
		ConvertWideString((char *)lpName,(char *)pszSearchedName);
	}
	else {
		strcpy(pszSearchedName,lpName);
	}
	do {
		if (pRes->HeaderSize+pRes->DataSize == 0)
			break;
		if (IsOrd((char *)pRes) && OrdID(pRes) == ORDID_RT_DLGINCLUDE) {
			/* Ignore include files */
			;
		}
		else if (IsOrd((char *)pRes) &&
				OrdID(pRes) == ORDID_RT_RESOURCE32) {
	        /*
            * This is the dummy resource that identifies a
            * 32 bit resource file.  This resource should be
            * skipped also.
            */
			}
			else {
			/* This is some other kind of a resource. See if it matches */
				if (pRes->DataSize) {
					int size = ResourceSize(pRes);	
					pszType = ResourceType(pRes);
					if (IsOrd(pszType) && OrdID(pszType) == type) {	
					    pszName = ResourceName(pRes);
						if (!IsOrd(pszName)) {
							if (pszName[1] == 0 && pszName[3] == 0)
								ConvertWideString(pszName,Name);
							else
								strcpy(Name,pszName);
						}
						else {
							sprintf(Name,"%d",OrdID(pszName));
						}
						if (!strcmp(Name,pszSearchedName)) {
							/* found it.*/
							if (type == 5) {
								/* Build a dialog box */
								pdbh = (PDIALOGBOXHEADER) SkipResHeader(pRes);
								bb = malloc(size);
								memcpy(bb,pdbh,size);
								result = CreateDialogIndirectParam(GetModuleHandle(NULL),
									(LPDLGTEMPLATE)bb,
									parentWnd,
									pDialogProc,param);
								free(bb);
								return result;
							}
							else if (type == 4) {
								/* Build a menu */
								return (HWND) ReadMenu((char *)SkipResHeader(pRes));
							}
							else if (type == 3) {
								/* Build an Icon */
								HICON hicon;
								hicon = CreateIconFromResource((PBYTE)SkipResHeader(pRes),
									size,
									TRUE,
									0x30000);
								return (HWND)hicon;
							}
							else if (type == 1) {
								/* Build a cursor */
								return (HWND)CreateIconFromResource((PBYTE)SkipResHeader(pRes),
									size,
									FALSE,
									0x30000);
							}
							else if (type == 2 || type == 14) {
								/* Build bitmap */
								char *start = SkipResHeader(pRes);
								bb = malloc(size);
								memcpy(bb,start,size);
								return (HWND) bb;
							}
						}
					}

				}
			}
			/* Move to the next resource. */
		pRes = (PRES) (((char *) pRes) + pRes->HeaderSize + pRes->DataSize);
        DWordAlign((PBYTE *)&pRes);
	} while (pRes < (PRES) ((char *) pResAll + size));
	return (HWND) 0;
}