Just another collection of code snippets from me to you.
(also check out my UI Snippets)
Use this as a "Quick Reference Guide" when you need to remember "how to it"
VB.net Code Snippets Reference
Move a File
Code:
My.Computer.FileSystem.CopyFile("FileLocaion", "FileDestination")
Save Window Size Settings
Code:
If Me.WindowState = FormWindowState.Normal Then
My.Settings.WindowSize = Me.Size
End If
Save Windows Location
Code:
If Me.WindowState = FormWindowState.Normal Then
My.Settings.WindowLocation = Me.Location
End If
Loads a windows previous size from settings
Code:
If Not My.Settings.WindowSize.Width = 0 Then
Me.Size = My.Settings.WindowSize
End If
Loads Previous Locations From Settings
Code:
If Not My.Settings.WindowLocation.X = 0 Then
Me.Location = My.Settings.WindowLocation
End If
Auto Update Previous Version Settings
Code:
If My.Settings.CallUpgrade = True Then
My.Settings.Upgrade()
My.Settings.CallUpgrade = False
End If
Send Input to Send Mouse Clicks
Declare
Code:
Public Structure MOUSEINPUT
Public dx As Integer
Public dy As Integer
Public mouseData As Integer
Public dwFlags As Integer
Public dwtime As Integer
Code:
Code:
Public Sub MouseClick()
Dim inputme(0) As INPUT_TYPE
inputme(0).xi.dx = 0
inputme(0).xi.dy = 0
inputme(0).xi.mouseData = 0
inputme(0).xi.dwFlags = M_MOVE + M_LD + M_LU
inputme(0).xi.dwtime = 0
inputme(0).xi.dwExtraInfo = 0
inputme(0).dwType = INPUT_MOUSE
SendInput(1, inputme(0), Len(inputme(0)))
SetCursorPos(xyC)
End Sub
Get Windows Title
Declaration:This works with one textbox and one Button, But the code can be used where ever you like.
Code:
Dim mce As Boolean
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Module
Code:
Type POINTAPI
x As Long
y As Long
End Type
Code
Code:
Private Sub Button1_Click()
mse = True
intRetVal = SetCapture(hwnd)
End Sub
Private Sub Form_Load()
mse = False
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim window As Long
Dim buffer As String * 1024
Dim ptPoint As POINTAPI
If mse Then
ptPoint.x = x
ptPoint.y = y
retval = ClientToScreen(hwnd, ptPoint)
window = WindowFromPoint(ptPoint.x, ptPoint.y)
lngRetVal = GetWindowText(window, buffer, 1024)
Text1.Text = buffer
End If
End Sub
Play Wav File
Declarations
Code:
Public Const SND_ALIAS = &H10000
Public Const SND_ASYNC = &H1
Public Const SND_LOOP = &H8
Public Const SND_NOWAIT = &H2000
Public Const SND_SYNC = &H0
Code
(place in any event or trigger you like)
Code:
Dim sps As Long
sps = sndPlaySound("location/file.wav", SND_SYNC)
Detect of computer has a wav compatible Sound Card...
Declarations
Code:
Private Declare Function waveOutGetNumDevs Lib "winmm" () As Long
Code
Code:
Dim w As Long
w = waveOutGetNumDevs()
If i > 0 Then (there would have to be atleast 1 sound card)
MsgBox "Wav Compatible"
Else
MsgBox "Non Wav Comp."
End If