|
See the AddHours method[^] or the Subtraction operator[^]. Both will do nicely.
And don't forget to visit the TimeSpan [^]object.
Try:
DateTime nm6 = DateTime.Now - new TimeSpan (6, 0, 0);
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
Thanks.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
I save files from my application with an extention. I have two problem now:
1.I want when user double click on that file my application open and show the proper datas from that file.
2.When user save files ,it saves with my application icon,now its save with unknown window icon.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Mazdak wrote:
2.When user save files ,it saves with my application icon,now its save with unknown window icon.
There is quite a bit involved to do this using .net.
Take a look at this usenet post on microsoft.public.dotnet.languages.csharp. It should get you rolling.
Hey don't worry, I can handle it. I took something. I can see things no one else can see. Why are you dressed like that?
- Jack Burton
|
|
|
|
|
Thanks.
Well I found first one.I get it from command line.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
I am writing a utility to check the health of an application and I would like to check if a particular Windows service is installed and if it is whether it is running or not.
I have used the System.ServiceProcess.ServiceController class to see if a service is running or not (and this works fine) but I can't find a way to trap if the service is actually installed.
I could interate through the ServiceController[] using GetServices but this seems to be a bit "clunky" particularly becauseI want to check the existence of a number of services as the utility loads.
Is there a class/method that will do this for me?
Anyone got any ideas on how to do it?
Thanks for your help
Andy
|
|
|
|
|
I don't know if I understand your problem.When you can get list of services,check the name of them if your proper names are there so they are installed,whats the problem with that?
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Hi Mazy,
Thanks for the reply.
It just seems to be a lot of work when I would have expected an exception to be returned by ServiceController to say that the service is not installed.
If you use VBA and the windows API "advapi32.dll" the QueryServiceStatus method returns an error that shows if the service is installed - surely C# has an equivalent - maybe not.
Andy
|
|
|
|
|
Well,When I want to do that I just look up in ServiceController[] which used GetServices().I look just check each ServiceName property for ServiceController[] and if its there so it is installed.Its not that muck hard or caused any expetion.And I can get the status of each service by Status prperty.
Anyway,You can use QueryServiceStatus in C# too.You can use it like the way you use other win32 functions in C# but thats very hard and boring.You can write a DLL with MC++(I GUESS you can do that with VB.NET too) and do this jon in it and then it is REALLY easy to reuse it in C#.If you want to do it in this way I can help you more.
I don't think you have any other choices,there is nothing like that in .Net framework as much as I know.
HTH
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Mazy,
Many thanks for your advice.
You have confirmed my thoughts, it just seems odd that when someone has written a class that gets a service status that one of the status conditions would not be "its not installed".
I am going to opt for using ServiceConroller[].
Regards
Andy
|
|
|
|
|
I completely agree with you. Worse there doesn't seem to be any native .NET way of getting all the information you could normally get using QueryServiceStatus() that is returned in the SERVICE_STATUS structure. .NET needs to replace the ServiceStatus enum with a class.
|
|
|
|
|
This works for me..
public bool IsInstalled()
{
try
{
string str;
ServiceController sc = new ServiceController(myServiceName);
// accessing some property will throw an exception if not installed.
str = sc.ServiceName;
}
catch (Exception)
{
return false;
}
return true;
}
|
|
|
|
|
I've written a tray based application and overridden the OnClosing where I iconify the application instead of closing it. However, when I'm trying to shut down or restart my computer the program wont shut down and the computer wont reboot or shutdown until I exit the program. I know that WIndows sends the message WM_ENDSESSION when the system goes down, but how do I handle this from my hidden application in the traybar? Or is there another simple solution of this problem 
|
|
|
|
|
Is that the only method (OnClosing) you wrote an override for?
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
I've overridden OnLoad, OnResize, Dispose (that's default?) and OnClosing.
|
|
|
|
|
I hate to say it, but that's just weird. I have a similar app except minimize (rather than close) puts it in the tray and it doesn't seem to have any problem at all. So there may be something about the OnClosing method that I'm not aware of. Does your code look like this?:
protected void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
return;
}
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Is this a normal app with a tray icon, or a system service, because surely the app would shut down normally as any windows form app would. The only thing I can think of is that you havn't disposed the NotifyIcon in the Dispose Override.
If its a system service then I can't help, never written one in C#.
"If you just say porn then you get all manner of chaff and low grade stuff." - Paul Watson, Lounge 25 Mar 03 "But a fresh install - it's like having clean sheets" - C. Maunder Lounge 3 Mar '03
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
|
|
|
|
|
Somewhere on CP there is an article you can use in the Closing event to determine why you are being closed. Use that to handle the case where windows is shutting down to exit your program.
or
pahlsson wrote:
I know that WIndows sends the message WM_ENDSESSION
Your application is still running so it should still get the WM_ENDSESSION message. You'll need to lookup the real value of WM_ENDSESSION, then override WndProc to handle it.
protected override void WndProc(ref Message m)
{
const int WM_ENDSESSION = 0x0016;
switch(m.Msg)
{
case WM_ENDSESSION:
bool sessionEnding = (bool) m.WParam;
m.Result = 0;
break;
default:
base.WndProc(ref m);
}
} However, MSDN says "The application need not call the DestroyWindow or PostQuitMessage function when the session is ending." so I don't think this is a suitable addition without my first suggestion implemented.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Thanks for your answers, you have given me some new ideas to try out. However I have another problem now. When the app is to execute, I get an exception :-/
The exceptions says "Error creating window handle" at the Application.Run(); in main. It didn't yesterday 
|
|
|
|
|
Ah, solved it... my misstake 
|
|
|
|
|
Hello..
I want to make Directory Dialog Box not File Dialog Box..
(It means I want get Directory name When I select Directory name in the dialog. You Know!!)
However I hardly know How to make it.
Is there anyone can help me?
Thanks..
I'm not who I was
|
|
|
|
|
Using the .Net 1.1 SDK you can just use the
System.Windows.Forms.FolderBrowserDialog.
If you are using the 1.0 SDK you can inherit from
System.Windows.Forms.Design.FolderNameEditor.
This implementation will most likely require that you use a
FolderNameEditor.FolderBrowser.
I have a class already written that can do this job if you like.
Also, I think there is at least one implementation posted here on CP.
Hey don't worry, I can handle it. I took something. I can see things no one else can see. Why are you dressed like that?
- Jack Burton
|
|
|
|
|
By using FolderNameEditor class and FolderBrowser class u can make Directory Dialog Box.
public class DirBrowser : FolderNameEditor
{
FolderBrowser fb = new FolderBrowser();
public string DirectoryPath
{
get
{
return strDirectoryPath;
}
}
public DirBrowser() { }
public DialogResult ShowDialog()
{
fb.Description = "Choose Directory";
fb.StartLocation = FolderBrowserFolder.MyComputer;
fb.Style = FolderBrowserStyles.RestrictToFilesystem;
DialogResult dlgResult = fb.ShowDialog();
if (dlgResult == DialogResult.OK)
strDirectoryPath = fb.DirectoryPath;
else
strDirectoryPath = "";
return dlgResult;
}
private string strDirectoryPath = "";
}
Instaniate DirBrowser class, call ShowDialog function and use DirectoryPath property to get the directory path :-
DirBrowser obDirBrowser = new DirBrowser();
obDirBrowser.ShowDialog ();
txtLogFilePath.Text = obDirBrowser.DirectoryPath ;
Chito.
|
|
|
|
|
http://www.codeproject.com/cs/miscctrl/folderbrowser.asp[^]
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Hi guys,
I want to change title bar color, but I am doing something wrong. So please, if anybody knows what it is, it would be good to let me know.
I declare:
using System.Runtime.InteropServices;
then I import API:
[DllImport("user32.dll")]
public static extern int SetSysColors(int nChanges, int lpSysColor, int lpColorValues);
[DllImport("user32.dll")]
public static extern int GetSysColor(int nIndex);
and then I call it this way:
int iRes = GetSysColor(4);
MessageBox.Show("Result: " + iRes.ToString());
iRes = SetSysColors(0, 4, 14898176);
MessageBox.Show("Result: " + iRes.ToString());
The first message box returns 16777215 which is a color of the menu (number 4 is the constant for menu), so it means GetSysColor function works, but the second function returns 0, which means it failed, and color of the menu does not change.
Why is that? Am I missing something obvious?
Thanks for your answers.
.
|
|
|
|