|
|
If I open a form with a axwebbrowser-control in a mdi-container
and show an excel-sheet in the webcontrol, than close the form
and application, the excel-process leaves alive.
If I close the application without closing the form first
excel closes.
Help appreciated.
Litzi
|
|
|
|
|
Excel was closed when I used axWebBrowser1.Dispose()
in the closing event from the form
Litzi
|
|
|
|
|
Hello Gurus,
I am using Environment.GetEnvironmentVariable() method to retreive a value from a an defined environment variable in a Win2k machine.
This method is able to get the value from a console application mode. However, if I run my application in a window service mode. It fail to get any value from the same defined environment variable.
Is there any setting I need to perform? Any suggestion, please advise. Thanks.
|
|
|
|
|
maybe your service runs in an other environment (other user)
try to get for example >ver<
Litzi
|
|
|
|
|
The environment variable has to be a system environment variable, or a user environment variable for the user that the service runs as. Adding environment variables from the command-line are also only valid for that instance of the command line, or any programs started from the command line. To configure persistent, global environment variables, go to the Advanced tab of your System Properties (right-click on My Computer and select Properties) and click the Environment Variables button (or similar). You'll see sections for both user and system environment variables there.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hello all,
Thanks for your advise. The problem solved. Thanks.
|
|
|
|
|
is there something like:
#if theCompilerVersionIs1.0
using Microsoft.Data.Odbc;
#else
using System.Data.Odbc;
??
I have VS2002 and have to command line compile for 1.1 and it would be great not to change my code for this.
|
|
|
|
|
There is preproc conditions supported by the C# compiler, yes, but there is no such definitions provided by the compiler that are documented, so you'll have to pass them yourself using /d:SYMBOL or configuring additional symbols in your VS.NET project (go to project properties, expand Configuration Properties, click on Build, and add symbols to the Conditional Compilation Constants at the top). An example follows:
#if CSC10
using Microsoft.Data.Odbc;
#else
using System.Data.Odbc;
#endif
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
does anyone know how to implement drag drop events in native windows? there doesn't seem to be any WM_DRAGDROP message!
related question, are the dotnet drag drop events into a control implemented by some object or code library that is accessible?
TIA!
________________________________________
Gosh, it would be awful pleas'n, to reason out the reason, for things I can't explain.
Then perhaps I'd deserve ya, and be even worthy of ya..
if I only had a brain!
|
|
|
|
|
Drag and drop is not trivial to implement. .NET exposes this in a rather easy-to-use method that encapsulates all the native functions, interfaces, structs, and enums/constants. As you can see, though, not every control in .NET supports drag and drop, either. There is a lot that has to be done in order to do this for native windows. There is more documentation in the Platform SDK at http://msdn.microsoft.com/library/en-us/dnanchor/html/anch_WinShell.asp[^]. Specific interfaces and functions to look at are IDropSource , IDropTarget , IDataOject , and DoDragDrop . These are all from the Platform SDK, not the .NET Framework SDK (I only mentioned because a couple of these have similarly named equivalents in both). Those four interfaces and functions - along with the documentation about them - should be enough to get you started.
On a side note, so long as the clipboard formats are supported by both the drag source and the drop target - regardless whether either one is managed or native - and the data is formatted correctly you can drag and drop between windows.
Finally, if you are looking to add drag-n-drop support to your native Windows, first read about the Windows Shell and drag-n-drop interfaces from the link I gave you and continue in the Visual C++ or ATL/WTL/STL forum.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath, thank you for the great references (as usual!).
________________________________________
Gosh, it would be awful pleas'n, to reason out the reason, for things I can't explain.
Then perhaps I'd deserve ya, and be even worthy of ya..
if I only had a brain!
|
|
|
|
|
Hello,
I would like to improve my application; hope it can minimize to system tray, and appear again if double clicked on system tray icon.
I know I should use notify icon, but how can I catch the minimize event of my application and tell it to minimize to system tray?
I just hope to find a good example of using notify icon, could any one help and teach me?
Thank you
|
|
|
|
|
azusakt,
Well it may seem that the application is actually minimizing into the system tray. But what happens is that when you minimize your application you actually hide it. Then when you double click on the notify icon, you show the application in its normal state.
// This hids the application when Minimized. (Forms resize event)
private void frmMain_Resize(object sender, System.EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Hide();
}
}
// Show the application when doubleclick event happens (Icon Try Double Click Event)
private void nicTray_DoubleClick(object sender, System.EventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
}
Hope this helps.
|
|
|
|
|
Thanks for you reply Jeff,
I've done something like your code, and it works, but a little bit strange effect. I set the form's ShowInTaskBar property to false, and I used:
private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
this.notifyIcon.Visible = false;
}
private void ProgressBarForm_SizeChanged(object sender, System.EventArgs e)
{
if(this.WindowState == FormWindowState.Minimized)
{
this.Hide();
this.notifyIcon.Visible = true;
}
}
It works like your expection, but the visual effect looks strange,; it firstly minimized to left bottom corner and then hide, that means always flash to left corner and then restore. How can I minimize it directly to system tray?
|
|
|
|
|
Through so much unbelievable math it's not even funny! The minimization effect is handled by the Windows, not the application. You have to dig very deep into Windows to override that behavior (if possible) and do all the math yourself to draw the minimizing Window compacting and moving toward the systray icon. I've never seen an application do this - not even from Microsoft.
What I do so most often to combat this effect is to hide the window first, then minimize, or vice-versa to restore (restore then show). This way, you don't see the Window minimize and don't have to worry about such behavior (which I agree looks odd).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I've run into a situation I haven't seen before, and was wondering if someone with a bit more threading experience would like to chime in.
The class IsoCurrencyInfo maintains a collection of IsoCurrencyInfo singletons. The instances of IsoCurrencyInfo class themselves are read-only once created, so by themselves are thread-safe. The trick is keeping the ArrayList container in line. I think I have it nailed, but in doing so I am executing a return statement while inside a lock() .
The code works very well under heavy concurrent load , but I can't help wondering "Is this safe?" Is there a better way to structure this method to optimize the locking?
I have adapted the Singleton implementation pattern[^] from Microsoft Patterns & Practices[^].
public static IsoCurrencyInfo GetInstance(string isoCode)
{
IsoCurrencyInfo newICI = null;
if(null == _iciRegistry)
lock(syncRoot)
if(null == _iciRegistry)
{
_iciRegistry = new ArrayList();
newICI = new IsoCurrencyInfo(isoCode);
_iciRegistry.Add(newICI);
}
if(null == newICI)
lock(syncRoot)
{
foreach(IsoCurrencyInfo existingICI in _iciRegistry)
if(existingICI.AlphaCode == isoCode)
return existingICI;
newICI = new IsoCurrencyInfo(isoCode);
_iciRegistry.Add(newICI);
}
return newICI;
}
Thanks!
B
|
|
|
|
|
It's completely safe. The lock keyword translates to the following (verifiable if you use ildasm.exe or some other disassembler / decompiler to view the compiled code):
Monitor.Enter(syncRoot);
try
{
}
finally
{
Monitor.Exit(syncRoot);
} The finally block is always run - regardless of a return or a throw - except when Environment.Exit is called (which unloads the process and the CLR completely, thus it really won't matter that the lock wasn't released because the OS will reclaim any process resources).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thank you for a solid example. I didn't think of checking my decompiler's output.
|
|
|
|
|
Brandon,
Returning inside a lock is okay.
I don't necessarily see anything incorrect about your implementation. However, the double-checked locking pattern is essentially useless as you have used it since you'll always be aquiring at least one lock anyway. I would suggest the following code...
public class IsoCurrencyInfo
{
private static Hashtable _iciRegistry = new Hashtable();
public static IsoCurrencyInfo GetInstance(string isoCode)
{
if (!_iciRegistry.Contains(isoCode))
{
lock (syncRoot)
{
if (!_iciRegistry.Contains(isoCode))
{
_iciRegistry.Add(isoCode, new IsoCurrencyInfo(isoCode));
}
}
}
return (IsoCurrencyInfo)_iciRegistry[isoCode];
}
}
It is important to realize that the Hashtable is the only IDictionary collection that will work as I have used it. This is because the Hashtable can support multiple readers and one writer simultaneously. Likewise, you won't be able to use the same trick with an ArrayList. In this implementation the lock is rarely acquired.
Brian
|
|
|
|
|
Bravo!
Based on your code and some thought, I ended up restructuring the entire class. It is smaller, tighter, and a lot faster. My test suite execution time dropped from an average of more than 500ms to less than 200ms; it drops to less than 1ms when I pre-load the singletons. That lock-loop was killing me.
Thanks!
B
|
|
|
|
|
hai everybody... may i know how to write the coding for the log off, reboot and shut down function in C# language. The coding must be able to use own pc so such to control others pc... I got a sample code which is written in VB6 as below:
Private Sub butLogOff_Click()
SystemFunc "logoff"
End Sub
Private Sub butReboot_Click()
SystemFunc "reboot"
End Sub
Private Sub butShutdown_Click()
SystemFunc "shutdown"
End Sub
Private Sub SystemFunc(task As String)
Const CONST_SHUTDOWN = 1
Const CONST_LOGOFF = 0
Const CONST_POWEROFF = 8
Const CONST_REBOOT = 2
Const CONST_FORCE_REBOOT = 6
Const CONST_FORCE_POWEROFF = 12
Const CONST_FORCE_LOGOFF = 4
Const CONST_FORCE_SHUTDOWN = 5
Dim objInstance, objEnumerator, cmdValue, intStatus
Select Case task
Case "logoff"
cmdValue = CONST_LOGOFF
Case "reboot"
cmdValue = CONST_REBOOT
Case "shutdown"
cmdValue = CONST_SHUTDOWN
End Select
Set objEnumerator = objService.ExecQuery("Select * From Win32_OperatingSystem", , 0)
For Each objInstance In objEnumerator
intStatus = objInstance.Win32ShutDown(cmdValue)
If intStatus = 0 Then
ShowStatus "System Function call successful."
Else
ShowStatus "System Function call failed!"
End If
Next
End Sub
|
|
|
|
|
The WMI support in .NET is superb. The best way to do this is to create a new project, then open your Server explorer (the "Server" tab next to the "Toolbox" in the default VS.NET installation) add your computer unders Servers (if it isn't already), then drill-down the find the Management Classes node. If you don't see them, download the setup at http://go.microsoft.com/fwlink/?LinkId=3353[^].
Now find the Operating Systems node. Right-click and click Generate Managed Class. Now you have the Win32_OperatingSystem class encapsulated in a .NET class you can use in many ways! This will have several methods for what you need, such as a Shutdown and Reboot method.
You can then, for example, reboot a named machine like so:
ManagementScope scope = new ManagementScope(
string.Format(@"\\{0}\ROOT\CIMV2", name));
Sample.ROOT.CIMV2.OperatingSystem.OperatingSystemCollection systems =
Sample.ROOT.CIMV2.OperatingSystem.GetInstances(scope, null, null);
foreach (Sample.ROOT.CIMV2.OperatingSystem system in systems)
system.Reboot(); Sample is the just the namespace I used to write the example code. The Sample.ROOT.CIMV2 namespaces and the classes and nested classes therein where generated from the step above.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Could somebody give me a smidge of help with the System.Windows.Forms.MonthCalendar class? Or at least point me to some good tutorials using it.
All I'm trying to do at this point is this:
After a user has selected some dates in it, I'd like to go through the entire range of dates (or at least a reasonable portion) and get all selected dates that the user selected. I want to store those dates into an array of DateTime objects.
Any help or pointers? Thanks.
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|
|
You can use the SelectionRange (or the SelectionStart and SelectionEnd properties) to iterate between the start and end dates. You cold either temporarily add these to a growable ArrayList , or calculate the number of elements a DateTime[] array would require. The following uses the latter method:
TimeSpan span = monthCal.SelectionEnd - monthCal.SelectionStart;
int count = span.Days + 1;
DateTime[] dts = new DateTime[count];
for (int i=0; i<count; i++)
dts[i] = monthCal.SelectionStart + new TimeSpan(1, 0, 0, 0);
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|