Jump to content

Child GUI as title bar


Recommended Posts

I wonder if it is possible to have a child GUI as a title bar.

I want to have a personalized title bar and what I can get is not going to help me.

Basically I want 3 buttons (in the place where the normal windows controls are) each of them displaying its own icon.

Here is a simple example of what I'm trying to achieve:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 471, 200, 192, 150, $WS_POPUPWINDOW, $WS_EX_CLIENTEDGE)
$Form2 = GUICreate("Form1", 471, 39, 0, 0, BitOr($WS_CHILD,$WS_TABSTOP),$WS_EX_CLIENTEDGE ,$Form1)
$Test = GUICtrlCreateLabel("Test Window Tile", 24, 12, 87, 17)
$Icon1 = GUICtrlCreateIcon("shell32.dll", -48, 352, 3, 32, 32)
GUICtrlSetOnEvent(-1, "Icon1Click")
$Icon2 = GUICtrlCreateIcon("shell32.dll", -46, 392, 3, 32, 32)
GUICtrlSetOnEvent(-1, "Icon2Click")
$Icon3 = GUICtrlCreateIcon("shell32.dll", -28, 432, 3, 32, 32)
GUICtrlSetOnEvent(-1, "Icon3Click")
GUISetState(@SW_SHOW)
GUISwitch($Form1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func Icon1Click()

EndFunc
Func Icon2Click()

EndFunc
Func Icon3Click()
    Exit
EndFunc

Basically I would like:

- to be able to use the child window as a title bar

- to make it resize with the parent

Any help is appreciated.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

It is possible I'm sure, but is there any particular reason the title bar has to be a child window?

Just so you know, this can be accomplished with a label and some buttons on one window. Something like this:

#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>

$hMain = GUICreate('', 300, 300, default, default, BitOR($WS_SIZEBOX, $WS_POPUPWINDOW), $WS_EX_CLIENTEDGE)
GUICtrlCreateLabel('Title bar', 0, 0, 240, 20, $SS_CENTERIMAGE, $GUI_WS_EX_PARENTDRAG)
    GUICtrlSetBkColor(-1, 0xff)
    GUICtrlSetColor(-1, 0xffffff)
    GUICtrlSetFont(-1, 9, 800)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKLEFT, $GUI_DOCKRIGHT, $GUI_DOCKHEIGHT))
GUICtrlCreateButton('0', 240, 0, 20, 20)
    GUICtrlSetFont(-1, 8, 0, 0, 'Marlett')
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKRIGHT, $GUI_DOCKSIZE))
GUICtrlCreateButton('1', 260, 0, 20, 20)
    GUICtrlSetFont(-1, 8, 0, 0, 'Marlett')
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKRIGHT, $GUI_DOCKSIZE))
$bt_Close = GUICtrlCreateButton('r', 280, 0, 20, 20)
    GUICtrlSetFont(-1, 8, 0, 0, 'Marlett')
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKMENUBAR, $GUI_DOCKRIGHT, $GUI_DOCKSIZE))
GUICtrlCreateEdit('Hello!', 0, 20, 300, 280)
    GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)

GUISetState(@SW_SHOW, $hMain)

While 1
    $gm = GUIGetMsg()
    Switch $gm
        Case $bt_Close, $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

If you still require it to be a child window then I think you're going to have to hook into some of the windows events (WM_SIZE for sure, maybe WM_MOVE) and it's going to be a little more complicated. I haven't quite worked it out yet, but I'm sure it's doable.

Link to comment
Share on other sites

Thanks alot for the reply.

I did myself a similar thing before deciding to make my window resizeable. I have used a label and a smaller child GUI (just to hold the icons), as long as I didn't try to resize the window, everything is fine but once I started resizing, the child GUI didn't move and it ended up covered by the label.

You can see in my screenshot what my GUI looks like:

I had to use a child because I couldn't get a consistent view (the background of the title label is different than the GUI's background and by simply using some icons it didn't work; also, icons on top of the label didn't work too ...

My last resort will be to place the child on the left of the parent window ... but it will look crappy :idea:

post-18882-12730236449293_thumb.jpg

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Maybe something like this mod to your first example.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 471, 200, 192, 150, BitOr($WS_SIZEBOX,$WS_POPUPWINDOW), $WS_EX_CLIENTEDGE)
$Form2 = GUICreate("Form1", 471, 39, 0, 0, BitOr($WS_CHILD,$WS_TABSTOP),$WS_EX_CLIENTEDGE ,$Form1)
GUISetBkColor(0x0000ff)
$Test = GUICtrlCreateLabel("Test Window Tile", 24, 12, 87, 17)
GUICtrlSetResizing(-1,$GUI_DOCKLEFT+$GUI_DOCKWIDTH)
GUICtrlSetBkColor(-1,0x0000FF)
$Icon1 = GUICtrlCreateIcon("shell32.dll", -48, 352, 3, 32, 32)
GUICtrlSetResizing(-1,$GUI_DOCKRIGHT+$GUI_DOCKWIDTH)
GUICtrlSetOnEvent(-1, "Icon1Click")
$Icon2 = GUICtrlCreateIcon("shell32.dll", -46, 392, 3, 32, 32)
GUICtrlSetResizing(-1,$GUI_DOCKRIGHT+$GUI_DOCKWIDTH)
GUICtrlSetOnEvent(-1, "Icon2Click")
$Icon3 = GUICtrlCreateIcon("shell32.dll", -28, 432, 3, 32, 32)
GUICtrlSetResizing(-1,$GUI_DOCKRIGHT+$GUI_DOCKWIDTH)
GUICtrlSetOnEvent(-1, "Icon3Click")
GUISetState(@SW_SHOW)
GUISwitch($Form1)
GUISetState(@SW_SHOW)
$p = wingetpos($Form1)
$c = WinGetPos($Form2)
$deltaWid = $p[2] - $c[2]
#EndRegion ### END Koda GUI section ###



GUIRegisterMsg($WM_SIZE,"ResizeChild")
While 1
    Sleep(100)
WEnd

Func Icon1Click()

EndFunc
Func Icon2Click()

EndFunc
Func Icon3Click()
    Exit
EndFunc

Func ResizeChild($hW,$im,$wp,$lp)
    if $hW <> $Form1 then Return
    Local $p = wingetpos($Form1)
    Local $c = wingetpos($Form2)
    if $p[2] -$deltaWid = $c[2] then Return

    winmove($Form2,"",0,0,$p[2]-$deltaWid)

EndFunc
Edited by martin
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.
Link to comment
Share on other sites

@martin

Thanks alot for this idea :idea:

Been thinking to do the same but didn't dig too deep into this. It is definitely a good solution to solve the resize issue.

It looks more and more likely that using a child window as a title bar is not going to work (at least not easy to accomplish) - it is OK for resizing and displaying buttons and such but fails when it comes to move both windows.

Anyway - I still have a workaround thanks to your idea :)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

@martin

Thanks alot for this idea :idea:

Been thinking to do the same but didn't dig too deep into this. It is definitely a good solution to solve the resize issue.

It looks more and more likely that using a child window as a title bar is not going to work (at least not easy to accomplish) - it is OK for resizing and displaying buttons and such but fails when it comes to move both windows.

Anyway - I still have a workaround thanks to your idea :)

You can make the child behave like a title bar as far as dragging is concerned in various ways. Here is one way.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 471, 200, 192, 150, BitOR($WS_SIZEBOX, $WS_POPUPWINDOW), $WS_EX_CLIENTEDGE)
$Form2 = GUICreate("Form1", 471, 39, 0, 0, BitOR($WS_CHILD, $WS_TABSTOP), $WS_EX_CLIENTEDGE, $Form1)
GUISetBkColor(0x0000ff)
$Test = GUICtrlCreateLabel("Test Window Tile", 24, 12, 87, 17)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKWIDTH)
GUICtrlSetBkColor(-1, 0x0000FF)
$Icon1 = GUICtrlCreateIcon("shell32.dll", -48, 352, 3, 32, 32)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKWIDTH)
GUICtrlSetOnEvent(-1, "Icon1Click")
$Icon2 = GUICtrlCreateIcon("shell32.dll", -46, 392, 3, 32, 32)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKWIDTH)
GUICtrlSetOnEvent(-1, "Icon2Click")
$Icon3 = GUICtrlCreateIcon("shell32.dll", -28, 432, 3, 32, 32)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKWIDTH)
GUICtrlSetOnEvent(-1, "Icon3Click")
GUISetState(@SW_SHOW)
GUISwitch($Form1)
GUISetState(@SW_SHOW)
$p = WinGetPos($Form1)
$c = WinGetPos($Form2)
$deltaWid = $p[2] - $c[2]
#endregion ### END Koda GUI section ###



GUIRegisterMsg($WM_SIZE, "ResizeChild")
;GuiRegisterMsg($GUI_EVENT_PRIMARYDOWN,"TrachParent")
GUIRegisterMsg($WM_NCHITTEST, "TrackParent")
While 1
    Sleep(100)
WEnd

Func Icon1Click()

EndFunc ;==>Icon1Click
Func Icon2Click()

EndFunc ;==>Icon2Click
Func Icon3Click()
    Exit
EndFunc ;==>Icon3Click

Func ResizeChild($hW, $im, $wp, $lp)
    If $hW <> $Form1 Then Return
    Local $p = WinGetPos($Form1)
    Local $c = WinGetPos($Form2)
    If $p[2] - $deltaWid = $c[2] Then Return

    WinMove($Form2, "", 0, 0, $p[2] - $deltaWid)

EndFunc ;==>ResizeChild

Func TrackParent($hWnd, $iMsg, $iwParam, $ilParam)
    If $hWnd = $Form1 Then Return $GUI_RUNDEFMSG
    Local $id = _API_DefWindowProc($hWnd, $iMsg, $iwParam, $ilParam)
    If $id = 1 Or $id = $Test Then
    DllCall("user32.dll", "long", "SendMessage", "hwnd", $Form1, "int", $WM_SYSCOMMAND, "int", 0xF012, "int", 0)
    EndIf

EndFunc ;==>TrackParent

Func _API_DefWindowProc($hWnd, $iMsg, $iwParam, $ilParam)
    Local $aResult

    $aResult = DllCall("User32.dll", "int", "DefWindowProc", "hwnd", $hWnd, "int", $iMsg, "int", $iwParam, "int", $ilParam)
    Return $aResult[0]
EndFunc ;==>_API_DefWindowProc

You can also use the method in this post to resize $Form1 without the $WS_EX_CLIENTEDGE, and then you could thin blue lables or pics around the edge of $Form1 to look like a border. But maybe you should be looking at EZSkin?

Edited by martin
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.
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...