hn4u @ Last updated 21/11/04 22:42
Go to my homepage at http://4u.jcisio.com
Full version available at http://4u.jcisio.com/r/article379.htm

Không rõ

Vô hiệu DeskTop

Hôm nay chúng tôi tiếp tục giới thiệu với các bạn một ví dụ về cách sử dụng hàm API trong VB.Bạn có muốn làm cho Desktop bị ''tê liệt'' không? Bạn hoàn toàn có thể vì Desktop cũng là một cửa sổ như bao chương trình khác, điều bạn cần biết là class name của nó ''Progman''.

Bạn thêm vào một Module :

Option Explicit

DefLng A-Z

Declare Function FindWindowEx Lib ''user32'' _

Alias ''FindWindowExA'' (ByVal hWnd As Long, _

ByVal hWndChild As Long, ByVal lpszClassName As String, _

ByVal lpszWindow As String) As Long

Declare Function ShowWindow Lib ''user32'' _

(ByVal hWnd As Long, ByVal nCmdShow As Long) As Long

Public Const SW_HIDE = 0

Public Const SW_SHOW = 5

Public Const g_cstrShellViewWnd As String = ''Progman''

Sau đó thêm vào Project hai button và đoạn code sau:

Option Explicit

DefLng A-Z

Private Function FindShellWindow() As Long

'Hàm dùng để lấy Handle của Desktop

Dim hWnd As Long

On Error Resume Next

hWnd = FindWindowEx(0&, 0&, g_cstrShellViewWnd, vbNullString)

If hWnd <> 0 Then

FindShellWindow = hWnd

End If

End Function

Private Sub HideShowWindow(ByVal hWnd As Long, Optional ByVal Hide As Boolean = False)

Dim lngShowCmd As Long

On Error Resume Next

If Hide = True Then

lngShowCmd = SW_HIDE

Else

lngShowCmd = SW_SHOW

End If

Call ShowWindow(hWnd, lngShowCmd)

End Sub

Private Sub command2_Click()

Dim hWnd As Long

On Error Resume Next

hWnd = FindShellWindow()

If hWnd <> 0 Then

Call HideShowWindow(hWnd)

End If

End Sub

Private Sub command1_Click()

Dim hWnd As Long

On Error Resume Next

hWnd = FindShellWindow()

If hWnd <> 0 Then

Call HideShowWindow(hWnd, True)

End If

End Sub

Private Sub Form_Load()

Command1.Caption = ''Hide Desktop''

Command2.Caption = ''Show Desktop''

End Sub


hainam4u @ Last updated 21/11/04 22:42
Go to my homepage at http://4u.jcisio.com