我想做个窗口换肤的控件。但是不知道如何将一张图片覆盖在标题栏上,就像换肤软件一样,改变窗体样式。代码该怎样写,能给个例子吗?

解决方案 »

  1.   

    ' Unique Form Example - Written completely by Grayda
    '   firestorm.stormynight.net' This code shows you how to create cool looking forms to use in your application
    ' No OCXs are required, and only one form with minimal coding. Please vote, coz I
    ' need em! :)' You may use this code, and modify it, as long as you give me lots of credit for it :)' This declaration allows us to click on and hold onto our title bar or corners for resize (Even if they aren't present)
    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
    ' Lets go of the titlebar or corners
    Private Declare Sub ReleaseCapture Lib "user32" ()
    ' Constant for mouse down
    Const WM_NCLBUTTONDOWN = &HA1
    ' Our titlebar
    Const WCAPTION = 2
    ' The South-Eastern corner of our form, for resizing
    Const W_SE_RESIZE = 17Private Sub Form_Resize()
    ' Positions the label at 0,0 and spans the entire form
    Label1.Move 0, 0, Me.Width
    ' Positions our information in the center
    Label2.Move Me.Width / 2 - Label2.Width / 2, Me.Height / 2 - Label2.Height / 2
    ' Label3 is our resize button. This code places it in the corner
    Label3.Move Me.Width - Label3.Width, Me.Height - Label3.Height
    ' Label4 is our close button. Slaps it at the end of our form (up the top)
    Label4.Move Me.Width - Label4.Width - 100
    ' Label5 is the minimize button
    Label5.Move Me.Width - Label5.Width - Label4.Width - Label6.Width - 150
    ' Label6 is the maximize and restore button
    Label6.Move Me.Width - Label4.Width - 450
    End SubPrivate Sub Label1_DblClick()
    '  When you double click on a form title, it will maximize. This does the same thing
    Label6_Click
    End SubPrivate Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ' Grabs onto our form's titlebar. If you want the focus to follow the mouse, then take away the
    ' if button = 1 if statement
        If Button = 1 Then
            ReleaseCapture
            SendMessage Me.hwnd, WM_NCLBUTTONDOWN, WCAPTION, 0&
        End If
    End Sub
    Private Sub Label3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ' This code grabs onto our resize bars and resizes the form. Try replacing W_SE_RESIZE with a
    ' number between 10 and 17 to see the resizing effects
        If Button = 1 Then
            ReleaseCapture
            SendMessage Me.hwnd, WM_NCLBUTTONDOWN, W_SE_RESIZE, 0&
        End If
    End Sub
    Private Sub Label4_Click()
    End
    End SubPrivate Sub Label5_Click()
    ' Minimize the form
    Me.WindowState = 1
    End SubPrivate Sub Label6_Click()
    ' Is it maximized? If so, then return it to normal. Else maximize it
    If WindowState <> 2 Then
    Me.WindowState = 2
    Else
    WindowState = 0
    End If
    End Sub
      

  2.   

    这个是去掉标题后的标准窗体操作
    必须
    BorderStyle=0
      

  3.   

    用  ActiveSkin控件  做吧   很容易的
      

  4.   

    自绘标题栏也可以(需要拦截WM_NCPaint消息)
      

  5.   

    可以参考:http://search.csdn.net/Expert/topic/2434/2434707.xml?temp=7.085818E-02
      

  6.   

    “不行,那有菜单的情况下,菜单会跑到上面。”
    找一个第三方的菜单控件(可以定义位置),反正你做换皮效果,搞个COOL的菜单也是应该的,这种菜单很容易用的。:-)
      

  7.   

    同意 rainstormmaster 的说法。用下面的代码,楼主看看 WM_NCPAINT 消息被拦截的情况。
    运行的时候把窗体的一部分拉到屏幕外面再拉回来。' 窗体模块
    Option ExplicitPrivate Sub Form_Load()
        ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf WindowProc)
    End SubPrivate Sub Form_Unload(Cancel As Integer)
        SetWindowLong Me.hwnd, GWL_WNDPROC, ret
    End Sub
    ' 标准模块
    Option Explicit
    Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Public Const GWL_WNDPROC = (-4)
    Public Const WM_RBUTTONDOWN = &H204
    Private Const WM_NCPAINT = &H85
    Public ret As LongFunction WindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        If Msg = WM_NCPAINT Then
            Debug.Print "收到 WM_NCPAINT 消息"
        Else
            WindowProc = CallWindowProc(ret, hwnd, Msg, wParam, lParam)
        End If
    End Function
      

  8.   

    rainstormmaster(暴风雨 v2.0) :http://vbaccelerator.com/home/VB/Code/Controls/Skins/article.asp这个例子有些复杂,而且它的代码有一些放在了dll文件里,无法看到。http://search.csdn.net/Expert/topic/2434/2434707.xml?temp=7.085818E-02你只是改变了标题栏的颜色,怎么把图片赋在标题栏和边框上呢?