Advertisement
AZJIO

Drop-down list

May 30th, 2014
948
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 10.81 KB | None | 0 0
  1. #include <GUIConstantsEx.au3>
  2. #include <GuiMenu.au3>
  3. #include <WindowsConstants.au3>
  4. #include <StaticConstants.au3>
  5. #include <ButtonConstants.au3>
  6. #include <GuiButton.au3>
  7. #include <GuiImageList.au3>
  8.  
  9. #include <FontConstants.au3>
  10. #include <Array.au3>
  11.  
  12. $sp = '|'
  13. Opt("GUIDataSeparatorChar", $sp)
  14. Local $i_ID_Boot_Item[1], $a_List, $i_ID_Src_Item[1], $aDrive
  15.  
  16. $hGUI = GUICreate("Test WinSetup", 576, 473)
  17. If Not @Compiled Then GUISetIcon("shell32.dll", -42)
  18. $iBtnSource = GUICtrlCreateButton('Dummy', 0, 0, 570, 23)
  19.  
  20. $hImgSrc = _GUIImageList_Create(32, 32, 5, 3, 6)
  21. ; _GUIImageList_AddIcon($hImgSrc, "shell32.dll", -42, True)
  22. _GUIImageList_AddIcon($hImgSrc, "shell32.dll", 235, True)
  23. $hImgDisk = _GUIImageList_Create(32, 32, 5, 3, 6)
  24. ; _GUIImageList_AddIcon($hImgDisk, "shell32.dll", -9, True)
  25. _GUIImageList_AddIcon($hImgDisk, "shell32.dll", 234, True)
  26.  
  27. GUICtrlCreateGroup('Select location of Windows installation files', 10, 33, 550, 90)
  28. GUICtrlSetFont(-1, 11, 400)
  29. $iBtnSource = GUICtrlCreateButton('Select...', 20, 58, 90, 40)
  30. _GUICtrlButton_SetImageList(-1, $hImgSrc)
  31. $iLbSource = GUICtrlCreateInput('', 120, 65, 430, 22)
  32. $iDummySrc = GUICtrlCreateDummy()
  33.  
  34. GUICtrlCreateGroup('Select location of the Boot drive', 10, 128, 550, 90)
  35. GUICtrlSetFont(-1, 11, 400)
  36. $iBtnDisk = GUICtrlCreateButton('Select', 20, 158, 90, 40)
  37. _GUICtrlButton_SetImageList(-1, $hImgDisk)
  38. $iLbDisk = GUICtrlCreateLabel(' Disk: none', 120, 165, 330, 26, $SS_CENTERIMAGE + $SS_LEFTNOWORDWRAP)
  39. ; GUICtrlSetBkColor(-1, 0xF0F0F0)
  40. ; $iLbDiskBig = GUICtrlCreateInput('', 120, 143, 40, 26)
  41. GUICtrlSetFont(-1, 10, 400)
  42. ; GUICtrlSetBkColor(-1, 0xfdffae)
  43.  
  44. GUICtrlCreateLabel('MBR', 450, 140, 80, 17, $SS_RIGHT)
  45. GUICtrlCreateLabel('BOOTMGR PBR', 450, 160, 80, 17, $SS_RIGHT)
  46. GUICtrlCreateLabel('BOOT PART', 450, 180, 80, 17, $SS_RIGHT)
  47. $icon1 = GUICtrlCreateIcon("shell32.dll", -145, 534, 140, 16, 16)
  48. $icon2 = GUICtrlCreateIcon("shell32.dll", -145, 534, 160, 16, 16)
  49. $icon3 = GUICtrlCreateIcon("shell32.dll", -145, 534, 180, 16, 16)
  50. $iBtnFrm = GUICtrlCreateButton('Formatting', 250, 192, 90, 22)
  51. GUICtrlSetState(-1, $GUI_DISABLE)
  52.  
  53. GUICtrlCreateGroup('Select location of the Installation drive', 10, 228, 550, 90)
  54. GUICtrlSetFont(-1, 11, 400)
  55. $iBtnDisk2 = GUICtrlCreateButton('Select', 20, 258, 90, 40)
  56. _GUICtrlButton_SetImageList(-1, $hImgDisk)
  57. $iLbDisk2 = GUICtrlCreateLabel(' 0:3  E: Fixed WinXP_50/1000    NTFS     50.294 Gb', 120, 265, 330, 26, $WS_BORDER + $SS_CENTERIMAGE + $SS_LEFTNOWORDWRAP)
  58. GUICtrlSetBkColor(-1, 0xFFFFCE)
  59. ; $iLbDiskBig2 = GUICtrlCreateInput('', 120, 243, 40, 22)
  60. GUICtrlSetFont(-1, 11, 400)
  61. ; GUICtrlSetBkColor(-1, 0xfdffae)
  62.  
  63. $iBtnFrm = GUICtrlCreateButton('Formatting', 250, 292, 90, 22)
  64.  
  65. GUICtrlCreateGroup('Options', 10, 323, 550, 100)
  66. GUICtrlCreateGroup('', 10, 423, 550, 40)
  67.  
  68. GUISetState()
  69. GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
  70.  
  71. While 1
  72.     Switch GUIGetMsg()
  73.         Case $iDummySrc
  74.             $sPath = FileOpenDialog('Choose...', "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "image (*.wim)", 1 + 4, 'install.wim', $hGUI)
  75.             If Not @error Then GUICtrlSetData($iLbSource, $sPath)
  76.         Case $iBtnDisk
  77.             _CreateMenuDisk()
  78.         Case $iBtnSource
  79.             $tmp = _CreateMenuSource()
  80.             If @extended Then GUICtrlSetData($iLbSource, $tmp)
  81.         Case $GUI_EVENT_CLOSE
  82.             Exit
  83.     EndSwitch
  84. WEnd
  85.  
  86. Func _CreateMenuSource()
  87.     Local $aPos, $iContMenu, $tpoint, $d, $sPath ;, $hFont
  88.     $aDrive = DriveGetDrive('ALL')
  89.     If Not @error Then
  90.         $iContMenu = GUICtrlCreateContextMenu($iBtnSource)
  91.         ; GUICtrlSetFont(-1, -1, -1, -1, "Courier New")
  92.  
  93.         ; $hFont = _WinAPI_CreateFont(16, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "Courier New")
  94.         ; If $hFont Then
  95.             ; _WinAPI_SetFont(GUICtrlGetHandle($iContMenu), $hFont)
  96.         ; Else
  97.             ; $iError += 1
  98.         ; EndIf
  99.  
  100.         ReDim $i_ID_Src_Item[$aDrive[0] + 1]
  101.         $i_ID_Src_Item[0] = $aDrive[0]
  102.         $d = 0
  103.         For $i = 1 To $aDrive[0]
  104.             If $aDrive[$i] = 'a:' Or $aDrive[$i] = 'b:' Then ContinueLoop
  105.             If FileExists($aDrive[$i] & '\sources\install.wim') Then
  106.                 $d += 1
  107.                 $aDrive[$d] = $aDrive[$i] & '\sources\install.wim'
  108.                 $i_ID_Src_Item[$d] = GUICtrlCreateMenuItem($aDrive[$d], $iContMenu)
  109.             EndIf
  110.         Next
  111.         If $d = 0 Then
  112.             GUICtrlDelete($iContMenu)
  113.             ; If $hFont Then _WinAPI_DeleteObject($hFont)
  114.             ReDim $i_ID_Src_Item[1]
  115.             $i_ID_Src_Item[0] = 0
  116.             $aDrive = 0
  117.             $sPath = FileOpenDialog('Choose...', "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "image (*.wim)", 1 + 4, 'install.wim', $hGUI)
  118.             If Not @error Then Return SetError(0, 1, $sPath)
  119.             Return
  120.         EndIf
  121.         $d += 1
  122.         $aDrive[$d] = 'Choose other'
  123.         $i_ID_Src_Item[$d] = GUICtrlCreateMenuItem($aDrive[$d], $iContMenu)
  124.         ReDim $i_ID_Src_Item[$d + 1]
  125.         $i_ID_Src_Item[0] = $d
  126.         ReDim $aDrive[$d + 1]
  127.  
  128.         $aPos = ControlGetPos($hGUI, "", $iBtnSource)
  129.         $tpoint = DllStructCreate("int X;int Y")
  130.         DllStructSetData($tpoint, "X", $aPos[0])
  131.         DllStructSetData($tpoint, "Y", $aPos[1] + $aPos[3])
  132.         _WinAPI_ClientToScreen($hGUI, $tpoint)
  133.         _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($iContMenu), $hGUI, DllStructGetData($tpoint, "X"), DllStructGetData($tpoint, "Y"), 1)
  134.         GUICtrlDelete($iContMenu)
  135.         ; If $hFont Then _WinAPI_DeleteObject($hFont)
  136.     EndIf
  137.     ReDim $i_ID_Src_Item[1]
  138.     $i_ID_Src_Item[0] = 0
  139.     $aDrive = 0
  140.     Return
  141. EndFunc   ;==>_CreateMenu
  142.  
  143. Func _CreateMenuDisk()
  144.     Local $aPos, $iContMenu, $sList, $tpoint
  145.     $sList = _GetDrv()
  146.     If $sList Then
  147.         $iContMenu = GUICtrlCreateContextMenu($iBtnDisk)
  148.         GUICtrlSetFont(-1, -1, -1, -1, "Courier New")
  149.         $a_List = StringSplit($sList, $sp)
  150.         ReDim $i_ID_Boot_Item[$a_List[0] + 1]
  151.         $i_ID_Boot_Item[0] = $a_List[0]
  152.         For $i = 1 To $a_List[0]
  153.             $i_ID_Boot_Item[$i] = GUICtrlCreateMenuItem($a_List[$i], $iContMenu)
  154.         Next
  155.  
  156.         $aPos = ControlGetPos($hGUI, "", $iBtnDisk)
  157.         $tpoint = DllStructCreate("int X;int Y")
  158.         DllStructSetData($tpoint, "X", $aPos[0])
  159.         DllStructSetData($tpoint, "Y", $aPos[1] + $aPos[3])
  160.         _WinAPI_ClientToScreen($hGUI, $tpoint)
  161.         _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($iContMenu), $hGUI, DllStructGetData($tpoint, "X"), DllStructGetData($tpoint, "Y"), 1)
  162.         GUICtrlDelete($iContMenu)
  163.     EndIf
  164.     ReDim $i_ID_Boot_Item[1]
  165.     $i_ID_Boot_Item[0] = 0
  166.     $a_List = 0
  167. EndFunc   ;==>_CreateMenu
  168.  
  169. Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
  170.     Local $iID = BitAND($wParam, 0x0000FFFF)
  171.     If $i_ID_Boot_Item[0] Then
  172.         Switch $iID
  173.             Case $i_ID_Boot_Item[1] To $i_ID_Boot_Item[$i_ID_Boot_Item[0]]
  174.                 GUICtrlSetData($iLbDisk, $a_List[$iID - $i_ID_Boot_Item[1] + 1])
  175.                 ; Local $tmp = StringRegExp($a_List[$iID - $i_ID_Boot_Item[1] + 1], '(?i)^.{6}([a-z]:).+', 1)
  176.                 ; If Not @error Then GUICtrlSetData($iLbDiskBig, $tmp[0])
  177.                 $i_ID_Boot_Item[0] = 0
  178.                 Return $GUI_RUNDEFMSG
  179.         EndSwitch
  180.     EndIf
  181.     If $i_ID_Src_Item[0] Then
  182.         Switch $iID
  183.             Case $i_ID_Src_Item[1] To $i_ID_Src_Item[$i_ID_Src_Item[0]]
  184.                 If $aDrive[$iID - $i_ID_Src_Item[1] + 1] = 'Choose other' Then
  185.                     GUICtrlSendToDummy($iDummySrc)
  186.                 Else
  187.                     GUICtrlSetData($iLbSource, $aDrive[$iID - $i_ID_Src_Item[1] + 1])
  188.                 EndIf
  189.                 $i_ID_Src_Item[0] = 0
  190.                 Return $GUI_RUNDEFMSG
  191.         EndSwitch
  192.     EndIf
  193. EndFunc   ;==>WM_COMMAND
  194.  
  195. Func _GetDrv()
  196.     Local $sInfo = _ComboListDrive('Fixed')
  197.     $sInfo &= _ComboListDrive('Removable')
  198.     Return StringTrimLeft($sInfo, 1)
  199. EndFunc
  200.  
  201. Func _ComboListDrive($Type) ; coded by AZJIO (2013.01.26)
  202.     Local $aDrive = DriveGetDrive($Type), $list = '', $sString, $sLabel, $aDisc_Partition
  203.     If @error Then Return ''
  204.     If $Type = 'Removable' Then $Type = 'Rem'
  205.     For $i = 1 To $aDrive[0]
  206.         If $aDrive[$i] = 'A:' Then ContinueLoop
  207.         $sLabel = DriveGetLabel($aDrive[$i])
  208.         If StringLen($sLabel) > 15 Then $sLabel = StringLeft($sLabel, 12) & '...'
  209.         $aDisc_Partition = _GetDiskNimberForDrive($aDrive[$i])
  210.         ; If @error Then Local $aDisc_Partition[2] = ['?', '?']
  211.         $sString = StringFormat('%2s:%-2s %-2s %-5s %-15s %-5s ', $aDisc_Partition[0], $aDisc_Partition[1], StringUpper($aDrive[$i]), $Type, $sLabel, _
  212.                 DriveGetFileSystem($aDrive[$i])) & _GetSize(DriveSpaceTotal($aDrive[$i])) & ' Gb'
  213.         $list &= $sp & $sString
  214.     Next
  215.     Return $list
  216. EndFunc   ;==>_ComboListDrive
  217.  
  218. Func _GetSize($s)
  219.     $s = StringFormat('%.03f', $s / 1024)
  220.     If StringLen($s) > 7 Then $s = StringRegExpReplace(StringTrimRight($s, 4), '(\A\d{1,3}(?=(\d{3})+\z)|\d{3}(?=\d))', '\1 ') & StringRight($s, 4)
  221.     Return StringFormat('%9s', $s) ; 9 терабайт
  222. EndFunc
  223.  
  224.  
  225. ; http://www.autoitscript.com/forum/topic/91598-get-disk-number-from-drive-letter/?p=659721
  226. ; Описание ........: Возвращает номер диска и номер раздела в формате n:n (<номер диска>:<номер раздела>)
  227. ; Параметры:
  228. ;       $sDriveLetter - Буква диска с двоеточием, например C:
  229. ;                   Неудачно , возвращает -1, @error:
  230. ;                  |1 - Ошибка CreateFile, ваша система очень старая
  231. ;                  |2 - Диск не существует
  232. ;                  |3 - Неудачный вызов DeviceIoControl
  233. ;                  |4 - Не раздела диска
  234. Func _GetDiskNimberForDrive($sDriveLetter) ; Буква диска
  235.  
  236.     Local $aDrive[2] = ['?', '?']
  237.  
  238.     Local $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFile", _
  239.             "str", "\\.\" & $sDriveLetter, _; Буква диска
  240.             "dword", 0, _
  241.             "dword", 0, _
  242.             "ptr", 0, _
  243.             "dword", 3, _; OPEN_EXISTING
  244.             "dword", 128, _; FILE_ATTRIBUTE_NORMAL
  245.             "ptr", 0)
  246.  
  247.     If @error Then
  248.         Return SetError(1, 0, $aDrive); Ваша система очень старая. Сделайте что-нибудь.
  249.     EndIf
  250.  
  251.     If $a_hCall[0] = -1 Then
  252.         Return SetError(2, 0, $aDrive) ; Диск не существует
  253.     EndIf
  254.  
  255.     Local $hDevice = $a_hCall[0]
  256.  
  257.     Local $tIOCTL_STORAGE_GET_DEVICE_NUMBER = DllStructCreate("dword DeviceType;" & _
  258.             "dword DeviceNumber;" & _
  259.             "int PartitionNumber")
  260.  
  261.     Local $a_iCall = DllCall("kernel32.dll", "int", "DeviceIoControl", _
  262.             "hwnd", $hDevice, _
  263.             "dword", 0x2D1080, _; IOCTL_STORAGE_GET_DEVICE_NUMBER
  264.             "ptr", 0, _
  265.             "dword", 0, _
  266.             "ptr", DllStructGetPtr($tIOCTL_STORAGE_GET_DEVICE_NUMBER), _
  267.             "dword", DllStructGetSize($tIOCTL_STORAGE_GET_DEVICE_NUMBER), _
  268.             "dword*", 0, _
  269.             "ptr", 0)
  270.  
  271.     If @error Or Not $a_hCall[0] Then
  272.         DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice)
  273.         Return SetError(3, 0, $aDrive); неудачный вызов DeviceIoControl
  274.     EndIf
  275.  
  276.     DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice)
  277.  
  278.     If DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceType") = 7 Then; FILE_DEVICE_DISK
  279.         $aDrive[0] = DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceNumber")
  280.         $aDrive[1] = DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "PartitionNumber")
  281.         Return SetError(0, 0, $aDrive)
  282.     EndIf
  283.  
  284.     Return SetError(4, 0, $aDrive); Не раздела диска
  285.  
  286. EndFunc   ;==>_GetDiskNimberForDrive
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement