鸟人 发表于 2013-4-28 13:00:39

任务栏 工具栏?

本帖最后由 鸟人 于 2013-4-28 15:18 编辑


图为 鲁大师 的 任务栏标尺 想写出这样的效果我是用的笨办法。要真正实现上图那样的效果谁有更完美的方法?

#include <GDIpProgress.au3> ;http://www.autoitx.com/thread-12893-1-1.html
Local $green_Images = @ScriptDir & '\' & RanName() & '.tmp'
FileWrite($green_Images, green_jpg())
Local $bg_Images = @ScriptDir & '\' & RanName() & '.tmp'
FileWrite($bg_Images, bg_jpg())
OnAutoItExitRegister('exits')
Local $pos = ControlGetPos("", "", "")
Local $TopForm = GUICreate("", 50, $pos - 5, $pos - 72, @DesktopHeight - $pos - 3, 0x940C0000, BitOR(0x00080000, 0x00000080, 0x80000, 0x20))
DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hWnd", $TopForm, "long", 0, "byte", 255, "long", 0x2) ;鼠标穿透?
Local $sID = _ProgressCreate(0, 0, 50, 30)
_ProgressSetText($sID, "%P%%")
_ProgressSetImages($sID, $green_Images, $bg_Images)
_ProgressSetFont($sID, "", -1, -1, 0x0000FF)
GUISetState()
AdlibRegister('Read_Memory', 1000)
While 1
        Sleep(100)
WEnd
Func exits()
        AdlibUnRegister('Read_Memory')
        _ProgressDelete($sID)
        _Progress_CallBack_Free(1)
        _GDIPlus_Shutdown()
        FileDelete($green_Images)
        FileDelete($bg_Images)
EndFunc   ;==>exits
Func Read_Memory()
        If WinExists($TopForm) Then WinSetOnTop($TopForm, "", 1)
        $pos = ControlGetPos("", "", "")
        If IsArray($pos) Then _
                        WinMove($TopForm, "", $pos - 72, @DesktopHeight - $pos - 3)
        $spos = WinGetPos($TopForm)
        If IsArray($spos) Then _
                        ControlMove($TopForm, "", $sID, 4, $spos / 4)
        Local $mem = MemGetStats()
        If GUICtrlRead($sID) <> $mem & '%' Then _
                        _ProgressSet($sID, $mem)
EndFunc   ;==>Read_Memory

Func RanName()
        Local $i, $sText = ""
        For $i = 1 To Random(5, 10, 1)
                $sText &= Chr(Random(65, 90, 1))
        Next
        Return $sText
EndFunc   ;==>RanName
Func green_jpg()
        Local $FileBin = ""
        $FileBin &= "FFD8FFE000104A46494600010101004800480000FFE100164578696600004D4D002A00000008000000000000FFFE00134372656174656420776974682047494D50FFDB0043000503040404030504040405050506070C08070707070F0B0B090C110F1212"
        $FileBin &= "110F111113161C1713141A1511111821181A1D1D1F1F1F13172224221E241C1E1F1EFFDB0043010505050706070E08080E1E1411141E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E"
        $FileBin &= "1E1E1EFFC00011080019012C03012200021101031101FFC4001C0000010501010100000000000000000000040001020607050308FFC4003F10000102040205080607090000000000000001030204050652A1111531429212162132415391931314435181"
        $FileBin &= "A2072233367274B2253554556165717382FFC4001B01000301010101010000000000000000000102030004050607FFC40030110001020305060504030000000000000001000203A1E1040506165211154142519114314353611213E2F0213281FFDA000C"
        $FileBin &= "03010002110311003F00DAA4AE5B7E06A0F5F7E9914C2C28AE2BCEC1CA55D1D3A74F4E90D82E3B523EABB47F838D980DC8BFB51EFC446462D87C7BEF07B091B38AFCBAD188A3C17B9A07913C7E57D0A95EB61763B49F31B2495CB73B1DA5F98D98535105"
        $FileBin &= "B5190379BFA2E5CD368D216DA95AB7FB1EA77990124ACD0BB1E90F3203196E3096E306F171E0986258C7942D7D2B1455D8F48F9900E954A3AFB592E380CA1A8BFA863316C08B738F05765FF19DCA1699AC290BBD26BFF508FEB9475FE0FC6133E6942605"
        $FileBin &= "185B1DD17436F98A782BC7AC521776497846F4D475DC92F90A7C04D368DE2DEAA2F68BD15B55CA376B525E100DCBA2F7523E101555D8454DE31E8EF68CAD6AE50FB5990F0806F4B414F654FF00080A8B878C66F1AF4A6F98C15CD662809B5BA77C84566A"
        $FileBin &= "DE4DB0537E428AE823ABEF01B7C40A2EBF638E135A22CEDB889D30D33C5B23AC2DAF752FC5B333757A01E3885DE31070507624B40E135A9EB2B67FB5F13636B3B613F95713664D1C4784710379C4E8A27145A0709AD835ADAFEFA4F13636B7B593B691C6"
        $FileBin &= "D98DC511E51440DEB13A4D4CE2BB48E51DCADA75CDAB8A91C6D8DAEAD44DEA3F1B66251290894DBDA274487175A4728EE56E1AEED3C547E3685AF2D3C546E368C31548AA9B7BC5E88670B5691DCADD75EDA58A8DC6D0B5F5A58A8BC6D184AA91536F88BD"
        $FileBin &= "10CE36AD23B95BC6BFB4715178DA16BFB4715178DA306518DBE62F443395AF48EE56F5AFED1C545E3685CE0B47DF45E368C1446DF317A2D9CAD7A4772B7AE705A3A3AD44E36884571DA10ED8A87E63460EA0B31B1466DF114F04ECC616A27FA8EE56F6ED"
        $FileBin &= "D367226847287A7FDAD1C7A8DC89E9A1D513B0B72CB0EC9671391A74AE9EAF469D8612E7DA17AB5BF74C1F894F4EEEB6BE3DA003D0AFA5B82FA8D6EB6063C6C1B0AE3D669D35355172269B8BEB2E9D9B0329F6D4E2C09144BA3E05BAAFF7A6ABF9B73F52"
        $FileBin &= "874BF510775C41C492FF003F8AAAC5C1AC88F73DD17CC93E555556ADB9A4DFC825BB76653DA645AA0096899B85A39E5551382208F52555546EDF98C791EEDD066137F22E52FB03D9D84CDCCC1CD2AA5C9F05BEA4AAA8CDD0A6137F20B6A8AFA6FE45DA11"
        $FileBin &= "44017534737EF74EDC2F09BCF2AAAA35477937F2088292EA6F64771DD8A02FED52ADBA5A79BF7BAE9661B87AE555E10D29DD1D6C8F44A5BB8B2057815CED2C2E769E695574B70DC3D72AAEAEAB7316432D29DC591C6888A8FB95BAA554F96A1EB95575E2"
        $FileBin &= "A53ABBD91E51D25DC591CC5181B91BAA554870C433CF2AA31CA3BD8B205768AF2EFE4454E6D4760A6E369E69554DD84E11E795516ED0DFD1D7C81E3A0CC63C8AC4CFDB44790BB859AE5550383611F52555668A81318F23C63B7A6177F22BE2065F66B955"
        $FileBin &= "4CE09827D495576E2B76671E4422B72671E471C40CBCCD72AA4381A09F56555D45B6E671E4456DA99C791CD1032F335CAA94E0483EECAABA3CD999C790CB6CCCE3C8E788D9759AE554321C0F765547F366671E437366671E4022065D66B9550C8503DD97"
        $FileBin &= "E48E5B6267BCC86E6C4CF7990108D9759AE555B2140F765F92379B133DE642E6C4CF7990108D9759AE555B2140F765F92316D899C79024D5B13690AF262D3F018411879A39E5544603823D59557066E8B38D3BF59B8B47F82CF4385D96A740DC4D44AAAA"
        $FileBin &= "ABB1418D7FE87BEEA39F9B8FF4C275D8EE9F0D17EE7D7B7FCAAF56E9C322EEB47DE113EAFE08D9B3679FCED2BFFFD9"
        Return Binary("0x" & $FileBin)
EndFunc   ;==>green_jpg
Func bg_jpg()
        Local $FileBin = ""
        $FileBin &= "FFD8FFE000104A46494600010101004800480000FFE100164578696600004D4D002A00000008000000000000FFFE00134372656174656420776974682047494D50FFDB0043000503040404030504040405050506070C08070707070F0B0B090C110F1212"
        $FileBin &= "110F111113161C1713141A1511111821181A1D1D1F1F1F13172224221E241C1E1F1EFFDB0043010505050706070E08080E1E1411141E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E"
        $FileBin &= "1E1E1EFFC00011080019012C03012200021101031101FFC4001A000101010100030000000000000000000000060705030408FFC4003110000101080200030606030000000000000005010203041355929315530611121421323336B20722233173743471"
        $FileBin &= "C2FFC40014010100000000000000000000000000000000FFC40014110100000000000000000000000000000000FFDA000C03010002110311003F00FA2D2E751A227CABD3523251A61F82E3D12245718F3CF3CD758D6B5AD69EE5640B5276A748B91F932F"
        $FileBin &= "FC10BEC61D167EC051D640B5276A745640B5276A749D00515640B5276A745640B5276A749D00515640B5276A745640B5276A749D00515640B5276A745640B5276A749D00515640B5276A745640B5276A749D00515640B5276A745640B5276A749D005156"
        $FileBin &= "40B5276A745640B5276A749D00515640B5276A745640B5276A749D00515640B5276A745640B5276A749D00515640B5276A745640B5276A749D00515640B5276A745640B5276A749D00515640B5276A745640B5276A749D00515640B5276A745640B5276A"
        $FileBin &= "749D00515640B5276A745640B5276A749D00515640B5276A745640B5276A749D00515640B5276A745640B5276A749D00515640B5276A745640B5276A749D00503F3080EB3DE949BA9D24BC5EB5EC8A309C4A89EC901F82C79B0E03DE977D5EA798D6F933"
        $FileBin &= "FD30F3CD7C24B789FF00C996FE0FFB7C0A448948F1E4A562B90A235D7A043F7B1D6B59F030EB313A67C99FA3131699478C7EAB54FEDC4FB9A7240DBB8E99E9898B471D33D313169888036EE3A67A6262D1C74CF4C4C5A62200DBB8E99E9898B471D33D31"
        $FileBin &= "3169888036EE3A67A6262D1C74CF4C4C5A62200DBB8E99E9898B471D33D313169888036EE3A67A6262D1C74CF4C4C5A62200DBB8E99E9898B471D33D313169888036EE3A67A6262D1C74CF4C4C5A62200DBB8E99E9898B471D33D313169888036EE3A67A"
        $FileBin &= "6262D1C74CF4C4C5A62200DBB8E99E9898B471D33D313169888036EE3A67A6262D1C74CF4C4C5A62200DBB8E99E9898B471D33D313169888036EE3A67A6262D1C74CF4C4C5A62200DBB8E99E9898B471D33D313169888036EE3A67A6262D1C74CF4C4C5A"
        $FileBin &= "62200DBB8E99E9898B471D33D31316988803679A4F9AF4FC9898B48AF18D480A10213613FEA76033CD9E96F9B3F3BC469AFF00E0F7D2913FB6FF00DAE81FFFD9"
        Return Binary("0x" & $FileBin)
EndFunc   ;==>bg_jpg


GDIpProgress.au3

pusofalse 发表于 2013-4-28 15:01:16

楼主兄你在帖子中点名指姓,那些真正会的人看到以后都跑了,如果你想让自己的问题得以快速解决,就把吹捧某些人的话给删了吧。

鸟人 发表于 2013-4-28 15:28:30

我没有吹捧某些人的意思,我只是觉得他能帮我解决问题,也没看低其他人的意思。
如果那样让某些人心里不爽了我在这里向某些人道歉!

pusofalse 发表于 2013-4-28 18:00:36

效果截图:


