SDK App - 1. Define Class

Category: SDK

Date: 02-16-2022

Return to Index


 
'There are essentially 5 parts to creating a window:
'A data structure is filled out with the window properties and the CreateWindowEx
'API is used to register the window, then the ShowWindow/UpdateWindow API are used
'to display the window.  A message loop keeps the window on the screen and a message
'function is used to respond to messages sent to the window (including sending a
'PostQuitMessage() to end the message loop and close the application.
1. Define
2. Register
3. Show
4. Message Loop
5. Message Response
 
'1. Define
'Declare a variable of type WndClassEx and fill the elements of that variable with the Window properties
 
    Local myWin AS WndClassEx
 
    'Define the elements of a window
    myWin.cbSize         = SizeOf(wce)
    myWin.Style          = %CS_HREDRAW Or %CS_VREDRAW
    myWin.lpfnWndProc    = CodePTR(WndProc)       'message function - "WndProc" can be any function name
    myWin.cbClsExtra     = 0
    myWin.cbWndExtra     = 0
    myWin.hInstance      = hInst
    myWin.hIcon          = LoadIcon(hInst, "aainfo")     'icon from PBR file
    myWin.hCursor        = LoadCursor(%NULL, ByVal %IDC_ARROW)
    myWin.hbrBackground  = %NULL ' No class background, we do it ourselves
    myWin.lpszMenuName   = %NULL
    myWin.lpszClassName  = VarPTR(szAppName)
    myWin.hIconSm        = LoadIcon(hInst, ByVal %IDI_APPLICATION)
    RegisterClassEx myWin
 
'Per MSDN, you must initialize any unused members of the WNDCLASSEX structure to zero Or NULL.
'The Window Class elements are as shown in the following table.
 
 
'MSDN
'The WndClassEX structure is covered in more detail at MSDN
http://msdn.microsoft.com/en-us/library/ms633577%28VS.85%29.aspx
'The following information is a summary of the MSDN page.
 
WNDCLASSEX Structure
'The WNDCLASSEX structure contains Window Class information. It is used with the RegisterClassEx
'and GetClassInfoEx functions.
 
cbSize
'Specifies the size, in bytes, of the structure. Set this member to SizeOf(WNDCLASSEX).
'Be sure to Set this member before calling the GetClassInfoEx Function.
 
'Style
'Specifies the Class Style(s). This member can be any combination of the Class Styles.
 
'lpfnWndProc
'Pointer to the Window procedure. You must use the CallWindowProc Function to Call the Window procedure. For more information, see WindowProc.
'cbClsExtra
'Specifies the number of extra bytes to allocate following the Window-Class structure. The system initializes the bytes to zero.
'cbWndExtra
'Specifies the number of extra bytes to allocate following the Window Instance. The system initializes the bytes to zero. If an application uses WNDCLASSEX to Register a Dialog Box created by using the Class directive in the resource file, it must Set this member to DLGWINDOWEXTRA.
'hInstance
'Handle to the Instance that contains the Window procedure For the Class.
'hIcon
'Handle to the Class Icon. This member must be a Handle to an Icon resource. If this member is NULL, the system provides a default Icon.
'hCursor
'Handle to the Class cursor. This member must be a Handle to a cursor resource. If this member is NULL, an application must explicitly Set the cursor shape whenever the mouse moves into the application's window.
'hbrBackground
'Handle to the Class background brush. This member can be a Handle to the physical brush to be used For painting the background, Or it can be a Color value. A Color value must be one of the following standard system colors (the value 1 must be added to the chosen Color). If a Color value is given, you must convert it to one of the following HBRUSH types:
            * COLOR_ACTIVEBORDER
            * COLOR_ACTIVECAPTION
            * COLOR_APPWORKSPACE
            * COLOR_BACKGROUND
            * COLOR_BTNFACE
            * COLOR_BTNSHADOW
            * COLOR_BTNTEXT
            * COLOR_CAPTIONTEXT
            * COLOR_GRAYTEXT
            * COLOR_HIGHLIGHT
            * COLOR_HIGHLIGHTTEXT
            * COLOR_INACTIVEBORDER
            * COLOR_INACTIVECAPTION
            * COLOR_MENU
            * COLOR_MENUTEXT
            * COLOR_SCROLLBAR
            * COLOR_WINDOW
            * COLOR_WINDOWFRAME
            * COLOR_WINDOWTEXT
 
'        The system automatically deletes Class background brushes when the Class is unregistered by using UnregisterClass. An application should Not Delete these brushes.''''
'
'        When this member is NULL, an application must Paint its own background whenever it is requested to Paint in its Client area. To determine whether the background must be painted, an application can either process the WM_ERASEBKGND message Or test the fErase member of the PAINTSTRUCT structure filled by the BeginPaint Function.
 
'    lpszMenuName
'       Pointer to a null-terminated character String that specifies the resource Name of the Class Menu, as the Name appears in the resource file. If you use an integer to identify the Menu, use the MAKEINTRESOURCE Macro. If this member is NULL, windows belonging to this Class have no default Menu.
 
'lpszClassName
'pointer to a null-terminated string - the Window Class Name (any name registered with RegisterClass Or RegisterClassEx, or any of the predefined control-class names.
 
        The maximum length For lpszClassName is 256. If lpszClassName is greater than the maximum length, the RegisterClassEx Function will fail.
 
'hIconSm
'handle to a small icon associated with the Window Class. If NULL, the icon is drawn from hIcon property
 
'gbs_00353
'Date: 03-10-2012


created by gbSnippets
http://www.garybeene.com/sw/gbsnippets.htm