Sign in to follow this  
Followers 0
anixon

GUI Placement

8 posts in this topic

This snippet of code produces Window which has the look required for my purpose:

GUICreate("MenuC", 50, 305, -1, -1,0x80000000 + 0x00400000, 0x00000008 + 0x00000080)

However the abilty to drag and drop the window to a new position on the screen is disabled. Can the look be maintained and the drag and drop function remain active?

Cheers

Ant...

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Easy way would be setting $GUI_WS_EX_PARENTDRAG style for all controls that will be in this window. Also create empty labels to cover up most space unoccupied by controls, and give them $GUI_WS_EX_PARENTDRAG too.

Unless I misunderstand what you want. Because this thing which I think you want isn't called "drag and drop function" :)

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

This snippet of code produces Window which has the look required for my purpose:

GUICreate("MenuC", 50, 305, -1, -1,0x80000000 + 0x00400000, 0x00000008 + 0x00000080)

However the abilty to drag and drop the window to a new position on the screen is disabled. Can the look be maintained and the drag and drop function remain active?

Cheers

Ant...

#include <guiconstants.au3>
#include <misc.au3>

$b = GUICreate("MenuC", 50, 305, -1, -1,0x80000000 + 0x00400000, 0x00000008 + 0x00000080)
GUISetState()
While 1
$msg = GUIGetMsg()
 If $msg = $GUI_EVENT_PRIMARYDOWN Then
    $mp = MouseGetPos()
    $wp = WinGetPos("MenuC")
    While _IsPressed("01")
        $newp = MouseGetPos()
        WinMove("MenuC",'',$wp[0] + $newp[0] - $mp[0],$wp[1] + $newp[1] - $mp[1])
    WEnd
     
 EndIf
 

WEnd

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#include <guiconstants.au3>
#include <misc.au3>

$b = GUICreate("MenuC", 50, 305, -1, -1,0x80000000 + 0x00400000, 0x00000008 + 0x00000080)
GUISetState()
While 1
$msg = GUIGetMsg()
 If $msg = $GUI_EVENT_PRIMARYDOWN Then
    $mp = MouseGetPos()
    $wp = WinGetPos("MenuC")
    While _IsPressed("01")
        $newp = MouseGetPos()
        WinMove("MenuC",'',$wp[0] + $newp[0] - $mp[0],$wp[1] + $newp[1] - $mp[1])
    WEnd
     
 EndIf
 

WEnd
Thanks martin that works just fine and I very much appreciate your help.

I am going to mod it to write the new position to an ini file so that when the application starts again it can read the co-ordinates of the last new position. That way the user can decide where MenuC should be located on the screen. When I get it working I will post it back to this help instalment so that other users can use it for their own purposes.

Cheers

Ant..

Share this post


Link to post
Share on other sites

Thanks martin that works just fine and I very much appreciate your help.

I am going to mod it to write the new position to an ini file so that when the application starts again it can read the co-ordinates of the last new position. That way the user can decide where MenuC should be located on the screen. When I get it working I will post it back to this help instalment so that other users can use it for their own purposes.

Cheers

Ant..

This is the modification:

CODE
#include <guiconstants.au3>

#include <misc.au3>

Global $message

$Co_Ord1 = IniRead(@ScriptDir & "\image.ini", "section24", "value1", "-1")

$Co_Ord2 = IniRead(@ScriptDir & "\image.ini", "section24", "value2", "-1")

GUICreate("MenuC", 50, 305, $Co_Ord1, $Co_Ord2, 0x80000000 + 0x00400000, 0x00000008 + 0x00000080)

$ExitButton = GUICtrlCreateButton("Exit", 5, 5, 40, 35)

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_PRIMARYDOWN

$mp = MouseGetPos()

$wp = WinGetPos("MenuC")

While _IsPressed("01")

$newp = MouseGetPos()

WinMove("MenuC", '', $wp[0] + $newp[0] - $mp[0], $wp[1] + $newp[1] - $mp[1])

WEnd

If $wp[0] + $newp[0] - $mp[0] <> $Co_Ord1 Then

IniWrite(@ScriptDir & "\image.ini", "section24", "value1", $wp[0] + $newp[0] - $mp[0])

IniWrite(@ScriptDir & "\image.ini", "section24", "value2", $wp[1] + $newp[1] - $mp[1])

EndIf

Case $msg = $ExitButton

GUIDelete()

PLExit()

EndSelect

WEnd

;Exit Routine

Func PLExit()

If $Co_Ord1 <> $wp[0] + $newp[0] - $mp[0] Or $Co_Ord2 <> $wp[1] + $newp[1] - $mp[1] Then

$message = " New Menu Position Saved"

DisplayMessage()

EndIf

Exit

EndFunc ;==>PLExit

;Message Box Subroutine

Func DisplayMessage()

SplashTextOn("MenuC", $message, 270, 50, 150, 350, 36, "times new roman", 10, 600)

Sleep(2000)

SplashOff()

EndFunc ;==>DisplayMessage

Cheers

Ant..

Share this post


Link to post
Share on other sites

This is the modification:

CODE
#include <guiconstants.au3>

#include <misc.au3>

Global $message

$Co_Ord1 = IniRead(@ScriptDir & "\image.ini", "section24", "value1", "-1")

$Co_Ord2 = IniRead(@ScriptDir & "\image.ini", "section24", "value2", "-1")

GUICreate("MenuC", 50, 305, $Co_Ord1, $Co_Ord2, 0x80000000 + 0x00400000, 0x00000008 + 0x00000080)

$ExitButton = GUICtrlCreateButton("Exit", 5, 5, 40, 35)

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_PRIMARYDOWN

$mp = MouseGetPos()

$wp = WinGetPos("MenuC")

While _IsPressed("01")

$newp = MouseGetPos()

WinMove("MenuC", '', $wp[0] + $newp[0] - $mp[0], $wp[1] + $newp[1] - $mp[1])

WEnd

If $wp[0] + $newp[0] - $mp[0] <> $Co_Ord1 Then

IniWrite(@ScriptDir & "\image.ini", "section24", "value1", $wp[0] + $newp[0] - $mp[0])

IniWrite(@ScriptDir & "\image.ini", "section24", "value2", $wp[1] + $newp[1] - $mp[1])

EndIf

Case $msg = $ExitButton

GUIDelete()

PLExit()

EndSelect

WEnd

;Exit Routine

Func PLExit()

If $Co_Ord1 <> $wp[0] + $newp[0] - $mp[0] Or $Co_Ord2 <> $wp[1] + $newp[1] - $mp[1] Then

$message = " New Menu Position Saved"

DisplayMessage()

EndIf

Exit

EndFunc ;==>PLExit

;Message Box Subroutine

Func DisplayMessage()

SplashTextOn("MenuC", $message, 270, 50, 150, 350, 36, "times new roman", 10, 600)

Sleep(2000)

SplashOff()

EndFunc ;==>DisplayMessage

Cheers

Ant..

This is probably a bit more exciting.

The code manages both a horizontal and vertical menu strip (can be run as popups) positions and saves the changes.

CODE
#include <guiconstants.au3>

#include <misc.au3>

Global $message, $xPos, $yPos, $section, $value1, $value2

;Read the Menu Positions

While 1

$MenuCPos1 = IniRead(@ScriptDir & "\image.ini", "section23", "value1", "-1")

$MenuCPos2 = IniRead(@ScriptDir & "\image.ini", "section23", "value2", "-1")

$MenuCPos3 = IniRead(@ScriptDir & "\image.ini", "section24", "value1", "-1")

$MenuCPos4 = IniRead(@ScriptDir & "\image.ini", "section24", "value2", "-1")

$mCPos = IniRead(@ScriptDir & "\image.ini", "section25", "value1", "")

If $mCPos = 1 Then

GUICreate("MenuC", 40, 305, $MenuCPos1, $MenuCPos2, 0x80000000 + 0x00400000, 0x00000008 + 0x00000080)

Else

GUICreate("MenuC", 305, 40, $MenuCPos3, $MenuCPos4, 0x80000000 + 0x00400000, 0x00000008 + 0x00000080)

EndIf

If $mCPos = 1 Then

$ChangeMenu = GUICtrlCreateButton("H", 5, 45, 30, 30)

Else

$ChangeMenu = GUICtrlCreateButton("V", 45, 5, 30, 30)

EndIf

$ExitButton = GUICtrlCreateButton("Exit", 5, 5, 30, 30)

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_PRIMARYDOWN

$mp = MouseGetPos()

$wp = WinGetPos("MenuC")

While _IsPressed("01")

$newp = MouseGetPos()

WinMove("MenuC", '', $wp[0] + $newp[0] - $mp[0], $wp[1] + $newp[1] - $mp[1])

$xPos = $wp[0] + $newp[0] - $mp[0]

$yPos = $wp[1] + $newp[1] - $mp[1]

WEnd

PreProcessPosXY()

Case $msg = $ChangeMenu

GUIDelete()

If $mCPos = 1 Then

$section = "section25"

$value1 = 0

Else

$section = "section25"

$value1 = 1

EndIf

SaveChanges()

ExitLoop

Case $msg = $ExitButton

GUIDelete()

PLExit()

EndSelect

WEnd

WEnd

;Check for Position Change

Func PreProcessPosXY()

If $mCPos = 1 Then

If $xPos <> $MenuCPos1 Or $yPos <> $MenuCPos2 Then

$section = "section23"

$value1 = $xPos

$value2 = $yPos

$message = " New Menu Position Saved"

DisplayMessage()

SaveChanges()

EndIf

Else

If $xPos <> $MenuCPos3 Or $yPos <> $MenuCPos4 Then

$section = "section24"

$value1 = $xPos

$value2 = $yPos

$message = " New Menu Position Saved"

DisplayMessage()

SaveChanges()

EndIf

EndIf

EndFunc ;==>PreProcessPosXY

Func SaveChanges()

;Save Changes

If $value1 >= 0 Then

IniWrite(@ScriptDir & "\image.ini", $section, "value1", $value1)

EndIf

If $value2 >= 0 Then

IniWrite(@ScriptDir & "\image.ini", $section, "value2", $value2)

EndIf

;Read New X Y Positions

$MenuCPos1 = IniRead(@ScriptDir & "\image.ini", "section23", "value1", "-1")

$MenuCPos2 = IniRead(@ScriptDir & "\image.ini", "section23", "value2", "-1")

$MenuCPos3 = IniRead(@ScriptDir & "\image.ini", "section24", "value1", "-1")

$MenuCPos4 = IniRead(@ScriptDir & "\image.ini", "section24", "value2", "-1")

EndFunc ;==>SaveChanges

;Exit Routine

Func PLExit()

Exit

EndFunc ;==>PLExit

;Message Box Subroutine

Func DisplayMessage()

SplashTextOn("MenuC", $message, 270, 50, 150, 350, 36, "times new roman", 10, 600)

Sleep(2000)

SplashOff()

EndFunc ;==>DisplayMessage

Cheers

Ant..

Share this post


Link to post
Share on other sites

This is probably a bit more exciting.

The code manages both a horizontal and vertical menu strip (can be run as popups) positions and saves the changes.

CODE
#include <guiconstants.au3>

#include <misc.au3>

Global $message, $xPos, $yPos, $section, $value1, $value2

;Read the Menu Positions

While 1

$MenuCPos1 = IniRead(@ScriptDir & "\image.ini", "section23", "value1", "-1")

$MenuCPos2 = IniRead(@ScriptDir & "\image.ini", "section23", "value2", "-1")

$MenuCPos3 = IniRead(@ScriptDir & "\image.ini", "section24", "value1", "-1")

$MenuCPos4 = IniRead(@ScriptDir & "\image.ini", "section24", "value2", "-1")

$mCPos = IniRead(@ScriptDir & "\image.ini", "section25", "value1", "")

If $mCPos = 1 Then

GUICreate("MenuC", 40, 305, $MenuCPos1, $MenuCPos2, 0x80000000 + 0x00400000, 0x00000008 + 0x00000080)

