UxTheme.pas 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. {******************************************************************************}
  2. { }
  3. { Visual Styles (Themes) API interface Unit for Object Pascal }
  4. { }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
  6. { Corporation. All Rights Reserved. }
  7. { }
  8. { The original file is: uxtheme.h, released June 2001. The original Pascal }
  9. { code is: UxTheme.pas, released July 2001. The initial developer of the }
  10. { Pascal code is Marcel van Brakel ([email protected]). }
  11. { }
  12. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
  13. { Marcel van Brakel. All Rights Reserved. }
  14. { }
  15. { Portions created by Mike Lischke are Copyright (C) 1999-2002 }
  16. { Mike Lischke. All Rights Reserved. }
  17. { }
  18. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
  19. { }
  20. { You may retrieve the latest version of this file at the Project JEDI home }
  21. { page, located at http://delphi-jedi.org or my personal homepage located at }
  22. { http://members.chello.nl/m.vanbrakel2 }
  23. { }
  24. { The contents of this file are used with permission, subject to the Mozilla }
  25. { Public License Version 1.1 (the "License"); you may not use this file except }
  26. { in compliance with the License. You may obtain a copy of the License at }
  27. { http://www.mozilla.org/MPL/MPL-1.1.html }
  28. { }
  29. { Software distributed under the License is distributed on an "AS IS" basis, }
  30. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  31. { the specific language governing rights and limitations under the License. }
  32. { }
  33. { Alternatively, the contents of this file may be used under the terms of the }
  34. { GNU Lesser General Public License (the "LGPL License"), in which case the }
  35. { provisions of the LGPL License are applicable instead of those above. }
  36. { If you wish to allow use of your version of this file only under the terms }
  37. { of the LGPL License and not to allow others to use your version of this file }
  38. { under the MPL, indicate your decision by deleting the provisions above and }
  39. { replace them with the notice and other provisions required by the LGPL }
  40. { License. If you do not delete the provisions above, a recipient may use }
  41. { your version of this file under either the MPL or the LGPL License. }
  42. { }
  43. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  44. { }
  45. {******************************************************************************}
  46. unit UxTheme;
  47. {$HPPEMIT ''}
  48. {$HPPEMIT '#include "uxtheme.h"'}
  49. {$HPPEMIT ''}
  50. interface
  51. uses
  52. Windows;
  53. procedure FreeThemeLibrary;
  54. function InitThemeLibrary: Boolean;
  55. function UseThemes: Boolean;
  56. const
  57. WM_THEMECHANGED = $031A;
  58. type
  59. HIMAGELIST = THANDLE; // TODO TEMPORARY
  60. HTHEME = THANDLE; // handle to a section of theme data for class
  61. {$EXTERNALSYM HTHEME}
  62. //----------------------------------------------------------------------------------------------------------------------
  63. // NOTE: PartId's and StateId's used in the theme API are defined in the
  64. // hdr file <tmschema.h> using the TM_PART and TM_STATE macros. For
  65. // example, "TM_PART(BP, PUSHBUTTON)" defines the PartId "BP_PUSHBUTTON".
  66. //----------------------------------------------------------------------------------------------------------------------
  67. // OpenThemeData() - Open the theme data for the specified HWND and
  68. // semi-colon separated list of class names.
  69. //
  70. // OpenThemeData() will try each class name, one at
  71. // a time, and use the first matching theme info
  72. // found. If a match is found, a theme handle
  73. // to the data is returned. If no match is found,
  74. // a "NULL" handle is returned.
  75. //
  76. // When the window is destroyed or a WM_THEMECHANGED
  77. // msg is received, "CloseThemeData()" should be
  78. // called to close the theme handle.
  79. //
  80. // hwnd - window handle of the control/window to be themed
  81. //
  82. // pszClassList - class name (or list of names) to match to theme data
  83. // section. if the list contains more than one name,
  84. // the names are tested one at a time for a match.
  85. // If a match is found, OpenThemeData() returns a
  86. // theme handle associated with the matching class.
  87. // This param is a list (instead of just a single
  88. // class name) to provide the class an opportunity
  89. // to get the "best" match between the class and
  90. // the current theme. For example, a button might
  91. // pass L"OkButton, Button" if its ID=ID_OK. If
  92. // the current theme has an entry for OkButton,
  93. // that will be used. Otherwise, we fall back on
  94. // the normal Button entry.
  95. //----------------------------------------------------------------------------------------------------------------------
  96. var
  97. OpenThemeData: function(hwnd: HWND; pszClassList: LPCWSTR): HTHEME; stdcall;
  98. {$EXTERNALSYM OpenThemeData}
  99. //----------------------------------------------------------------------------------------------------------------------
  100. // CloseTHemeData() - closes the theme data handle. This should be done
  101. // when the window being themed is destroyed or
  102. // whenever a WM_THEMECHANGED msg is received
  103. // (followed by an attempt to create a new Theme data
  104. // handle).
  105. //
  106. // hTheme - open theme data handle (returned from prior call
  107. // to OpenThemeData() API).
  108. //----------------------------------------------------------------------------------------------------------------------
  109. var
  110. CloseThemeData: function(hTheme: HTHEME): HRESULT; stdcall;
  111. {$EXTERNALSYM CloseThemeData}
  112. //----------------------------------------------------------------------------------------------------------------------
  113. // functions for basic drawing support
  114. //----------------------------------------------------------------------------------------------------------------------
  115. // The following methods are the theme-aware drawing services.
  116. // Controls/Windows are defined in drawable "parts" by their author: a
  117. // parent part and 0 or more child parts. Each of the parts can be
  118. // described in "states" (ex: disabled, hot, pressed).
  119. //----------------------------------------------------------------------------------------------------------------------
  120. // For the list of all themed classes and the definition of all
  121. // parts and states, see the file "tmschmea.h".
  122. //----------------------------------------------------------------------------------------------------------------------
  123. // Each of the below methods takes a "iPartId" param to specify the
  124. // part and a "iStateId" to specify the state of the part.
  125. // "iStateId=0" refers to the root part. "iPartId" = "0" refers to
  126. // the root class.
  127. //----------------------------------------------------------------------------------------------------------------------
  128. // Note: draw operations are always scaled to fit (and not to exceed)
  129. // the specified "Rect".
  130. //----------------------------------------------------------------------------------------------------------------------
  131. //----------------------------------------------------------------------------------------------------------------------
  132. // DrawThemeBackground()
  133. // - draws the theme-specified border and fill for
  134. // the "iPartId" and "iStateId". This could be
  135. // based on a bitmap file, a border and fill, or
  136. // other image description.
  137. //
  138. // hTheme - theme data handle
  139. // hdc - HDC to draw into
  140. // iPartId - part number to draw
  141. // iStateId - state number (of the part) to draw
  142. // pRect - defines the size/location of the part
  143. // pClipRect - optional clipping rect (don't draw outside it)
  144. //----------------------------------------------------------------------------------------------------------------------
  145. var
  146. DrawThemeBackground: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer; const pRect: TRect;
  147. pClipRect: PRECT): HRESULT; stdcall;
  148. {$EXTERNALSYM DrawThemeBackground}
  149. //----------------------------------------------------------------------------------------------------------------------
  150. //----- DrawThemeText() flags ----
  151. const
  152. DTT_GRAYED = $1; // draw a grayed-out string
  153. {$EXTERNALSYM DTT_GRAYED}
  154. //----------------------------------------------------------------------------------------------------------------------
  155. // DrawThemeText() - draws the text using the theme-specified
  156. // color and font for the "iPartId" and
  157. // "iStateId".
  158. //
  159. // hTheme - theme data handle
  160. // hdc - HDC to draw into
  161. // iPartId - part number to draw
  162. // iStateId - state number (of the part) to draw
  163. // pszText - actual text to draw
  164. // dwCharCount - number of chars to draw (-1 for all)
  165. // dwTextFlags - same as DrawText() "uFormat" param
  166. // dwTextFlags2 - additional drawing options
  167. // pRect - defines the size/location of the part
  168. //----------------------------------------------------------------------------------------------------------------------
  169. var
  170. DrawThemeText: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer; pszText: LPCWSTR; iCharCount: Integer;
  171. dwTextFlags, dwTextFlags2: DWORD; const pRect: TRect): HRESULT; stdcall;
  172. {$EXTERNALSYM DrawThemeText}
  173. //----------------------------------------------------------------------------------------------------------------------
  174. // GetThemeBackgroundContentRect()
  175. // - gets the size of the content for the theme-defined
  176. // background. This is usually the area inside
  177. // the borders or Margins.
  178. //
  179. // hTheme - theme data handle
  180. // hdc - (optional) device content to be used for drawing
  181. // iPartId - part number to draw
  182. // iStateId - state number (of the part) to draw
  183. // pBoundingRect - the outer RECT of the part being drawn
  184. // pContentRect - RECT to receive the content area
  185. //----------------------------------------------------------------------------------------------------------------------
  186. var
  187. GetThemeBackgroundContentRect: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer;
  188. const pBoundingRect: TRect; pContentRect: PRECT): HRESULT; stdcall;
  189. {$EXTERNALSYM GetThemeBackgroundContentRect}
  190. //----------------------------------------------------------------------------------------------------------------------
  191. // GetThemeBackgroundExtent() - calculates the size/location of the theme-
  192. // specified background based on the
  193. // "pContentRect".
  194. //
  195. // hTheme - theme data handle
  196. // hdc - (optional) device content to be used for drawing
  197. // iPartId - part number to draw
  198. // iStateId - state number (of the part) to draw
  199. // pContentRect - RECT that defines the content area
  200. // pBoundingRect - RECT to receive the overall size/location of part
  201. //----------------------------------------------------------------------------------------------------------------------
  202. var
  203. GetThemeBackgroundExtent: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer; const pContentRect: TRect;
  204. var pExtentRect: TRect): HRESULT; stdcall;
  205. {$EXTERNALSYM GetThemeBackgroundExtent}
  206. //----------------------------------------------------------------------------------------------------------------------
  207. type
  208. THEMESIZE = (
  209. TS_MIN, // minimum size
  210. TS_TRUE, // size without stretching
  211. TS_DRAW // size that theme mgr will use to draw part
  212. );
  213. {$EXTERNALSYM THEMESIZE}
  214. TThemeSize = THEMESIZE;
  215. //----------------------------------------------------------------------------------------------------------------------
  216. // GetThemePartSize() - returns the specified size of the theme part
  217. //
  218. // hTheme - theme data handle
  219. // hdc - HDC to select font into & measure against
  220. // iPartId - part number to retrieve size for
  221. // iStateId - state number (of the part)
  222. // prc - (optional) rect for part drawing destination
  223. // eSize - the type of size to be retreived
  224. // psz - receives the specified size of the part
  225. //----------------------------------------------------------------------------------------------------------------------
  226. var
  227. GetThemePartSize: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer; prc: PRECT; eSize: THEMESIZE;
  228. var psz: TSize): HRESULT; stdcall;
  229. {$EXTERNALSYM GetThemePartSize}
  230. //----------------------------------------------------------------------------------------------------------------------
  231. // GetThemeTextExtent() - calculates the size/location of the specified
  232. // text when rendered in the Theme Font.
  233. //
  234. // hTheme - theme data handle
  235. // hdc - HDC to select font & measure into
  236. // iPartId - part number to draw
  237. // iStateId - state number (of the part)
  238. // pszText - the text to be measured
  239. // dwCharCount - number of chars to draw (-1 for all)
  240. // dwTextFlags - same as DrawText() "uFormat" param
  241. // pszBoundingRect - optional: to control layout of text
  242. // pszExtentRect - receives the RECT for text size/location
  243. //----------------------------------------------------------------------------------------------------------------------
  244. var
  245. GetThemeTextExtent: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer; pszText: LPCWSTR;
  246. iCharCount: Integer; dwTextFlags: DWORD; pBoundingRect: PRECT; var pExtentRect: TRect): HRESULT; stdcall;
  247. {$EXTERNALSYM GetThemeTextExtent}
  248. //----------------------------------------------------------------------------------------------------------------------
  249. // GetThemeTextMetrics()
  250. // - returns info about the theme-specified font
  251. // for the part/state passed in.
  252. //
  253. // hTheme - theme data handle
  254. // hdc - optional: HDC for screen context
  255. // iPartId - part number to draw
  256. // iStateId - state number (of the part)
  257. // ptm - receives the font info
  258. //----------------------------------------------------------------------------------------------------------------------
  259. var
  260. GetThemeTextMetrics: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer;
  261. var ptm: TEXTMETRIC): HRESULT; stdcall;
  262. {$EXTERNALSYM GetThemeTextMetrics}
  263. //----------------------------------------------------------------------------------------------------------------------
  264. // GetThemeBackgroundRegion()
  265. // - computes the region for a regular or partially
  266. // transparent theme-specified background that is
  267. // bound by the specified "pRect".
  268. // If the rectangle is empty, sets the HRGN to NULL
  269. // and return S_FALSE.
  270. //
  271. // hTheme - theme data handle
  272. // hdc - optional HDC to draw into (DPI scaling)
  273. // iPartId - part number to draw
  274. // iStateId - state number (of the part)
  275. // pRect - the RECT used to draw the part
  276. // pRegion - receives handle to calculated region
  277. //----------------------------------------------------------------------------------------------------------------------
  278. var
  279. GetThemeBackgroundRegion: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer; const pRect: TRect;
  280. var pRegion: HRGN): HRESULT; stdcall;
  281. {$EXTERNALSYM GetThemeBackgroundRegion}
  282. //----------------------------------------------------------------------------------------------------------------------
  283. //----- HitTestThemeBackground, HitTestThemeBackgroundRegion flags ----
  284. // Theme background segment hit test flag (default). possible return values are:
  285. // HTCLIENT: hit test succeeded in the middle background segment
  286. // HTTOP, HTLEFT, HTTOPLEFT, etc: // hit test succeeded in the the respective theme background segment.
  287. const
  288. HTTB_BACKGROUNDSEG = $0000;
  289. {$EXTERNALSYM HTTB_BACKGROUNDSEG}
  290. // Fixed border hit test option. possible return values are:
  291. // HTCLIENT: hit test succeeded in the middle background segment
  292. // HTBORDER: hit test succeeded in any other background segment
  293. HTTB_FIXEDBORDER = $0002; // Return code may be either HTCLIENT or HTBORDER.
  294. {$EXTERNALSYM HTTB_FIXEDBORDER}
  295. // Caption hit test option. Possible return values are:
  296. // HTCAPTION: hit test succeeded in the top, top left, or top right background segments
  297. // HTNOWHERE or another return code, depending on absence or presence of accompanying flags, resp.
  298. HTTB_CAPTION = $0004;
  299. {$EXTERNALSYM HTTB_CAPTION}
  300. // Resizing border hit test flags. Possible return values are:
  301. // HTCLIENT: hit test succeeded in middle background segment
  302. // HTTOP, HTTOPLEFT, HTLEFT, HTRIGHT, etc: hit test succeeded in the respective system resizing zone
  303. // HTBORDER: hit test failed in middle segment and resizing zones, but succeeded in a background border segment
  304. HTTB_RESIZINGBORDER_LEFT = $0010; // Hit test left resizing border,
  305. {$EXTERNALSYM HTTB_RESIZINGBORDER_LEFT}
  306. HTTB_RESIZINGBORDER_TOP = $0020; // Hit test top resizing border
  307. {$EXTERNALSYM HTTB_RESIZINGBORDER_TOP}
  308. HTTB_RESIZINGBORDER_RIGHT = $0040; // Hit test right resizing border
  309. {$EXTERNALSYM HTTB_RESIZINGBORDER_RIGHT}
  310. HTTB_RESIZINGBORDER_BOTTOM = $0080; // Hit test bottom resizing border
  311. {$EXTERNALSYM HTTB_RESIZINGBORDER_BOTTOM}
  312. HTTB_RESIZINGBORDER = (HTTB_RESIZINGBORDER_LEFT or HTTB_RESIZINGBORDER_TOP or
  313. HTTB_RESIZINGBORDER_RIGHT or HTTB_RESIZINGBORDER_BOTTOM);
  314. {$EXTERNALSYM HTTB_RESIZINGBORDER}
  315. // Resizing border is specified as a template, not just window edges.
  316. // This option is mutually exclusive with HTTB_SYSTEMSIZINGWIDTH; HTTB_SIZINGTEMPLATE takes precedence
  317. HTTB_SIZINGTEMPLATE = $0100;
  318. {$EXTERNALSYM HTTB_SIZINGTEMPLATE}
  319. // Use system resizing border width rather than theme content margins.
  320. // This option is mutually exclusive with HTTB_SIZINGTEMPLATE, which takes precedence.
  321. HTTB_SYSTEMSIZINGMARGINS = $0200;
  322. {$EXTERNALSYM HTTB_SYSTEMSIZINGMARGINS}
  323. //----------------------------------------------------------------------------------------------------------------------
  324. // HitTestThemeBackground()
  325. // - returns a HitTestCode (a subset of the values
  326. // returned by WM_NCHITTEST) for the point "ptTest"
  327. // within the theme-specified background
  328. // (bound by pRect). "pRect" and "ptTest" should
  329. // both be in the same coordinate system
  330. // (client, screen, etc).
  331. //
  332. // hTheme - theme data handle
  333. // hdc - HDC to draw into
  334. // iPartId - part number to test against
  335. // iStateId - state number (of the part)
  336. // pRect - the RECT used to draw the part
  337. // hrgn - optional region to use; must be in same coordinates as
  338. // - pRect and pTest.
  339. // ptTest - the hit point to be tested
  340. // dwOptions - HTTB_xxx constants
  341. // pwHitTestCode - receives the returned hit test code - one of:
  342. //
  343. // HTNOWHERE, HTLEFT, HTTOPLEFT, HTBOTTOMLEFT,
  344. // HTRIGHT, HTTOPRIGHT, HTBOTTOMRIGHT,
  345. // HTTOP, HTBOTTOM, HTCLIENT
  346. //----------------------------------------------------------------------------------------------------------------------
  347. var
  348. HitTestThemeBackground: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer; dwOptions: DWORD;
  349. const pRect: TRect; hrgn: HRGN; ptTest: TPoint; var pwHitTestCode: WORD): HRESULT; stdcall;
  350. {$EXTERNALSYM HitTestThemeBackground}
  351. //----------------------------------------------------------------------------------------------------------------------
  352. // DrawThemeEdge() - Similar to the DrawEdge() API, but uses part colors
  353. // and is high-DPI aware
  354. // hTheme - theme data handle
  355. // hdc - HDC to draw into
  356. // iPartId - part number to draw
  357. // iStateId - state number of part
  358. // pDestRect - the RECT used to draw the line(s)
  359. // uEdge - Same as DrawEdge() API
  360. // uFlags - Same as DrawEdge() API
  361. // pContentRect - Receives the interior rect if (uFlags & BF_ADJUST)
  362. //----------------------------------------------------------------------------------------------------------------------
  363. var
  364. DrawThemeEdge: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer; const pDestRect: TRect; uEdge,
  365. uFlags: UINT; pContentRect: PRECT): HRESULT; stdcall;
  366. {$EXTERNALSYM DrawThemeEdge}
  367. //----------------------------------------------------------------------------------------------------------------------
  368. // DrawThemeIcon() - draws an image within an imagelist based on
  369. // a (possible) theme-defined effect.
  370. //
  371. // hTheme - theme data handle
  372. // hdc - HDC to draw into
  373. // iPartId - part number to draw
  374. // iStateId - state number of part
  375. // pRect - the RECT to draw the image within
  376. // himl - handle to IMAGELIST
  377. // iImageIndex - index into IMAGELIST (which icon to draw)
  378. //----------------------------------------------------------------------------------------------------------------------
  379. var
  380. DrawThemeIcon: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId: Integer; const pRect: TRect; himl: HIMAGELIST;
  381. iImageIndex: Integer): HRESULT; stdcall;
  382. {$EXTERNALSYM DrawThemeIcon}
  383. //----------------------------------------------------------------------------------------------------------------------
  384. // IsThemePartDefined() - returns TRUE if the theme has defined parameters
  385. // for the specified "iPartId" and "iStateId".
  386. //
  387. // hTheme - theme data handle
  388. // iPartId - part number to find definition for
  389. // iStateId - state number of part
  390. //----------------------------------------------------------------------------------------------------------------------
  391. var
  392. IsThemePartDefined: function(hTheme: HTHEME; iPartId, iStateId: Integer): BOOL; stdcall;
  393. {$EXTERNALSYM IsThemePartDefined}
  394. //----------------------------------------------------------------------------------------------------------------------
  395. // IsThemeBackgroundPartiallyTransparent()
  396. // - returns TRUE if the theme specified background for
  397. // the part/state has transparent pieces or
  398. // alpha-blended pieces.
  399. //
  400. // hTheme - theme data handle
  401. // iPartId - part number
  402. // iStateId - state number of part
  403. //----------------------------------------------------------------------------------------------------------------------
  404. var
  405. IsThemeBackgroundPartiallyTransparent: function(hTheme: HTHEME; iPartId, iStateId: Integer): BOOL; stdcall;
  406. {$EXTERNALSYM IsThemeBackgroundPartiallyTransparent}
  407. //----------------------------------------------------------------------------------------------------------------------
  408. // lower-level theme information services
  409. //----------------------------------------------------------------------------------------------------------------------
  410. // The following methods are getter routines for each of the Theme Data types.
  411. // Controls/Windows are defined in drawable "parts" by their author: a
  412. // parent part and 0 or more child parts. Each of the parts can be
  413. // described in "states" (ex: disabled, hot, pressed).
  414. //----------------------------------------------------------------------------------------------------------------------
  415. // Each of the below methods takes a "iPartId" param to specify the
  416. // part and a "iStateId" to specify the state of the part.
  417. // "iStateId=0" refers to the root part. "iPartId" = "0" refers to
  418. // the root class.
  419. //----------------------------------------------------------------------------------------------------------------------
  420. // Each method also take a "iPropId" param because multiple instances of
  421. // the same primitive type can be defined in the theme schema.
  422. //----------------------------------------------------------------------------------------------------------------------
  423. //----------------------------------------------------------------------------------------------------------------------
  424. // GetThemeColor() - Get the value for the specified COLOR property
  425. //
  426. // hTheme - theme data handle
  427. // iPartId - part number
  428. // iStateId - state number of part
  429. // iPropId - the property number to get the value for
  430. // pColor - receives the value of the property
  431. //----------------------------------------------------------------------------------------------------------------------
  432. var
  433. GetThemeColor: function(hTheme: HTHEME; iPartId, iStateId, iPropId: Integer; var pColor: COLORREF): HRESULT; stdcall;
  434. {$EXTERNALSYM GetThemeColor}
  435. //----------------------------------------------------------------------------------------------------------------------
  436. // GetThemeMetric() - Get the value for the specified metric/size
  437. // property
  438. //
  439. // hTheme - theme data handle
  440. // hdc - (optional) hdc to be drawn into (DPI scaling)
  441. // iPartId - part number
  442. // iStateId - state number of part
  443. // iPropId - the property number to get the value for
  444. // piVal - receives the value of the property
  445. //----------------------------------------------------------------------------------------------------------------------
  446. var
  447. GetThemeMetric: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId, iPropId: Integer;
  448. var piVal: Integer): HRESULT; stdcall;
  449. {$EXTERNALSYM GetThemeMetric}
  450. //----------------------------------------------------------------------------------------------------------------------
  451. // GetThemeString() - Get the value for the specified string property
  452. //
  453. // hTheme - theme data handle
  454. // iPartId - part number
  455. // iStateId - state number of part
  456. // iPropId - the property number to get the value for
  457. // pszBuff - receives the string property value
  458. // cchMaxBuffChars - max. number of chars allowed in pszBuff
  459. //----------------------------------------------------------------------------------------------------------------------
  460. var
  461. GetThemeString: function(hTheme: HTHEME; iPartId, iStateId, iPropId: Integer; pszBuff: LPWSTR;
  462. cchMaxBuffChars: Integer): HRESULT; stdcall;
  463. {$EXTERNALSYM GetThemeString}
  464. //----------------------------------------------------------------------------------------------------------------------
  465. // GetThemeBool() - Get the value for the specified BOOL property
  466. //
  467. // hTheme - theme data handle
  468. // iPartId - part number
  469. // iStateId - state number of part
  470. // iPropId - the property number to get the value for
  471. // pfVal - receives the value of the property
  472. //----------------------------------------------------------------------------------------------------------------------
  473. var
  474. GetThemeBool: function(hTheme: HTHEME; iPartId, iStateId, iPropId: Integer; var pfVal: BOOL): HRESULT; stdcall;
  475. {$EXTERNALSYM GetThemeBool}
  476. //----------------------------------------------------------------------------------------------------------------------
  477. // GetThemeInt() - Get the value for the specified int property
  478. //
  479. // hTheme - theme data handle
  480. // iPartId - part number
  481. // iStateId - state number of part
  482. // iPropId - the property number to get the value for
  483. // piVal - receives the value of the property
  484. //----------------------------------------------------------------------------------------------------------------------
  485. var
  486. GetThemeInt: function(hTheme: HTHEME; iPartId, iStateId, iPropId: Integer; var piVal: Integer): HRESULT; stdcall;
  487. {$EXTERNALSYM GetThemeInt}
  488. //----------------------------------------------------------------------------------------------------------------------
  489. // GetThemeEnumValue() - Get the value for the specified ENUM property
  490. //
  491. // hTheme - theme data handle
  492. // iPartId - part number
  493. // iStateId - state number of part
  494. // iPropId - the property number to get the value for
  495. // piVal - receives the value of the enum (cast to int*)
  496. //----------------------------------------------------------------------------------------------------------------------
  497. var
  498. GetThemeEnumValue: function(hTheme: HTHEME; iPartId, iStateId, iPropId: Integer; var piVal: Integer): HRESULT; stdcall;
  499. {$EXTERNALSYM GetThemeEnumValue}
  500. //----------------------------------------------------------------------------------------------------------------------
  501. // GetThemePosition() - Get the value for the specified position
  502. // property
  503. //
  504. // hTheme - theme data handle
  505. // iPartId - part number
  506. // iStateId - state number of part
  507. // iPropId - the property number to get the value for
  508. // pPoint - receives the value of the position property
  509. //----------------------------------------------------------------------------------------------------------------------
  510. var
  511. GetThemePosition: function(hTheme: HTHEME; iPartId, iStateId, iPropId: Integer;var pPoint: TPoint): HRESULT; stdcall;
  512. {$EXTERNALSYM GetThemePosition}
  513. //----------------------------------------------------------------------------------------------------------------------
  514. // GetThemeFont() - Get the value for the specified font property
  515. //
  516. // hTheme - theme data handle
  517. // hdc - (optional) hdc to be drawn to (DPI scaling)
  518. // iPartId - part number
  519. // iStateId - state number of part
  520. // iPropId - the property number to get the value for
  521. // pFont - receives the value of the LOGFONT property
  522. // (scaled for the current logical screen dpi)
  523. //----------------------------------------------------------------------------------------------------------------------
  524. var
  525. GetThemeFont: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId, iPropId: Integer;
  526. var pFont: LOGFONT): HRESULT; stdcall;
  527. {$EXTERNALSYM GetThemeFont}
  528. //----------------------------------------------------------------------------------------------------------------------
  529. // GetThemeRect() - Get the value for the specified RECT property
  530. //
  531. // hTheme - theme data handle
  532. // iPartId - part number
  533. // iStateId - state number of part
  534. // iPropId - the property number to get the value for
  535. // pRect - receives the value of the RECT property
  536. //----------------------------------------------------------------------------------------------------------------------
  537. var
  538. GetThemeRect: function(hTheme: HTHEME; iPartId, iStateId, iPropId: Integer; var pRect: TRect): HRESULT; stdcall;
  539. {$EXTERNALSYM GetThemeRect}
  540. //----------------------------------------------------------------------------------------------------------------------
  541. type
  542. _MARGINS = record
  543. cxLeftWidth: Integer; // width of left border that retains its size
  544. cxRightWidth: Integer; // width of right border that retains its size
  545. cyTopHeight: Integer; // height of top border that retains its size
  546. cyBottomHeight: Integer; // height of bottom border that retains its size
  547. end;
  548. {$EXTERNALSYM _MARGINS}
  549. MARGINS = _MARGINS;
  550. {$EXTERNALSYM MARGINS}
  551. PMARGINS = ^MARGINS;
  552. {$EXTERNALSYM PMARGINS}
  553. TMargins = MARGINS;
  554. //----------------------------------------------------------------------------------------------------------------------
  555. // GetThemeMargins() - Get the value for the specified MARGINS property
  556. //
  557. // hTheme - theme data handle
  558. // hdc - (optional) hdc to be used for drawing
  559. // iPartId - part number
  560. // iStateId - state number of part
  561. // iPropId - the property number to get the value for
  562. // prc - RECT for area to be drawn into
  563. // pMargins - receives the value of the MARGINS property
  564. //----------------------------------------------------------------------------------------------------------------------
  565. var
  566. GetThemeMargins: function(hTheme: HTHEME; hdc: HDC; iPartId, iStateId, iPropId: Integer; prc: PRECT;
  567. var pMargins: MARGINS): HRESULT; stdcall;
  568. {$EXTERNALSYM GetThemeMargins}
  569. //----------------------------------------------------------------------------------------------------------------------
  570. const
  571. MAX_INTLIST_COUNT = 10;
  572. {$EXTERNALSYM MAX_INTLIST_COUNT}
  573. type
  574. _INTLIST = record
  575. iValueCount: Integer; // number of values in iValues
  576. iValues: array [0..MAX_INTLIST_COUNT - 1] of Integer;
  577. end;
  578. {$EXTERNALSYM _INTLIST}
  579. INTLIST = _INTLIST;
  580. {$EXTERNALSYM INTLIST}
  581. PINTLIST = ^INTLIST;
  582. {$EXTERNALSYM PINTLIST}
  583. TIntList = INTLIST;
  584. //----------------------------------------------------------------------------------------------------------------------
  585. // GetThemeIntList() - Get the value for the specified INTLIST struct
  586. //
  587. // hTheme - theme data handle
  588. // iPartId - part number
  589. // iStateId - state number of part
  590. // iPropId - the property number to get the value for
  591. // pIntList - receives the value of the INTLIST property
  592. //----------------------------------------------------------------------------------------------------------------------
  593. var
  594. GetThemeIntList: function(hTheme: HTHEME; iPartId, iStateId, iPropId: Integer; var pIntList: INTLIST): HRESULT; stdcall;
  595. {$EXTERNALSYM GetThemeIntList}
  596. //----------------------------------------------------------------------------------------------------------------------
  597. type
  598. PROPERTYORIGIN = (
  599. PO_STATE, // property was found in the state section
  600. PO_PART, // property was found in the part section
  601. PO_CLASS, // property was found in the class section
  602. PO_GLOBAL, // property was found in [globals] section
  603. PO_NOTFOUND); // property was not found
  604. {$EXTERNALSYM PROPERTYORIGIN}
  605. TPropertyOrigin = PROPERTYORIGIN;
  606. //----------------------------------------------------------------------------------------------------------------------
  607. // GetThemePropertyOrigin()
  608. // - searches for the specified theme property
  609. // and sets "pOrigin" to indicate where it was
  610. // found (or not found)
  611. //
  612. // hTheme - theme data handle
  613. // iPartId - part number
  614. // iStateId - state number of part
  615. // iPropId - the property number to search for
  616. // pOrigin - receives the value of the property origin
  617. //----------------------------------------------------------------------------------------------------------------------
  618. var
  619. GetThemePropertyOrigin: function(hTheme: HTHEME; iPartId, iStateId, iPropId: Integer;
  620. var pOrigin: PROPERTYORIGIN): HRESULT; stdcall;
  621. {$EXTERNALSYM GetThemePropertyOrigin}
  622. //----------------------------------------------------------------------------------------------------------------------
  623. // SetWindowTheme()
  624. // - redirects an existing Window to use a different
  625. // section of the current theme information than its
  626. // class normally asks for.
  627. //
  628. // hwnd - the handle of the window (cannot be NULL)
  629. //
  630. // pszSubAppName - app (group) name to use in place of the calling
  631. // app's name. If NULL, the actual calling app
  632. // name will be used.
  633. //
  634. // pszSubIdList - semicolon separated list of class Id names to
  635. // use in place of actual list passed by the
  636. // window's class. if NULL, the id list from the
  637. // calling class is used.
  638. //----------------------------------------------------------------------------------------------------------------------
  639. // The Theme Manager will remember the "pszSubAppName" and the
  640. // "pszSubIdList" associations thru the lifetime of the window (even
  641. // if themes are subsequently changed). The window is sent a
  642. // "WM_THEMECHANGED" msg at the end of this call, so that the new
  643. // theme can be found and applied.
  644. //----------------------------------------------------------------------------------------------------------------------
  645. // When "pszSubAppName" or "pszSubIdList" are NULL, the Theme Manager
  646. // removes the previously remember association. To turn off theme-ing for
  647. // the specified window, you can pass an empty string (L"") so it
  648. // won't match any section entries.
  649. //----------------------------------------------------------------------------------------------------------------------
  650. var
  651. SetWindowTheme: function(hwnd: HWND; pszSubAppName: LPCWSTR; pszSubIdList: LPCWSTR): HRESULT; stdcall;
  652. {$EXTERNALSYM SetWindowTheme}
  653. //----------------------------------------------------------------------------------------------------------------------
  654. // GetThemeFilename() - Get the value for the specified FILENAME property.
  655. //
  656. // hTheme - theme data handle
  657. // iPartId - part number
  658. // iStateId - state number of part
  659. // iPropId - the property number to search for
  660. // pszThemeFileName - output buffer to receive the filename
  661. // cchMaxBuffChars - the size of the return buffer, in chars
  662. //----------------------------------------------------------------------------------------------------------------------
  663. var
  664. GetThemeFilename: function(hTheme: HTHEME; iPartId, iStateId, iPropId: Integer; pszThemeFileName: LPWSTR;
  665. cchMaxBuffChars: Integer): HRESULT; stdcall;
  666. {$EXTERNALSYM GetThemeFilename}
  667. //----------------------------------------------------------------------------------------------------------------------
  668. // GetThemeSysColor() - Get the value of the specified System color.
  669. //
  670. // hTheme - the theme data handle. if non-NULL, will return
  671. // color from [SysMetrics] section of theme.
  672. // if NULL, will return the global system color.
  673. //
  674. // iColorId - the system color index defined in winuser.h
  675. //----------------------------------------------------------------------------------------------------------------------
  676. var
  677. GetThemeSysColor: function(hTheme: HTHEME; iColorId: Integer): COLORREF; stdcall;
  678. {$EXTERNALSYM GetThemeSysColor}
  679. //----------------------------------------------------------------------------------------------------------------------
  680. // GetThemeSysColorBrush()
  681. // - Get the brush for the specified System color.
  682. //
  683. // hTheme - the theme data handle. if non-NULL, will return
  684. // brush matching color from [SysMetrics] section of
  685. // theme. if NULL, will return the brush matching
  686. // global system color.
  687. //
  688. // iColorId - the system color index defined in winuser.h
  689. //----------------------------------------------------------------------------------------------------------------------
  690. var
  691. GetThemeSysColorBrush: function(hTheme: HTHEME; iColorId: Integer): HBRUSH; stdcall;
  692. {$EXTERNALSYM GetThemeSysColorBrush}
  693. //----------------------------------------------------------------------------------------------------------------------
  694. // GetThemeSysBool() - Get the boolean value of specified System metric.
  695. //
  696. // hTheme - the theme data handle. if non-NULL, will return
  697. // BOOL from [SysMetrics] section of theme.
  698. // if NULL, will return the specified system boolean.
  699. //
  700. // iBoolId - the TMT_XXX BOOL number (first BOOL
  701. // is TMT_FLATMENUS)
  702. //----------------------------------------------------------------------------------------------------------------------
  703. var
  704. GetThemeSysBool: function(hTheme: HTHEME; iBoolId: Integer): BOOL; stdcall;
  705. {$EXTERNALSYM GetThemeSysBool}
  706. //----------------------------------------------------------------------------------------------------------------------
  707. // GetThemeSysSize() - Get the value of the specified System size metric.
  708. // (scaled for the current logical screen dpi)
  709. //
  710. // hTheme - the theme data handle. if non-NULL, will return
  711. // size from [SysMetrics] section of theme.
  712. // if NULL, will return the global system metric.
  713. //
  714. // iSizeId - the following values are supported when
  715. // hTheme is non-NULL:
  716. //
  717. // SM_CXBORDER (border width)
  718. // SM_CXVSCROLL (scrollbar width)
  719. // SM_CYHSCROLL (scrollbar height)
  720. // SM_CXSIZE (caption width)
  721. // SM_CYSIZE (caption height)
  722. // SM_CXSMSIZE (small caption width)
  723. // SM_CYSMSIZE (small caption height)
  724. // SM_CXMENUSIZE (menubar width)
  725. // SM_CYMENUSIZE (menubar height)
  726. //
  727. // when hTheme is NULL, iSizeId is passed directly
  728. // to the GetSystemMetrics() function
  729. //----------------------------------------------------------------------------------------------------------------------
  730. var
  731. GetThemeSysSize: function(hTheme: HTHEME; iSizeId: Integer): Integer; stdcall;
  732. {$EXTERNALSYM GetThemeSysSize}
  733. //----------------------------------------------------------------------------------------------------------------------
  734. // GetThemeSysFont() - Get the LOGFONT for the specified System font.
  735. //
  736. // hTheme - the theme data handle. if non-NULL, will return
  737. // font from [SysMetrics] section of theme.
  738. // if NULL, will return the specified system font.
  739. //
  740. // iFontId - the TMT_XXX font number (first font
  741. // is TMT_CAPTIONFONT)
  742. //
  743. // plf - ptr to LOGFONT to receive the font value.
  744. // (scaled for the current logical screen dpi)
  745. //----------------------------------------------------------------------------------------------------------------------
  746. var
  747. GetThemeSysFont: function(hTheme: HTHEME; iFontId: Integer; var plf: LOGFONT): HRESULT; stdcall;
  748. {$EXTERNALSYM GetThemeSysFont}
  749. //----------------------------------------------------------------------------------------------------------------------
  750. // GetThemeSysString() - Get the value of specified System string metric.
  751. //
  752. // hTheme - the theme data handle (required)
  753. //
  754. // iStringId - must be one of the following values:
  755. //
  756. // TMT_CSSNAME
  757. // TMT_XMLNAME
  758. //
  759. // pszStringBuff - the buffer to receive the string value
  760. //
  761. // cchMaxStringChars - max. number of chars that pszStringBuff can hold
  762. //----------------------------------------------------------------------------------------------------------------------
  763. var
  764. GetThemeSysString: function(hTheme: HTHEME; iStringId: Integer; pszStringBuff: LPWSTR;
  765. cchMaxStringChars: Integer): HRESULT; stdcall;
  766. {$EXTERNALSYM GetThemeSysString}
  767. //----------------------------------------------------------------------------------------------------------------------
  768. // GetThemeSysInt() - Get the value of specified System int.
  769. //
  770. // hTheme - the theme data handle (required)
  771. //
  772. // iIntId - must be one of the following values:
  773. //
  774. // TMT_DPIX
  775. // TMT_DPIY
  776. // TMT_MINCOLORDEPTH
  777. //
  778. // piValue - ptr to int to receive value
  779. //----------------------------------------------------------------------------------------------------------------------
  780. var
  781. GetThemeSysInt: function(hTheme: HTHEME; iIntId: Integer; var piValue: Integer): HRESULT; stdcall;
  782. {$EXTERNALSYM GetThemeSysInt}
  783. //----------------------------------------------------------------------------------------------------------------------
  784. // IsThemeActive() - can be used to test if a system theme is active
  785. // for the current user session.
  786. //
  787. // use the API "IsAppThemed()" to test if a theme is
  788. // active for the calling process.
  789. //----------------------------------------------------------------------------------------------------------------------
  790. var
  791. IsThemeActive: function: BOOL; stdcall;
  792. {$EXTERNALSYM IsThemeActive}
  793. //----------------------------------------------------------------------------------------------------------------------
  794. // IsAppThemed() - returns TRUE if a theme is active and available to
  795. // the current process
  796. //----------------------------------------------------------------------------------------------------------------------
  797. var
  798. IsAppThemed: function: BOOL; stdcall;
  799. {$EXTERNALSYM IsAppThemed}
  800. //----------------------------------------------------------------------------------------------------------------------
  801. // GetWindowTheme() - if window is themed, returns its most recent
  802. // HTHEME from OpenThemeData() - otherwise, returns
  803. // NULL.
  804. //
  805. // hwnd - the window to get the HTHEME of
  806. //----------------------------------------------------------------------------------------------------------------------
  807. var
  808. GetWindowTheme: function(hwnd: HWND): HTHEME; stdcall;
  809. {$EXTERNALSYM GetWindowTheme}
  810. //----------------------------------------------------------------------------------------------------------------------
  811. // EnableThemeDialogTexture()
  812. //
  813. // - Enables/disables dialog background theme. This method can be used to
  814. // tailor dialog compatibility with child windows and controls that
  815. // may or may not coordinate the rendering of their client area backgrounds
  816. // with that of their parent dialog in a manner that supports seamless
  817. // background texturing.
  818. //
  819. // hdlg - the window handle of the target dialog
  820. // dwFlags - ETDT_ENABLE to enable the theme-defined dialog background texturing,
  821. // ETDT_DISABLE to disable background texturing,
  822. // ETDT_ENABLETAB to enable the theme-defined background
  823. // texturing using the Tab texture
  824. //----------------------------------------------------------------------------------------------------------------------
  825. const
  826. ETDT_DISABLE = $00000001;
  827. {$EXTERNALSYM ETDT_DISABLE}
  828. ETDT_ENABLE = $00000002;
  829. {$EXTERNALSYM ETDT_ENABLE}
  830. ETDT_USETABTEXTURE = $00000004;
  831. {$EXTERNALSYM ETDT_USETABTEXTURE}
  832. ETDT_ENABLETAB = (ETDT_ENABLE or ETDT_USETABTEXTURE);
  833. {$EXTERNALSYM ETDT_ENABLETAB}
  834. var
  835. EnableThemeDialogTexture: function(hwnd: HWND; dwFlags: DWORD): HRESULT; stdcall;
  836. {$EXTERNALSYM EnableThemeDialogTexture}
  837. //----------------------------------------------------------------------------------------------------------------------
  838. // IsThemeDialogTextureEnabled()
  839. //
  840. // - Reports whether the dialog supports background texturing.
  841. //
  842. // hdlg - the window handle of the target dialog
  843. //----------------------------------------------------------------------------------------------------------------------
  844. var
  845. IsThemeDialogTextureEnabled: function(hwnd: HWND): BOOL; stdcall;
  846. {$EXTERNALSYM IsThemeDialogTextureEnabled}
  847. //----------------------------------------------------------------------------------------------------------------------
  848. //---- flags to control theming within an app ----
  849. const
  850. STAP_ALLOW_NONCLIENT = (1 shl 0);
  851. {$EXTERNALSYM STAP_ALLOW_NONCLIENT}
  852. STAP_ALLOW_CONTROLS = (1 shl 1);
  853. {$EXTERNALSYM STAP_ALLOW_CONTROLS}
  854. STAP_ALLOW_WEBCONTENT = (1 shl 2);
  855. {$EXTERNALSYM STAP_ALLOW_WEBCONTENT}
  856. //----------------------------------------------------------------------------------------------------------------------
  857. // GetThemeAppProperties()
  858. // - returns the app property flags that control theming
  859. //----------------------------------------------------------------------------------------------------------------------
  860. var
  861. GetThemeAppProperties: function: DWORD; stdcall;
  862. {$EXTERNALSYM GetThemeAppProperties}
  863. //----------------------------------------------------------------------------------------------------------------------
  864. // SetThemeAppProperties()
  865. // - sets the flags that control theming within the app
  866. //
  867. // dwFlags - the flag values to be set
  868. //----------------------------------------------------------------------------------------------------------------------
  869. var
  870. SetThemeAppProperties: procedure(dwFlags: DWORD); stdcall;
  871. {$EXTERNALSYM SetThemeAppProperties}
  872. //----------------------------------------------------------------------------------------------------------------------
  873. // GetCurrentThemeName()
  874. // - Get the name of the current theme in-use.
  875. // Optionally, return the ColorScheme name and the
  876. // Size name of the theme.
  877. //
  878. // pszThemeFileName - receives the theme path & filename
  879. // cchMaxNameChars - max chars allowed in pszNameBuff
  880. //
  881. // pszColorBuff - (optional) receives the canonical color scheme name
  882. // (not the display name)
  883. // cchMaxColorChars - max chars allowed in pszColorBuff
  884. //
  885. // pszSizeBuff - (optional) receives the canonical size name
  886. // (not the display name)
  887. // cchMaxSizeChars - max chars allowed in pszSizeBuff
  888. //----------------------------------------------------------------------------------------------------------------------
  889. var
  890. GetCurrentThemeName: function(pszThemeFileName: LPWSTR; cchMaxNameChars: Integer; pszColorBuff: LPWSTR;
  891. cchMaxColorChars: Integer; pszSizeBuff: LPWSTR; cchMaxSizeChars: Integer): HRESULT; stdcall;
  892. {$EXTERNALSYM GetCurrentThemeName}
  893. //----------------------------------------------------------------------------------------------------------------------
  894. // GetThemeDocumentationProperty()
  895. // - Get the value for the specified property name from
  896. // the [documentation] section of the themes.ini file
  897. // for the specified theme. If the property has been
  898. // localized in the theme files string table, the
  899. // localized version of the property value is returned.
  900. //
  901. // pszThemeFileName - filename of the theme file to query
  902. // pszPropertyName - name of the string property to retreive a value for
  903. // pszValueBuff - receives the property string value
  904. // cchMaxValChars - max chars allowed in pszValueBuff
  905. //----------------------------------------------------------------------------------------------------------------------
  906. const
  907. SZ_THDOCPROP_DISPLAYNAME = WideString('DisplayName');
  908. {$EXTERNALSYM SZ_THDOCPROP_DISPLAYNAME}
  909. SZ_THDOCPROP_CANONICALNAME = WideString('ThemeName');
  910. {$EXTERNALSYM SZ_THDOCPROP_CANONICALNAME}
  911. SZ_THDOCPROP_TOOLTIP = WideString('ToolTip');
  912. {$EXTERNALSYM SZ_THDOCPROP_TOOLTIP}
  913. SZ_THDOCPROP_AUTHOR = WideString('author');
  914. {$EXTERNALSYM SZ_THDOCPROP_AUTHOR}
  915. var
  916. GetThemeDocumentationProperty: function(pszThemeName, pszPropertyName: LPCWSTR; pszValueBuff: LPWSTR;
  917. cchMaxValChars: Integer): HRESULT; stdcall;
  918. {$EXTERNALSYM GetThemeDocumentationProperty}
  919. //----------------------------------------------------------------------------------------------------------------------
  920. // Theme API Error Handling
  921. //
  922. // All functions in the Theme API not returning an HRESULT (THEMEAPI_)
  923. // use the WIN32 function "SetLastError()" to record any call failures.
  924. //
  925. // To retreive the error code of the last failure on the
  926. // current thread for these type of API's, use the WIN32 function
  927. // "GetLastError()".
  928. //
  929. // All Theme API error codes (HRESULT's and GetLastError() values)
  930. // should be normal win32 errors which can be formatted into
  931. // strings using the Win32 API FormatMessage().
  932. //----------------------------------------------------------------------------------------------------------------------
  933. //----------------------------------------------------------------------------------------------------------------------
  934. // DrawThemeParentBackground()
  935. // - used by partially-transparent or alpha-blended
  936. // child controls to draw the part of their parent
  937. // that they appear in front of.
  938. //
  939. // hwnd - handle of the child control
  940. // hdc - hdc of the child control
  941. // prc - (optional) rect that defines the area to be
  942. // drawn (CHILD coordinates)
  943. //----------------------------------------------------------------------------------------------------------------------
  944. var
  945. DrawThemeParentBackground: function(hwnd: HWND; hdc: HDC; prc: PRECT): HRESULT; stdcall;
  946. {$EXTERNALSYM DrawThemeParentBackground}
  947. //----------------------------------------------------------------------------------------------------------------------
  948. // EnableTheming() - enables or disables themeing for the current user
  949. // in the current and future sessions.
  950. //
  951. // fEnable - if FALSE, disable theming & turn themes off.
  952. // - if TRUE, enable themeing and, if user previously
  953. // had a theme active, make it active now.
  954. //----------------------------------------------------------------------------------------------------------------------
  955. var
  956. EnableTheming: function(fEnable: BOOL): HRESULT; stdcall;
  957. {$EXTERNALSYM EnableTheming}
  958. implementation
  959. uses
  960. SyncObjs;
  961. //----------------------------------------------------------------------------------------------------------------------
  962. const
  963. themelib = 'uxtheme.dll';
  964. var
  965. ThemeLibrary: THandle;
  966. ReferenceCount: Integer; // We have to keep track of several load/unload calls.
  967. Lock: TCriticalSection;
  968. procedure FreeThemeLibrary;
  969. begin
  970. Lock.Enter;
  971. try
  972. if ReferenceCount > 0 then
  973. Dec(ReferenceCount);
  974. if (ThemeLibrary <> 0) and (ReferenceCount = 0) then
  975. begin
  976. FreeLibrary(ThemeLibrary);
  977. ThemeLibrary := 0;
  978. OpenThemeData := nil;
  979. CloseThemeData := nil;
  980. DrawThemeBackground := nil;
  981. DrawThemeText := nil;
  982. GetThemeBackgroundContentRect := nil;
  983. GetThemeBackgroundExtent := nil;
  984. GetThemePartSize := nil;
  985. GetThemeTextExtent := nil;
  986. GetThemeTextMetrics := nil;
  987. GetThemeBackgroundRegion := nil;
  988. HitTestThemeBackground := nil;
  989. DrawThemeEdge := nil;
  990. DrawThemeIcon := nil;
  991. IsThemePartDefined := nil;
  992. IsThemeBackgroundPartiallyTransparent := nil;
  993. GetThemeColor := nil;
  994. GetThemeMetric := nil;
  995. GetThemeString := nil;
  996. GetThemeBool := nil;
  997. GetThemeInt := nil;
  998. GetThemeEnumValue := nil;
  999. GetThemePosition := nil;
  1000. GetThemeFont := nil;
  1001. GetThemeRect := nil;
  1002. GetThemeMargins := nil;
  1003. GetThemeIntList := nil;
  1004. GetThemePropertyOrigin := nil;
  1005. SetWindowTheme := nil;
  1006. GetThemeFilename := nil;
  1007. GetThemeSysColor := nil;
  1008. GetThemeSysColorBrush := nil;
  1009. GetThemeSysBool := nil;
  1010. GetThemeSysSize := nil;
  1011. GetThemeSysFont := nil;
  1012. GetThemeSysString := nil;
  1013. GetThemeSysInt := nil;
  1014. IsThemeActive := nil;
  1015. IsAppThemed := nil;
  1016. GetWindowTheme := nil;
  1017. EnableThemeDialogTexture := nil;
  1018. IsThemeDialogTextureEnabled := nil;
  1019. GetThemeAppProperties := nil;
  1020. SetThemeAppProperties := nil;
  1021. GetCurrentThemeName := nil;
  1022. GetThemeDocumentationProperty := nil;
  1023. DrawThemeParentBackground := nil;
  1024. EnableTheming := nil;
  1025. end;
  1026. finally
  1027. Lock.Leave;
  1028. end;
  1029. end;
  1030. //----------------------------------------------------------------------------------------------------------------------
  1031. function InitThemeLibrary: Boolean;
  1032. begin
  1033. Lock.Enter;
  1034. try
  1035. Inc(ReferenceCount);
  1036. if ThemeLibrary = 0 then
  1037. begin
  1038. ThemeLibrary := LoadLibrary(themelib);
  1039. if ThemeLibrary > 0 then
  1040. begin
  1041. OpenThemeData := GetProcAddress(ThemeLibrary, 'OpenThemeData');
  1042. CloseThemeData := GetProcAddress(ThemeLibrary, 'CloseThemeData');
  1043. DrawThemeBackground := GetProcAddress(ThemeLibrary, 'DrawThemeBackground');
  1044. DrawThemeText := GetProcAddress(ThemeLibrary, 'DrawThemeText');
  1045. GetThemeBackgroundContentRect := GetProcAddress(ThemeLibrary, 'GetThemeBackgroundContentRect');
  1046. GetThemeBackgroundExtent := GetProcAddress(ThemeLibrary, 'GetThemeBackgroundExtent');
  1047. GetThemePartSize := GetProcAddress(ThemeLibrary, 'GetThemePartSize');
  1048. GetThemeTextExtent := GetProcAddress(ThemeLibrary, 'GetThemeTextExtent');
  1049. GetThemeTextMetrics := GetProcAddress(ThemeLibrary, 'GetThemeTextMetrics');
  1050. GetThemeBackgroundRegion := GetProcAddress(ThemeLibrary, 'GetThemeBackgroundRegion');
  1051. HitTestThemeBackground := GetProcAddress(ThemeLibrary, 'HitTestThemeBackground');
  1052. DrawThemeEdge := GetProcAddress(ThemeLibrary, 'DrawThemeEdge');
  1053. DrawThemeIcon := GetProcAddress(ThemeLibrary, 'DrawThemeIcon');
  1054. IsThemePartDefined := GetProcAddress(ThemeLibrary, 'IsThemePartDefined');
  1055. IsThemeBackgroundPartiallyTransparent := GetProcAddress(ThemeLibrary, 'IsThemeBackgroundPartiallyTransparent');
  1056. GetThemeColor := GetProcAddress(ThemeLibrary, 'GetThemeColor');
  1057. GetThemeMetric := GetProcAddress(ThemeLibrary, 'GetThemeMetric');
  1058. GetThemeString := GetProcAddress(ThemeLibrary, 'GetThemeString');
  1059. GetThemeBool := GetProcAddress(ThemeLibrary, 'GetThemeBool');
  1060. GetThemeInt := GetProcAddress(ThemeLibrary, 'GetThemeInt');
  1061. GetThemeEnumValue := GetProcAddress(ThemeLibrary, 'GetThemeEnumValue');
  1062. GetThemePosition := GetProcAddress(ThemeLibrary, 'GetThemePosition');
  1063. GetThemeFont := GetProcAddress(ThemeLibrary, 'GetThemeFont');
  1064. GetThemeRect := GetProcAddress(ThemeLibrary, 'GetThemeRect');
  1065. GetThemeMargins := GetProcAddress(ThemeLibrary, 'GetThemeMargins');
  1066. GetThemeIntList := GetProcAddress(ThemeLibrary, 'GetThemeIntList');
  1067. GetThemePropertyOrigin := GetProcAddress(ThemeLibrary, 'GetThemePropertyOrigin');
  1068. SetWindowTheme := GetProcAddress(ThemeLibrary, 'SetWindowTheme');
  1069. GetThemeFilename := GetProcAddress(ThemeLibrary, 'GetThemeFilename');
  1070. GetThemeSysColor := GetProcAddress(ThemeLibrary, 'GetThemeSysColor');
  1071. GetThemeSysColorBrush := GetProcAddress(ThemeLibrary, 'GetThemeSysColorBrush');
  1072. GetThemeSysBool := GetProcAddress(ThemeLibrary, 'GetThemeSysBool');
  1073. GetThemeSysSize := GetProcAddress(ThemeLibrary, 'GetThemeSysSize');
  1074. GetThemeSysFont := GetProcAddress(ThemeLibrary, 'GetThemeSysFont');
  1075. GetThemeSysString := GetProcAddress(ThemeLibrary, 'GetThemeSysString');
  1076. GetThemeSysInt := GetProcAddress(ThemeLibrary, 'GetThemeSysInt');
  1077. IsThemeActive := GetProcAddress(ThemeLibrary, 'IsThemeActive');
  1078. IsAppThemed := GetProcAddress(ThemeLibrary, 'IsAppThemed');
  1079. GetWindowTheme := GetProcAddress(ThemeLibrary, 'GetWindowTheme');
  1080. EnableThemeDialogTexture := GetProcAddress(ThemeLibrary, 'EnableThemeDialogTexture');
  1081. IsThemeDialogTextureEnabled := GetProcAddress(ThemeLibrary, 'IsThemeDialogTextureEnabled');
  1082. GetThemeAppProperties := GetProcAddress(ThemeLibrary, 'GetThemeAppProperties');
  1083. SetThemeAppProperties := GetProcAddress(ThemeLibrary, 'SetThemeAppProperties');
  1084. GetCurrentThemeName := GetProcAddress(ThemeLibrary, 'GetCurrentThemeName');
  1085. GetThemeDocumentationProperty := GetProcAddress(ThemeLibrary, 'GetThemeDocumentationProperty');
  1086. DrawThemeParentBackground := GetProcAddress(ThemeLibrary, 'DrawThemeParentBackground');
  1087. EnableTheming := GetProcAddress(ThemeLibrary, 'EnableTheming');
  1088. end;
  1089. end;
  1090. Result := ThemeLibrary > 0;
  1091. finally
  1092. Lock.Leave;
  1093. end;
  1094. end;
  1095. //----------------------------------------------------------------------------------------------------------------------
  1096. function UseThemes: Boolean;
  1097. begin
  1098. Result := ThemeLibrary > 0;
  1099. if Result then
  1100. Result := IsAppThemed and IsThemeActive;
  1101. end;
  1102. //----------------------------------------------------------------------------------------------------------------------
  1103. initialization
  1104. Lock := TCriticalSection.Create;
  1105. finalization
  1106. while ReferenceCount > 0 do
  1107. FreeThemeLibrary;
  1108. Lock.Free;
  1109. end.