VB.Net Tutorial/Windows/IE Address Book

Материал из VB Эксперт
Перейти к: навигация, поиск

Address box autocomplete

Imports System.Runtime.InteropServices
Imports System.Windows.Forms
public class AutoComplete
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
  Inherits System.Windows.Forms.Form
  Public Sub New()
    MyBase.New()
    InitializeComponent()
  End Sub
  Private components As System.ruponentModel.IContainer
  Friend WithEvents Label1 As System.Windows.Forms.Label
  Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
  Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
  Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.Label1 = New System.Windows.Forms.Label()
    Me.TextBox1 = New System.Windows.Forms.TextBox()
    Me.CheckBox1 = New System.Windows.Forms.CheckBox()
    Me.CheckBox2 = New System.Windows.Forms.CheckBox()
    Me.SuspendLayout()
    "
    "Label1
    "
    Me.Label1.Location = New System.Drawing.Point(10, 15)
    Me.Label1.Name = "Label1"
    Me.Label1.Size = New System.Drawing.Size(70, 20)
    Me.Label1.TabIndex = 0
    Me.Label1.Text = "TextBox:"
    "
    "TextBox1
    "
    Me.TextBox1.Location = New System.Drawing.Point(65, 10)
    Me.TextBox1.Name = "TextBox1"
    Me.TextBox1.Size = New System.Drawing.Size(235, 22)
    Me.TextBox1.TabIndex = 1
    Me.TextBox1.Text = ""
    "
    "CheckBox1
    "
    Me.CheckBox1.Location = New System.Drawing.Point(20, 45)
    Me.CheckBox1.Name = "CheckBox1"
    Me.CheckBox1.Size = New System.Drawing.Size(145, 20)
    Me.CheckBox1.TabIndex = 2
    Me.CheckBox1.Text = "Auto Complete (Suggest)"
    "
    "CheckBox2
    "
    Me.CheckBox2.Location = New System.Drawing.Point(20, 65)
    Me.CheckBox2.Name = "CheckBox2"
    Me.CheckBox2.Size = New System.Drawing.Size(145, 20)
    Me.CheckBox2.TabIndex = 3
    Me.CheckBox2.Text = "Auto Complete (Append)"
    "
    "Form1
    "
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 15)
    Me.ClientSize = New System.Drawing.Size(307, 93)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.CheckBox2, Me.CheckBox1, Me.TextBox1, Me.Label1})
    Me.MaximizeBox = False
    Me.Name = "Form1"
    Me.Text = "Auto Complete"
    Me.ResumeLayout(False)
  End Sub
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    AutoComplete()
  End Sub
  Private Sub CheckBox1_CheckStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckStateChanged
    AutoComplete()
  End Sub
  Private Sub CheckBox2_CheckStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckStateChanged
    AutoComplete()
  End Sub
  Private Sub AutoComplete()
    Dim dwFlags As Integer
    If CheckBox1.CheckState Then
      dwFlags = SHACF_URLALL Or SHACF_FILESYSTEM Or SHACF_AUTOSUGGEST_FORCE_ON
      If CheckBox2.CheckState Then
        dwFlags = dwFlags Or SHACF_AUTOAPPEND_FORCE_ON
      Else
        dwFlags = dwFlags Or SHACF_AUTOAPPEND_FORCE_OFF
      End If
    Else
      dwFlags = SHACF_URLALL Or SHACF_FILESYSTEM Or SHACF_AUTOSUGGEST_FORCE_OFF
      If CheckBox2.CheckState Then
        dwFlags = dwFlags Or SHACF_AUTOAPPEND_FORCE_ON
      Else
        dwFlags = dwFlags Or SHACF_AUTOAPPEND_FORCE_OFF
      End If
    End If
    SHAutoComplete(TextBox1.Handle.ToInt32, dwFlags)
  End Sub
  Public Const SHACF_DEFAULT As Integer = &H0S
  Public Const SHACF_FILESYSTEM As Integer = &H1S
  Public Const SHACF_URLHISTORY As Integer = &H2S
  Public Const SHACF_URLMRU As Integer = &H4S
  Public Const SHACF_USETAB As Integer = &H8S
  Public Const SHACF_FILESYS_ONLY As Integer = &H10S
  Public Const SHACF_AUTOSUGGEST_FORCE_ON As Integer = &H10000000
  Public Const SHACF_AUTOSUGGEST_FORCE_OFF As Integer = &H20000000
  Public Const SHACF_AUTOAPPEND_FORCE_ON As Integer = &H40000000
  Public Const SHACF_AUTOAPPEND_FORCE_OFF As Integer = &H80000000
  Public Const SHACF_URLALL As Integer = (SHACF_URLHISTORY Or SHACF_URLMRU)
  Public Declare Function SHAutoComplete Lib "Shlwapi.dll" (ByVal hwndEdit As Integer, ByVal dwFlags As Integer) As Integer
End Class

Open URL

Imports System.Runtime.InteropServices

public class OpenURLDialog
    Public Shared Sub Main
      Dim proc As New System.Diagnostics.Process()
      Try
        proc.Start("rundll32.exe", "shdocvw.dll,OpenURL www.vbex.ru" )
      Catch ex As Exception
        Console.WriteLine(ex.StackTrace.ToString())
      End Try
    
    End Sub
End Class

Module Module1
  Public Const CSIDL_PROGRAMS As Short = &H2S
  " My Documents
  Public Const CSIDL_PERSONAL As Short = &H5S
  Public Const CSIDL_FAVORITES As Short = &H6S
  Public Const CSIDL_STARTUP As Short = &H7S
  Public Const CSIDL_STARTMENU As Short = &HBS
  Public Const CSIDL_DESKTOPDIRECTORY As Short = &H10S
  " {Windows}\ShellNew
  Public Const CSIDL_TEMPLATES As Short = &H15S
  Public Const CSIDL_COMMON_STARTMENU As Short = &H16S
  Public Const CSIDL_COMMON_PROGRAMS As Short = &H17S
  Public Const CSIDL_COMMON_STARTUP As Short = &H18S
  Public Const CSIDL_COMMON_DESKTOPDIRECTORY As Short = &H19S
  Public Const CSIDL_APPDATA As Short = &H1AS
  Public Const CSIDL_COMMON_FAVORITES As Short = &H1FS
  " All Users\Application Data Windows NT
  Public Const CSIDL_COMMON_APPDATA As Short = &H23S
  " nShowCmd
  Public Const SW_HIDE As Short = 0
  Public Const SW_SHOWNORMAL As Short = 1
  Public Const SW_SHOWMINIMIZED As Short = 2
  Public Const SW_SHOWMAXIMIZED As Short = 3
  Public Const SW_MAXIMIZE As Short = 3
  Public Const SW_SHOWNOACTIVATE As Short = 4
  Public Const SW_SHOW As Short = 5
  Public Const SW_MINIMIZE As Short = 6
  Public Const SW_SHOWMINNOACTIVE As Short = 7
  Public Const SW_SHOWNA As Short = 8
  Public Const SW_RESTORE As Short = 9
  " Error Code
  Public Const ERROR_FILE_NOT_FOUND As Short = 2
  Public Const ERROR_PATH_NOT_FOUND As Short = 3
  Public Const ERROR_BAD_FORMAT As Short = 11
  Public Const SE_ERR_FNF As Short = 2
  Public Const SE_ERR_PNF As Short = 3
  Public Const SE_ERR_ACCESSDENIED As Short = 5
  Public Const SE_ERR_OOM As Short = 8
  Public Const SE_ERR_SHARE As Short = 26
  Public Const SE_ERR_ASSOCINCOMPLETE As Short = 27
  Public Const SE_ERR_DDETIMEOUT As Short = 28
  Public Const SE_ERR_DDEFAIL As Short = 29
  Public Const SE_ERR_DDEBUSY As Short = 30
  Public Const SE_ERR_NOASSOC As Short = 31
  Public Const SE_ERR_DLLNOTFOUND As Short = 32
  Public Declare Function DoAddToFavDlg Lib "shdocvw.dll" (ByVal hwnd As Integer, ByVal szPath As String, ByVal nSizeOfPath As Integer, ByVal szTitle As String, ByVal nSizeOfTitle As Integer, ByVal pidl As Integer) As Integer
  Public Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Integer, ByVal nFolder As Integer, ByRef pidl As Integer) As Integer
  Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpSectionName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
End Module