WIN32 Window Classes with WIndows Forms

  • Thread starter Thread starter Steve Marsden
  • Start date Start date
S

Steve Marsden

Hi

With WIN32 you could create your own Window Class (not C++ Class) which you
registered with RegisterClass, create and code a windowproc for this window
and then host that window on a dialog box using the Custom Control and
specifying class as the name of the Window Class you registered and hey
presto you could have your own window/control on a dialogbox.

Is there a way to do this with a Windows Form.

We have a large WIN32 C application which we have just complied with /CLR
and are starting to slowly convert/integrate with ..NET and Windows Forms
but we have quite a few of these Window Classes which for now it would be
great to host on a Windows Form rather have to port all the code to C++ and
Object Classes etc.

Anyone know if this is possible and how?

Thanks

Steve
 
Steve,
Anyone know if this is possible and how?

Create a class derived from Control, override the CreateParams
property and use it to return the window class to use.



Mattias
 
Mattias

Thanks for the reply. This sounds hopeful.

As a newbie I am OK creating the class derived from Control but nor sure
about overiiding the CreateParams property and returnng the windows class.

Could you gove me a short example.

Thanks

Steve
 
Further to the above I found some code which shoudl do what I want but it
fails with "Invalid Window Class Name"

public __gc class testclass : public System::Windows::Forms::Control
{
protected:
__property System::Windows::Forms::CreateParams * get_CreateParams()
{
System::Windows::Forms::CreateParams * createParams;
createParams = __super::get_CreateParams();
createParams->ClassName = "generic";
return createParams;
}
};

generic is a class I already have registered using RegisterClass elseeher in
my project

wndclass.lpszClassName="generic";
wndclass.lpfnWndProc=GenericProc;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=dlgbkbr;
if (!RegisterClass(&wndclass))
return -1;

If I change "generic" to "BUTTON" so I am using a system class it works but
not with my own window class
 
I am tried changing my class stytle to CS_GLOBALCLASS and this removed the
error.

My only remaining problem now is my control is not being painted.

I have debugged I am definitely getting into the wndproc for my class but I
am not getting any WM_PAINT messages.

Any ideas?
 
Back
Top