Tujuan pada bagian ke-6
Menambahkan fasilitas Popup Windows
Langkah-langkah
Tambahkan satu modul, selanjutnya gantilah namanya menjadi modForeGround.
Gantilah kode di bawah menjadi:
If s <> strFromClipboard ThenKode diatas terdapat pada:
ParsingText s, List1
strFromClipboard = s
Text1.Text = strFromClipboard
pSetForegroundWindow hwnd 'ini untuk memanggil aplikasi agar dapat tampil paling depan
End If
Private Sub Timer1_Timer()Seperti yang telah dijelaskan pada bagian ke-3.
Kode-kode
Option ExplicitUji Coba
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function AttachThreadInput Lib "user32" ByVal idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long) As Long
Declare Function GetForegroundWindow Lib "user32" ) As Long
Declare Function GetWindowThreadProcessId Lib "user32" ByVal hwnd As Long, lpdwProcessId As Long) As Long
Declare Function IsIconic Lib "user32" ByVal hwnd As Long) As Long
Declare Function SetForegroundWindow Lib "user32" ByVal hwnd As Long) As Long
Declare Function ShowWindow Lib "user32" ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function BringWindowToTop Lib "user32" ByVal hwnd As Long) As Long
Public Const SW_SHOW = 5
Public Const SW_RESTORE = 9
Public Const GW_OWNER = 4
Public Const GWL_HWNDPARENT = -8)
Public Const GWL_EXSTYLE = -20)
Public Const WS_EX_TOOLWINDOW = &H80
Public Const WS_EX_APPWINDOW = &H40000
Public Sub pSetForegroundWindow(ByVal hwnd As Long)
Dim lForeThreadID As Long
Dim lThisThreadID As Long
Dim lReturn As Long
If hwnd <> GetForegroundWindow() Then
If IsIconic(hwnd) Then
Call ShowWindow(hwnd, SW_RESTORE)
Else
Call ShowWindow(hwnd, SW_SHOW)
End If
lForeThreadID = GetWindowThreadProcessId(GetForegroundWindow, ByVal 0&)
lThisThreadID = GetWindowThreadProcessId(hwnd, ByVal 0&)
If lForeThreadID <> lThisThreadID Then
Call AttachThreadInput(lForeThreadID, lThisThreadID, True)
lReturn = SetForegroundWindow(hwnd)
BringWindowToTop hwnd
Call AttachThreadInput(lForeThreadID, lThisThreadID, False)
Else
lReturn = SetForegroundWindow(hwnd)
BringWindowToTop hwnd
End If
End If
End Sub
- Compile terlebih dahulu projectnya
- Jalankan aplikasi melalui Windows Explorer
- Copy sembarang text, dari MSWord, Browser, dsb.
- Jika prosedurnya benar, maka aplikasi tersebut akan tampil paling depan.