Public Class API
Public Shared Function <DllImport("user32.dll")>_
MessageBox(Byval Hwnd As Integer,ByVal [Text] As String,_
ByVal Caption As String, ByVal Type As Integer) As Integer
End Funtion
End Class
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
再将以下代码添加到已添加按钮的 Click 事件处理程序中来调用该过程,并提供适当的参数:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim RetVal As Integer ' Stores the return value.
RetVal = MBox(0, "Declare DLL Test", "Windows API MessageBox", _
MB_ICONQUESTION Or MB_YESNO)
' Check the return value.
If RetVal = IDYES Then
MsgBox("You chose Yes")
Else
MsgBox("You chose No")
End If
End Sub