Jump to content

desktopwidth/height


pomj
 Share

Recommended Posts

Hi, I'm a newbie to autoit programming so I aplogize if I have missed something obvious.

I'm trying to implement some window managing functions I've come to appreciate while using larswm in linux and I wonder how I get the "real" desktop workarea. I tried @DesktopWidth and @DesktopHeight but these macros seems to ignore the taskbar.

cheers

/michael

Link to comment
Share on other sites

Well to use that you would have to know the heigt of the taskbar (since the user can change that), and you would have to check the taskbars place AND if the user have custom lines.. So I guess theres no good way to get it :whistle: A simple but ugly way would be making a gui maximize it and then read its height and width - ugly but it should work.. I dont know if you can do this with @SW_HIDE

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Link to comment
Share on other sites

Well if i maximize the window correctly - it would give me the height and the widtt of the workarea :whistle: And you cant really use the taskbar, since people have sometimes more than one.. (people like me) and the other taskbar is also on top

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Link to comment
Share on other sites

Like Shevilie said before "you would have to know the heigt and width of the taskbar (since the user can changed)"

#include <GUIConstants.au3>

Opt("WinTitleMatchMode", 4)

$Pos = WinGetPos("classname=Shell_TrayWnd")
$Pos[3] = @DesktopHeight - ($Pos[3] + 32)

$Form1 = GUICreate("AForm1", $Pos[2], $Pos[3], -1, -1)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

Of course, you should really do some more checking as the taskbar can be placed on any of the four sides of the screen. I wonder if there is some API call that gets the "working area" (for lack of a better term) of the screen. I mean, when a Window receives the maximize notification it has to get the size info from somewhere... right?

Link to comment
Share on other sites

Well I once wanted this information for a program I was writing to simulate the "toast" style popups of MSN messenger. You know when a user logs on and a small window slides onto the screen from the bottom right? I ended up writing a bunch of code to detect where the taskbar was, what position it was in, etc, etc. So that when I slid the window onto the screen it would end up in the right place (I allowed for custom position of where the window would slide from/to ie: top-right slide from top, bottom-right slide from right, etc). I lost the script which was unfortunate at the time, but not so bad now as it probably wouldn't even work with AutoIt now (lots of changes to the GUI stuff). So now with DllCall being available to us, I just wonder if there was not some easier way for me to get the available area of the screen.

Also, I like your maximized window idea... I'll have to try that.

*Edit: Hmm.. some confusiing results.

First, I don't think you can maximize a window while it's hidden, and using the $WS_MAXIMIZE style creates a fullscreen window (ie: maximized over the taskbar), so that doesn't help.

Second: Maximizing after it's visible and then doing WinGetPos yields (on my resolution of 1280x800) a window width/height of 1286x756. So the width ends up larger than the actual screen.

Edited by Saunders
Link to comment
Share on other sites

Of course, you should really do some more checking as the taskbar can be placed on any of the four sides of the screen. I wonder if there is some API call that gets the "working area" (for lack of a better term) of the screen. I mean, when a Window receives the maximize notification it has to get the size info from somewhere... right?

Until somebody comes with an API call this does the trick. :whistle:

#include <GUIConstants.au3>

Opt("WinTitleMatchMode", 4)

$Pos = WinGetPos("classname=Shell_TrayWnd")
If $Pos[2] <> @DesktopWidth Then $Pos[2] = @DesktopWidth - $Pos[2]
If $Pos[3] <> @DesktopHeight Then 
    $Pos[3] = @DesktopHeight - ($Pos[3] + 32)
Else
    $Pos[3] -= 32
EndIf

$Form1 = GUICreate("AForm1", $Pos[2], $Pos[3], -1, -1)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

  • Moderators

I remember seeing someone has done that already.

You really should just not post. You never have anything valid to say... 2 or 3 times in this thread alone, you've said... "Someone has done it"... no shit... why don't you find it.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Until somebody comes with an API call this does the trick. :whistle:

#include <GUIConstants.au3>

Opt("WinTitleMatchMode", 4)

$Pos = WinGetPos("classname=Shell_TrayWnd")
If $Pos[2] <> @DesktopWidth Then $Pos[2] = @DesktopWidth - $Pos[2]
If $Pos[3] <> @DesktopHeight Then 
    $Pos[3] = @DesktopHeight - ($Pos[3] + 32)
Else
    $Pos[3] -= 32
EndIf

$Form1 = GUICreate("AForm1", $Pos[2], $Pos[3], -1, -1)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
@Danny35...

I've done this type of stuff before, believe I've posted it even (maybe that's what Secure_IT is talking out his ass about)... anyway... If I can offer a suggestion.

My taskbar height is larger than standard... to make sure I don't error on the height and width, I use ControlGetPos().

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Heh, when I run that code, it tries to create a window with width/height of -4 x 716.

Here, I just wrote this function and tested it quickly. It returns a string of Top, Right, Bottom, or Left depending on what side of the screen the taskbar is on.

Just a little concept function. Gives an idea of how something more complex can be accomplished.

Func _GetTaskbarSide()
    Local $h_Wnd, $a_Pos
    Local $i_WTMM = Opt('WinTitleMatchMode', 4)
    Local $v_Return = 0
    Do
        $h_Wnd = WinGetHandle('classname=Shell_TrayWnd')
        If @error Then
            SetError(1)
            ExitLoop
        EndIf
        
        $a_Pos = WinGetPos($h_Wnd)
        
        If $a_Pos[0] < 0 AND $a_Pos[1] < 0 Then
            If $a_Pos[2] > @DesktopWidth Then
                $v_Return = 'Top'
            Else
                $v_Return = 'Left'
            EndIf
        ElseIf $a_Pos[1] < 0 Then
            $v_Return = 'Right'
        Else
            $v_Return = 'Bottom'
        EndIf
    Until True
    
    Opt('WinTitleMatchMode', $i_WTMM)
    Return $v_Return
EndFunc

*Edit: Maybe later after I get some sleep (just got home from work, it's like 0530hrs) I'll finally get off my butt and rewrite the code to actually figure out the usable desktop area.

Edited by Saunders
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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