新聞中心
VB.NET經(jīng)過(guò)長(zhǎng)時(shí)間的發(fā)展,很多用戶都很了解VB.NET Windows API函數(shù)了,這里我發(fā)表一下個(gè)人理解,和大家討論討論。VB.NET要實(shí)現(xiàn)查看文件中的圖標(biāo),目前只使用.Net FrameWork SDK是無(wú)法實(shí)現(xiàn)這種功能的,正如前面所說(shuō),主要是由于.Net FrameWork SDK推出的時(shí)間較短,其功能還不可能面面俱到。

專業(yè)領(lǐng)域包括做網(wǎng)站、網(wǎng)站設(shè)計(jì)、商城網(wǎng)站建設(shè)、微信營(yíng)銷、系統(tǒng)平臺(tái)開發(fā), 與其他網(wǎng)站設(shè)計(jì)及系統(tǒng)開發(fā)公司不同,成都創(chuàng)新互聯(lián)的整合解決方案結(jié)合了幫做網(wǎng)絡(luò)品牌建設(shè)經(jīng)驗(yàn)和互聯(lián)網(wǎng)整合營(yíng)銷的理念,并將策略和執(zhí)行緊密結(jié)合,為客戶提供全網(wǎng)互聯(lián)網(wǎng)整合方案。
#T#解決問(wèn)題的關(guān)鍵是正確使用Windows API函數(shù),其中所涉及到的Windows API函數(shù)主要有二個(gè):其一是獲得指定文件中的圖標(biāo)數(shù)目;其二是從指定文件的指定位置導(dǎo)出圖標(biāo)的Windows句柄。這二個(gè)函數(shù)都位于 “Shell32.dll”文件中,并且函數(shù)的入口點(diǎn)都為“ExtractIcon”。下面是在VB.NET中分別使用DllImport特征類和“Declare”語(yǔ)句申明這二個(gè)VB.NET Windows API函數(shù)的具體方法。
1.使用DllImport特征類來(lái)申明VB.NET Windows API函數(shù):
下面是在VB.NET中使用DllImport特征類申明二個(gè)Windows API函數(shù)的具體示例:
- 函數(shù)ExtractIcon,其功能是是從指定文件的指定位置導(dǎo)出圖標(biāo)的Windows句柄。
- < System.Runtime.InteropServices.DllImport ( "Shell32.dll" , EntryPoint := "ExtractIcon" ) > _
- Public Function _
- ExtractIcon ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As UInt32 ) As System.IntPtr
- End Function
- '函數(shù)Icon_Num,其功能是獲得指定文件中的圖標(biāo)數(shù)目
- < System.Runtime.InteropServices.DllImport ( "Shell32.dll" , EntryPoint := "ExtractIcon" ) > _
- Public Function _
- Icon_Num ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As Integer ) As Integer
- End Function
在使用DllImport特征類申明Windows API函數(shù)時(shí),如果申明的函數(shù)名稱和函數(shù)的入口點(diǎn)相同,則可以在申明Windows API函數(shù)時(shí),省略定義函數(shù)入口點(diǎn)對(duì)應(yīng)的代碼,即EntryPoint對(duì)象字段對(duì)應(yīng)的代碼,這樣聲明ExtractIcon函數(shù)的代碼也可以簡(jiǎn)化為如下所示:
- < System.Runtime.InteropServices.DllImport ( "Shell32.dll" ) > _
- Public Function _
- ExtractIcon ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As UInt32 ) As System.IntPtr
- End Function
2.使用“Declare”語(yǔ)句來(lái)申明Windows API函數(shù):
使用“Declare”語(yǔ)句的確比使用DllImport特征類要簡(jiǎn)單了許多,下面是在VB.NET中使用“Declare”語(yǔ)句來(lái)聲明上述二個(gè)Windows API函數(shù)的具體方法:
- Declare Auto Function ExtractIcon Lib "Shell32.dll" Alias "ExtractIcon"
- ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As UInt32 ) As System.IntPtr
- '聲明ExtractIcon函數(shù)
- Declare Auto Function Icon_Num Lib "Shell32.dll" Alias "ExtractIcon"
- ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As Integer ) As Integer
- '聲明Icon_Num函數(shù)
在VB.NET中聲明Windows API函數(shù)時(shí),“Declare”語(yǔ)句中Alias關(guān)鍵字的作用相當(dāng)于使用DllImport特征類中的EntryPoint對(duì)象字段。同樣在使用 “Declare”語(yǔ)句聲明Windows API函數(shù)時(shí),如果聲明的函數(shù)和函數(shù)的入口點(diǎn)相同,也可以省略Alias關(guān)鍵字對(duì)應(yīng)的代碼,所以ExtractIcon函數(shù)也可以簡(jiǎn)化為如下:
- Declare Auto Function ExtractIcon Lib "Shell32.dll"
- ( ByVal src As System.IntPtr , ByVal strFileName As string , ByVal uiIconIndex As UInt32 )
- As System.IntPtr
下面就結(jié)合一個(gè)示例的編寫過(guò)程來(lái)掌握的這二個(gè)Windows API函數(shù)的具體使用方法,這個(gè)示例的作用就是讀取指定文件中的圖標(biāo)數(shù)目,并顯示文件中的圖標(biāo)。
網(wǎng)頁(yè)名稱:VB.NETWindowsAPI函數(shù)兩步通
瀏覽地址:http://fisionsoft.com.cn/article/coggphg.html


咨詢
建站咨詢
