Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: Psyke1 en 12 Diciembre 2010, 22:02 pm



Título: [SRC] [Tip] AlignListBox [by Mr. Frog ©]
Publicado por: Psyke1 en 12 Diciembre 2010, 22:02 pm
Me encontre con estas constantes para alinear un ListBox e hice esta sencilla función, poner en un módulo:
Solo incluyo alineamiento de items a la derecha e izquierda, porque para centrarlos hay que hacerlo de forma diferente. :silbar:
Posteado en http://www.visual-coders.com.ar/

Código
  1. Option Explicit
  2. '=========================================================
  3. ' º Function : AlignListBox
  4. ' º Author   : Mr. Frog ©
  5. ' º Mail     : vbpsyke1@mixmail.com
  6. ' º Recommended Websites :
  7. '       http://visual-coders.com.ar
  8. '       http://InfrAngeluX.Sytes.Net
  9. '       http://twitter.com/#!/PsYkE1
  10. '=========================================================
  11.  
  12. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  13. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  14.  
  15. Private Const GWL_EXSTYLE                       As Long = (-20)
  16. Private Const WS_EX_RIGHT                       As Long = &H1000&
  17. Private Const WS_EX_LEFT                        As Long = &H0&
  18. Private Const WS_EX_LEFTSCROLLBAR               As Long = &H4000&
  19. Private Const WS_EX_RIGHTSCROLLBAR              As Long = &H0&
  20.  
  21. Public Enum AlignConstants
  22.   aLeft = 0
  23.   aRight = 1
  24. End Enum
  25.  
  26. Public Enum OptionAlign
  27.   Items = 0
  28.   ScollBar = 1
  29. End Enum
  30.  
  31. Public Function AlignListBox(ByVal myListBox As ListBox, _
  32.                               ByVal ThingToAlign As OptionAlign, _
  33.                               Optional ByVal Align As AlignConstants = aLeft) As Long
  34. Dim lStyle                                              As Long
  35. Dim lHwnd                                               As Long
  36.    If Not (myListBox Is Nothing) Then
  37.        lHwnd = myListBox.hwnd
  38.        lStyle = GetWindowLong(lHwnd, GWL_EXSTYLE)
  39.        If Align = aRight Then
  40.            If ThingToAlign = Items Then
  41.                lStyle = lStyle Or WS_EX_RIGHT
  42.            Else
  43.                lStyle = lStyle And WS_EX_RIGHTSCROLLBAR
  44.            End If
  45.        Else
  46.            If ThingToAlign = Items Then
  47.                lStyle = lStyle And WS_EX_LEFT
  48.            Else
  49.                lStyle = lStyle Or WS_EX_LEFTSCROLLBAR
  50.            End If
  51.        End If
  52.        AlignListBox = SetWindowLong(lHwnd, GWL_EXSTYLE, lStyle)
  53.    End If
  54. End Function

Ejemplo:

Código
  1. Option Explicit
  2.  
  3. Private Sub Form_Load()
  4. Dim Q                               As Long
  5.    For Q = 0 To (Screen.FontCount - 1)
  6.        List1.AddItem Screen.Fonts(Q)
  7.    Next Q
  8.  
  9.    AlignListBox List1, Items, aRight
  10.    'AlignListBox List1, Items, aLeft
  11.    AlignListBox List1, ScollBar, aLeft
  12.    'AlignListBox List1, ScollBar, aRight
  13. End Sub

Resultado:
(http://img31.imageshack.us/img31/5813/dibujomo.jpg)

DoEvents! :P


Título: Re: [SRC] [Tip] AlignListBox [by Mr. Frog ©]
Publicado por: agus0 en 13 Diciembre 2010, 03:14 am
Gracias por compartir Mr. Frog... Te diste por venisido con mi programa???  :laugh:


Título: Re: [SRC] [Tip] AlignListBox [by Mr. Frog ©]
Publicado por: Psyke1 en 13 Diciembre 2010, 03:19 am
De nada... ;)
Ahora estoy acabando una cosa similar de una manera NUNCA vista. :)
Gracias por compartir Mr. Frog... Te diste por venisido con mi programa???  :laugh:
:xD
Ya lo hable con Dessa, eso solo te pasa a ti, no tengo W7 para probarlo, en Wxp ya te dije que me va bien. :silbar:

DoEvents! :P


Título: Re: [SRC] [Tip] AlignListBox [by Mr. Frog ©]
Publicado por: agus0 en 13 Diciembre 2010, 03:36 am
De nada... ;)
Ahora estoy acabando una cosa similar de una manera NUNCA vista. :):xD
Ya lo hable con Dessa, eso solo te pasa a ti, no tengo W7 para probarlo, en Wxp ya te dije que me va bien. :silbar:

DoEvents! :P

Como Programador, hay que depurar el Software para todos los Sistemas, ademas, Con mas razón siendo W$7 el que falla, por que es el mas actual Jajaja