找回密码
 加入
搜索
查看: 19338|回复: 11

[特效] 山寨 seniors 大侠的 自绘标题栏【简单 增加 自绘边框,Hover,Down效果】

 火.. [复制链接]
发表于 2013-7-1 21:13:57 | 显示全部楼层 |阅读模式
本帖最后由 Ycxw2008 于 2013-7-2 08:58 编辑

练习为主,不喜勿喷.
欢迎各位指点交流


没仔细整理代码,有错误请见谅

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlusEx.au3>
#include <WinAPIEx.au3>

Global Const $TME_HOVER = 0x00000001
Global Const $TME_LEAVE = 0x00000002
Global Const $TME_NONCLIENT = 0x00000010
Global Const $WVR_VALIDRECTS = 0x0400
Global Const $WM_NCUAHDRAWCAPTION = 0x00AE
Global Const $WM_NCUAHDRAWFRAME = 0x00AF
Global Const $SC_CLOSE = 0xF060
Global Const $SC_MINIMIZE = 0xF020
Global Const $SC_MAXIMIZE = 0xF030
Global Const $SC_RESTORE = 0xF120
Global Const $SC_MOVE = 0xF010
Global Const $SC_MOUSEMENU = 0xF090

Global $rcLBD = DllStructCreate($tagRECT), $rcTBD = DllStructCreate($tagRECT), $rcRBD = DllStructCreate($tagRECT), $rcBBD = DllStructCreate($tagRECT)
Global $rcBL = DllStructCreate($tagRECT), $rcBR = DllStructCreate($tagRECT), $rcTL = DllStructCreate($tagRECT), $rcTR = DllStructCreate($tagRECT)
Global $rcCLIENT = DllStructCreate($tagRECT), $rcCAPTION = DllStructCreate($tagRECT)
Global $rcCLOSE = DllStructCreate($tagRECT), $rcMAX = DllStructCreate($tagRECT), $rcMIN = DllStructCreate($tagRECT), $rcICON = DllStructCreate($tagRECT)

Global $m_Left, $m_Top, $m_Width, $m_Height, $mHover

Opt('GUIOnEventMode', 1)

GUIRegisterMsg($WM_CREATE, 'WM_CREATE')
GUIRegisterMsg($WM_SIZE, 'WM_SIZE')
GUIRegisterMsg($WM_MOVE, 'WM_MOVE')
GUIRegisterMsg($WM_NCPAINT, 'WM_NCPAINT')
GUIRegisterMsg($WM_NCCALCSIZE, 'WM_NCCALCSIZE')
GUIRegisterMsg($WM_NCACTIVATE, 'WM_NCACTIVATE')
GUIRegisterMsg($WM_NCMOUSEMOVE, 'WM_NCMOUSEMOVE')
GUIRegisterMsg($WM_NCMOUSEHOVER, 'WM_NCMOUSEHOVER')
GUIRegisterMsg($WM_NCMOUSELEAVE, 'WM_NCMOUSELEAVE')
GUIRegisterMsg($WM_NCHITTEST, 'WM_NCHITTEST')
GUIRegisterMsg($WM_NCLBUTTONUP, 'WM_NCLBUTTONUP')
GUIRegisterMsg($WM_NCLBUTTONDOWN, 'WM_NCLBUTTONDOWN')

Global $zhu_gui = GUICreate("metro演示", 400, 300, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_POPUP, $WS_VISIBLE, $WS_CAPTION, $WS_SYSMENU))

GUISetOnEvent($GUI_EVENT_CLOSE, "exitfunc")

GUISetState()

While 1
        Sleep(100)
WEnd

Func UpdateRect()
        Local $tRight = $m_Width
        Local $tBottom = $m_Height
        Local $tLeft = $tRight - 4
        Local $tTop = $tBottom - 4
        DllStructSetData($rcTL, 1, 0)
        DllStructSetData($rcTL, 2, 0)
        DllStructSetData($rcTL, 3, 4)
        DllStructSetData($rcTL, 4, 4)

        DllStructSetData($rcBL, 1, 0)
        DllStructSetData($rcBL, 2, $tTop)
        DllStructSetData($rcBL, 3, 4)
        DllStructSetData($rcBL, 4, $tBottom)

        DllStructSetData($rcTR, 1, $tLeft)
        DllStructSetData($rcTR, 2, 0)
        DllStructSetData($rcTR, 3, $tRight)
        DllStructSetData($rcTR, 4, 4)

        DllStructSetData($rcBR, 1, $tLeft)
        DllStructSetData($rcBR, 2, $tTop)
        DllStructSetData($rcBR, 3, $tRight)
        DllStructSetData($rcBR, 4, $tBottom)

        DllStructSetData($rcLBD, 1, 0)
        DllStructSetData($rcLBD, 2, 4)
        DllStructSetData($rcLBD, 3, 4)
        DllStructSetData($rcLBD, 4, $tTop)

        DllStructSetData($rcRBD, 1, $tLeft)
        DllStructSetData($rcRBD, 2, 4)
        DllStructSetData($rcRBD, 3, $tRight)
        DllStructSetData($rcRBD, 4, $tTop)

        DllStructSetData($rcTBD, 1, 4)
        DllStructSetData($rcTBD, 2, 0)
        DllStructSetData($rcTBD, 3, $tLeft)
        DllStructSetData($rcTBD, 4, 4)

        DllStructSetData($rcBBD, 1, 4)
        DllStructSetData($rcBBD, 2, $tTop)
        DllStructSetData($rcBBD, 3, $tLeft)
        DllStructSetData($rcBBD, 4, $tBottom)

        DllStructSetData($rcCAPTION, 1, 4)
        DllStructSetData($rcCAPTION, 2, 4)
        DllStructSetData($rcCAPTION, 3, $tLeft)
        DllStructSetData($rcCAPTION, 4, 30)

        DllStructSetData($rcCLOSE, 2, 4)
        DllStructSetData($rcCLOSE, 4, 24)
        DllStructSetData($rcCLOSE, 3, $tLeft)
        DllStructSetData($rcCLOSE, 1, $tLeft - 21)

        DllStructSetData($rcMAX, 2, 4)
        DllStructSetData($rcMAX, 4, 24)
        DllStructSetData($rcMAX, 3, $tLeft - 21)
        DllStructSetData($rcMAX, 1, $tLeft - 41)

        DllStructSetData($rcMIN, 2, 4)
        DllStructSetData($rcMIN, 4, 24)
        DllStructSetData($rcMIN, 3, $tLeft - 41)
        DllStructSetData($rcMIN, 1, $tLeft - 61)

        DllStructSetData($rcICON, 1, 4)
        DllStructSetData($rcICON, 3, 20)
        DllStructSetData($rcICON, 2, 4)
        DllStructSetData($rcICON, 4, 20)
EndFunc   ;==>UpdateRect


Func __myDraw($hWnd)
        $hDC = _WinAPI_GetWindowDC($hWnd)
        $hBrush = _WinAPI_CreateSolidBrush(0xA24F27)
        _WinAPI_FillRect($hDC, DllStructGetPtr($rcTL), $hBrush)
        _WinAPI_FillRect($hDC, DllStructGetPtr($rcBL), $hBrush)
        _WinAPI_FillRect($hDC, DllStructGetPtr($rcTR), $hBrush)
        _WinAPI_FillRect($hDC, DllStructGetPtr($rcBR), $hBrush)
        _WinAPI_FillRect($hDC, DllStructGetPtr($rcLBD), $hBrush)
        _WinAPI_FillRect($hDC, DllStructGetPtr($rcTBD), $hBrush)
        _WinAPI_FillRect($hDC, DllStructGetPtr($rcRBD), $hBrush)
        _WinAPI_FillRect($hDC, DllStructGetPtr($rcBBD), $hBrush)
        _WinAPI_DeleteObject($hBrush)

        $hBrush = _WinAPI_CreateSolidBrush(0x938573)
        _WinAPI_FillRect($hDC, DllStructGetPtr($rcCAPTION), $hBrush)
        _WinAPI_DeleteObject($hBrush)

        _WinAPI_SetBkMode($hDC, $TRANSPARENT)

        DrawCloseButton($hDC, DllStructGetPtr($rcCLOSE), 0x59B9F7)
        DrawMaxButton($hDC, DllStructGetPtr($rcMAX), 0x0983E7)
        DrawMinButton($hDC, DllStructGetPtr($rcMIN), 0x384FD1)

        _WinAPI_DrawIconEx($hDC, 4, 4, _WinAPI_GetClassLongEx($hWnd, -34))

        _WinAPI_ReleaseDC($hWnd, $hDC)
EndFunc   ;==>__myDraw


Func DrawHoverButton($HTBUTTON)
        $hDC = _WinAPI_GetWindowDC($zhu_gui)
        If $mHover Then
                Switch $mHover
                        Case $HTMINBUTTON
                                DrawMinButton($hDC, DllStructGetPtr($rcMIN), 0x384FD1)
                        Case $HTMAXBUTTON
                                DrawMaxButton($hDC, DllStructGetPtr($rcMAX), 0x0983E7)
                        Case $HTCLOSE
                                DrawCloseButton($hDC, DllStructGetPtr($rcCLOSE), 0x59B9F7)
                EndSwitch
        EndIf
        Switch $HTBUTTON
                Case $HTMINBUTTON
                        $mHover = $HTMINBUTTON
                        DrawMinButton($hDC, DllStructGetPtr($rcMIN), 0xFF0000)
                Case $HTMAXBUTTON
                        $mHover = $HTMAXBUTTON
                        DrawMaxButton($hDC, DllStructGetPtr($rcMAX), 0x00FF00)
                Case $HTCLOSE
                        $mHover = $HTCLOSE
                        DrawCloseButton($hDC, DllStructGetPtr($rcCLOSE), 0x00FFFF)
        EndSwitch
        _WinAPI_ReleaseDC($zhu_gui, $hDC)
EndFunc   ;==>DrawHoverButton

Func DrawMinButton($pDC, $ptr, $color)
        Local $MemDC = _WinAPI_CreateCompatibleDC($pDC)
        Local $hHBITMAP = _WinAPI_CreateCompatibleBitmapEx($pDC, $m_Width, $m_Height, 0xEEEEEE)
        Local $hOld = _WinAPI_SelectObject($MemDC, $hHBITMAP)
        Local $hBrush = _WinAPI_CreateSolidBrush($color)
        _WinAPI_FillRect($MemDC, $ptr, $hBrush)
        Local $dX = $m_Width - 61
        _WinAPI_DrawLine($MemDC, $dX, 18, $dX + 12, 18)
        _WinAPI_DrawLine($MemDC, $dX, 19, $dX + 12, 19)
        _WinAPI_DrawLine($MemDC, $dX, 20, $dX + 12, 20)
        _WinAPI_TransparentBlt($pDC, 0, 0, $m_Width, $m_Height, $MemDC, 0, 0, $m_Width, $m_Height, 0xEEEEEE)
        _WinAPI_SelectObject($MemDC, $hOld)
        _WinAPI_DeleteDC($MemDC)
