Archive for the ‘Visual Basic’ Category
Disable tombol Close X pada form
Option Explicit
Private Declare Function DeleteMenu Lib “user32″ (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function GetSystemMenu Lib “user32″ (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Const MF_BYPOSITION = &H400&
Private ReadyToClose As Boolean
Private Sub RemoveMenus(frm As Form, remove_restore As Boolean, remove_move As Boolean, remove_size As Boolean, remove_minimize As Boolean, remove_maximize As Boolean, remove_seperator As Boolean,
remove_close As Boolean)
Dim hMenu As Long
‘ Mengambil dari menu handle pada form
hMenu = GetSystemMenu(hwnd, False)
If remove_close Then DeleteMenu hMenu, 6, MF_BYPOSITION
If remove_seperator Then DeleteMenu hMenu, 5, MF_BYPOSITION
If remove_maximize Then DeleteMenu hMenu, 4, MF_BYPOSITION
If remove_minimize Then DeleteMenu hMenu, 3, MF_BYPOSITION
If remove_size Then DeleteMenu hMenu, 2, MF_BYPOSITION
If remove_move Then DeleteMenu hMenu, 1, MF_BYPOSITION
If remove_restore Then DeleteMenu hMenu, 0, MF_BYPOSITION
End Sub
Private Sub cmdClose_Click()
ReadyToClose = True
Unload Me
End Sub
Private Sub Form_Load()
‘ Menghapus sistem close pada menu separator.
RemoveMenus Me, False, False, _
False, False, False, True, True
End Sub
‘ Batalkan jikaReadyToClose dalam modus false.
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = Not ReadyToClose
End Sub
Form “Always on Top”
Deklarasi
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)
Code yang digunakan
‘Code ini akan menampilkan form selalu didepan
rtn = SetWindowPos(OnTop.hwnd, -2, 0, 0, 0, 0, 3)
‘Code ini untuk mengembalikan fungsi diatas
rtn = SetWindowPos(OnTop.hwnd, -1, 0, 0, 0, 0, 3)
Cara Menjalankan : Copy code di bawah pada form code)
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)
Private Sub Form_Load()
this code makes the window stay on top
rtn = SetWindowPos(OnTop.hwnd, -2, 0, 0, 0, 0, 3)
End Sub
Cek kecepatan akses form
‘*******************************************************
‘ Paste This code in the module don’t in form_Load
‘ Change Start object as sub main
‘ For check speed form : run the form for the first time and look how many you get access on speed form.
‘ Step two load picture or large picture in form and then check again how many form speed is u get.
‘*******************************************************
Private Declare Function GetTickCount Lib “kernel32″ () As Long
Sub main()
Dim lSpeedTime As Long
Dim SInfoSpeed As String
lSpeedTime = GetTickCount
Load Form1
Form1.Show
lSpeedTime = GetTickCount – lSpeedTime
‘ this is only simulation
If lSpeedTime <= 50 Then
SInfoSpeed = “[Very Fast]”
ElseIf lSpeedTime >= 50 And lSpeedTime <= 100 Then
SInfoSpeed = “[Normal]”
ElseIf lSpeedTime >= 100 And lSpeedTime <= 200 Then
SInfoSpeed = “[Slow]”
ElseIf lSpeedTime >= 200 Then
SInfoSpeed = “[Very Slow]”
End If
Form1.Caption = “Time Speed Form: ” & lSpeedTime & ” Milliseconds – ” & SInfoSpeed
End Sub









