Sign in to follow this  
Followers 0
charvi

Is Graphic on Picture allowed?

15 posts in this topic

#1 ·  Posted (edited)

Edit: post removed - please read next post with a full working example

Edited by charvi

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello again,

Please take this complete working example to test the $h_Graph which is my problem, and ignore the example in the previous post.

As you see, the $h_Pic is working like a charm, but why not $h_Graph?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <GuiToolBar.au3>
#include <GuiComboBoxEx.au3>
#include <Array.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <File.au3>
#include <Misc.au3>
#include <GDIPlus.au3>

Global $h_Win, $h_Pic, $h_Graph, $Msg
Global $a_Factors[4] = [0.0, 0.4, 0.6, 1.0]
Global $a_Positions[4] = [0.0, 0.3, 0.7, 1.0]

$h_Win = GUICreate("Graphic Test", 1024, 768, -1, -1)

$h_Pic = GUICtrlCreatePic("", 0, 0, 1024, 768)
_PicSetGradient_($h_Pic, 0, 0, 1024, 768, $a_Factors, $a_Positions, "0x800040", "0x000000", -1, True)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)

$h_Graph = GUICtrlCreateGraphic(0, 0, 1024, 768)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xffff00)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 100, 100)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, 600, 600)
GUISetState(@SW_SHOW)
; ====================================================================================================
While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd
; ====================================================================================================
;==== PicSetGradient
; When using PicSetGradient(), we need the following elements:
; $hPicID           : the grphic handle, for example $cID = GUICtrlCreatePic("", 0, 0, $iW, $iH)
; $iX               : the left position of the graphical zone
; $iY               : the up position of the graphical zone
; $iW               : the width of the graphical zone
; $iH               : the height of the graphical zone
; $aFactors         : an array containing the color factors, for example: $aFactors[4] = [0.0, 0.4, 0.6, 1.0]
; $aPositions       : an array containing the color positions, for example: $aPositions[4] = [0.0, 0.3, 0.7, 1.0]
; $iClr1            : the color to start from, for example "0x800040"
; $iClr2            : the color to end to, for example "0xFFFFFF"
; $iDirection       : 0=left to right - 1=up to down - 2=left up to right down - 3=right up to left down
; $bGammaCorrection : gamma correction: True or False

Func _PicSetGradient_($hPicID, $iX, $iY, $iW, $iH, $aFactors, $aPositions, $iClr1, $iClr2, $iDirection, $bGammaCorrection)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local $hWnd, $iC1, $iC2, $hBitmap, $hImage, $hGraphic, $hBrushLin, $hbmp, $aBmp
    $hWnd = GUICtrlGetHandle($hPicID)

    $iC1 = StringReplace($iClr1, "0x", "0xFF")
    $iC2 = StringReplace($iClr2, "0x", "0xFF")
    $hBitmap = _WinAPI_CreateBitmap($iW, $iH, 1, 32)
    _GDIPlus_Startup()
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    $hBrushLin = _GDIPlus_CreateLineBrushFromRect(0, 0, $iW, $iH, $aFactors, $aPositions, $iC1, $iC2, $iDirection)
    GDIPlus_SetLineGammaCorrection($hBrushLin, $bGammaCorrection)
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iW, $iH, $hBrushLin)
    $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $aBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hbmp)
    If $aBmp[0] <> 0 Then _WinAPI_DeleteObject($aBmp[0])
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_BrushDispose($hBrushLin)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_Shutdown()
;~     For $i = $Combo To $Label[1]
;~         GUICtrlSetState($i, $GUI_SHOW)
;~     Next
EndFunc   ;==>PicSetGradient


;==== GDIPlus_CreateLineBrushFromRect === Malkey's function
;Description - Creates a LinearGradientBrush object from a set of boundary points and boundary colors.
; $aFactors - If non-array, default array will be used.
;           Pointer to an array of real numbers that specify blend factors. Each number in the array
;           specifies a percentage of the ending color and should be in the range from 0.0 through 1.0.
;$aPositions - If non-array, default array will be used.
;            Pointer to an array of real numbers that specify blend factors' positions. Each number in the array
;            indicates a percentage of the distance between the starting boundary and the ending boundary
;            and is in the range from 0.0 through 1.0, where 0.0 indicates the starting boundary of the
;            gradient and 1.0 indicates the ending boundary. There must be at least two positions
;            specified: the first position, which is always 0.0, and the last position, which is always
;            1.0. Otherwise, the behavior is undefined. A blend position between 0.0 and 1.0 indicates a
;            line, parallel to the boundary lines, that is a certain fraction of the distance from the
;            starting boundary to the ending boundary. For example, a blend position of 0.7 indicates
;            the line that is 70 percent of the distance from the starting boundary to the ending boundary.
;            The color is constant on lines that are parallel to the boundary lines.
; $iArgb1    - First Top color in 0xAARRGGBB format
; $iArgb2    - Second color in 0xAARRGGBB format
; $LinearGradientMode -  LinearGradientModeHorizontal       = 0x00000000,
;                        LinearGradientModeVertical         = 0x00000001,
;                        LinearGradientModeForwardDiagonal  = 0x00000002,
;                        LinearGradientModeBackwardDiagonal = 0x00000003
; $WrapMode  - WrapModeTile       = 0,
;              WrapModeTileFlipX  = 1,
;              WrapModeTileFlipY  = 2,
;              WrapModeTileFlipXY = 3,
;              WrapModeClamp      = 4
; GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect, ARGB color1, ARGB color2,
;             LinearGradientMode mode, GpWrapMode wrapMode, GpLineGradient **lineGradient)
; Reference:  http://msdn.microsoft.com/en-us/library/ms534043(VS.85).aspx
;
Func _GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth, $iHeight, $aFactors, $aPositions, _
        $iArgb1 = 0xFF0000FF, $iArgb2 = 0xFFFF0000, $LinearGradientMode = 0x00000001, $WrapMode = 0)

    Local $tRect, $pRect, $aRet, $tFactors, $pFactors, $tPositions, $pPositions, $iCount, $iI, $hStatus

    If $iArgb1 = Default Then $iArgb1 = 0xFF0000FF
    If $iArgb2 = Default Then $iArgb2 = 0xFFFF0000
    If $LinearGradientMode = -1 Or $LinearGradientMode = Default Then $LinearGradientMode = 0x00000001
    If $WrapMode = -1 Or $LinearGradientMode = Default Then $WrapMode = 1

    $tRect = DllStructCreate("float X;float Y;float Width;float Height")
    $pRect = DllStructGetPtr($tRect)
    DllStructSetData($tRect, "X", $iX)
    DllStructSetData($tRect, "Y", $iY)
    DllStructSetData($tRect, "Width", $iWidth)
    DllStructSetData($tRect, "Height", $iHeight)

    ;Note: Withn _GDIPlus_Startup(), $ghGDIPDll is defined
    $aRet = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushFromRect", "ptr", $pRect, "int", $iArgb1, _
            "int", $iArgb2, "int", $LinearGradientMode, "int", $WrapMode, "int*", 0)

    If IsArray($aFactors) = 0 Then Dim $aFactors[4] = [0.0, 0.4, 0.6, 1.0]
    If IsArray($aPositions) = 0 Then Dim $aPositions[4] = [0.0, 0.3, 0.7, 1.0]

    $iCount = UBound($aPositions)
    $tFactors = DllStructCreate("float[" & $iCount & "]")
    $pFactors = DllStructGetPtr($tFactors)
    For $iI = 0 To $iCount - 1
        DllStructSetData($tFactors, 1, $aFactors[$iI], $iI + 1)
    Next
    $tPositions = DllStructCreate("float[" & $iCount & "]")
    $pPositions = DllStructGetPtr($tPositions)
    For $iI = 0 To $iCount - 1
        DllStructSetData($tPositions, 1, $aPositions[$iI], $iI + 1)
    Next

    $hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _
            "ptr", $pFactors, "ptr", $pPositions, "int", $iCount)
    Return $aRet[6] ; Handle of Line Brush
EndFunc   ;==>_GDIPlus_CreateLineBrushFromRect

;===========================================================
; Description:  Specifies whether gamma correction is enabled for this linear gradient brush.
; Parameters
; $hBrush             - [in] Pointer to the LinearGradientBrush object.
; $useGammaCorrection - [in] Boolean value that specifies whether gamma correction occurs
;                     during rendering. TRUE specifies that gamma correction is enabled,
;                     and FALSE specifies that gamma correction is not enabled. By default,
;                     gamma correction is disabled during construction of a
;                     LinearGradientBrush object.
;GdipSetLineGammaCorrection(GpLineGradient *brush, BOOL useGammaCorrection)
;
Func GDIPlus_SetLineGammaCorrection($hBrush, $useGammaCorrection = True)
    Local $aResult  
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetLineGammaCorrection", "hwnd", $hBrush, "int", $useGammaCorrection)
    Return $aResult[0]
