Solved

Is Multiple LoadIcon() safe ?

Posted on 1998-08-22
5
393 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

631 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