如何在Excel 64位全屏模式下隐藏标题栏

时间:2019-01-15 12:45:20

标签: excel vba window title

当前,我们在Excel中有一些报告,可将其用作各个部门电视屏幕的仪表板。我们将它们设置为全屏模式以隐藏功能区等,但最顶部的标题栏仍然显示。我有一些代码可以用来隐藏它,但它仅适用于32位Excel。我还需要将此功能用于64位(或改为)。

我一直在使用32位的代码如下。

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 GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetFocus Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hWndLock As Long) As Long


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 '// Title bar bit
Private Const WS_SYSMENU As Long = &H80000 '// System menu bit
Private Const WS_THICKFRAME As Long = &H40000 '// Sizable frame bit
Private Const WS_MINIMIZEBOX As Long = &H20000 '// Minimize box bit
Private Const WS_MAXIMIZEBOX As Long = &H10000 '// Maximize box bit
Private Const WS_EX_TOOLWINDOW As Long = &H80 '// Tool Window: small titlebar bit
Private Const SC_CLOSE As Long = &HF060 'Constant to identify the Close menu item
'// Set or clear a bit from a style flag
Private Sub SetBit(ByRef lStyle As Long, ByVal lBit As Long, ByVal bOn As Boolean)


If bOn Then
lStyle = lStyle Or lBit
Else
lStyle = lStyle And Not lBit
End If


End Sub
Public Sub SetStyleHide()


Dim lStyle As Long, hMenu As Long

'Get the basic window style
lStyle = GetWindowLong(Application.hwnd, GWL_STYLE)


If lStyle = 0 Then
MsgBox "Unable to determine application window handle...", vbExclamation, "Error"
Exit Sub
End If


'// Build up the basic window style flags for the form adapted to the application window not UF's


SetBit lStyle, WS_CAPTION, False
SetBit lStyle, WS_SYSMENU, False
SetBit lStyle, WS_THICKFRAME, False
SetBit lStyle, WS_MINIMIZEBOX, False
SetBit lStyle, WS_MAXIMIZEBOX, False


'Set the basic window styles
SetWindowLong Application.hwnd, GWL_STYLE, lStyle


'Get the extended window style
lStyle = GetWindowLong(Application.hwnd, GWL_EXSTYLE)

'// Handle the close button
'// hMenu = GetSystemMenu(Application.hWnd, 1)


'// Not wanted - delete it from the control menu
hMenu = GetSystemMenu(Application.hwnd, 0)
DeleteMenu hMenu, SC_CLOSE, 0&

'Update the window with the changes
DrawMenuBar Application.hwnd
SetFocus Application.hwnd


End Sub


Public Sub SetStyleShow()


Dim lStyle As Long, hMenu As Long

'Get the basic window style
lStyle = GetWindowLong(Application.hwnd, GWL_STYLE)

If lStyle = 0 Then
MsgBox "Unable to determine application window handle...", vbExclamation, "Error"
Exit Sub
End If


'// Build up the basic window style flags for the form adapted to the application window not UF's


SetBit lStyle, WS_CAPTION, True
SetBit lStyle, WS_SYSMENU, True
SetBit lStyle, WS_THICKFRAME, True
SetBit lStyle, WS_MINIMIZEBOX, True
SetBit lStyle, WS_MAXIMIZEBOX, True


'Set the basic window styles
SetWindowLong Application.hwnd, GWL_STYLE, lStyle


'Get the extended window style
lStyle = GetWindowLong(Application.hwnd, GWL_EXSTYLE)

'// Handle the close button
'// hMenu = GetSystemMenu(Application.hWnd, 1)


'// Not wanted - delete it from the control menu
'hMenu = GetSystemMenu(Application.hwnd, 0)
'DeleteMenu hMenu, SC_CLOSE, 0&

'Update the window with the changes
DrawMenuBar Application.hwnd
SetFocus Application.hwnd


End Sub

这对于32位来说可以正常工作,但是如果我在64位版本上运行它会出错。有什么办法解决吗?

0 个答案:

没有答案