Important alert: (current site time 7/16/2013 2:07:36 AM EDT)
 

VB icon

* Ultimate Window Handler! *

Email
Submitted on: 4/24/1999
By: Matt Evans 
Level: Not Given
User Rating: By 11 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 83876
 
     This is the ultimate window handler. This can *Hide a window* *Show a window* *Minimize Window* *Maximize Window* *Close Window*
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :* Ultimate Window Handler! *
'**************************************
Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
Public Const WM_CLOSE = &H10
Public Const SW_HIDE = 0
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: * Ultimate Window Handler! *
' Description:This is the ultimate window handler. This can 
*Hide a window*
*Show a window*
*Minimize Window*
*Maximize Window*
*Close Window*
' By: Matt Evans
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1655&lngWId=1'for details.'**************************************

Sub WindowHandle(win,cas as long)
'by storm
'Case 0 = CloseWindow
'Case 1 = Show Win
'Case 2 = Hide Win
'Case 3 = Max Win
'Case 4 = Min Win
Select Case cas
Case 0:
Dim X%
X% = SendMessage(win, WM_CLOSE, 0, 0)
Case 1:
X = ShowWindow(win, SW_SHOW)
Case 2:
X = ShowWindow(win, SW_HIDE)
Case 3:
X = ShowWindow(win, SW_MAXIMIZE)
Case 4:
X = ShowWindow(win, SW_MINIMIZE)
End Select
'any questions e-mail me at storm@n2.com
End Sub


Other 11 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

6/12/1999 6:03:00 PMDavidG

The ShowWindow declaration was missing from the API info. Load it using the API viewer, or nab this, and you'll be set:

Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

(If this comment was disrespectful, please report it.)

 
6/17/1999 2:33:00 AMsome one

How do I hide a program that make itself
as a toolbar on the desktop and
narrows the desktop area ?
(It does not have any visible caption)

T H A N K S ! ! !

Some One

some--one@geocities.com

(If this comment was disrespectful, please report it.)

 
7/6/1999 7:21:00 PMMark

This doesn't work under win31 as there is no user32.dll file. Does anyone know where equivalent functions may be found within win31 dlls?
(If this comment was disrespectful, please report it.)

 
7/12/1999 10:46:00 PMSean

Hmmm.... you need a handle to each window... at first I thought you could just use the caption title... but what I need to know is how to get a list or something of all the handles currently availible... For example, an open Internet explorer window. It might be difficult to assume that a window of IE would be open on a user's computer, so is there a way to grab a list of availible window handles so that conceivably I could make every open window HIDDEN??? Anyone got any ideas for this?

(If this comment was disrespectful, please report it.)

 
12/12/1999 2:28:06 AMNajmul Hussain

Hi,
the caption of my MDI window keeps changing during the course of the application.
Does this code take care of that ???

(If this comment was disrespectful, please report it.)

 
12/12/1999 5:13:17 AMGilb

Sean, I seem to remember a little undocumented function of the Win32 API, I don't know if it would be the same for Win3.x but the function was EnumWindows or something like that... Have a little investigate, if you can't find anything then if you need it for Win95, then I have a little program which uses this function, then sorts all the windows according to hierarchy with their window title, hDC and hWnd (I think, if I remember correctly), and I was going to add a popup menu on each item which would allow you to manipulate the window in a variety of ways.
(If this comment was disrespectful, please report it.)

 
12/14/1999 1:57:15 PMKonstantin Tretyakov

Check out my MiniWinHacker App on Planet-Source Code for normal control of the windows in your system (e.g. EnumWindows). Thanx.
(If this comment was disrespectful, please report it.)

 
2/22/2000 6:38:45 PMDade

Man i hate sayin this,
yea i know back in the day win3.x was tops, maybe its secure, but gee you guys still programming on it?
LoL
*sigh*
:o)Later,
Dade
(If this comment was disrespectful, please report it.)

 
7/6/2000 3:15:31 PMShon

I have found that closing a window with the Sendmessage API does not work on an Internet Explorer window. Can anyone tell me why?
(If this comment was disrespectful, please report it.)

 
7/28/2000 5:06:28 AMErmanno

I found this code very useful, but it is much more useful if you add the following line to the api declaration: Public Const SW_NORMAL = 1 !!!!This allow to
(If this comment was disrespectful, please report it.)

 
8/27/2000 11:10:11 AMOTSER

This doesn't work with Internet Explorer windows because it's actually the WRONG API call -- you should be using PostMessage rather than SendMessage. Here's the declaration for your convenience:

Declare Function PostMessage Lib
(If this comment was disrespectful, please report it.)

 
8/18/2001 5:39:38 PMTry This

http://www.planet-source-code.com/xq/ASP/txtCodeId.10923/lngWId.1/qx/vb/scripts/ShowCode .htm
(If this comment was disrespectful, please report it.)

 
4/3/2002 2:48:05 PMJames Dougherty

Why would a basic API call be copyrighted? hmmm anyway... -James-

(If this comment was disrespectful, please report it.)

 
5/19/2002 8:17:35 PMMawan

Where is the example? I do not know how to close all windows using this program. I think we must collect all window names, handles, or something like that.
(If this comment was disrespectful, please report it.)

 
4/4/2003 3:59:11 AM

you are a brilliant programmer! Thanx 4 the code. Can you make a 'Task Manage' in VB6-listing all running applications/processes and closing some?
(If this comment was disrespectful, please report it.)

 
11/2/2003 1:55:13 AM

hi,
CAN SOMEBODY HELP ME
i want to close another application which is an exe after some checking for which i had already worked for.Now the problem is for closing that window only
a prompt reply will be appreciated
(If this comment was disrespectful, please report it.)

 
2/20/2005 4:12:42 PMMattias Frisk

fasd
(If this comment was disrespectful, please report it.)

 
10/31/2005 12:35:50 AMBalaji software developer

this code good only for learn how can handle of window , ONLY!!!
(If this comment was disrespectful, please report it.)

 
4/8/2006 7:29:55 PMstonie

lol hey nj homie email me.
(If this comment was disrespectful, please report it.)

 
9/14/2006 11:18:56 PMMatthew

doesnt work , 1 globe
(If this comment was disrespectful, please report it.)

 
12/19/2007 9:55:45 AMDellen

This Very Nice For Combine With My Program
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.