Sign in to follow this  
Followers 0
madflame991

Same coordinates, and yet it moves...

9 posts in this topic

Hello! I followed the simple example from the help file on creating windows and moving them...

I created a child window (and it's parent); the parent window has $WS_POPUP and WS_MAXIMIZE; Why does the child window move in the example below?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Dim $gui, $background, $pic, $basti_stay, $msg
Dim $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\logo4.gif"
Dim $X = 10, $Y = 300
    
$gui = GUICreate("Background", 400, 100,-1,-1,$WS_POPUP+$WS_MAXIMIZE)
$background = GUICtrlCreatePic(@SystemDir & "\oobe\images\mslogo.jpg", 0, 0, 400, 100)
GUISetState(@SW_SHOW)

$pic = GUICreate("", 169, 68, $X, $Y, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_MDICHILD, $gui)
$basti_stay = GUICtrlCreatePic($sFile, 0, 0, 169, 68)
GUISetState(@SW_SHOW)
Sleep(2000)
WinMove($pic,'',$X,$Y);it's the same $X and $Y and yet it moves... why?
Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

When the control is created initially it's not at those exact coordinates. It's at 13 by 322, I'm not sure exactly why though. Either way when you use WinMove it replaces it to the actual coordinates.

And off topic, adding styles together is a big no-no. Should always use BitOR.

ie: Instead of $WS_POPUP+$WS_MAXIMIZE

Use BitOR($WS_POPUP, $WS_MAXIMIZE)

Edited by RobSaunders

Share this post


Link to post
Share on other sites

Thx for the tip on using BitOr when summing hex values... I used the basic "+" operator because I thought it was a bit faster than calling a function.

When the control is created initially it's not at those exact coordinates.

That's what I'm trying to do... create the child window at those exact coordinates. Anyone who knows how to do it please post here.

Share this post


Link to post
Share on other sites

I had this issue once before and found it has to do with the border styles of the different windows. You need to add a fudge factor to the child window to prevent it from moving - it should be moving up and to the left (up and to the left) because the border of the child window is thinner than that of the main GUI.

Bob


You can't see a rainbow without first experiencing the rain.

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

I thought it should work normal too, but I guess not. Any reason it has to be in place at creation time? You could just do WinMove() before GUISetState().

Also, as to your comment about BitOR, I'm honestly not sure which is faster (though the difference should be negligible anyway) but adding values together can potentially yield unexpected results, BitOR is the proper way to combine styles.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

The deal is that when you create a child window at 0x0 it will be created where the client coords would be if it was a "normal" window. It is solvable by a little math like this in the example below. (I used this method in Franks Gadgets)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Dim $gui, $background, $pic, $basti_stay, $msg
Dim $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\logo4.gif"
Dim $X = 10, $Y = 300, $Correction[2]

$GUIWindows = GUICreate("Windows test", 32, 32, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW)
$GUIWindows2 = GUICreate("Windows test2", 32, 32, 0, 0, $WS_POPUP, BitOR($WS_CLIPCHILDREN, $WS_EX_MDICHILD, $WS_EX_TOOLWINDOW), $GUIWindows)
$Pos4 = WinGetPos($GUIWindows2)
GUIDelete($GUIWindows2)
GUIDelete($GUIWindows)
$Correction[0] = "-" & $Pos4[0]     ;This make sure all "ChildGui"s is created on the right spot (0,0)
$Correction[1] = "-" & $Pos4[1]     ;This make sure all "ChildGui"s is created on the right spot (0,0)
    
$gui = GUICreate("Background", 400, 100,-1,-1, BitOR($WS_POPUP, $WS_MAXIMIZE))
$background = GUICtrlCreatePic(@SystemDir & "\oobe\images\mslogo.jpg", 0, 0, 400, 100)
GUISetState(@SW_SHOW)

$pic = GUICreate("", 169, 68, $Correction[0]+$X, $Correction[1]+$Y, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $gui)
$basti_stay = GUICtrlCreatePic($sFile, 0, 0, 169, 68)
GUISetState(@SW_SHOW)
Sleep(2000)
WinMove($pic,'',$X,$Y);it's the same $X and $Y and yet it moves... why?
Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE
Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites

is this for cabal ?

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
Sign in to follow this  
Followers 0