Archive for January, 2008

Merubah Speed dari Windows Start Menu

Saturday, January 19th, 2008

Untuk melakukannya kita membuat string baru pada windows registry dengan nama MenuShowDelay dengan nilai antara 1 s/d 1000, pada lokasi HKEY_CURRENT_USER\Control Panel\Desktop

Pada module ketikan kode berikut ini: Public Const EWX_REBOOT = 2
Public Const EWX_FORCE = 4
Declare Function ExitWindowsEx Lib “user32″ (ByVal _
uFlags As Long, ByVal dwReserved As Long) As Long
Declare Function RegCreateKey Lib “advapi32.dll” Alias _
“RegCreateKeyA” (ByVal Hkey As Long, ByVal lpSubKey As _
String, phkResult As Long) As Long

Declare Function RegCloseKey Lib “advapi32.dll” (ByVal _
Hkey As Long) As Long

Declare Function RegQueryValueEx Lib “advapi32.dll” Alias _
“RegQueryValueExA” (ByVal Hkey As Long, ByVal lpValueName _
As String, ByVal lpReserved As Long, lpType As Long, _
lpData As Any, lpcbData As Long) As Long

Declare Function RegSetValueEx Lib “advapi32.dll” Alias _
“RegSetValueExA” (ByVal Hkey As Long, ByVal lpValueName _
As String, ByVal Reserved As Long, ByVal dwType As Long, _
lpData As Any, ByVal cbData As Long) As Long

Public Const REG_SZ = 1
Public Const REG_DWORD = 4 Public Sub savestring(Hkey As Long, strPath As String, _
strValue As String, strdata As String)
Dim keyhand
Dim r
r = RegCreateKey(Hkey, strPath, keyhand)
r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal _
strdata, Len(strdata))
r = RegCloseKey(keyhand)
End Sub

Taruh 2 command buttons dan masukan kode berikut ini: Private Sub Command1_Click()
On Error GoTo error
a% = InputBox(”Enter a number between 1 and 1000″, _
“Start Menu Speed”)
‘a is the integer value of the input in the inputbox ‘checking the input If a% > 0 And a% < 1001 Then
‘input is a valid number between 1 and 1000
‘and a (integer) is to be converted in b (string)
b$ = CStr(a%) ‘creating MenuShowDelay with it´s value
‘(if allready exists it just changes the value)
Call savestring(HKEY_CURRENT_USER, _
“Control Panel\Desktop”, “MenuShowDelay”, b$)
‘resetting computer
MsgBox “Reset your Computer”, , “Changes are made”
t& = ExitWindowsEx(EWX_FORCE Or EWX_REBOOT, 0)
Else
‘value is a number but not valid
MsgBox “Not a valid number between 1 and 1000″
End If
Exit Sub
error:
‘error, input was not a valid number
MsgBox “Invalid Data Input”
End Sub
Private Sub Command2_Click()
Unload Me
End Sub

Mengaktifkan Screen Saver Menggunakan API

Saturday, January 19th, 2008

Contoh dibawah ini adalah untuk mengaktifkan screen saver dari Visual Basic screen saver dengan mengirim Windows message kepada Control-menu box form. Microsoft Windows mengaktifkan screen savers melalui System-menu box form. System-menu box ini juga dikenal sebagai Control-menu box dalam Visual Basic. Kita dapat mengirim Windows messages kepada Control-menu box dengan menggunakan SendMessage Windows API (application programming interface) function. Declarations #If Win32 Then

Private Declare Function SendMessage Lib “user32″ _
Alias “SendMessageA” (ByVal hWnd As Long, ByVal wMsg _
As Long, ByVal wParam As Long, ByVal lParam As Long) _
As Long

Const WM_SYSCOMMAND = &H112&
Const SC_SCREENSAVE = &HF140&

#Else

Private Declare Function SendMessage Lib “User” _
(ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal _
wParam As Integer, lParam As Any) As Long

Const WM_SYSCOMMAND = &H112
Const SC_SCREENSAVE = &HF140&

#End If Code