Else

GUICreate("MenuC", 305, 40, $MenuCPos3, $MenuCPos4, 0x80000000 + 0x00400000, 0x00000008 + 0x00000080)

EndIf

If $mCPos = 1 Then

$ChangeMenu = GUICtrlCreateButton("H", 5, 45, 30, 30)

Else

$ChangeMenu = GUICtrlCreateButton("V", 45, 5, 30, 30)

EndIf

$ExitButton = GUICtrlCreateButton("Exit", 5, 5, 30, 30)

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_PRIMARYDOWN

$mp = MouseGetPos()

$wp = WinGetPos("MenuC")

While _IsPressed("01")

$newp = MouseGetPos()

WinMove("MenuC", '', $wp[0] + $newp[0] - $mp[0], $wp[1] + $newp[1] - $mp[1])

$xPos = $wp[0] + $newp[0] - $mp[0]

$yPos = $wp[1] + $newp[1] - $mp[1]

WEnd

PreProcessPosXY()

Case $msg = $ChangeMenu

GUIDelete()

If $mCPos = 1 Then

$section = "section25"

$value1 = 0

Else

$section = "section25"

$value1 = 1

EndIf

SaveChanges()

ExitLoop

Case $msg = $ExitButton

GUIDelete()

PLExit()

EndSelect

WEnd

WEnd

;Check for Position Change

Func PreProcessPosXY()

If $mCPos = 1 Then

If $xPos <> $MenuCPos1 Or $yPos <> $MenuCPos2 Then

$section = "section23"

$value1 = $xPos

$value2 = $yPos

$message = " New Menu Position Saved"

DisplayMessage()

SaveChanges()

EndIf

Else

If $xPos <> $MenuCPos3 Or $yPos <> $MenuCPos4 Then

$section = "section24"

$value1 = $xPos

$value2 = $yPos

$message = " New Menu Position Saved"

DisplayMessage()

SaveChanges()

EndIf

EndIf

EndFunc ;==>PreProcessPosXY

Func SaveChanges()

;Save Changes

If $value1 >= 0 Then

IniWrite(@ScriptDir & "\image.ini", $section, "value1", $value1)

EndIf

If $value2 >= 0 Then

IniWrite(@ScriptDir & "\image.ini", $section, "value2", $value2)

EndIf

;Read New X Y Positions

$MenuCPos1 = IniRead(@ScriptDir & "\image.ini", "section23", "value1", "-1")

$MenuCPos2 = IniRead(@ScriptDir & "\image.ini", "section23", "value2", "-1")

$MenuCPos3 = IniRead(@ScriptDir & "\image.ini", "section24", "value1", "-1")

$MenuCPos4 = IniRead(@ScriptDir & "\image.ini", "section24", "value2", "-1")

EndFunc ;==>SaveChanges

;Exit Routine

Func PLExit()

Exit

EndFunc ;==>PLExit

;Message Box Subroutine

Func DisplayMessage()

SplashTextOn("MenuC", $message, 270, 50, 150, 350, 36, "times new roman", 10, 600)

Sleep(2000)

SplashOff()

EndFunc ;==>DisplayMessage

Cheers

Ant..

This code works where there is no windows bar (what ever it is called) which contains the name of the window plus the min/max buttons and X to close. If the window has these elements then the code is a little bit different because this type of window can be dragged and all you then need to do is store the new position. The Selection would then be changed to the following.

CODE
Case $msg = $GUI_EVENT_PRIMARYDOWN

$wp = WinGetPos($pTitle)

$xPos = $wp[0]

$yPos = $wp[1]

If $xPos <> $MenuAPos1 Or $yPos <> $MenuAPos2 Then

GUIDelete()

$section = "section23"

$value1 = $xPos

$value2 = $yPos

SaveChanges()

ExitLoop

EndIf

You will note that the code to move the window (as in the previous case) is not required. All works very nicely and looks very professional.

Cheers

Ant..

Share this post


Link to post
Share on other sites

THANK YOU

:)

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