elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Los 10 CVE más críticos (peligrosos) de 2020


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 2 3 4 5 6 [7] 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ... 59 Ir Abajo Respuesta Imprimir
Autor Tema: Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)  (Leído 485,159 veces)
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #60 en: 8 Abril 2013, 09:09 am »

· Mover un control
Con opciones de Dirección, velocidad, intervalo, timeout, y hacer búcle sobre el form.





Código
  1. #Region " Move control "
  2.  
  3.    ' [ Move control ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MoveControl(Label1, Direction.Right, 100, 1000, 10, True)
  9.    ' MoveControl(Label1, Direction.Left, 1, 9999999, 2, True)
  10.  
  11.    Dim ControlToMove As Control
  12.    Dim ControlLoop As Boolean
  13.    Dim StartMove As New Timer
  14.    Dim EndMove As New Timer
  15.  
  16.    Public Enum Direction
  17.        Up = 1
  18.        Down = 2
  19.        Left = 3
  20.        Right = 4
  21.    End Enum
  22.  
  23.    Public Sub MoveControl(ByVal Control As Control, _
  24.                           ByVal Direction As Direction, _
  25.                           ByVal Interval As Int64, _
  26.                           ByVal TimeOut As Int64, _
  27.                           ByVal Speed As Int16, _
  28.                           ByVal LoopInsideForm As Boolean)
  29.  
  30.        ControlToMove = Control
  31.        ControlLoop = LoopInsideForm
  32.        StartMove.Tag = Direction
  33.        'TimeOut = TimeOut * 1000 ' If want to use seconds instead of Milliseconds.
  34.        StartMove.Interval = Interval
  35.        EndMove.Interval = TimeOut
  36.  
  37.        For x = 1 To Speed ' Add X amount of handles
  38.            AddHandler StartMove.Tick, AddressOf StartMove_Tick
  39.        Next
  40.  
  41.        AddHandler EndMove.Tick, AddressOf EndMove_Tick
  42.        StartMove.Start() : EndMove.Start()
  43.  
  44.    End Sub
  45.  
  46.    ' Start/continue moving
  47.    Private Sub StartMove_Tick(Sender As Object, e As EventArgs)
  48.  
  49.        If ControlLoop Then ' Loop inside form
  50.            Select Case Sender.tag
  51.                Case 1 ' Up
  52.                    If ControlToMove.Location.Y <= (0 - ControlToMove.Size.Height) Then
  53.                        ControlToMove.Location = New Point(ControlToMove.Location.X, Me.Size.Height)
  54.                    End If
  55.                Case 2 ' Down
  56.                    If ControlToMove.Location.Y >= (Me.Size.Height) Then
  57.                        ControlToMove.Location = New Point(ControlToMove.Location.X, -0)
  58.                    End If
  59.                Case 3 ' Left
  60.                    If ControlToMove.Location.X <= (0 - ControlToMove.Size.Width) Then
  61.                        ControlToMove.Location = New Point(Me.Size.Width, ControlToMove.Location.Y)
  62.                    End If
  63.                Case 4 ' Right
  64.                    If ControlToMove.Location.X >= (Me.Size.Width) Then
  65.                        ControlToMove.Location = New Point(-ControlToMove.Width, ControlToMove.Location.Y)
  66.                    End If
  67.            End Select
  68.        End If
  69.  
  70.        Select Case Sender.Tag ' Direction
  71.            Case 1 : ControlToMove.Location = New Point(ControlToMove.Location.X, ControlToMove.Location.Y - 1) ' Up
  72.            Case 2 : ControlToMove.Location = New Point(ControlToMove.Location.X, ControlToMove.Location.Y + 1) ' Down
  73.            Case 3 : ControlToMove.Location = New Point(ControlToMove.Location.X - 1, ControlToMove.Location.Y) ' Left
  74.            Case 4 : ControlToMove.Location = New Point(ControlToMove.Location.X + 1, ControlToMove.Location.Y) ' Right
  75.        End Select
  76.  
  77.    End Sub
  78.  
  79.    ' End Moving
  80.    Private Sub EndMove_Tick(sender As Object, e As EventArgs)
  81.        StartMove.Stop()
  82.        EndMove.Stop()
  83.        RemoveHandler StartMove.Tick, AddressOf StartMove_Tick
  84.        RemoveHandler EndMove.Tick, AddressOf EndMove_Tick
  85.    End Sub
  86.  
  87. #End Region


« Última modificación: 8 Abril 2013, 09:16 am por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #61 en: 8 Abril 2013, 13:09 pm »

Obtener las familias de las fuentes instaladas:

EDITO: MEJORADO Y SIMPLIFICADO

Código
  1. #Region " Get Installed Fonts Function "
  2.  
  3.    ' [ Get Installed Fonts Function ]
  4.    '
  5.    ' Examples :
  6.    ' For Each Font As FontFamily In Get_Installed_Fonts() : MsgBox(Font.Name) : Next
  7.    '
  8.    ' For Each FontFam As FontFamily In Get_Installed_Fonts()
  9.    '     Dim MyFont As New Font(FontFam.Name, 8)
  10.    '     MsgBox(MyFont.Italic)
  11.    '     MsgBox(MyFont.OriginalFontName)
  12.    '     MyFont.Dispose()
  13.    ' Next
  14.  
  15.    Private Function Get_Installed_Fonts() As FontFamily()
  16.        Using AllFonts As New Drawing.Text.InstalledFontCollection ' Get the installed fonts collection.
  17.            Return AllFonts.Families ' Return an array of the system's font familiies.
  18.        End Using
  19.    End Function
  20.  
  21. #End Region





Unas de las típicas y quemadísimas funciones para convertir un string a binário:

Código
  1. #Region " ASCII To Binary Function "
  2.  
  3.    ' [ ASCII To Binary Function ]
  4.    '
  5.    ' Examples :
  6.    ' MsgBox(ASCII_To_Binary("Test"))
  7.  
  8.    Private Function ASCII_To_Binary(ByVal str As String) As String
  9.        Dim Binary_String As String = Nothing
  10.  
  11.        For i As Integer = 0 To str.Length - 1
  12.            Binary_String &= LongToBinary(Asc(str.Substring(i, 1))).Substring(LongToBinary(Asc(str.Substring(i, 1))).Length - 8)
  13.        Next i
  14.  
  15.        Return Binary_String
  16.    End Function
  17.  
  18.    ' Convert this Long value into a Binary string.
  19.    Private Function LongToBinary(ByVal long_value As Long, Optional ByVal separate_bytes As Boolean = True) As String
  20.  
  21.        ' Convert into hex.
  22.        Dim hex_string As String = long_value.ToString("X")
  23.  
  24.        ' Zero-pad to a full 16 characters.
  25.        hex_string = hex_string.PadLeft(16, "0")
  26.  
  27.        ' Read the hexadecimal digits one at a time from right to left.
  28.        Dim result_string As String = ""
  29.        For digit_num As Integer = 0 To 15
  30.  
  31.            ' Convert this hexadecimal digit into a binary nibble.
  32.            Dim digit_value As Integer = Integer.Parse(hex_string.Substring(digit_num, 1), Globalization.NumberStyles.HexNumber)
  33.  
  34.            ' Convert the value into bits.
  35.            Dim factor As Integer = 8
  36.            Dim nibble_string As String = ""
  37.            For bit As Integer = 0 To 3
  38.                If digit_value And factor Then
  39.                    nibble_string &= "1"
  40.                Else
  41.                    nibble_string &= "0"
  42.                End If
  43.                factor \= 2
  44.            Next bit
  45.  
  46.            ' Add the nibble's string to the left of the result string.
  47.            result_string &= nibble_string
  48.        Next digit_num
  49.  
  50.        ' Add spaces between bytes if desired.
  51.        If separate_bytes Then
  52.            Dim tmp As String = ""
  53.            For i As Integer = 0 To result_string.Length - 8 Step 8
  54.                tmp &= result_string.Substring(i, 8) & " "
  55.            Next i
  56.            result_string = tmp.Substring(0, tmp.Length - 1)
  57.        End If
  58.  
  59.        ' Return the result.
  60.        Return result_string
  61.  
  62.    End Function
  63.  
  64. #End Region





...O viceversa:

Código
  1. #Region " Binary To ASCII Function "
  2.  
  3.    ' [ Binary To ASCII Function ]
  4.    '
  5.    ' Examples :
  6.    ' MsgBox(Binary_To_ASCII("01010100 01100101 01110011 01110100"))
  7.    ' MsgBox(Binary_To_ASCII("01010100011001010111001101110100"))
  8.  
  9.    Private Function Binary_To_ASCII(ByVal str As String) As String
  10.        Dim ASCII_String As String = Nothing
  11.  
  12.        ' Strip out spaces in case the string are separated by spaces.
  13.        str = str.Replace(" ", "")
  14.  
  15.        For i As Integer = 0 To str.Length - 1 Step 8
  16.            ASCII_String &= Chr(BinaryToLong(str.Substring(i, 8)))
  17.        Next i
  18.  
  19.        Return ASCII_String
  20.    End Function
  21.  
  22.    ' Convert this Binary value into a Long.
  23.    Private Function BinaryToLong(ByVal binary_value As String) As Long
  24.  
  25.        ' Remove any leading &B if present.
  26.        binary_value = binary_value.Trim().ToUpper()
  27.        If binary_value.StartsWith("&B") Then binary_value = binary_value.Substring(2)
  28.  
  29.        ' Strip out spaces in case the bytes are separated by spaces.
  30.        binary_value = binary_value.Replace(" ", "")
  31.  
  32.        ' Left pad with zeros so we have a full 64 bits.
  33.        binary_value = binary_value.PadLeft(64, "0")
  34.  
  35.        ' Read the bits in nibbles from left to right. (A nibble is half a byte)
  36.        Dim hex_result As String = ""
  37.        For nibble_num As Integer = 0 To 15
  38.  
  39.            ' Convert this nibble into a hexadecimal string.
  40.            Dim factor As Integer = 1
  41.            Dim nibble_value As Integer = 0
  42.  
  43.            ' Read the nibble's bits from right to left.
  44.            For bit As Integer = 3 To 0 Step -1
  45.                If binary_value.Substring(nibble_num * 4 + bit, 1).Equals("1") Then
  46.                    nibble_value += factor
  47.                End If
  48.                factor *= 2
  49.            Next bit
  50.  
  51.            ' Add the nibble's value to the right of the result hex string.
  52.            hex_result &= nibble_value.ToString("X")
  53.        Next nibble_num
  54.  
  55.        ' Convert the result string into a long.
  56.        Return Long.Parse(hex_result, Globalization.NumberStyles.HexNumber)
  57.  
  58.    End Function
  59.  
  60. #End Region


« Última modificación: 9 Abril 2013, 10:43 am por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #62 en: 9 Abril 2013, 10:59 am »

· Hexadecimal a Decimal:

Código
  1. #Region " Hex To Dec Function "
  2.  
  3.    ' [ Hex To Dec Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Hex_To_Dec("0x020032")) ' Result: 131122
  9.  
  10.    Private Function Hex_To_Dec(ByVal str As String) As Int32
  11.        Return Convert.ToInt32(str, 16)
  12.    End Function
  13.  
  14. #End Region





· Decimal a Hexadecimal:

Código
  1. #Region " Dec To Hex Function "
  2.  
  3.    ' [ Dec To Hex Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Dec_To_Hex(131122)) ' Result: 0x020032
  9.  
  10.    Private Function Dec_To_Hex(ByVal int As Int32) As String
  11.        Return Convert.ToString(int, 16)
  12.    End Function
  13.  
  14. #End Region





· Comprueba si una fuente está instalada:

EDITO: MEJORADO Y SIMPLIFICADO

#Region " Font Is Installed? Function "

    ' [ Font Is Installed? Function ]
    '
    ' // By Elektro H@cker
    '
    ' Examples :
    ' MsgBox(Font_Is_Installed("Lucida Console"))

    Private Function Font_Is_Installed(ByVal FontName As String) As Boolean
        Dim AllFonts As New Drawing.Text.InstalledFontCollection
        If AllFonts.Families.ToList().Contains(New FontFamily(FontName)) Then Return True Else Return False
    End Function

#End Region


Otra versión que me han proporcionado, mucho más simplificada:

Código
  1. #Region " Font Is Installed? Function "
  2.  
  3.    ' [ Font Is Installed? Function ]
  4.    '
  5.    ' Examples :
  6.    ' MsgBox(Font_Is_Installed("Lucida Console"))
  7.  
  8.    Public Shared Function Font_Is_Installed(ByVal FontName As String) As Boolean
  9.        Using TestFont As Font = New Font(FontName, 8)
  10.            Return CBool(String.Compare(FontName, TestFont.Name, StringComparison.InvariantCultureIgnoreCase) = 0)
  11.        End Using
  12.    End Function
  13.  
  14. #End Region
« Última modificación: 9 Abril 2013, 11:34 am por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #63 en: 9 Abril 2013, 16:50 pm »

· Mostrar un MessageBox centrado al form

Código
  1. #Region " Centered Messagebox "
  2.  
  3.    ' [ Centered Messagebox Function ]
  4.    '
  5.    ' Instructions :
  6.    ' 1. Add the Class
  7.    ' 2. Use it
  8.    '
  9.    ' Examples :
  10.    ' Using New Centered_MessageBox(Me)
  11.    '     MessageBox.Show("Test Text", "Test Title", MessageBoxButtons.OK)
  12.    ' End Using
  13.  
  14.    ' Centered_MessageBox.vb
  15. #Region " Centered MessageBox Class"
  16.  
  17. Imports System.Text
  18. Imports System.Drawing
  19. Imports System.Windows.Forms
  20. Imports System.Runtime.InteropServices
  21.  
  22.    Class Centered_MessageBox
  23.        Implements IDisposable
  24.        Private mTries As Integer = 0
  25.        Private mOwner As Form
  26.  
  27.        Public Sub New(owner As Form)
  28.            mOwner = owner
  29.            owner.BeginInvoke(New MethodInvoker(AddressOf findDialog))
  30.        End Sub
  31.  
  32.        Private Sub findDialog()
  33.            ' Enumerate windows to find the message box
  34.            If mTries < 0 Then
  35.                Return
  36.            End If
  37.            Dim callback As New EnumThreadWndProc(AddressOf checkWindow)
  38.            If EnumThreadWindows(GetCurrentThreadId(), callback, IntPtr.Zero) Then
  39.                If System.Threading.Interlocked.Increment(mTries) < 10 Then
  40.                    mOwner.BeginInvoke(New MethodInvoker(AddressOf findDialog))
  41.                End If
  42.            End If
  43.        End Sub
  44.        Private Function checkWindow(hWnd As IntPtr, lp As IntPtr) As Boolean
  45.            ' Checks if <hWnd> is a dialog
  46.            Dim sb As New StringBuilder(260)
  47.            GetClassName(hWnd, sb, sb.Capacity)
  48.            If sb.ToString() <> "#32770" Then
  49.                Return True
  50.            End If
  51.            ' Got it
  52.            Dim frmRect As New Rectangle(mOwner.Location, mOwner.Size)
  53.            Dim dlgRect As RECT
  54.            GetWindowRect(hWnd, dlgRect)
  55.            MoveWindow(hWnd, frmRect.Left + (frmRect.Width - dlgRect.Right + dlgRect.Left) \ 2, frmRect.Top + (frmRect.Height - dlgRect.Bottom + dlgRect.Top) \ 2, dlgRect.Right - dlgRect.Left, dlgRect.Bottom - dlgRect.Top, True)
  56.            Return False
  57.        End Function
  58.        Public Sub Dispose() Implements IDisposable.Dispose
  59.            mTries = -1
  60.        End Sub
  61.  
  62.        ' P/Invoke declarations
  63.        Private Delegate Function EnumThreadWndProc(hWnd As IntPtr, lp As IntPtr) As Boolean
  64.        <DllImport("user32.dll")> _
  65.        Private Shared Function EnumThreadWindows(tid As Integer, callback As EnumThreadWndProc, lp As IntPtr) As Boolean
  66.        End Function
  67.        <DllImport("kernel32.dll")> _
  68.        Private Shared Function GetCurrentThreadId() As Integer
  69.        End Function
  70.        <DllImport("user32.dll")> _
  71.        Private Shared Function GetClassName(hWnd As IntPtr, buffer As StringBuilder, buflen As Integer) As Integer
  72.        End Function
  73.        <DllImport("user32.dll")> _
  74.        Private Shared Function GetWindowRect(hWnd As IntPtr, ByRef rc As RECT) As Boolean
  75.        End Function
  76.        <DllImport("user32.dll")> _
  77.        Private Shared Function MoveWindow(hWnd As IntPtr, x As Integer, y As Integer, w As Integer, h As Integer, repaint As Boolean) As Boolean
  78.        End Function
  79.        Private Structure RECT
  80.            Public Left As Integer
  81.            Public Top As Integer
  82.            Public Right As Integer
  83.            Public Bottom As Integer
  84.        End Structure
  85.    End Class
  86.  
  87. #End Region
  88.  
  89. #End Region
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #64 en: 9 Abril 2013, 20:23 pm »

