Results 1 to 12 of 12

Thread: Maximize all

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Location
    Sri Lanka
    Posts
    66
    Any body have any idea how to Maximize all windows in windows using VB

    Thanks

  2. #2
    Hyperactive Member jovton's Avatar
    Join Date
    Nov 2000
    Location
    South Africa
    Posts
    266
    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Location
    Sri Lanka
    Posts
    66

    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

  4. #4
    Hyperactive Member jovton's Avatar
    Join Date
    Nov 2000
    Location
    South Africa
    Posts
    266
    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

  5. #5
    Hyperactive Member jovton's Avatar
    Join Date
    Nov 2000
    Location
    South Africa
    Posts
    266
    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.
    jovton

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Location
    Sri Lanka
    Posts
    66

    Thanks a bunch....

    Thank you v. much

    I'll give it a try

  7. #7
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    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.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  8. #8
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    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
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  9. #9
    Hyperactive Member jovton's Avatar
    Join Date
    Nov 2000
    Location
    South Africa
    Posts
    266
    Great job!
    Use [ code][/code] tags.
    jovton

  10. #10
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    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) 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.
    Last edited by Lord Orwell; Mar 14th, 2001 at 05:46 AM.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  11. #11
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    485
    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

  12. #12
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    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.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width