用vb.net开发api viewer(1)
发表于:2007-06-30来源:作者:点击数:
标签:
下面我们要做的是利用 vb .net 开发 类似于vb6.0中的api viewer tools的工具,它可以向我们展示利用 vb.net 和C#如何调用win32 的api函数 利用vb.net或c#调用api不是一件容易的事,因为语法等已经发生了很大的变化,愿这篇文章给大家带来帮助 确信你的机器文件
下面我们要做的是利用
vb.net开发类似于vb6.0中的api viewer tools的工具,它可以向我们展示利用
vb.net和C#如何调用win32 的api函数
利用vb.net或c#调用api不是一件容易的事,因为语法等已经发生了很大的变化,愿这篇文章给大家带来帮助
确信你的机器文件包含安装vs6.0所安装的 Microsoft Visual Studio\Common\Tools\Winapi目录下的win32api.txt等文件
我们要查看的就是这个文件,如同使用api viewer tools一样软件的界面如下
下面我将给出代码
新建vb.net应用程序命名为api.net
添加引用
system
system.data
system.drawing
system.
windows.forms
system.xml
添加窗体(Viewer.vb)
代码如下
Public Class frmViewer
Inherits System.Windows.Forms.Form
#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
Friend WithEvents cmbOption As System.Windows.Forms.ComboBox
Friend WithEvents lstItem As System.Windows.Forms.ListBox
Friend WithEvents txtSearch As System.Windows.Forms.TextBox
Friend WithEvents txtOutPut As System.Windows.Forms.RichTextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents txtAdd As System.Windows.Forms.RichTextBox
Friend WithEvents btAdd As System.Windows.Forms.Button
Friend WithEvents btCopy As System.Windows.Forms.Button
Friend WithEvents btClear As System.Windows.Forms.Button
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents optPublic As System.Windows.Forms.RadioButton
Friend WithEvents optPrivate As System.Windows.Forms.RadioButton
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
Friend WithEvents optCSharp As System.Windows.Forms.RadioButton
Friend WithEvents optVB As System.Windows.Forms.RadioButton
@#Required by the Windows Form Designer
Private components As System.ComponentModel.Container
@#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.
<System.Diagnostics.De
buggerStepThrough()> Private Sub InitializeComponent()
Me.txtAdd = New System.Windows.Forms.RichTextBox()
Me.optVB = New System.Windows.Forms.RadioButton()
Me.btClear = New System.Windows.Forms.Button()
Me.cmbOption = New System.Windows.Forms.ComboBox()
Me.btCopy = New System.Windows.Forms.Button()
Me.lstItem = New System.Windows.Forms.ListBox()
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog()
Me.Label4 = New System.Windows.Forms.Label()
Me.txtOutPut = New System.Windows.Forms.RichTextBox()
Me.btAdd = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.MenuItem5 = New System.Windows.Forms.MenuItem()
Me.MenuItem6 = New System.Windows.Forms.MenuItem()
Me.optCSharp = New System.Windows.Forms.RadioButton()
Me.MenuItem3 = New System.Windows.Forms.MenuItem()
Me.MainMenu1 = New System.Windows.Forms.MainMenu()
Me.MenuItem1 = New System.Windows.Forms.MenuItem()
Me.MenuItem2 = New System.Windows.Forms.MenuItem()
Me.MenuItem4 = New System.Windows.Forms.MenuItem()
Me.optPrivate = New System.Windows.Forms.RadioButton()
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.optPublic = New System.Windows.Forms.RadioButton()
Me.GroupBox2 = New System.Windows.Forms.GroupBox()
Me.txtSearch = New System.Windows.Forms.TextBox()
Me.GroupBox1.SuspendLayout()
Me.GroupBox2.SuspendLayout()
Me.SuspendLayout()
@#
@#txtAdd
@#
Me.txtAdd.Location = New System.Drawing.Point(9, 280)
Me.txtAdd.Name = "txtAdd"
Me.txtAdd.ReadOnly = True
Me.txtAdd.Size = New System.Drawing.Size(741, 205)
Me.txtAdd.TabIndex = 8
Me.txtAdd.Text = ""
@#
@#optVB
@#
Me.optVB.Checked = True
Me.optVB.Location = New System.Drawing.Point(69, 19)
Me.optVB.Name = "optVB"
Me.optVB.Size = New System.Drawing.Size(161, 15)
Me.optVB.TabIndex = 0
Me.optVB.TabStop = True
Me.optVB.Text = "Visual Basic.NET"
@#
@#btClear
@#
Me.btClear.Location = New System.Drawing.Point(512, 248)
Me.btClear.Name = "btClear"
Me.btClear.Size = New System.Drawing.Size(132, 25)
Me.btClear.TabIndex = 11
Me.btClear.Text = "C&lear"
@#
@#cmbOption
@#
Me.cmbOption.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cmbOption.DropDownWidth = 218
Me.cmbOption.Items.AddRange(New Object() {"Const
ants", "Declares", "Types"})
Me.cmbOption.Location = New System.Drawing.Point(10, 23)
Me.cmbOption.Name = "cmbOption"
Me.cmbOption.Size = New System.Drawing.Size(279, 20)
Me.cmbOption.Sorted = True
Me.cmbOption.TabIndex = 0
@#
@#btCopy
@#
Me.btCopy.Location = New System.Drawing.Point(297, 248)
Me.btCopy.Name = "btCopy"
Me.btCopy.Size = New System.Drawing.Size(132, 25)
Me.btCopy.TabIndex = 10
Me.btCopy.Text = "&Copy"
@#
@#lstItem
@#
Me.lstItem.ItemHeight = 12
Me.lstItem.Location = New System.Drawing.Point(9, 131)
Me.lstItem.Name = "lstItem"
Me.lstItem.Size = New System.Drawing.Size(279, 100)
Me.lstItem.TabIndex = 1
@#
@#Label4
@#
Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label4.Location = New System.Drawing.Point(13, 108)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(270, 20)
Me.Label4.TabIndex = 7
Me.Label4.Text = "API Header"
@#
@#txtOutPut
@#
Me.txtOutPut.Location = New System.Drawing.Point(307, 131)
Me.txtOutPut.Name = "txtOutPut"
Me.txtOutPut.ReadOnly = True
Me.txtOutPut.Size = New System.Drawing.Size(444, 110)
Me.txtOutPut.TabIndex = 3
Me.txtOutPut.Text = ""
@#
@#btAdd
@#
Me.btAdd.Location = New System.Drawing.Point(82, 248)
Me.btAdd.Name = "btAdd"
Me.btAdd.Size = New System.Drawing.Size(132, 25)
Me.btAdd.TabIndex = 9
Me.btAdd.Text = "&Add"
@#
@#Label1
@#
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(307, 108)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(439, 17)
Me.Label1.TabIndex = 4
Me.Label1.Text = "Actual API Text"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
@#
@#Label2
@#
Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(12, 2)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(273, 18)
Me.Label2.TabIndex = 5
Me.Label2.Text = "API Type"
@#
@#Label3
@#
Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(12, 56)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(277, 16)
Me.Label3.TabIndex = 6
Me.Label3.Text = "Enter Search text"
@#
@#MenuItem5
@#
Me.MenuItem5.Index = 1
Me.MenuItem5.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem6})
Me.MenuItem5.Text = "Help"
@#
@#MenuItem6
@#
Me.MenuItem6.Index = 0
Me.MenuItem6.Text = "About"
@#
@#optCSharp
@#
Me.optCSharp.Location = New System.Drawing.Point(255, 17)
Me.optCSharp.Name = "optCSharp"
Me.optCSharp.Size = New System.Drawing.Size(161, 15)
Me.optCSharp.TabIndex = 1
Me.optCSharp.Text = "C#"
@#
@#MenuItem3
@#
Me.MenuItem3.Index = 1
Me.MenuItem3.Text = "-"
@#
@#MainMenu1
@#
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem5})
@#
@#MenuItem1
@#
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2, Me.MenuItem3, Me.MenuItem4})
Me.MenuItem1.Text = "File"
@#
@#MenuItem2
@#
Me.MenuItem2.Index = 0
Me.MenuItem2.Text = "Load Text File"
@#
@#MenuItem4
@#
Me.MenuItem4.Index = 2
Me.MenuItem4.Text = "Exit"
@#
@#optPrivate
@#
Me.optPrivate.Location = New System.Drawing.Point(255, 17)
Me.optPrivate.Name = "optPrivate"
Me.optPrivate.Size = New System.Drawing.Size(161, 15)
Me.optPrivate.TabIndex = 1
Me.optPrivate.Text = "Private"
@#
@#GroupBox1
@#
Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.optPrivate, Me.optPublic})
Me.GroupBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.GroupBox1.Location = New System.Drawing.Point(307, 59)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(444, 40)
Me.GroupBox1.TabIndex = 12
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "Declare Scope"
@#
@#optPublic
@#
Me.optPublic.Checked = True
Me.optPublic.Location = New System.Drawing.Point(69, 19)
Me.optPublic.Name = "optPublic"
Me.optPublic.Size = New System.Drawing.Size(161, 15)
Me.optPublic.TabIndex = 0
Me.optPublic.TabStop = True
Me.optPublic.Text = "Public "
@#
@#GroupBox2
@#
Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.optCSharp, Me.optVB})
Me.GroupBox2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.GroupBox2.Location = New System.Drawing.Point(307, 7)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(444, 40)
Me.GroupBox2.TabIndex = 12
Me.GroupBox2.TabStop = False
Me.GroupBox2.Text = "Language"
@#
@#txtSearch
@#
Me.txtSearch.Location = New System.Drawing.Point(10, 76)
Me.txtSearch.Name = "txtSearch"
Me.txtSearch.Size = New System.Drawing.Size(279, 21)
Me.txtSearch.TabIndex = 2
Me.txtSearch.Text = ""
@#
@#frmViewer
@#
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(764, 496)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox2, Me.GroupBox1, Me.btClear, Me.btCopy, Me.btAdd, Me.txtAdd, Me.Label4, Me.Label3, Me.Label2, Me.Label1, Me.txtOutPut, Me.txtSearch, Me.lstItem, Me.cmbOption})
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.MaximizeBox = False
Me.Menu = Me.MainMenu1
Me.Name = "frmViewer"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "API Viewer"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
原文转自:http://www.ltesting.net