{"id":367,"date":"2009-04-19T23:54:57","date_gmt":"2009-04-20T02:54:57","guid":{"rendered":"http:\/\/leandroascierto.com\/blog\/?p=367"},"modified":"2011-08-27T08:35:43","modified_gmt":"2011-08-27T11:35:43","slug":"texto-espejado","status":"publish","type":"post","link":"https:\/\/leandroascierto.com\/blog\/texto-espejado\/","title":{"rendered":"Texto Espejado"},"content":{"rendered":"<p style=\"text-align: justify;\">Esta es una funci\u00f3n que se encarga de dibujar un texto con un efecto espejado al estilo Windows Vista.<\/p>\n<p style=\"text-align: justify;\" align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.leandroascierto.com\/blog\/imagenes\/texto_espejado.png\" alt=\"Texto Espejado\" width=\"436\" height=\"400\" \/><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n'-----------------------------'\r\n'Autor: Leandro Ascierto\r\n'Fecha: 27\/11\/2008\r\n'Tercera Revision\r\n'-----------------------------'\r\n\r\nOption Explicit\r\nPrivate Declare Function GetTextMetrics Lib &quot;gdi32.dll&quot; Alias &quot;GetTextMetricsA&quot; (ByVal hdc As Long, ByRef lpMetrics As TEXTMETRIC) As Long\r\nPrivate Declare Function AlphaBlend Lib &quot;msimg32.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 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 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 DeleteDC Lib &quot;gdi32.dll&quot; (ByVal hdc As Long) As Long\r\nPrivate Declare Function GetDC Lib &quot;user32.dll&quot; (ByVal hwnd As Long) As Long\r\nPrivate Declare Function StretchBlt 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 dwRop As Long) As Long\r\nPrivate Declare Function DrawText Lib &quot;user32.dll&quot; Alias &quot;DrawTextA&quot; (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, ByRef lpRect As RECT, ByVal wFormat As Long) As Long\r\nPrivate Declare Function SetBkMode Lib &quot;gdi32.dll&quot; (ByVal hdc As Long, ByVal nBkMode As Long) As Long\r\nPrivate Declare Function GetBkMode Lib &quot;gdi32.dll&quot; (ByVal hdc As Long) As Long\r\nPrivate Declare Function GetCurrentObject Lib &quot;gdi32.dll&quot; (ByVal hdc As Long, ByVal uObjectType As Long) As Long\r\nPrivate Declare Function GetTextColor 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 SetTextColor Lib &quot;gdi32.dll&quot; (ByVal hdc As Long, ByVal crColor As Long) As Long\r\nPrivate Declare Function OffsetRect Lib &quot;user32&quot; (lpRect As RECT, ByVal x As Long, ByVal y 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\nPrivate Declare Sub RtlMoveMemory Lib &quot;kernel32.dll&quot; (Destination As Any, Source As Any, ByVal Length As Long)\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 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\nPrivate Type TEXTMETRIC\r\n    tmHeight As Long\r\n    tmAscent As Long\r\n    tmDescent As Long\r\n    tmInternalLeading As Long\r\n    tmExternalLeading As Long\r\n    tmAveCharWidth As Long\r\n    tmMaxCharWidth As Long\r\n    tmWeight As Long\r\n    tmOverhang As Long\r\n    tmDigitizedAspectX As Long\r\n    tmDigitizedAspectY As Long\r\n    tmFirstChar As Byte\r\n    tmLastChar As Byte\r\n    tmDefaultChar As Byte\r\n    tmBreakChar As Byte\r\n    tmItalic As Byte\r\n    tmUnderlined As Byte\r\n    tmStruckOut As Byte\r\n    tmPitchAndFamily As Byte\r\n    tmCharSet As Byte\r\nEnd Type\r\n\r\nPrivate Const DT_CALCRECT           As Long = &amp;H400\r\nPrivate Const DT_BOTTOM             As Long = &amp;H8\r\nPrivate Const DT_SINGLELINE         As Long = &amp;H20\r\nPrivate Const OBJ_FONT              As Long = 6\r\nPrivate Const AC_SRC_OVER           As Long = &amp;H0\r\n\r\nPublic Enum tShadowDirection\r\n    sdCenter = 0\r\n    sdLeft = 1\r\n    sdRight = 2\r\n    sdInside = 3\r\n    sdOutside = 4\r\nEnd Enum\r\n\r\nPublic Enum tPercent\r\n    Percent100 = 0\r\n    Percent75 = 1\r\n    Percent50 = 2\r\n    Percent25 = 3\r\nEnd Enum\r\n\r\nPublic Function DrawTextReflecion(DestDC As Long, _\r\n                        ByVal x As Long, _\r\n                        ByVal y As Long, _\r\n                        Text As String, _\r\n                        Optional ByVal IgnoreTMDescent As Boolean, _\r\n                        Optional ByVal WaveIntesity As Long, _\r\n                        Optional ByVal ShadowDirection As tShadowDirection, _\r\n                        Optional ByVal Color As OLE_COLOR = -1, _\r\n                        Optional ByVal ShadowPecent As tPercent = Percent75, _\r\n                        Optional ByVal BackLight As Boolean = True)\r\n\r\n    Dim ShadowLeft As Long, ShadowRight As Long\r\n    Dim Left As Long, Top As Long, Width As Long, Height As Long\r\n    Dim DC As Long, MemDC As Long, hBmp As Long, OldhBmp As Long, OldhFont As Long\r\n    Dim BF As BLENDFUNCTION, lBF As Long\r\n    Dim TM As TEXTMETRIC\r\n    Dim Rec As RECT\r\n    Dim i As Integer\r\n\r\n    Dim Percent As Single\r\n\r\n    'Calculamos el tama\u00f1o del texto\r\n    DrawText DestDC, Text, Len(Text), Rec, DT_CALCRECT\r\n\r\n    Width = Rec.Right\r\n    Height = Rec.Bottom\r\n\r\n    'Creamos un Bitmap\r\n    DC = GetDC(0)\r\n    MemDC = CreateCompatibleDC(DC)\r\n    hBmp = CreateCompatibleBitmap(DC, Width, Height)\r\n    OldhBmp = SelectObject(MemDC, hBmp)\r\n    ReleaseDC 0&amp;, DC\r\n\r\n    'Copiamos la fuente de destino\r\n    OldhFont = SelectObject(MemDC, GetCurrentObject(DestDC, OBJ_FONT))\r\n\r\n    'Copiamos el BackMode de destino\r\n    SetBkMode MemDC, GetBkMode(DestDC)\r\n\r\n    'Copiamos el color de texto de destino\r\n    SetTextColor MemDC, IIf(Color &lt;&gt; -1, Color, GetTextColor(DestDC))\r\n\r\n    'Tomamos una captura del destino\r\n    StretchBlt MemDC, 0, 0, Width, Height, DestDC, x, y + Height * 2, Width, -Height, vbSrcCopy\r\n\r\n    OffsetRect Rec, 0, 0\r\n    'dibujamos el texto\r\n    DrawText MemDC, Text, Len(Text), Rec, DT_BOTTOM Or DT_SINGLELINE\r\n\r\n    'obtenemos informacion de la metrica de la fuente.\r\n    GetTextMetrics MemDC, TM\r\n\r\n    Select Case ShadowPecent\r\n        Case 0: Percent = TM.tmAscent \/ 1\r\n        Case 1: Percent = TM.tmAscent \/ 1.25\r\n        Case 2: Percent = TM.tmAscent \/ 1.65\r\n        Case 3: Percent = TM.tmAscent \/ 2\r\n        Case Else: Percent = TM.tmAscent\r\n    End Select\r\n\r\n    'pintamos el hdc utilizando AlphaBlend para provocar el espejado.\r\n    For i = TM.tmDescent To Percent\r\n        With BF\r\n            .BlendOp = AC_SRC_OVER\r\n            .SourceConstantAlpha = Abs(200 - ((20 * i) \/ Percent) * 10)\r\n        End With\r\n        RtlMoveMemory lBF, BF, 4\r\n\r\n        Select Case ShadowDirection\r\n            Case 1\r\n                ShadowLeft = -i + TM.tmDescent\r\n            Case 2\r\n                ShadowLeft = i - TM.tmDescent\r\n            Case 3\r\n                ShadowLeft = -i + TM.tmDescent\r\n                ShadowRight = (i - TM.tmDescent) * 2\r\n            Case 4\r\n                ShadowLeft = i - TM.tmDescent\r\n                ShadowRight = -(i - TM.tmDescent) * 2\r\n        End Select\r\n\r\n        Top = y + Height - 1\r\n        Left = x - (Rnd(i) * WaveIntesity) + ShadowLeft\r\n        AlphaBlend DestDC, Left, Top + IIf(BackLight, i, -i), Width + ShadowRight, 1, MemDC, 0, Height - i, Width, 1, lBF\r\n    Next\r\n\r\n    OffsetRect Rec, x, y + IIf(IgnoreTMDescent And BackLight, TM.tmDescent * 2, 0)\r\n\r\n    'Bibujamos el texto original\r\n    DrawText DestDC, Text, Len(Text), Rec, DT_BOTTOM Or DT_SINGLELINE\r\n\r\n    'limpiamos la memoria\r\n    SelectObject MemDC, OldhFont\r\n    SelectObject MemDC, OldhBmp\r\n    DeleteDC MemDC\r\n    DeleteObject hBmp\r\nEnd Function\r\n<\/pre>\n<\/p>\n<p align=\"center\"><a href=\"https:\/\/leandroascierto.com\/blog\/descarga.php?url=Texto Espejado.zip\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" title=\"Descargar\" src=\"https:\/\/leandroascierto.com\/blog\/descarga.php?file=Texto Espejado.zip\" alt=\"\" width=\"280\" height=\"61\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Esta es una funci\u00f3n que se encarga de dibujar un texto con un efecto espejado al estilo Windows Vista. &#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#8216; &#8216;Autor: Leandro Ascierto &#8216;Fecha: 27\/11\/2008 &#8216;Tercera Revision &#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#8216; Option Explicit Private Declare Function GetTextMetrics Lib &quot;gdi32.dll&quot; Alias &quot;GetTextMetricsA&quot; (ByVal hdc As Long, ByRef lpMetrics As TEXTMETRIC) As Long Private Declare Function AlphaBlend Lib &quot;msimg32.dll&quot; (ByVal <a href='https:\/\/leandroascierto.com\/blog\/texto-espejado\/' 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":[74,73],"class_list":["post-367","post","type-post","status-publish","format-standard","hentry","category-graficos","tag-drawtext","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\/367","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=367"}],"version-history":[{"count":3,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/367\/revisions"}],"predecessor-version":[{"id":543,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/posts\/367\/revisions\/543"}],"wp:attachment":[{"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/media?parent=367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/categories?post=367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leandroascierto.com\/blog\/wp-json\/wp\/v2\/tags?post=367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}