Article View: borland.public.cppbuilder.nativeapi
Article #3164Re: LoadImage Vs ExtractIcon
From: Bob Gonder
Date: Thu, 31 Aug 2006 16:47
Date: Thu, 31 Aug 2006 16:47
91 lines
4172 bytes
4172 bytes
Mike Collins wrote:
>Image->Picture->Icon->Handle = LoadImage(hDLL, MAKEINTRESOURCE(12),
>IMAGE_ICON, 32, 32, LR_DEFAULTSIZE);
It doesn't sound like LR_DEFAULTSIZE is compatable with 32,32.
You are asking for exclusive 32,32 icons.
If you used 0,0 with LR_DEFAULTSIZE, you would get 16,16 or SM_CXICON
If you used 0,0 *Without* LR_DEFAULTSIZE, you would get whatever is
available.
>- is it necessary to free the handle that is returned from LoadImage using
>DestroyIcon? I never seem any reference to this when i've seen BCB examples
>and i've never had any resource leaks reported...
No, but its nice to do. From MSDN:
When you are finished using a bitmap, cursor, or icon you loaded
without specifying the LR_SHARED flag, you can release its associated
memory by calling one of the functions in the following table.
The system automatically deletes these resources when the process that
created them terminates; however, calling the appropriate function
saves memory and decreases the size of the process's working set.
So, not a leak, but uses more memory until freed.
>Secondly, is there any advantage to using LoadImage api over ExtractIcon?
LoadImage has more options. And can share loaded resources. And can
select best-fit images from multi-size/colordepth icons.
ExtractIcon has no options nor "best-fit".
> To avoid any possible copyright issues,
To avoid copyright issues, make your own icons.
> However, LoadImage seems to fail if i try
>to load an icon that has an Id grater than 56.
Mine stops at 54 (XP home, SP2)
ExtractIcon works for the full number of icons.
If anyone wants to play with it, compile as console app.
To switch from ExtractIcon to LoadImage, uncomment the 4 lines, and
comment the ExtractIcon.
#include <windows.h>
extern HINSTANCE _hInstance; // global in c0x32
/* ---------------------------------------------------------------- */
void _stdcall ErrorBox( HWND hWnd, DWORD errorcode,LPCTSTR titl)
{ VOID* lpBuffer;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER+FORMAT_MESSAGE_FROM_SYSTEM+70,
NULL,errorcode,0,(char*)&lpBuffer,0,NULL);
MessageBox( hWnd, (char*)lpBuffer, titl,
MB_OK|MB_ICONINFORMATION|MB_TOPMOST );
LocalFree( lpBuffer );
}
/* ---------------------------------------------------------------- */
int main(void)
{
int i;
int max = (int)ExtractIcon( _hInstance,
"C:\\Windows\\system32\\shell32.dll", -1 );
HICON hIcon;
HWND hWnd = 0;
char msg[1024];
// HMODULE hMod = GetModuleHandle(
// "C:\\Windows\\system32\\shell32.dll" );
for( i = 1; i <= max; ++i )
{
// hIcon = LoadImage( hMod, MAKEINTRESOURCE(i), IMAGE_ICON,
// 0,0, LR_DEFAULTCOLOR | LR_SHARED );
hIcon = ExtractIcon( _hInstance,
"C:\\Windows\\system32\\shell32.dll", i );
if( (int)hIcon > 1 )
{
wsprintf( msg, "\r\nIcon Test #%i of %i\r\n", i, max);
ShellAbout ( hWnd, "Icon Tester#About IconTest",
// title bar and first line text
msg, // other dialog text
hIcon ); // icon to display
DestroyIcon( hIcon );
}else{
ErrorBox( hWnd, GetLastError(), "LoadImage Error" );
};
};
return 0;
}
Technical Details
Message-ID:
<itudf25vqa20031niancgc5in17pf91jcs@4ax.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<44f6ea84$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,b9f657fbba67ecb4 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: Bob Gonder <notbg@notmindspring.invalid> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: LoadImage Vs ExtractIcon Date: Thu, 31 Aug 2006 09:47:22 -0700 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <itudf25vqa20031niancgc5in17pf91jcs@4ax.com> References: <44f6ea84$1@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 69.69.87.29 X-Trace: newsgroups.borland.com 1157042838 69.69.87.29 (31 Aug 2006 09:47:18 -0700) Lines: 93 Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail