Reference Codebot.Themes.Windows.Hooks.pas
Part of the Codebot Themes Design package
The Codebot.Themes.Windows.Hooks unit themes every window of the program on Windows by intercepting the routines Windows and the LCL draw with, rather than changing one control at a time.
DarkHooksInstall patches the import tables of every loaded module outside the Windows folder, which covers the program, the LCL, and the libraries of the IDE, and of comctl32.dll, which draws the common controls. The routine variables of the UxTheme unit, which the LCL draws with, are pointed at the same hooks. The hooks replace these routines:
- GetSysColor and GetSysColorBrush, which return the colors of the palette of Codebot.Themes.Windows.Colors.
- CreateWindowExW, which gives each new window its visual style, its title bar, and the subclasses that paint its menu bar and the drop down list of a combo box.
- OpenThemeData and its variants, which record the class of each theme handle and open the dark variant of the class when the palette is dark.
- DrawThemeBackground and DrawThemeText, which paint the parts of controls in the colors of the palette, such as tabs, headers, menus, buttons, borders, status bars, progress bars, track bars, tool bars, and cool bars.
- DrawEdge, which draws edges such as the separators of menus in the colors of the palette.
- SystemParametersInfo, which gives the LCL the menu font of the theme.
- DeleteObject, which refuses to delete the brushes of the palette.
- LoadLibrary and LoadLibraryEx, which patch each library loaded later, along with the libraries it brings with it.
Two thread hooks watch the messages of windows. One subclasses the popup menus Windows creates itself, and paints them into a bitmap before copying them to the window, so the light background and separators Windows draws are never seen. The other repaints the sunken borders of edits and lists after Windows paints them.
DarkHooksSetTheme switches the theme while the program runs and themes every window again, and DarkHooksSetMenuFont sets the name of the menu font. DarkHooksUninstall puts back every patched routine whose module is still loaded, restores the routine variables of the UxTheme unit, and removes the hooks and subclasses, so nothing calls into the unit again. DarkHooksModuleUnloaded forgets the routines of a library being unloaded. If the program ends without DarkHooksUninstall, the unit puts everything back as it finalizes.
Items 6 items
| Name | Kind | Line |
|---|---|---|
| DarkHooksInstall | function | 43 |
| DarkHooksModuleUnloaded | procedure | 62 |
| DarkHooksReport | function | 45 |
| DarkHooksSetMenuFont | procedure | 55 |
| DarkHooksSetTheme | procedure | 51 |
| DarkHooksUninstall | procedure | 59 |