' Hide/Show Taskbar
' Wait for a process to finish
' Set up a listbox with TAB delimited columns.
' Get the system time
' Possible sharable VB memory
' Search a ListBox Control Quickly
' HOWTO: Write Data to a File Using WriteFile API
' HOWTO: Position a MsgBox Using a Windows Hook Procedure
' HOWTO: Minimize All Windows From Visual Basic
' Get error messages directly from the system
' HOWTO: Use a Satellite DLL for Localization Purposes
' An Alternate Method of Preventing Duplicate Instances
' How to Determine the Number of Lines in a Textbox
' Adding a Vertical Splitter Bar
' Closing all the forms
' Canceling a X-Button-Click
' Using the Clipboard
' HOWTO: Modify the Width of the Drop Down List in a Combo Box
'**************************************
'     Hide/Show Taskbar
'**************************************

Dim hWnd1 As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
	(ByVal lpClassName As String, _
	ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "user32" _
	(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
	ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
	ByVal cy As Long, ByVal wFlags As Long) As Long 
Const SWP_HIDEWINDOW = &H80
Const SWP_SHOWWINDOW = &H40

hWnd1 = FindWindow("Shell_traywnd", "")
'To hide the Taskbar, use this code:
Call SetWindowPos(hwnd1, 0, 0, 0, 0, 0, SWP_HIDEWINDOW)
'To show it again:
Call SetWindowPos(hwnd1, 0, 0, 0, 0, 0, SWP_SHOWWINDOW)




'**************************************
'     Wait for a process to finish
'**************************************

Public Const SYNCHRONIZE = &H100000  
Public Const INFINITE = &HFFFF
Public Const WAIT_OBJECT_0 = 0
Public Const WAIT_TIMEOUT = &H102

Declare Function OpenProcess Lib "kernel32" _
	(ByVal dwDesiredAccess As Long, _
	ByVal bInheritHandle As Long, _
	ByVal dwProcessId As Long) As Long
Declare Function WaitForSingleObject Lib "kernel32" _
	(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Dim lPid As Long
Dim lHnd As Long
Dim lRet As Long

If Trim$(txtApp) = "" Then Exit Sub

lPid = Shell(txtApp.Text, vbNormalFocus)
If lPid <> 0 Then
        lHnd = OpenProcess(SYNCHRONIZE, 0, lPid)
        If lHnd <> 0 Then                                                      
                lRet = WaitForSingleObject(lHnd, INFINITE) 
                CloseHandle (lHnd) 
        End If
        MsgBox "Just terminated.", vbInformation, "Shelled Application"
End If



'**************************************
' Set up a listbox with TAB delimited columns.
' Add the desired tabstops to an array.
'
' NOTE: tabstops are defined in terms of "dialog units". While the
'       GetDialogBaseUnits function combined with a simple calculation
'       can be used to convert between dialog units and pixels, the
'       easiest way to set tabstops where you want is by trial and error.
'**************************************

Public Const LB_SETTABSTOPS = &H192
Declare Function SendMessageArray Lib "user32" Alias "SendMessageA" _
	(ByVal hwnd As Long, ByVal wMsg As Long, _
	ByVal wParam As Long, lParam As Any) As Long

Dim aTabs(4) As Long
aTabs(0) = 30
aTabs(1) = 165
aTabs(2) = 210
aTabs(3) = 255

'Clear any existing tabs.
Call SendMessageArray(lstWindows.hwnd, LB_SETTABSTOPS, 0&, 0&)
'Set the tabs.
Call SendMessageArray(lstWindows.hwnd, LB_SETTABSTOPS, 4&, aTabs(0))





'**************************************
'     Get the system time
'**************************************

Declare Function GetCurrentTime& Lib "User" ()



'**************************************
'     Possible sharable VB memory
'**************************************

Declare Function ReadProcessMemory Lib "kernel32" _
	Alias "ReadProcessMemory" _
	(ByVal hProcess As Long, lpBaseAddress As Any, _
	lpBuffer As Any, ByVal nSize As Long, _
	lpNumberOfBytesWritten As Long) As Long
Declare Function WriteProcessMemory Lib "kernel32" _
	Alias "WriteProcessMemory" _
	(ByVal hProcess As Long, lpBaseAddress As Any, _
	lpBuffer As Any, ByVal nSize As Long, _
	lpNumberOfBytesWritten As Long) As Long
Declare Function GetCurrentProcessId Lib "kernel32" _
	Alias "GetCurrentProcessId" () As Long
Declare Function OpenProcess Lib "kernel32" _
	(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
	ByVal dwProcessId As Long) As Long

Public Const SPECIFIC_RIGHTS_ALL =&H0000FFFF 
Public Const STANDARD_RIGHTS_REQUIRED = &H000F0000 
Public Const STANDARD_RIGHTS_ALL = &H001F0000 
    		
Dim a As Long, b as Long
a = 'process id To open
b = OpenProcess((SPECIFIC_RIGHTS_ALL And STANDARD_RIGHTS_ALL), False, a)

Dim c As Long, d As Boolean, e As Long, f As Long
d = ReadProcessMemory(a, ByVal b, ByVal VarPtr(c), 4, e)
d = WriteProcessMemory(a, ByVal b, c, 4, e)




'**************************************
'    Search a ListBox Control Quickly
'**************************************

Const LB_FINDSTRING = &H18F
Private Declare Function SendMessage Lib "User32" _
	Alias "SendMessageA" _
	(ByVal hWnd As Long, ByVal wMsg As Integer, _
	ByVal wParam As Integer, lParam As Any) As Long

Private Sub Form_Load()
 List1.Clear
 List1.AddItem "Apples" : List1.AddItem "Banana"
 List1.AddItem "Bread" : List1.AddItem "Break"
 Text1.Text = ""
End Sub

Private Sub Text1_Change()
 List1.ListIndex = SendMessage(List1.hWnd, LB_FINDSTRING, -1, ByVal Text1.Text)
End Sub




'**************************************
'   HOWTO: Write Data to a File Using WriteFile API
'**************************************

http://support.microsoft.com/support/kb/articles/q165/9/42.asp?FR=0

'**************************************
'   HOWTO: Position a MsgBox Using a Windows Hook Procedure
'**************************************

http://support.microsoft.com/support/kb/articles/q180/9/36.asp?FR=0




'**************************************
'   HOWTO: Minimize All Windows From Visual Basic
'**************************************
Private Declare Sub keybd_event Lib "user32" _
	(ByVal bVk As Byte, ByVal bScan As Byte, _
	ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const KEYEVENTF_KEYUP = &H2
Const VK_LWIN = &H5B

' 77 is the character code for the letter 'M'
Call keybd_event(VK_LWIN, 0, 0, 0)
Call keybd_event(77, 0, 0, 0)
Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)




'**************************************
'   Get error messages directly from the system
'**************************************

http://codeguru.developer.com/vb/articles/1588.shtml
 



'**************************************
'   HOWTO: Use a Satellite DLL for Localization Purposes
'**************************************

http://support.microsoft.com/support/kb/articles/Q188/6/59.ASP




'**************************************
'   An Alternate Method of Preventing Duplicate Instances
'**************************************

http://www.mvps.org/vbnet/code/system/appprevinst.htm





'**************************************
'   How to Determine the Number of Lines in a Textbox
'**************************************

Public Declare Function SendMessage Lib "user32" _
	Alias "SendMessageA" _
	(ByVal hwnd As Long, ByVal wMsg As Long, _ 
	ByVal wParam As Long, lParam As Any) As Long

Public Const EM_GETLINECOUNT = &HBA
Public Const EM_LINEFROMCHAR = &HC9
Public Const EM_LINEINDEX = &HBB
Public Const EM_LINELENGTH = &HC1
Public Const EM_GETSEL = &HB0
Public Const EM_SETSEL = &HB1

Dim cursorPos As Long, lineCount as Long, currentLine as Long
' The number of lines
lineCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0&, ByVal 0&)
' The line containing the cursor
currentLine = SendMessage(Text1.hwnd, EM_LINEFROMCHAR, -1&, ByVal 0&) + 1
On Local Error Resume Next
'get the character position of the cursor
cursorPos = SendMessage(Text1.hwnd, EM_GETSEL, 0&, ByVal 0&)
Text1.SetFocus
'Select To Top
Call SendMessage(Text1.hwnd, EM_SETSEL, 0, ByVal cursorPos)




'**************************************
'   Adding a Vertical Splitter Bar
'**************************************

http://www.mvps.org/vbnet/code/neet/splitterbar.htm




'**************************************
'   Closing all the forms
'**************************************

Dim frm As Form
For Each frm in Forms
   Unload frm 
Next frm 
	 


'**************************************
'   Canceling a X-Button-Click. 
'**************************************

' Place this code in Form1_Unload()
Cancel = True 'Cancel Unloading


 
 
'**************************************
'   Using the clipboard
'**************************************

' Clearing the clipboard
Clipboard.Clear
' Setting clipboard text
Clipboard.SetText Text1.Text
' Getting clipboard text
Text2.Text = Clipboard.GetText




'**************************************
'   HOWTO: Modify the Width of the Drop Down List in a Combo Box
'**************************************

http://support.microsoft.com/support/kb/articles/Q131/8/45.asp