Atlanta Custom Software Development 

   Search        Code/Page

User Login



Forgot the Password?
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
» Regular Expr Tester
» Free Tools

This sample code will show you how to use FindWindow api to get handle to various window by window title. If you have window handle then you can use APIs like ShowWindow, SetWindowPos and many more to perform various operations (e.g. hide/show, resize etc.) to that window.

Step-By-Step Example

- Create a standard exe project
- Add three commandbuttons on the form1
- Add the following code in form1

Click here to copy the following block
'API declaration
Private Declare Function ShowWindow Lib "user32" ( _
    ByVal hWnd As Long, _
    ByVal nCmdShow As Long) As Long

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    ByVal hWnd1 As Long, _
    ByVal hWnd2 As Long, _
    ByVal lpsz1 As String, _
    ByVal lpsz2 As String) As Long

Private 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) As Long


Sub StartButton(show As Boolean)
  Dim hWndTray As Long
  Dim hWnd As Long

  hWndTray = FindWindow("Shell_TrayWnd", "")
  hWnd = FindWindowEx(hWndTray, 0, "Button", vbNullString)
  If show = False Then
    ShowWindow hWnd, 5  'show start button
    ShowWindow hWnd, 0  'hide start button
  End If
End Sub

Sub TaskBar(show As Boolean)
  Dim hWnd As Long
  hWnd = FindWindow("Shell_traywnd", "")
  If show = False Then
    SetWindowPos hWnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW  'show taskbar
    SetWindowPos hWnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW  'hide taskbar
  End If
End Sub
Sub DeskIcon(show As Boolean)
  Dim hWnd As Long
  '//First get the handle to desktop (window name is "Progman")
  hWnd = FindWindowEx(0&, 0&, "Progman", vbNullString)
  If show = False Then
    ShowWindow hWnd, 5  'show desktop icon
    ShowWindow hWnd, 0  'hide desktop icon
  End If
End Sub

'//Show/hide StartButton
Private Sub Check1_Click()
  StartButton Check1.Value
End Sub

'//Show/hide Taskbar
Private Sub Check2_Click()
  TaskBar Check2.Value
End Sub

'//Show/hide Desktop Icons
Private Sub Check3_Click()
  DeskIcon Check3.Value
End Sub

Private Sub Form_Load()
  Check1.Caption = "Hide/Show Start Menu"
  Check2.Caption = "Hide/Show Taskbar"
  Check3.Caption = "Hide/Show Desktop Icons"
End Sub

Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with, SQL Server and other MS technologies. He is, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )

Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.