Jump to content

GUICreate Window Position Bug?

Recommended Posts


I have two 27" Monitors in Dual setup.  I created the following code in another thread due to not able to get TrayTips to work how I need.
It creates a popup window via GUICreate.

I have discovered an odd quirk that I am not sure why it is happening.  If you do not have these same sized monitors then you will not be able to see the problem if you run the code as is.

Using the code below I am moving the created popup window to various areas of my desktop.
Trying to get it to hug the left side of the left monitor or specifically the desktop,  a certain number "1921"  will center the window instead.

There is a boundary border around the GUI window.

$Left = 1920  <== The left side of the GUI Window and the left side of the desktop there is a one pixel space between them

$Left = 1921  <== The left side of the GUI Window and the left side of the monitor are SUPPOSE to Hug, no gaps
                                 Instead this centers the window on the left monitor 

$Left = 1922  <== The left side edge of the gui window is just over the desktop left edge out of sight, can't see the white left border.


#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <ColorConstants.au3>

$Left = 1920
$Top = 150
Notice("Left Edge","Left Monitor - Left Edge",4,1,$Left,$Top)

; -- BUG --
$Left = 1921  ; <--  1921 puts gui window center of screen - Left Monitor   WHY?
$Top = 150
Notice("Funky Position","Moves to center of left monitor",4,2,$Left,$Top)
; -- END BUG --

$Left = 1922
$Top = 150
Notice("Past Left Edge","Moves Left of Left Edge - Left Monitor",4,1,$Left,$Top)

Func Notice($message, $description, $timeout = 2, $icon=0,$Left=352,$Top=120)
    Local $iconArray[4]  = ["", "16783",  "161", "240" ]
    Local $popup = GUICreate("",350,60,(@DesktopWidth - $Left),(@DesktopHeight - $Top),$WS_POPUP+$WS_BORDER) ; title, width, height, left, top, style, exStyle, parent

    if($icon > 3) Then $icon = 0
    if($timeout < 1) Then $timeout = 2
    $timeout = $timeout * 1000

    if($icon > 0) Then GUICtrlCreateIcon("shell32.dll", $iconArray[$icon], 10, 7,43,43) ; filename, iconName, left, top, width, height, style, exstyle

    $theMessage = GUICtrlCreateLabel($message,65, 10, 300, 30) ; text, left, top, width, height, style, ex style
    GUICtrlSetFont(-1, 12, 600, 0, "", 2) ; size, weight, attribute ( 2 = italic, 4 = underline, 8 = strike ), fontname, quality
    $theDescription = GUICtrlCreateLabel($description, 65, 32, 300, 30)
    GUICtrlSetFont(-1, 9, 100, 0,"",2) ;
    GUICtrlSetColor(-1, 0xACAEAC)

    GUISetState(@SW_SHOW, $popup)

Is there something I am doing wrong in my code or is this a bug?

Why does the code above when 1921 is entered into the LEFT option for GUICreate position does it dramatically alter the gui window position?

Share this post

Link to post
Share on other sites
GUICreate("",350,60,(@DesktopWidth - $Left),(@DesktopHeight - $Top),$WS_POPUP+$WS_BORDER) ; title, width, height, left, top,

This is the specific line for creating and positioning the Gui Window.

$Left = 1921


(@DesktopWidth - 1921)   <==  PROBLEM occurs

Edited by iAmNewbe

Share this post

Link to post
Share on other sites

Further Investigation

Two Monitors, Left Monitor and Right Monitor

@DesktopWidth = 1920


LEFT Option of GUICreate contains

(@DesktopWidth - 1920)   Result Numerical 0  AND Positions to Left side of Left Monitor

(@DesktopWidth - 0)   Result Numerical 1920  AND Positions to Left side of Right Monitor

(@DesktopWidth - 1921)   Result Numerical -1  AND Positions to Center of Left Monitor

(@DesktopWidth - -1)   Result Numerical 1921 AND Positions to close to Left Edge of Right Monitor (gaps between edges of GUI Window and Right Monitor)

0  <== Left Side of Left Monitor

-1 <== Centers on Left Monitor

-2 <== Left Edge of GUI is past Left Edge of Desktop out of sight


It seems the issue is when -1 is used in the spacing of the Left Option for GUICreate.

For me in this situation if I just use 0 without @DesktopWidth calc then it positions how I want on the left edge of the left monitor / desktop.   

Share this post

Link to post
Share on other sites

Discrepancy between first post and post #3

In Post 1   

(@DesktopWidth - $Left)

when $Left is 1920 which after calculation result is ZERO I said position of GUI is one pixel off from Left side of desktop.


When removal of @DesktopWidth and just place the numeric 0  then the GUI touches the Left side of the desktop.

Both are same numerically.   When testing again with both of these options I get the equal result of the GUI window left edge touching the left edge of the desktop.
I do NOT know why I got a different result the first time around.

I am pulling the $Left variable or integer from an ini file setting.  For some reason I can not pass @DesktopWidth or other @ constants via ini file it just does not work so I have to hard code these constants / directives into the code and just pass the numeric number through. Which I believe are strings when doing it this way and not integers.

I am not sure why -1 does not work but I will just use the 0 for LEFT option for positioning horizontally where I want via subtracting the desktop width by itself to get zero.



Share this post

Link to post
Share on other sites

Long story short

-1 centers GUI

0 Paces GUI on left edge of desktop

I do not understand -1 result with GUI placement.

Share this post

Link to post
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


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.