Page 1 of 1

Using commands in vb with a class to control the command

Posted: Thu Jul 19, 2012 7:13 am
by lucky134
Hello this is my first tutorial :) this is about using commands sort of like sendmessage type stuff!
------------------------------------------------------------------------------------------------------------------------------------------------------------
You need:
1 Class named Command.vb
1 Contextstrip named "Commands" - put a menustriptool name it devices then add on cd drive then open:

Image

under form1 design change the name to "core"
also set contextmenu to: commands

right click core and click view code, and copy and paste this:
Code: Select all
Public Class Core
    Dim _command As New Command
    Private Sub OpenToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles OpenToolStripMenuItem.Click
        _command.OpenCD()
    End Sub
End Class
last copy and paste this in command.vb:
Code: Select all
Public Class Command
    Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
        (ByVal lpszCommand As String, ByVal lpszReturnString As String, _
        ByVal cchReturnLength As Long, ByVal hwndCallback As Long) As Long
    Public Sub OpenCD()
        mciSendString("set CDAudio door open", 0, 0, 0)
    End Sub
End Class
Debug it right click then use the context menu to navigate to the open drive and click it and it should open your drive!!!
there are many more commands like that have to do with os based stuff plus things like advanced pc restart shutdown start screensaver and more good luck!

Credits:
50% MSDN forums - for the set audio cd open code!
50% Me - doing the custom _command part

I am using this to make something very special i might release it in the yay future if i ever finish it :P

Re: Using commands with class

Posted: Thu Jul 19, 2012 7:44 am
by Shim
nice tutorial lucky134 , keep it up the good work . :D

Re: Using commands in vb with a class to control the command

Posted: Fri Jul 20, 2012 9:10 am
by pip
That's ma brother :P