#1: How to Flip Windows
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")
#2: Open / Close CD ROM Drive
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
Then to Open the CD Door:
Code:
Public Sub OpenCDDoor()
Dim retval As Long
retval = mciSendString("set CDAudio door open", "", 0, 0)
End Sub
To Close the CD Door:
Code:
Public Sub CloseCDDoor()
Dim retval As Long
retval = mciSendString("set CDAudio door closed", "", 0, 0)
End Sub
#3: Turn Monitor to Off/On/LowState
First import this namespace:
Code:
Imports System.Runtime.InteropServices
Define constants:
Code:
Public WM_SYSCOMMAND As Integer = &H112
Public SC_MONITORPOWER As Integer = &HF170
Then declare a windows api function:
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
To Turn On:
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
To Turn Off:
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
Put it to Lowstate:
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
#4: Set Desktop Wallpaper
First import this namespace:
Code:
Imports System.Drawing.Imaging
Then declare a windows API:
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
'Constants to be used with the above API:
Code:
Private Const SPI_SETDESKWALLPAPER = 20
Private Const SPIF_UPDATEINIFILE = &H1
'Create a new picture box:
Code:
Dim pic As New PictureBox
Finally call the following code to change the wallpaper:
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)
#5: Toggle NumLock/CapsLock/ScrollLock
'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
API Function:
Code:
Private Declare Sub keybd_event Lib "user32" ( _
ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Integer, _
ByVal dwExtraInfo As Integer _
)
Now to toggle the Numlock key, use:
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
To toggle the CapsLock key, use:
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
To toggle the ScrollLock key, use:
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
Note: You can check the state of the NumLock/CapsLock/ScrollLock before toggling them:
Code:
'This will turn on NumLock if it is turned off.
If Not My.Computer.Keyboard.NumLock Then
NumLock()
End If
I will keep posting new tutorials from time to time.
Thanks and Regards,
Hassan