Fungsi ShellExecute


Fungsi ShellExecute merupakan salah satu fungsi API yang memiliki kegunaan yang beragam, mulai dari menjalankan file sampai dengan membuka alamat website.

Di bagian '(Declarations)' dari Form ketikkan :
[ VB 6.0 ]
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
[ VB .NET ]
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Integer, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Integer) As Integer



Berikut macam-macam penggunaanya : (khusus untuk VB .NET, gantikan kode yang berwarna merah dengan kode "Me.Handle.ToInt32")

1). Membuka folder atau file.
ShellExecute Me.hwnd, "", "ALAMAT LOKASI FOLDER / FILE", "", "", vbNormalFocus

2). Menemukan folder / file dalam Windows Explorer.
ShellExecute Me.hwnd, "", "explorer.exe", "/select, ALAMAT LOKASI FOLDER / FILE", "", vbMaximizedFocus

3). Mencetak file.
ShellExecute Me.hwnd, "Print", "ALAMAT LOKASI FILE", "", "", vbNormalFocus

4). Membuka jendela pencarian / search berdasarkan folder.
ShellExecute Me.hwnd, "Find", "ALAMAT LOKASI FOLDER", "", "", vbNormalFocus

5). Membuka alamat website.
ShellExecute Me.hwnd, "", "ALAMAT WEBSITE", "", "", vbMaximizedFocus

6). Membuka aplikasi e-mail.
ShellExecute Me.hwnd, "", "mailto:ALAMAT E-MAIL", "", "", vbMaximizedFocus

0 komentar:

Label Blink


Buat Form baru dengan sebuah Label dan sebuah Timer (Enabled=True; Interval=100).

Di bagian kontrol Timer-nya ketikkan :
Label1.Visible = Not Label1.Visible

Atau anda bisa ketikkan :
[ VB 6.0 ]
Randomize
Label1.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
[ VB .NET ]
Randomize()
Label1.ForeColor = ColorTranslator.FromOle(RGB(Rnd() * 255, Rnd() * 255, Rnd() * 255))

0 komentar:

Form Berwarna Gradien


Kode berikut ini akan mengubah latar Form menjadi kombinasi warna secara gradien.

[ VB 6.0 ]
Buat sebuah Module baru dan ketikkan :
Enum GradMode
gmHorizontal = 0
gmVertical = 1
End Enum

Public Function GradientForm(ByVal Frm As Form, ByVal StartColor As Long, ByVal Endcolor As Long, ByVal Mode As GradMode)
Dim Rs As Integer, Gs As Integer, Bs As Integer
Dim Re As Integer, Ge As Integer, Be As Integer
Dim Rk As Single, Gk As Single, Bk As Single
Dim R As Integer, G As Integer, B As Integer
Dim i As Integer, j As Single

On Error Resume Next
Frm.AutoRedraw = True
Frm.ScaleMode = vbPixels

Rs = StartColor And (Not &HFFFFFF00)
Gs = (StartColor And (Not &HFFFF00FF)) \ &H100&
Bs = (StartColor And (Not &HFF00FFFF)) \ &HFFFF&
Re = Endcolor And (Not &HFFFFFF00)
Ge = (Endcolor And (Not &HFFFF00FF)) \ &H100&
Be = (Endcolor And (Not &HFF00FFFF)) \ &HFFFF&

j = IIf(Mode = gmHorizontal, Frm.ScaleWidth, Frm.ScaleHeight)
Rk = (Rs - Re) / j: Gk = (Gs - Ge) / j: Bk = (Bs - Be) / j

For i = 0 To j
R = Rs - i * Rk: G = Gs - i * Gk: B = Bs - i * Bk
If Mode = gmHorizontal Then
Frm.Line (i, 0)-(i - 1, Frm.ScaleHeight), RGB(R, G, B), B
Else
Frm.Line (0, i)-(Frm.ScaleWidth, i - 1), RGB(R, G, B), B
End If
Next
End Function

Untuk menggunakannya ketikkan kode berikut di bagian 'Form_Resize' dari Form.
GradientForm Me, vbRed, vbBlue, 0



[ VB .NET ]
Buat sebuah Module baru dan ketikkan :
Public Sub GradientForm(ByVal Frm As Form, ByVal StartColor As Color, ByVal EndColor As Color, ByVal Mode As System.Drawing.Drawing2D.LinearGradientMode)
Dim a As New System.Drawing.Drawing2D.LinearGradientBrush(New RectangleF(0, 0, Frm.Width, Frm.Height), StartColor, EndColor, Mode)
Dim g As Graphics = Frm.CreateGraphics
g.FillRectangle(a, New RectangleF(0, 0, Frm.Width, Frm.Height))
g.Dispose()
End Sub

Untuk menggunakannya tambahkan kode berikut di Form :
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
GradientForm(Me, Color.Red, Color.Blue, 0)
End Sub

Dan di bagian 'Form_Resize'-nya ketikkan :
GradientForm(Me, Color.Red, Color.Blue, 0)

0 komentar:

Form Bentuk Oval


