Any body have any idea how to Maximize all windows in windows using VB
Thanks
Printable View
Any body have any idea how to Maximize all windows in windows using VB
Thanks
Let's asume that you have a form named Form1,
which has a listbox named lstEnumRef.
The following code goes into a public module:
Just one thing, though...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
It makes all windows in the system visible.
Meaning ALL windows.
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
Place the followwing additional declarations in your public module.
Modify the WindowTextFromWnd function to look like this one.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
I hope it helps. ;)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've got the final (and best) solution.
Add the following constant:
And the following declaration:Code:Public Const WS_MAXIMIZEBOX = &H10000
Modify the WindowTextFromWnd function to look like this one:Code:Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
You can delete the unneccesary constants, variables and functions that were declared,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
if you are not going to use them.
Thank you v. much
I'll give it a try
Thats pretty funny :) The same thing happened to me while i was trying to make a program to do this for your post :rolleyes: 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.Quote:
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
Ok this (much smaller) code does what you want. Yes, this little amount of code is all of it! :D
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
Great job!
Use [ code][/code] tags.
Surely you don't assume that my code was formatted to start with? ;)
By the way, do you have a link to the program you use to post with? I am getting tired of black-and-white code and don't feel like major richtext programming any time soon (im mad at richtext boxes in general) :rolleyes: due to a but that microsoft has never fixed :( . If you read the properties of a character next to the cursor, it incorrectly tells you the properties of the character to the left of it. Say these 2 letters are in a richtextbox:
JL and the cursor is between them.
If you read properties, it will say the letter L but tell you it is bold and not underlined.
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?Quote:
Originally posted by Lord Orwell
Ok this (much smaller) code does what you want. Yes, this little amount of code is all of it! :D
Thanks
Harddisk
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.