{"id":377,"date":"2009-04-19T00:21:32","date_gmt":"2009-04-19T03:21:32","guid":{"rendered":"http:\/\/leandroascierto.com\/blog\/?p=377"},"modified":"2011-08-27T08:34:18","modified_gmt":"2011-08-27T11:34:18","slug":"fillrectex","status":"publish","type":"post","link":"https:\/\/leandroascierto.com\/blog\/fillrectex\/","title":{"rendered":"FillRectEx"},"content":{"rendered":"<p style=\"text-align: justify;\">Funci\u00f3n para rellenar un rect\u00e1ngulo en un hdc con parte o el total de otro hdc, la funci\u00f3n es muy r\u00e1pida en dibujar.<\/p>\n<p align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.leandroascierto.com\/blog\/imagenes\/fill_rect_ex.gif\" alt=\"Fill Rect Ex\" width=\"331\" height=\"266\" \/><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n\r\nOption Explicit\r\n' --------------------------------\r\n' Autor Leandro Ascierto\r\n' --------------------------------\r\nPrivate Declare Function GetDC Lib &quot;user32&quot; (ByVal hwnd As Long) As Long\r\nPrivate Declare Function CreateCompatibleDC Lib &quot;gdi32&quot; (ByVal hdc As Long) As Long\r\nPrivate Declare Function CreateCompatibleBitmap Lib &quot;gdi32&quot; (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long\r\nPrivate Declare Function SelectObject Lib &quot;gdi32&quot; (ByVal hdc As Long, ByVal hObject As Long) As Long\r\nPrivate Declare Function DeleteDC Lib &quot;gdi32&quot; (ByVal hdc As Long) As Long\r\nPrivate Declare Function DeleteObject Lib &quot;gdi32.dll&quot; (ByVal hObject As Long) As Long\r\nPrivate Declare Function CreatePatternBrush Lib &quot;gdi32.dll&quot; (ByVal hBitmap As Long) As Long\r\nPrivate Declare Function FillRect Lib &quot;user32&quot; (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long\r\nPrivate Declare Function SetRect Lib &quot;user32&quot; (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long\r\nPrivate Declare Function BitBlt Lib &quot;gdi32&quot; (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long\r\nPrivate Declare Function SetBrushOrgEx Lib &quot;gdi32.dll&quot; (ByVal hdc As Long, ByVal nXOrg As Long, ByVal nYOrg As Long, ByRef lppt As POINTAPI) As Long\r\nPrivate Declare Function ReleaseDC Lib &quot;user32.dll&quot; (ByVal hwnd As Long, ByVal hdc As Long) As Long\r\n\r\nPrivate Type POINTAPI\r\n    x As Long\r\n    y As Long\r\nEnd Type\r\n\r\nPrivate Type RECT\r\n    Left As Long\r\n    Top As Long\r\n    Right As Long\r\n    Bottom As Long\r\nEnd Type\r\n\r\n' Funci\u00f3n que rellena un hdc con el contenido de otro en forma repetitiva\r\nPrivate Sub FillRectEx(DestDC As Long, DestX As Long, DestY As Long, DestWidth As Long, DestHeight As Long, SrcDC As Long, SrcX As Long, SrcY As Long, SrcWidth As Long, SrcHeight As Long)\r\n\r\n    Dim DC As Long\r\n    Dim hDCMemory As Long\r\n    Dim hBmp As Long\r\n    Dim OldhBmp As Long\r\n    Dim hBrush As Long\r\n    Dim Rec As RECT\r\n    Dim PT As POINTAPI\r\n\r\n    DC = GetDC(0)\r\n    hDCMemory = CreateCompatibleDC(0)\r\n    hBmp = CreateCompatibleBitmap(DC, SrcWidth, SrcHeight)\r\n    ReleaseDC 0&amp;, DC\r\n    OldhBmp = SelectObject(hDCMemory, hBmp)\r\n    BitBlt hDCMemory, 0, 0, SrcWidth, SrcHeight, SrcDC, SrcX, SrcY, vbSrcCopy\r\n    hBrush = CreatePatternBrush(hBmp)\r\n    SetRect Rec, DestX, DestY, DestWidth + DestX, DestHeight + DestY\r\n\r\n    SetBrushOrgEx hdc, DestX, DestY, PT\r\n    FillRect DestDC, Rec, hBrush\r\n    SetBrushOrgEx hdc, PT.x, PT.y, PT\r\n\r\n    DeleteObject hBrush\r\n    DeleteObject SelectObject(hDCMemory, OldhBmp)\r\n    DeleteDC hDCMemory\r\n End Sub\r\n\r\nPrivate Sub Form_Load()\r\n    With Picture1\r\n        .Visible = False\r\n        .AutoSize = True\r\n        .ScaleMode = vbPixels\r\n        .AutoRedraw = True\r\n        .Picture = Me.Icon\r\n    End With\r\nEnd Sub\r\n\r\nPrivate Sub Form_Paint()\r\n    FillRectEx Me.hdc, 0, 0, Me.ScaleWidth, Me.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight\r\nEnd Sub\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Funci\u00f3n para rellenar un rect\u00e1ngulo en un hdc con parte o el total de otro hdc, la funci\u00f3n es muy r\u00e1pida en dibujar. Option Explicit &#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8216; Autor Leandro Ascierto &#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; Private Declare Function GetDC Lib &quot;user32&quot; (ByVal hwnd As Long) As Long Private Declare Function CreateCompatibleDC Lib &quot;gdi32&quot; (ByVal hdc As Long) <a href='https:\/\/leandroascierto.com\/blog\/fillrectex\/' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[73],"class_list":["post-377","post","type-post","status-publish","format-standard","hentry","category-graficos","tag-gdi32","category-41-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/comments?post=377"}],"version-history":[{"count":4,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/377\/revisions"}],"predecessor-version":[{"id":540,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/377\/revisions\/540"}],"wp:attachment":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/media?parent=377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/categories?post=377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/tags?post=377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}