Click to See Complete Forum and Search --> : I hope someone can help me.
markwestcott
Jan 5th, 2000, 04:49 AM
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
MartinLiss
Jan 5th, 2000, 05:28 AM
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).]
markwestcott
Jan 5th, 2000, 05:32 AM
Thanks for trying to help, but this is not what I meant. I would like to be able to minimize other apps windows.
Thanks
QWERTY
Jan 5th, 2000, 05:34 AM
Try this:
In Module:
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
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).]
markwestcott
Jan 5th, 2000, 05:44 AM
Thanks for this. However, the code does not work. I have followed your instructions and upon pressing the CommandButton, nothing happens. Any ideas?
QWERTY
Jan 5th, 2000, 05:46 AM
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.
markwestcott
Jan 5th, 2000, 05:59 AM
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
jpark
Jan 5th, 2000, 06:37 AM
Just for minimize all windows
Place a CommandButton onto Form1.
Copy and paste the following code into Form1's Code Window.
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).]
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.