📄 jwauxtheme.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. }
{ }
{ 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 JwaUxTheme;
{$WEAKPACKAGEUNIT}
{$HPPEMIT ''}
{$HPPEMIT '#include "uxtheme.h"'}
{$HPPEMIT ''}
{$I WINDEFINES.INC}
interface
uses
JwaWinType, JwaWinGDI;
type
HIMAGELIST = HANDLE; // TODO TEMPORARY
type
HTHEME = HANDLE; // 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.
//---------------------------------------------------------------------------
function OpenThemeData(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).
//---------------------------------------------------------------------------
function CloseThemeData(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)
//------------------------------------------------------------------------
function DrawThemeBackground(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer;
const pRect: RECT; 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
//-------------------------------------------------------------------------
function DrawThemeText(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer;
pszText: LPCWSTR; iCharCount: Integer; dwTextFlags, dwTextFlags2: DWORD;
const pRect: RECT): 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
//-------------------------------------------------------------------------
function GetThemeBackgroundContentRect(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer;
const pBoundingRect: RECT; 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
//-------------------------------------------------------------------------
function GetThemeBackgroundExtent(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer;
const pContentRect: RECT; var pExtentRect: RECT): 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
//-------------------------------------------------------------------------
function GetThemePartSize(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer;
prc: PRECT; eSize: THEMESIZE; var psz: TSize): HRESULT; stdcall;
{$EXTERNALSYM GetThemePartSize}
//-------------------------------------------------------------------------
// GetThemeTextExtent() - calculates the size/location of the specified
// text when rendered in the Theme Font.
//
// hTheme - theme data handle
// hdc - HDC to select font & measure into
// iPartId - part number to draw
// iStateId - state number (of the part)
// pszText - the text to be measured
// dwCharCount - number of chars to draw (-1 for all)
// dwTextFlags - same as DrawText() "uFormat" param
// pszBoundingRect - optional: to control layout of text
// pszExtentRect - receives the RECT for text size/location
//-------------------------------------------------------------------------
function GetThemeTextExtent(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer;
pszText: LPCWSTR; iCharCount: Integer; dwTextFlags: DWORD; pBoundingRect: PRECT;
var pExtentRect: RECT): HRESULT; stdcall;
{$EXTERNALSYM GetThemeTextExtent}
//-------------------------------------------------------------------------
// GetThemeTextMetrics()
// - returns info about the theme-specified font
// for the part/state passed in.
//
// hTheme - theme data handle
// hdc - optional: HDC for screen context
// iPartId - part number to draw
// iStateId - state number (of the part)
// ptm - receives the font info
//-------------------------------------------------------------------------
function GetThemeTextMetrics(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer;
var ptm: TEXTMETRIC): HRESULT; stdcall;
{$EXTERNALSYM GetThemeTextMetrics}
//-------------------------------------------------------------------------
// GetThemeBackgroundRegion()
// - computes the region for a regular or partially
// transparent theme-specified background that is
// bound by the specified "pRect".
// If the rectangle is empty, sets the HRGN to NULL
// and return S_FALSE.
//
// hTheme - theme data handle
// hdc - optional HDC to draw into (DPI scaling)
// iPartId - part number to draw
// iStateId - state number (of the part)
// pRect - the RECT used to draw the part
// pRegion - receives handle to calculated region
//-------------------------------------------------------------------------
function GetThemeBackgroundRegion(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer;
const pRect: RECT; var pRegion: HRGN): HRESULT; stdcall;
{$EXTERNALSYM GetThemeBackgroundRegion}
//-------------------------------------------------------------------------
//----- HitTestThemeBackground, HitTestThemeBackgroundRegion flags ----
// Theme background segment hit test flag (default). possible return values are:
// HTCLIENT: hit test succeeded in the middle background segment
// HTTOP, HTLEFT, HTTOPLEFT, etc: // hit test succeeded in the the respective theme background segment.
const
HTTB_BACKGROUNDSEG = $0000;
{$EXTERNALSYM HTTB_BACKGROUNDSEG}
// Fixed border hit test option. possible return values are:
// HTCLIENT: hit test succeeded in the middle background segment
// HTBORDER: hit test succeeded in any other background segment
HTTB_FIXEDBORDER = $0002; // Return code may be either HTCLIENT or HTBORDER.
{$EXTERNALSYM HTTB_FIXEDBORDER}
// Caption hit test option. Possible return values are:
// HTCAPTION: hit test succeeded in the top, top left, or top right background segments
// HTNOWHERE or another return code, depending on absence or presence of accompanying flags, resp.
HTTB_CAPTION = $0004;
{$EXTERNALSYM HTTB_CAPTION}
// Resizing border hit test flags. Possible return values are:
// HTCLIENT: hit test succeeded in middle background segment
// HTTOP, HTTOPLEFT, HTLEFT, HTRIGHT, etc: hit test succeeded in the respective system resizing zone
// HTBORDER: hit test failed in middle segment and resizing zones, but succeeded in a background border segment
HTTB_RESIZINGBORDER_LEFT = $0010; // Hit test left resizing border,
{$EXTERNALSYM HTTB_RESIZINGBORDER_LEFT}
HTTB_RESIZINGBORDER_TOP = $0020; // Hit test top resizing border
{$EXTERNALSYM HTTB_RESIZINGBORDER_TOP}
HTTB_RESIZINGBORDER_RIGHT = $0040; // Hit test right resizing border
{$EXTERNALSYM HTTB_RESIZINGBORDER_RIGHT}
HTTB_RESIZINGBORDER_BOTTOM = $0080; // Hit test bottom resizing border
{$EXTERNALSYM HTTB_RESIZINGBORDER_BOTTOM}
HTTB_RESIZINGBORDER = (HTTB_RESIZINGBORDER_LEFT or HTTB_RESIZINGBORDER_TOP or
HTTB_RESIZINGBORDER_RIGHT or HTTB_RESIZINGBORDER_BOTTOM);
{$EXTERNALSYM HTTB_RESIZINGBORDER}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -