📄 uxtheme.pas
字号:
{******************************************************************************}
{ }
{ Visual Styles (Themes) API interface Unit for Object Pascal }
{ }
{ Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
{ Corporation. All Rights Reserved. }
{ }
{ The original file is: uxtheme.h, released June 2001. The original Pascal }
{ code is: UxTheme.pas, released July 2001. The initial developer of the }
{ Pascal code is Marcel van Brakel (brakelm@chello.nl). }
{ }
{ Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
{ Marcel van Brakel. All Rights Reserved. }
{ }
{ Portions created by Mike Lischke are Copyright (C) 1999-2002 }
{ Mike Lischke. All Rights Reserved. }
{ }
{ Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
{ }
{ You may retrieve the latest version of this file at the Project JEDI home }
{ page, located at http://delphi-jedi.org or my personal homepage located at }
{ http://members.chello.nl/m.vanbrakel2 }
{ }
{ The contents of this file are used with permission, subject to the Mozilla }
{ Public License Version 1.1 (the "License"); you may not use this file except }
{ in compliance with the License. You may obtain a copy of the License at }
{ http://www.mozilla.org/MPL/MPL-1.1.html }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, }
{ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
{ the specific language governing rights and limitations under the License. }
{ }
{ Alternatively, the contents of this file may be used under the terms of the }
{ GNU Lesser General Public License (the "LGPL License"), in which case the }
{ provisions of the LGPL License are applicable instead of those above. }
{ If you wish to allow use of your version of this file only under the terms }
{ of the LGPL License and not to allow others to use your version of this file }
{ under the MPL, indicate your decision by deleting the provisions above and }
{ replace them with the notice and other provisions required by the LGPL }
{ License. If you do not delete the provisions above, a recipient may use }
{ your version of this file under either the MPL or the LGPL License. }
{ }
{ For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
{ }
{******************************************************************************}
unit UxTheme;
{$HPPEMIT ''}
{$HPPEMIT '#include "uxtheme.h"'}
{$HPPEMIT ''}
interface
uses
Windows;
procedure FreeThemeLibrary;
function InitThemeLibrary: Boolean;
function UseThemes: Boolean;
const
WM_THEMECHANGED = $031A;
type
HIMAGELIST = THANDLE; // TODO TEMPORARY
HTHEME = THANDLE; // handle to a section of theme data for class
{$EXTERNALSYM HTHEME}
//----------------------------------------------------------------------------------------------------------------------
// NOTE: PartId's and StateId's used in the theme API are defined in the
// hdr file <tmschema.h> using the TM_PART and TM_STATE macros. For
// example, "TM_PART(BP, PUSHBUTTON)" defines the PartId "BP_PUSHBUTTON".
//----------------------------------------------------------------------------------------------------------------------
// OpenThemeData() - Open the theme data for the specified HWND and
// semi-colon separated list of class names.
//
// OpenThemeData() will try each class name, one at
// a time, and use the first matching theme info
// found. If a match is found, a theme handle
// to the data is returned. If no match is found,
// a "NULL" handle is returned.
//
// When the window is destroyed or a WM_THEMECHANGED
// msg is received, "CloseThemeData()" should be
// called to close the theme handle.
//
// hwnd - window handle of the control/window to be themed
//
// pszClassList - class name (or list of names) to match to theme data
// section. if the list contains more than one name,
// the names are tested one at a time for a match.
// If a match is found, OpenThemeData() returns a
// theme handle associated with the matching class.
// This param is a list (instead of just a single
// class name) to provide the class an opportunity
// to get the "best" match between the class and
// the current theme. For example, a button might
// pass L"OkButton, Button" if its ID=ID_OK. If
// the current theme has an entry for OkButton,
// that will be used. Otherwise, we fall back on
// the normal Button entry.
//----------------------------------------------------------------------------------------------------------------------
var
OpenThemeData: function(hwnd: HWND; pszClassList: LPCWSTR): HTHEME; stdcall;
{$EXTERNALSYM OpenThemeData}
//----------------------------------------------------------------------------------------------------------------------
// CloseTHemeData() - closes the theme data handle. This should be done
// when the window being themed is destroyed or
// whenever a WM_THEMECHANGED msg is received
// (followed by an attempt to create a new Theme data
// handle).
//
// hTheme - open theme data handle (returned from prior call
// to OpenThemeData() API).
//----------------------------------------------------------------------------------------------------------------------
var
CloseThemeData: function(hTheme: HTHEME): HRESULT; stdcall;
{$EXTERNALSYM CloseThemeData}
//----------------------------------------------------------------------------------------------------------------------
// functions for basic drawing support
//----------------------------------------------------------------------------------------------------------------------
// The following methods are the theme-aware drawing services.
// Controls/Windows are defined in drawable "parts" by their author: a
// parent part and 0 or more child parts. Each of the parts can be
// described in "states" (ex: disabled, hot, pressed).
//----------------------------------------------------------------------------------------------------------------------
// For the list of all themed classes and the definition of all
// parts and states, see the file "tmschmea.h".
//----------------------------------------------------------------------------------------------------------------------
// Each of the below methods takes a "iPartId" param to specify the
// part and a "iStateId" to specify the state of the part.
// "iStateId=0" refers to the root part. "iPartId" = "0" refers to
// the root class.
//----------------------------------------------------------------------------------------------------------------------
// Note: draw operations are always scaled to fit (and not to exceed)
// the specified "Rect".
//----------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------
// DrawThemeBackground()
// - draws the theme-specified border and fill for
// the "iPartId" and "iStateId". This could be
// based on a bitmap file, a border and fill, or
// other image description.
//
// hTheme - theme data handle
// hdc - HDC to draw into
// iPartId - part number to draw
// iStateId - state number (of the part) to draw
// pRect - defines the size/location of the part
// pClipRect - optional clipping rect (don't draw outside it)
//----------------------------------------------------------------------------------------------------------------------
var
DrawThemeBackground: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer; const pRect: TRect;
pClipRect: PRECT): HRESULT; stdcall;
{$EXTERNALSYM DrawThemeBackground}
//----------------------------------------------------------------------------------------------------------------------
//----- DrawThemeText() flags ----
const
DTT_GRAYED = $1; // draw a grayed-out string
{$EXTERNALSYM DTT_GRAYED}
//----------------------------------------------------------------------------------------------------------------------
// DrawThemeText() - draws the text using the theme-specified
// color and font for the "iPartId" and
// "iStateId".
//
// hTheme - theme data handle
// hdc - HDC to draw into
// iPartId - part number to draw
// iStateId - state number (of the part) to draw
// pszText - actual text to draw
// dwCharCount - number of chars to draw (-1 for all)
// dwTextFlags - same as DrawText() "uFormat" param
// dwTextFlags2 - additional drawing options
// pRect - defines the size/location of the part
//----------------------------------------------------------------------------------------------------------------------
var
DrawThemeText: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer; pszText: LPCWSTR; iCharCount: Integer;
dwTextFlags, dwTextFlags2: DWORD; const pRect: TRect): HRESULT; stdcall;
{$EXTERNALSYM DrawThemeText}
//----------------------------------------------------------------------------------------------------------------------
// GetThemeBackgroundContentRect()
// - gets the size of the content for the theme-defined
// background. This is usually the area inside
// the borders or Margins.
//
// hTheme - theme data handle
// hdc - (optional) device content to be used for drawing
// iPartId - part number to draw
// iStateId - state number (of the part) to draw
// pBoundingRect - the outer RECT of the part being drawn
// pContentRect - RECT to receive the content area
//----------------------------------------------------------------------------------------------------------------------
var
GetThemeBackgroundContentRect: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer;
const pBoundingRect: TRect; pContentRect: PRECT): HRESULT; stdcall;
{$EXTERNALSYM GetThemeBackgroundContentRect}
//----------------------------------------------------------------------------------------------------------------------
// GetThemeBackgroundExtent() - calculates the size/location of the theme-
// specified background based on the
// "pContentRect".
//
// hTheme - theme data handle
// hdc - (optional) device content to be used for drawing
// iPartId - part number to draw
// iStateId - state number (of the part) to draw
// pContentRect - RECT that defines the content area
// pBoundingRect - RECT to receive the overall size/location of part
//----------------------------------------------------------------------------------------------------------------------
var
GetThemeBackgroundExtent: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer; const pContentRect: TRect;
var pExtentRect: TRect): HRESULT; stdcall;
{$EXTERNALSYM GetThemeBackgroundExtent}
//----------------------------------------------------------------------------------------------------------------------
type
THEMESIZE = (
TS_MIN, // minimum size
TS_TRUE, // size without stretching
TS_DRAW // size that theme mgr will use to draw part
);
{$EXTERNALSYM THEMESIZE}
TThemeSize = THEMESIZE;
//----------------------------------------------------------------------------------------------------------------------
// GetThemePartSize() - returns the specified size of the theme part
//
// hTheme - theme data handle
// hdc - HDC to select font into & measure against
// iPartId - part number to retrieve size for
// iStateId - state number (of the part)
// prc - (optional) rect for part drawing destination
// eSize - the type of size to be retreived
// psz - receives the specified size of the part
//----------------------------------------------------------------------------------------------------------------------
var
GetThemePartSize: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer; prc: PRECT; eSize: THEMESIZE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -