Jump to content

Recommended Posts

Posted (edited)

MSDN links for CreateHatchBrush and Rectangle API functions

http://msdn.microsoft.com/en-us/library/dd183504%28v=vs.85%29.aspx

http://msdn.microsoft.com/en-us/library/dd162898%28v=vs.85%29.aspx

#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Const $HS_HORIZONTAL = 0
Const $HS_VERTICAL = 1
Const $HS_FDIAGONAL = 2
Const $HS_BDIAGONAL = 3
Const $HS_CROSS = 4
Const $HS_DIAGCROSS = 5

Global $ib_transparent = False

$hGui = GUICreate("Hatch Brushes (GDI)", 400, 400)
$hDC = _WinAPI_GetDC($hGui)
$cbx_transparent = GUICtrlCreateCheckbox('Transparent', 150, 350, 100)
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cbx_transparent
            $ib_transparent = BitAnd(GUICtrlRead($cbx_transparent),$GUI_CHECKED) = $GUI_CHECKED
            _WinAPI_InvalidateRect($hGui)
    EndSwitch
WEnd

Func DrawHatches()
    ; note: colors are in 0xbbggrr format
    _WinAPI_SetBkColor($hDC, 0xFFFF00) ; green-blue

    If $ib_transparent Then
        _WinAPI_SetBkMode($hDC, $TRANSPARENT)
    Else
        _WinAPI_SetBkMode($hDC, $OPAQUE)
    EndIf

    $hBrush = _WinAPI_CreateHatchBrush($HS_HORIZONTAL, 0xFF0000)
    $hOld = _WinAPI_SelectObject($hDC, $hBrush)
    _WinAPI_Rectangle($hDC, 50, 10, 150, 90)
    _WinAPI_SelectObject($hDC, $hOld)
    _WinAPI_DeleteObject($hBrush)

    $hBrush = _WinAPI_CreateHatchBrush($HS_VERTICAL, 0xFF0000)
    $hOld = _WinAPI_SelectObject($hDC, $hBrush)
    _WinAPI_Rectangle($hDC, 250, 10, 350, 90)
    _WinAPI_SelectObject($hDC, $hOld)
    _WinAPI_DeleteObject($hBrush)

    $hBrush = _WinAPI_CreateHatchBrush($HS_FDIAGONAL, 0xFF0000)
    $hOld = _WinAPI_SelectObject($hDC, $hBrush)
    _WinAPI_Rectangle($hDC, 50, 110, 150, 190)
    _WinAPI_SelectObject($hDC, $hOld)
    _WinAPI_DeleteObject($hBrush)

    $hBrush = _WinAPI_CreateHatchBrush($HS_BDIAGONAL, 0xFF0000)
    $hOld = _WinAPI_SelectObject($hDC, $hBrush)
    _WinAPI_Rectangle($hDC, 250, 110, 350, 190)
    _WinAPI_SelectObject($hDC, $hOld)
    _WinAPI_DeleteObject($hBrush)

    $hBrush = _WinAPI_CreateHatchBrush($HS_CROSS, 0xFF0000)
    $hOld = _WinAPI_SelectObject($hDC, $hBrush)
    _WinAPI_Rectangle($hDC, 50, 210, 150, 290)
    _WinAPI_SelectObject($hDC, $hOld)
    _WinAPI_DeleteObject($hBrush)

    $hBrush = _WinAPI_CreateHatchBrush($HS_DIAGCROSS, 0xFF0000)
    $hOld = _WinAPI_SelectObject($hDC, $hBrush)
    _WinAPI_Rectangle($hDC, 250, 210, 350, 290)
    _WinAPI_SelectObject($hDC, $hOld)
    _WinAPI_DeleteObject($hBrush)
EndFunc

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

; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_CreateHatchBrush
; Description ...: Creates a logical brush that has the specified hatch pattern and color
; Syntax.........: _WinAPI_CreateHatchBrush($iStyle, $nColor)
; Parameters ....: $iStyle    - The hatch style of the brush. This parameter can be one of the following values:
;                 |HS_BDIAGONAL  - 45-degree upward left-to-right hatch
;                 |HS_CROSS   - Horizontal and vertical crosshatch
;                 |HS_DIAGCROSS  - 45-degree crosshatch
;                 |HS_FDIAGONAL  - 45-degree downward left-to-right hatch
;                 |HS_HORIZONTAL - Horizontal hatch
;                 |HS_VERTICAL   - Vertical hatch
;                 $nColor     - The foreground color of the brush that is used for the hatches
; Return values .: Success    - HBRUSH Value that identifies a logical brush
;                 Failure     - 0
; Author ........: Zedna
; Modified.......:
; Remarks .......: When you no longer need the HBRUSH object call the _WinAPI_DeleteObject function to delete it
; Related .......: CreateSolidBrush
; Link ..........: @@MsdnLink@@ CreateHatchBrush
; Example .......: Yes
; ===============================================================================================================================
Func _WinAPI_CreateHatchBrush($iStyle, $nColor)
    Local $aResult = DllCall("gdi32.dll", "handle", "CreateHatchBrush", "int", $iStyle, "dword", $nColor)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_CreateHatchBrush

; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_Rectangle
; Description ...: Draws a rectangle, the rectangle is outlined by using the current pen and filled by using the current brush
; Syntax.........: _WinAPI_Rectangle($hDC, $iLeft, $iTop, $iRight, $iBottom)
; Parameters ....: $hDC  - Handle to the device context
;                 $iLeft   - X-coordinate in logical coordinates of the upper-left corner of the rectangle
;                 $iTop - Y-coordinate in logical coordinates of the upper-left corner of the rectangle
;                 $iRight  - X-coordinate in logical coordinates of the lower-right corner of the rectangle
;                 $iBottom - Y-coordinate in logical coordinates of the lower-right corner of the rectangle
; Return values .: Success    - True
;                 Failure     - False
; Author ........: Zedna
; Modified.......:
; Remarks .......: The current position is neither used nor updated by Rectangle.
;                 The rectangle that is drawn excludes the bottom and right edges.
;                 If a PS_NULL pen is used, the dimensions of the rectangle are 1 pixel less in height and 1 pixel less in width.
; Related .......:
; Link ..........: @@MsdnLink@@ Rectangle
; Example .......: Yes
; ===============================================================================================================================
Func _WinAPI_Rectangle($hDC, $iLeft, $iTop, $iRight, $iBottom)
    Local $aResult = DllCall("gdi32.dll", "int", "Rectangle", "handle", $hDC, "int", $iLeft, "int", $iTop, "int", $iRight, "int", $iBottom)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_Rectangle

post-6483-0-16782400-1334252738_thumb.pn

post-6483-0-37717000-1334252800_thumb.pn

Edited by Zedna
Posted

Nice design. Thanks Zedna, I'm sure I'll have some use for those functions.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Posted (edited)

I found also an old script with hatch brush implementation but with GDI+.

;Coded by UEZ 2009.12.06
#include <gdiplus.au3>
Opt("GUIOnEventMode", 1)

_GDIPlus_Startup()
Global $width = @DesktopWidth * 0.75
Global $height = @DesktopHeight * 0.75

Global $hwnd = GUICreate("GDI+: Filled Brushes by UEZ", $width, $height, -1, -1, Default)
GUISetOnEvent(-3, "_Exit")
GUISetState()

Global $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsSetSmoothingMode($graphics, 4)

Global $brush[53]
For $i = 0 To UBound($brush) - 1
    $brush[$i] = _GDIPlus_HatchBrushCreate($i, 0xFF0000FF, 0xFFFFFFFF)
Next

$dx = Int($width / 8)
$dy = Int($height / 7)

_GDIPlus_GraphicsClear($graphics, 0xFF000000)

$k = 0
For $i = 0 To $height -1 Step $dy
    For $j = 0 To $width - 1 Step $dx
        If $k <= UBound($brush) -1 Then _GDIPlus_GraphicsFillEllipse($graphics, $j, $i, $dx, $dy, $brush[$k])
        $k += 1
    Next
Next

While Sleep(15000)
WEnd


Func _Exit()
    For $i = 0 To UBound($brush) - 1
        _GDIPlus_BrushDispose($brush[$i])
    Next
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc

Func _GDIPlus_HatchBrushCreate($iHatchStyle = 0, $iARGBForeground = 0xFFFFFFFF, $iARGBBackground = 0xFF0000FF)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateHatchBrush", "int", $iHatchStyle, "uint", $iARGBForeground, "uint", $iARGBBackground, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return SetError($aResult[0], 0, $aResult[4])
EndFunc   ;==>_GDIPlus_HatchBrushCreate

Br,

UEZ

Edited by UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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