Tag Archives: flash

Detect when Removable USB Volume Drive Devices are Attached or Removed – VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (11 votes, average: 4.36 out of 5)
 

Below is some code I saw on a vb message board along time ago but I can’t remember where. It may have been vbforums.com. I made some code changes and then tested the code to have it throw a messagebox with the drive letter of the new usb device being attached or removed. It uses application subclassing to intercept the messages and checks if any are activated by a removable volume being Removed, Inserted, Attached, etc.. If it is then it will parse the volume drive letter of the device and throw a messagebox letting you know. USB devices like flash drives (Thumb Drives or Pen Drive’s as they are also called), external hard drives, etc. with a removable disk volume should be detected just fine. My testing recognized different usb volumes with no problems. You can use this code with VB.NET, Visual Basic 2008, VB 2010, 2013, etc. to check for both the arrival of usb volume devices and the removal. You can also make some changes to make it work for VB 6.0 as well. Visual Basic 6.0 will need an addiional API call or two for the subclassing portion.


These go in your declaration section of your program.

    '
    'The messages to look for.
    Private Const WM_DEVICECHANGE As Integer = &H219
    Private Const DBT_DEVICEARRIVAL As Integer = &H8000
    Private Const DBT_DEVICEREMOVECOMPLETE As Integer = &H8004
    Private Const DBT_DEVTYP_VOLUME As Integer = &H2  '
    '
    'Get the information about the detected volume.
    Private Structure DEV_BROADCAST_VOLUME

        Dim Dbcv_Size As Integer

        Dim Dbcv_Devicetype As Integer

        Dim Dbcv_Reserved As Integer

        Dim Dbcv_Unitmask As Integer

        Dim Dbcv_Flags As Short

    End Structure

 

Now for the subclassing based code. This is where it starts to get alittle difficult…

Continue reading

How to make the Applications Titlebar Flash

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 1.00 out of 5)
 

Sometimes you may want to get the attention of your users and causing your apps titlebar is a good way to do so. There is a simple little Windows API call that will do this for you. (This little function can be used with all versions of Visual Basic. Just be sure to set the parameter types to the proper ones for whichever version you are using.) Below is the API declare for the FlashWindow function…

Declare for .NET

Private Declare Function FlashWindow Lib “user32? Alias “FlashWindow” (ByVal wHandle As Int32, ByVal invertStates As Boolean) As Int32

Declare for VB 6.0

PrivateDeclareFunction FlashWindow Lib "user32" Alias "FlashWindow" (ByVal wHandle As Long, ByVal invertStates As Boolean) As Long

All thats left to do it call this function with the handle of your application via the wHandle parameter. You will want to set the invert parameter to True which will make the titlebar flash while changing states.

FlashWindow(Me.Handle.ToInt32, True)

For Visual Basic 6.0 just use it like so…

FlashWindow Me.hWnd, True

If you want your window to flash multiple times, you can call the function in a timer control set to the interval for how often to flash. Otherwise you can use the – FlashWindowEx function. You should have no problems finding info for that function. It gives you more control over the flashing. I will go over that function at another time…

Jason