我在一個DLL模塊里建立了一個視窗,有選單有圖示。如下從DLL模塊資源里加載了一個視窗圖示和一個選單:
HICON hIcon = LoadIcon(hDllInst, MAKEINTRESOURCE(ICON_ID));
HMENU hMenu = LoadMenu(hDllMod, MAKEINTRESOURCE(MENU_ID));
我的問題是當DLL退出的時候,這個hIcon和和hMenu代表的圖示資源和選單資源需要釋放嗎?需要的話如何釋放?這個句柄需要關閉嗎?
之所以提這個問題主要是這個DLL可能被重復呼叫很多次,怕資源泄漏。
uj5u.com熱心網友回復:
CWinApp::LoadIconHICON LoadIcon( LPCTSTR lpszResourceName ) const;
HICON LoadIcon( UINT nIDResource ) const;
Return Value
A handle to an icon if successful; otherwise NULL.
Parameters
lpszResourceName
Points to a null-terminated string that contains the name of the icon resource. You can also use a CString for this argument.
nIDResource
ID number of the icon resource.
Remarks
Loads the icon resource named by lpszResourceName or specified by nIDResource from the executable file. LoadIcon loads the icon only if it has not been previously 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 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 );
Return Value
Nonzero if the menu resource was loaded successfully; otherwise 0.
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.
Remarks
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
uj5u.com熱心網友回復:
謝謝關注!這兩個函式用法我看了。我的疑問是在不需要的時候,需不需要做其他額外的措施顯式釋放資源?比如選單句柄是否算核心資源,是否需要顯式關閉。轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/82931.html
標籤:資源
上一篇:如何創建正確的.xlsx檔案?????????????
下一篇:windows編程哪里抄錯了啊。
