| 
							 
 
						 | 
						
							
								
									
										 | 
									 
									
										 | 
									 
									
										
											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 |   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     Else     ShowWindow hWnd, 0     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     Else     SetWindowPos hWnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW     End If End Sub Sub DeskIcon(show As Boolean)   Dim hWnd As Long      hWnd = FindWindowEx(0&, 0&, "Progman", vbNullString)   If show = False Then     ShowWindow hWnd, 5     Else     ShowWindow hWnd, 0     End If End Sub
 
  Private Sub Check1_Click()   StartButton Check1.Value End Sub
 
  Private Sub Check2_Click()   TaskBar Check2.Value End Sub
 
  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 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 ) | 
	 
 
						 | 
						
						 |