Change Windows Class Name

M

Manpreet Randhawa

Is there a way to override the forms default window class name ..
(WindowsForms10.Window.8.....) ?

I tried to override CreateParams but got an exception
System.ComponentModel.Win32Exception "Invalid window class name"

Can someone please help as my app needs to be located by a c++ app
which is using FindWindow() method.

Any help will be greatly appreciated...
 
H

Herfried K. Wagner [MVP]

Manpreet Randhawa said:
Is there a way to override the forms default window class name ..
(WindowsForms10.Window.8.....) ?

I tried to override CreateParams but got an exception
System.ComponentModel.Win32Exception "Invalid window class name"

Can someone please help as my app needs to be located by a c++ app
which is using FindWindow() method.

Maybe you can base an implementation of the control on 'NativeWindow' and
set the window class name there. But this will require you to reimplement
the whole control...
 
G

Guest

It makes no sense to try to change the Windows class name. The class name is
a system-wide unique name for each TYPE of window. This means that all
combobox'es have the same class name, all buttons have the same class name
etc. Whenever calling the Win32 CreateWindow you must specify the class name
to tell Windows which kind of window it should create. All windows classes
must be registered with RegisterClass before the name can be used with
CreateWindow (I recommend Brent Rector's book on Win32 programming if you are
interested).

If you want to use FindWindow, you should use the title of the window to
find it.

HTH, Jakob.
 
M

Manpreet Randhawa

The reason for not using the window title in FindWindow is because the
title changes depending on whether a child form is open or not as the
name of the child form is then appended to the title.

Is there another function which can be used in place of FindWindow on
the other side, which can somehow use the exe name or any other
alternative?
 
G

Guest

Manpret, the window title changes but the window name probably doesn't
change. Look at the Name property of the form. The other thing you can do is
to break point inside one of the event handles (like MouseMove or Paint) and
look at the sender object. This object can be cast back into a form pointer
and the name property can be extracted.
 

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

Top