EndFunc   ;==>GDIPlus_SetLineGammaCorrection
Edited by charvi

Share this post


Link to post
Share on other sites

I found out that Zedna had exact the same problem in August 2005 (40 months earlier!):

http://www.autoitscript.com/forum/index.ph...amp;#entry97355

Bad news is that jpm replied that is NOT possible:

Graphics is always a background painting.

no possibility to put them on top.

That's the limit of not redesining a specific control.

Usualy other control badly work when overlapped.

What a pity... :) Weren't there a solution in the meantime?

So Malkey's beautiful gradient cannot be used if I want to draw lines?.... :)

Any solution is welcome...

Share this post


Link to post
Share on other sites

You might want to check out Tobias' Graphic Functions @

http://www.autoitscript.com/forum/index.php?showtopic=56833

Thanks a lot ResNullius, Tobias' Graphic Functions was what I needed, but unfortunately, the drawings are not done over images, but also behind. Probably because I run them on Vista and Tobias wrote them for the XP. So I searched further, further and found that it can probably be accomplished with GDI+ functions. But they are far more complex. I have not yet found a series of GDI+ functions...

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Just draw your lines or anything over your picture by GDI/GDI+ or whatever else in WM_PAINT:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <GuiToolBar.au3>
#include <GuiComboBoxEx.au3>
#include <Array.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <File.au3>
#include <Misc.au3>
#include <GDIPlus.au3>

Global $h_Win, $h_Pic, $h_Graph, $Msg
Global $a_Factors[4] = [0.0, 0.4, 0.6, 1.0]
Global $a_Positions[4] = [0.0, 0.3, 0.7, 1.0]
Global $gdi_dll = DllOpen("gdi32.dll")

$h_Win = GUICreate("Graphic Test", 1024, 768, -1, -1)

$Pic = GUICtrlCreatePic("", 0, 0, 1024, 768)
$h_Pic = GUICtrlGetHandle($Pic)
$pic_hdc = _WinAPI_GetDC($h_Pic)
_PicSetGradient_($Pic, 0, 0, 1024, 768, $a_Factors, $a_Positions, "0x800040", "0x000000", -1, True)
GUICtrlSetState(-1, $GUI_DISABLE)

;~ $h_Graph = GUICtrlCreateGraphic(0, 0, 1024, 768)
;~ GUICtrlSetState(-1, $GUI_DISABLE)
;~ GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xffff00)
;~ GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 100, 100)
;~ GUICtrlSetGraphic(-1, $GUI_GR_LINE, 600, 600)
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
GUISetState(@SW_SHOW)
; ====================================================================================================

While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd
; ====================================================================================================

Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    _WinAPI_RedrawWindow($h_Pic, 0, 0, $RDW_UPDATENOW) ; force redraw of pic (Rect=0 Region=0)
    DrawMyStuff() ; then draw my stuff on top
    _WinAPI_RedrawWindow($h_Pic, 0, 0, $RDW_VALIDATE) ; then force no-redraw of pic
    Return $GUI_RUNDEFMSG
EndFunc

Func DrawMyStuff() ; draw line
    $size = 1
        $pen = DLLCall($gdi_dll,"int","CreatePen","int",0,"int",$size,"int",0xffff00)
    $obj_orig = DLLCall($gdi_dll,"int","SelectObject","int",$pic_hdc,"int",$pen[0])
    DLLCall($gdi_dll,"int","MoveToEx","int",$pic_hdc,"int",100,"int",100,"int",0)
    DLLCall($gdi_dll,"int","LineTo","int",$pic_hdc,"int",600,"int",600) ; line
    DLLCall($gdi_dll,"int","SelectObject","int",$pic_hdc,"int",$obj_orig[0])
    DLLCall($gdi_dll,"int","DeleteObject","int",$pen[0])
EndFunc

Func OnAutoItExit()
    DllClose($gdi_dll)
    _WinAPI_ReleaseDC($h_Pic, $pic_hdc)
EndFunc

;==== PicSetGradient
; When using PicSetGradient(), we need the following elements:
; $hPicID           : the grphic handle, for example $cID = GUICtrlCreatePic("", 0, 0, $iW, $iH)
; $iX               : the left position of the graphical zone
; $iY               : the up position of the graphical zone
; $iW               : the width of the graphical zone
; $iH               : the height of the graphical zone
; $aFactors         : an array containing the color factors, for example: $aFactors[4] = [0.0, 0.4, 0.6, 1.0]
; $aPositions       : an array containing the color positions, for example: $aPositions[4] = [0.0, 0.3, 0.7, 1.0]
; $iClr1            : the color to start from, for example "0x800040"
; $iClr2            : the color to end to, for example "0xFFFFFF"
; $iDirection       : 0=left to right - 1=up to down - 2=left up to right down - 3=right up to left down
; $bGammaCorrection : gamma correction: True or False

Func _PicSetGradient_($hPicID, $iX, $iY, $iW, $iH, $aFactors, $aPositions, $iClr1, $iClr2, $iDirection, $bGammaCorrection)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local $hWnd, $iC1, $iC2, $hBitmap, $hImage, $hGraphic, $hBrushLin, $hbmp, $aBmp
    $hWnd = GUICtrlGetHandle($hPicID)

    $iC1 = StringReplace($iClr1, "0x", "0xFF")
    $iC2 = StringReplace($iClr2, "0x", "0xFF")
    $hBitmap = _WinAPI_CreateBitmap($iW, $iH, 1, 32)
    _GDIPlus_Startup()
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    $hBrushLin = _GDIPlus_CreateLineBrushFromRect(0, 0, $iW, $iH, $aFactors, $aPositions, $iC1, $iC2, $iDirection)
    GDIPlus_SetLineGammaCorrection($hBrushLin, $bGammaCorrection)
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iW, $iH, $hBrushLin)
    $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $aBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hbmp)
    If $aBmp[0] <> 0 Then _WinAPI_DeleteObject($aBmp[0])
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_BrushDispose($hBrushLin)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_Shutdown()
;~     For $i = $Combo To $Label[1]
;~         GUICtrlSetState($i, $GUI_SHOW)
;~     Next
EndFunc   ;==>PicSetGradient


;==== GDIPlus_CreateLineBrushFromRect === Malkey's function
;Description - Creates a LinearGradientBrush object from a set of boundary points and boundary colors.
; $aFactors - If non-array, default array will be used.
;           Pointer to an array of real numbers that specify blend factors. Each number in the array
;           specifies a percentage of the ending color and should be in the range from 0.0 through 1.0.
;$aPositions - If non-array, default array will be used.
;            Pointer to an array of real numbers that specify blend factors' positions. Each number in the array
;            indicates a percentage of the distance between the starting boundary and the ending boundary
;            and is in the range from 0.0 through 1.0, where 0.0 indicates the starting boundary of the
;            gradient and 1.0 indicates the ending boundary. There must be at least two positions
;            specified: the first position, which is always 0.0, and the last position, which is always
;            1.0. Otherwise, the behavior is undefined. A blend position between 0.0 and 1.0 indicates a
;            line, parallel to the boundary lines, that is a certain fraction of the distance from the
;            starting boundary to the ending boundary. For example, a blend position of 0.7 indicates
;            the line that is 70 percent of the distance from the starting boundary to the ending boundary.
;            The color is constant on lines that are parallel to the boundary lines.
; $iArgb1    - First Top color in 0xAARRGGBB format
; $iArgb2    - Second color in 0xAARRGGBB format
; $LinearGradientMode -  LinearGradientModeHorizontal       = 0x00000000,
;                        LinearGradientModeVertical         = 0x00000001,
;                        LinearGradientModeForwardDiagonal  = 0x00000002,
;                        LinearGradientModeBackwardDiagonal = 0x00000003
; $WrapMode  - WrapModeTile       = 0,
;              WrapModeTileFlipX  = 1,
;              WrapModeTileFlipY  = 2,
;              WrapModeTileFlipXY = 3,
;              WrapModeClamp      = 4
; GdipCreateLineBrushFromRect(GDIPCONST GpRectF* rect, ARGB color1, ARGB color2,
;             LinearGradientMode mode, GpWrapMode wrapMode, GpLineGradient **lineGradient)
; Reference:  http://msdn.microsoft.com/en-us/library/ms534043(VS.85).aspx
;
Func _GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth, $iHeight, $aFactors, $aPositions, _
        $iArgb1 = 0xFF0000FF, $iArgb2 = 0xFFFF0000, $LinearGradientMode = 0x00000001, $WrapMode = 0)

    Local $tRect, $pRect, $aRet, $tFactors, $pFactors, $tPositions, $pPositions, $iCount, $iI, $hStatus

    If $iArgb1 = Default Then $iArgb1 = 0xFF0000FF
    If $iArgb2 = Default Then $iArgb2 = 0xFFFF0000
    If $LinearGradientMode = -1 Or $LinearGradientMode = Default Then $LinearGradientMode = 0x00000001
    If $WrapMode = -1 Or $LinearGradientMode = Default Then $WrapMode = 1

    $tRect = DllStructCreate("float X;float Y;float Width;float Height")
    $pRect = DllStructGetPtr($tRect)
    DllStructSetData($tRect, "X", $iX)
    DllStructSetData($tRect, "Y", $iY)
    DllStructSetData($tRect, "Width", $iWidth)
    DllStructSetData($tRect, "Height", $iHeight)

    ;Note: Withn _GDIPlus_Startup(), $ghGDIPDll is defined
    $aRet = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushFromRect", "ptr", $pRect, "int", $iArgb1, _
            "int", $iArgb2, "int", $LinearGradientMode, "int", $WrapMode, "int*", 0)

    If IsArray($aFactors) = 0 Then Dim $aFactors[4] = [0.0, 0.4, 0.6, 1.0]
    If IsArray($aPositions) = 0 Then Dim $aPositions[4] = [0.0, 0.3, 0.7, 1.0]

    $iCount = UBound($aPositions)
    $tFactors = DllStructCreate("float[" & $iCount & "]")
    $pFactors = DllStructGetPtr($tFactors)
    For $iI = 0 To $iCount - 1
        DllStructSetData($tFactors, 1, $aFactors[$iI], $iI + 1)
    Next
    $tPositions = DllStructCreate("float[" & $iCount & "]")
    $pPositions = DllStructGetPtr($tPositions)
    For $iI = 0 To $iCount - 1
        DllStructSetData($tPositions, 1, $aPositions[$iI], $iI + 1)
    Next

    $hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _
            "ptr", $pFactors, "ptr", $pPositions, "int", $iCount)
    Return $aRet[6] ; Handle of Line Brush
EndFunc   ;==>_GDIPlus_CreateLineBrushFromRect

;===========================================================
; Description:  Specifies whether gamma correction is enabled for this linear gradient brush.
; Parameters
; $hBrush             - [in] Pointer to the LinearGradientBrush object.
; $useGammaCorrection - [in] Boolean value that specifies whether gamma correction occurs
;                     during rendering. TRUE specifies that gamma correction is enabled,
;                     and FALSE specifies that gamma correction is not enabled. By default,
;                     gamma correction is disabled during construction of a
;                     LinearGradientBrush object.
;GdipSetLineGammaCorrection(GpLineGradient *brush, BOOL useGammaCorrection)
;
Func GDIPlus_SetLineGammaCorrection($hBrush, $useGammaCorrection = True)
    Local $aResult 
     $aResult = DllCall($ghGDIPDll, "int", "GdipSetLineGammaCorrection", "hwnd", $hBrush, "int", $useGammaCorrection)
    Return $aResult[0]
EndFunc   ;==>GDIPlus_SetLineGammaCorrection

For more inspiration look at my Radar project - in my signature or here

http://www.autoitscript.com/forum/index.php?showtopic=75659

I draw red cross over GIF image (picture control)

Edited by Zedna

Share this post


Link to post
Share on other sites

Here is a GDIPlus related script to experiment with.

The colour format is 0xAARRGGBB. AA is the alpha channel. 0x00RRGGBB is completely transparent. 0xFFRRGGBB is fully opaque.

The script contains an image from file ( enter your own full path image file)

Next a blue diagonal line

Then a partial transparent gradient (Maroon at top to black at bottom of picture control)

Then top most is a red diagonal line, a blue ellipse, and some yellow text.

The button and label control are not part of the graphics.

Notice the fading image and fading blue line as it disappears behind the fully opaque black part of the gradient.

Try changing the 50% transparent maroon colour 0x80800040 line 61 to 0xFF800040 fully opaque, 0% transparent.

Notice the diagonal blue line and image can not be seen.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

Opt("GUIOnEventMode", 1) ;0=disabled, 1=OnEvent mode enabled
Global $ApW = 600, $ApH = 400
Global $Button[1]
Global Const $iPI = 3.1415926535897932384626433832795

$hGui = GUICreate("GDIPlus Graphics on Picture Control - OnEvent Mode", $ApW + 40, $ApH + 40)
GUISetOnEvent(-3, "_Quit")
GUISetBkColor(0xffA0A0, $hGui)

$Pic = GUICtrlCreatePic("", 20, 20, $ApW, $ApH)
GUICtrlSetState(-1, $GUI_DISABLE)

;Button and Label not apart of GDI+ graphics as saved image shows.
$Button[0] = GUICtrlCreateButton("Exit", 5, 5, 100, 45)
GUICtrlSetOnEvent($Button[0], "_Quit")
GUICtrlSetBkColor(-1, 0xF000FF)
GUICtrlSetColor(-1, 0xBadB0B)

GUICtrlCreateLabel("A GUICtrlCreateLabel", $ApW * 0.5, $ApH * 0.75, 200, 20)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, 12, 800, 2)
GUICtrlSetColor(-1, 0x0000ff)
PicSetGraphics($Pic, $ApW, $ApH); <-- Draw GDIPlus graphics on Picture control.

GUISetState(@SW_SHOW, $hGui)

While 1
    Sleep(10)
WEnd

Func PicSetGraphics($cID, $iW, $iH)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local $hWnd, $hBitmap, $hImage, $hGraphic, $hBrush, $hBrush1, $hbmp, $aBmp
    $hWnd = GUICtrlGetHandle($cID)
    _GDIPlus_Startup()
   
    ;Buffer     
    $hBitmap = _WinAPI_CreateSolidBitmap($hGui, 0xFFFFFF, $iW, $iH) 
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
   
    ;=======>  All Graphics Here ============================================
    
    ;Load and display image from file bmp, jpg, png, tif, wmf, or gif
    $hImage1 = _GDIPlus_ImageLoadFromFile (@WindowsDir & "\Web\Wallpaper\Autumn.jpg"); Replace with your image file
     _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage1, 0, 0, $iW, $iH)     
     
    ;Blue Diagonal line behind gradient and infront of image
    $hPen = _GDIPlus_PenCreate(0xFF0000FF, 4)
    _GDIPlus_GraphicsDrawLine($hGraphic,  0 , 0,$ApW,$ApH, $hPen)    
     
    ;Gradient Background - At the top Maroon 50% transparency to fully opaque black at bottom
    Global $a_Factors[4] = [0.0, 0.4, 0.8, 1.0]
    Global $a_Positions[4] = [0.0, 0.3, 0.6, 1.0]   
    $hBrushLin = _GDIPlus_CreateLineBrushFromRect( 0, 0, $iW, $iH, $a_Factors, $a_Positions, 0x80800040, 0xFF000000,1,0)
    GDIPlus_SetLineGammaCorrection($hBrushLin);, $bGammaCorrection)
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iW, $iH, $hBrushLin)    
      
    ;Ellipse
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF0080FF)
    _GDIPlus_GraphicsFillEllipse($hGraphic, 230, 20, 50, 90, $hBrush)
   
    ;Diagonal red line on top of gradient
    $hPen = _GDIPlus_PenCreate(0xFFFF0000, 2)
    _GDIPlus_GraphicsDrawLine($hGraphic, 0, $ApH, $ApW, 0, $hPen)
    _GDIPlus_GraphicsDrawString ($hGraphic, "Hello world",$ApW/2, $ApH-15) ; From help file 
    
    ; Draw text 
    $sText = "Text using _GDIPlus_GraphicsDrawStringEx()"
    $hBrush1 = _GDIPlus_BrushCreateSolid(0xFFAFAf00)
    $hFormat = _GDIPlus_StringFormatCreate(0)
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 12, 1, 3)
    $tLayout = _GDIPlus_RectFCreate(65, 105, 300,60) ; increase 300 to 380 for one line of text
    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sText, $hFont, $tLayout, $hFormat)
   _GDIPlus_GraphicsDrawStringEx($hGraphic, $sText, $hFont, $tLayout, $hFormat, $hBrush1)
 
    ; ==========> End of all Graphics ========================================
   
    ; Keeps all GDIPlus graphics visible
    $hbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $aBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hbmp)
    _WinAPI_RedrawWindow($hGui, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME))
   
    ; Save Graphics on picture control
    _GDIPlus_ImageSaveToFile($hImage, @DesktopDir & "\TestWrite1.png")
    ShellExecute(@DesktopDir & "\TestWrite1.png")
   
     _WinAPI_DeleteObject($aBmp[0])
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrush1)
     _GDIPlus_BrushDispose($hBrushLin)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hbmp)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_Shutdown()
EndFunc   ;==>PicSetGraphics

Func _Quit()
    Local $iDeletePict = MsgBox(4, "Delete Saved Image File", "Do you wish to delete the saved image file, TestWrite1.png? Y/N")
    If $iDeletePict = 6 Then FileDelete(@DesktopDir & "\TestWrite1.png")
    Exit
EndFunc   ;==>_Quit

Func _GDIPlus_CreateLineBrushFromRect($iX, $iY, $iWidth, $iHeight, $aFactors, $aPositions, _
        $iArgb1 = 0xFFFFFFFF, $iArgb2 = 0xFF000000, $LinearGradientMode = 0x00000001, $WrapMode = 0)

    Local $tRect, $pRect, $aRet, $tFactors, $pFactors, $tPositions, $pPositions, $iCount, $iI, $hStatus

    If $iArgb1 = Default Then $iArgb1 = 0xFF0000FF
    If $iArgb2 = Default Then $iArgb2 = 0xFFFF0000
    If $LinearGradientMode = -1 Or $LinearGradientMode = Default Then $LinearGradientMode = 0x00000001
    If $WrapMode = -1 Or $LinearGradientMode = Default Then $WrapMode = 1

    $tRect = DllStructCreate("float X;float Y;float Width;float Height")
    $pRect = DllStructGetPtr($tRect)
    DllStructSetData($tRect, "X", $iX)
    DllStructSetData($tRect, "Y", $iY)
    DllStructSetData($tRect, "Width", $iWidth)
    DllStructSetData($tRect, "Height", $iHeight)

    ;Note: Withn _GDIPlus_Startup(), $ghGDIPDll is defined
    $aRet = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushFromRect", "ptr", $pRect, "int", $iArgb1, _
            "int", $iArgb2, "int", $LinearGradientMode, "int", $WrapMode, "int*", 0)

    If IsArray($aFactors) = 0 Then Dim $aFactors[4] = [0.0, 0.4, 0.6, 1.0]
    If IsArray($aPositions) = 0 Then Dim $aPositions[4] = [0.0, 0.3, 0.7, 1.0]

    $iCount = UBound($aPositions)
    $tFactors = DllStructCreate("float[" & $iCount & "]")
    $pFactors = DllStructGetPtr($tFactors)
    For $iI = 0 To $iCount - 1
        DllStructSetData($tFactors, 1, $aFactors[$iI], $iI + 1)
    Next
    $tPositions = DllStructCreate("float[" & $iCount & "]")
    $pPositions = DllStructGetPtr($tPositions)
    For $iI = 0 To $iCount - 1
        DllStructSetData($tPositions, 1, $aPositions[$iI], $iI + 1)
    Next

    $hStatus = DllCall($ghGDIPDll, "int", "GdipSetLineBlend", "hwnd", $aRet[6], _
            "ptr", $pFactors, "ptr", $pPositions, "int", $iCount)
    Return $aRet[6] ; Handle of Line Brush
EndFunc   ;==>_GDIPlus_CreateLineBrushFromRect

Func GDIPlus_SetLineGammaCorrection($hBrush, $useGammaCorrection = True)
    Local $aResult 
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetLineGammaCorrection", "hwnd", $hBrush, "int", $useGammaCorrection)
    Return $aResult[0]
EndFunc   ;==>GDIPlus_SetLineGammaCorrection

Share this post


Link to post
Share on other sites

@Malkey

Do you have a collection somewhere of all your GDI+ functions that are not part of AutoIt? With examples? It's really great stuff.

Share this post


Link to post
Share on other sites

@Zedna

MANY many many thanks, Zedna !!!! You have made a lucky man :)

I could include your code in my final program - amazing to see that it's working now!! -

Now I know:

- how to select the thickness of the pen:

- how to select the pen colour

- how to place the pen at coordinate (x1,y1)

- how to draw a line to the point (x2,y2)

@Malkey

Many thanks to you too Malkey for the excellent GDI examples you are providing. It helps me a lot understanding the GDI concept. Your Gradient stuff is really amazing! :)

Being happy now, I am going to study their working and use them in my AutoIt software o:)

Share this post


Link to post
Share on other sites

From AtoIt 3.2.13.8 are these API functions as standard include files.

So instead of DllCall() you can call _WinAPI_xxx() functions.

_WinAPI_DrawLine($hDC, $iX1, $iY1, $iX2, $iY2)

3.2.13.8 (4th October, 2008) (Beta)

- Added: _WinAPI_CreatePen, _WinAPI_DrawLine, _WinAPI_LineTo, _WinAPI_MoveTo, _WinAPI_GetBkMode, _WinAPI_SetBkMode (Zedna)

Share this post


Link to post
Share on other sites

děkuji mnohokrát za informaci Zedna :) Thanks for the information :)

These new functions will be much easier to use indeed.

Is it safe to upgrade now? It is actually still a beta version...

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

děkuji mnohokrát za informaci Zedna :) Thanks for the information :)

These new functions will be much easier to use indeed.

Is it safe to upgrade now? It is actually still a beta version...

From AutoIt 3.2.13.x version is dropped support for older Win9x/WinNT4.0 OS

Windows 9x and Windows NT 4.0 Operating System support has been removed

So if you don't use these OS'es then don't hesitate and upgrade to latest beta.

Of course you may have installed latest release (3.2.12.1) and latest beta (3.2.13.11) at the same time on your machine without any problems.

Another option is to download latest beta as ZIP file and from Include\WinAPI.au3 file copy these new functions into your script.

Then you may call them also from older AutoIt's version.

BTW: How did you discovered Czech thanks for me o:)  ?

Edited by Zedna

Share this post


Link to post
Share on other sites

Okay Zedna, I have Vista, so I will download and install the last beta version in parallel with the current stable - and see which is the best one :)

*OT*

Myslel jsem, e jsi chytřejí :) I used http://www.lexilogos.com/tcheque_dictionnaire.htm , typed my words in French and clicked on Seznam. Such a dictionary database could be written in AutoIt too. I will try this with Japanese later as I have studied Japanese for 3 years, so I thought why not give it a try... I hope that AutoIt has good support for UTF-8 for the Japanese characters. I already tried to make labels with success. But that's for 2009.... To be continued....

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Okay Zedna, I have Vista, so I will download and install the last beta version in parallel with the current stable - and see which is the best one :)

Also don't forget to download/use also latest Scite4AutoIt3 package which helps a lot

and it supports run/compile release/beta versions.

http://www.autoitscript.com/autoit3/scite/downloads.shtml

*OT*

Myslel jsem, že jsi chytřejší :) I used http://www.lexilogos.com/tcheque_dictionnaire.htm , typed my words in French and clicked on Seznam. Such a dictionary database could be written in AutoIt too. I will try this with Japanese later as I have studied Japanese for 3 years, so I thought why not give it a try... I hope that AutoIt has good support for UTF-8 for the Japanese characters. I already tried to make labels with success. But that's for 2009.... To be continued....

I know about Google Online Translator

http://translate.google.com/translate_t#

But it's not 100% good in gramatics and your Czech sentences are 100% correct so I was curious.

Edited by Zedna

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Bad news is that jpm replied that is NOT possible:

...

Any solution is welcome...

Sigh.

This IS possible.

Here's an example:

#include <GUIConstantsEx.au3>

;--- GUI ---
GUICreate("",300,300)

;--- Background ---
GUICtrlCreatePic("coke.gif",0,0,300,300)

;--- Graphic Control ---
$graph = GUICtrlCreateGraphic(50,50,201,201)
GUICtrlSetBkColor(-1,0xFFFFFF)
GUICtrlSetColor(-1,0x000000)

;--- Some Lines ---
For $i = 1 to 200
    GUICtrlSetGraphic($graph,$GUI_GR_LINE,$i,100 + (Sin($i - 100) * 10))
Next

GUISetState()
While 1
    Sleep(100)
WEnd

Using this background gif:

...Gives this result in windows XP CLASSIC Theme:

See here for explanation:

My thread before it went totally OT

Edited by andybiochem

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

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
Sign in to follow this  
Followers 0