Jump to content

[SOLVED] GUI Area


johnmcloud
 Share

Recommended Posts

Hi guys,

I'ts hard to explain for me, so i'll post directly an example.

I want to definite the max area for the position of a gui, so i don't want to make something like this image:

Posted Image

But an area ( in red ) like this:

Posted Image

The Parent-Child GUI was only an example, anyway i'll post it:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinApi.au3>
$hGUI_Parent = GUICreate("Parent", 500, 500)
GUISetState()
$hGUI_Child = GUICreate("Child", 200, 200, 10, 20, BitOR($WS_MAXIMIZEBOX, $GUI_SS_DEFAULT_GUI))
GUISetState()
_WinAPI_SetParent($hGUI_Child, $hGUI_Parent

While 1
$Msg = GUIGetMsg(1)
Switch $Msg[0]
Case $GUI_EVENT_CLOSE
If $Msg[1] = $hGUI_Child Then
GUIDelete($hGUI_Child)
Else
Exit
EndIf
EndSwitch
WEnd

I have think something with WinGetPos, maybe if the gui2 position is more then gui1 size then move inside again, but i don't know if is the correct approach.

Thanks for any help/suggestion

Edited by johnmcloud
Link to comment
Share on other sites

  • Moderators

johnmcloud,

I cannot do it with an API child, but I can with a MIDI child: ;)

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

$hGUI_Parent = GUICreate("Parent", 500, 500)
GUISetState()

$hGUI_Child_API = GUICreate("API Child", 200, 200, 100, 100, BitOR($WS_MAXIMIZEBOX, $GUI_SS_DEFAULT_GUI))
_WinAPI_SetParent($hGUI_Child_API, $hGUI_Parent)
GUISetState()

$hGUI_Child_MIDI = GUICreate("MIDI Child", 200, 200, 200, 200, BitOR($WS_MAXIMIZEBOX, $GUI_SS_DEFAULT_GUI), $WS_EX_MDICHILD, $hGUI_Parent)
GUISetState()

GUIRegisterMsg($WM_WINDOWPOSCHANGING, "_WM_WINDOWPOSCHANGING")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)

    Switch $hWnd
        Case $hGUI_Child_API, $hGUI_Child_MIDI
            ; Get position of parent
            Local $aMain_Pos = WinGetPos($hGUI_Parent)
            If Not IsArray($aMain_Pos) Then Return
            ; Get position of child
            Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam)
            Local $iLeft = DllStructGetData($stWinPos, 3)
            Local $iTop = DllStructGetData($stWinPos, 4)
            Local $iWidth = DllStructGetData($stWinPos, 5)
            Local $iHeight = DllStructGetData($stWinPos, 6)
            ; Set drag limits
            Local $iX_Min = $aMain_Pos[0]
            Local $iY_Min = $aMain_Pos[1] + 24
            Local $iX_Max = $aMain_Pos[0] + $aMain_Pos[2] - $iWidth
            Local $iY_Max = $aMain_Pos[1] + $aMain_Pos[3] - $iHeight
            ; And reset them if passed
            If $iLeft < $iX_Min Then DllStructSetData($stWinPos, 3, $iX_Min)
            If $iLeft > $iX_Max Then DllStructSetData($stWinPos, 3, $iX_Max)
            If $iTop  < $iY_Min Then DllStructSetData($stWinPos, 4, $iY_Min)
            If $iTop  > $iY_Max Then DllStructSetData($stWinPos, 4, $iY_Max)
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc   ;==>_WM_WINDOWPOSCHANGING

Any use? :huh:

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi melba,

I can't use MIDI child, and API don't work very well ;)

This is what i have do for now ( so you can't say i don't work lol )

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinApi.au3>
$hGUI_Parent = GUICreate("Parent", 500, 500)
GUISetState()
$hGUI_Child = GUICreate("Child", 200, 300, 10, 20, BitOR($WS_MAXIMIZEBOX, $GUI_SS_DEFAULT_GUI))
$hButton = GUICtrlCreateButton("Test", 10, 10, 50, 50)
GUISetState()
_WinAPI_SetParent($hGUI_Child, $hGUI_Parent)
While 1
$Msg = GUIGetMsg(1)
Switch $Msg[0]
Case $GUI_EVENT_CLOSE
If $Msg[1] = $hGUI_Child Then
    GUIDelete($hGUI_Child)
Else
    Exit
EndIf
EndSwitch
Test()
WEnd
Func Test()
Local $size_parent = WinGetPos($hGUI_Parent)
Local $size_child = WinGetPos($hGUI_Child)
If IsArray($size_parent) Then
If IsArray($size_child) Then
$x_parent = $size_parent[0]
$y_parent = $size_parent[1]
$w_parent = $size_parent[2]
$h_parent = $size_parent[3]
$x_child = $size_child[0]
$y_child = $size_child[1]
$w_child = $size_child[2]
$h_child = $size_child[3]
If $x_child <= $x_parent Then
    WinMove($hGUI_Child, "", -1, -1)
EndIf
If $x_child >= $w_parent - $w_child + $x_parent Then
    WinMove($hGUI_Child, "", $w_parent - $w_child - $w_child / 36, -1)
EndIf
If $y_child >= $h_parent - $h_child + $y_parent Then
    WinMove($hGUI_Child, "", -1, $h_parent - $h_child - $y_child / 12)
EndIf
If $y_child <= $y_parent * 2 Then
    WinMove($hGUI_Child, "", -1, $y_parent / 12)
EndIf
EndIf
EndIf
EndFunc ;==>Test

Maybe we can merge both system, and add a limit insted of WinMove

EDIT: Change this part of code:

Local $iX_Min = $aMain_Pos[0] - $aMain_Pos[0]
Local $iY_Min = $aMain_Pos[1] - $aMain_Pos[1]
Local $iX_Max = $aMain_Pos[0] + $aMain_Pos[2] - $aMain_Pos[0] - $iWidth
Local $iY_Max = $aMain_Pos[1] + $aMain_Pos[3] - $aMain_Pos[1] - $iHeight

And you have the correct limit for API GUI :D

The left and top are perfect, but right and down not, some mm

Edited by johnmcloud
Link to comment
Share on other sites

  • Moderators

johnmcloud,

I have fixed the API problem: :party:

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

$hGUI_Parent = GUICreate("Parent", 500, 500)
GUISetState()

$hGUI_Child_API = GUICreate("API Child", 200, 200, 100, 100, BitOR($WS_MAXIMIZEBOX, $GUI_SS_DEFAULT_GUI))
_WinAPI_SetParent($hGUI_Child_API, $hGUI_Parent)
GUISetState()

$hGUI_Child_MIDI = GUICreate("MIDI Child", 200, 200, 200, 200, BitOR($WS_MAXIMIZEBOX, $GUI_SS_DEFAULT_GUI), $WS_EX_MDICHILD, $hGUI_Parent)
GUISetState()

GUIRegisterMsg($WM_WINDOWPOSCHANGING, "_WM_WINDOWPOSCHANGING")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)

    ; Get position of parent
    Local $aMain_Pos = WinGetPos($hGUI_Parent)
    If Not IsArray($aMain_Pos) Then Return

    Switch $hWnd
        Case $hGUI_Child_MIDI
            ; Get position of child
            Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam)
            Local $iLeft = DllStructGetData($stWinPos, 3)
            Local $iTop = DllStructGetData($stWinPos, 4)
            Local $iWidth = DllStructGetData($stWinPos, 5)
            Local $iHeight = DllStructGetData($stWinPos, 6)
            ; Set drag limits
            Local $iX_Min = $aMain_Pos[0]
            Local $iY_Min = $aMain_Pos[1] + 24
            Local $iX_Max = $aMain_Pos[0] + $aMain_Pos[2] - $iWidth
            Local $iY_Max = $aMain_Pos[1] + $aMain_Pos[3] - $iHeight
            ; And reset them if passed
            If $iLeft < $iX_Min Then DllStructSetData($stWinPos, 3, $iX_Min)
            If $iLeft > $iX_Max Then DllStructSetData($stWinPos, 3, $iX_Max)
            If $iTop  < $iY_Min Then DllStructSetData($stWinPos, 4, $iY_Min)
            If $iTop  > $iY_Max Then DllStructSetData($stWinPos, 4, $iY_Max)
        Case $hGUI_Child_API
            ; Get position of child
            Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam)
            Local $iLeft = DllStructGetData($stWinPos, 3)
            Local $iTop = DllStructGetData($stWinPos, 4)
            Local $iWidth = DllStructGetData($stWinPos, 5)
            Local $iHeight = DllStructGetData($stWinPos, 6)
            ; Set drag limits
            Local $iX_Min = 0
            Local $iY_Min = 0
            Local $iX_Max = $aMain_Pos[2] - $iWidth
            Local $iY_Max = $aMain_Pos[3] - $iHeight
            ; And reset them if passed
            If $iLeft < $iX_Min Then DllStructSetData($stWinPos, 3, $iX_Min)
            If $iLeft > $iX_Max Then DllStructSetData($stWinPos, 3, $iX_Max)
            If $iTop  < $iY_Min Then DllStructSetData($stWinPos, 4, $iY_Min)
            If $iTop  > $iY_Max Then DllStructSetData($stWinPos, 4, $iY_Max)
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc   ;==>_WM_WINDOWPOSCHANGING

I was using the wrong coordinates. :>

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

johnmcloud,

Sorry, I missed your post. Well done for finding the solution yourself! :thumbsup:

And if you think I do not make many errors - check the number of edited posts I have! :D

M23

P.S. Have you worked out how to concatenate more than 2 arrays yet? ;)

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

johnmcloud,

I knew you would get it. ;)

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...