· Devuelve el título de la ventana de un proceso

Código
  1. #Region " Get Process Window Title Function "
  2.  
  3.    ' [ Get Process Window Title Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Get_Process_Window_Title("cmd"))
  9.    ' MsgBox(Get_Process_Window_Title("cmd.exe"))
  10.  
  11.    Private Function Get_Process_Window_Title(ByVal ProcessName As String) As String
  12.        If ProcessName.ToLower.EndsWith(".exe") Then ProcessName = ProcessName.Substring(0, ProcessName.Length - 4)
  13.        Dim ProcessArray = Process.GetProcessesByName(ProcessName)
  14.        If ProcessArray.Length = 0 Then Return Nothing Else Return ProcessArray(0).MainWindowTitle
  15.    End Function
  16.  
  17. #End Region



· Devuelve el handle de un proceso
Código
  1. #Region " Get Process Handle Function "
  2.  
  3.    ' [ Get Process Handle Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Get_Process_Handle("cmd"))
  9.    ' MsgBox(Get_Process_Handle("cmd.exe"))
  10.  
  11.    Private Function Get_Process_Handle(ByVal ProcessName As String) As IntPtr
  12.        If ProcessName.ToLower.EndsWith(".exe") Then ProcessName = ProcessName.Substring(0, ProcessName.Length - 4)
  13.        Dim ProcessArray = Process.GetProcessesByName(ProcessName)
  14.        If ProcessArray.Length = 0 Then Return Nothing Else Return ProcessArray(0).MainWindowHandle
  15.    End Function
  16.  
  17. #End Region



· Devuelve el PID de un proceso

Código
  1. #Region " Get Process PID Function "
  2.  
  3.    ' [ Get Process PID Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Get_Process_PID("cmd"))
  9.    ' MsgBox(Get_Process_PID("cmd.exe"))
  10.  
  11.    Private Function Get_Process_PID(ByVal ProcessName As String) As IntPtr
  12.        If ProcessName.ToLower.EndsWith(".exe") Then ProcessName = ProcessName.Substring(0, ProcessName.Length - 4)
  13.        Dim ProcessArray = Process.GetProcessesByName(ProcessName)
  14.        If ProcessArray.Length = 0 Then Return Nothing Else Return ProcessArray(0).Id
  15.    End Function
  16.  
  17. #End Region
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #65 en: 10 Abril 2013, 13:25 pm »

· Cargar fuentes de texto desde los recursos:

Nota: Este code ya lo posteé pero se me olvidó agregar lo más importante, la class, así que lo vuelvo a postear xD

Código
  1. #Region " Use Custom Text-Font "
  2.  
  3.    ' [ Use Custom Text-Font ]
  4.    '
  5.    ' Instructions :
  6.    ' 1. Add a .TTF font to the resources
  7.    ' 2. Add the class
  8.    ' 3. Use it
  9.    '
  10.    ' Examples:
  11.    ' Label1.Font = New Font(GameFont.Font, 10.0!)
  12.    ' Label1.Text = "This is your custom font !!"
  13.  
  14.    Dim MyFont As New CustomFont(My.Resources.kakakaka)
  15.  
  16.    Private Sub Main_Disposed(sender As Object, e As System.EventArgs) Handles Me.Disposed
  17.        MyFont.Dispose()
  18.    End Sub
  19.  
  20.    ' CustomFont.vb
  21. #Region " CustomFont Class "
  22.  
  23. Imports System.Drawing
  24. Imports System.Drawing.Text
  25. Imports System.Runtime.InteropServices
  26.  
  27.    ''' <summary>
  28.    ''' Represents a custom font not installed on the user's system.
  29.    ''' </summary>
  30.    Public NotInheritable Class CustomFont
  31.        Implements IDisposable
  32.  
  33.        Private fontCollection As New PrivateFontCollection()
  34.        Private fontPtr As IntPtr
  35.  
  36. #Region "Constructor"
  37.        ''' <summary>
  38.        ''' Creates a new custom font using the specified font data.
  39.        ''' </summary>
  40.        ''' <param name="fontData">The font data representing the font.</param>
  41.        Public Sub New(ByVal fontData() As Byte)
  42.            'Create a pointer to the font data and copy the
  43.            'font data into the location in memory pointed to
  44.            fontPtr = Marshal.AllocHGlobal(fontData.Length)
  45.            Marshal.Copy(fontData, 0, fontPtr, fontData.Length)
  46.  
  47.            'Add the font to the shared collection of fonts:
  48.            fontCollection.AddMemoryFont(fontPtr, fontData.Length)
  49.        End Sub
  50. #End Region
  51.  
  52. #Region "Destructor"
  53.        'Free the font in unmanaged memory, dispose of
  54.        'the font collection and suppress finalization
  55.        Public Sub Dispose() Implements IDisposable.Dispose
  56.            Marshal.FreeHGlobal(fontPtr)
  57.            fontCollection.Dispose()
  58.  
  59.            GC.SuppressFinalize(Me)
  60.        End Sub
  61.  
  62.        'Free the font in unmanaged memory
  63.        Protected Overrides Sub Finalize()
  64.            Marshal.FreeHGlobal(fontPtr)
  65.        End Sub
  66. #End Region
  67.  
  68. #Region "Properties"
  69.        ''' <summary>
  70.        ''' Gets the font family of the custom font.
  71.        ''' </summary>
  72.        Public ReadOnly Property Font() As FontFamily
  73.            Get
  74.                Return fontCollection.Families(0)
  75.            End Get
  76.        End Property
  77. #End Region
  78.  
  79.    End Class
  80.  
  81. #End Region
  82.  
  83. #End Region





· Esperar a que una aplicación termine de CARGAR

Nota : El código no está muy simplificado, pero se puede usar y funciona bien.
Nota 2: Esto sirve para aquellas aplicaciones a las que no le afecta un "Process.WaitForInputIdle", de lo contrario es una tontería usar este code tán largo y bruto.

Ejemplo de uso:

Código
  1.    Private Sub Wait_For_Application_To_Load(ByVal APP_Path As String, Optional ByVal APP_Arguments As String = Nothing)
  2.  
  3.        Process.Start("Photoshop.exe")
  4.        Timer_CheckCPU.Tag = "Photoshop"
  5.        Timer_CheckCPU.Enabled = True
  6.        While Not Timer_CheckCPU.Tag = ""
  7.            Application.DoEvents()
  8.        End While
  9.    End Sub


