The SetWindowPlacement API

bmatumbura
bmatumbura used Ask the Experts™
on
I have the following declarations & functions in my application.
====================================
Private Type POINTAPI
        X As Long
        Y As Long
End Type
Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
Private Type WINDOWPLACEMENT
        Length As Long
        flags As Long
        showCmd As Long
        ptMinPosition As POINTAPI
        ptMaxPosition As POINTAPI
        rcNormalPosition As RECT
End Type

Private Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long

Public Sub SetMinMaxPos(ByVal hwnd As Long)
  Dim WinEst As WINDOWPLACEMENT, Rectan As RECT, Punto As POINTAPI
  Dim rtn As Long
  WinEst.Length = Len(WinEst)
  ' Get the current window placement
  rtn = GetWindowPlacement(hwnd, WinEst)
  Rectan = WinEst.rcNormalPosition
  ' Set the new min/max positions
  Punto.X = -100 'WinEst.ptMinPosition.X
  Punto.Y = -100 'WinEst.ptMinPosition.Y
  'initialize the structure
  WinEst.Length = Len(WinEst)
  WinEst.showCmd = SW_SHOWNA
  WinEst.ptMinPosition = Punto
  WinEst.rcNormalPosition = Rectan
  'set the new window placement
  rtn = SetWindowPlacement(hwnd, WinEst)
End Sub

=========================================

My application closes the explorer shell (removing the start menu, desktop & icons, and the taskbar) and takes control of windows of running applications. To get the window handles, I am using the EnumWindowsProc API.

Everything works as expected, but when I minimize a window, it's displayed as a minimized icon at the botton of the screen.

I tried to use the SetWindowPlacement API in my function to set the coodinates of the minimized window off screen:

 SetMinMaxPos hwnd

but the minimized window still displays at the bottom of the screen. How do I remove these minimized windows without hiding the window from the running tasks window?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Try this


Private Const SW_MINIMIZE = 6
Private Type POINTAPI
        x As Long
        y As Long
End Type
Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
Private Type WINDOWPLACEMENT
        Length As Long
        flags As Long
        showCmd As Long
        ptMinPosition As POINTAPI
        ptMaxPosition As POINTAPI
        rcNormalPosition As RECT
End Type
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Dim Rectan As RECT
Private Sub Form_Load()
    'Tip submitted by pyp99 (pyp99@hotmail.com)
    Dim WinEst As WINDOWPLACEMENT
    Dim rtn As Long
    WinEst.Length = Len(WinEst)
    'get the current window placement
    rtn = GetWindowPlacement(Me.hwnd, WinEst)
    Rectan = WinEst.rcNormalPosition
End Sub
Private Sub Command1_Click()
    Dim WinEst As WINDOWPLACEMENT
    Dim Punto As POINTAPI
    Dim rtn As Long
    'set the new min/max positions
    Punto.x = 100
    Punto.y = 100
    'initialize the structure
    WinEst.Length = Len(WinEst)
    WinEst.showCmd = SW_MINIMIZE
    WinEst.ptMinPosition = Punto
    WinEst.ptMaxPosition = Punto
    WinEst.rcNormalPosition = Rectan
    'set the new window placement (minimized)
    rtn = SetWindowPlacement(Me.hwnd, WinEst)
End Sub
Author of the Year 2009

Commented:
Hi bmatumbura,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept EDDYKT's comment(s) as an answer.

bmatumbura, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept THIS comment as an answer.
==========
DanRollins -- EE database cleanup volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial