Jump to content

Recommended Posts

Posted

Just Wanted to know if it worked, because when i tried it did not work for me. basically i wanted to create a gradient for a program which supports the older systems.

Posted

On Win2000 you need to install gdi32.dll or gdiplus.dll to system32 folder. I don't think GDIPlus works before Win2000.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Posted

Does anyone have any idea of getting gradient by means of other methods. I came up with a solution which is just to create a gradient photo on a higher version of Autoit and windows and then use for the older windows but its NOT a good solution.

Posted

I have this in archived code but I forget who wrote it. I's using labels but you might get some ideas from it.

#NoTrayIcon
#include <GUIConstants.au3>
;/// Settings Here ///
$NumberOfGradients = 200
$SizeOfLayer = 1
;/////////////////////
GUICreate("Gradients", $NumberOfGradients*$SizeOfLayer, 70, -1, -1)
Dim $Label[$NumberOfGradients]
For $i = 0 To $NumberOfGradients-1
$Label[$i] = GUICtrlCreateLabel("", $i*$SizeOfLayer, 0, 10, 50)
Next
$Button = GUICtrlCreateButton("Random Gradient", 0, 50, $NumberOfGradients*$SizeOfLayer, 20)
GUISetState()
While 1
Switch GUIGetMsg()
  Case -3;$GUI_EVENT_CLOSE
   Exit
  Case $Button
   $Color = ColorGradient(RandomColor(), RandomColor(), $NumberOfGradients)
   For $i = 0 To $NumberOfGradients-1
    GUICtrlSetBkColor($Label[$i], $Color[$i])
   Next
EndSwitch
WEnd
Func ColorGradient($hInitialColor, $hFinalColor, $iReturnSize)
$hInitialColor = Hex($hInitialColor, 6)
$hFinalColor = Hex($hFinalColor, 6)

Local $iRed1 = Dec (StringLeft($hInitialColor, 2))
Local $iGreen1 = Dec (StringMid($hInitialColor, 3, 2))
Local $iBlue1 = Dec (StringMid($hInitialColor, 5, 2))

Local $iRed2 = Dec (StringLeft($hFinalColor, 2))
Local $iGreen2 = Dec (StringMid($hFinalColor, 3, 2))
Local $iBlue2 = Dec (StringMid($hFinalColor, 5, 2))

Local $iPlusRed = ($iRed2-$iRed1)/($iReturnSize-1)
Local $iPlusBlue = ($iBlue2-$iBlue1)/($iReturnSize-1)
Local $iPlusGreen = ($iGreen2-$iGreen1)/($iReturnSize-1)

Dim $iColorArray[$iReturnSize]
For $i = 0 To $iReturnSize-1
  $iNowRed = Floor($iRed1 + ($iPlusRed*$i))
  $iNowBlue = Floor($iBlue1 + ($iPlusBlue*$i))
  $iNowGreen = Floor($iGreen1 + ($iPlusGreen*$i))
  $iColorArray[$i] = Dec (Hex($iNowRed, 2) & Hex($iNowGreen, 2) & Hex($iNowBlue, 2))
Next
Return ($iColorArray)
EndFunc
Func RandomColor($hMinColor = 0x000000, $hMaxColor = 0xFFFFFF)
$hMinColor = Hex($hMinColor, 6)
$hMaxColor = Hex($hMaxColor, 6)

Local $iRed1 = Dec (StringLeft($hMinColor, 2))
Local $iGreen1 = Dec (StringMid($hMinColor, 3, 2))
Local $iBlue1 = Dec (StringMid($hMinColor, 5, 2))

Local $iRed2 = Dec (StringLeft($hMaxColor, 2))
Local $iGreen2 = Dec (StringMid($hMaxColor, 3, 2))
Local $iBlue2 = Dec (StringMid($hMaxColor, 5, 2))

Local $iRndRed = Random($iRed1, $iRed2, 1)
Local $iRndGreen = Random($iGreen1, $iGreen2, 1)
Local $iRndBlue = Random($iBlue1, $iBlue2, 1)

Return Dec (Hex($iRndRed, 2) & Hex($iRndGreen, 2) & Hex($iRndBlue, 2))
EndFunc

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Posted (edited)

@Aipion

This old example uses the native graphic control and would work in v3.2.12.1

For more gradient examples that will work with older AutoIt versions and OS's, use the forum advanced search for 'Gradient' and posts from 2007 and earlier

I don't know who wrote this, some examples of _GUICtrlCreateGradient() on the forum go back to 2005

_GUICtrlCreateGradient() author: Gary Frost

Yashied's WinAPIEx has some GDI gradient examples that would run on older older OS's and Autoit versions

some modification of the code will be required to work with older AutoIt versions

; Gradient 2 - Graphic
#include <WindowsConstants.au3> ;Newer AutoIt versions
#include <GuiConstants.au3> ;Older AutoIt include has WM_ constants
#include <Color.au3>

;~ Global $GUI_GR_LINE      = 2
;~ Global $GUI_GR_MOVE      = 6
;~ Global $GUI_GR_COLOR = 8
Global Const $G_VERTICAL = 1
Global Const $G_HORIZONTAL = 2

CreateWindow()

Do
Until GUIGetMsg() = -3

Func CreateWindow()
Local $iColTop = 0x0000FF
Local $iColBtm = 0xFFFFFF
Local $GUI_Width = 300
Local $GUI_Height = 400
GUICreate("Gradient Demo", $GUI_Width, $GUI_Height, (@DesktopWidth - $GUI_Width) / 2, (@DesktopHeight - $GUI_Height) / 2, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS)
_GUICtrlCreateGradient($iColTop, $iColBtm, 0, 0, $GUI_Width, $GUI_Height, $G_HORIZONTAL)
GUISetState()
EndFunc   ;==>CreateWindow

Func _GUICtrlCreateGradient($nStartColor, $nEndColor, $nX, $nY, $nWidth = 255, $nHeight = 20, $n_type = 1)
;Gary Frost
;[url="http://www.autoitscript.com/forum/topic/30907-color-gradients-easy/page__view__findpost__p__221361"]http://www.autoitscript.com/forum/topic/30907-color-gradients-easy/page__view__findpost__p__221361[/url]

Local $colorR = _ColorGetRed($nStartColor)
Local $colorG = _ColorGetGreen($nStartColor)
Local $colorB = _ColorGetBlue($nStartColor)
Local $nStepR, $nStepG, $nStepB, $sColor
GUICtrlCreateGraphic($nX, $nY, $nWidth, $nHeight)
Select
  Case $n_type = $G_VERTICAL
   $nStepR = (_ColorGetRed($nEndColor) - $colorR) / $nWidth
   $nStepG = (_ColorGetGreen($nEndColor) - $colorG) / $nWidth
   $nStepB = (_ColorGetBlue($nEndColor) - $colorB) / $nWidth
   For $i = 0 To $nWidth
    $sColor = "0x" & StringFormat("%02X%02X%02X", $colorR + $nStepR * $i, $colorG + $nStepG * $i, $colorB + $nStepB * $i)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $sColor, 0xFFFFFF)
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $i, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, $i, $nHeight)
   Next
  Case $n_type = $G_HORIZONTAL
   $nStepR = (_ColorGetRed($nEndColor) - $colorR) / $nHeight
   $nStepG = (_ColorGetGreen($nEndColor) - $colorG) / $nHeight
   $nStepB = (_ColorGetBlue($nEndColor) - $colorB) / $nHeight
   For $i = 0 To $nHeight
    $sColor = "0x" & StringFormat("%02X%02X%02X", $colorR + $nStepR * $i, $colorG + $nStepG * $i, $colorB + $nStepB * $i)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $sColor, 0xFFFFFF)
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, $nWidth, $i)
   Next
EndSelect
EndFunc   ;==>_GUICtrlCreateGradient
Edited by rover

I see fascists...

Posted

More GDIP info for you

GDI+ can be used in all Windows-based applications. GDI+ is new technology that is included in Windows XP and Windows Server 2003. It is required as a redistributable for applications that run on the Microsoft Windows NT 4.0 SP6, Windows 2000, Windows 98, and Windows Millennium Edition (Windows Me) operating systems.

GDI+ functions and classes are not supported for use within a Windows service. Attempting to use these functions and classes from a Windows service may produce unexpected problems, such as diminished service performance and run-time exceptions or errors.

Note When you use the GDI+ API, you must never allow your application to download arbitrary fonts from untrusted sources. The operating system requires elevated privileges to assure that all installed fonts are trusted.

Source: http://msdn.microsoft.com/en-us/library/ms533798(v=vs.85).aspx

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Posted

Thanks @rover & @GEOSoft both of your codes worked, thanks very much.

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