excel 在VBA中隐藏任务栏和窗口标题栏

mnowg1ta  于 2022-11-18  发布在  其他
关注(0)|答案(1)|浏览(411)

有人知道如何在没有窗口标题栏或任务栏的情况下在VBA中获得完全全屏吗?(我使用的是Windows 10 x64)
在我的研究中,我只找到了Windows XP和2000或其他旧版本Windows的代码。这是我找到的代码:

Public Declare PtrSafe Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As APPBARDATA) As LongPtr

Public Const ABM_GETSTATE = &H4
Public Const ABM_SETSTATE = &HA
Public Const ABS_AUTOHIDE = &H1
Public Const ABS_ALWAYSONTOP = &H2

Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Public Type APPBARDATA
cbSize As Long
hwnd As Long
uCallbackMessage As Long
uEdge As Long
rc As RECT
lParam As Long
End Type

Sub TaskbarAutohideOn()
Dim ABD As APPBARDATA
ABD.cbSize = Len(ABD)
SHAppBarMessage ABM_GETSTATE, ABD
ABD.lParam = ABS_AUTOHIDE
SHAppBarMessage ABM_SETSTATE, ABD
End Sub

Sub TaskbarAutohideOff()
Dim ABD As APPBARDATA
ABD.cbSize = Len(ABD)
SHAppBarMessage ABM_GETSTATE, ABD
ABD.lParam = ABS_ALWAYSONTOP
SHAppBarMessage ABM_SETSTATE, ABD
End Sub
wfveoks0

wfveoks01#

我找到了解决方案。此代码适用于Windows 10:

Option Explicit

#If VBA7 Then

'// 64 Bits

'// Declarações DLL para alterar ou aparência do UserForm

Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long

Private Declare PtrSafe Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

#Else

'// 32 Bits

'// Declarações DLL para alterar ou aparência do UserForm

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

#End If

'// Constantes windows para barra de título

Private Const GWL_STYLE As Long = (-16)           '//The offset of a window's style

Private Const GWL_EXSTYLE As Long = (-20)         '//The offset of a window's extended style

Private Const WS_CAPTION As Long = &HC00000       '//Style to add a titlebar

Private Const WS_EX_DLGMODALFRAME As Long = &H1   '//Controls if the window has an icon
 
'// Constantes windows para transparência

Private Const WS_EX_LAYERED = &H80000             '//color

Private Const LWA_COLORKEY = &H1                  '//Chroma key for fading a certain color on your Form

Private Const LWA_ALPHA = &H2                     '//Only needed if you want to fade the entire userform

Function HideTitleBarAndBordar(frm As Object)

'// Hide TitleBar and UserForm Border

    Dim lngWindow As Long

    Dim lFrmHdl As Long

    lFrmHdl = FindWindow(vbNullString, frm.Caption)

    
'// Build window and set window until you remove the caption, title bar and frame around the window

    lngWindow = GetWindowLong(lFrmHdl, GWL_STYLE)

    lngWindow = lngWindow And (Not WS_CAPTION)

    SetWindowLong lFrmHdl, GWL_STYLE, lngWindow

    lngWindow = GetWindowLong(lFrmHdl, GWL_EXSTYLE)

    lngWindow = lngWindow And Not WS_EX_DLGMODALFRAME

    SetWindowLong lFrmHdl, GWL_EXSTYLE, lngWindow

    DrawMenuBar lFrmHdl

End Function

Function MakeUserformTransparent(frm As Object, Optional Color As Variant)

'//set transparencies on userform***********************************

Dim formhandle As Long

Dim bytOpacity As Byte

formhandle = FindWindow(vbNullString, frm.Caption)

If IsMissing(Color) Then Color = &H8000&        '//rgbWhite

bytOpacity = 0

SetWindowLong formhandle, GWL_EXSTYLE, GetWindowLong(formhandle, GWL_EXSTYLE) Or WS_EX_LAYERED

frm.BackColor = Color

SetLayeredWindowAttributes formhandle, Color, bytOpacity, LWA_COLORKEY

End Function

相关问题