Libreoffice在windows上有没有办法深色

如题,不全深色都行,主题深色就行.实在是太闪眼睛了.

autohotkey论坛这个帖子里有
Invert window colors - AutoHotkey Community
全局反色和单个窗口反色的代码。

单个窗口反色需要配置UIA,较为复杂。
全局反色ctrl shift f 触发。

#NoEnv
#SingleInstance Force
SetBatchLines -1
DllCall("LoadLibrary", "Str", "Magnification.dll")
Initialized := False
OnExit, Uninitialize
InvertMatrix := [-1,  0,  0,  0,  0
               ,  0, -1,  0,  0,  0
               ,  0,  0, -1,  0,  0
               ,  0,  0,  0,  1,  0
               ,  1,  1,  1,  0,  1]
VarSetCapacity(MagEffectInvert, 100, 0)
Addr := &MagEffectInvert
For I, V In InvertMatrix
   Addr := NumPut(V, Addr + 0, "Float")
Return
; ----------------------------------------------------------------------------------------------------------------------
Uninitialize:
   If (Initialized)
      DllCall("Magnification.dll\MagUninitialize")
ExitApp
; ----------------------------------------------------------------------------------------------------------------------
^+f::
   If (Initialized)
      Initialized := DllCall("Magnification.dll\MagUninitialize", "UInt") & 0
   Else If (Initialized := DllCall("Magnification.dll\MagInitialize", "UInt"))
      DllCall("Magnification.dll\MagSetFullscreenColorEffect", "Ptr", &MagEffectInvert)
Return#NoEnv
#SingleInstance Force
SetBatchLines -1
DllCall("LoadLibrary", "Str", "Magnification.dll")
Initialized := False
OnExit, Uninitialize
InvertMatrix := [-1,  0,  0,  0,  0
               ,  0, -1,  0,  0,  0
               ,  0,  0, -1,  0,  0
               ,  0,  0,  0,  1,  0
               ,  1,  1,  1,  0,  1]
VarSetCapacity(MagEffectInvert, 100, 0)
Addr := &MagEffectInvert
For I, V In InvertMatrix
   Addr := NumPut(V, Addr + 0, "Float")
Return
; ----------------------------------------------------------------------------------------------------------------------
Uninitialize:
   If (Initialized)
      DllCall("Magnification.dll\MagUninitialize")
ExitApp
; ----------------------------------------------------------------------------------------------------------------------
^+f::
   If (Initialized)
      Initialized := DllCall("Magnification.dll\MagUninitialize", "UInt") & 0
   Else If (Initialized := DllCall("Magnification.dll\MagInitialize", "UInt"))
      DllCall("Magnification.dll\MagSetFullscreenColorEffect", "Ptr", &MagEffectInvert)
