{"id":375,"date":"2009-05-01T00:19:12","date_gmt":"2009-05-01T03:19:12","guid":{"rendered":"http:\/\/leandroascierto.com\/blog\/?p=375"},"modified":"2011-08-27T08:32:21","modified_gmt":"2011-08-27T11:32:21","slug":"drawalphaselection","status":"publish","type":"post","link":"https:\/\/leandroascierto.com\/blog\/drawalphaselection\/","title":{"rendered":"DrawAlphaSelection"},"content":{"rendered":"<p style=\"text-align: justify;\">Esta es una funci\u00f3n para dibujar una selecci\u00f3n al estilo Windows XP.<\/p>\n<p align=\"center\">\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.leandroascierto.com\/blog\/imagenes\/draw_alpha_selection.gif\" alt=\"Draw Alpha Selection\" width=\"319\" height=\"316\" \/><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n\r\nOption Explicit\r\n \r\n'=========Gdi32 Api========\r\nPrivate Declare Function Rectangle Lib &quot;gdi32&quot; (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long\r\nPrivate Declare Function CreateCompatibleDC Lib &quot;gdi32.dll&quot; (ByVal hdc As Long) As Long\r\nPrivate Declare Function CreateCompatibleBitmap Lib &quot;gdi32.dll&quot; (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long\r\nPrivate Declare Function DeleteObject Lib &quot;gdi32.dll&quot; (ByVal hObject As Long) As Long\r\nPrivate Declare Function DeleteDC Lib &quot;gdi32.dll&quot; (ByVal hdc As Long) As Long\r\nPrivate Declare Function GdiAlphaBlend Lib &quot;gdi32.dll&quot; (ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal hdc As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal lInt As Long, ByVal BLENDFUNCT As Long) As Long\r\nPrivate Declare Function CreatePen Lib &quot;gdi32.dll&quot; (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long\r\nPrivate Declare Function CreateSolidBrush Lib &quot;gdi32.dll&quot; (ByVal crColor As Long) As Long\r\n'=========user32 Api========\r\nPrivate Declare Function GetDC Lib &quot;user32.dll&quot; (ByVal hwnd As Long) 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\n'=========Oleaut32 Api========\r\nPrivate Declare Function OleTranslateColor Lib &quot;oleaut32.dll&quot; (ByVal lOleColor As Long, ByVal lHPalette As Long, ByVal lColorRef As Long) As Long\r\n \r\n'=========Kernel32 Api========\r\nPrivate Declare Sub CopyMemory Lib &quot;kernel32&quot; Alias &quot;RtlMoveMemory&quot; (ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)\r\nPrivate Declare Function SelectObject Lib &quot;gdi32.dll&quot; (ByVal hdc As Long, ByVal hObject As Long) As Long\r\n \r\nPrivate Type UcsRgbQuad\r\n    R                       As Byte\r\n    G                       As Byte\r\n    B                       As Byte\r\n    a                       As Byte\r\nEnd Type\r\n \r\nPrivate Type BLENDFUNCTION\r\n    BlendOp                 As Byte\r\n    BlendFlags              As Byte\r\n    SourceConstantAlpha     As Byte\r\n    AlphaFormat             As Byte\r\nEnd Type\r\n \r\nPrivate Sub DrawAlphaSelection(hdc As Long, ByVal X As Long, ByVal y As Long, ByVal Width As Long, ByVal Height As Long, ByVal Color As OLE_COLOR)\r\n \r\n    Dim BF                  As BLENDFUNCTION\r\n    Dim hDCMemory           As Long\r\n    Dim hBmp                As Long\r\n    Dim hOldBmp             As Long\r\n    Dim DC                  As Long\r\n    Dim lColor              As Long\r\n    Dim hPen                As Long\r\n    Dim hBrush              As Long\r\n    Dim lBF                 As Long\r\n \r\n    BF.SourceConstantAlpha = 128\r\n \r\n    DC = GetDC(0)\r\n    hDCMemory = CreateCompatibleDC(0)\r\n    hBmp = CreateCompatibleBitmap(DC, Width, Height)\r\n    hOldBmp = SelectObject(hDCMemory, hBmp)\r\n \r\n    hPen = CreatePen(0, 1, Color)\r\n    hBrush = CreateSolidBrush(pvAlphaBlend(Color, vbWhite, 120))\r\n    DeleteObject SelectObject(hDCMemory, hBrush)\r\n    DeleteObject SelectObject(hDCMemory, hPen)\r\n    Rectangle hDCMemory, 0, 0, Width, Height\r\n \r\n    CopyMemory VarPtr(lBF), VarPtr(BF), 4\r\n    GdiAlphaBlend hdc, X, y, Width, Height, hDCMemory, 0, 0, Width, Height, lBF\r\n \r\n    SelectObject hDCMemory, hOldBmp\r\n    DeleteObject hBmp\r\n    ReleaseDC 0&amp;, DC\r\n    DeleteDC hDCMemory\r\n    DeleteObject hPen\r\n    DeleteObject hBrush\r\n \r\nEnd Sub\r\n \r\nPrivate Function pvAlphaBlend(ByVal clrFirst As Long, ByVal clrSecond As Long, ByVal lAlpha As Long) As Long\r\n \r\n    Dim clrFore             As UcsRgbQuad\r\n    Dim clrBack             As UcsRgbQuad\r\n \r\n    OleTranslateColor clrFirst, 0, VarPtr(clrFore)\r\n    OleTranslateColor clrSecond, 0, VarPtr(clrBack)\r\n    With clrFore\r\n        .R = (.R * lAlpha + clrBack.R * (255 - lAlpha)) \/ 255\r\n        .G = (.G * lAlpha + clrBack.G * (255 - lAlpha)) \/ 255\r\n        .B = (.B * lAlpha + clrBack.B * (255 - lAlpha)) \/ 255\r\n    End With\r\n    CopyMemory VarPtr(pvAlphaBlend), VarPtr(clrFore), 4\r\n \r\nEnd Function\r\n \r\nPrivate Sub Form_Paint()\r\n    Cls\r\n    DrawAlphaSelection Me.hdc, 10, 50, 100, 200, vbRed\r\n    DrawAlphaSelection Me.hdc, 50, 30, 200, 100, vbBlue\r\n    DrawAlphaSelection Me.hdc, 200, 80, 100, 100, vbGreen\r\n    DrawAlphaSelection Me.hdc, 80, 200, 200, 30, vbYellow\r\n    DrawAlphaSelection Me.hdc, 130, 70, 50, 200, vbMagenta\r\nEnd Sub\r\n<\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Esta es una funci\u00f3n para dibujar una selecci\u00f3n al estilo Windows XP. Option Explicit &#8216;=========Gdi32 Api======== Private Declare Function Rectangle Lib &quot;gdi32&quot; (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long Private Declare Function CreateCompatibleDC Lib &quot;gdi32.dll&quot; (ByVal hdc As Long) As <a href='https:\/\/leandroascierto.com\/blog\/drawalphaselection\/' 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-375","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\/375","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=375"}],"version-history":[{"count":2,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/375\/revisions"}],"predecessor-version":[{"id":537,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/375\/revisions\/537"}],"wp:attachment":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/media?parent=375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/categories?post=375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/tags?post=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}