{"id":465,"date":"2009-10-06T08:14:52","date_gmt":"2009-10-06T11:14:52","guid":{"rendered":"http:\/\/leandroascierto.com\/blog\/?p=465"},"modified":"2011-08-27T08:22:11","modified_gmt":"2011-08-27T11:22:11","slug":"dibujar-lineas-con-las-apis-de-windows","status":"publish","type":"post","link":"https:\/\/leandroascierto.com\/blog\/dibujar-lineas-con-las-apis-de-windows\/","title":{"rendered":"Dibujar l\u00edneas con las Apis de Windows"},"content":{"rendered":"<p style=\"text-align: justify;\">Una funci\u00f3n para tener siempre a mano, sobre todo para cuando trabajemos con hdc en memoria.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOption Explicit\r\nPrivate Declare Function OleTranslateColor Lib &quot;oleaut32.dll&quot; (ByVal lOleColor As Long, ByVal lHPalette As Long, lColorRef 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 MoveToEx Lib &quot;gdi32&quot; (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal lpPoint As Long) As Long\r\nPrivate Declare Function DeleteObject Lib &quot;gdi32.dll&quot; (ByVal hObject 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 LineTo Lib &quot;gdi32.dll&quot; (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long\r\n \r\n \r\nPublic Sub DrawLine(ByVal hdc As Long, _\r\n                    ByVal X1 As Long, _\r\n                    ByVal Y1 As Long, _\r\n                    ByVal X2 As Long, _\r\n                    ByVal Y2 As Long, _\r\n                    Optional ByVal Color As Long = -1, _\r\n                    Optional ByVal BorderWidth As Long = 1)\r\n \r\n    Dim hPen As Long\r\n    Dim TransColor As Long\r\n    Dim OldPen As Long\r\n \r\n    If Color &lt;&gt; -1 Then\r\n        Call OleTranslateColor(Color, 0&amp;, TransColor)\r\n        hPen = CreatePen(0, BorderWidth, TransColor)\r\n        OldPen = SelectObject(hdc, hPen)\r\n    End If\r\n \r\n    If X1 &gt;= 0 Then\r\n        MoveToEx hdc, X1, Y1, 0\r\n    End If\r\n \r\n    LineTo hdc, X2, Y2\r\n \r\n    If hPen &lt;&gt; 0 Then\r\n        SelectObject hdc, OldPen\r\n        DeleteObject hPen\r\n    End If\r\n \r\nEnd Sub\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Una funci\u00f3n para tener siempre a mano, sobre todo para cuando trabajemos con hdc en memoria. Option Explicit Private Declare Function OleTranslateColor Lib &quot;oleaut32.dll&quot; (ByVal lOleColor As Long, ByVal lHPalette As Long, lColorRef As Long) As Long Private Declare Function CreatePen Lib &quot;gdi32.dll&quot; (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) <a href='https:\/\/leandroascierto.com\/blog\/dibujar-lineas-con-las-apis-de-windows\/' 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-465","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\/465","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=465"}],"version-history":[{"count":2,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/465\/revisions"}],"predecessor-version":[{"id":510,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/465\/revisions\/510"}],"wp:attachment":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/media?parent=465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/categories?post=465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/tags?post=465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}