Window Classes (Windows and Messages)
This topic describes the types of window classes, how the system locates them, and the elements that define the default behavior of windows that belong to them.
A window class is a set of attributes that the system uses as a template to create a window. Every window is a member of a window class. All window classes are process specific.
In This Section
Name | Description |
---|---|
About Window Classes | Discusses window classes. Each window class has an associated window procedure shared by all windows of the same class. The window procedure processes messages for all windows of that class and therefore controls their behavior and appearance. |
Using Window Classes | Demonstrates how to register a local window and use it to create a main window. |
Window Class Reference | Contains the API reference. |
Window Class Functions
Name | Description |
---|---|
GetClassInfoEx | Retrieves information about a window class, including a handle to the small icon associated with the window class. The GetClassInfo function does not retrieve a handle to the small icon. |
GetClassLong | Retrieves the specified 32-bit (long) value from the WNDCLASSEX structure associated with the specified window. |
GetClassLongPtr | Retrieves the specified value from the WNDCLASSEX structure associated with the specified window. |
GetClassName | Retrieves the name of the class to which the specified window belongs. |
GetWindowLong | Retrieves information about the specified window. The function also retrieves the 32-bit (long) value at the specified offset into the extra window memory. |
GetWindowLongPtr | Retrieves information about the specified window. The function also retrieves the value at a specified offset into the extra window memory. |
RegisterClass | Registers a window class for subsequent use in calls to the CreateWindow or CreateWindowEx function. |
RegisterClassEx | Registers a window class for subsequent use in calls to the CreateWindow or CreateWindowEx function. |
SetClassLongPtr | Replaces the specified value at the specified offset in the extra class memory or the WNDCLASSEX structure for the class to which the specified window belongs. |
SetClassWord | Replaces the 16-bit (WORD) value at the specified offset into the extra class memory for the window class to which the specified window belongs. |
SetWindowLong | Changes an attribute of the specified window. The function also sets the 32-bit (long) value at the specified offset into the extra window memory. |
SetWindowLongPtr | Changes an attribute of the specified window. The function also sets a value at the specified offset in the extra window memory. |
UnregisterClass | Unregisters a window class, freeing the memory required for the class. |
The following functions are obsolete.
Name | Description |
---|---|
GetClassInfo | Retrieves information about a window class.
|
GetClassWord | Retrieves the 16-bit (WORD) value at the specified offset into the extra class memory for the window class to which the specified window belongs.
|
SetClassLong | Replaces the specified 32-bit (long) value at the specified offset into the extra class memory or the WNDCLASSEX structure for the class to which the specified window belongs.
Style ClassDefinitionEnables the sharing of properties, resources, and event handlers between instances of a type. ExamplesThe following example shows a style declaration that will affect the Background property of a Control. To apply the above style, do the following: You can also apply styles to all elements of a given type by using the TargetType property. Adding the target type to the style means that you no longer have to fully qualify the property you are setting with the ClassName.PropertyName syntax. The following example defines a style that will be applied to every TextBlock element. Many WPF controls consist of a combination of other WPF controls, so creating a style that applies to all controls of a type can have broad impact. For instance, if you create a style that targets the TextBlock controls in a Canvas, the style is applied to all TextBlock controls in the canvas, even if the TextBlock is part of another control, such as a ListBox. For information on how to extend or inherit from a defined style, see the BasedOn page. RemarksYou can set a Style on any element that derives from FrameworkElement or FrameworkContentElement. A style is most commonly declared as a resource inside the Resources section. Because styles are resources, they obey the same scoping rules that apply to all resources, so where you declare a style affects where it can be applied. If, for instance, you declare the style in the root element of your application definition XAML file, the style can be used anywhere in your application. If you are creating a navigation application and declare the style in one of the application’s XAML files, the style can be used only in that XAML file. For more information on scoping rules for resources, see XAML Resources. The style declaration consists of a Style object that contains a collection of one or more Setter objects. Each Setter consists of a Property and a Value. The property is the name of the property of the element the style is to apply to. After the style is declared as a resource, it can then be referenced just like any other resource. If there is more than one setter in the setter collection with the same Property property value, the setter that is declared last is used. Similarly, if you set a value for the same property in a style and on an element directly, the value set on the element directly takes precedence. The Windows Presentation Foundation (WPF) styling and templating model allows maintenance and sharing of a look as well as the separation of presentation and logic. The styling and templating model includes a suite of features that enable you to customize your UI. This suite of features includes the Style class as well as the following: Style КлассОпределениеОбеспечивает возможность совместного использования свойств, ресурсов и обработчиков событий экземплярами типа. Enables the sharing of properties, resources, and event handlers between instances of a type. ПримерыВ следующем примере показано объявление стиля, которое будет влиять на Background свойство объекта Control . The following example shows a style declaration that will affect the Background property of a Control. Чтобы применить приведенный выше стиль, выполните следующие действия. To apply the above style, do the following: Стили можно также применить ко всем элементам заданного типа с помощью TargetType Свойства. You can also apply styles to all elements of a given type by using the TargetType property. Добавление целевого типа к стилю означает, что больше не нужно полностью определять свойство, которое вы задаете с помощью ClassName.PropertyName синтаксиса. Adding the target type to the style means that you no longer have to fully qualify the property you are setting with the ClassName.PropertyName syntax. В следующем примере определяется стиль, который будет применен к каждому TextBlock элементу. The following example defines a style that will be applied to every TextBlock element. Многие элементы управления WPF состоят из сочетания других элементов управления WPF, поэтому создание стиля, применяемого ко всем элементам управления типа, может иметь широкие последствия. Many WPF controls consist of a combination of other WPF controls, so creating a style that applies to all controls of a type can have broad impact. Например, при создании стиля, предназначенного TextBlock для элементов управления в Canvas , стиль применяется ко всем TextBlock элементам управления на холсте, даже если TextBlock является частью другого элемента управления, например ListBox . For instance, if you create a style that targets the TextBlock controls in a Canvas, the style is applied to all TextBlock controls in the canvas, even if the TextBlock is part of another control, such as a ListBox. Сведения о том, как расширить или наследовать из определенного стиля, см BasedOn . на странице. For information on how to extend or inherit from a defined style, see the BasedOn page. КомментарииМожно задать Style для любого элемента, производного от FrameworkElement или FrameworkContentElement . You can set a Style on any element that derives from FrameworkElement or FrameworkContentElement. Стиль чаще всего объявляется как ресурс внутри Resources раздела. A style is most commonly declared as a resource inside the Resources section. Так как стили являются ресурсами, они подчиняются тем же правилам области, которые применяются ко всем ресурсам, поэтому объявление стиля влияет на место его применения. Because styles are resources, they obey the same scoping rules that apply to all resources, so where you declare a style affects where it can be applied. Например, если вы объявили стиль в корневом элементе файла XAML определения приложения, стиль можно использовать в любом месте приложения. If, for instance, you declare the style in the root element of your application definition XAML file, the style can be used anywhere in your application. Если вы создаете приложение навигации и объявляете стиль в одном из XAML-файлов приложения, стиль можно использовать только в этом файле XAML. If you are creating a navigation application and declare the style in one of the application’s XAML files, the style can be used only in that XAML file. Дополнительные сведения о правилах области для ресурсов см. в разделе ресурсы XAML. For more information on scoping rules for resources, see XAML Resources. Объявление стиля состоит из Style объекта, содержащего коллекцию из одного или нескольких Setter объектов. The style declaration consists of a Style object that contains a collection of one or more Setter objects. Каждый Setter из них состоит из Property и Value . Each Setter consists of a Property and a Value. Свойство является именем свойства элемента, к которому применяется стиль. The property is the name of the property of the element the style is to apply to. После объявления стиля в качестве ресурса он может ссылаться так же, как и любой другой ресурс. After the style is declared as a resource, it can then be referenced just like any other resource. Если в коллекции Setter имеется несколько методов задания с одинаковым Property значением свойства, используется метод задания, объявленный последним. If there is more than one setter in the setter collection with the same Property property value, the setter that is declared last is used. Аналогично, если задать значение для одного и того же свойства в стиле и в элементе напрямую, то значение, заданное для элемента напрямую, имеет приоритет. Similarly, if you set a value for the same property in a style and on an element directly, the value set on the element directly takes precedence. Модель стилизации и шаблонов Windows Presentation Foundation (WPF) обеспечивает поддержку и совместное использование внешнего вида, а также разделение представления и логики. The Windows Presentation Foundation (WPF) styling and templating model allows maintenance and sharing of a look as well as the separation of presentation and logic. Модель стилизации и шаблонов включает набор функций, позволяющих настраивать пользовательский интерфейс. The styling and templating model includes a suite of features that enable you to customize your UI. Этот набор функций включает класс, а Style также следующие компоненты: This suite of features includes the Style class as well as the following: Более подробную информацию см. в разделе Стилизация и использование шаблонов. For more information, see Styling and Templating. КонструкторыИнициализирует новый экземпляр класса Style. Initializes a new instance of the Style class. Инициализирует новый экземпляр класса Style для использования с заданным объектом Type. Initializes a new instance of the Style class to use on the specified Type. Инициализирует новый экземпляр класса Style для использования с указанным Type, основанный на заданном Style. Initializes a new instance of the Style class to use on the specified Type and based on the specified Style. СвойстваВозвращает или задает определенный стиль, являющийся основой текущего стиля. Gets or sets a defined style that is the basis of the current style. Возвращает объект Dispatcher, с которым связан этот объект DispatcherObject. Gets the Dispatcher this DispatcherObject is associated with. (Унаследовано от DispatcherObject) |
IsSealed | |
Equals(Object) | |
GetHashCode() | |
MemberwiseClone() | |
RegisterName(String, Object) | |
UnregisterName(String) |
Явные реализации интерфейса
Добавляет дочерний объект. Adds a child object.
Добавляет к объекту текстовое содержимое узла. Adds the text content of a node to the object.
Возвращает объект с предоставленным идентифицирующим именем. Returns an object that has the provided identifying name.
Запрашивает, доступно ли заданное внешнее свойство в текущей области. Queries whether a specified ambient property is available in the current scope.