Return```

另外,单个窗口反色,这个软件也可以实现, Release ShaderGlass v0.7 · mausimus/ShaderGlass · GitHub

还有这个软件

autohotkey 单个窗口反色的代码和配置方法。

效果:

配置方法:
安装autohotkey,在autohotkey的安装目录下,将autohotkeyU32,U64,A32分别复制一份,重命名为添加_UIA后缀
image

运行以下激活代码.ahk(如果路径不是C:\Program Files\AutoHotkey,需自行修改)

EnableUIAccess("C:\Program Files\AutoHotkey\AutoHotkeyA32_UIA.exe")
EnableUIAccess("C:\Program Files\AutoHotkey\AutoHotkeyU32_UIA.exe")
EnableUIAccess("C:\Program Files\AutoHotkey\AutoHotkeyU64_UIA.exe")

EnableUIAccess(filename)
{
    hStore := DllCall("Crypt32\CertOpenStore", "ptr", 10 ; STORE_PROV_SYSTEM_W
        , "uint", 0, "ptr", 0, "uint", 0x20000 ; SYSTEM_STORE_LOCAL_MACHINE
        , "wstr", "Root", "ptr")
    if !hStore
        throw "CertOpenStore"
    ; Find or create certificate for signing.
    p := DllCall("Crypt32\CertFindCertificateInStore", "ptr", hStore
        , "uint", 0x10001 ; X509_ASN_ENCODING|PKCS_7_ASN_ENCODING
        , "uint", 0, "uint", 0x80007 ; FIND_SUBJECT_STR
        , "wstr", "AutoHotkey", "ptr", 0, "ptr")
    if p
        cert := new CertContext(p)
    else
        cert := EnableUIAccess_CreateCert("AutoHotkey", hStore)
    ; Set uiAccess attribute in manifest.
    EnableUIAccess_SetManifest(filename)
    ; Sign the file (otherwise uiAccess attribute is ignored).
    EnableUIAccess_SignFile(filename, cert, "AutoHotkey")
}

EnableUIAccess_SetManifest(file)
{
    xml := ComObjCreate("Msxml2.DOMDocument")
    xml.async := false
    xml.setProperty("SelectionLanguage", "XPath")
    xml.setProperty("SelectionNamespaces"
        , "xmlns:v1='urn:schemas-microsoft-com:asm.v1' "
        . "xmlns:v3='urn:schemas-microsoft-com:asm.v3'")
    if !xml.load("res://" file "/#24/#1") ; Load current manifest
        throw "manifest/load"
    
    node := xml.selectSingleNode("/v1:assembly/v3:trustInfo/v3:security"
                    . "/v3:requestedPrivileges/v3:requestedExecutionLevel")
    if !node ; Not AutoHotkey v1.1?
        throw "manifest/parse"
    
    node.setAttribute("uiAccess", "true")
    xml := RTrim(xml.xml, "`r`n")
    
    VarSetCapacity(data, data_size := StrPut(xml, "utf-8") - 1)
    StrPut(xml, &data, "utf-8")
    
    if !(hupd := DllCall("BeginUpdateResource", "str", file, "int", false))
        throw "rsrc"
    r := DllCall("UpdateResource", "ptr", hupd, "ptr", 24, "ptr", 1
                    , "ushort", 1033, "ptr", &data, "uint", data_size)
    if !DllCall("EndUpdateResource", "ptr", hupd, "int", !r) && r
        throw "rsrc"
}

EnableUIAccess_CreateCert(CertName, hStore)
{
    if !DllCall("Advapi32\CryptAcquireContext", "ptr*", hProv
        , "str", CertName, "ptr", 0, "uint", 1, "uint", 0) ; PROV_RSA_FULL=1, open existing=0
    {
        if !DllCall("Advapi32\CryptAcquireContext", "ptr*", hProv
            , "str", CertName, "ptr", 0, "uint", 1, "uint", 8) ; PROV_RSA_FULL=1, CRYPT_NEWKEYSET=8
            throw "CryptAcquireContext"
        prov := new CryptContext(hProv)

        if !DllCall("Advapi32\CryptGenKey", "ptr", hProv
                , "uint", 2, "uint", 0x4000001, "ptr*", hKey) ; AT_SIGNATURE=2, EXPORTABLE=..01
            throw "CryptGenKey"
        (new CryptKey(hKey)) ; To immediately release it.
    }

    Loop 2
    {
        if A_Index = 1
            pbName := cbName := 0
        else
            VarSetCapacity(bName, cbName), pbName := &bName
        if !DllCall("Crypt32\CertStrToName", "uint", 1, "str", "CN=" CertName
            , "uint", 3, "ptr", 0, "ptr", pbName, "uint*", cbName, "ptr", 0) ; X509_ASN_ENCODING=1, CERT_X500_NAME_STR=3
            throw "CertStrToName"
    }
    VarSetCapacity(cnb, 2*A_PtrSize), NumPut(pbName, NumPut(cbName, cnb))

    VarSetCapacity(endTime, 16)
    DllCall("GetSystemTime", "ptr", &endTime)
    NumPut(NumGet(endTime, "ushort") + 10, endTime, "ushort") ; += 10 years

    if !hCert := DllCall("Crypt32\CertCreateSelfSignCertificate"
        , "ptr", hProv, "ptr", &cnb, "uint", 0, "ptr", 0
        , "ptr", 0, "ptr", 0, "ptr", &endTime, "ptr", 0, "ptr")
        throw "CertCreateSelfSignCertificate"
    cert := new CertContext(hCert)

    if !DllCall("Crypt32\CertAddCertificateContextToStore", "ptr", hStore
        , "ptr", hCert, "uint", 1, "ptr", 0) ; STORE_ADD_NEW=1
        throw "CertAddCertificateContextToStore"

    return cert
}

EnableUIAccess_DeleteCertAndKey(CertName)
{
    DllCall("Advapi32\CryptAcquireContext", "ptr*", undefined
        , "str", CertName, "ptr", 0, "uint", 1, "uint", 16) ; PROV_RSA_FULL=1, CRYPT_DELETEKEYSET=16
    if !hStore := DllCall("Crypt32\CertOpenStore", "ptr", 10 ; STORE_PROV_SYSTEM_W
        , "uint", 0, "ptr", 0, "uint", 0x20000 ; SYSTEM_STORE_LOCAL_MACHINE
        , "wstr", "Root", "ptr")
		throw "CertOpenStore"
	if !p := DllCall("Crypt32\CertFindCertificateInStore", "ptr", hStore
        , "uint", 0x10001 ; X509_ASN_ENCODING|PKCS_7_ASN_ENCODING
        , "uint", 0, "uint", 0x80007 ; FIND_SUBJECT_STR
        , "wstr", CertName, "ptr", 0, "ptr")
		return 0
	if !DllCall("Crypt32\CertDeleteCertificateFromStore", "ptr", p)
		throw "CertDeleteCertificateFromStore"
	return 1
}

class CryptContext {
    __New(p) {
        this.p := p
    }
    __Delete() {
        DllCall("Advapi32\CryptReleaseContext", "ptr", this.p, "uint", 0)
    }
}
class CertContext extends CryptContext {
    __Delete() {
        DllCall("Crypt32\CertFreeCertificateContext", "ptr", this.p)
    }
}
class CryptKey extends CryptContext {
    __Delete() {
        DllCall("Advapi32\CryptDestroyKey", "ptr", this.p)
    }
}

EnableUIAccess_SignFile(File, CertCtx, Name)
{
    VarSetCapacity(wfile, 2 * StrPut(File, "utf-16")), StrPut(File, &wfile, "utf-16")
    VarSetCapacity(wname, 2 * StrPut(Name, "utf-16")), StrPut(Name, &wname, "utf-16")
    cert_ptr := IsObject(CertCtx) ? CertCtx.p : CertCtx

    EnableUIAccess_Struct(file_info, "ptr", A_PtrSize*3 ; SIGNER_FILE_INFO
        , "ptr", &wfile)
    VarSetCapacity(dwIndex, 4, 0) ; DWORD
    EnableUIAccess_Struct(subject_info, "ptr", A_PtrSize*4 ; SIGNER_SUBJECT_INFO
        , "ptr", &dwIndex, "ptr", SIGNER_SUBJECT_FILE:=1, "ptr", &file_info)
    EnableUIAccess_Struct(cert_store_info, "ptr", A_PtrSize*4 ; SIGNER_CERT_STORE_INFO
        , "ptr", cert_ptr, "ptr", SIGNER_CERT_POLICY_CHAIN:=2)
    EnableUIAccess_Struct(cert_info, "uint", 8+A_PtrSize*2 ; SIGNER_CERT
        , "uint", SIGNER_CERT_STORE:=2, "ptr", &cert_store_info)
    EnableUIAccess_Struct(authcode_attr, "uint", 8+A_PtrSize*3 ; SIGNER_ATTR_AUTHCODE
        , "int", false, "ptr", true, "ptr", &wname)
    EnableUIAccess_Struct(sig_info, "uint", 8+A_PtrSize*4 ; SIGNER_SIGNATURE_INFO
        , "uint", CALG_SHA1:=0x8004, "ptr", SIGNER_AUTHCODE_ATTR:=1
        , "ptr", &authcode_attr)

    hr := DllCall("MSSign32\SignerSign"
        , "ptr", &subject_info, "ptr", &cert_info, "ptr", &sig_info
        , "ptr", 0, "ptr", 0, "ptr", 0, "ptr", 0, "uint")
    if (hr != 0)
        throw hr
}

EnableUIAccess_Struct(ByRef struct, arg*)
{
    VarSetCapacity(struct, arg[2], 0), p := &struct
    Loop % arg.Length()//2
        p := NumPut(arg[2], p+0, arg[1]), arg.RemoveAt(1, 2)
    return &struct
}

窗口颜色反转代码,f7触发

Gui, +HWNDhGui +AlwaysOnTop
DllCall("GetWindowBand", "ptr", hGui, "uint*", band)
Gui, Destroy
hGui := ""
if (band = 1)
{
   If (A_PtrSize = 8)
      RunWait "C:\Program Files\AutoHotkey\AutoHotkeyU64_UIA.exe" "%A_ScriptFullPath%"
   Else If A_IsUnicode
      RunWait "C:\Program Files\AutoHotkey\AutoHotkeyU32_UIA.exe" "%A_ScriptFullPath%"
   Else
      RunWait "C:\Program Files\AutoHotkey\AutoHotkeyA32_UIA.exe" "%A_ScriptFullPath%"
}
#SingleInstance Force
#MaxThreadsPerHotkey 2
DetectHiddenWindows, On
SetBatchLines -1
SetWinDelay -1
OnExit, Uninitialize
return

f7::
hTarget := WinExist("A")
if (hTarget = hTargetPrev)
{
   hTargetPrev := ""
   count--
   return
}
count++
hTargetPrev := hTarget
if (hGui = "")
{
   DllCall("LoadLibrary", "str", "magnification.dll")
   DllCall("magnification.dll\MagInitialize")
   Matrix := "-1|0|0|0|0|"
           . "0|-1|0|0|0|"
           . "0|0|-1|0|0|"
           . "0|0|0|1|0|"
           . "1|1|1|0|1"
   VarSetCapacity(MAGCOLOREFFECT, 100, 0)
   Loop, Parse, Matrix, |
      NumPut(A_LoopField, MAGCOLOREFFECT, (A_Index - 1) * 4, "float")
   loop 2
   {
      if (A_Index = 2)
         Gui, %A_Index%: +AlwaysOnTop   ; needed for ZBID_UIACCESS
      Gui, %A_Index%: +HWNDhGui%A_Index% -DPIScale +toolwindow -Caption +E0x02000000 +E0x00080000 +E0x20 ;  WS_EX_COMPOSITED := E0x02000000  WS_EX_LAYERED := E0x00080000  WS_EX_CLICKTHROUGH := E0x20
      hChildMagnifier%A_Index% := DllCall("CreateWindowEx", "uint", 0, "str", "Magnifier", "str", "MagnifierWindow", "uint", WS_CHILD := 0x40000000, "int", 0, "int", 0, "int", 0, "int", 0, "ptr", hGui%A_Index%, "uint", 0, "ptr", DllCall("GetWindowLong" (A_PtrSize=8 ? "Ptr" : ""), "ptr", hGui%A_Index%, "int", GWL_HINSTANCE := -6 , "ptr"), "uint", 0, "ptr")
      DllCall("magnification.dll\MagSetColorEffect", "ptr", hChildMagnifier%A_Index%, "ptr", &MAGCOLOREFFECT)
   }
}
Gui, 2: Show, NA   ; needed for removing flickering
hGui := hGui1
hChildMagnifier := hChildMagnifier1
loop
{
   if (count != 1)   ; target window changed
   {
      if (count = 2)
         count--
      WinHide, ahk_id %hGui%
      return
   }
   VarSetCapacity(WINDOWINFO, 60, 0)
   if (DllCall("GetWindowInfo", "ptr", hTarget, "ptr", &WINDOWINFO) = 0) and (A_LastError = 1400)   ; destroyed
   {
      count--
      WinHide, ahk_id %hGui%
      return
   }
   if (NumGet(WINDOWINFO, 36, "uint") & 0x20000000) or !(NumGet(WINDOWINFO, 36, "uint") & 0x10000000)  ; minimized or not visible
   {
      if (wPrev != 0)
      {
         WinHide, ahk_id %hGui%
         wPrev := 0
      }
      sleep 10
      continue
   }
   x := NumGet(WINDOWINFO, 20, "int")
   y := NumGet(WINDOWINFO, 8, "int")
   w := NumGet(WINDOWINFO, 28, "int") - x
   h := NumGet(WINDOWINFO, 32, "int") - y
   if (hGui = hGui1) and ((NumGet(WINDOWINFO, 44, "uint") = 1) or (DllCall("GetAncestor", "ptr", WinExist("A"), "uint", GA_ROOTOWNER := 3, "ptr") = hTarget))   ; activated
   {
      hGui := hGui2
      hChildMagnifier := hChildMagnifier2
      WinMove, ahk_id %hGui%,, x, y, w, h
      WinMove, ahk_id %hChildMagnifier%,, 0, 0, w, h
      WinShow, ahk_id %hChildMagnifier%
      WinShow, ahk_id %hGui%
      hideGui := hGui1
   }
   else if (hGui = hGui2) and (NumGet(WINDOWINFO, 44, "uint") != 1) and ((hr := DllCall("GetAncestor", "ptr", WinExist("A"), "uint", GA_ROOTOWNER := 3, "ptr")) != hTarget) and hr   ; deactivated
   {
      hGui := hGui1
      hChildMagnifier := hChildMagnifier1
      WinMove, ahk_id %hGui%,, x, y, w, h
      WinMove, ahk_id %hChildMagnifier%,, 0, 0, w, h
      WinShow, ahk_id %hChildMagnifier%
      DllCall("SetWindowPos", "ptr", hGui, "ptr", hTarget, "int", 0, "int", 0, "int", 0, "int", 0, "uint", 0x0040|0x0010|0x001|0x002)
      DllCall("SetWindowPos", "ptr", hTarget, "ptr", 1, "int", 0, "int", 0, "int", 0, "int", 0, "uint", 0x0040|0x0010|0x001|0x002)   ; some windows can not be z-positioned before setting them to bottom
      DllCall("SetWindowPos", "ptr", hTarget, "ptr", hGui, "int", 0, "int", 0, "int", 0, "int", 0, "uint", 0x0040|0x0010|0x001|0x002)
      hideGui := hGui2 
   }
   else if (x != xPrev) or (y != yPrev) or (w != wPrev) or (h != hPrev)   ; location changed
   {
      WinMove, ahk_id %hGui%,, x, y, w, h
      WinMove, ahk_id %hChildMagnifier%,, 0, 0, w, h
      WinShow, ahk_id %hChildMagnifier%
      WinShow, ahk_id %hGui%
   }
   if (A_PtrSize = 8)
   {
      VarSetCapacity(RECT, 16, 0)
      NumPut(x, RECT, 0, "int")
      NumPut(y, RECT, 4, "int")
      NumPut(w, RECT, 8, "int")
      NumPut(h, RECT, 12, "int")
      DllCall("magnification.dll\MagSetWindowSource", "ptr", hChildMagnifier, "ptr", &RECT)
   }
   else
      DllCall("magnification.dll\MagSetWindowSource", "ptr", hChildMagnifier, "int", x, "int", y, "int", w, "int", h)
   xPrev := x, yPrev := y, wPrev := w, hPrev := h
   if hideGui
   {
      WinHide, ahk_id %hideGui%
      hideGui := ""
   }
}
return

Uninitialize:
if (hGui != "")
   DllCall("magnification.dll\MagUninitialize")
ExitApp
2 个赞

最近您用AHK解决了很多问题,真是一位高手。也跟着您开了眼界,原来AHK如此的强大。

我不是高手 :joy:,autohotkey论坛很多高手,我没事喜欢逛一逛

我看了下,话说,libreoffice 自己就有深色功能啊。。。。。。
效果

设置这两处

感觉效果很差,灰蒙蒙一片。
话说你的标题栏咋弄得深色。

我想把他这个dark搞成深灰或者暗黑

那你试试窗口反色工具吧
这种效果:

标题栏深色在设置里

这是啥软件

这个有那么亿点复杂,看样子我需要彻底学习一下这个东西,保证不会用出问题

不用麻烦了,我找了个超简单的方法

…\libreoffice\share\gallery\personas\dark

转到这个目录下面
把原本灰不拉叽的三张图全都用画图涂黑就好了。。。
image

弄完之后,先选个白色主题,点应用,再点黑色,点应用,就OK了。
image

满意的话,请点解决方案

1 个赞

@God-Asimov 我就想问问,现在平时使用 Libreoffice 还有没有兼容问题?我也想转,但以前用的时候总会出现各种各样的兼容问题。

确实可以,正在尝试找一个好一点的配色。
顺便问一下你的标题栏用的哪个软件。

个人感觉没有,不过我在sandboxie里留了个wps以备不时之需。

1 个赞

libreoffice相对于msoffice wps分别有什么优缺点啊

windows自带个性化设置

win11特性?我的win10好像不行