Jump to content
KF5WGB

Shrink GUI from top down not bottom up

Recommended Posts

Hi,

When resizing/shrinking an existing GUI, WinMove does it from the bottom up, loosing whats on top. How do I reverse that. In other words, I want the top part of the GUI stay as it is and the bottom part "shrunk".
Run my little script and hit F5 (Hide/Show SolarData) and you see what I mean. The bottom with the picture now overlays the top (shrunk up). If you run the script without Internet connection you do not see the pic and you can not resize the GUI. That is what I want it to show when F5 is pressed AND internet connection is available.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <INet.au3>

Opt("TrayIconHide", 1) ;0=show, 1=hide tray icon

HotKeySet("{F5}", "_HideSolarDasta")

Global $Solarwindow = 1, $MainWindow, $nMsg

#Region ### START Koda GUI section ### Form=IC-7300
$MainWindow = GUICreate("IC-7300 Time Sync & Memory Keyer", 425, 269, -1, -1, $GUI_SS_DEFAULT_GUI, BitOR($WS_EX_TOPMOST,$WS_EX_TRANSPARENT,$WS_EX_WINDOWEDGE))
;$MainWindow = GUICreate("IC-7300 Time Sync & Memory Keyer", 425, 269, -1, -1, $GUI_SS_DEFAULT_GUI, BitOR($WS_EX_TRANSPARENT,$WS_EX_WINDOWEDGE))
GUISetBkColor(0xA0A0A4)
;GUISetBkColor(0xFFFFFF)
$coded = GUICtrlCreateLabel("Coded by", 242, 88, 96, 28)
GUICtrlSetFont(-1, 12, 00, 0, "Comic Sans MS")
$KF5WGB = GUICtrlCreateLabel("KF5WGB", 242, 108, 96, 28)
GUICtrlSetFont(-1, 12, 200, 0, "Comic Sans MS")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "Goto KF5WGB's QRZ page")

$Transmit1 = GUICtrlCreateButton("TX1", 20, 14, 49, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_TOP,$BS_FLAT))
GUICtrlSetFont($Transmit1, 12, 400, 0, "Arial")
GUICtrlSetCursor (-1, 0)
;GUICtrlSetState($Transmit1, $Gui_Disable)
GUICtrlSetTip(-1, "Transmit recording from slot 1")

$Transmit2 = GUICtrlCreateButton("TX2", 99, 14, 49, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_TOP,$BS_FLAT))
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetCursor (-1, 0)
;GUICtrlSetState($Transmit2, $Gui_Disable)
GUICtrlSetTip(-1, "Transmit recording from slot 2")

$Transmit3 = GUICtrlCreateButton("TX3", 178, 14, 49, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_TOP,$BS_FLAT))
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetCursor (-1, 0)
;GUICtrlSetState($Transmit3, $Gui_Disable)
GUICtrlSetTip(-1, "Transmit recording from slot 3")

$Transmit4 = GUICtrlCreateButton("TX4", 257, 14, 49, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_TOP,$BS_FLAT))
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetCursor (-1, 0)
;GUICtrlSetState($Transmit4, $Gui_Disable)
GUICtrlSetTip(-1, "Transmit recording from slot 4")

$Transmit5 = GUICtrlCreateButton("TX5", 21, 56, 49, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_TOP,$BS_FLAT))
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetCursor (-1, 0)
;GUICtrlSetState($Transmit5, $Gui_Disable)
GUICtrlSetTip(-1, "Transmit recording from slot 5")

$Transmit6 = GUICtrlCreateButton("TX6", 100, 56, 49, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_TOP,$BS_FLAT))
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetCursor (-1, 0)
;GUICtrlSetState($Transmit6, $Gui_Disable)
GUICtrlSetTip(-1, "Transmit recording from slot 6")

$Transmit7 = GUICtrlCreateButton("TX7", 179, 56, 49, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_TOP,$BS_FLAT))
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetCursor (-1, 0)
;GUICtrlSetState($Transmit7, $Gui_Disable)
GUICtrlSetTip(-1, "Transmit recording from slot 7")

