[comp.windows.ms] RegisterClass

grosen@amadeus.ucsb.edu (Mark D. Grosen) (07/10/90)

I have implemented some window classes that I would like to use in DLL's,
since I have several applications that use them.  The "Guide to Programmin"
makes a passing reference to registering window classes in the DLL's
initialization function.  A couple questions:

1)  Where do I get an instance handle to use with RegisterClass()?

2)  I want to use CS_GLOBALCLASS so that all applications can use
this window class.  What happens when the first application that caused
the DLL to be loaded (and hence initialized) terminates and other
subsequent applications using the windows class continue running?

Are there any references where this is covered, like maybe the MSJ?

Mark

Mark D. Grosen		ARPA: grosen@amadeus.ucsb.edu
Signal Processing Lab / Communications Research Lab
ECE Dept.
University of California
Santa Barbara, CA  93106

goodearl@world.std.com (Robert D Goodearl) (07/10/90)

In article <5923@hub.ucsb.edu> grosen@amadeus.ucsb.edu (Mark D. Grosen) writes:
>
>I have implemented some window classes that I would like to use in DLL's,
>since I have several applications that use them.  The "Guide to Programmin"
>makes a passing reference to registering window classes in the DLL's
>initialization function.  A couple questions:
>
>1)  Where do I get an instance handle to use with RegisterClass()?

The sample code provided with the sdk includes the following function:

int FAR PASCAL LibMain(hModule, wDataSeg, cbHeapSize, lpszCmdLine)
HANDLE  hModule;
WORD    wDataSeg;
WORD    cbHeapSize;
LPSTR   lpszCmdLine;
{
}

I believe this is the standard entry function (like "WinMain" for an
application).  hModule provides the module handle for the DLL.  I believe
this would be used instead of the application's instance handle.

>
>2)  I want to use CS_GLOBALCLASS so that all applications can use
>this window class.  What happens when the first application that caused
>the DLL to be loaded (and hence initialized) terminates and other
>subsequent applications using the windows class continue running?
>

From the online help:

CS_GLOBALCLASS  Specifies that the window class is an application global
class. An application global class is created by an
application or library and is available to all applications. The
class is destroyed when the application or library that
created the class terminates;  it is essential, therefore, that
all windows created with the application global class be
closed before this occurs.

I have not tried this in windows 3.0, but hopefully it has been fixed.
(It didn't work in 2.1).

The question that comes to mind is -- is the DLL considered "terminated" when
all applications that are using it have terminated?  If so, each application
using the DLL would need to call some kind of initialization function in the
DLL which would only call register class if the DLL had not already been 
initialized.

Has anybody out there actually tried this?

----------
Bob Goodearl -- goodearl@world.std.com