Class

  • Thread starter Thread starter GTi
  • Start date Start date
G

GTi

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
 
GTi said:
"Ernst Kuschke (C# MVP)" <[email protected]>
wrote in message


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top