VB.NET作为一款功能强大的面向对象语言,为我们带来了很多不一样的体验。我们今天可以通过对VB.NET调用WinAPI的操作技巧的掌握,来体验一下这款语言给我们带来的不同之处,从而初步掌握它的应用技巧。
创新互联建站凭借专业的设计团队扎实的技术支持、优质高效的服务意识和丰厚的资源优势,提供专业的网站策划、成都网站设计、做网站、成都外贸网站建设公司、网站优化、软件开发、网站改版等服务,在成都10年的网站建设设计经验,为成都成百上千家中小型企业策划设计了网站。
以下为VB.NET调用WinAPI的演示实例:
- Declare Auto Function MBox Lib
"user32.dll" _- Alias "MessageBox" (ByVal hWnd
As Integer, _- ByVal txt As String, ByVal
caption As String, _- ByVal Typ As Integer) As Integer
- '定义一些要调用参数
- Const MB_ICONQUESTION = &H20L
- Const MB_YESNO = &H4
- Const IDYES = 6
- Const IDNO = 7
- Private Sub Button1_Click(ByVal
sender As System.Object, ByVal e
As System.EventArgs) Handles
Button1.Click- Dim RetVal As Integer ' 存储返回的值.
- RetVal = MBox(0, "调用WinApi成功否?",
"Windows API 信息框", _- MB_ICONQUESTION Or MB_YESNO)
- ' Check the return value.
- If RetVal = IDYES Then
- MsgBox("您选择了是")
- Else
- MsgBox("您选择了不是")
- End If
- End Sub
以下附上本CALLAPI.vb的所有代码。各位可根据自己的要求对这段VB.NET调用WinAPI代码自行修改。
- Public Class CallApi
- Inherits System.Windows.Forms.Form
- Declare Auto Function MBox Lib
"user32.dll" _- Alias "MessageBox" (ByVal hWnd
As Integer, _- ByVal txt As String, ByVal
caption As String, _- ByVal Typ As Integer) As Integer
- '定义一些要调用参数
- Const MB_ICONQUESTION = &H20L
- Const MB_YESNO = &H4
- Const IDYES = 6
- Const IDNO = 7
- #Region " Windows Form Designer
generated code "- Public Sub New()
- MyBase.New()
- 'This call is required by the
Windows Form Designer.- InitializeComponent()
- 'Add any initialization after the
InitializeComponent() call- End Sub
- 'Form overrides dispose to clean
up the component list.- Protected Overloads Overrides Sub
Dispose(ByVal disposing As Boolean)- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- 'Required by the Windows
Form Designer- Private components As System.
ComponentModel.IContainer- 'NOTE: The following procedure is
required by the Windows Form Designer- 'It can be modified using the
Windows Form Designer.- 'Do not modify it using the code editor.
- Friend WithEvents Button1 As System.
Windows.Forms.Button
Private Sub InitializeComponent()- Me.Button1 = New System.Windows.Forms.Button()
- Me.SuspendLayout()
- '
- 'Button1
- '
- Me.Button1.Location = New System.
Drawing.Point(88, 56)- Me.Button1.Name = "Button1"
- Me.Button1.Size = New System.Drawing.Size(168, 48)
- Me.Button1.TabIndex = 0
- Me.Button1.Text = "调用API的信息框"
- '
- 'CallApi
- '
- Me.AutoScaleBaseSize = New System.
Drawing.Size(5, 13)- Me.ClientSize = New System.Drawing.Size(384, 205)
- Me.Controls.AddRange(New System.Windows.
Forms.Control() {Me.Button1})- Me.Name = "CallApi"
- Me.Text = "CallApi"
- Me.ResumeLayout(False)
- End Sub
- #End Region
- Private Sub Button1_Click(ByVal sender
As System.Object, ByVal e As System.
EventArgs) Handles Button1.Click- Dim RetVal As Integer ' 存储返回的值.
- RetVal = MBox(0, "调用WinApi成功否?",
"Windows API 信息框", _- MB_ICONQUESTION Or MB_YESNO)
- ' Check the return value.
- If RetVal = IDYES Then
- MsgBox("您选择了是")
- Else
- MsgBox("您选择了不是")
- End If
- End Sub
- End Class
VB.NET调用WinAPI代码示例就为大家介绍到这里。
文章名称:VB.NET调用WinAPI实例探讨
网页URL:http://www.csdahua.cn/qtweb/news48/502748.html
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网