Delphi Full Fashion Manual Visual Style --- Make non-standard Win32 control or self-drawing controls also have Windows XP interface style
Here first, talking two concepts: Theme (topic) and Visual Style. Theme first appeared in Microsoft Plus! For Windows 95, which is a set value collection in Wallpaper, Cursors, Fonts, Sounds, Icons, and so on Windows. Visual Style is introduced in Windows XP, and Visual Style specifies the appearance of Contrars and other APIs using these appearances. Using Visual Style must be ComctL32.dll 6, and ComctL32.dll 6 cannot be distributed to previous versions of Windows, so you can only use Visual Style under Windows XP.
Delphi 7 provides better support for Visual Style for Visual Style. First, 7 MeniFest is encapsulated into VCL - TXPMenifest, which added UXTHEME.PAS unit, which is a reference declaration for a set of APIs and constants, constants, and the like for Visual Style (probably 47 API functions), more important It is 7 that also adds a THEMES.PAS unit, which is a further simplified and encapsulation of this API, and the Win32 control of 7 has a great change in Visual Style than Delphi 6, which is the credit of this unit.
Generally, the program to be compiled in 7 has Visual Style in Windows XP, just put VCL - TXPMENIFEST on the main form, but for some non-standard or self-drawn controls, or a classic interface. Here, how to make these controls have Visual Style with the methods provided in THEMES.PAS.
There is only one class in Themes.PAS: Tthemeservices. This class has an important attribute: Themesenabled (Boolean type) is to determine that the current program can use Visual Style, this property is only used in the program using TXPMENIFEST and runs under Windows XP and uses the topic of Windows XP (ie desktop topic) Not a Windows Classic) is True, because the program is running under the previous version of Windows, so your program has to provide this property to the processing process (generally the original processing). It is also necessary to mention several important functions of this type of package: DrawEdge is used to draw the boundaries of the control part, DrawElement is used to draw the entire interface, DrawText is used to write. This class also handles the WM_THEMECHANGED message, so when we change the desktop topic, the program will automatically adjust the appearance. Let's talk about a function (polymorphic function) of our most commonly used: getElementDetails, the return value of this function is used in several DrawXXX functions above, the input value of this function is the element in the type of 24 enumerations, this 24 enumeration types are defined at the beginning of Themes.Pas unit (starting from the second TthemedButton until TthemedWindow). Finally, we don't go directly to use this class directly, there is a function in Themes.Pas unit:
Function Themeservices: Tthemeservices; return value is this class, so we use this method directly, and 7 VCLs do this.
Ok, let's take a simple example below. Delphi's TPANEL control is not a standard control, we come on it to implement Visual Style. Infining a new project in Delphi 7, put TXPMENIFEST on the main form, reference the themes unit in Unit1 unit,
TFORM1 = Class (TFORM)
The next code is added (mainly the Paint method of the TCUSTompanel):
TVSPANEL = Class (TCUSTompanel)
Private
//
protected
proca;
public
//
END;
The heavy-duty PAINT method is achieved as follows:
Procedure tvspanel.paint;
VAR
Details: TtheMedelementDetails;
Begin
inherited;
If Themeservices.Themesenabled Then
Begin
Details: = themeservices.getElementDetails (TBPushbuttonhot); {Here you draw a button in a hot state}
PerforseBackground (Self, Canvas.Handle); {Erase button background}
Themeservices.drawElement (Canvas.Handle, Details, ClientRect);
Themeservices.drawtext (canvas.Handle, Details, Caption, ClientRect,
DT_EXPANDTABS OR DT_VCENTER OR DT_CENTER OR DT_SINGLINE, 0);
END;
END;
TCUSTompanel changes, and then instantiate Tvspanel in the Create event of the main form, the code is as follows:
Procedure TFORM1.FormCreate (Sender: TOBJECT);
VAR
APANEL: TVSPANEL;
Begin
Apanel: = tvspanel.create (Application);
APANEL.LEFT: = 100;
APANEL.TOP: = 100;
APANEL.WIDTH: = 200;
APANEL.HEIGHT: = 30;
APANEL.CAPTION: = 'PANEL' with Button Style;
APANEL.PARENT: = Self;
END;
Ok, run to see if the Visual Style effect is out. I have a floating window with ThintWindow and add Visual Style. The effect is not bad. If it is fine, make the floating strip of Microsoft Pinyin input method under Windows XP. The same interface.
In addition, there are several important things that are not mentioned, such as Part and State, you can check MSDN, in User Interface Design and Developments / Windows Shell / Shell Refrence / Visual Styles Refrence, Email can also be discussed with me: happyjoe @ 21cn.com