$Transmit8 = GUICtrlCreateButton("TX8", 258, 56, 49, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_TOP,$BS_FLAT))
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetCursor ($Transmit8, 0)
;GUICtrlSetState($Transmit8, $Gui_Disable)
GUICtrlSetTip(-1, "Transmit recording from slot 8")
;GUICtrlSetCursor (-1, 2)

$syncclock = GUICtrlCreateButton("Sync Clock", 326, 14, 73, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_TOP,$BS_FLAT))
GUICtrlSetBkColor(-1, 0xB4B4B4)
GUICtrlSetTip(-1, "Sync Radio clock with PC clock")
GUICtrlSetCursor (-1, 0)

$listports = GUICtrlCreateButton("Set COM", 326, 56, 73, 25, BitOR($BS_DEFPUSHBUTTON,$BS_CENTER,$BS_TOP,$BS_FLAT))
GUICtrlSetBkColor(-1, 0xB4B4B4)
GUICtrlSetTip(-1, "Set COM port")
GUICtrlSetCursor (-1, 0)

;using GetIP to see if we are connected. If yes, get the picture
$dData = _GetIP()
If $dData > 0 Then ;  internet connection is working
    ; Display HAMQSL Solardata in IEObject
    Global $oIE = _IECreateEmbedded()
    Global $bUpdateTip, $bTurnOff
    $hIE = GUICtrlCreateObj($oIE,6, 137, 410, 125)
    _IENavigate($oIE, 'about:blank', 1)
    _IEDocWriteHTML($oIE, _GetHTML2())
    _IEAction($oIE, "refresh")
    _IELoadWait($oIE)

    $oDocument = $oIE.document
    $oDocument.body.scroll = "no"
    ; ---
    $oMyIMG = $oDocument.getElementById('IMG1') ; <-- this reference doesn't work in ObjEvent()

    $oMyIMG = _WebBrowser_JS_ElementGetRef($oIE, $oMyIMG) ; <-- the reference returned by this function will work in ObjEvent()
    ;                                                           You can find this and some other utility functions related to
    ;                                                           the BrowserControl here: https://www.autoitscript.com/forum/topic/200338-browsercontrol-companion/
    ; set ObjEvent to catch events from the IMG element
    ; https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa742802%28v%3dvs.85%29
    Global $oEventObject2 = ObjEvent($oMyIMG, "IMGevent_", "HTMLImgEvents2") ; <-- catch directly events fired by the image

    ; see here for more references:
    ; https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/hh801968(v=vs.85)
    Else
    $WGP = WinGetPos($MainWindow)
    WinMove($MainWindow, "", Default, Default, Default, $WGP[3] - 130)
EndIf

If @error Then Exit MsgBox($MB_OK, "AutoIt COM Test", "ObjEvent: Can't use event interface. Error code: " & Hex(@error, 8))

$clock = GuiCtrlCreateLabel("00:00:00", 320, 100, 280, 22)
GUICtrlSetFont($clock, 14, 100, 1, "Orbitron")
$freqreadout = GuiCtrlCreateLabel("00.000.000", 10, 90, 225, 32)
GUICtrlSetFont($freqreadout, 14, 100, 1, "Orbitron")

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

while 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        ; do nothing
    EndSwitch
WEnd

Func _HideSolarDasta()
    If $dData > 0 Then
        If $Solarwindow = 1 Then
            $Solarwindow = 0
            $WGP = WinGetPos($MainWindow)
            WinMove($MainWindow, "", Default, Default, Default, $WGP[3] - 130)
        Else
            $Solarwindow = 1
            $WGP = WinGetPos($MainWindow)
            WinMove($MainWindow, "", Default, Default, Default, $WGP[3] + 130)
        EndIf
    EndIf
EndFunc

Func _GetHTML2()
            Local $sHTML = _
            "<!DOCTYPE HTML>" & @CRLF & _
            "<html>" & @CRLF & _
            "<head>" & @CRLF & _
            '<style type="text/css">' & @CRLF & _
            'html {overflow:hidden;}' & @CRLF & _
            '</style>' & @CRLF & _
            '<meta http-equiv="X-UA-Compatible" content="IE=edge" />' & @CRLF & _
            "<title>solar101pic.php (410×125)</title>" & @CRLF & _
            '</head>' & @CRLF & _
            '<body>' & @CRLF & _
            '' & @CRLF & _
            '<body style="margin: 12px; background: #0e0e0e;">' & @CRLF & _
            '' & @CRLF & _ ; '<img id="IMG1" style="-webkit-user-select: none;margin: auto;" src="http://www.hamqsl.com/solar101pic.php">' & @CRLF & _
            '<img id="IMG1" src="http://www.hamqsl.com/solar101pic.php", style="position: absolute; left:0; top:0; width: 410px; height: 125px">' & @CRLF & _
            "</body>" & @CRLF & _
            "</html>"
            Return $sHTML
            ;'<meta HTTP-Equiv="refresh" CONTENT="10; URL=http://www.hamqsl.com/solar101pic.php">' & @CRLF & _
EndFunc   ;==>_GetHTML2

; #FUNCTION# ====================================================================================================================
; Name ..........: _WebBrowser_JS_ElementGetRef
; Description ...: retrieves a reference of an object by it's ID suitable to be used from AutoIt
; Syntax ........: _WebBrowser_JS_ElementGetRef(Byref $oIE_Server, $oElement)
; Parameters ....: $oIE_Server          - a Webbrowser object reference.
;                  $oElement            - a reference to an object element of the web page.
; Return values .: an Object reference to the passed element (retrieved by means of ID)
; Author ........: Gianni Addiego (Chimp)
; Modified ......:
; Notes .......: the reference to the object retrieved by this function can be successfully passed to the AutoIt function ObjEvent().
;                If you simply use a reference to a javascript object retrieved by any other means, but not by it's ID, it may not work
;                in the AutoIt function ObjEvent() (strange but true), so the need to write this function that will force a reference by ID
;                to the passed object. There is no need to pass the ID of that object since it's retrieved automatically by the function.
;                If the passed object does not have an ID, we create one on the fly for the sole purpose of referring to it and release it
;                immediately afterwards in order to leave things as they were.
; Related .......:
; Link ..........: https://www.autoitscript.com/forum/topic/200338-browsercontrol-companion/
; Example .......:
; ===============================================================================================================================
Func _WebBrowser_JS_ElementGetRef(ByRef $oIE_Server, $oElement)
    Local $oWindow = $oIE_Server.document.parentwindow ; .JSglobal
    Local $oElementByIdReference
    If $oElement.Id = '' Then
        $oElement.setAttribute('Id', 'DummyId') ; we need an ID (a temporary ID)
        $oElementByIdReference = Execute('$oWindow.' & $oElement.getAttribute('Id')) ; get element's reference by Id
        $oElement.setAttribute('Id', '') ; remove the temporary ID (we leave things as we found them)
    Else
        $oElementByIdReference = Execute('$oWindow.' & $oElement.getAttribute('Id'))
    EndIf
    Return $oElementByIdReference
EndFunc   ;==>_WebBrowser_JS_ElementGetRef

Is it possible to keep the GUI or do I have to create a new one every time I hit the F5 Key?

Thanks for any help

KF5WGB

Share this post


Link to post
Share on other sites

The issue seems to be the default resizing behavior of the Obj control.  I added a couple of GUICtrlSetState commands in the _HideSolarData function to hide and show the $hIE Obj Control and noticed your other controls also shrink in size which I doubt you want.  An easy work-around would be to set the default control resizing option to the top of the script.

Beneath your Opt("TrayIconHide, 1) declaration, try adding this option.

Opt("GUIResizemode", $GUI_DOCKALL)

 


Share this post


Link to post
Share on other sites
15 hours ago, spudw2k said:

 Beneath your Opt("TrayIconHide, 1) declaration, try adding this option.

Opt("GUIResizemode", $GUI_DOCKALL)

 

That worked. I have to remember that one. Maybe it is time to write an UDF (winresize($handle, Vpos, Hpos, @shrinkmode) ) or something like that.

 Thanks for your input

KF5WGB

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...