|
Mr. Jan Dolinay has written an article, "Detecting USB Drive Removal in a C# Program" (http://www.codeproject.com/KB/system/DriveDetector.aspx[^]).
The code works well when I plug and remove a mass storage USB device.
However, when I plug/remove a non-memory storage USB device, (e.g.: a control device), it could capture a WM_DEVICECHANGE message with WParam = DBT_DEVNODES_CHANGED. It never raises DBT_DEVICEARRIVAL message or DBT_DEVICEREMOVECOMPLETE message.
Can anybody tell me how to detect the plug/removal of this kind of USB device?
Thank you.
lk
lk
|
|
|
|
|
Hi,
This might not be the best way of doing it, but it took me all of five minutes to do .... so here goes:
DriveInfo drive = new DriveInfo("F");
if (drive.DriveType == DriveType.Removable)
{
while (drive.IsReady)
{
Thread.Sleep(1000);
}
MessageBox.Show("Drive removed");
}
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
Programm3r,
Thank you for your reply.
But DriveInfo seems for drive devices, which are mass memory storage device.
For mass memory storage device, we can also use windows message to detect the device plug/remove.
What I need to detect is NOT a mass memory storage device, and hence Windows message doesn't post the device DBT_DEVICEARRIVAL/DBT_DEVICEREMOVECOMPLETE message when I plug/remove it from the USB port. It seems the windows processing is different.
Regards,
lk
|
|
|
|
|
I just did a quick google and came across this[^].
Is it of any use?
|
|
|
|
|
Hey I am looking at the same code that Jan Dolinay has posted and figured as much that it does not detect non-memory storage USB device.
I have a couple of USB Human Interface Devices like microphone, foot pedal etc which I need to detect, was wondering if you figured out how to do it.. It would be great if you would like to share it.
Thanks,
Darsh
|
|
|
|
|
Hi all,
I'm trying to bring one of the tab pages to the fore ground when a user would right click on it. And as silly as this sounds, but I'm struggling. I have tried the following without success.
tabControlMain.TabPages[tabControlMain.SelectedIndex].Show();
Thanks in advance
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
Your looking for the SelectTab[^] method on the tab control itself
i.e.
this.tabControl1.SelectTab(this.tabPage1);
|
|
|
|
|
|
ahhhh I get ya,
private void tabControl1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
for (int i = 0; i < this.tabControl1.TabCount; i++)
{
Rectangle tabArea = tabControl1.GetTabRect(i);
if (tabArea.Contains(e.Location))
{
}
}
}
}
|
|
|
|
|
|
thats odd :/
try the other mouse events ... down and up.
|
|
|
|
|
|
no probs
|
|
|
|
|
Hi,
I am guessing here but if the user uses the right mouse button the tab page would not be selected. You have to get the index of the clicked tab page.
Volker Weichert
|
|
|
|
|
Yes you are correct. This is actually the main problem I'm having, so ... how does one access the tabpage when the right mouse button was click?? How would one make use of the tab index, cause any tabpageb could be selected at any moment ....
Thanks for the response.
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
If you check out the link in my above post you'll see the SelectTab method takes an index.
|
|
|
|
|
|
You might want to try something like this in your event handler:
Point p;
if (e.Button == MouseButtons.Right)
p = new Point(e.X, e.Y);
for (int i = 0; i < tabControl1.TabCount; i++)
{
if (tabControl1.GetTabRect(i).Contains(p))
tabControl1.SelectTab(i);
}
}
Volker Weichert
|
|
|
|
|
|
I need to read a value at a specific address on an SD Card how can I do that?
any Ideas?
BiG RaLpH
modified on Friday, January 04, 2008 8:37:12 AM
|
|
|
|
|
Please don't cross post the same question in multiple forums. It makes collaborating on an answer quite difficult.
|
|
|
|
|
Take a look through the source code to frhed[^]. One of the versions (can't remember if it's the beta or not) allows for direct-drive access, the code is in C++ but it's not too difficult to convert to C# if you have some experience from calling Win32 APIs.
|
|
|
|
|
Hi,
I setting pictureBox.image = Image.FromFile("eweew.bmp");
This works file, but at times I want no picture to be displayed.
How do I set pictureBox.image to no value or default?
Thanks in advance.
Rapier
|
|
|
|
|
Try setting it to null.
Edited:
Don't forget to dispose the image before clearing it.
modified on Friday, January 04, 2008 7:55:36 AM
|
|
|
|
|
Giorgi Dalakishvili wrote: Try setting it to null
will it throw an exception?
|
|
|
|