Atlanta Custom Software Development 

   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» 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

Const SWP_HIDEWINDOW = &H80
Const SWP_SHOWWINDOW = &H40

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
  Else
    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
  Else
    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
  Else
    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


Audit, Notify, Deploy and Manage SSIS
Download the Free 30-day Trial Version...Learn More About This Product...

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 VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, 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   |  Blogs

© 2008 BinaryWorld LLC. All rights reserved.