Jump to content

Recommended Posts

Posted

Probably a really stupid question, but I have little to no experience of GDI and was wondering how to draw text on to the custom window? This is what I have so far:

;This allows the png to be dragged by clicking anywhere on the main image.
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
$GUI = _GUICreate_Alpha("Look at the shiny", @ScriptDir & "\iTT_Toast_PNG.png", @DesktopWidth - 212, @DesktopHeight - 162)
$myGuiHandle = WinGetHandle("Look at the shiny")
GUISetState()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($myGuiHandle)
_GDIPlus_GraphicsDrawString ($hGraphic, "Hello world", 10, 30)

But nothing.

James

Posted (edited)

This seems like it shouldn't be so hard but no matter what I try I can't make these type of child windows stay behind the parent window,stay independently movable but still move with the parent.? Any suggestions?

Edited by a440hz

Are you experienced?

Posted

@a440hz

Inspired by this topic, I decided to make this udf, eliminating the hassle of having to control multiple windows each having a separate image. Take a look at it and see if you like it. If you do, please improve on it. The basic framework for a script is already done, it just needs fine tuned to the preferences of the user.

  • 1 month later...
Posted

Well, this is interesting!

But I can't seem to find a way to add a label to the main GUI, I tried:

;This is an invisible control container. You can create regular windows controls on this panel.
$controlGui = GUICreate("ControlGUI", 400, 400, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $myGuiHandle)
GuictrlCreateButton ( "lossssssssssssssssssssssssssssssssssssssssdfklhalskjdjklasdfjklasjkdfjkasjkdfjklasdljkjklasdjfjasdfl", 20, 20, 200, 200 )
GUICtrlSetBkColor($controlGui, 0xFF00FF)
GUICtrlSetState(-1, $GUI_DISABLE)

But it doesn't seem to work, how can I make text display on the PNG?

I too am unable to get normal GUI controls to work on this invisible GUI. I've had several different attempts and can't get any of them to work.

Has anyone got this to work?

Posted

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <StaticConstants.au3>
Global Const $AC_SRC_ALPHA = 1

_GDIPlus_Startup()

$pngSrc = @ScriptDir & "\GUIBK.png"
;This allows the png to be dragged by clicking anywhere on the main image.
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
$GUI = _GUICreate_Alpha("Look at the shiny", $pngSrc)
$myGuiHandle = WinGetHandle("Look at the shiny")
GUISetState()
$butGui = GUICreate("ControlGUI", 400, 400, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $myGuiHandle)
GUICtrlCreateButton("Testing",100,100,100,100)
GUISetBkColor(0xABCDEF)
_WinAPI_SetLayeredWindowAttributes($butGui, 0xABCDEF, 255)
GUISetState()

;This png is draggable as if it were a child window. It has about 50 pixels at the top that allow it to be dragged
$TransparentButtonTest = GUICreate("Test321", 100, 100, -1, -1, $WS_EX_MDICHILD, $WS_EX_LAYERED, $myGuiHandle)
$hImageButton = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Fav.png")
SetBitMap($TransparentButtonTest, $hImageButton, 255)

GUISetState()

;This png is static. It is in a fixed position relative to the main window png, and is dragged along with it.
;For fun, it fades out in cycles.
$TransparentButtonTest2 = GUICreate("Test123", 250, 250, 400, 200,$WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $myGuiHandle)
$hImageButton2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Windows.png")
SetBitMap($TransparentButtonTest2, $hImageButton2, 255)

GUISetState()
$i = 0

While 1
$i = $i + 1
If $i = 255 Then $i = 0
    $msg = GUIGetMsg()
    $advMsg = GUIGetMsg(1)
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop

    EndSelect
SetBitMap($TransparentButtonTest2, $hImageButton2, $i)
WEnd


_GDIPlus_Shutdown()

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hwnd = WinGetHandle("Look at the shiny")) And ($iMsg = $WM_NCHITTEST) Then
    Return $HTCAPTION
    EndIf
EndFunc

Func _GUICreate_Alpha($sTitle, $sPath, $iX=-1, $iY=-1, $iOpacity=255)
    Local $hGUI, $hImage, $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
    $hImage = _GDIPlus_ImageLoadFromFile($sPath)
    $width = _GDIPlus_ImageGetWidth($hImage)
    $height = _GDIPlus_ImageGetHeight($hImage)
    $hGUI = GUICreate($sTitle, $width, $height, $iX, $iY, $WS_POPUP, $WS_EX_LAYERED)
    
    $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", $width)
    DllStructSetData($tSize, "Y", $height)
    $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, 2)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteObject($hImage)
    _WinAPI_DeleteDC($hMemDC)
EndFunc ;==>_GUICreate_Alpha

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", $AC_SRC_ALPHA)
    _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   ;==>SetBitmap

  • 3 years later...
Posted

Hi! Sorry if I read this posts not so attentive :) Can you show me working example of using png as a button? I was trying the preiovious example, standard controls GUICtrlCreateButton("Testing",100,100,100,100) work, while using png as a background, but I cant use png as button!!!

 

Thanx in advance!!!!

Posted

Would like to test this but the attachments are broke. Please fix this.

Also I see an example for writing text on the png, but how would we go about making an input box(like on the png, say if the input box is part of the png, as we wanted to be able to get text from it, is this possible, or do we have to use a standard input box?

I also previously saw an example on here somewhere of how to move a window by clicking anywhere inside it, and dragging using wm_event, i think this would be a more preferable method of moving the gui than just the pixels at the top where the title bar would "normally" be.

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