Declare Function RegisterClass Lib "user32.dll" Alias "RegisterClassA" (lpWndClass As WNDCLASS) As Long
RegisterClass registers a new window class for use. Only after registering the window class can it be used to create windows. This function is unable to set the small icon associated with a window class; to do that, use the more powerful RegisterClassEx function. After the window class is completely finished being used, use UnregisterClass to unregister it.
If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns an atom identifying the class.
None.
' This code is licensed according to the terms and conditions listed here. ' Register a new window class. The various properties to ' give it will be explained in the code. ' *** Place the following code in a module. *** ' Define the window procedure to use for the class. Here, we'll ' just make a wrapper for the default window procedure. Public Function WindowProc (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long ' Return whatever the default window procedure returns. WindowProc = DefWindowProc(hWnd, uMsg, wParam, lParam) End Function ' *** Place the following code where you want to register the class. *** Dim classinfo As WNDCLASS ' holds info about the class Dim classatom As Long ' receives an atom to the class just registered ' Set the various data members of the structure. ' Class style: give each window its own DC; redraw when resized. classinfo.style = CS_OWNDC Or CS_HREDRAW Or CS_VREDRAW ' Use the window procedure above to process messages. classinfo.lpfnWndProc = AddressOf WindowProc ' We aren't using any extra information. classinfo.cbClsExtra = 0 classinfo.cbWndExtra = 0 ' Handle to the instance of this application. classinfo.hInstance = App.hInstance ' Use the icon stored in C:\MyApp\deficon.ico. classinfo.hIcon = ExtractIcon(App.hInstance, "C:\MyApp\deficon.ico", 0) ' Use the cursor stored in C:\MyApp\mouse.cur. classinfo.hCursor = LoadCursorFromFile("C:\MyApp\mouse.cur") ' Fill the background with the system color for an application's workspace. classinfo.hbrBackground = COLOR_APPWORKSPACE ' No menu resource to use. classinfo.lpszMenuName = "" ' Give the class a name. classinfo.lpszClassName = "CustomClass" ' Finally, register the class. classatom = RegisterClass(classinfo) ' Now the class CustomClass can be used to create windows. ' *** Place the following code where you wish to unregister the window class. *** Dim retval As Long ' Unregister the window class. retval = UnregisterClass("CustomClass", App.hInstance)
RegisterClassEx, UnregisterClass
Window Classes
Go back to the alphabetical Function listing.
Go back to the Reference section index.
Last Modified: August 24, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/r/registerclass.html