Jump to content

Is this GUI thing possible?


AoRaToS
 Share

Recommended Posts

If you want a window to maintain it's position relative to another window then it's not particulary difficult no matter what type of window and what controls you have.

Here is your code modified a bit.

#include <GuiConstantsEx.au3>
  #include <ButtonConstants.au3>
  #include <Constants.au3>
  #include <WindowsConstants.au3>
  #include <StaticConstants.au3>
  #include <Misc.au3>
  
  Opt("GUIOnEventMode", 1)
  Global $OptionsGUI = -1
  $MainGUI = GUICreate("TEST", 205, 362, @DesktopWidth - 210, Default, BitOR($WS_POPUP, $WS_DLGFRAME), $WS_EX_TOOLWINDOW)
  GUICtrlCreatePic("", 1, 0, 205, 50, Default, $GUI_WS_EX_PARENTDRAG)
  $More = GUICtrlCreateButton("More", 82, 300, 40, 30)
  GUICtrlSetOnEvent($More, "Options")
  GUISetState(@SW_SHOW)
  GUIRegisterMsg($WM_MOVE,"Follow")
  While 1
      Sleep(100)
  WEnd
  
  Func Options()
      if IsHWnd($OptionsGUI) then return
      Local $Check[2], $wp = wingetPos($MainGui)
      $OptionsGUI = GUICreate("Options", 190, 297, $wp[0] - 190,$wp[1], BitOR($WS_POPUP, $WS_OVERLAPPED), BitOR($WS_EX_TOOLWINDOW, $WS_EX_CLIENTEDGE));, BitOR($WS_POPUP, $WS_OVERLAPPED), BitOR($WS_EX_TOOLWINDOW, $WS_EX_MDICHILD, $WS_EX_CLIENTEDGE, $WS_EX_LAYERED), $MainGUI)
      $okbutton = GUICtrlCreateButton("OK", 30, 277, 60, 17, $BS_DEFPUSHBUTTON)
      $cancelbutton = GUICtrlCreateButton("Cancel", 100, 277, 60, 17)
      GUICtrlSetOnEvent($cancelbutton, "onExit")
      $Tab = GUICtrlCreateTab(2, 5, 187, 270)
      $Tab1 = GUICtrlCreateTabItem("TEST")
      $ChangeUserNameLabel = GUICtrlCreateLabel("TEST", 5, 33, 55, 20)
      $ChangeUserNameInput = GUICtrlCreateInput("", 70, 30, 115, 20)
      GUICtrlSetLimit(-1, 15)
      $ChangeRefreshLabel = GUICtrlCreateLabel("Auto-Refresh", 5, 58, 70, 20)
      $ChangeRefreshInput = GUICtrlCreateInput("", 70, 55, 30, 20)
      GUICtrlSetLimit(-1, 2)
      $Combo = GUICtrlCreateCombo("", 105, 55, 80, 20)
      GUICtrlSetData(-1, "seconds|minutes|hours")
      $Check[0] = GUICtrlCreateCheckbox("TEST1", 5, 80, 115, 20)
      $Check[1] = GUICtrlCreateCheckbox("TEST2", 5, 140, 115, 20)
      $Tab2 = GUICtrlCreateTabItem("TEST")
      GUICtrlCreateLabel("ZZZZZZZZZZZZZZ", 20, 33, 150, 20)
      $CheckUpdate = GUICtrlCreateButton("No limit", 45, 80, 100, 20)
      GUICtrlCreatePic("", 0, 0, 190, 300)
      GUICtrlSetState(-1, $GUI_DISABLE)
      GUISetState(@SW_SHOW)
  EndFunc;==>Options
  
  Func onExit()
      Exit
  EndFunc;==>onExit
  
  Func Follow($hWnd,$iMsg,$wParam,$lParam)
     Local $iX,$iY
     If $hWnd <> $MainGUI then return

     $iX = BitAnd($lParam,0xFFFF)
     $iY = BitAnd($lParam,0xffff0000)/0x10000
     
     winmove($OptionsGUI,"",$iX - 190,$iY)
     
 EndFunc

Thank you Martin for your solution. I felt it was in the "$OptionsGUI = GUICreate" but for the life of me I could not figure out the right combination. This was very helpful to me

REB

MEASURE TWICE - CUT ONCE

Link to comment
Share on other sites

Thank you Martin for your solution. I felt it was in the "$OptionsGUI = GUICreate" but for the life of me I could not figure out the right combination. This was very helpful to me

REB

OK. Studyingat the earlier posts (which I should have done before) I see that the original problem was to do with a layered window. Here is the solution to that problem, which seems to be caused by the layered window using black as the transparent colour, and results in the text looking awful depending on what is behind the window. I think that the answer is to set the transparent colour to some unlikely colour.

#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Misc.au3>

Opt("GUIOnEventMode", 1)

$MainGUI = GUICreate("TEST", 205, 362, @DesktopWidth - 210, Default, BitOR($WS_POPUP, $WS_DLGFRAME), $WS_EX_TOOLWINDOW)
GUICtrlCreatePic("", 1, 0, 205, 50, Default, $GUI_WS_EX_PARENTDRAG)
$More = GUICtrlCreateButton("More", 82, 300, 40, 30)
GUICtrlSetOnEvent($More, "Options")
GUISetState(@SW_SHOW)

While 1
 Sleep(100)
WEnd

Func Options()
 Local $Check[2]
 $OptionsGUI = GUICreate("Options", 190, 297, -195, +35, BitOR($WS_POPUP, $WS_OVERLAPPED), BitOR($WS_EX_TOOLWINDOW, $WS_EX_MDICHILD, $WS_EX_CLIENTEDGE, $WS_EX_LAYERED), $MainGUI)
 $okbutton = GUICtrlCreateButton("OK", 30, 277, 60, 17, $BS_DEFPUSHBUTTON)
 $cancelbutton = GUICtrlCreateButton("Cancel", 100, 277, 60, 17)
 GUICtrlSetOnEvent($cancelbutton, "onExit")
 $Tab = GUICtrlCreateTab(2, 5, 187, 270)
 $Tab1 = GUICtrlCreateTabItem("TEST")
 $ChangeUserNameLabel = GUICtrlCreateLabel("TEST", 5, 33, 55, 20)
 $ChangeUserNameInput = GUICtrlCreateInput("", 70, 30, 115, 20)
 GUICtrlSetLimit(-1, 15)
 $ChangeRefreshLabel = GUICtrlCreateLabel("Auto-Refresh", 5, 58, 70, 20)
 $ChangeRefreshInput = GUICtrlCreateInput("", 70, 55, 30, 20)
 GUICtrlSetLimit(-1, 2)
 $Combo = GUICtrlCreateCombo("", 105, 55, 80, 20)
 GUICtrlSetData(-1, "seconds|minutes|hours")
 $Check[0] = GUICtrlCreateCheckbox("TEST1", 5, 80, 115, 20)
 $Check[1] = GUICtrlCreateCheckbox("TEST2", 5, 140, 115, 20)
 $Tab2 = GUICtrlCreateTabItem("TEST")
 GUICtrlCreateLabel("ZZZZZZZZZZZZZZ", 20, 33, 150, 20)
 $CheckUpdate = GUICtrlCreateButton("No limit", 45, 80, 100, 20)
 GUICtrlCreatePic("", 0, 0, 190, 300)
 GUICtrlSetState(-1, $GUI_DISABLE)
 GUISetState(@SW_SHOW)
 _API_SetLayeredWindowAttributes($OptionsGUI,0xABCDEF,255)
EndFunc  ;==>Options

Func onExit()
 Exit
EndFunc

;===============================================================================
;
; Function Name:   _API_SetLayeredWindowAttributes
; Description:: Sets Layered Window Attributes:) See MSDN for more informaion
; Parameter(s):
;                 $hwnd - Handle of GUI to work on
;                 $i_transcolor - Transparent color
;                 $Transparency - Set Transparancy of GUI
;                 $isColorRef - If True, $i_transcolor is a COLORREF-Strucure, else an RGB-Color
; Requirement(s):  Layered Windows
; Return Value(s): Success: 1
;                 Error: 0
;                  @error: 1 to 3 - Error from DllCall
;                  @error: 4 - Function did not succeed - use
;                              _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $isColorRef = False)

    Local Const $AC_SRC_ALPHA = 1
    Local Const $ULW_ALPHA = 2
    Local Const $LWA_ALPHA = 0x2
    Local Const $LWA_COLORKEY = 0x1
    If Not $isColorRef Then
        $i_transcolor = Hex(String($i_transcolor), 6)
        $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $LWA_COLORKEY + $LWA_ALPHA)
    Select
        Case @error
            Return SetError(@error, 0, 0)
        Case $Ret[0] = 0
            Return SetError(4, 0, 0)
        Case Else
            Return 1
    EndSelect
EndFunc ;==>_API_SetLayeredWindowAttributes
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

  • 2 months later...

Thank you for that solution martin! (It's been a long time, I wasn't following the topic anymore since I hadn't found a solution)

Both ways work great, I chose the second one because I had less code to change and it fitted my needs better...

Now I can see the background of previously transparent gif's I have, so I will change the backgroung color to 0xABCDEF so it should be transparent...

What color would that be in Photoshop? #ABCDEF?

Edited by AoRaToS

s!mpL3 LAN Messenger

Current version 2.9.9.1 [04/07/2019]

s!mpL3 LAN Messenger.zip

s!mpL3

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