EndFunc   ;==>DrawMinButton

Func DrawMaxButton($pDC, $ptr, $color)
        Local $MemDC = _WinAPI_CreateCompatibleDC($pDC)
        Local $hHBITMAP = _WinAPI_CreateCompatibleBitmapEx($pDC, $m_Width, $m_Height, 0xEEEEEE)
        Local $hOld = _WinAPI_SelectObject($MemDC, $hHBITMAP)
        Local $hBrush = _WinAPI_CreateSolidBrush($color)
        _WinAPI_FillRect($MemDC, $ptr, $hBrush)
        Local $dX = $m_Width - 41
        _WinAPI_DrawLine($MemDC, $dX, 9, $dX + 12, 9)
        _WinAPI_DrawLine($MemDC, $dX, 10, $dX + 12, 10)
        _WinAPI_DrawLine($MemDC, $dX, 11, $dX, 19)
        _WinAPI_DrawLine($MemDC, $dX + 11, 11, $dX + 11, 19)
        _WinAPI_DrawLine($MemDC, $dX, 19, $dX + 12, 19)
        _WinAPI_TransparentBlt($pDC, 0, 0, $m_Width, $m_Height, $MemDC, 0, 0, $m_Width, $m_Height, 0xEEEEEE)
        _WinAPI_SelectObject($MemDC, $hOld)
        _WinAPI_DeleteDC($MemDC)
EndFunc   ;==>DrawMaxButton

Func DrawCloseButton($pDC, $ptr, $color)
        Local $MemDC = _WinAPI_CreateCompatibleDC($pDC)
        Local $hHBITMAP = _WinAPI_CreateCompatibleBitmapEx($pDC, $m_Width, $m_Height, 0xEEEEEE)
        Local $hOld = _WinAPI_SelectObject($MemDC, $hHBITMAP)
        Local $hBrush = _WinAPI_CreateSolidBrush($color)
        _WinAPI_FillRect($MemDC, $ptr, $hBrush)
        Local $dX = $m_Width - 21
        For $N = 0 To 10
                _WinAPI_DrawLine($MemDC, $dX, 9 + $N, $dX + 3, 9 + $N)
                _WinAPI_DrawLine($MemDC, $dX, 19 - $N, $dX + 3, 19 - $N)
                $dX += 1
        Next
        _WinAPI_TransparentBlt($pDC, 0, 0, $m_Width, $m_Height, $MemDC, 0, 0, $m_Width, $m_Height, 0xEEEEEE)
        _WinAPI_SelectObject($MemDC, $hOld)
        _WinAPI_DeleteDC($MemDC)
EndFunc   ;==>DrawCloseButton

Func WM_NCHITTEST($hWnd, $Msg, $wParam, $lParam)
        Local $Mpos = DllStructCreate($tagPOINT)
        DllStructSetData($Mpos, 1, BitAND($lParam, 0xFFFF) + $m_Left)
        DllStructSetData($Mpos, 2, BitShift($lParam, 16) + $m_Top)
;~      DllStructSetData($Mpos, 1, BitAND($lParam, 0xFFFF))
;~      DllStructSetData($Mpos, 2, BitShift($lParam, 16))
;~      _WinAPI_ScreenToClient($hWnd, $Mpos)
        If _WinAPI_PtInRect($rcMIN, $Mpos) Then
                Return $HTMINBUTTON
        ElseIf _WinAPI_PtInRect($rcMAX, $Mpos) Then
                Return $HTMAXBUTTON
        ElseIf _WinAPI_PtInRect($rcCLOSE, $Mpos) Then
                Return $HTCLOSE
        ElseIf _WinAPI_PtInRect($rcICON, $Mpos) Then
                Return $HTSYSMENU
        ElseIf _WinAPI_PtInRect($rcCAPTION, $Mpos) Then
                Return $HTCAPTION
        ElseIf _WinAPI_PtInRect($rcLBD, $Mpos) Then
                Return $HTLEFT
        ElseIf _WinAPI_PtInRect($rcRBD, $Mpos) Then
                Return $HTRIGHT
        ElseIf _WinAPI_PtInRect($rcTBD, $Mpos) Then
                Return $HTTOP
        ElseIf _WinAPI_PtInRect($rcBBD, $Mpos) Then
                Return $HTBOTTOM
        ElseIf _WinAPI_PtInRect($rcTL, $Mpos) Then
                Return $HTTOPLEFT
        ElseIf _WinAPI_PtInRect($rcTR, $Mpos) Then
                Return $HTTOPRIGHT
        ElseIf _WinAPI_PtInRect($rcBL, $Mpos) Then
                Return $HTBOTTOMLEFT
        ElseIf _WinAPI_PtInRect($rcBR, $Mpos) Then
                Return $HTBOTTOMRIGHT
        ElseIf _WinAPI_PtInRect($rcCLIENT, $Mpos) Then
                Return $HTCLIENT
        EndIf
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NCHITTEST

Func WM_NCLBUTTONUP($hWnd, $Msg, $wParam, $lParam)
        Switch $wParam
                Case $HTCLOSE
                        $hDC = _WinAPI_GetWindowDC($hWnd)
                        DrawCloseButton($hDC, DllStructGetPtr($rcCLOSE), 0x59B9F7)
                        _WinAPI_ReleaseDC($hWnd, $hDC)
                        _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_CLOSE, $lParam)
                Case $HTMINBUTTON
                        $hDC = _WinAPI_GetWindowDC($hWnd)
                        DrawMinButton($hDC, DllStructGetPtr($rcMIN), 0xFF0000)
                        _WinAPI_ReleaseDC($hWnd, $hDC)
                        If _WinAPI_IsIconic($hWnd) Then
                                _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_RESTORE, $lParam)
                        Else
                                _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_MINIMIZE, $lParam)
                        EndIf
                Case $HTMAXBUTTON
                        $hDC = _WinAPI_GetWindowDC($hWnd)
                        DrawMaxButton($hDC, DllStructGetPtr($rcMAX), 0x0983E7)
                        _WinAPI_ReleaseDC($hWnd, $hDC)
                        If _WinAPI_IsZoomed($hWnd) Then
                                _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_RESTORE, $lParam)
                        Else
                                _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_MAXIMIZE, $lParam)
                        EndIf
        EndSwitch
        Return 0;表示自己处理完成,不让系统处理
EndFunc   ;==>WM_NCLBUTTONUP

Func WM_NCLBUTTONDOWN($hWnd, $Msg, $wParam, $lParam)
        Switch $wParam
                Case $HTMINBUTTON
                        $hDC = _WinAPI_GetWindowDC($hWnd)
                        DrawMinButton($hDC, DllStructGetPtr($rcMIN), 0x00FFFF)
                        _WinAPI_ReleaseDC($hWnd, $hDC)
                Case $HTMAXBUTTON
                        $hDC = _WinAPI_GetWindowDC($hWnd)
                        DrawMaxButton($hDC, DllStructGetPtr($rcMAX), 0xAA00FF)
                        _WinAPI_ReleaseDC($hWnd, $hDC)
                Case $HTCLOSE
                        $hDC = _WinAPI_GetWindowDC($hWnd)
                        DrawCloseButton($hDC, DllStructGetPtr($rcCLOSE), 0xFF0000)
                        _WinAPI_ReleaseDC($hWnd, $hDC)
                Case $HTCAPTION
                        Return $GUI_RUNDEFMSG
                Case $HTSYSMENU
                        Return $GUI_RUNDEFMSG
        EndSwitch
        Return 0;表示自己处理完成,不让系统处理
EndFunc   ;==>WM_NCLBUTTONDOWN

Func WM_NCMOUSEMOVE($hWnd, $Msg, $wParam, $lParam)
        _WinAPI_TrackMouseEvent($hWnd, $TME_LEAVE + $TME_HOVER + $TME_NONCLIENT, 10)
        Return 0
EndFunc   ;==>WM_NCMOUSEMOVE

Func WM_NCMOUSEHOVER($hWnd, $Msg, $wParam, $lParam)
        Switch $wParam
                Case $HTMINBUTTON
                        DrawHoverButton($HTMINBUTTON)
                Case $HTMAXBUTTON
                        DrawHoverButton($HTMAXBUTTON)
                Case $HTCLOSE
                        DrawHoverButton($HTCLOSE)
        EndSwitch
        Return 0
EndFunc   ;==>WM_NCMOUSEHOVER

Func WM_NCMOUSELEAVE($hWnd, $Msg, $wParam, $lParam)
        Switch $mHover
                Case $HTMINBUTTON
                        $hDC = _WinAPI_GetWindowDC($hWnd)
                        DrawMinButton($hDC, DllStructGetPtr($rcMIN), 0x384FD1)
                        _WinAPI_ReleaseDC($hWnd, $hDC)
                        $mHover = 0
                Case $HTMAXBUTTON
                        $hDC = _WinAPI_GetWindowDC($hWnd)
                        DrawMaxButton($hDC, DllStructGetPtr($rcMAX), 0x0983E7)
                        _WinAPI_ReleaseDC($hWnd, $hDC)
                        $mHover = 0
                Case $HTCLOSE
                        $hDC = _WinAPI_GetWindowDC($hWnd)
                        DrawCloseButton($hDC, DllStructGetPtr($rcCLOSE), 0x59B9F7)
                        _WinAPI_ReleaseDC($hWnd, $hDC)
                        $mHover = 0
        EndSwitch
        Return 0
EndFunc   ;==>WM_NCMOUSELEAVE

