Home > Software engineering >  ICONS and menu resource
ICONS and menu resource

Time:09-27

In a DLL module I set up a window, the menu icon, the loaded from the DLL module resources a window icon, and a menu:
HICON HICON=LoadIcon (hDllInst, MAKEINTRESOURCE (ICON_ID));
HMENU HMENU=LoadMenu (hDllMod, MAKEINTRESOURCE (MENU_ID));
My question is when the end of the DLL, this hIcon and hMenu represents ICONS and menu resources need to be released? Need to how to release? The handle need to shut down?
The reason this problem is mainly the DLL may be repeated calls to many times, be afraid of resource leaks,

CodePudding user response:

CWinApp: : LoadIcon
HICON LoadIcon (LPCTSTR lpszResourceName) const;

HICON LoadIcon (UINT nIDResource) const;

The Return Value

A handle to an icon if successful; Otherwise a NULL.

The Parameters

LpszResourceName

Points to a null - terminated string that contains the name of the icon resource. You can also use a cstrings for this argument.

NIDResource

The ID number of the icon resource.

Few

Loads of the icon resource named by lpszResourceName or specified by nIDResource from the executable file. The LoadIcon Loads the icon only if it has not had previously the loaded; Otherwise, it retrieves a handle of the existing resource.

You can use the LoadStandardIcon or LoadOEMIcon member function to access the predefined Windows ICONS.

Note This member function calls the Win32 API functionLoadIcon, which can only load the an icon whose size conforms to the SM_CXICON and SM_CYICON system metric values.

CWinApp Overview | Class Members | Hierarchy Chart

See Also CWinApp: : LoadStandardIcon, CWinApp: : LoadOEMIcon, : : LoadIcon


CMenu: : LoadMenu
BOOL LoadMenu (LPCTSTR lpszResourceName);

BOOL LoadMenu (UINT nIDResource);

The Return Value

Nonzero if the menu resource was the loaded successfully. Otherwise 0.

The Parameters

LpszResourceName

Points to a null - terminated string that contains the name of the menu resource to load.

NIDResource

Specifies the menu ID of the menu resource to load.

Few

Loads a menu resource from the application's executable file and attaches it to the CMenu object.

Before exiting, an application must free system resources associated with a menu if the menu is not assigned to a window. An application frees a menu by calling the DestroyMenu member function.

CMenu Overview | Class Members | Hierarchy Chart

See Also CMenu: : AppendMenu, CMenu: : DestroyMenu CMenu: : LoadMenuIndirect, : : LoadMenu

CodePudding user response:

Thank you for your attention! These two functions usage I watched, my question is when not needed, need not to need to do additional measures to explicitly release resources? Such as menu handle is to calculate the core resources, whether need to explicitly closed,
  • Related