Jump to content

Recommended Posts

Posted

Hi All,

I've tried searching the forums for this but haven't found anything that does what I'm looking for.

I'm trying to make a small form that sits at the top of the screen but reserves that screen space. So when a window is dragged or maximized it never covers the form. Just like the taskbar at the bottom (for most people).

I can get the monitor(s) resolutions to make the form fit I just can't find a way to reserve the screen space?!

Anyone done something similar or can point me in the right direction?

Cheers

;)

  • Moderators
Posted (edited)

Smiley1244,

I have used these functions to set/get the desktop work area: :)

Edit: See working example below

I hope that they are what you are looking for. ;)

M23

Edited by Melba23
Removed code as better is available below

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

Thanks M23,

I'm very new to dll calling, only used once before. Could you give me a working example of the functions?

In the meantime I extracted the relevant code and searching for key phrases I found the following example (posted by mat) that does work but is a lot different to yours (and it doesn't move already maximized windows but that minor).

Global Const $SPI_SETWORKAREA               = 0x002F
Global Const $SPI_GETWORKAREA               = 0x0030
Global Const $SPIF_UPDATEINIFILE             = 0x0001
Global Const $SPIF_SENDWININICHANGE       = 0x0002
Global Const $SPIF_SENDCHANGE               = $SPIF_SENDWININICHANGE
MsgBox (0, _SetWorkArea (-1, 100, -1, -1), @Error)
Func _SetWorkArea ($iLeft = -1, $iTop = -1, $iRight = -1, $iBottom = -1)
    Local $aResult, $rect = DllStructCreate ("int[4]"), $pRect = DllStructGetPtr ($rect)
   ; Change -1's
   If $iLeft = -1 Then $iLeft = 0
   If $iTop = -1 Then $iTop = 0
   If $iRight = -1 Then $iRight = @DesktopWidth + 0
   If $iBottom = -1 Then $iBottom = @DesktopHeight + 0
   ; Set struct data
   DllStructSetData ($rect, 1, $iLeft  , 1)  ;left
   DllStructSetData ($rect, 1, $iTop   , 2)  ;top
   DllStructSetData ($rect, 1, $iRight , 3)  ;right
   DllStructSetData ($rect, 1, $iBottom, 4)  ;bottom
   ; Set the area
    $aResult = DllCall("user32.dll", _
                      "int", "SystemParametersInfo", _
                      "int", $SPI_SETWORKAREA, _
                      "int", 0, _
                      "ptr", $pRect, _
                      "int", $SPIF_SENDCHANGE)
    If @error Then Return SetError(@error, 0, False)
    Return $aResult[0] <> 0
EndFunc ; ==> _SetWorkArea
Edited by Smiley1244
  • Moderators
Posted

Smiley1244,

  Quote

Could you give me a working example of the functions?

Just as well you asked - I had not copied them correctly above. ;)

You say you are trying to reserve space at the top of the screen - so you would need to do something like this to block the top 100 pixels:

#include <StructureConstants.au3>
#include <WinAPI.au3>

Global $iLeft = 0, $iTop = 100, $iRight = 1680, $iBottom = 1020
; Set $iTop to 0 to regain use of those pixels and obviosuly set $iRight and $iBottom to fit your display size 

; I recommend commenting this out and finding out your actual display size first ;)
_SetDesktopWorkArea($iLeft, $iTop, $iRight, $iBottom)

_GetDesktopWorkArea($iLeft, $iTop, $iRight, $iBottom)

ConsoleWrite($iLeft & " - " & $iTop & " - " & $iRight & " - " & $iBottom & @CRLF)

Func _GetDesktopWorkArea(ByRef $iLeft, ByRef $iTop, ByRef $iRight, ByRef $iBottom)
    Local Const $SPI_GETWORKAREA = 48
    Local $tStruct = DllStructCreate($tagRECT)
    If _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($tStruct)) Then
        $iLeft = DllStructGetData($tStruct, "Left")
        $iRight = DllStructGetData($tStruct, "Right")
        $iTop = DllStructGetData($tStruct, "Top")
        $iBottom = DllStructGetData($tStruct, "Bottom")
        Return True
    EndIf
    Return False
EndFunc   ;==>_GetDesktopWorkArea


Func _SetDesktopWorkArea($iLeft, $iTop, $iRight, $iBottom)
    Local Const $SPI_SETWORKAREA = 47
    Local $tStruct = DllStructCreate($tagRECT)
    DllStructSetData($tStruct, "Left", $iLeft)
    DllStructSetData($tStruct, "Right", $iRight)
    DllStructSetData($tStruct, "Top", $iTop)
    DllStructSetData($tStruct, "Bottom", $iBottom)
    If _WinAPI_SystemParametersInfo($SPI_SETWORKAREA, 0, DllStructGetPtr($tStruct)) Then
        Return True
    EndIf
    Return False
EndFunc   ;==>_SetDesktopWorkArea

Clearer now? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Yep the works, thanks M23.

I've already adapted that to a working example.

Thanks for the help.

;)

I'm sure you know this already but for anyone reading this, it might be a Windows 7 thing?! You can't hard re-set to the screen resolution as it puts windows behind the windows taskbar. Easy get round is to use keep the original values from _GetDesktopWorkArea.

;Store Original Desktop Sizes
_GetDesktopWorkArea($iLeft, $iTop, $iRight, $iBottom)
$aOriginalDesktopArea[0] = $iLeft
$aOriginalDesktopArea[1] = $iTop
$aOriginalDesktopArea[2] = $iRight
$aOriginalDesktopArea[3] = $iBottom
Posted

I created this a while ago.

#include <APIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

Example()

Func Example()
    ; Set the working area of the Desktop, in this case 120px to the left and retaining the same height and width.
    Local $aWorkingArea = _WorkingArea(150, Default, Default, Default)

    ; Create the GUI.
    Local $hGUI = GUICreate('', 150, $aWorkingArea[1], $aWorkingArea[2], $aWorkingArea[3], $WS_POPUP)
    Local $iClose = GUICtrlCreateButton('Close', 5, 5, 150 - 10, 25)
    GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $iClose
                ExitLoop

        EndSwitch
    WEnd

    ; Delete the GUI.
    GUIDelete($hGUI)

    ; Reset the working area to the previous values.
    _WorkingArea()
EndFunc   ;==>Example

Func _WorkingArea($iLeft = Default, $iTop = Default, $iWidth = Default, $iHeight = Default)
    Local Static $tWorkArea = 0
    If IsDllStruct($tWorkArea) Then
        _WinAPI_SystemParametersInfo($SPI_SETWORKAREA, 0, DllStructGetPtr($tWorkArea), $SPIF_SENDCHANGE)
        $tWorkArea = 0
    Else
        $tWorkArea = DllStructCreate($tagRECT)
        _WinAPI_SystemParametersInfo($SPI_GETWORKAREA, 0, DllStructGetPtr($tWorkArea))

        Local $tCurrentArea = DllStructCreate($tagRECT)
        Local $aArray[4] = [$iLeft, $iTop, $iWidth, $iHeight]
        For $i = 0 To 3
            If $aArray[$i] = Default Or $aArray[$i] < 0 Then
                $aArray[$i] = DllStructGetData($tWorkArea, $i + 1)
            EndIf
            DllStructSetData($tCurrentArea, $i + 1, $aArray[$i])
            $aArray[$i] = DllStructGetData($tWorkArea, $i + 1)
        Next
        _WinAPI_SystemParametersInfo($SPI_SETWORKAREA, 0, DllStructGetPtr($tCurrentArea), $SPIF_SENDCHANGE)
        $aArray[2] -= $aArray[0]
        $aArray[3] -= $aArray[1]
        Local $aReturn[4] = [$aArray[2], $aArray[3], $aArray[0], $aArray[1]]
        Return $aReturn
    EndIf
EndFunc   ;==>_WorkingArea

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Hi Guinness,

That's similar to the way I'm using M23's code. Do you know is there an easy way to get all existing windows to redraw? I thought it might be '$SPIF_SENDCHANGE' but that doesn't seem to affect the other windows?! Maybe using '_WinAPI_RedrawWindow'?

Also is there a way to handle multiply screens? as everything currrently happens only on the primary display?

Thank you both for your help on this

;)

Posted

  Quote

That's similar to the way I'm using M23's code.

There is a slight difference as my function retains the current desktop size using a Static variable and then reverts back when called without any parameters.

  Quote

Maybe using '_WinAPI_RedrawWindow'?

You could try using WinList & _WinAPI_RedrawWindow with the flag $RDW_FRAME.

  Quote

Also is there a way to handle multiply screens? as everything currrently happens only on the primary display?

I only have a single monitor, sorry.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Sorry Guinness when I said similar, I meant I'd built something similar from M23's code that recalls the original values.

'WinList & _WinAPI_RedrawWindow with the flag $RDW_FRAME.' didn't work, but I found a low tech solution . . .

WinMinimizeAll()

WinMinimizeAllUndo()

Which works pretty well ;)

Thanks again to you both, I'll read up on the Win_API calls.

Posted

When you say the 'original values' do you mean the desktop size before setting it?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

  On 6/13/2012 at 12:33 PM, 'Smiley1244 said:

Yes, well no, the original working area.

So is that a yes or no?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 2 weeks later...
Posted (edited)

Sorry for the slow reply I've progressed this further but I've run into a few issues.

No, I'm not recalling the "desktop size", I am recalling the original working area (desktop minus taskbar space).

1. I still haven't found a way to handle multiple monitors so only works with the primary screen.

2. Any displayed UAC prompt (only tested with Windows 7) resets the original working area. Is there a way to detect a UAC prompt being displayed?

3. The WinMinimizeAll, WinMinimizeAllUndo method of resizing maximized windows after changing the working area caused numerous issues. It was screwing up some windows so they were always on top and other weird issues. This might be due to my system being 4 screens from two graphics cards.

I'm currently using

*************

func _MinMaxedWindows()
Local $aWinList = WinList()
Local $TopWindow = ""

For $i=1 to $aWinList[0][0]
If $aWinList[$i][0]<>"Program Manager" And $aWinList[$i][0]<>"Start" And $aWinList[$i][0]<>"" And BitAND(WinGetState($aWinList[$i][1]),32) = 32 Then

WinSetState($aWinList[$i][0],"",@SW_MINIMIZE)
WinSetState($aWinList[$i][0],"",@SW_MAXIMIZE)

EndIf
Next
WinActivate($TopWindow)

EndFunc

*************

But it is slow if lots of windows are open :D

Any suggestions would be greatly appreciated.

Edited by Smiley1244

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...