Jump to content

Problems with controls on a colored panel


Recommended Posts

I haven't tried anything like this for quite a while, but two problems arose when I tried to place a couple of controls on top of a colored portion of a GUI:

  • the button is surrounded by a pixel-width of the GUI's background color
  • the drag parent option doesn't work unless the color panel is enabled

I've tried a couple of button styles, like $BS_FLAT, but nothing helped.  I've attached my test script.

Is there a better (non-GDI+) approach for colorizing areas?  Or are there easy fixes for the above?

Thanks in advance for any assistance.

56a6ce4b3a183_BGTest.PNG.4783c61e59d718a

#include <GUIConstantsEx.au3>

GUICreate("BG Color Test", 400, 300)
GUISetBkColor(0xDD0000)

; this is the top area
$idEntry1 = GUICtrlCreateInput("First entry", 20, 60, 200, 25)
$idOK = GUICtrlCreateButton("OK", 300, 60, 40, 25)

; this is the bottom area ... that needs a different BG color
GUICtrlCreateLabel("", 0, 150, 400, 150, -1, $GUI_WS_EX_PARENTDRAG) ; << drag doesn't work
GUICtrlSetBkColor(-1, 0x44CCAA)
GUICtrlSetState(-1, $GUI_DISABLE)   ; <<< this enables the following fields, but disables drag
$idEntry2 = GUICtrlCreateInput("Second entry", 20, 200, 200, 25)
$idClose = GUICtrlCreateButton("Close", 300, 200, 60, 25)         ; << but background color shows

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idClose
            ExitLoop
        Case $idOK
            MsgBox(0, "Button", "Button works!", 1)
    EndSwitch
WEnd

 

Link to post
Share on other sites

Try this (non GDI+ version) :baby:

#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <WindowsConstants.au3>

Global Const $SC_DRAGMOVE = 0xF012
Global $hGUI = GUICreate("BG Color Test", 400, 300)
GUICtrlCreateLabel("", 0, 0, 400, 150)
GUICtrlSetBkColor(-1, 0xDD0000)
GUICtrlSetState(-1, $GUI_DISABLE)

; this is the top area
$idEntry1 = GUICtrlCreateInput("First entry", 20, 60, 200, 25)
$idOK = GUICtrlCreateButton("OK", 300, 60, 40, 25)

; this is the bottom area ... that needs a different BG color
GUICtrlCreateLabel("", 0, 150, 400, 150)
GUICtrlSetBkColor(-1, 0x44CCAA)
GUICtrlSetState(-1, $GUI_DISABLE)   ; <<< this enables the following fields, but disables drag

$idEntry2 = GUICtrlCreateInput("Second entry", 20, 200, 200, 25)
$idClose = GUICtrlCreateButton("Close", 300, 200, 60, 25)         ; << but background color shows

GUISetState()

GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idClose
            ExitLoop
        Case $idOK
            MsgBox(0, "Button", "Button works!", 1)
    EndSwitch
WEnd

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc   ;==>_WM_LBUTTONDOWN

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to post
Share on other sites

It works.

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc   ;==>_WM_LBUTTONDOWN

That drag method is a new one for me.

Would you happen to know what's causing the 1-pix frame around the buttons?  Although the GUI BG color doesn't show through, what I was hoping for was this:

 

Without frame.png

Link to post
Share on other sites

To apply transparency you have to use the woodoo GDI+ stuff:

 

#include <ButtonConstants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <WindowsConstants.au3>

Global Const $SC_DRAGMOVE = 0xF012
Global $hGUI = GUICreate("BG Color Test", 600, 300)
GUISetBkColor(0xFFFFFF)
$iPic_Bg1 = GUICtrlCreatePic("", 0, 0, 400, 150)
GUICtrlSetState(-1, $GUI_DISABLE)
;~ GUICtrlSetBkColor(-1, 0xDD0000)
GDIp_Woodoo(0xF0FF0000, $iPic_Bg1, $hGUI) ;ARGB format

; this is the top area
$idEntry1 = GUICtrlCreateInput("First entry", 20, 60, 200, 25)
$iOK = GUICtrlCreateButton("OK", 300, 60, 40, 25, $BS_FLAT)

; this is the bottom area ... that needs a different BG color
$iPic_Bg2 = GUICtrlCreatePic("", 100, 100, 400, 150)
GUICtrlSetState(-1, $GUI_DISABLE)   ; <<< this enables the following fields, but disables drag
GDIp_Woodoo(0xA085FF84, $iPic_Bg2, $hGUI) ;ARGB format

$idEntry2 = GUICtrlCreateInput("Second entry", 120, 150, 200, 25)
$iClose = GUICtrlCreateButton("Close", 400, 150, 60, 25, $BS_FLAT)         ; << but background color shows

GUISetState()

GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $iClose
            ExitLoop
        Case $iOK
            MsgBox(0, "Button", "Button works!", 1)
    EndSwitch
WEnd

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc   ;==>_WM_LBUTTONDOWN

Func GDIp_Woodoo($iColor, $iCtrlID, $hGUI, $bReleaseGDI = True)
    Local $aSize = ControlGetPos($hGUI, "", $iCtrlID)
    If @error Then Return SetError(1, 0, 0)
    _GDIPlus_Startup()
    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($aSize[2], $aSize[3]), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsClear($hGfx, $iColor)
    Local Const $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_DeleteObject(GUICtrlSendMsg($iCtrlID, 0x0172, $IMAGE_BITMAP, $hBitmap_GDI))
    _GDIPlus_GraphicsDispose($hGfx)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    If $bReleaseGDI Then Return _WinAPI_DeleteObject($hBitmap_GDI)
    Return $hBitmap_GDI
EndFunc

I'm on Win8 and the buttons look flat.

Edited by UEZ
Forgot the _GDIPlus_Shutdown() call within the woodoo function

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to post
Share on other sites

Thanks for your follow-up response.  I actually use GDI+ in about half of my scripts.  In this instance, I was trying to keep a small script simple ... and small.

What I've explored in the mean time is a fairly old method (2008?) for mimicing the button hover and click effects using jpg images for the buttons.  It looks promising, so far.  But GDI+ will be waiting in the wings, of course.  I will admit that I remain surprised that the one-pix "margin" seems to be a longstanding problem for Windows.  I can't see a valid reason for it.

But that aside, thanks for your help. 

 

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