NewUxTheme.pas 65 KB

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