本帖最后由 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
|