代码没有判断任务的高度,而是使用了常数,自己修改吧。
#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")
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 <> _WinAPI_GetWindowLong($hWnd, 0) Then
                                _WinAPI_SetWindowLong($hWnd, 0, $aPos1)
                                _WinAPI_MoveWindow($hWnd, $aPos1 - $HWND_CX, 5, $HWND_CX, $HWND_CY)

                                Local $aPos2 = ControlGetPos($hShell, "", "ReBarWindow321")
                                Local $hRebar = ControlGetHandle($hShell, "", "ReBarWindow321")

                                _WinAPI_MoveWindow($hRebar, $aPos2, $aPos2, $aPos2 - $HWND_CX - 5, $aPos2, True)

                        EndIf
                Case 2
                        Local $iUsage = MemGetStats()
                        $iUsage = Int($iUsage)
                       
                        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 = [, [$HWND_CX, Int($HWND_CY / 2), 0xC0C0C0]]               
                _WinAPI_GradientFill($hDC, $aVertex)
                Local $aVertex = [, [$HWND_CX, $HWND_CY, 0xFFFFFF]]
                _WinAPI_GradientFill($hDC, $aVertex)

                Local $iPercent = _WinAPI_GetWindowLong($hWnd, -21)
               
                Local $iUsage = Int($iPercent * $HWND_CX / 100)

                Local $aVertex = [, [$iUsage, Int($HWND_CY / 2), 0xFFB206]]
                _WinAPI_GradientFill($hDC, $aVertex)
                Local $aVertex = [, [$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

鸟人 发表于 2013-4-28 21:10:25

直接在 SciTE编辑器 中按F5 它跳到上面去了。


把任务栏拉高一点就这样了。

seniors 发表于 2013-4-30 09:36:49

回复 4# pusofalse
学习了,在winapi中一直没找到_TranslateMessage($pMsg)
_DispatchMessage($pMsg)学到了利用GWL_USERDATA传递数据,不要用全局变量,爽
不知道传多一点数据怎么处理

dncsk 发表于 2013-4-30 12:32:07

楼主的应该是系统托盘 而非任务栏吧。。。

pusofalse 发表于 2013-4-30 15:04:46

回复 6# seniors


    将数据放在一个缓冲区结构中,例如:Const $tagOBJECT_STRUCT = "hwnd hWnd;hwnd hBitmap;dword dwItemCount;ptr lpUserData;ptr lParam"

Local $pObject = _MemGlobalAlloc(4 * 5) ; 4=sizeof(DWORD), 5=数据结构中的字段数量。
Local $tObject = DllStructCreate($tagOBJECT_STRUCT, $pObject)

DllStructSetData($tObject, "hWnd", $hWnd) ; 窗口句柄。
DllStructSetData($tObject, "hBitmap", $hBitmap) ; 位图句柄。
DllStructSetData($tObject, "dwItemCount", 0) ; 项目数量。
DllStructSetData($tObject, "lpUserData", 0) ; 用户自定义数据。
DllStructSetData($tObject, "lParam", 0x12345678) ; 其他数据。

_WinAPI_SetWindowLong($hWnd, $GWL_USERDATA, $pObject)获取数据时,代码如下:
Local $pObject = _WinAPI_GetWindowLong($hWnd, $GWL_USERDATA)
Local $tObject = DllStructCreate($tagOBJECT_STRUCT, $pObject)

Local $hBitmap = DllStructGetData($tObject, "hBitmap") ; 位图句柄。
Local $pUserData = DllStructGetData($tObject, "lpUserData") ; 用户数据。
; ...或者,调用User32.dll中的SetProp、GetProp,设置、获取 与窗口关联在一起的自定义属性。_SetProp($hWnd, "hBitmap", $hBitmap) ; 位图句柄。
_SetProp($hWnd, "dwItemCount", 0) ; 项目数量。
_SetProp($hWnd, "lpUserData", 0) ; 用户数据。

Local $hBitmap = _GetProp($hWnd, "hBitmap") ;获取与窗口相关联的位图。
Local $iItemCount = _GetProp($hWnd, "dwItemCount") ; 获取窗口中的子项数量。
Local $pUserData = _GetProp($hWnd, "lpUserData") ; 获取用户自定义数据。
; ...

Func _GetProp($hWnd, $sProperty)
        Local $iResult = DllCall("User32.dll", "long", "GetPropW", "hwnd", $hWnd, "wstr", $sProperty)

        Return $iResult
EndFunc        ;==>_GetProp

Func _SetProp($hWnd, $sProperty, $vData)
        Local $iResult = DllCall("User32.dll", "bool", "SetPropW", "hwnd", $hWnd, "wstr", $sProperty, "long", $vData)

        Return $iResult
EndFunc        ;==>_SetProp再者,在注册窗口的类时,设置WNDCLASSEX结构中的cbWndExtra字段为sizeof(DWORD),之后就可以用_WinAPI_SetWindowLong($hWnd, 0, ...)这一语句来设置窗口的自定义数据,获取这个数据时,使用_WinAPI_GetWindowLong($hWnd, 0),4#的代码中也有这个运用的示例。

不管哪种方法,其中的“自定义数据”只能是一个32位数,而不能是字符串。如果是字符串,那么可以将它放在一个缓冲区之中,之后关联字符串到窗口时,传递字符串缓冲区的指针即可,指针亦是一个32位数。

seniors 发表于 2013-4-30 15:20:46

回复 8# pusofalse
谢谢P大版,知道了
感觉把数据放在结构中,传一个指针,在我的头脑里比较清晰能理解

tutou9997 发表于 2013-5-1 00:17:00

这个太好了...标记
页: [1]
查看完整版本: 任务栏 工具栏?