Advertisement
AZJIO

Toolbar

May 30th, 2012
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 5.97 KB | None | 0 0
  1. #include <GuiToolbar.au3>
  2. #include <GuiImageList.au3>
  3. #include <GuiConstantsEx.au3>
  4. #include <WindowsConstants.au3>
  5. #include <GDIPlus.au3>
  6.  
  7. Global $iItem
  8. Global $hGUI, $hToolbar, $hNormal, $hDisabled, $hHot
  9. Global Enum $but1 = 1000, $but2, $but3, $but4
  10.  
  11. ; Создание GUI
  12. $hGUI = GUICreate("Toolbar", 400, 300)
  13. $hToolbar = _GUICtrlToolbar_Create($hGUI)
  14. GUISetState()
  15. GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
  16.  
  17. $CloseBMP = _ImgProcess(Binary("0x89504E470D0A1A0A0000000D49484452000000100000000F0806000000ED734F2F000000097048597300000B1300000B1301009A9C180000008049444154785E9D93610A80200C85F7C2837934BBD93CD98B09239865CD0F4A067BDFDC0F41B981086501AD255024403E3B00589A517248029243B22D0030AD5A12D383C86FB0CFBE80E4F8FD5AA1F72E6F686BFC75835A6BAC732BA8AA87ECB43A0812120F67051EB6732D00E0DF1436A2A47C3C167AC88935286BCED6962D1714C53BA791E5B88A0000000049454E44AE426082"))
  18.  
  19. $CloseBMP2 = _ImgProcess(Binary("0x89504E470D0A1A0A0000000D49484452000000100000000F0806000000ED734F2F0000006F4944415478DA63644005FF19F003464202FF8100BB4E4646AC7A48320024073588912C03B0B99E6803B0183680062019C448D8802A1F9C0634B29B12E102A0018CED5B19FE577A236C86F28936005913B2612419806C08C95E20C90568A6911C0698CE2131163040434303DE840100CC5460089F51B34E0000000049454E44AE426082"))
  20.  
  21. ; Список иконок для нормальных кнопок
  22. $hNormal = _GUIImageList_Create(16,16, 5)
  23. _GUIImageList_AddIcon($hNormal, 'shell32.dll', 3)
  24. _GUIImageList_AddIcon($hNormal, 'regedit.exe', 0)
  25. _GUIImageList_AddIcon($hNormal, 'notepad.exe', 0)
  26. _GUIImageList_Add($hNormal, $CloseBMP)
  27. _GUICtrlToolbar_SetImageList($hToolbar, $hNormal)
  28.  
  29. ; Список иконок для отключенных кнопок
  30. $hDisabled = _GUIImageList_Create(16,16, 5)
  31. _GUIImageList_AddIcon($hDisabled, 'shell32.dll', 7)
  32. _GUIImageList_AddIcon($hDisabled, 'shell32.dll', 8)
  33. _GUIImageList_AddIcon($hDisabled, 'shell32.dll', 12)
  34. _GUIImageList_Add($hDisabled, $CloseBMP2)
  35. _GUICtrlToolbar_SetDisabledImageList($hToolbar, $hDisabled)
  36.  
  37. ; Список иконок для состояния наведения на кнопку
  38. $hHot = _GUIImageList_Create(16,16, 5)
  39. _GUIImageList_AddIcon($hHot, 'shell32.dll', 4)
  40. _GUIImageList_AddIcon($hHot, 'shell32.dll', 12)
  41. _GUIImageList_AddIcon($hHot, 'shell32.dll', 3)
  42. _GUIImageList_Add($hHot, $CloseBMP2)
  43. _GUICtrlToolbar_SetHotImageList($hToolbar, $hHot)
  44.  
  45. ; Добавление кнопок
  46. _GUICtrlToolbar_AddButton($hToolbar, $but1, 0)
  47. _GUICtrlToolbar_AddButton($hToolbar, $but2, 1)
  48. _GUICtrlToolbar_AddButton($hToolbar, $but3, 2)
  49. _GUICtrlToolbar_AddButton($hToolbar, $but4, 3)
  50.  
  51. ; Disable Blue button
  52. ; _GUICtrlToolbar_EnableButton($hToolbar, $idBlue, False)
  53.  
  54. Do
  55. Until GUIGetMsg() = $GUI_EVENT_CLOSE
  56.  
  57. Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
  58.     #forceref $hWndGUI, $MsgID, $wParam
  59.     Local $tNMHDR, $event, $hwndFrom, $code, $i_idNew, $dwFlags, $lResult, $idFrom, $i_idOld
  60.     Local $tNMTOOLBAR, $tNMTBHOTITEM
  61.     $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
  62.     $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom")
  63.     $idFrom = DllStructGetData($tNMHDR, "IDFrom")
  64.     $code = DllStructGetData($tNMHDR, "Code")
  65.     Switch $hwndFrom
  66.         Case $hToolbar
  67.             Switch $code
  68.                 Case $NM_LDOWN
  69.                     $a = _GUICtrlToolbar_CommandToIndex ($hToolbar, $iItem)
  70.                     Switch $iItem
  71.                         Case $but1
  72.                             Run('Explorer.exe')
  73.                         Case $but2
  74.                             Run('regedit.exe')
  75.                         Case $but3
  76.                             Run('notepad.exe')
  77.                         Case $but4
  78.                             Exit
  79.                     EndSwitch
  80.                 Case $TBN_HOTITEMCHANGE
  81.                     $tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
  82.                     $i_idOld = DllStructGetData($tNMTBHOTITEM, "idOld")
  83.                     $i_idNew = DllStructGetData($tNMTBHOTITEM, "idNew")
  84.                     $iItem = $i_idNew
  85.                     $dwFlags = DllStructGetData($tNMTBHOTITEM, "dwFlags")
  86.                     If BitAND($dwFlags, $HICF_LEAVING) = $HICF_LEAVING Then
  87.                                 ; SoundPlay(@WindowsDir & "\media\start.wav")
  88.                     Else
  89.                         Switch $i_idNew
  90.                             Case $but1, $but2, $but3, $but4
  91.                                 SoundPlay(@WindowsDir & "\media\start.wav")
  92.                         EndSwitch
  93.                     EndIf
  94.             EndSwitch
  95.     EndSwitch
  96.     Return $GUI_RUNDEFMSG
  97. EndFunc   ;==>_WM_NOTIFY
  98.  
  99. Func _ImgProcess(Const $bBinary);Merged code by Progandy and Zedna
  100.     Local $iLen = BinaryLen($bBinary)
  101.     If $iLen = 0 Then Return SetError(2, 0, 0)
  102.     Local $hMem = _MemGlobalAlloc($iLen, $GMEM_MOVEABLE)
  103.     If @error Or Not $hMem Then Return SetError(3, 0, 0)
  104.     DllStructSetData(DllStructCreate("byte[" & $iLen & "]", _MemGlobalLock($hMem)), 1, $bBinary)
  105.     If @error Then
  106.         _MemGlobalUnlock($hMem)
  107.         _MemGlobalFree($hMem)
  108.         Return SetError(4, 0, 0)
  109.     EndIf
  110.     _MemGlobalUnlock($hMem)
  111.     _GDIPlus_Startup()
  112.     Local $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $hMem, "bool", True, "ptr*", 0)
  113.     If @error Or $aResult[0] <> 0 Or $aResult[3] = 0 Then Return SetError(5, @error, 0)
  114.     Local $hImage = DllCall($ghGDIPDll, "uint", "GdipLoadImageFromStream", "ptr", $aResult[3], "int*", 0)
  115.     Local $error = @error
  116.     Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr")
  117.     DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $aResult[3], "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT))
  118.     If @error Then Return SetError(6, $error, 0)
  119.     If $hImage[2] = 0 Then Return SetError(7, 0, $hImage[2])
  120.     Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage[2])
  121.     _GDIPlus_ImageDispose($hImage[2])
  122.     _GDIPlus_Shutdown()
  123.     Return SetError(0, 0, $hBitmap)
  124. EndFunc   ;==>_ImgProcess
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement