Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Is Multiple LoadIcon() safe ?

Posted on 1998-08-22
5
Medium Priority
?
395 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 200 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

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.  …
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

722 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