[Leeched] Visual Basic Tutorials
#1: How to Flip Windows
Works on Windows Vista And Windows 7, and if Aero is on.
'This will Flip all the windows
#2: Open / Close CD ROM Drive
Start by declaring a function. This function is a call from OS.
Then to Open the CD Door:
To Close the CD Door:
#3: Turn Monitor to Off/On/LowState
First import this namespace:
Define constants:
Then declare a windows api function:
To Turn On:
To Turn Off:
Put it to Lowstate:
#4: Set Desktop Wallpaper
First import this namespace:
Then declare a windows API:
'Constants to be used with the above API:
'Create a new picture box:
Finally call the following code to change the wallpaper:
#5: Toggle NumLock/CapsLock/ScrollLock
'Constants to be used:
API Function:
Now to toggle the Numlock key, use:
To toggle the CapsLock key, use:
To toggle the ScrollLock key, use:
Note: You can check the state of the NumLock/CapsLock/ScrollLock before toggling them:
I will keep posting new tutorials from time to time.
Thanks and Regards,
Hassan
Works on Windows Vista And Windows 7, and if Aero is on.
'This will Flip all the windows
Code:
Shell("C:\Windows\System32\rundll32.exe DwmApi #105")
Start by declaring a function. This function is a call from OS.
Code:
Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _ (ByVal lpCommandString As String, ByVal lpReturnString As String, _ ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Code:
Public Sub OpenCDDoor()
Dim retval As Long
retval = mciSendString("set CDAudio door open", "", 0, 0)
End Sub
Code:
Public Sub CloseCDDoor()
Dim retval As Long
retval = mciSendString("set CDAudio door closed", "", 0, 0)
End Sub
First import this namespace:
Code:
Imports System.Runtime.InteropServices
Code:
Public WM_SYSCOMMAND As Integer = &H112 Public SC_MONITORPOWER As Integer = &HF170
Code:
<DllImport("user32.dll")> _
Private Shared Function SendMessage(ByVal hWnd As Integer, ByVal hMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function
Code:
Public Sub TurnOn() Dim x As Int32 'Main is the main form of the application. You can change it to any form of the application. x = Main.Handle SendMessage(x, WM_SYSCOMMAND, SC_MONITORPOWER, -1) End Sub
Code:
Public Sub TurnOff() Dim x As Int32 'Main is the main form of the application. You can change it to any form of the application. x = Main.Handle SendMessage(x, WM_SYSCOMMAND, SC_MONITORPOWER, 2) End Sub
Code:
Public Sub LowState() Dim x As Int32 'Main is the main form of the application. You can change it to any form of the application. x = Main.Handle SendMessage(x, WM_SYSCOMMAND, SC_MONITORPOWER, 1) End Sub
First import this namespace:
Code:
Imports System.Drawing.Imaging
Code:
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As String, ByVal fuWinIni As Integer) As Integer
Code:
Private Const SPI_SETDESKWALLPAPER = 20 Private Const SPIF_UPDATEINIFILE = &H1
Code:
Dim pic As New PictureBox
Code:
Dim ImageToSet As String="Full location of the image" Dim imagePath1 As String = Application.StartupPath & "\wall.bmp" pic.Image = Image.FromFile(ImageToSet) pic.Image.Save(imagePath1, ImageFormat.Bmp) 'Set the parameters to change the wallpaper to the image you selected: SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath1, SPIF_UPDATEINIFILE) My.Computer.FileSystem.DeleteFile(imagePath1)
'Constants to be used:
Code:
Private Const VK_NUMLOCK As Integer = &H90 Private Const VK_SCROLL As Integer = &H91 Private Const VK_CAPITAL As Integer = &H14 Private Const KEYEVENTF_EXTENDEDKEY As Integer = &H1 Private Const KEYEVENTF_KEYUP As Integer = &H2
Code:
Private Declare Sub keybd_event Lib "user32" ( _ ByVal bVk As Byte, _ ByVal bScan As Byte, _ ByVal dwFlags As Integer, _ ByVal dwExtraInfo As Integer _ )
Code:
Public Sub NumLock() keybd_event(VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0) ' Release the key keybd_event(VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0) End Sub
Code:
Public Sub CapsLock() keybd_event(VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0) ' Release the key keybd_event(VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0) End Sub
Code:
Public Sub ScrollLock() keybd_event(VK_SCROLL, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0) ' Release the key keybd_event(VK_SCROLL, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0) End Sub
Code:
'This will turn on NumLock if it is turned off. If Not My.Computer.Keyboard.NumLock Then NumLock() End If
Thanks and Regards,
Hassan


