效果截图:
代码没有判断任务的高度,而是使用了常数,自己修改吧。
#NoTrayIcon
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPIEX.au3>
Const $tagWNDCLASSEX1 = "uint cbSize;uint style;ptr lpfnWndProc;int cbClsExtra;int cbWndExtra;ptr hInstance;ptr hIcon;ptr hCursor;ptr hbrBackground;ptr lpszMenuName;ptr lpszClassName;ptr hIconSm;"
Const $tagMSG1 = "hwnd hWnd;uint message;wparam wParam;lparam lParam;dword time;long x;long y"
Local $hModule = _WinAPI_GetModuleHandle(0)
Local $hWndProc = DllCallbackRegister("_WndProc", "long", "hwnd;long;wparam;lparam")
Local $pWndProc = DllCallbackGetPtr($hWndProc)
; #### register window class ####
; =============================================================
Local $tWndClass = DllStructCreate($tagWNDCLASSEX1)
Local $pWndClass = DllStructGetPtr($tWndClass)
Local $tClassName = DllStructCreate("wchar szClassName[64]")
Local $pClassName = DllStructGetPtr($tClassName)
DllStructSetData($tClassName, "szClassName", "hello")
DllStructSetData($tWndClass, "cbSize", DllStructGetSize($tWndClass))
DllStructSetData($tWndClass, "style", 3) ; CS_HREDRAW or CS_VREDRAW
DllStructSetData($tWndClass, "lpfnWndProc", $pWndProc)
DllStructSetData($tWndClass, "cbClsExtra", 0)
DllStructSetData($tWndClass, "cbWndExtra", 4)
DllStructSetData($tWndClass, "hInstance", $hModule)
DllStructSetData($tWndClass, "hIcon", _LoadIcon(0, 32512)) ; 32512=IDI_APPLICATION
DllStructSetData($tWndClass, "hCursor", _LoadCursor(0, 32512)) ; 32512=IDC_ARROW
DllStructSetData($tWndClass, "hbrBackground", 5)
DllStructSetData($tWndClass, "lpszMenuName", 0)
DllStructSetData($tWndClass, "lpszClassName", $pClassName)
DllStructSetData($tWndClass, "hIconSm", 0)
_RegisterClassEx($pWndClass)
; =============================================================
Const $HWND_CX = 80 ; window width
Const $HWND_CY = 20 ; window height
Local $hWnd = _WinAPI_CreateWindowEx(0, "hello", "", BitOR($WS_POPUP, $WS_VISIBLE), 10, 10, $HWND_CX, $HWND_CY, 0, 0, $hModule, 0)
; #### message loop ####
; =====================================================
Local $tMsg = DllStructCreate($tagMSG1)
Local $pMsg = DllStructGetPtr($tMsg)
While _IsWindow($hWnd)
If _GetMessage($pMsg, 0, 0, 0) < 1 Then
ExitLoop
EndIf
_TranslateMessage($pMsg)
_DispatchMessage($pMsg)
WEnd
DllCallbackFree($hWndProc)
; =====================================================
Func _WndProc($hWnd, $iMsg, $wParam, $lParam)
Switch $iMsg
Case $WM_TIMER
Switch Number($wParam)
Case 1
Local $hShell = _WinAPI_FindWindow("Shell_TrayWnd", "")
Local $aPos1 = ControlGetPos($hShell, "", "TrayNotifyWnd1")
If $aPos1[0] <> _WinAPI_GetWindowLong($hWnd, 0) Then
_WinAPI_SetWindowLong($hWnd, 0, $aPos1[0])
_WinAPI_MoveWindow($hWnd, $aPos1[0] - $HWND_CX, 5, $HWND_CX, $HWND_CY)
Local $aPos2 = ControlGetPos($hShell, "", "ReBarWindow321")
Local $hRebar = ControlGetHandle($hShell, "", "ReBarWindow321")
_WinAPI_MoveWindow($hRebar, $aPos2[0], $aPos2[1], $aPos2[2] - $HWND_CX - 5, $aPos2[3], True)
EndIf
Case 2
Local $iUsage = MemGetStats()
$iUsage = Int($iUsage[0])
If $iUsage <> _WinAPI_GetWindowLong($hWnd, -21) Then ; -21=GWL_USERDATA
_WinAPI_SetWindowLong($hWnd, -21, $iUsage)
_WinAPI_InvalidateRect($hWnd, 0, False)
EndIf
EndSwitch
Case $WM_PAINT
Local $tPaint
Local $hDC = _WinAPI_BeginPaint($hWnd, $tPaint)
Local $aVertex[2][3] = [[0, 0, 0xFFFFFF], [$HWND_CX, Int($HWND_CY / 2), 0xC0C0C0]]
_WinAPI_GradientFill($hDC, $aVertex)
Local $aVertex[2][3] = [[0, Int($HWND_CY / 2), 0xC0C0C0], [$HWND_CX, $HWND_CY, 0xFFFFFF]]
_WinAPI_GradientFill($hDC, $aVertex)
Local $iPercent = _WinAPI_GetWindowLong($hWnd, -21)
Local $iUsage = Int($iPercent * $HWND_CX / 100)
Local $aVertex[2][3] = [[0, 0, 0xFFFFFF], [$iUsage, Int($HWND_CY / 2), 0xFFB206]]
_WinAPI_GradientFill($hDC, $aVertex)
Local $aVertex[2][3] = [[0, Int($HWND_CY / 2), 0xFFB206], [$iUsage, $HWND_CY, 0xFFFFFF]]
_WinAPI_GradientFill($hDC, $aVertex)
Local $iWidth = _WinAPI_GetWindowWidth($hWnd) ; $HWND_CX
Local $iHeight = _WinAPI_GetWindowHeight($hWnd) ; $HWND_CY
Local $tRect = _WinAPI_CreateRect(0, 0, $iWidth, $iHeight)
Local $hBrush = _WinAPI_GetStockObject($NULL_BRUSH)
Local $hPen = _WinAPI_CreatePen(0, 3, 0xC0C0C0)
_WinAPI_SelectObject($hDC, $hPen)
_WinAPI_SelectObject($hDC, $hBrush)
_WinAPI_Rectangle($hDC, $tRect)
_WinAPI_SetBkMode($hDC, $TRANSPARENT)
_WinAPI_DrawText($hDC, $iPercent & "%", $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
_WinAPI_DeleteObject($hPen)
_WinAPI_DeleteObject($hBrush)
Return _WinAPI_EndPaint($hWnd, $tPaint)
Case $WM_CLOSE
Opt("TrayIconHide", 0)
Opt("TrayIconHide", 1)
Case $WM_KEYDOWN
If $wParam = 27 Then ; 27=ESC
_WndProc($hWnd, $WM_CLOSE, 0, 0)
EndIf
Case $WM_CREATE
_WinAPI_SetParent($hWnd, _WinAPI_FindWindow("Shell_TrayWnd", ""))
_SetTimer($hWnd, 1, 100, 0)
_SetTimer($hWnd, 2, 3000, 0)
_WndProc($hWnd, $WM_TIMER, 1, 0)
_WndProc($hWnd, $WM_TIMER, 2, 0)
EndSwitch
Return _DefWindowProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc ;==>_WndProc
|