Func WM_NCCALCSIZE($hWnd, $Msg, $wParam, $lParam)
        Local $stDrawItem
        Switch $hWnd
                Case $zhu_gui
                        If $wParam Then
                                $stDrawItem = DllStructCreate("long[4];long[4];long[4];ptr", $lParam)
                                Local $cLeft = DllStructGetData($stDrawItem, 1, 1) + 4
                                Local $cTop = DllStructGetData($stDrawItem, 1, 2) + 30
                                Local $cRight = DllStructGetData($stDrawItem, 1, 3) - 4
                                Local $cBottom = DllStructGetData($stDrawItem, 1, 4) - 4
                                DllStructSetData($stDrawItem, 1, $cLeft, 1)
                                DllStructSetData($stDrawItem, 1, $cTop, 2)
                                DllStructSetData($stDrawItem, 1, $cRight, 3)
                                DllStructSetData($stDrawItem, 1, $cBottom, 4)
                                $m_Left = DllStructGetData($stDrawItem, 2, 1)
                                $m_Top = DllStructGetData($stDrawItem, 2, 2)
                                $m_Width = DllStructGetData($stDrawItem, 2, 3) - $m_Left
                                $m_Height = DllStructGetData($stDrawItem, 2, 4) - $m_Top
                                DllStructSetData($rcCLIENT, 1, 4)
                                DllStructSetData($rcCLIENT, 2, $cTop - $m_Top)
                                DllStructSetData($rcCLIENT, 3, $cRight - $cLeft)
                                DllStructSetData($rcCLIENT, 4, $cBottom - $cTop)
                                UpdateRect()
                                Return $WVR_VALIDRECTS;指修改了客户区大小
                        EndIf
        EndSwitch
EndFunc   ;==>WM_NCCALCSIZE

Func exitfunc()
        Exit
EndFunc   ;==>exitfunc

Func WM_MOVE($hWnd, $Msg, $wParam, $lParam)
        Return 0
EndFunc   ;==>WM_MOVE

Func WM_CREATE($hWnd, $Msg, $wParam, $lParam)
        Local $rgn = _WinAPI_CreateRectRgn(0, 0, 400, 300)
        _WinAPI_SetWindowRgn($hWnd, $rgn, 1)
        _WinAPI_SetWindowPos($hWnd, 0, 0, 0, 400, 300, BitOR($SWP_FRAMECHANGED, $SWP_NOMOVE));强制发送WM_NCCALCSIZE
        _WinAPI_DeleteObject($rgn)
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_CREATE

Func WM_NCACTIVATE($hWnd, $Msg, $wParam, $lParam)
        _SendMessage($hWnd, $WM_NCPAINT, 1)
        Return 1
EndFunc   ;==>WM_NCACTIVATE

Func WM_NCPAINT($hWnd, $Msg, $wParam, $lParam)
        __myDraw($hWnd)
        Return 1
EndFunc   ;==>WM_NCPAINT

Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
        Local $ncWidth = BitAND($lParam, 0xFFFF), $ncHeight = BitShift($lParam, 16)
        DllStructSetData($rcCLIENT, 3, $ncWidth)
        DllStructSetData($rcCLIENT, 4, $ncHeight)
        $m_Width = $ncWidth + 8
        $m_Height = $ncHeight + 34
        Local $rgn = _WinAPI_CreateRectRgn(0, 0, $m_Width, $m_Height)
        _WinAPI_SetWindowRgn($hWnd, $rgn, 1)
        _WinAPI_DeleteObject($rgn)
        Return 1
EndFunc   ;==>WM_SIZE

评分

参与人数 2金钱 +80 贡献 +2 收起 理由
seniors + 50 + 2 为什么刚运行没效果,我的刚运行有效果的
lpxx + 30

查看全部评分

发表于 2013-7-2 14:01:09 | 显示全部楼层
颜色搭配很好看
 楼主| 发表于 2013-7-2 14:34:38 | 显示全部楼层
本帖最后由 Ycxw2008 于 2013-7-2 15:17 编辑

回复 2# seniors


    运行没效果?我没这情况啊。
   你改下WM_NCACTIVATE里面的代码试试。


    还有想问一下,_WinAPI_TransparentBlt的时候会覆盖掉我初始画的 关闭 最小化 最大化 里面的那些Line ,怎么能做到不覆盖呢。
   

大神能不能指点下下面代码中怎么做到最大化 最小化也能有关闭按钮那样的效果(也就是你写的360界面同样的效果)
图片都是你那360界面.rar 里面的


#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <GDIPlusEx.au3>
#include <WinAPIEx.au3>
Opt('GUIOnEventMode', 1)
Global $zhuwidth = 400, $zhuheight = 300, $winround = 10
Global $topbutton[7], $topbuttonimg[7], $topbuttonhoverimg[7], $topbuttondownimg[7], $topbuttontip[7], $onTopbuttonFlag = 0, $onTopbuttonNum = 0, $DownTopbuttonNum = 0

Global $zhu_gui = GUICreate("360界面预览", $zhuwidth, $zhuheight)
GUISetOnEvent($GUI_EVENT_CLOSE, "exitfunc")
_GDIPlus_Startup()
_initRect()
GUIRegisterMsg($WM_LBUTTONDOWN, 'WM_LBUTTONDOWN')
GUIRegisterMsg($WM_LBUTTONUP, 'WM_LBUTTONUP')
GUIRegisterMsg($WM_PAINT, "WM_PAINT")

GUISetState()

While 1
        Sleep(10)
WEnd
Func DrawNormalImage($pDC, $btRect, $file)
        Local $W = DllStructGetData($btRect, 3) - DllStructGetData($btRect, 1)
        Local $H = DllStructGetData($btRect, 4) - DllStructGetData($btRect, 2)
        Local $hCDC = _WinAPI_CreateCompatibleDC($pDC)
        Local $hHBITMAP = _WinAPI_CreateCompatibleBitmapEx($pDC, $W, $H, 0xFFFFFF)
        Local $hOld = _WinAPI_SelectObject($hCDC, $hHBITMAP)
        Local $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hCDC)
        Local $kzImage = _GDIPlus_ImageLoadFromFile($file)
        _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $kzImage, 0, 0, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage), 0, 0, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage))
        _WinAPI_BitBlt($pDC, DllStructGetData($btRect, 1), DllStructGetData($btRect, 2), $W, $H, $hCDC, 0, 0, $SRCCOPY)
        _WinAPI_SelectObject($hCDC, $hOld)
        _WinAPI_DeleteDC($hCDC)
