Results 1 to 8 of 8

Thread: I hope someone can help me.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Posts
    79

    Post

    I everyone (again)! I am quite new to the Windows API, and wonder if anyone could show me some code to do this:

    1) when one button is pressed to find all currently maximised windows and to minimise them.

    2) when another button is pressed to maximise all the windows that I have just minimised.

    I realise that if someone shows me how to do the first one I will probably be able to do the second.

    Thanks in advance,


    Mark

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    If you are talking about the windows in your app, you don't need to use an API. In Form1, just do Form2.WindowState = vbMinimized, and to return them to their previous state do Form2.WindowState = vbNormal
    .

    ------------------
    Marty

    [This message has been edited by MartinLiss (edited 01-05-2000).]

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Posts
    79

    Post

    Thanks for trying to help, but this is not what I meant. I would like to be able to minimize other apps windows.

    Thanks

  4. #4
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    Try this:
    In Module:
    Code:
    Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Const WS_MINIMIZEBOX = &H20000
    Private Const SW_MINIMIZE = 6
    Private Const GWL_STYLE = (-16)
    
    Public Function EnumProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
        'Make sure the Window is Visible and Minimizable..
        If IsWindowVisible(hwnd) Then
            If (GetWindowLong(hwnd, GWL_STYLE) And WS_MINIMIZEBOX) = WS_MINIMIZEBOX Then
                'Minimize it
                Call ShowWindow(hwnd, SW_MINIMIZE)
            End If
        End If
        EnumProc = hwnd
    End Function
    In form
    Code:
    Private Sub Command1_Click()
        Call EnumWindows(AddressOf EnumProc, 0)
    End Sub
    Hope this helps (HTH)

    Regards

    ------------------
    Visual Basic Programmer
    ------------------
    PolComSoft
    You will hear a lot about it.



    [This message has been edited by QWERTY (edited 01-05-2000).]

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Posts
    79

    Post

    Thanks for this. However, the code does not work. I have followed your instructions and upon pressing the CommandButton, nothing happens. Any ideas?

  6. #6
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    Well it works on my machine. Are you sure you copied everything all right?

    ------------------
    Visual Basic Programmer
    ------------------
    PolComSoft
    You will hear a lot about it.


  7. #7

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Posts
    79

    Post

    Very sure. The button has no affect at all. Maybe you could email the project and see if that works, just incase I am doing something wrong, but I doubt it.

    Thanks a lot


    Mark

  8. #8
    Member
    Join Date
    Jan 1999
    Location
    Garden Grove, CA, Orange
    Posts
    55

    Post

    Just for minimize all windows

    Place a CommandButton onto Form1.

    Copy and paste the following code into Form1's Code Window.

    Code:
    Private Declare Sub keybd_event Lib "user32" ( _
    ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    
          Const KEYEVENTF_KEYUP = &H2
          Const VK_LWIN = &H5B
    
    Private Sub Command1_Click()
       ' 77 is the character code for the letter 'M'
             Call keybd_event(VK_LWIN, 0, 0, 0)
             Call keybd_event(77, 0, 0, 0)
             Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
    End Sub
    Joon


    [This message has been edited by jpark (edited 01-05-2000).]

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