Código
  1. #Region " Wait For Application To Load (UNFINISHED AND WAITING TO BE IMPROVED)"
  2.  
  3.    Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByVal lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
  4.    Private WithEvents Timer_CheckCPU As New Timer
  5.  
  6.    Dim Memory_Value_Changed As Boolean
  7.    Dim CPU_Changed As Boolean
  8.    Dim CPU_Time As Boolean
  9.    Dim Running_Time As Boolean
  10.    Private _desiredTime_ms As Integer = 1500
  11.  
  12.    Private Sub Timer_CheckCPU_Tick(sender As Object, ev As EventArgs) Handles Timer_CheckCPU.Tick
  13.        Timer_CheckCPU.Enabled = False
  14.        Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName(Timer_CheckCPU.Tag)
  15.        Dim hprocess As Process = pProcess(0)
  16.        If hprocess Is Nothing Then
  17.            Running = False
  18.            Timer_CheckCPU.Enabled = True
  19.            Return
  20.        End If
  21.        Running = True
  22.        Memory = hprocess.PrivateMemorySize64
  23.        CPUTotal = hprocess.TotalProcessorTime.TotalMilliseconds
  24.  
  25.        If AllConditionsGood() Then
  26.            If Not (_countdown.IsRunning) Then
  27.                _countdown.Reset()
  28.                _countdown.Start()
  29.            End If
  30.            Dim _elapsed As Long = _countdown.ElapsedMilliseconds
  31.            If _elapsed >= _desiredTime_ms Then
  32.                Timer_CheckCPU.Tag = ""
  33.                Return
  34.            End If
  35.        Else
  36.            _countdown.Reset()
  37.        End If
  38.        Timer_CheckCPU.Enabled = True
  39.    End Sub
  40.  
  41.    Private Function AllConditionsGood() As Boolean
  42.        If CPU_Time Then Return False
  43.        If Memory_Value_Changed Then Return False
  44.        If Running_Time Then Return False
  45.        Return True
  46.    End Function
  47.  
  48.    Private _countdown As New Stopwatch
  49.  
  50.    Private _Running As Boolean = False
  51.    Public WriteOnly Property Running() As Boolean
  52.        Set(ByVal value As Boolean)
  53.            _Running = value
  54.            If value Then
  55.                Running_Time = False
  56.            Else
  57.                Running_Time = True
  58.            End If
  59.        End Set
  60.    End Property
  61.  
  62.    Private _CPUTotal As Double
  63.    Public WriteOnly Property CPUTotal() As Double
  64.        Set(ByVal value As Double)
  65.            CPU = value - _CPUTotal 'used cputime since last check
  66.            _CPUTotal = value
  67.        End Set
  68.    End Property
  69.  
  70.    Private _CPU As Double
  71.    Public WriteOnly Property CPU() As Double
  72.        Set(ByVal value As Double)
  73.            If value = 0 Then
  74.                CPU_Time = False
  75.            Else
  76.                CPU_Time = True
  77.            End If
  78.            _CPU = value
  79.        End Set
  80.    End Property
  81.  
  82.    Private _Memory As Long
  83.    Public WriteOnly Property Memory() As Long
  84.        Set(ByVal value As Long)
  85.            MemoryDiff = Math.Abs(value - _Memory)
  86.            _Memory = value
  87.        End Set
  88.    End Property
  89.  
  90.    Private _MemoryDiff As Long
  91.    Public WriteOnly Property MemoryDiff() As Long
  92.        Set(ByVal value As Long)
  93.            If value = _MemoryDiff Then
  94.                Memory_Value_Changed = False
  95.            Else
  96.                Memory_Value_Changed = True
  97.            End If
  98.            _MemoryDiff = value
  99.        End Set
  100.    End Property
  101.  
  102. #End Region
« Última modificación: 10 Abril 2013, 13:28 pm por EleKtro H@cker » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #66 en: 12 Abril 2013, 11:15 am »

Cargar configuración desde un archivo INI

Código
  1. Dim INI_File As String = ".\Test.ini"

Código
  1. ' By Elektro H@cker
  2.  
  3.    Private Sub Load_INI_settings()
  4.  
  5.        Dim Line As String = Nothing
  6.        Dim ValueName As String = Nothing
  7.        Dim Value
  8.  
  9.        Dim xRead As IO.StreamReader
  10.        xRead = IO.File.OpenText(INI_File)
  11.        Do Until xRead.EndOfStream
  12.  
  13.            Line = xRead.ReadLine().ToLower
  14.            ValueName = Line.Split("=")(0).ToLower
  15.            Value = Line.Split("=")(1)
  16.  
  17.            If ValueName = "Game".ToLower Then TextBox_Game.Text = Value
  18.            If ValueName = "SaveSettings".ToLower  Then CheckBox_SaveSettings.Checked = Value
  19.  
  20.        Loop
  21.  
  22.        xRead.Close()
  23.        xRead.Dispose()
  24.  
  25.    End Sub
« Última modificación: 12 Abril 2013, 11:28 am por EleKtro H@cker » En línea

ABDERRAMAH


Desconectado Desconectado

Mensajes: 431


en ocasiones uso goto ¬¬


Ver Perfil WWW
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #67 en: 12 Abril 2013, 14:17 pm »

dada una lista de imágenes, un tamaño por imágen y un número de imágenes por línea devuelve un bitmap con todas las imágenes dibujadas sobre una cuadricula del tamaño indicado. Muy útil para el manejo de gráficos 2D.

