Solved

Is Multiple LoadIcon() safe ?

Posted on 1998-08-22
5
388 Views
Last Modified: 2013-12-03
Dear experts

I'm using VC++5.0 SP3 on WIndows NT 4.0 SP3.
In my app, I'd like to use LoadIcon() several times
for a button control in a DialogBar to notice user the situaltion is changed.
But I'm afraid that if I use LoadIcon() for a Button Control, there may take place resourse leak or memory leak...
Is it safe to using LoadIcon() multiple times for a Button Control ?

Any comments will be appreciated.
0
Comment
Question by:okg
5 Comments
 
LVL 11

Expert Comment

by:alexo
ID: 1413814
I think so.  LoadIcon() behaves similarly to the more generic LoadResource().
Here's what the documentation of LoadResource() says:

"Both Windows 95 and Windows NT automatically free resources. You do not need to call the FreeResource function to free a resource loaded by using the LoadResource function."

So, no leaks.

0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 100 total points
ID: 1413815
 Function Load Icon

HICON LoadIcon(hinst, pszIcon)

HINSTANCE hinst;      /* handle of application instance      */
LPCSTR pszIcon;      /* icon-name string or icon resource identifier      */

The LoadIcon function loads the specified icon resource
from the executable file associated with the given
application instance.

This function loads the icon resource only
if it has not been loaded; otherwise, it retrieves a handle
of the existing resource.

An application can use the LoadIcon function to access
the predefined icons used by Windows.
To do this, the application must set the hinst parameter
to NULL and the pszIcon parameter to one of the following values:

Value      Meaning

IDI_APPLICATION      Default application icon.
IDI_ASTERISK      Asterisk (used in informative messages).
IDI_EXCLAMATION      Exclamation point (used in warning messages).
IDI_HAND      Hand-shaped icon (used in serious warning messages).
IDI_QUESTION      Question mark (used in prompting messages).

It is not necessary to destroy these system icons.
But an application should use the DestroyIcon function
to destroy any private icons it loads.

If you use LoadIcon and  DestroyIcon , it is very save!

0
 
LVL 23

Expert Comment

by:chensu
ID: 1413816
I agree with alexo.

"It is only necessary to call DestroyIcon for icons and cursors created with the CreateIconIndirect function."
0
 

Author Comment

by:okg
ID: 1413817
Thanks a lot.

I'm using LoadIcon() for custom Icon. i.e. I drew it.
No leak anyway ?
0
 
LVL 11

Expert Comment

by:alexo
ID: 1413818
None.  Don't worry.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  â€¦
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now