Untuk mengaktifkan screen saver, gunakan baris perintah sebagai berikut:

Dim result As Long
result = SendMessage(Form1.hWnd, WM_SYSCOMMAND, SC_SCREENSAVE, 0&)

Register & Unregister ActiveX Controls

Saturday, January 19th, 2008

Ada dua fungsi untuk meregister & unregister ActiveX Control yaitu DLLRegisterServer dan DLLUnregisterServer. Contoh program dibawah ini adalah untuk meregister dan unregister Microsoft Common Controls OCX, ComCtl32.OCX. Declarations Declare Function RegComCtl32 Lib “ComCtl32.OCX” _
Alias “DllRegisterServer” () As Long
Declare Function UnRegComCtl32 Lib “ComCtl32.OCX” _
Alias “DllUnregisterServer” () As Long
Const ERROR_SUCCESS = &H0 Code

Untuk register Microsoft Common Controls OCX:

If RegComCtl32 = ERROR_SUCCESS Then
MsgBox “Registration Successful”
Else
MsgBox “Registration Unsuccessful”
End If

If UnRegComCtl32 = ERROR_SUCCESS Then
MsgBox “UnRegistration Successful”
Else
MsgBox “UnRegistration Unsuccessful”
End If

Mengetahui Warna Title Bar

Saturday, January 19th, 2008

Gunakan fungsi API GetSysColor dengan parameternya. Declare Function GetSysColor Lib “user32″ Alias _
“GetSysColor” (ByVal nIndex As Long) As Long

Fungsi ini akan menghasilkan RGB value dari object.Misalnya jika anda ingin mengetahui warna dari form yang aktif. Gunakan kode berikut ini:

col& = GetSysColor(COLOR_ACTIVECAPTION)

Merubah Warna Title Bar

Saturday, January 19th, 2008

Declarasi fungsi API : Declare Function SetSysColors Lib “user32″ Alias _
“SetSysColors” (ByVal nChanges As Long, lpSysColor As _
Long, lpColorValues As Long) As Long

Constants : Public Const COLOR_SCROLLBAR = 0 ‘The Scrollbar colour
Public Const COLOR_BACKGROUND = 1 ‘Colour of the background with no wallpaper
Public Const COLOR_ACTIVECAPTION = 2 ‘Caption of Active Window
Public Const COLOR_INACTIVECAPTION = 3 ‘Caption of Inactive window
Public Const COLOR_MENU = 4 ‘Menu
Public Const COLOR_WINDOW = 5 ‘Windows background
Public Const COLOR_WINDOWFRAME = 6 ‘Window frame
Public Const COLOR_MENUTEXT = 7 ‘Window Text
Public Const COLOR_WINDOWTEXT = 8 ‘3D dark shadow (Win95)
Public Const COLOR_CAPTIONTEXT = 9 ‘Text in window caption
Public Const COLOR_ACTIVEBORDER = 10 ‘Border of active window
Public Const COLOR_INACTIVEBORDER = 11 ‘Border of inactive window
Public Const COLOR_APPWORKSPACE = 12 ‘Background of MDI desktop
Public Const COLOR_HIGHLIGHT = 13 ‘Selected item background
Public Const COLOR_HIGHLIGHTTEXT = 14 ‘Selected menu item
Public Const COLOR_BTNFACE = 15 ‘Button
Public Const COLOR_BTNSHADOW = 16 ‘3D shading of button
Public Const COLOR_GRAYTEXT = 17 ‘Grey text, of zero if dithering is used.
Public Const COLOR_BTNTEXT = 18 ‘Button text
Public Const COLOR_INACTIVECAPTIONTEXT = 19 ‘Text of inactive window
Public Const COLOR_BTNHIGHLIGHT = 20 ‘3D highlight of button

Untuk merubah warna title bar, caption anda dapat memanggil fungsi ini sebagai berikut:

t& = SetSysColors(1, COLOR_ACTIVECAPTION, RGB(255,0,0))

Pada contoh ini akan merubah aktif caption menjadi merah.