Código
  1. Public Function get_Image_matrix(ByRef imagelist As Bitmap(), sze As Size, imgs_per_line As Integer)
  2.        Dim imagesize As New Size(1, 1)
  3.        imagesize.Width = sze.Width * imgs_per_line
  4.        imagesize.Height = Math.Ceiling((imagelist.Length / imgs_per_line) * sze.Height)
  5.  
  6.        If (imagesize.Height = 0) Then
  7.            imagesize.Height = 1 * sze.Height
  8.        End If
  9.        If (imagesize.Width = 0) Then
  10.            imagesize.Width = 1 * sze.Width
  11.        End If
  12.  
  13.        Dim rtn As New Bitmap(imagesize.Width, imagesize.Height)
  14.        Dim gr As Graphics = Graphics.FromImage(rtn)
  15.  
  16.        Dim xc As Integer = 0
  17.        Dim yc As Integer = 0
  18.        Dim index As Integer = 0
  19.  
  20.        Dim needlines As Integer = Math.Ceiling(imagelist.Length / imgs_per_line)
  21.  
  22.        Do While yc < imagesize.Height
  23.            Do While xc < imgs_per_line * sze.Width
  24.                Try
  25.                    gr.DrawImage(imagelist(index), New Rectangle(xc, yc, sze.Width, sze.Height))
  26.  
  27.                Catch ex As Exception
  28.  
  29.                End Try
  30.                index += 1
  31.                xc += 1 * sze.Width
  32.            Loop
  33.            xc = 0
  34.            yc += 1 * sze.Height
  35.        Loop
  36.  
  37.        Return rtn
  38.    End Function

« Última modificación: 12 Abril 2013, 19:52 pm por ABDERRAMAH » En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #68 en: 13 Abril 2013, 12:02 pm »

@ABDERRAMAH
Gracias por aportar!



Mi recopilación personal de snippets ha sido re-ordenada y actualizada en el post principal, ya son un total de 200 snippets! :)

Saludos.
En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.809



Ver Perfil
Re: Librería de Snippets !! (Posteen aquí sus snippets)
« Respuesta #69 en: 13 Abril 2013, 12:58 pm »

· Enviar texto a una ventana PERO sin activar el foco de esa ventana :)

Ejemplo de uso:
Código
  1.    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  2.        ' Abrimos una instancia minimizada del bloc de notas
  3.        Process.Start("CMD", "/C Start /MIN Notepad.exe")
  4.        ' Y enviamos el texto a la instancia minimizada del bloc de notas!
  5.        ' Nota: El while es para esperar a que el notepad termine de cargar, no es algo imprescindible.
  6.        While Not SendKeys_To_App("notepad.exe", "By Elektro H@cker" & vbCrLf & "... :D") : Application.DoEvents() : End While
  7.    End Sub

Función:
Código
  1. #Region " SendKeys To App "
  2.  
  3.    ' [ SendKeys To App Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' SendKeys_To_App("notepad.exe", "By Elektro H@cker" & vbCrLf & "... :D")
  9.  
  10.    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  11.    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
  12.    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
  13.    Private Const EM_REPLACESEL = &HC2
  14.  
  15.    Private Function SendKeys_To_App(ByVal App_Name As String, ByVal str As String) As Boolean
  16.        Dim nPadHwnd As Long, ret As Long, EditHwnd As Long
  17.        Dim APP_WindowTitle As String
  18.  
  19.        If App_Name.ToLower.EndsWith(".exe") Then App_Name = App_Name.Substring(0, App_Name.Length - 4) ' Rename APP Name
  20.  
  21.        Dim ProcessArray = Process.GetProcessesByName(App_Name)
  22.        If ProcessArray.Length = 0 Then
  23.            Return False ' App not found
  24.        Else
  25.            APP_WindowTitle = ProcessArray(0).MainWindowTitle ' Set window title of the APP
  26.        End If
  27.  
  28.        nPadHwnd = FindWindow(App_Name, APP_WindowTitle)
  29.  
  30.        If nPadHwnd > 0 Then
  31.            EditHwnd = FindWindowEx(nPadHwnd, 0&, "Edit", vbNullString) ' Find edit window
  32.            If EditHwnd > 0 Then ret = SendMessage(EditHwnd, EM_REPLACESEL, 0&, str) ' Send text to edit window
  33.            Return True  ' Text sended
  34.        Else
  35.            Return False ' Name/Title not found
  36.        End If
  37.  
  38.    End Function
  39.  
  40. #End Region
« Última modificación: 13 Abril 2013, 13:01 pm por EleKtro H@cker » En línea

Páginas: 1 2 3 4 5 6 [7] 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ... 59 Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines