Jump to content

Can I lock child window to it's parent - creating customized tabs.


Recommended Posts

When I create window then coordinates 0,0 will create it at left top of parent window. But when I use WinMove() to move it to coordinates 0,0 then it's absolute coordinates will be 0,0.

I played with different window styles and opt() but WinMove() still uses absolute coordinates. Is there way to make child window act like control (moving it to 0,0 would move it to top left corner of client area instead of absoulute coordinates).

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 377, 321, 192, 124)
GUISetState(@SW_SHOW)
$child  = GUICreate("", 100, 20, 0, 0, 0x80000000, 0x00000040, $Form1)
GUISetBkColor(0xff)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Sleep(1000)
WinMove($child,"",0,100)

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

    EndSwitch
WEnd

edit: copied style and exstyle from button and this way it worked.

Problem is that this way child images on child window randomly don't get drawn

What I have is:

1) GUI

2) background image covers whole GUI

2)other image on BG image.

Edited by E1M1

edited

Link to comment
Share on other sites

Like this >>

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

Global $aWinGetPos, $hChild, $hGUI

$hGUI = GUICreate("GUI Example", 377, 321, 192, 124)
$hChild = GUICreate("", 100, 20, 0, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0xff)
GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hChild)

Sleep(1000)
$aWinGetPos = WinGetPos($hGUI)
WinMove($hChild, "", ($aWinGetPos[0] + 2.5) + 0, $aWinGetPos[1] + 100)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Here's my full code.

Problem: when you click "remove tab" all tabs get's moved to 0,0 by absolute coordinates.

When you set tab's style to 0x50030001 then "remove tab" button works the way it should work but image that displays plugins.bmp doesn't draw.

and when you click on tab, it doesn't get selected.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Winapi.au3>
#include <array.au3>
$iTab = 0
Dim $tabsdata[1][8]
$GUI = GUICreate("Form1", 500, 300, 192, 124)
$add = GUICtrlCreateButton("Add tab",0,100)
$remove = GUICtrlCreateButton("Remove tab",100,100)
GUISetState(@SW_SHOW)
GUIRegisterMsg(0x0006, "ClickHandler")

while 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case -3
            Exit
        Case $add
            AddTab()
        Case $remove
            removeTab()
    EndSwitch
WEnd

Func ClickHandler($hWnd, $Msg, $wParam, $lParam)
    If $hWnd <> $GUI Then
        For $i = 0 To UBound($tabsdata) - 1
            If $hWnd = $tabsdata[$i][5] Then
                ConsoleWrite("Click Handler activating tab:" & $i & @CRLF)
                GUICtrlSetImage($tabsdata[$iTab][6], @scriptdir & "\normal.bmp")
                GUICtrlSetImage($tabsdata[$i][6], @scriptdir & "\active.bmp")
                $iTab = $i
            EndIf
        Next
    EndIf
    _SendMessage($GUI, 0x0006)
EndFunc   ;==>ClickHandler

Func AddTab()
    If StringLen($tabsdata[UBound($tabsdata) - 1][0]) > 0 Then
        ReDim $tabsdata[UBound($tabsdata) + 1][8]
    EndIf
    If UBound($tabsdata) > 1 Then
        GUICtrlSetImage($tabsdata[$iTab][6], @scriptdir & "\normal.bmp")
    EndIf
    $tabsdata[UBound($tabsdata) - 1][0] = UBound($tabsdata) - 1
    $tabsdata[UBound($tabsdata) - 1][5] = GUICreate("", 100, 20, (UBound($tabsdata) - 1) * 100, 0, 0x80000000, 0x00000040, $GUI)
    $tabsdata[UBound($tabsdata) - 1][6] = GUICtrlCreatePic(@scriptdir & "\active.bmp", 0, 0, 100, 20, $GUI_DISABLE, $GUI_WS_EX_PARENTDRAG)
    $tabsdata[UBound($tabsdata) - 1][7] = GUICtrlCreatePic(@scriptdir & "\plugins.bmp", 77, 3, 16, 16, BitOR($SS_NOTIFY, $GUI_ONTOP))
    GUICtrlCreateLabel("Tab " & $tabsdata[UBound($tabsdata) - 1][0], 5, 3, 75, 17)
    GUICtrlSetBkColor(-1, -2)
    $rgn1 = _WinAPI_CreateRoundRectRgn(0, 0, 101, 20, 7, 7) ; left-top
    $rgn2 = _WinAPI_CreateRectRgn(0, 10, 100, 20) ; right-top
    _WinAPI_CombineRgn($rgn1, $rgn1, $rgn2, $RGN_OR)
    _WinAPI_DeleteObject($rgn2)
    _WinAPI_SetWindowRgn($tabsdata[UBound($tabsdata) - 1][5], $rgn1)
    GUISetState()
    $iTab = UBound($tabsdata) - 1

    GUISwitch($GUI)
EndFunc   ;==>AddTab

;Controlled tab removal
Func removeTab()
    If StringLen($tabsdata[UBound($tabsdata) - 1][0]) > 0 Then

        GUIDelete($tabsdata[$iTab][5])
        _ArrayDelete($tabsdata, $iTab)

        If Not IsArray($tabsdata) Then
            ResetVars()
            Return
        EndIf

        TabsDefragment()

        $iTab -= 1
        If $iTab = -1 Then $iTab = UBound($tabsdata) - 1
        GUICtrlSetImage($tabsdata[$iTab][6], @scriptdir & "\active.bmp")

        For $i = 0 To UBound($tabsdata) - 1
            WinMove($tabsdata[$i][5],"",$i*100,0)
        Next

    EndIf
EndFunc   ;==>removeTab

Func TabsDefragment()
    For $i = 0 To UBound($tabsdata, 1) - 1
        $tabsdata[$i][0] = $i
    Next
EndFunc   ;==>TabsDefragment

Func ResetVars()
    $iTab = 0
    Dim $tabsdata[1][8];Tabs (captured)
EndFunc   ;==>ResetVars

Edit: this calculation makes it draw tabs on window border.

For $i = 0 To UBound($tabsdata) - 1
            $ParentPos = WinGetPos($GUI)
            $MePos = WinGetPos($tabsdata[$i][5])
            WinMove($tabsdata[$i][5],"",$ParentPos[0]+($i*100),$MePos[1])
        Next

Edit: this algorithm is better but still bugy

For $i = ($iTab +1) To UBound($tabsdata) - 1
            $MePos = WinGetPos($tabsdata[$i][5])
            WinMove($tabsdata[$i][5],"",$MePos[0]-100,$MePos[1])
        Next

Solution (probable)

Func removeTab($bRelease = False)
;~  MsgBox(0,0,0)
    If StringLen($tabsdata[UBound($tabsdata) - 1][0]) > 0 Then

        GUIDelete($tabsdata[$iTab][5])
        _ArrayDelete($tabsdata, $iTab)

        If Not IsArray($tabsdata) Then
            ResetVars()
            Return
        EndIf

        TabsDefragment()

        $oldTab = $iTab
        $iTab -= 1
        If $iTab = -1 Then $iTab = UBound($tabsdata) - 1
        GUICtrlSetImage($tabsdata[$iTab][6], @TempDir & "\active.bmp")

        For $i = $oldTab To UBound($tabsdata) - 1
            $MePos = WinGetPos($tabsdata[$i][5])
            WinMove($tabsdata[$i][5],"",$MePos[0]-100,$MePos[1])
        Next

    EndIf
EndFunc   ;==>removeTab

Image files attached to topic:

gui.zip

Edited by E1M1

edited

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