Jump to content

Recommended Posts

Posted (edited)

I've seen some widgets in this forum but I wanted something simple (e.g. for RSS) and, while playing with the help file, I came up with this:

#NoTrayIcon
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#Include <WinAPI.au3>
#include <Constants.au3>

AutoItSetOption("GUICloseOnESC",0);disable ESC; use the icon to exit
Global $hGUI, $Edit

_Widget_Create(200,300)

Func _Widget_Create($iW=200,$iH=200)
    If $iW<200 Or $iH<200 Then
        MsgBox(0,"Frendly warning...","Please choose dimensions above 200!")
        Exit
    EndIf
    ;create GUI
    $hGUI = GUICreate("", $iW, $iH, @DesktopWidth - $iW-10, (@DesktopHeight - $iH)/2, BitOR($WS_SYSMENU,$WS_POPUP), BitOR($WS_EX_TOOLWINDOW,$WS_EX_LAYERED))
    GUISetBkColor(0x000000)
    ;create icons for resize, config and close
    Local $hResize = GUICtrlCreateIcon("shell32.dll", -44, 6, 6, 16, 16)
    GUICtrlSetTip(-1, "Minimize or" & @CRLF & "maximize" & @CRLF & "widget","Widget",1,1)
    GUICtrlSetCursor (-1, 0)

    Local $hConfig = GUICtrlCreateIcon("shell32.dll", -166, 42, 6, 16, 16)
    GUICtrlSetTip(-1, "Configuration","Widget",1,1)
    GUICtrlSetCursor (-1, 0)

    Local $hExit = GUICtrlCreateIcon("shell32.dll", -132, $iW-20, 6, 16, 16)
    GUICtrlSetTip(-1, "Close","Widget",1,1)
    GUICtrlSetCursor (-1, 0)
    ;put some controls in it
    ;label:
    Local $Label = GUICtrlCreateLabel("Name:", 8, 48, 70, 20)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    GUICtrlSetColor(-1, 0xDDDD00)

    Local $Input = GUICtrlCreateInput("Input", $iW - 120, 45, 110, 20)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetBkColor(-1, 0x0000EE)

    $Edit = GUICtrlCreateEdit("", 8, 95, $iW - 16, 100, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_VSCROLL), 0)
    Local $randtext
    For $z = 1 To 20
        $randtext &= "This is line no." & $z & @CRLF
    Next
    GUICtrlSetData(-1, $randtext)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    GUICtrlSetColor(-1, 0xFFFF00)
    GUICtrlSetBkColor(-1, 0x363636)

    Local $Button1 = GUICtrlCreateButton("Test", 8, 220, 40, 20)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    GUICtrlSetBkColor(-1, 0xC0C0C0)
    Local $Button2 = GUICtrlCreateButton("Coffee", $iW-48, 220, 40, 20)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    GUICtrlSetBkColor(-1, 0xC0DCC0)

    ;this is for dragging the gui
    Local $hPic = GUICtrlCreatePic("", 1, 1, $iW-2, $iH-2, BitOR($GUI_SS_DEFAULT_PIC,$SS_CENTERIMAGE,$WS_BORDER), BitOR($WS_EX_STATICEDGE,$GUI_WS_EX_PARENTDRAG))
    WinSetTrans($hGUI,"",150)
    GUISetState(@SW_SHOW)
    While 1
        Sleep(10)
        Switch GUIGetMsg()
            Case $hExit
                Exit
            Case $Button1
                GUICtrlSetData($Input,"First button pressed")
            Case $Button2
                _Button2()
            Case $hConfig
                _Config()
            Case $hResize
                Local $wigWidth = _WinAPI_GetWindowWidth($hGUI)
                Local $pos = WinGetPos($hGUI)
                Local $a, $b, $n
                If $iH>$iW Then
                    $a = $iH
                    $b = $iW
                Else
                    $a = $iW
                    $b = $iH
                EndIf
                $n = $a - $b
                If $a=$b Then $n = $a/2
                Switch $wigWidth
                    Case $iW
                        For $i = 0 To $n Step 10
                        _WinAPI_SetWindowPos($hGUI, $HWND_TOP, $pos[0] + $i, $pos[1], $iW - $i, $iH - 1.5*$i, $SWP_NOZORDER)
                    Next
                    Case ($iW - $n)
                        For $i = 0 To $n Step 10
                        _WinAPI_SetWindowPos($hGUI, $HWND_TOP, $pos[0] - $i, $pos[1], $iW + $i - $n, $iH + $i - $n, $SWP_NOZORDER)
                        Next
                EndSwitch
                Sleep(50)
        EndSwitch
    WEnd
EndFunc

Func _Config()
    Local $iW, $iH, $hWnd
    $iW=200
    $iH=200
    ;create Config GUI
    Local $pos = WinGetPos($hGUI)
    If $pos[0]-$iW>0 Then
        $hWnd = GUICreate("", $iW, $iH, $pos[0] - $iW, $pos[1], BitOR($WS_SYSMENU,$WS_POPUP), $WS_EX_LAYERED)
    Else
        $hWnd = GUICreate("", $iW, $iH, $pos[0] + $pos[2], $pos[1], BitOR($WS_SYSMENU,$WS_POPUP), $WS_EX_LAYERED)
    EndIf

    GUISetBkColor(0x000000)
    ;create icon for close
    Local $hExit = GUICtrlCreateIcon("shell32.dll", -216, $iW-20, 6, 16, 16)
    GUICtrlSetTip(-1, "Close the configuration","Widget",1,1)
    GUICtrlSetCursor (-1, 0)
    ;put some controls in it
    Global $Label1 = GUICtrlCreateLabel("Here put some controls to configure this widget" & @CRLF & _
                                        "(run at startup, remember position, tray icon, read/write from/to INI etc, etc.)" & @CRLF & @CRLF & _
                                        "It's my choice!...", 8, 35, $iW - 16, $iH - 70, BitOR($SS_CENTER,$WS_BORDER))
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    GUICtrlSetColor(-1, 0xFFFF00)

    GUICtrlCreatePic("", 1, 1, $iW-2, $iH-2, BitOR($GUI_SS_DEFAULT_PIC,$SS_CENTERIMAGE,$WS_BORDER), BitOR($WS_EX_STATICEDGE,$GUI_WS_EX_PARENTDRAG))
    WinSetTrans($hWnd,"",150)
    GUISetState(@SW_SHOW)
    While 1
        Sleep(10)
        Switch GUIGetMsg()
            Case $hExit
                GUIDelete($hWnd)
                Return
        EndSwitch
    WEnd
EndFunc

Func _Button2()
    GUICtrlSetData($Edit,"Intravenously, intramuscularly or cup?")
EndFunc

It works well, but I was wondering how can configuration window be docked with the main widget window when I move it? (Something like winamp playlist)

Maybe the answer is simple, but I can't figure it out   :blink:

Thanks in advance!

Edited by taietel
Posted (edited)

taietel,

Check this forum link and do a forum search on some keywords like dockable windows, dock gui and others to find more examples to help you figure out a solution.

jfcby

Edited by jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Posted

jfcby, thanks for the link!

Gary's function for docking isn't quite of what I want (in that function, the windows docking is delayed), BUT it's a great start. I'm already working on it and I'll get back.

Regards,

M.Iancu

Posted

In AMT I use these functions to attach the child GUIs.

Func On_WM_MOVING($hWnd, $Msg, $wParam, $lParam)
    If $hWnd = $gui_main Then
        _Move_attached_GUIs()
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>On_WM_MOVING

Func On_WM_EXITSIZEMOVE($hWnd, $Msg, $wParam, $lParam)
    If $hWnd <> $gui_main Then
        _Move_attached_GUIs()
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>On_WM_EXITSIZEMOVE

where the _Move_attached_GUIs() function contains the movement instructions relative to the main GUI.

Posted

Thanks KaFu, but I didn't found the AMT. The page was suspended...

I guess I will just live it like this (it doesn't hurts!  :blink: ):

#NoTrayIcon
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#Include <WinAPI.au3>
#include <Constants.au3>
#include <Misc.au3>

Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
Opt("TrayIconHide", 1)
AutoItSetOption("GUICloseOnESC",0);disable ESC; use the icon to exit

Global $hGUI, $hWnd, $Edit, $wW, $wH, $wfW, $wfH, $sX, $sY, $sW, $sH, $sR, $sRemPos, $mTray, $mTrayX, $hExit
Global $f_Config = @ScriptDir & "\config.ini"
_Tray()
_Startup()
_Widget_CreateGUI($wW,$wH,$wfW,$wfH)
If @error Then Exit

Func _Widget_CreateGUI($iW=200,$iH=200,$fW=100,$fH=150)
    ;$iW = Widget width
    ;$iH = Widget height
    ;$fW = Widget width minimized
    ;$fH = Widget height minimized

    ;create GUI
    $hGUI = GUICreate("", $iW, $iH, @DesktopWidth - $iW-10, (@DesktopHeight - $iH)/2, BitOR($WS_SYSMENU,$WS_POPUP), BitOR($WS_EX_TOOLWINDOW,$WS_EX_LAYERED))
    GUISetBkColor(0x000000)
    ;create icons for resize, config and close
    Local $hResize = GUICtrlCreateIcon("shell32.dll", -44, 6, 6, 16, 16)
    GUICtrlSetTip(-1, "Minimize or" & @CRLF & "maximize" & @CRLF & "widget","Widget",1,1)
    GUICtrlSetCursor (-1, 0)

    Local $hConfig = GUICtrlCreateIcon("shell32.dll", -166, 42, 6, 16, 16)
    GUICtrlSetTip(-1, "Configuration","Widget",1,1)
    GUICtrlSetCursor (-1, 0)

    Local $hTray = GUICtrlCreateIcon("shell32.dll", -177, 80, 6, 16, 16)
    GUICtrlSetTip(-1, "Minimize to tray","Widget",1,1)
    GUICtrlSetCursor (-1, 0)

    Local $hExit = GUICtrlCreateIcon("shell32.dll", -132, $iW-20, 6, 16, 16)
    GUICtrlSetTip(-1, "Close","Widget",1,1)
    GUICtrlSetCursor (-1, 0)

    ;this is for dragging the gui
    GUICtrlCreatePic("", 1, 1, $iW-2, $iH-2, BitOR($GUI_SS_DEFAULT_PIC,$SS_CENTERIMAGE,$WS_BORDER), BitOR($WS_EX_STATICEDGE,$GUI_WS_EX_PARENTDRAG))
    WinSetTrans($hGUI,"",150)
    _WinAPI_SetWindowPos($hGUI, $HWND_TOP, $sX, $sY, $sW, $sH, $SWP_NOZORDER)
    GUISetState(@SW_SHOW)
    While 1
        Sleep(10)
        Switch GUIGetMsg()
            Case $hExit
                _RememberPos(IniRead($f_Config,"Config","RememberPosition",""))
                Exit
            Case $hTray
                _MinimizeToTray()
            Case $hConfig
                GUICtrlSetTip($hExit, "First close" & @CRLF & "the Configuration" & @CRLF & "window","Widget",1,1)
                _Config()
                WinWaitClose($hWnd)
                GUICtrlSetTip($hExit, "Close","Widget",1,1)
            Case $hResize
                Local $wigWidth = _WinAPI_GetWindowWidth($hGUI)
                Local $pos = WinGetPos($hGUI)
                Local $a, $b, $n
                If $iH>$iW Then
                    $a = $iH
                    $b = $iW
                Else
                    $a = $iW
                    $b = $iH
                EndIf
                $n = $a - $b
                If $a=$b Then $n = $a/2
                Switch $wigWidth
                    Case $iW
                        _WinAPI_SetWindowPos($hGUI, $HWND_TOP, $pos[0]+$fW, $pos[1], $fW, $fH, $SWP_DRAWFRAME)
                    Case ($iW - $n)
                        _WinAPI_SetWindowPos($hGUI, $HWND_TOP, $pos[0]-$fW, $pos[1], $iW, $iH, $SWP_NOZORDER)
                EndSwitch
                Sleep(50)
        EndSwitch
    WEnd
EndFunc
;INTERNAL USE ONLY
Func _Config()
    Local $iW, $iH
    $iW=200
    $iH=200
    ;create Config GUI
    Local $pos = WinGetPos($hGUI)
    If $pos[0]-$iW>0 Then
        $hWnd = GUICreate("", $iW, $iH, $pos[0] - $iW, $pos[1], BitOR($WS_SYSMENU,$WS_POPUP), $WS_EX_LAYERED)
    Else
        $hWnd = GUICreate("", $iW, $iH, $pos[0] + $pos[2], $pos[1], BitOR($WS_SYSMENU,$WS_POPUP), $WS_EX_LAYERED)
    EndIf

    GUISetBkColor(0x000000)
    ;create icon for close
    Local $hExitc = GUICtrlCreateIcon("shell32.dll", -216, $iW-20, 6, 16, 16)
    GUICtrlSetTip(-1, "Close the configuration","Widget",1,1)
    GUICtrlSetCursor (-1, 0)
    ;put some controls in it
    GUICtrlCreateLabel("Here put some controls to configure this widget" & @CRLF & _
                                        "(run at startup, remember position, tray icon, read/write from/to INI etc, etc.)" & @CRLF & @CRLF & _
                                        "It's my choice!...", 8, 35, $iW - 16, $iH - 70, BitOR($SS_CENTER,$WS_BORDER))
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    GUICtrlSetColor(-1, 0xFFFF00)

    XPStyleToggle(1);turn xp themes off
    Local $bRemPos = GUICtrlCreateCheckbox("Remember position",8,$iH-45,120,20)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    GUICtrlSetColor(-1, 0xFFFF88)
    GUICtrlSetState($bRemPos,$sRemPos)

    Local $bStartup = GUICtrlCreateCheckbox("Run at Startup",8,$iH-25,100,20)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    GUICtrlSetColor(-1, 0xFFFF88)
    GUICtrlSetState($bStartup,$sR)
    XPStyleToggle(0);turn XP themes on again

    GUICtrlCreatePic("", 1, 1, $iW-2, $iH-2, BitOR($GUI_SS_DEFAULT_PIC,$SS_CENTERIMAGE,$WS_BORDER), BitOR($WS_EX_STATICEDGE,$GUI_WS_EX_PARENTDRAG))
    WinSetTrans($hWnd,"",150)
    GUISetState(@SW_SHOW)
    Local $pw1 = WinGetPos($hGUI)
    Local $pw2 = WinGetPos($hWnd)
    Local $dif = $pw1[0] - $pw2[2]
    While 1
        Sleep(10)
        Switch GUIGetMsg()
            Case $hExitc
                GUIDelete($hWnd)
                Return
            Case $bRemPos
                Switch GUICtrlRead($bRemPos)
                    Case 1
                        _RememberPos(1)
                    Case 4
                        _RememberPos(0)
                EndSwitch
            Case $bStartup
                Local $bSt = GUICtrlRead($bStartup)
                If $bSt = 1 Then
                    FileCreateShortcut(@ScriptFullPath, @StartupCommonDir & "\" & @ScriptName & ".lnk")
                ElseIf $bSt = 4 Then
                    FileDelete(@StartupCommonDir & "\" & @ScriptName & ".lnk")
                Else
                EndIf
                IniWrite(@ScriptDir & "\config.ini","Config","RunAtStartup",$bSt)
            Case ($dif <> $pw2[0]  And BitAND(WinGetState($hGUI),8))
                _MoveWindows()
        EndSwitch
    WEnd
EndFunc

Func _MoveWindows()
    Local $p1 = WinGetPos($hGUI)
    Local $p2 = WinGetPos($hWnd)
    If ($p1[0]-$p2[2])<0 Then
        WinMove($hWnd,"",$p1[0]+$p1[2]+1,$p1[1],$p2[2],$p2[3],3)
    Else
        WinMove($hWnd,"",$p1[0]-$p2[2],$p1[1],$p2[2],$p2[3],3)
    EndIf
EndFunc

Func _Startup()
    If Not FileExists($f_Config) Then
        Local $ft = FileOpen($f_Config,2)
        Local $sText = "[Config]" & @CRLF
        $sText &= "WidgetW=200" & @CRLF
        $sText &= "WidgetH=300" & @CRLF
        $sText &= "WidgetMinW=100" & @CRLF
        $sText &= "WidgetMinH=150" & @CRLF
        $sText &= "StartupX=" & (@DesktopWidth - 110) & @CRLF
        $sText &= "StartupY=" & (@DesktopHeight - 150)/2 & @CRLF
        $sText &= "StartupW=100" & @CRLF
        $sText &= "StartupH=150" & @CRLF
        $sText &= "RunAtStartup=4" & @CRLF
        $sText &= "RememberPosition=1" & @CRLF
        FileWrite($ft,$sText)
        FileClose($ft)
    EndIf
        $wW = IniRead($f_Config,"Config","WidgetW","200")
        $wH = IniRead($f_Config,"Config","WidgetH","300")
        $wfW = IniRead($f_Config,"Config","WidgetMinW","100")
        $wfH = IniRead($f_Config,"Config","WidgetMinH","150")
        $sX = IniRead($f_Config,"Config","StartupX",@DesktopWidth - 110)
        $sY = IniRead($f_Config,"Config","StartupY",(@DesktopHeight - 150)/2)
        $sW = IniRead($f_Config,"Config","StartupW","100")
        $sH = IniRead($f_Config,"Config","StartupH","150")
        $sR = IniRead($f_Config,"Config","RunAtStartup","4")
        $sRemPos = IniRead($f_Config,"Config","RememberPosition","1")
EndFunc

Func _RememberPos($rp)
    Local $pos = WinGetPos($hGUI)
    Switch $rp
        Case 1
            IniWrite($f_Config,"Config","StartupX",$pos[0])
            IniWrite($f_Config,"Config","StartupY",$pos[1])
            IniWrite($f_Config,"Config","StartupW",$pos[2])
            IniWrite($f_Config,"Config","StartupH",$pos[3])
            IniWrite($f_Config,"Config","RememberPosition","1")
        Case 0
            IniWrite($f_Config,"Config","RememberPosition","0")
        Case Else
            MsgBox(48,"Error","Invalid option!")
    EndSwitch
EndFunc

Func XPStyleToggle($Off = 1)
    ;Thanks to Martin (http://www.autoitscript.com/forum/index.php?showtopic=89319&view=findpost&p=641878)
    ;and jfcby for point me to that post
    Local $XS_n
     If Not StringInStr(@OSTYPE, "WIN32_NT") Then Return 0
     If $Off Then
        $XS_n = DllCall("uxtheme.dll", "int", "GetThemeAppProperties")
         DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
         Return 1
     ElseIf IsArray($XS_n) Then
         DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", $XS_n[0])
         $XS_n = ""
         Return 1
     EndIf
     Return 0
 EndFunc

 Func _Tray()
    TraySetIcon("", -1)
    TraySetClick("16")
    $mTray = TrayCreateItem("&Show the widget")
    TrayItemSetOnEvent($mTray, "_Tray_ShowGUI")
    TrayCreateItem("")
    Local $mTrayX = TrayCreateItem("&Exit")
    TrayItemSetOnEvent($mTrayX, "_Tray_Exit")
EndFunc

Func _Tray_ShowGUI()
    TrayItemSetState($mTray, 4)
    GUISetState(@SW_SHOWNORMAL, $hGUI)
    Opt("TrayIconHide", 1)
EndFunc

Func _Tray_Exit()
    TrayItemSetState($mTrayX, 4)
    Local $iMsgBoxAnswer = MsgBox(36, "Widget", "Are you sure?")
    Select
        Case $iMsgBoxAnswer = 6 ;Da
            GUIDelete()
            Exit
        Case $iMsgBoxAnswer = 7 ;Nu
    EndSelect
EndFunc

Func _MinimizeToTray()
    GUISetState(@SW_HIDE, $hGUI)
    TraySetIcon("shell32.dll", -14)
    Opt("TrayIconHide", 0)
    TraySetToolTip("Right-Click for menu")
    TrayTip("I'm here! - Widget © 2010", "If you need me, I'm just a right-click away!",1,1)
    Sleep(2000)
    TrayTip("Clear","",1,1)
EndFunc

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
×
×
  • Create New...