Tidak selamanya Form harus berbentuk kotak, dengan sedikit penambahan kode, bentuk Form dapat diubah menjadi bentuk shape.

[ VB 6.0 ]
Buat sebuah Form baru (properti BorderStyle=None), lalu di bagian '(Declarations)' dari Form ketikkan :
Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long

Untuk membuat Form berbentuk shape rounded rectangle, di bagian 'Form_Load' ketikkan :
Dim l As Long
l = CreateRoundRectRgn(0, 0, Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY, 20, 20)
SetWindowRgn Me.hwnd, l, 0

Sedangkan untuk membuat Form berbentuk shape oval / lingkaran, di bagian 'Form_Load' ketikkan :
Dim l As Long
l = CreateEllipticRgn(0, 0, Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY)
SetWindowRgn Me.hwnd, l, 0




[ VB .NET ]
Buat sebuah Form baru (properti FormBorderStyle=None), lalu di bagian '(Declarations)' dari Form ketikkan :
Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Integer, ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer, ByVal X3 As Integer, ByVal Y3 As Integer) As Integer
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Integer, ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer) As Integer
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Integer, ByVal hRgn As Integer, ByVal bRedraw As Boolean) As Integer

Untuk membuat Form berbentuk shape rounded rectangle, di 'Form1_Load' ketikkan :
Dim i As Integer
i = CreateRoundRectRgn(0, 0, Me.Width, Me.Height, 20, 20)
SetWindowRgn(Me.Handle, i, 0)

Sedangkan untuk membuat Form berbentuk shape oval / lingkaran, di bagian 'Form1_Load' ketikkan :
Dim i As Integer
i = CreateEllipticRgn(0, 0, Me.Width, Me.Height)
SetWindowRgn(Me.Handle, i, 0)




Untuk menggerakkan Form tersebut, caranya ada disini.

0 komentar:

Form Login


Form Login biasanya dibuat untuk memberikan keterbatasan akses terhadap aplikasi, sehingga keamanan data yang diakses aplikasi terjaga dengan baik.
Download source code-nya disini

0 komentar:

Mengubah Teks ke Suara


Kode berikut ini akan menunjukkan bagaimana suatu teks diubah menjadi suara.
Dim s
Set s = CreateObject("sapi.spvoice")
s.Speak Text1.Text

0 komentar:

Menggerakkan Form Tanpa Border

Berikut cara untuk menggerakkan Form yang sengaja tanpa / tidak diberi border. [ VB 6.0 ] Di bagian 'Form_MouseMove' ketikkan :
If Me.WindowState <> 0 Then Exit Sub

Static l As Integer, t As Integer
If Button = 1 Then
Me.Left = (Me.Left + X) - l
Me.Top = (Me.Top + Y) - t
Else
l = X
t = Y
End If


[ VB .NET ]
Di bagian 'Form1_MouseMove' ketikkan :
If Me.WindowState <> FormWindowState.Normal Then Exit Sub

Static p As Point
If e.Button = Windows.Forms.MouseButtons.Left Then
Me.Left = (Me.Left + e.X) - p.X
Me.Top = (Me.Top + e.Y) - p.Y
Else
p = e.Location
End If

1 komentar:

Form Transparan


Kode berikut ini akan membuat Form menjadi transparan atau tembus pandang.

Buat sebuah Module baru lalu ketikkan :
Option Explicit

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long


Public Sub FadeForm(ByVal Frm As Form, ByVal Level As Byte)
On Error Resume Next
Dim msg As Long

msg = GetWindowLong(Frm.hwnd, -20) Or &H80000
SetWindowLong Frm.hwnd, -20, msg
SetLayeredWindowAttributes Frm.hwnd, 0, Level, &H2
End Sub

Selanjutnya di bagian Form yang akan dijadikan transparan, di 'Form_Load' ketikkan :
FadeForm Me, 125

Tingkat transparasi dapat dirubah dengan mengganti nilai properti Level-nya (0-255).

0 komentar:

Form About ala Windows


Kode berikut ini akan memunculkan Form About sama seperti aplikasi bawaan Windows ex: Notepad. Sehingga aplikasi Anda seakan-akan merupakan aplikasi buatan Windows.

[ VB 6.0 ]
Pada bagian '(Declarations)' dari Form ketikkan :

Private Declare Function ShellAbout Lib "shell32.dll" Alias "ShellAboutA" (ByVal hWnd As Long, ByVal szApp As String, ByVal szOtherStuff As String, ByVal hIcon As Long) As Long
Untuk memanggilnya ketikkan :
ShellAbout Me.hWnd, "Nama Aplikasi", "Deskripsi", Me.Icon


[ VB .NET ]
Pada bagian '(Declarations)' dari Form ketikkan :
Private Declare Function ShellAbout Lib "shell32.dll" Alias "ShellAboutA" (ByVal hWnd As Integer, ByVal szApp As String, ByVal szOtherStuff As String, ByVal hIcon As Integer) As Integer
Untuk memanggilnya ketikkan :
ShellAbout(Me.Handle.ToInt32, "Nama Aplikasi", "Deskripsi", Me.Icon.Handle.ToInt32)

0 komentar:

Cool B themes Slider