EndFunc   ;==>DrawNormalImage


Func DrawImage($pDC, $btRect, $file)
        Local $hCDC = _WinAPI_CreateCompatibleDC($pDC)
        Local $hHBITMAP = _WinAPI_CreateCompatibleBitmapEx($pDC, $zhuwidth, $zhuheight, 0xEEEEEE)
        Local $hOld = _WinAPI_SelectObject($hCDC, $hHBITMAP)
        Local $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hCDC)
        Local $kzImage = _GDIPlus_ImageLoadFromFile($file)
        _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $kzImage, 0, 0, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage), DllStructGetData($btRect, 1), DllStructGetData($btRect, 2), _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage))
        _WinAPI_TransparentBlt($pDC, 0, 0, $zhuwidth, $zhuheight, $hCDC, 0, 0, $zhuwidth, $zhuheight, 0xEEEEEE)
        _WinAPI_SelectObject($hCDC, $hOld)
        _WinAPI_DeleteDC($hCDC)
EndFunc   ;==>DrawImage

Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
        If $hWnd == $zhu_gui Then
                Local $tPAINTSTRUCT, $hDC
                $hDC = _WinAPI_BeginPaint($hWnd, $tPAINTSTRUCT)
                $rc = _WinAPI_GetClientRect($hWnd)
                Local $hBrush = _WinAPI_CreateSolidBrush(0xFFFFFF)
                _WinAPI_FillRect($hDC, DllStructGetPtr($rc), $hBrush)
                _WinAPI_DeleteObject($hBrush)
;~                 DrawNormalImage($hDC, $topbutton[0], "top\TopPanelBtnClose.png")
;~                 DrawNormalImage($hDC, $topbutton[1], "top\TopPanelBtnMax.png")
;~                 DrawNormalImage($hDC, $topbutton[2], "top\TopPanelBtnMin.png")
                Local $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC);从DC创建图形对象
                Local $kzImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\top\TopPanelBtnClose.png")
                $zhubtnx = $zhuwidth - 2 - _GDIPlus_ImageGetWidth($kzImage)
                _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $kzImage, 0, 0, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage), $zhubtnx, 1, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage))
                $kzImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\top\TopPanelBtnMax.png")
                $zhubtnx -= _GDIPlus_ImageGetWidth($kzImage)
                _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $kzImage, 0, 0, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage), $zhubtnx, 1, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage))
                $kzImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\top\TopPanelBtnMin.png")
                $zhubtnx -= _GDIPlus_ImageGetWidth($kzImage)
                _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $kzImage, 0, 0, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage), $zhubtnx, 1, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage))
                $kzImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\top\TopPanelBtnSetting.png")
                $zhubtnx -= _GDIPlus_ImageGetWidth($kzImage)
                _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $kzImage, 0, 0, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage), $zhubtnx, 1, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage))
                $kzImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\top\TopPanelBtnFeedback.png")
                $zhubtnx -= _GDIPlus_ImageGetWidth($kzImage)
                _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $kzImage, 0, 0, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage), $zhubtnx, 1, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage))
                $kzImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\top\skin.png")
                $zhubtnx -= _GDIPlus_ImageGetWidth($kzImage)
                _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $kzImage, 0, 0, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage), $zhubtnx + 1, 2, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage))
                $kzImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\top\TopPanelBtnSkin.png")
                $zhubtnx = $zhuwidth - 20 - _GDIPlus_ImageGetWidth($kzImage)
                _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $kzImage, 0, 0, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage), $zhubtnx, 30, _GDIPlus_ImageGetWidth($kzImage), _GDIPlus_ImageGetHeight($kzImage))
                _WinAPI_DeleteObject($kzImage)
                _WinAPI_EndPaint($hWnd, $tPAINTSTRUCT)
                Return 0
        EndIf
EndFunc   ;==>WM_PAINT

Func WM_LBUTTONDOWN($hWnd, $Msg, $wParam, $lParam)
        Local $tPoint, $DownTopbuttonFlag, $DownPanBtnFlag
        $tPoint = _WinAPI_GetMousePos(True, $hWnd)
        Switch $hWnd
                Case $zhu_gui
                        $DownTopbuttonFlag = 0
                        ;检测鼠标是否在系统按钮区域,在则置hover标识
                        For $iI = 1 To 7
                                If _WinAPI_PtInRect($topbutton[$iI - 1], $tPoint) Then
                                        $DownTopbuttonFlag = $iI
                                        ExitLoop
                                EndIf
                        Next
                        Switch $DownTopbuttonFlag
                                Case 1 To 7
                                        If $DownTopbuttonNum <> $DownTopbuttonFlag Then
                                                $DownTopbuttonNum = $DownTopbuttonFlag
                                                Local $hDC = _WinAPI_GetDC($hWnd)
                                                DrawImage($hDC, $topbutton[$DownTopbuttonNum - 1], $topbuttondownimg[$DownTopbuttonNum - 1])
                                                _WinAPI_ReleaseDC($hWnd, $hDC)
                                        EndIf
                        EndSwitch
        EndSwitch
EndFunc   ;==>WM_LBUTTONDOWN

Func WM_LBUTTONUP($hWnd, $Msg, $wParam, $lParam)
        Local $tPoint, $DownTopbuttonFlag
        $tPoint = _WinAPI_GetMousePos(True, $hWnd)
        Switch $hWnd
                Case $zhu_gui
                        If $DownTopbuttonNum Then
                                Local $hDC = _WinAPI_GetDC($hWnd)
                                DrawNormalImage($hDC, $topbutton[$DownTopbuttonNum - 1], $topbuttonimg[$DownTopbuttonNum - 1])
                                _WinAPI_ReleaseDC($hWnd, $hDC)
                                $DownTopbuttonNum = 0
                        EndIf
        EndSwitch
EndFunc   ;==>WM_LBUTTONUP


Func exitfunc()
        _GDIPlus_Shutdown()
        Exit
EndFunc   ;==>exitfunc

Func _initRect();初始化系统按钮图标位置,中间大按钮位置等
        Local $kzImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\top\TopPanelBtnClose.png")
        $mybtnx = $zhuwidth - 2 - _GDIPlus_ImageGetWidth($kzImage)
        $topbutton[0] = DllStructCreate($tagRECT)
        DllStructSetData($topbutton[0], 1, $mybtnx)
        DllStructSetData($topbutton[0], 2, 1)
        DllStructSetData($topbutton[0], 3, $mybtnx + _GDIPlus_ImageGetWidth($kzImage))
        DllStructSetData($topbutton[0], 4, _GDIPlus_ImageGetHeight($kzImage) + 1)
        $topbuttonimg[0] = @ScriptDir & "\top\TopPanelBtnClose.png"
        $topbuttonhoverimg[0] = @ScriptDir & "\top\TopPanelCloseOver.png"
        $topbuttondownimg[0] = @ScriptDir & "\top\TopPanelCloseDown.png"
        $topbuttontip[0] = "关闭"
        
        $kzImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\top\TopPanelBtnMax.png")
        $mybtnx -= _GDIPlus_ImageGetWidth($kzImage)
        $topbutton[1] = DllStructCreate($tagRECT)
        DllStructSetData($topbutton[1], 1, $mybtnx + 1)
        DllStructSetData($topbutton[1], 2, 1)
        DllStructSetData($topbutton[1], 3, $mybtnx + _GDIPlus_ImageGetWidth($kzImage))
        DllStructSetData($topbutton[1], 4, _GDIPlus_ImageGetHeight($kzImage) + 1)
        $topbuttonimg[1] = @ScriptDir & "\top\TopPanelBtnMax.png"
        $topbuttonhoverimg[1] = @ScriptDir & "\top\MiddleOver.png"
        $topbuttondownimg[1] = @ScriptDir & "\top\MiddleDown.png"
        $topbuttontip[1] = "最大化"
        
        $kzImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\top\TopPanelBtnMin.png")
        $mybtnx -= _GDIPlus_ImageGetWidth($kzImage)
        $topbutton[2] = DllStructCreate($tagRECT)
        DllStructSetData($topbutton[2], 1, $mybtnx + 1)
        DllStructSetData($topbutton[2], 2, 1)
        DllStructSetData($topbutton[2], 3, $mybtnx + _GDIPlus_ImageGetWidth($kzImage))
        DllStructSetData($topbutton[2], 4, _GDIPlus_ImageGetHeight($kzImage) + 1)
        $topbuttonimg[2] = @ScriptDir & "\top\TopPanelBtnMin.png"
        $topbuttonhoverimg[2] = @ScriptDir & "\top\MiddleOver.png"
        $topbuttondownimg[2] = @ScriptDir & "\top\MiddleDown.png"
        $topbuttontip[2] = "最小化"
        
        $kzImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\top\TopPanelBtnSetting.png")
        $mybtnx -= _GDIPlus_ImageGetWidth($kzImage)
        $topbutton[3] = DllStructCreate($tagRECT)
        DllStructSetData($topbutton[3], 1, $mybtnx + 1)
        DllStructSetData($topbutton[3], 2, 1)
        DllStructSetData($topbutton[3], 3, $mybtnx + _GDIPlus_ImageGetWidth($kzImage))
        DllStructSetData($topbutton[3], 4, _GDIPlus_ImageGetHeight($kzImage) + 1)
        $topbuttonimg[3] = @ScriptDir & "\top\TopPanelBtnSetting.png"
        $topbuttonhoverimg[3] = @ScriptDir & "\top\MiddleOver.png"
        $topbuttondownimg[3] = @ScriptDir & "\top\MiddleDown.png"
        $topbuttontip[3] = "设置"
        
        $kzImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\top\TopPanelBtnFeedback.png")
        $mybtnx -= _GDIPlus_ImageGetWidth($kzImage)
        $topbutton[4] = DllStructCreate($tagRECT)
        DllStructSetData($topbutton[4], 1, $mybtnx)
        DllStructSetData($topbutton[4], 2, 1)
        DllStructSetData($topbutton[4], 3, $mybtnx + _GDIPlus_ImageGetWidth($kzImage))
        DllStructSetData($topbutton[4], 4, _GDIPlus_ImageGetHeight($kzImage) + 1)
        $topbuttonimg[4] = @ScriptDir & "\top\TopPanelBtnFeedback.png"
        $topbuttonhoverimg[4] = @ScriptDir & "\top\over.png"
        $topbuttondownimg[4] = @ScriptDir & "\top\mask.png"
        $topbuttontip[4] = "反馈"
        
        $kzImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\top\skin.png")
        $mybtnx -= _GDIPlus_ImageGetWidth($kzImage)
        $topbutton[5] = DllStructCreate($tagRECT)
        DllStructSetData($topbutton[5], 1, $mybtnx)
        DllStructSetData($topbutton[5], 2, 1)
        DllStructSetData($topbutton[5], 3, $mybtnx + _GDIPlus_ImageGetWidth($kzImage))
        DllStructSetData($topbutton[5], 4, _GDIPlus_ImageGetHeight($kzImage) + 1)
        $topbuttonimg[5] = @ScriptDir & "\top\skin.png"
        $topbuttonhoverimg[5] = @ScriptDir & "\top\over.png"
        $topbuttondownimg[5] = @ScriptDir & "\top\mask.png"
        $topbuttontip[5] = "皮肤"
        
        $kzImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\top\TopPanelBtnSkin.png")
        $mybtnx = $zhuwidth - 20 - _GDIPlus_ImageGetWidth($kzImage)
        $topbutton[6] = DllStructCreate($tagRECT)
        DllStructSetData($topbutton[6], 1, $mybtnx)
        DllStructSetData($topbutton[6], 2, 30)
        DllStructSetData($topbutton[6], 3, $mybtnx + _GDIPlus_ImageGetWidth($kzImage))
        DllStructSetData($topbutton[6], 4, _GDIPlus_ImageGetHeight($kzImage) + 30)
        $topbuttonimg[6] = @ScriptDir & "\top\TopPanelBtnSkin.png"
        $topbuttonhoverimg[6] = @ScriptDir & "\top\over.png"
        $topbuttondownimg[6] = @ScriptDir & "\top\mask.png"
        $topbuttontip[6] = "配色"
        _WinAPI_DeleteObject($kzImage)
EndFunc   ;==>_initRect
发表于 2013-7-2 15:59:44 | 显示全部楼层
现在身边没电脑,也没看懂你的问题.
 楼主| 发表于 2013-7-2 17:10:37 | 显示全部楼层
回复 4# seniors


    用BitBlt 拷贝矩形 会覆盖我之前的矩形

    不过我发现StretchBlt可以解决我的问题
发表于 2013-7-2 19:34:16 | 显示全部楼层
BitBlt是原图
StretchBlt是拉伸
TransparentBlt是可以指定透明颜色
发表于 2013-7-7 19:46:28 | 显示全部楼层
学习一下 啊
发表于 2013-7-7 21:32:31 | 显示全部楼层
发表于 2013-7-8 16:33:34 | 显示全部楼层
我运行了一下,看不到效果。
发表于 2013-7-8 16:33:37 | 显示全部楼层
我运行了一下,看不到效果。
发表于 2013-8-26 12:11:34 | 显示全部楼层
回复 9# szjz2000


    运行后按最大化按钮就看到。
之后不管怎样操作均有效果。
发表于 2013-11-14 17:55:06 | 显示全部楼层
本帖最后由 wszhov 于 2013-11-14 17:56 编辑
"D:\autoit3\UserInclude\GDIPlusEx.au3"(107,151) : error: $tagGDIPCOLORMATRIX 上一次定义为一个 'Const' 变量..
Global Const $tagGDIPCOLORMATRIX = "float m[25];"        ; [5][5] matrix; [0][0] - red, [1][1] - green, [2][2] - blue; [3][3] - alpha, [4][4] - ~should~ be 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"D:\autoit3\UserInclude\GDIPlusEx.au3"(110,33) : error: $GDIP_RLUM 上一次定义为一个 'Const' 变量..
Global Const $GDIP_RLUM = 0.3086
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"D:\autoit3\UserInclude\GDIPlusEx.au3"(111,33) : error: $GDIP_GLUM 上一次定义为一个 'Const' 变量..
Global Const $GDIP_GLUM = 0.6094
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"D:\autoit3\UserInclude\GDIPlusEx.au3"(112,33) : error: $GDIP_BLUM 上一次定义为一个 'Const' 变量..
Global Const $GDIP_BLUM = 0.0820
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"D:\autoit3\UserInclude\GDIPlusEx.au3"(2056,63) : error: _GDIPlus_BitmapCreateFromResource() 已经被定义.
Func _GDIPlus_BitmapCreateFromResource($hInst, $vResourceName)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"D:\autoit3\UserInclude\GDIPlusEx.au3"(2103,110) : error: _GDIPlus_BitmapCreateFromScan0() 已经被定义.
Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"D:\autoit3\UserInclude\GDIPlusEx.au3"(2125,47) : error: _GDIPlus_BitmapCreateFromStream() 已经被定义.
Func _GDIPlus_BitmapCreateFromStream($pStream)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"D:\autoit3\UserInclude\GDIPlusEx.au3"(2171,49) : error: _GDIPlus_BitmapGetPixel() 已经被定义.
Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
- - -- - -
"D:\autoit3\UserInclude\GDIPlusEx.au3"(107,151) : error: $tagGDIPCOLORMATRIX 上一次定义为一个 'Const' 变量..
Global Const $tagGDIPCOLORMATRIX = "float m[25];"
好多提示
这是怎么回事哦?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-22 01:48 , Processed in 0.095936 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表