Window Windows class

Source: Internet
Author: User

the window Class WNDCLASS summary summarizes the following several questions:1. What is a window class2. Three types of window classes3. Window class The meaning of each field4Registration and logoff of window classes5How to use the window classes, subclasses, and superclass are described below, respectively:1. What is a window class?    The window class defines a series of properties that the system uses as a template to create one or more windows.    Each window class is associated with a Windows Procedure Function (window procedure), and all Windows (window) created by the window class share the same window procedure function. The window class (RegisterClassEx) must be registered before the window is created in the process. When registering a window class, the window class is associated with a window class name (classname).        When creating a window, just pass in the window class name and the system will help you find the corresponding window class to create the window.        What is the function and display of a window created by a window class depends largely on how the window procedure function is written. The relationship between a window class and a window can be analogous to a relationship between a class and an object.    A window class is like a class definition, and a window is like an object. A window procedure function is like a member function of a class, and the first parameter in a window procedure function is a handle to a window, and a member function similar to a class has a default Thispointer. C++the class definition in the linker can be found by Win32, there is no such thing, so you need to register the window class to find the class definition according to the class name. Problem: Customizing a window class, such as implementing a ListBox control, how to add an external interface to this control? Similar to the listbox. Setlistitem () How is this interface implemented? Doubts here be deciphered2The three types of window classes have three types of window classes that differ in scope, registration, and destruction timing:1the window class registered by the System window class (System Classes) can be used without registering the program.                    The system registers the system window class for the first time the program calls the GDI function, and each program gets a copy of the System window class.                Scope: All WIN32 processes in the system destroy time: Unable to destroy the following are some system Classes:button that can be used directly by the program                ComboBox Edit ListBox mdiclient ScrollBar                     Static Some system Classes are used internally: Combolbox ddemlevent Message #32768                #32769                #32770                #32771                #32772                    2The Program Global window Class (Application global Classes) program registers its own window class, WNDCLASS's style is specified as Cs_globalclass, and all modules in the current process can be used after registration. For example, to register a global window class in the A.dll DllMain, if b.exe loads the A.dll, then you can use that window class in B.exe.                    The whole point is that. Scope: All modules of a process (EXE, DLL) destroy time: self-unregisterclass as an extension of this feature, Win32 has a technique that allows a third-party control to be implemented in a DLL , and then load the DLL into each Win32 process address space. This control can be used by all processes so that the details of this technique are to register a third-party control in the DLL's DllMain, and then write the name of the DLL to the registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ Windows Nt\currentversion\windows\appinit_dlls So when any Win32 process is loaded, the system also loads the DLL into the program's process address space (this can be a bit extravagant, not every Process requires this third-party control).                    This allows the window class to be used directly in any Win32 process. 3Program Local window class (application local Classes) program self-registered window class, WNDCLASS style does not specify Cs_globalclass, registered only after registration module can be used.                    For example, the local window class registered in the A.dll can only be used in A.dll, even if b.exe loads the a.dll.                    Scope: Only the module that registers the window class can use the destroy time: self-unregisterclass Program The local window class is the most frequently used class (in most cases the window class does not need to be used for other modules) Question: Is the global window class or local window class registered in the DLL automatically destroyed when the DLL is unloaded? If a window has been created, will the window be destroyed automatically?                There is doubt be deciphered here. 3. window class each field means that the window class is represented by the WNDCLASS structure, and Wndclassex is an extended version, with a small icon HICONSM member. typedefstructtagwndclassex {UINT cbsize;        UINT style;        WNDPROC Lpfnwndproc; intCbclsextra; intCbwndextra;        HINSTANCE hinstance;        Hicon Hicon;        Hcursor Hcursor;        Hbrush Hbrbackground;        LPCTSTR Lpszmenuname;        LPCTSTR lpszClassName;    Hicon HICONSM; } wndclassex,*Pwndclassex;        lpszClassName: Window class name, identifies a window class, equivalent to the window class ID; Within the same module, you cannot register a local window class with the same name, and within the same process, you cannot register a global window class with the same name, but you can register a local window class with the same name as the global window class or the System window class, which is determined by the order in which the system looks for the window class. When you create a window based on the window class name, the system navigates to the window class in the following order:1Look up the window class from the list of local window classes based on the window class name hinstance The hinstance of the current module (the different modules of the program can register the local window class with the same window class name);2If there is no window class name to look up in the local window class list, look it up from the Global window class table;3If there is no window class name to look up in the Global window class list, look it up from the System window class table, in this order, the system will still be correctly positioned to the local window class, even if the local window class name is the same as the global window class or the System window class. For example, you can register a"Edit"The local window class, created within the module"Edit"window, the definition of the local window class is used instead of the system window class.            HINSTANCE: the instance handle, which identifies the module in which the window class resides, can be the hinstance of the process, the hmodule of the DLL, and cannot be NULL;                Lpfnwndproc: Window procedure function address, the function of the window is implemented by this function. For Windows created from this class, all messages are handed over to this window procedure function for processing.            The program can use SetWindowLong to change the process function of the window class, which is called "Subclass (Subclassing)", which will be described in detail later.  The Style:style member determines the style of the window created from the class and can use a combination of the following values: CS_OWNDC,CS_CLASSDC,CS_PARENTDC: These flags determine the default window DC (device context):1If you use the CS_OWNDC flag, all Windows instances that belong to this window class are owned by their own DCs (known as Private DCs), so the program only needs to call GetDC or BeginPaint to get the DC, and the system initializes a DC for the window, and the Save program changes the Change. The ReleaseDC and EndPaint functions are no longer needed. When CS_OWNDC is selected, the program must be careful when it changes the Mapping mode, and when the background of the window is erased by the system, the system assumes that the default mapping mode is Mm_text.                If the private DC's mapping mode is different, the window will no longer be visible where it was erased. 2If you use the CS_CLASSDC flag, all instances of the window that belong to the class share the same DC (known as Class DCs). The class DC has the advantage of having a private DC, while saving more memory (because you do not need to allocate 800 bytes of DC space for each window instance). Each window instance gets a device context (DC) handle through GetDC or beginpaint, and if no other window needs the DC, it is not necessary to call ReleaseDC or EndPaint to release the DC. In a window instance, with GETWINDOWDC, GetDC, GetDCEx, BeginPaint get the DC and make changes to some of these parameters, the changes are made in addition to the clipping area and the device's own properties (device origin) is valid for all other window instances. As with CS_OWNDC, it is important to ensure that the innuendo pattern is also mm_text, otherwise the background erased by the system will no longer be visible.                Programs written for NT are best not to use this flag because the "save memory" benefits are not obvious at all. 3If you use the CS_PARENTDC flag, the window that belongs to this class uses the handle of its parent window. Similar to CS_CLASSDC, multiple windows share a DC, unlike the multiple windows (although having a parent-child relationship and sharing a DC) do not require that all belong to the same window class.                Note If the program needs to change the mapping mode of each child window, it is best not to use the CS_PARENTDC flag, otherwise it will be easy to cause the child window mapping mode confusion, because all the child windows use the same DC. 4. If you do not specify CS_OWNDC, CS_CLASSDC, CS_PARENTDC These flags, the window of this class uses a universal DC and is placed in the DC buffer for use. The general purpose DC is obtained before use, released after use, and at the time of the DC, the context of the DC is initialized by default, unless the DC is already in the window's DC buffer (for example, no ReleaseDC or EndPaint release DC), so that the DC's clipping boundary and device                                Properties do not need to be re-initialized, you can save some time.            Question: These fields relate to concepts such as DC and mapping patterns that are not yet known, and are doubtful be deciphered. Cs_globalclass:cs_globalclass is the only flag that works on the class itself rather than on a window.                            The system saves the window class containing this flag as the application global class.                            Cs_bytealignclient, Cs_bytealignwindow: Byte alignment flag, is said to be useless. Cs_hredraw, the CS_VREDRAW:CS_HREDRAW flag indicates that the entire window is redrawn when the horizontal size (width) of the window changes. Cs_vredraw the window when the vertical size (height) of the window changes.                                Both buttons and scroll bars have both styles. Question: Under what circumstances do you need to specify these two flags?            Doubt be deciphered.                            Cs_noclose: If this flag is specified, the Close button on the window and the close command on the system menu are invalidated. The CS_DBLCLKS:CS_DBLCLKS flag enables the window to detect double-click events.                    The details of the window response double-click are as follows: Wm_lbuttondown Wm_lbuttonup Wm_lbuttondown Wm_lbuTtonup is actually two clicks, and if the CS_DBLCLKS flag is specified, the system wants the window to send the following message in turn: Wm_lbuttondown W M_lbuttonup WM_LBUTTONDBLCLK Wm_lbuttonup The second wm_lbuttondown was replaced by a W                                M_LBUTTONDBLCLK Note that one or more messages may be inserted in the middle of the sequence, so the two message sequences are not necessarily completely contiguous. In fact, when the CS_DBLCLKS flag is not specified, the program itself can also detect double-click events.  See the MSDN Dr.gut"simulating Mouse Button Clicks"article, but there are some tricks. In general, if Cs_dblclks is not specified, the WM_LBUTTONDBLCLK message will not be received in the window's message loop. All standard window controls, dialog boxes, and Desktop window classes all have the CS_DBLCLKS flag by default.                        Third-party controls are best added to this style so that they work correctly in the dialog editor. Cs_savebits: Menu, dialog box, drop-down box all have cs_savebits flag. When the window uses this flag, the system saves a screen image that is obscured (or dimmed) by the window in bitmap form. First, the system requires the display drive to save the image bit data, if the display drive itself has enough storage space, the save operation is successful, the window system can also use these saved bit data. If not enough, the system stores bits of data in global memory as bitmaps, and allocates space for each window in the local heap of the use module, preserving the structure of some transactional data (such as the size of the bitmap data buffer).                When the program makes the window that obscures the screen disappear, the system can quickly recover the screen image from memory. The efficiency of cs_savebits itself is difficult to measure. Cs_savebits improves the performance of "temporary" windows such as menus, dialogs, drop-down boxes. However, the cost of storage bit information is also obvious, especially when the system replaces the display to drive the storage bit information, the system assumes the speed and storage overhead. The advantage of using cs_savebits actually depends on what happens in the area of the window cover, and if the area is quite complex and requires a lot of re-painting, then storing the area may be as easy as drawing the area, and if the reverse, the area can be redrawn quite quickly,                                Or when it is covered, it often changes and changes significantly, and the saved scheme affects overall performance.        Problem: Don't understand this part of the content, can be combined with MSDN to learn. The above style tags are optional fields, depending on the purpose of which you want to use. If the window size does not change, does not respond to double-click Operations, and is not used by other modules, set style==0is also possible. Hicon and Hiconsm: Window icons, Hicon are large icons that show up in the Task Switch window (Alt+TAB), large icon mode taskbar, Explorer, HICONSM is small icon, show in window title bar, small icon mode task bar.        The size of the window icon must match a certain size, the size can be specified by the GetSystemMetrics function Sm_cxicon, Sm_cyicon, Sm_cxsmicon, Sm_cysmicon to get the size of the standard dimensions of the icon.        You can modify the icon by Wm_seticon the message to get the icon by Wm_geticon the message. Hcursor: Window default mouse pointer. When this value is set, when the mouse moves into the window area, the system changes the pointer from the system default shape to the pointer shape you set. The program can use the LoadCursor function to get a pointer handle from a standard system pointer library (such as Idc_arrow) or a user-specified pointer resource. The program can change the pointer at any time through the SetCursor function.        If the value of Hcursor is not set (set to NULL), the program must be set when the mouse pointer moves into the window, otherwise the system default mouse pointer shape will be used. Lpszmenuname: Window default main Menu.        If a menu resource is not explicitly specified when the window is created, the default menu specified here is used.        You can use the Makeintresource macro to convert the ID number of a menu in a resource to a continuous string assignment to that member. Hbrbackground: Window background color, type Hbrush, can be assigned to a brush handle, or a color value.            In the case of color values, one of the following standard system colors must be used: Color_activeborder color_highlighttext color_activecaption            Color_inactiveborder color_appworkspace color_inactivecaption Color_background      Color_inactivecaptiontext color_btnface Color_menu Color_btnshadow      Color_menutext color_btntext Color_scrollbar Color_captiontext Color_win DOW color_graytext color_windowframe color_highlight Color_windowtext makes  When you assign a value with a color, you must add1and cast to Hbrush type: Wcex.hbrbackground = (hbrush) (Color_window +1); If the Hbrbackground member is set to NULL, the program must be responsible for drawing the background when responding to WM_PAINT.        The program can also respond to WM_ERASEBKGND messages, or determine whether the background needs to be redrawn, based on the value class ferase the member in the PAINTSTRUCT structure that is populated when the BeginPaint function is called.        Cbclsextra, Cbwndextra:cbclsextra refers to the window class extra memory size, which is shared by all windows created by the class, Cbwndextra refers to the window extra memory size, each window created by the class has an extra memory; The extra memory size can be up to +A byte. If not required, it must be set to0to prevent system errors from allocating memory.        If you declare and register a window of a dialog box type with a class, the value of Cbwndextra must be set to Dlgwindowextra, and the system dialog manager requires so much extra data to manage the dialog box. 4the registration and Logoff Registration window class uses the RegisterClass or RegisterClassEx function; parameters: Wndclass or wndclassex struct; return value: The original of the ATOM type        Sub-value, it is said that this value corresponds to each window class one by one. Note: Both RegisterClass and RegisterClassEx have two versions of ANSI and Unicode.             If you use the ANSI version, such as Registerclassa, the text information in the message will be in ANSI format, and if you use a Unicode version such as REGISTERCLASSEXW, the text information in the message will be in Unicode format. The Logoff window class uses the Unregisterclass function; parameters: lpszClassName, hinstance return value: If the window class is not located, or if a window is still not destroyed, it will fail and return a non-0values.                Note: Before calling Unregisterclass, you must first destroy all windows created by the class.        After the DLL is unloaded, the window class registered by the DLL is not logged off. 5. How to use the window class, subclass, superclass What happens once a class is registered, there is generally nothing more to do than create a window with that class.    Of course, if you need to access that class of information, subclass, or superclass the class, some methods are useful. Class Access function: Getclassinfoex Gets the window class information, enters HInstance and lpszClassName, and returns the corresponding WNDCLASSEX structure of the window class. You can also enter the Atom Getclasslong from the wndclassex structure to get aLongtype numeric value, input hWnd, NIndex, returns the information for a field in the Wndclassex structure of the window class that corresponds to the window. For example, Getclasslong (HWnd, Gcl_style) can get the style of the window class getclasslongptr is similar to the function above, but returns the result as a pointer. For example, Getclasslongptr (hwnd, GCLP_WNDPROC) can get the window class's procedure function address getclassname get the window class name of a window class, enter HWnd, return Lpclassna Me GetWindowLong gets the specified information for a window toLongtype return, enter HWnd, NIndex, return the information of a field in the window, such as GetWindowLong (HWnd, Gwl_style) can get the window of the styles getwindowlongptr with the above The function is similar in function, but returns the result as a pointer. For example Getwindowlongptr (hWnd, Gwlp_wndproc) can get window corresponding window class window procedure function setclasslongptr Replace Window class wndclassex a field Set Classword is similar to the function above, but it seems to give -SetWindowLong replaces a field of a window with a bit system, enters HWnd, NIndex, Dwnewlong can replace the specified field setwindowlongptr with the above function Functions similar to subclasses: terminology"sub-class"(subclassing) describes the process of replacing the original window with a new window procedure. Terminology"Real example of class"(that is, a subclass of a single window) is a window procedure that uses the SetWindowLong function to change a window instance. Terminology"Global sub-class"(Subclass the entire window class) refers to the default window procedure function that uses Setclasslong to change the entire class. In the +Windows system, it may be difficult to subclass a window or window class in another process, in general, subclasses occur in the same process ("Breaking process Boundaries"related topics are not covered in this article). Hyper-Class: Terminology"Hyper-Class"(superclassing) refers to the creation of a new class that inherits the basic functionality of the class using the window procedure of an existing class, and can be extended on that basis. For a description of subclasses and hyper-class, see MSDN"safe subclasing in Win32"a text http://jdearden.gotdns.org/programming_windows_notebook/safe_subclassing_in_win32.htmlReference Link: https://msdn.microsoft.com/en-us/library/ms633574 (v=vs.85). aspxhttp//blog.csdn.net/vcbear/article/details/5988

Window Windows class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.