|
Thank you very much ))
|
|
|
|
|
I would like to switch off with code the autorun function
when I put a new CD in the CD drive. I have to read
information from my programme for the files on the CD
without interupting from the autorun function.
How can I do this?
|
|
|
|
|
I don't understand. You want to write a program to switch off the autorun feature so you can insert a CD without it auto running? Why not just press the shift key while inserting the CD?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
This would be an option if it was only one cd; but the program that I'm building is for cataloging several cd's and it is not so practical to hold down the shift key for several seconds every time i want to add a cd. Keep in mind also that not all of my users will be aware of this option so i prefere to "temporary" disable the autorun function while using the program
|
|
|
|
|
As the Microsoft Powertoy TweakUI allows you to disable the Autorun function of drives, I think this can be done by manipulating the registry.
Don't know a concrete key for this, but maybe you could get this info in some forum which deals with Windows and stuff like that
www.troschuetz.de
|
|
|
|
|
Thank you very much.
The problem is that if I do this with windows registry
I have to restart my computer and I would want to do
this without restarting the computer.
Have you other idea?
|
|
|
|
|
Uuh, you're right. Didn't considered that.
Maybe you can somehow simulate the holding of the Shift-Key, which Colin proposed, programmatically. It isn't quite elegant, but maybe it works.
www.troschuetz.de
|
|
|
|
|
|
There is a programmatic way, and many installers (including the Windows Installer runtime) will do this when prompting for CDs.
In order to do this, you must P/Invoke the RegisterWindowsMessage API to register a windows message that should be handled in your Forms override to the WndProc method. I would recommend defining a property to easily enable or disable autorun:
public class MyForm : Form
{
internal static uint QueryCancelAutoPlayMsg;
private bool enableAutoPlay = true;
public bool EnableAutoPlay
{
get { return enableAutoPlay ; }
set { enableAutoPlay = value; }
}
[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern uint RegisterWindowMessage(string msg);
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (QueryCancelAutoPlayMsg == 0)
QueryCancelAutoPlayMsg = RegisterWindows=Message("QueryCancelAutoPlay");
if (m.Msg == QueryCancelAutoPlayMsg)
m.Result = new IntPtr((int)enableAutoPlay);
}
} Please note that this is only a sample. I recommend you read more about canceling autoplay on MSDN in Enabling and Disabling AutoPlay[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you very much!!!! ))
You are super! You have always
a answer for a difficult question!
Thank you very much once again! ))
|
|
|
|
|
I am a moderately-skilled VB.NET guy who has (very) recently moved to C#. Where I seem to be having trouble is whenever I expect the same sort of forgiveness that VB seemed to give.
It seems that enums in C# are not as flexible as they were in VB. I am not sure if this true, but I am struggling where I did not expect to.
I have an enum that has int values. Basically, it is like this:
public enum Things<br />
{thing0 = 0, thing1 = 1, thing2 = 2}
... and so forth. What I can't do is this:
int numericThing = 1;<br />
Things aThing;<br />
aThing = numericThing;
This throws a CS0029 error about how it cannot implicitly convert type int to type Things.
What am I missing? I mean, if it doesn't work this way? What's the point?
I do not want to curl into the fetal position and crawl back to VB...
|
|
|
|
|
You need to cast it to Things:
Things aThing = (Things)numericThing;
|
|
|
|
|
Wingnut74 wrote:
What am I missing? I mean, if it doesn't work this way? What's the point?
I do not want to curl into the fetal position and crawl back to VB...
As mentioned, you need to cast it to int.
And, IMO, this is one of the C# strenghts over VB. Notice, VB allows you to do things that may cause hard to find runtime bugs, while C# will stop them at the moment you're compiling. This is called a "strongly-typed language".
notice this code:
int numericThing = 1;
Things aThing;
aThing = (Things)numericThing;
Now, it compiles, but does it work? Not always. What if numericThing has a value that is an invalid Thing? You should validate it before assigning.
And that's why the C# compiler stopped you.
Yes, even I am blogging now!
|
|
|
|
|
Daniel Turini wrote:
Now, it compiles, but does it work? Not always. What if numericThing has a value that is an invalid Thing? You should validate it before assigning.
And that's why the C# compiler stopped you.
Thanks to both of you. I figured it was something I was missing and was related to the way I have become used to VB's mommy-coddling.
I am still a bit out of my comfort zone, but I see the truth of what you are saying. I just have some re-learning ahead of me.
Thanks again.
|
|
|
|
|
My question is why are you even trying to assign an integer to an enum?
Whatever it is be aware of the very useful Enum.Parse For instance, in the case of persisting to fule it might be better to use the enum's name incase the enum's underlyng value was ever changed.
|
|
|
|
|
I need to create an object that takes its values from a database. The value of the enum is stored as an int, and I need to convert it back to the enum as I build the object.
|
|
|
|
|
Daniel Turini wrote:
What if numericThing has a value that is an invalid Thing? You should validate it before assigning.
Or let it be an undefined value
top secret xacc-ide 0.0.1
|
|
|
|
|
hi,
i got error when compile the code that implement generic in C#
like this : public class Stack<T>
i read msdn that C# support generic
but why i get compile error
how to solve this?
Thanks
|
|
|
|
|
C# doesn't support Generic, at least not yet. This feature will be included in the upoming C# 2.0 standard.
Take a look at this article from MSDN magazine for some more information about C# 2.0.
www.troschuetz.de
|
|
|
|
|
just realize it is for C# 2.0
thanks Stefan
|
|
|
|
|
Hi
I have a question, that how i can convert value of textbox(string) to integer in C# ?
i will be happy if you help me!
|
|
|
|
|
|
Convert.ToInt32(this.textBox1.Text);
i would explain a bit more but my wrist is broken.
/\ |_ E X E GG
|
|
|
|
|
Hi
It's better you learn the 'Parse' way:
int Number = Int32.Parse(textbox1.text)
Why? You can use to various types. e.g:
double Number = double.Parse(textbox1.text)
DateTime ADate = DateTime.Parse(textbox1.text)
Regards
|
|
|
|
|
I need same thing in Windows Forms programming as with ASP.NET Label (on Web it is much easier because Text property is just droped into html source). So is there something similar already around or should I think my own way to do this... ?
Any suggestions are also welcome...
|
|
|
|