您可以使用Windows API在VBA中更改userform的titlebar的颜色吗? [英] Can you change the color of the titlebar of a userform in VBA using Windows API?

查看:759
本文介绍了您可以使用Windows API在VBA中更改userform的titlebar的颜色吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Windows API更改VBA用户窗体的标题栏的颜色。请注意,我只想更改特定用户形式的标题栏颜色,而不是全系统更改颜色。谢谢!

Is it possible to change the color of the title bar for a VBA userform using Windows API. Please note that I am only interested in changing the color of the title bar for a particular userform and not a system-wide them change. Thanks!

推荐答案

只是为了好玩;

UserForm:

Private gHWND As Long

Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    If Button = 1 Then HandleDragMove gHWND
End Sub

Private Sub UserForm_Initialize()
    gHWND = Setup(Me)
End Sub

Private Sub UserForm_Click()
    Unload Me
End Sub

*。BAS

Option Explicit
Private Const WM_NCLBUTTONDOWN = &HA1&
Private Const HTCAPTION = 2&
Private Const GWL_STYLE = (-16)
Private Const WS_BORDER = &H800000
Private Const WS_DLGFRAME = &H400000
Private Const WS_CAPTION = WS_BORDER Or WS_DLGFRAME
Private Declare Sub ReleaseCapture Lib "User32" ()
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal HWND As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
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

Function Setup(objForm As Object) As Long
    Setup = FindWindow("ThunderDFrame", objForm.Caption)
    SetWindowLong Setup, GWL_STYLE, GetWindowLong(Setup, GWL_STYLE) And Not WS_CAPTION
End Function

Public Sub HandleDragMove(HWND As Long)
    Call ReleaseCapture
    Call SendMessage(HWND, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End Sub

(需要mod为64位Office)

(Would need mod for 64bit Office)

这篇关于您可以使用Windows API在VBA中更改userform的titlebar的颜色吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