|
-
Mar 12th, 2001, 01:43 AM
#1
Thread Starter
Lively Member
Any body have any idea how to Maximize all windows in windows using VB
Thanks
-
Mar 12th, 2001, 03:39 PM
#2
Hyperactive Member
Let's asume that you have a form named Form1,
which has a listbox named lstEnumRef.
The following code goes into a public module:
Code:
Public Const SW_MAXIMIZE = 3
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, lParam As Any) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
Public Sub MaximizeAll()
enumwin
Dim wintel As Long, mywh As Long
For wintel = 0 To (Form1.lstEnumRef.ListCount - 1)
Call ShowWindow(Form1.lstEnumRef.ItemData(wintel), SW_MAXIMIZE)
Next wintel
End Sub
Public Sub enumwin()
Dim f As Long, c As Long
Form1.lstEnumRef.Clear
f = EnumWindows(AddressOf EnumWndProc, c)
End Sub
Public Function EnumWndProc(ByVal hwnd As Long, lParam As Long) As Long
lParam = lParam + 1 ' Increment count
Dim s As String
s = WindowTextFromWnd(hwnd) ' Get window title And insert into ListBox
If s <> "" Then
Form1.lstEnumRef.AddItem s
Form1.lstEnumRef.ItemData(Form1.lstEnumRef.NewIndex) = hwnd
End If
EnumWndProc = True ' Return True To keep enumerating
End Function
Public Function WindowTextFromWnd(ByVal hwnd As Long) As String
Dim sTemp As String, sTitle As String, c As Integer
sTemp = String$(255, 0)
c = GetWindowText(hwnd, sTemp, 256)
sTitle = Left$(sTemp, c)
WindowTextFromWnd = sTitle
End Function
Just one thing, though...
It makes all windows in the system visible.
Meaning ALL windows.
Last edited by jovton; Mar 12th, 2001 at 03:46 PM.
jovton
-
Mar 12th, 2001, 09:38 PM
#3
Thread Starter
Lively Member
Oh... Blimey.....
This time I realy got in to trouble playing arround with the system......
Every thing (e. e.) thing got maximized & I had to reboot...
Thanks any way........
Any idea how to maximize only programs in task bar
Thanks
bye
-
Mar 13th, 2001, 04:39 AM
#4
Hyperactive Member
Place the followwing additional declarations in your public module.
Code:
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Type WINDOWPLACEMENT
Length As Long
Flags As Long
ShowCmd As Long
PtMinPosition As POINTAPI
PtMaxPosition As POINTAPI
RcNormalPosition As RECT
End Type
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Modify the WindowTextFromWnd function to look like this one.
Code:
Public Function WindowTextFromWnd(ByVal nhwnd As Long) As String
Dim sTemp As String, sTitle As String, c As Integer, RetVal As Long, _
MyWinStruct As WINDOWPLACEMENT
sTemp = String$(255, 0)
c = GetWindowText(nhwnd, sTemp, 256)
sTitle = Left$(sTemp, c)
MyWinStruct.Length = Len(MyWinStruct)
MyWinStruct.Flags = 0
RetVal = GetWindowPlacement(nhwnd, MyWinStruct)
With MyWinStruct
If (.ShowCmd = SW_SHOWNORMAL) Or (.ShowCmd = SW_SHOWMAXIMIZED) Or (.ShowCmd = SW_SHOWMINIMIZED) Then
If (IsWindowVisible(nhwnd) > 0) Then _
WindowTextFromWnd = sTitle
Else
WindowTextFromWnd = ""
End If
End With
End Function
I hope it helps.
Last edited by jovton; Mar 13th, 2001 at 04:46 AM.
jovton
-
Mar 13th, 2001, 06:45 PM
#5
Hyperactive Member
I've got the final (and best) solution.
Add the following constant:
Code:
Public Const WS_MAXIMIZEBOX = &H10000
And the following declaration:
Code:
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Modify the WindowTextFromWnd function to look like this one:
Code:
Public Function WindowTextFromWnd(ByVal nhwnd As Long) As String
Dim sTemp As String, sTitle As String, c As Integer, RetVal As Long
sTemp = String$(255, 0)
c = GetWindowText(nhwnd, sTemp, 256)
sTitle = Left$(sTemp, c)
RetVal = GetWindowLong(nhwnd, GWL_STYLE)
If (RetVal And WS_MAXIMIZEBOX) = WS_MAXIMIZEBOX Then
If Not (IsWindowVisible(nhwnd) > 0) Then _
sTitle = ""
Else
sTitle = ""
End If
WindowTextFromWnd = sTitle
End Function
You can delete the unneccesary constants, variables and functions that were declared,
if you are not going to use them.
-
Mar 13th, 2001, 08:32 PM
#6
Thread Starter
Lively Member
Thanks a bunch....
Thank you v. much
I'll give it a try
-
Mar 14th, 2001, 01:15 AM
#7
Re: Oh... Blimey.....
Originally posted by ramindu
This time I realy got in to trouble playing arround with the system......
Every thing (e. e.) thing got maximized & I had to reboot...
Thanks any way........
Any idea how to maximize only programs in task bar
Thanks
bye
Thats pretty funny The same thing happened to me while i was trying to make a program to do this for your post The checking for minimize box is a great idea. I was trying to come up with a way of determining if the window was supposed to be maximizable.
-
Mar 14th, 2001, 02:13 AM
#8
Ok this (much smaller) code does what you want. Yes, this little amount of code is all of it! 
Private Const SW_SHOWMAXIMIZED = 3
Private Const WS_MAXIMIZEBOX = &H10000
Private Declare Function IsWindowVisible& Lib "user32" (ByVal hwnd As Long)
Private Declare Function ShowWindow& Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long)
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) 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 Const GWL_STYLE = (-16)
Private Sub Form_Load()
Dim WinHwnd As Long
Dim WindowAttributes As Long
Do
WinHwnd = FindWindowEx(0, WinHwnd, vbNullString, vbNullString)
WindowAttributes = GetWindowLong(WinHwnd, GWL_STYLE)
If (WindowAttributes And WS_MAXIMIZEBOX) = WS_MAXIMIZEBOX And IsWindowVisible(WinHwnd) <> 0 Then
Call ShowWindow(WinHwnd, SW_SHOWMAXIMIZED)
End If
Loop Until WinHwnd = 0
End Sub
-
Mar 14th, 2001, 04:28 AM
#9
Hyperactive Member
Great job!
Use [ code][/code] tags.
-
Mar 14th, 2001, 05:41 AM
#10
-
Mar 14th, 2001, 06:17 AM
#11
Hyperactive Member
Originally posted by Lord Orwell
Ok this (much smaller) code does what you want. Yes, this little amount of code is all of it! 
Oh Lord, are those codes gonna maximize all Windows on Form_Load event, or it can be placed into an MDI form to only maximize the child in it which are visible?
Thanks
Harddisk
-
Mar 14th, 2001, 07:19 PM
#12
It is extremely easy to convert.
Simply change this line:
WinHwnd = FindWindowEx(0, WinHwnd, vbNullString, vbNullString)
To this line:
WinHwnd = FindWindowEx(MDIClientHwnd, WinHwnd, vbNullString, vbNullString)
Where, obviously, MDIClient is the window handle to the mdi client.
I was WONDERING what possible use you could have for this code...
Ok now for the good news:
If that is all you want the code for, you can leave out the checks for maximize boxes and is_Visible.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|