Results 1 to 12 of 12
  1. #1
    MJLover's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Location
    Neverland
    Posts
    759
    Reputation
    33
    Thanks
    110
    My Mood
    Cheerful

    [Leeched] Visual Basic Tutorials

    #1: How to Flip Windows
    Works on Windows Vista And Windows 7, and if Aero is on.

    'This will Flip all the windows
    Code:
    Shell("C:\Windows\System32\rundll32.exe DwmApi #105")
    #2: Open / Close CD ROM Drive

    Start by declaring a function. This function is a call from OS.
    Code:
    Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
      (ByVal lpCommandString As String, ByVal lpReturnString As String, _
      ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
    Then to Open the CD Door:

    Code:
    Public Sub OpenCDDoor()
    Dim retval As Long
    retval = mciSendString("set CDAudio door open", "", 0, 0)
    End Sub
    To Close the CD Door:

    Code:
    Public Sub CloseCDDoor()
    Dim retval As Long
    retval = mciSendString("set CDAudio door closed", "", 0, 0)
    End Sub
    #3: Turn Monitor to Off/On/LowState

    First import this namespace:
    Code:
    Imports System.Runtime.InteropServices
    Define constants:
    Code:
    Public WM_SYSCOMMAND As Integer = &H112
    Public SC_MONITORPOWER As Integer = &HF170
    Then declare a windows api function:
    Code:
    <DllImport("user32.dll")> _
    Private Shared Function SendMessage(ByVal hWnd As Integer, ByVal hMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    End Function
    To Turn On:
    Code:
    Public Sub TurnOn()
    Dim x As Int32
    'Main is the main form of the application. You can change it to any form of the application.
    x = Main.Handle
    SendMessage(x, WM_SYSCOMMAND, SC_MONITORPOWER, -1)
    End Sub
    To Turn Off:
    Code:
    Public Sub TurnOff()
    Dim x As Int32
    'Main is the main form of the application. You can change it to any form of the application.
    x = Main.Handle
    SendMessage(x, WM_SYSCOMMAND, SC_MONITORPOWER, 2)
    End Sub
    Put it to Lowstate:
    Code:
    Public Sub LowState()
    Dim x As Int32
    'Main is the main form of the application. You can change it to any form of the application.
    x = Main.Handle
    SendMessage(x, WM_SYSCOMMAND, SC_MONITORPOWER, 1)
    End Sub
    #4: Set Desktop Wallpaper

    First import this namespace:
    Code:
    Imports System.Drawing.Imaging
    Then declare a windows API:
    Code:
    Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As String, ByVal fuWinIni As Integer) As Integer
    'Constants to be used with the above API:
    Code:
    Private Const SPI_SETDESKWALLPAPER = 20
    Private Const SPIF_UPDATEINIFILE = &H1
    'Create a new picture box:
    Code:
    Dim pic As New PictureBox
    Finally call the following code to change the wallpaper:
    Code:
    Dim ImageToSet  As String="Full location of the image"
    Dim imagePath1 As String = Application.StartupPath & "\wall.bmp"
    pic.Image = Image.FromFile(ImageToSet)
    pic.Image.Save(imagePath1, ImageFormat.Bmp)
    'Set the parameters to change the wallpaper to the image you selected:
    SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath1, SPIF_UPDATEINIFILE)
    My.Computer.FileSystem.DeleteFile(imagePath1)
    #5: Toggle NumLock/CapsLock/ScrollLock

    'Constants to be used:
    Code:
    Private Const VK_NUMLOCK As Integer = &H90
    Private Const VK_SCROLL As Integer = &H91
    Private Const VK_CAPITAL As Integer = &H14
    Private Const KEYEVENTF_EXTENDEDKEY As Integer = &H1
    Private Const KEYEVENTF_KEYUP As Integer = &H2
    API Function:
    Code:
    Private Declare Sub keybd_event Lib "user32" ( _
    ByVal bVk As Byte, _
    ByVal bScan As Byte, _
    ByVal dwFlags As Integer, _
    ByVal dwExtraInfo As Integer _
    )
    Now to toggle the Numlock key, use:
    Code:
    Public Sub NumLock()
    keybd_event(VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0)
    ' Release the key
    keybd_event(VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
    End Sub
    To toggle the CapsLock key, use:
    Code:
    Public Sub CapsLock()
    keybd_event(VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0)
    ' Release the key
    keybd_event(VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
    End Sub
    To toggle the ScrollLock key, use:
    Code:
    Public Sub ScrollLock()
    keybd_event(VK_SCROLL, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0)
    ' Release the key
    keybd_event(VK_SCROLL, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
    End Sub
    Note: You can check the state of the NumLock/CapsLock/ScrollLock before toggling them:

    Code:
    'This will turn on NumLock if it is turned off.
    If Not My.Computer.Keyboard.NumLock Then
    NumLock()
    End If
    I will keep posting new tutorials from time to time.

    Thanks and Regards,
    Hassan

  2. #2
    MJLover's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Location
    Neverland
    Posts
    759
    Reputation
    33
    Thanks
    110
    My Mood
    Cheerful

    Custom String Encoding / Decoding:

    A custom Encode/Decoder:

    Declare an integer:
    Code:
    Dim x as integer
    To Encode:
    Code:
    Function Encode(ByVal str As String)
    Dim res As String = ""
    If Not str = vbNullString Then
    For i As Integer = 0 To str.Length - 1
    If x = 2 Then
    Dim n As Integer = Asc(Mid(str, i + 1, 1)) + x
    res += Chr(n)
    x = 4
    ElseIf x = 4 Then
    Dim n As Integer = Asc(Mid(str, i + 1, 1)) + x
    res += Chr(n)
    x = 1
    Else
    Dim n As Integer = Asc(Mid(str, i + 1, 1)) + x
    res += Chr(n)
    x = 2
    End If
    Next
    End If
    x = 2
    Return res
    End Function
    To Decode:
    Code:
    Function Decode(Str as string)
    Dim res As String = ""
    If Not str = vbNullString Then
    For i As Integer = 0 To str.Length - 1
    If x = 2 Then
    Dim n As Integer = Asc(Mid(str, i + 1, 1)) - x
    res += Chr(n)
    x = 4
    ElseIf x = 4 Then
    Dim n As Integer = Asc(Mid(str, i + 1, 1)) - x
    res += Chr(n)
    x = 1
    Else
    Dim n As Integer = Asc(Mid(str, i + 1, 1)) - x
    res += Chr(n)
    x = 2
    End If
    Next
    End If
    x = 2
    Return res
    End Function
    Example:
    Code:
    Msgbox(Encode("JOIN THIS CHAT ABOUT VB ;)"))
    'Will return "LSJP$UJMT"GICX!CFPWX!XF!=-"
    
    Msgbox(Decode("LSJP$UJMT"GICX!CFPWX!XF!=-"))
    'Will return "JOIN THIS CHAT ABOUT VB ;)"
    You can enhance it using advanced string parsing techniques

    Regards

  3. #3
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    Selfwritten?

    Thanks for sharing.



  4. #4
    MJLover's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Location
    Neverland
    Posts
    759
    Reputation
    33
    Thanks
    110
    My Mood
    Cheerful

    Re: Self Written ?

    Encoder/Decoder is self written.

    The API tutorials aren't mine !!

    And you're welcome !

  5. #5
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    Give credits then :P



  6. #6
    MJLover's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Location
    Neverland
    Posts
    759
    Reputation
    33
    Thanks
    110
    My Mood
    Cheerful

    Extract Youtube Title and Download Link

    This is how we can extract the Youtube Title:

    First we need to import the following namespaces:
    Code:
    Imports System.Net
    Imports System.IO
    Then add this function to the application. This function gets the source code of any webpage.

    Code:
    Function GetPage(ByVal pageUrl As String) As String
    Dim s As String = ""
    Try
    Dim request As HttpWebRequest = WebRequest.Create(pageUrl)
    Dim response As HttpWebResponse = request.GetResponse()
    Using reader As StreamReader = New StreamReader(response.GetResponseStream())
    s = reader.ReadToEnd()
    End Using
    Catch ex As Exception
    Throw New Exception("Failed to get source code !!!")
    End Try
    Return s
    Now we need to parse the source code to extract the data we need:

    First we extract the Video Title using the following function:
    'This function is optional and is not needed if you want to just download the video.

    Code:
    Function GetTitle(ByVal URL As String)
    Dim result As String = "Couldn't extract title !!"
    Try
    If Not URL = vbNullString Then
    Dim c As String = GetPage(URL)
    Dim a1 As Integer = c.IndexOf("<title>") + 8
    Dim a2 As Integer = c.IndexOf("</title>", a1)
    Dim title As String = Mid(c, a1, a2 - a1).Replace("YouTube", "")
    title = title.Trim
    title = title.Remove(0, 2)
    result = title
    End If
    Catch ex As Exception
    End Try
    Return result
    End Function
    Then we use the following function to extract the video's download link:

    Code:
    Function getDownloadLink(ByVal URL As String)
    Dim result As String = "Couldn't extract link !!"
    Try
    If Not URL = vbNullString Then
    Dim c As String = GetPage(URL)
    Dim a1 As Integer = c.IndexOf("'VIDEO_ID': '") + 14
    Dim a2 As Integer = c.IndexOf("'", a1) + 1
    Dim id As String = Mid(c, a1, a2 - a1)
    Dim a3 As Integer = c.IndexOf("""t"": """) + 7
    Dim a4 As Integer = c.IndexOf("""", a3) + 1
    Dim t As String = Mid(c, a3, a4 - a3)
    result = id & "&t=" & t
    End If
    Catch ex As Exception
    End Try
    Return result
    End Function
    This is all the code.

    Example:

    Code:
    System.Diagnostics.Process.Start("https://www.youtube.com/get_video?video_id=" & getDownloadLink("https://www.youtube.com/watch?v=u_0q0kL03Lg"))
    If you want to download the video in high quality, insert "&fmt=18" or in HD then insert "&fmt=22" at the end of the Video URL.

    Hope this helps !!

    Regards

  7. #7
    MJLover's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Location
    Neverland
    Posts
    759
    Reputation
    33
    Thanks
    110
    My Mood
    Cheerful

    RE: Give Credits

    I googled all these functions long time ago so I don't know to whom these actually belong. I think originally they belong to Microsoft. If so, credits for API tutorials goes to Microsoft !!

  8. #8
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    These are all standard MSDN , Not self written code at all, The ones that are written

    "anyone with DIM"

    are all leeched. (C&P)

    But it doesn't matter, thanks for sharing.


     


     


     



    The Most complete application MPGH will ever offer - 68%




  9. #9
    MJLover's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Location
    Neverland
    Posts
    759
    Reputation
    33
    Thanks
    110
    My Mood
    Cheerful

    GMAIL Client

    @[MPGH]NextGen1:

    I don't understand "anyone with DIM" are all leeched. (C&P) !!!

    What it means ???

    Anywayz here's a Gmail client:

    Create a GUI like the one shown below:


    Then import this namespace:

    Code:
    Imports System.Net.Mail
    Create a new listbox:
    Code:
    Dim attachments As New ListBox
    If you want attachments in your mail, then attach the following code to the attachment button:

    Code:
    OFD.Filter = "All Files (*.*)|*.*"
    If Not OFD.ShowDialog = Windows.Forms.DialogResult.Cancel Then
    For Each n As String In OFD.FileNames
    attachments.Items.Add(n)
    Next
    End If
    lblAtt.Text = "Attachments [" & attachments.Items.Count & "]:"

    Finally attach the following code to the send button:

    Code:
    'Check the textboxes:
    
    If Not senderID.Text.EndsWith("@gmail.com") Then
    MsgBox("You must enter your Gmail ID to send an email.")
    Exit Sub
    End If
    If pass.Text = vbNullString Then
    MsgBox("You must enter your password for the given ID.")
    Exit Sub
    End If
    If recievers.Text = vbNullString Then
    MsgBox("Please enter recipients of the email.")
    Exit Sub
    End If
    If subj.Text = vbNullString Then
    subj.Text = "No Subject"
    End If
    If emailbody.Text = vbNullString Then
    emailbody.Text = "No Body"
    End If
    
    'If there are any attachments, calculate their size:
    Dim attchsz As Integer = 0
    If attachments.Items.Count > 0 Then
    For Each n As String In attachments.Items
    attchsz += CInt(My.Computer.FileSystem.GetFileInfo(n).Length / 1024 / 1024)
    Next
    End If
    If attchsz > 10 Then
    MsgBox("You have crossed the size limit of the email attachment.")
    Exit Sub
    End If
    
    'Try to send the mail:
    
    Try
    
    'Create a new mail message:
    Dim msg As New MailMessage(senderID.Text, recievers.Text, subj.Text, emailbody.Text)
    
    'If there are any carbon copies, attach them:
    If Not CCs.Text = vbNullString Then
    msg.CC.Add(CCs.Text)
    End If
    
    'If there are any blind carbon copies, attach them:
    If Not BCCs.Text = vbNullString Then
    msg.Bcc.Add(BCCs.Text)
    End If
    
    'If there are any attachments, attach them:
    If attachments.Items.Count > 0 Then
    For Each z As String In attachments.Items
    msg.Attachments.Add(New Net.Mail.Attachment(z))
    Next
    End If
    
    'Now enter the client info for your email.
    'I got the Google's smtp server and port number on the web.
    
    Dim client As New SmtpClient("smtp.gmail.com", 587)
    
    'Validate user...
    Dim Credentials As New System.Net.NetworkCredential(senderID.Text, pass.Text)
    client.Credentials = Credentials
    
    'Some sites require secure sockets layer connection. Google is one of them, so enable the ssl:
    
    client.EnableSsl = True
    
    'Finally send the message:
    client.Send(msg)
    
    Catch ex As Exception
    'If error occurs, report it to the user:
    MsgBox("Error sending email !!" & vbCrLf & ex.Message)
    Exit Sub
    End Try
    'If the mail is sent successfully, inform the user.
    MsgBox("Your email has been sent.")
    Hope this helps !!

    Regards

  10. #10
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    I determine leeched code based on 'Comments , Declarations, Decorations, You admit you got all these from google but yet you give no credit, your above gmail code matches tutorials online almost word for word .

    I will close this thread if you don't give credit

    If You get it from MSDN , Mark it MSDN, If you get it form codeproject, give credit,
    last thing we want over here at mpgh.net is to be known as leechers or anything similar
    ,
    'If for some reason, that is not ok with you, or you want to debate the matter, PM, don't discuss it further in here.

    Read Updated Rules
    https://www.mpgh.net/forum/33-visual-...2-24-10-a.html
    Last edited by NextGen1; 02-27-2010 at 08:26 AM.


     


     


     



    The Most complete application MPGH will ever offer - 68%




  11. #11
    MJLover's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Location
    Neverland
    Posts
    759
    Reputation
    33
    Thanks
    110
    My Mood
    Cheerful
    I was just asking that what leechers means, and have I already told you that I just remember that I googled the API functions a long time ago. And now i don't know where google linked me !!!

    Plus the gmail code above is written by me (I just got the smtp server and port number from web as I mentioned), 40-50 minutes ago. I really don't get how it matched word by word !! ??????????? That is impossible !!!

    Regards

  12. #12
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    Quote Originally Posted by What I Said Above
    'If for some reason, that is not ok with you, or you want to debate the matter, PM, don't discuss it further in here.


    What part of that did you not get?

    Fact: Most of these are straight off MSDN site, The above is very similar, but it doesn't matter, just remember to give credit

    This isn't a debate, I am sorry if it seems I am being offensive, Just keeping my section clean, and I like to keep the rules followed as well.

    And we don't need a whole thread that essentially is MSDN, We all know where to go for that....

    /Closed for being just like MSDN Library, if you don't know how to get there.

    https://msdn.microsof*****m/en-us/default.aspx
    You can get all these codes there

    Last edited by NextGen1; 02-27-2010 at 08:34 AM.


     


     


     



    The Most complete application MPGH will ever offer - 68%




Similar Threads

  1. Visual Basic Tutorials
    By NextGen1 in forum Programming Tutorials
    Replies: 1
    Last Post: 04-12-2012, 09:56 PM
  2. [Help] Visual Basic Tutorials
    By ¥øµñg&Ðång£r in forum CrossFire Hack Coding / Programming / Source Code
    Replies: 9
    Last Post: 05-02-2011, 08:27 PM
  3. [Tutorials] Mega Post of Visual Basic Tutorials !
    By Noxit in forum Visual Basic Programming
    Replies: 30
    Last Post: 09-02-2009, 09:09 PM
  4. C++ And Visual Basics Tutorial Vote
    By GG2GG in forum Programming Tutorials
    Replies: 6
    Last Post: 08-11-2009, 03:49 PM
  5. [Tutorial]Visual Basic 6 Many Options Tutorial by Yogilek.
    By yogilek in forum WarRock - International Hacks
    Replies: 4
    Last Post: 10-05-2007, 07:34 AM

Tags for this Thread