Jump to content

GUI works weird, no idea why


Recommended Posts

Here my code is:

#include <ComboConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

Global $Settings = @ScriptDir & "\Setting.ini"
Global $hCombo, $Form1, $Dummy1, $Button1, $Button2, $hImage, $Form1_Child, $Form1_Child2

CreateBaseGUI()
ShowBaseGUI()

While 1
    Sleep(1000)
    HideBaseGUI()
    Sleep(1000)
    ShowBaseGUI()
WEnd

Func CreateBaseGUI()
    _GDIPlus_Startup()

    $Active = IniRead($Settings, "Base", "ActiveSkin", "v1")

    $pngSrc = @ScriptDir & "\" & IniRead($Settings, $Active, "File", "Skins\v1.png")
    $hImage = _GDIPlus_ImageLoadFromFile($pngSrc)

    $width = _GDIPlus_ImageGetWidth($hImage)
    $height = _GDIPlus_ImageGetHeight($hImage)

    $iTop = IniRead($Settings, $Active, "InputTop", 17)
    $iLeft = IniRead($Settings, $Active, "InputLeft", 392)
    $iWidth = IniRead($Settings, $Active, "InputWidth", 235)

    $Form1 = GUICreate("RunMAINWIN", $width, $height, @DesktopWidth / 2 - 500, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    SetBitmap($Form1, $hImage, 0)

    $Form1_Child = GUICreate("RunCHDWIN", $iWidth - 66, 23, $iLeft, $iTop, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_MDICHILD, $Form1)
    $hCombo = GUICtrlCreateCombo("", 1, 1, $iWidth - 66, 10, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))

    $Form1_Child2 = GUICreate("RunCHDWIN2", 66, 23, $iLeft + $iWidth - 66, $iTop, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_MDICHILD, $Form1)
    $Button1 = GUICtrlCreateButton("Run", 0, 0, 43, 23)
    $Button2 = GUICtrlCreateButton("+", 43, 0, 23, 23)
    $Dummy1 = GUICtrlCreateDummy()

    Local $aAccelKeys[2][2] = [["^a", $Dummy1],["{ENTER}", $Button1]]
    GUISetAccelerators($aAccelKeys)
EndFunc

Func GetFocus()
    If Not WinActive($Form1) Then
        If Not WinActive($Form1_Child) Then
            If Not WinActive($Form1_Child2) Then
                AdlibUnRegister("GetFocus")
                HideBaseGUI()
            EndIf
        EndIf
    EndIf
EndFunc

Func HideBaseGUI()
    AdlibUnRegister("GetFocus")
    For $i = 255 To 0 Step -5
        SetBitmap($Form1, $hImage, $i)
        WinSetTrans("RunCHDWIN", "", $i)
        WinSetTrans("RunCHDWIN2", "", $i)
    Next

    GUISetState(@SW_HIDE, $Form1)
    GUISetState(@SW_HIDE, $Form1_Child)
    GUISetState(@SW_HIDE, $Form1_Child2)
    HotKeySet("", "HideBaseGUI")
    HotKeySet("^{SPACE}", "ShowBaseGUI")
EndFunc

Func ShowBaseGUI()
    GUISetState(@SW_SHOW, $Form1)
    GUISetState(@SW_SHOW, $Form1_Child)
    GUISetState(@SW_SHOW, $Form1_Child2)

    For $i = 0 To 255 Step 3
        SetBitmap($Form1, $hImage, $i)
        WinSetTrans("RunCHDWIN", "", $i)
        WinSetTrans("RunCHDWIN2", "", $i)
    Next

    HotKeySet("{ESC}", "HideBaseGUI")
    HotKeySet("^{SPACE}", "HideBaseGUI")
    WinActivate($Form1_Child)
    AdlibRegister("GetFocus")
EndFunc

Func SetBitmap($hGUI, $hImage, $iOpacity)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
    DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc

For me the following thing happens:

- GUI Creation success

- Show GUI works

- Hide GUI works

- Showing GUI against works, but $Form1_Child Is not showing up.

I tried every way I knew to make it work, but I failed :) I Hope you could help me.

Thanks a lot! :)

post-57268-0-02358600-1400360884_thumb.p

Link to comment
Share on other sites

Not sure why, but your problem is

WinActivate($Form1_Child)

Changing to

WinActivate($Form1)

Or removing it fixes your problem. I suppose its because your trying to activate a child window before activating the initial one? I dunno, I'm sure someone can shed light on it!

Edited by Damein

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

I didn't have to do any of that. Just copying it I could run it, lol. It shows up on the top and 'flashes' every 2 seconds.

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

I didn't have to do any of that. Just copying it I could run it, lol. It shows up on the top and 'flashes' every 2 seconds.

 

Yes, it should flash, but somewhy the combobox gets hidden after a while. After removing the Winactivate I still have problems. WinSetTrans succeed, but it doesn't change transparency.

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