"GTi" <gt*@gti.com> wrote in message news:42********@news.wineasy.se...
"Ernst Kuschke (C# MVP)" <Er**************@discussions.microsoft.com>
wrote in message
news:06**********************************@microsof t.com... You have to PInvoke afaik... I have an example in this 'helper' class:
http://dotnet.org.za/ernst/articles/3491.aspx
HTH!
-Ernst
"GTi" wrote:
In win32 I define my window class with
wcex.lpszClassName = "My.Window.App.Class";
RegisterClassEx(&wcex);
But I can't find anything similar in C#, in fact the class for
my application is WindowsForms10.Window.8.app4
But I can't find where this is defined.
How can I rename this class to my own name?
I do not want several instance of my window application.
How can I prevent this?
In C/C++ I use
if(FindWindow("WindowsForms10.Window.8.app4", NULL)) return(0);
This is sufficient for me.
Is there any C# way to do this or must I pInvoke FindWindow in C# too?
GTi
Ernst,
Thanks for the example.
But do U know how I can define my class name for the window application ?
You can't change the class name, this name is assigned to by the framework
class that creates the window.
Use a named mutex if you want to prevent multiple instances to run.
Something like this will do:
....
bool freeToRun;
string safeName = "Global\\StringUniquelyIdentifyingThisApplication" ;
// wrap the Mutex in a using block to prevent early clean-up of the OS mutex
handle.
using(System.Threading.Mutex m = new System.Threading.Mutex(true, safeName
, out freeToRun))
{
if (freeToRun)
{
Application.Run (new YourForm());
}
MessageBox.Show("Already running...");
}
Willy.