;============================================================ ; iron_darkmode.hsp — ダークモード対応 ; ; Windows 10/11 ダークモード検出 + WinForms ダークテーマ適用。 ; ; API: #ifndef __iron_darkmode_hsp__ #define __iron_darkmode_hsp__ #module iron_darkmode #uselib "advapi32.dll" #cfunc _dm_RegOpenKey "RegOpenKeyExA" int, str, int, int, var #cfunc _dm_RegQuery "RegQueryValueExA" int, str, int, var, var, var #cfunc _dm_RegClose "RegCloseKey" int #uselib "dwmapi.dll" #cfunc _DwmSetWindowAttribute "DwmSetWindowAttribute" int, int, var, int #uselib "user32.dll" #cfunc _dm_GetHwnd "GetActiveWindow" ;------------------------------------------------------------ ; darkmode_is_enabled() - Check system dark mode ;------------------------------------------------------------ #defcfunc darkmode_is_enabled local _hk, local _val, local _sz, local _type _hk = 0 ; HKEY_CURRENT_USER = 0x80000001 if _dm_RegOpenKey(0x80000001, "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", 0, 0x20019, _hk) != 0 : return 0 _sz = 4 : _val = 1 : _type = 0 _dm_RegQuery _hk, "AppsUseLightTheme", 0, _type, _val, _sz _dm_RegClose _hk ; AppsUseLightTheme: 0=dark, 1=light if _val == 0 : return 1 return 0 ;------------------------------------------------------------ ; darkmode_apply_titlebar - Dark title bar via DwmSetWindowAttribute ;------------------------------------------------------------ #deffunc darkmode_apply_titlebar local _hwnd, local _dark _hwnd = _dm_GetHwnd() if _hwnd == 0 : return -1 _dark = 1 ; DWMWA_USE_IMMERSIVE_DARK_MODE = 20 _DwmSetWindowAttribute _hwnd, 20, _dark, 4 return 0 ;------------------------------------------------------------ ; darkmode_apply - Apply dark colors to current HSP window ; Sets background to dark gray, text to white ;------------------------------------------------------------ #deffunc darkmode_apply local _frm, local _bg, local _fg if darkmode_is_enabled() == 0 : return 0 ; Set HSP window background color 30, 30, 30 boxf color 220, 220, 220 ; Apply title bar darkmode_apply_titlebar ; If hsp3net, set Form.BackColor/ForeColor getforms _frm, 0 if vartype(_frm) == 6 { newnet _bg, "", "System.Drawing.Color", 1 netres _bg mcall _bg, "FromArgb", 30, 30, 30 mcall _frm, "set_BackColor", _bg newnet _fg, "", "System.Drawing.Color", 1 netres _fg mcall _fg, "FromArgb", 220, 220, 220 mcall _frm, "set_ForeColor", _fg } return 1 ;------------------------------------------------------------ ; darkmode_colors - Get theme-appropriate colors ; stat: background RGB packed, refdval: foreground RGB packed ;------------------------------------------------------------ #defcfunc darkmode_bg if darkmode_is_enabled() : return 0x1E1E1E return 0xFFFFFF #defcfunc darkmode_fg if darkmode_is_enabled() : return 0xDCDCDC return 0x000000 #global #endif