{"id":369,"date":"2009-05-01T23:57:33","date_gmt":"2009-05-02T02:57:33","guid":{"rendered":"http:\/\/leandroascierto.com\/blog\/?p=369"},"modified":"2011-08-27T08:31:06","modified_gmt":"2011-08-27T11:31:06","slug":"drawgrip","status":"publish","type":"post","link":"https:\/\/leandroascierto.com\/blog\/drawgrip\/","title":{"rendered":"DrawGr\u00ecp"},"content":{"rendered":"<p style=\"text-align: justify;\">Esta es una funci\u00f3n simple para dibujar puntos sobre un Formulario, Picture Box o hdc, la funci\u00f3n es r\u00e1pida.<\/p>\n<p align=\"center\">\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.leandroascierto.com\/blog\/imagenes\/draw_grip.gif\" alt=\"Draw Grip\" width=\"350\" height=\"293\" \/><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOption Explicit\r\n\r\n'=========GDI32 Api========\r\nPrivate Declare Function CreateSolidBrush Lib &quot;gdi32.dll&quot; (ByVal crColor As Long) As Long\r\nPrivate Declare Function GetDC Lib &quot;user32.dll&quot; (ByVal hwnd As Long) As Long\r\nPrivate Declare Function SetRect Lib &quot;user32.dll&quot; (ByRef 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 SelectObject Lib &quot;gdi32.dll&quot; (ByVal hdc As Long, ByVal hObject As Long) As Long\r\nPrivate Declare Function DeleteObject Lib &quot;gdi32.dll&quot; (ByVal hObject As Long) As Long\r\nPrivate Declare Function GetDCBrushColor Lib &quot;gdi32.dll&quot; (ByVal hdc As Long) As Long\r\nPrivate Declare Function GetBkColor Lib &quot;gdi32.dll&quot; (ByVal hdc As Long) As Long\r\nPrivate Declare Function SetPixelV Lib &quot;gdi32.dll&quot; (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor 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 CreatePatternBrush Lib &quot;gdi32.dll&quot; (ByVal hBitmap As Long) As Long\r\nPrivate Declare Function DeleteDC Lib &quot;gdi32.dll&quot; (ByVal hdc As Long) As Long\r\nPrivate Declare Function GdiTransparentBlt Lib &quot;gdi32.dll&quot; (ByVal hdc 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 nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean\r\n\r\n'============User32 Api===========\r\nPrivate Declare Function FillRect Lib &quot;user32.dll&quot; (ByVal hdc As Long, ByRef lpRect As RECT, ByVal hBrush As Long) As Long\r\n\r\n'============Estructura Rect========\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\nPublic Function ShiftColor(ByVal clr As Long, ByVal d As Long) As Long\r\n  Dim R As Long, B As Long, G As Long\r\n    R = (clr And &amp;HFF) + d\r\n    G = ((clr \\ &amp;H100) Mod &amp;H100) + d\r\n    B = ((clr \\ &amp;H10000) Mod &amp;H100) + d\r\n    \r\n    If (d &gt; 0) Then\r\n        If (R &gt; &amp;HFF) Then R = &amp;HFF\r\n        If (G &gt; &amp;HFF) Then G = &amp;HFF\r\n        If (B &gt; &amp;HFF) Then B = &amp;HFF\r\n    ElseIf (d &lt; 0) Then\r\n        If (R &lt; 0) Then R = 0\r\n        If (G &lt; 0) Then G = 0\r\n        If (B &lt; 0) Then B = 0\r\n    End If\r\n    ShiftColor = R + &amp;H100&amp; * G + &amp;H10000 * B\r\nEnd Function\r\n\r\nPublic Sub DrawGrip(DestDC As Long, DestX As Long, DestY As Long, DestWidth As Long, DestHeight As Long)\r\n    Dim DC                      As Long\r\n    Dim hDCMemory               As Long\r\n    Dim hBmp                    As Long\r\n    Dim hOldBmp                 As Long\r\n    Dim hBrush                  As Long\r\n    Dim Rec                     As RECT\r\n    Dim lOriginalColor          As Long\r\n    Dim clrHighLight            As Long\r\n    Dim clrShadow               As Long\r\n\r\n    lOriginalColor = GetBkColor(DestDC)\r\n    clrHighLight = ShiftColor(lOriginalColor, &amp;H40)\r\n    clrShadow = ShiftColor(lOriginalColor, -&amp;H40)\r\n    \r\n    DC = GetDC(0)\r\n    hDCMemory = CreateCompatibleDC(0)\r\n    hBmp = CreateCompatibleBitmap(DC, 6, 6)\r\n    hOldBmp = SelectObject(hDCMemory, hBmp)\r\n          \r\n    hBrush = CreateSolidBrush(lOriginalColor)\r\n    SetRect Rec, 0, 0, 6, 6\r\n    FillRect hDCMemory, Rec, hBrush\r\n    DeleteObject hBrush\r\n    \r\n    SetPixelV hDCMemory, 2, 1, clrShadow\r\n    SetPixelV hDCMemory, 1, 2, clrShadow\r\n    SetPixelV hDCMemory, 2, 2, clrShadow\r\n    \r\n    SetPixelV hDCMemory, 0, 0, clrHighLight\r\n    SetPixelV hDCMemory, 1, 0, clrHighLight\r\n    SetPixelV hDCMemory, 0, 1, clrHighLight\r\n    SetPixelV hDCMemory, 1, 1, clrHighLight\r\n    \r\n    SetPixelV hDCMemory, 5, 4, clrShadow\r\n    SetPixelV hDCMemory, 4, 5, clrShadow\r\n    SetPixelV hDCMemory, 5, 5, clrShadow\r\n    \r\n    SetPixelV hDCMemory, 3, 3, clrHighLight\r\n    SetPixelV hDCMemory, 4, 3, clrHighLight\r\n    SetPixelV hDCMemory, 3, 4, clrHighLight\r\n    SetPixelV hDCMemory, 4, 4, clrHighLight\r\n    \r\n    hBrush = CreatePatternBrush(hBmp)\r\n    SelectObject hDCMemory, hOldBmp\r\n    DeleteObject hBmp\r\n    hBmp = CreateCompatibleBitmap(DC, DestWidth, DestHeight)\r\n    hOldBmp = SelectObject(hDCMemory, hBmp)\r\n    SetRect Rec, 0, 0, DestWidth, DestHeight\r\n    FillRect hDCMemory, Rec, hBrush\r\n    \r\n    GdiTransparentBlt DestDC, DestX, DestY, DestWidth, DestHeight, hDCMemory, 0, 0, DestWidth, DestHeight, lOriginalColor\r\n\r\n    DeleteObject hBrush\r\n    SelectObject hDCMemory, hOldBmp\r\n    DeleteObject hBmp\r\n    DeleteDC DC\r\n    DeleteDC hDCMemory    \r\nEnd Sub\r\n\r\nPrivate Sub Form_Paint()\r\n    DrawGrip Me.hdc, 0, 50, Me.ScaleWidth \/ Screen.TwipsPerPixelX, 9\r\n    DrawGrip Me.hdc, 100, 59, 16, Me.ScaleHeight \/ Screen.TwipsPerPixelY - 59\r\nEnd Sub\t\t\t\t\t\t\t\t\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Esta es una funci\u00f3n simple para dibujar puntos sobre un Formulario, Picture Box o hdc, la funci\u00f3n es r\u00e1pida. Option Explicit &#8216;=========GDI32 Api======== Private Declare Function CreateSolidBrush Lib &quot;gdi32.dll&quot; (ByVal crColor As Long) As Long Private Declare Function GetDC Lib &quot;user32.dll&quot; (ByVal hwnd As Long) As Long Private Declare Function SetRect Lib &quot;user32.dll&quot; (ByRef lpRect <a href='https:\/\/leandroascierto.com\/blog\/drawgrip\/' 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-369","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\/369","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=369"}],"version-history":[{"count":2,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/369\/revisions"}],"predecessor-version":[{"id":533,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/369\/revisions\/533"}],"wp:attachment":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/media?parent=369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/categories?post=369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/tags?post=369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}