Jump to content

ListView Click


Recommended Posts

Let me start by saying this is not necessary to my project.

This is more about me learning and understanding.

What I want to do is be able to click on any Item in the ListView and return a message.

This is an example I found and started tweaking to get it to do what I wanted.

I deleted some buttons and sent the click directly to a msgbox.

Double click an item returns a message.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>


$Form1 = GUICreate('boo', 361, 270, 200, 200)

;~ Create listview
    $hListView = _GUICtrlListView_Create ($Form1, "", 0, 0, 260, 377) ; LEFT],[TOP],WIDTH],[HEIGHT]
                 _GUICtrlListView_SetExtendedListViewStyle ($hListView, BitOR($LVS_AUTOARRANGE,$LVS_EX_FULLROWSELECT,$LVS_EX_DOUBLEBUFFER,$LVS_EX_SUBITEMIMAGES))

  ; Add columns
    _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
    _GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 150)

    ; Add items
    _GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1)

    _GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW)


Do
$msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE



;~ ========================================================
;~ This thing is responcible for click events
;~ ========================================================
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode

                Case $NM_DBLCLK  ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                   Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)

                   $Index = DllStructGetData($tInfo, "Index")

                   $subitemNR = DllStructGetData($tInfo, "SubItem")


                   ; make sure user clicks on the listview & only the activate
                   If $Index <> -1 Then

                       ; col1 ITem index
                        $item = StringSplit(_GUICtrlListView_GetItemTextString($hListView, $Index),'|')
                        $item = $item[1]

                        ;Col item 2 index
                        $item2 = StringSplit(_GUICtrlListView_GetItemTextString($hListView, $subitemNR),'|')
                        $item2= $item2[2]

                        MsgBox(0, 'List View', "Please Select Drive from Drop Down List below")

                    EndIf

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

What my problem is the Items are not set in the ListView in my script below.

This is my feeble attempt at applying the above to my script.

Import all Drivers

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Best Driver Import.ico
#AutoIt3Wrapper_Res_Fileversion=1.5.0.0
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Tidy_Stop_OnError=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <SendMessage.au3>
#include <GuiListView.au3>

$Form1 = GUICreate("Import all Drivers", 400, 400, 600, -1, BitOR($WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU), BitOR($WS_EX_OVERLAPPEDWINDOW, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
GUISetBkColor(0xABCDFF)
$ListView = GUICtrlCreateListView("FileSystem        | Drive | ", 50, 40, 300, 190)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$aDrives = DriveGetDrive("Fixed")
For $i = 1 To UBound($aDrives) - 1
    $sData = DriveGetFileSystem($aDrives[$i]) & " | " & StringUpper($aDrives[$i]) & "" & DriveGetLabel($aDrives[$i])
    GUICtrlCreateListViewItem($sData, $ListView)
Next
$Label1 = GUICtrlCreateLabel("List of Available Drives to Import From", 60, 20, 275, 24)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Select Drive from dropdown list below", 65, 230, 275, 24)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Combo1 = GUICtrlCreateCombo("", 100, 260, 200, 20, $CBS_DROPDOWNLIST)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("OK", 100, 350, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("Cancel", 220, 350, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
For $i = 10 To 99
    If DriveStatus(Chr($i) & ':') = 'READY' Then
        If DriveGetType(Chr($i) & ":") = 'FIXED' Then GUICtrlSetData($Combo1, Chr($i) & ':')
    EndIf
Next
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Button2
            Exit
        Case $Button1
            $version = StringLeft(FileGetVersion(GUICtrlRead($Combo1) & "\Windows\system32\WinVer.exe"), 3)
            If StringLeft($version, 3) = "6.1" Then
                $version = "WIN7"
            ElseIf StringLeft($version, 3) = "6.0" Then
                $version = "VISTA"
            ElseIf StringLeft($version, 3) = "5.1" Then
                $version = "XP"
            ElseIf Not FileExists($version) Then
                MsgBox(262144, "No OS found", "No Windows OS found")
                ContinueLoop
            EndIf
            $arch = (GUICtrlRead($Combo1) & "\Windows\system32\WinVer.exe")
            Local $stType = DllStructCreate("dword;")
            $aRet = DllCall("kernel32.dll", "hwnd", "GetBinaryType", "str", $arch, "ptr", DllStructGetPtr($stType))

            ; Local Const $SCS_32BIT_BINARY = 0 ; A 32-bit Windows-based application
            ; Local Const $SCS_DOS_BINARY = 1 ; An MS-DOS – based application
            ; Local Const $SCS_WOW_BINARY = 2 ; A 16-bit Windows-based application
            ; Local Const $SCS_PIF_BINARY = 3 ; A PIF file that executes an MS-DOS – based application
            ; Local Const $SCS_POSIX_BINARY = 4 ; A POSIX – based application
            ; Local Const $SCS_OS216_BINARY = 5 ; A 16-bit OS/2-based application
            ; Local Const $SCS_64BIT_BINARY = 6 ; A 64-bit Windows-based application

            If DllStructGetData($stType, 1) = "0" Then
                $arch = "_x32"
            ElseIf DllStructGetData($stType, 1) = "6" Then
                $arch = "_x64"
            EndIf
            $1 = MsgBox(262144 + 4 + 32, "OSVersion & Arch", (GUICtrlRead($Combo1) & $version & $arch) & @CRLF & "Do you wish to continue?")
            If $1 = 6 Then
                $hGUI = GUICreate("Test", 400, 40, -1, -1, $WS_POPUP, $WS_EX_TOPMOST, $WS_EX_LAYERED)
                GUISetBkColor(0xABCDFF)
                $Label3 = GUICtrlCreateLabel("Importing Drivers Please be Patient", 20, 0, 275, 24)
                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                $idProgress = GUICtrlCreateProgress(0, 18, 400, 20, BitOR($PBS_MARQUEE, $PBS_SMOOTH))
                $hProgress = GUICtrlGetHandle($idProgress)
                _SendMessage($hProgress, $PBM_SETMARQUEE, True, 20) ; final parameter is update time in ms
                GUISetState()
                Do
                    RunWait("Dpinst.exe /se /sw /s /path " & (GUICtrlRead($Combo1) & "\Windows"))
                    Exit
                Until GUIGetMsg() = $GUI_EVENT_CLOSE
                Exit
            EndIf
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $ListView
    If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode

                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)

                    $Index = DllStructGetData($tInfo, "Index")

                    $subitemNR = DllStructGetData($tInfo, "SubItem")


                    ; make sure user clicks on the listview & only the activate
                    If $Index <> -1 Then

                        ; col1 ITem index
                        $item = StringSplit(_GUICtrlListView_GetItemTextString($ListView, $Index), '|')
                        $item = $item[1]

                        ;Col item 2 index
                        $item2 = StringSplit(_GUICtrlListView_GetItemTextString($ListView, $subitemNR), '|')
                        $item2 = $item2[2]

                        MsgBox(0, 'List View', "Please Select Drive from Drop Down List below")

                    EndIf

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

I think what I need to do is use the return value of each Item instead of the item itself.

I really have no Idea how to approach this.

 

This is all part of a Win7PE project I'm working on

I started on the above script about a week ago just prior to signing up to the forum.

Below is the first part of my project I started on a little over a month ago.

Although it has nothing to do with what I'm working on now,

I would eventually like to merge everything into one script.

Best Driver Import

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Best Driver Import.ico
#AutoIt3Wrapper_Res_Description=Driver Import
#AutoIt3Wrapper_Res_Fileversion=2.0.0.0
#AutoIt3Wrapper_Add_Constants=n
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Tidy_Stop_OnError=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
#region
$Form1 = GUICreate("Driver Import", 450, 200, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
GUISetBkColor(0xA6CAF0)
$widthCell = 370
GUICtrlCreateLabel("       Select the drivers you want and Click Import.", 40, 20, $widthCell)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("      All Drivers Imports all MS and Non MS drivers.", 40, 40, $widthCell)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("All non MS drivers should be sufficient in most cases.", 40, 60, $widthCell)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Checkbox1 = GUICtrlCreateCheckbox("Net/WiFi", 90, 90, 97, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "Checkbox1Click")
$Checkbox2 = GUICtrlCreateCheckbox("Video", 260, 90, 97, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "Checkbox2Click")
$Checkbox3 = GUICtrlCreateCheckbox("Audio", 90, 110, 97, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "Checkbox3Click")
$Checkbox4 = GUICtrlCreateCheckbox("Other", 260, 110, 97, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "Checkbox4Click")
GUICtrlSetState($Checkbox4, $GUI_DISABLE + $GUI_UNCHECKED)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Checkbox5 = GUICtrlCreateCheckbox("All Non MS", 90, 130, 97, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "Checkbox5Click")
$Checkbox6 = GUICtrlCreateCheckbox("All Drivers", 260, 130, 97, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent(-1, "Checkbox6Click")
$Import = GUICtrlCreateButton("Import", 100, 170, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent($Import, "ImportClick")
$Exit = GUICtrlCreateButton("Exit", 270, 170, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetOnEvent($Exit, "ExitClick")
GUISetState(@SW_SHOW)
#endregion

While 1
    Sleep(100)

WEnd

Func ImportClick()
    If GUICtrlRead($Checkbox1) = $GUI_CHECKED Or GUICtrlRead($Checkbox2) = $GUI_CHECKED Or GUICtrlRead($Checkbox3) = $GUI_CHECKED Or GUICtrlRead($Checkbox4) = $GUI_CHECKED Then
        GUISetState(@SW_HIDE, $Form1)
        RunWait("RunScanner.exe /t 10 /cp /sd /ac /m+ /y ddc.exe b /target:" & EnvGet("SYSTEMDRIVE") & "\driverbackup")
        RunWait(DirCreate(EnvGet("SYSTEMDRIVE") & "\driverbackup\Install\"))
    EndIf
    If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
        RunWait(DirMove(@HomeDrive & "\driverbackup\Net\", @HomeDrive & "\driverbackup\Install\", 1))
        RunWait(DirMove(@HomeDrive & "\driverbackup\Bluetooth\", @HomeDrive & "\driverbackup\Install\", 1))
    EndIf
    If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
        RunWait(DirMove(@HomeDrive & "\driverbackup\Display\", @HomeDrive & "\driverbackup\Install\", 1))
    EndIf
    If GUICtrlRead($Checkbox3) = $GUI_CHECKED Then
        RunWait(DirMove(@HomeDrive & "\driverbackup\MEDIA\", @HomeDrive & "\driverbackup\Install\", 1))
    EndIf
    If GUICtrlRead($Checkbox4) = $GUI_CHECKED Then

    EndIf
    If GUICtrlRead($Checkbox5) = $GUI_CHECKED Then
        GUISetState(@SW_HIDE, $Form1)
        RunWait("RunScanner.exe /t 10 /cp /sd /ac /m+ /y ddc.exe b /target:" & EnvGet("SYSTEMDRIVE") & "\driverbackup")
    EndIf
    If GUICtrlRead($Checkbox6) = $GUI_CHECKED Then
        Run("Import all Drivers.exe")
        Exit
    EndIf
    If GUICtrlRead($Checkbox1) = $GUI_CHECKED Or GUICtrlRead($Checkbox2) = $GUI_CHECKED Or GUICtrlRead($Checkbox3) = $GUI_CHECKED Or GUICtrlRead($Checkbox4) = $GUI_CHECKED Then
        RunWait("Dpinst.exe /path " & EnvGet("SYSTEMDRIVE") & "\driverbackup\Install\")
        GUISetState(@SW_SHOW, $Form1)
        DirRemove(EnvGet("SYSTEMDRIVE") & "\driverbackup", 1)
        Exit
    EndIf
    If GUICtrlRead($Checkbox5) = $GUI_CHECKED Then
        RunWait("Dpinst.exe /path " & EnvGet("SYSTEMDRIVE") & "\driverbackup\")
        GUISetState(@SW_SHOW, $Form1)
        DirRemove(EnvGet("SYSTEMDRIVE") & "\driverbackup", 1)
        Exit
    EndIf
EndFunc   ;==>ImportClick

Func Checkbox1Click()
    If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
    EndIf
EndFunc   ;==>Checkbox1Click

Func Checkbox2Click()
    If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
    EndIf
EndFunc   ;==>Checkbox2Click

Func Checkbox3Click()
    If GUICtrlRead($Checkbox3) = $GUI_CHECKED Then
    EndIf
EndFunc   ;==>Checkbox3Click

Func Checkbox4Click()
    If GUICtrlRead($Checkbox4) = $GUI_CHECKED Then
    EndIf
EndFunc   ;==>Checkbox4Click

Func Checkbox5Click()
    If GUICtrlRead($Checkbox5) = $GUI_CHECKED Then
        GUICtrlSetState($Checkbox1, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox2, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox3, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox4, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox6, $GUI_DISABLE + $GUI_UNCHECKED)
    Else
        GUICtrlSetState($Checkbox1, $GUI_ENABLE)
        GUICtrlSetState($Checkbox2, $GUI_ENABLE)
        GUICtrlSetState($Checkbox3, $GUI_ENABLE)
        GUICtrlSetState($Checkbox4, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox6, $GUI_ENABLE)
    EndIf
EndFunc   ;==>Checkbox5Click

Func Checkbox6Click()
    If GUICtrlRead($Checkbox6) = $GUI_CHECKED Then
        GUICtrlSetState($Checkbox1, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox2, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox3, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox4, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox5, $GUI_DISABLE + $GUI_UNCHECKED)
    Else
        GUICtrlSetState($Checkbox1, $GUI_ENABLE)
        GUICtrlSetState($Checkbox2, $GUI_ENABLE)
        GUICtrlSetState($Checkbox3, $GUI_ENABLE)
        GUICtrlSetState($Checkbox4, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox5, $GUI_ENABLE)
    EndIf

EndFunc   ;==>Checkbox6Click

Func ExitClick()
    DirRemove(EnvGet("SYSTEMDRIVE") & "\driverbackup", 1)
    Exit
EndFunc   ;==>ExitClick

Func Form1Close()
    DirRemove(EnvGet("SYSTEMDRIVE") & "\driverbackup", 1)
    Exit
EndFunc   ;==>Form1Close

My PC I have 2 hard drives with 5 partitions, 3 containing OS. Win7 x86, Win7 x64 and XP.

ListView would show 5 drives.3 OS and 2 for file storage.

If you can help me out and show me what to do or just point me in the right direction

and see how bad I can screw things up.

Any help appreciated

Link to comment
Share on other sites

Did you try with DriveGetDrive("ALL")? It returns an Array.

Saludos

Link to comment
Share on other sites

So if I understand correctly you want a list view with all HD's and when you click (doubleclick) on one it shows if a OS is installed?

If so:

Danyfirex' idea is a perfect start to populate your listview with the drives, then setup your "If - ElseIf - XP, Vista" etc.. snippet to update a label on your GUI with the information or a MsgBox if thats what you want.

This might come in handy when trying to select a listview item:

_GUICtrlListView_GetSelectedIndices

Good Luck !

Bill

Link to comment
Share on other sites

Look in the help file at the example in _GUICtrlListView_Create, there are a LOT of windows messages that can be played with to do what you're looking to do.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

ListView is for display only, Drive Letter, DriveLabel and any other important info about each drive.

Dropdown is for actual drive selection. This is because parameter to be passed is drive letter only.

Run the Import all Drivers script and you'll see what I mean.

I found my problem, I overlooked this line "GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")".

Left it alone for awhile and when I went back to it, it just kind of jumped out at me.

Run this script and you'll see what I'm talking about, it does what I want.

Next I need to convert this to GuiOnEvent so I can merge it with Best Driver Import.

Import all Drivers

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Best Driver Import.ico
#AutoIt3Wrapper_Res_Fileversion=1.5.0.0
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Tidy_Stop_OnError=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <SendMessage.au3>
#include <GuiListView.au3>

Global $ListView
gui2()
Func gui2()
    $hGUI2 = GUICreate("Import all Drivers", 400, 400, -1, -1, BitOR($WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU), BitOR($WS_EX_OVERLAPPEDWINDOW, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
    GUISetBkColor(0xABCDFF)
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")  ;This is the required line I missed
    $cLabel = GUICtrlCreateLabel("", 10, 20, 100, 20)
    $ListView = GUICtrlCreateListView("FileSystem        | Drive | ", 50, 40, 300, 190)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUICtrlSetTip($ListView, "Please Select Drive from Drop Down List below")
    $aDrives = DriveGetDrive("Fixed")
    For $i = 1 To UBound($aDrives) - 1
        $sData = DriveGetFileSystem($aDrives[$i]) & " | " & StringUpper($aDrives[$i]) & "" & DriveGetLabel($aDrives[$i])
        GUICtrlCreateListViewItem($sData, $ListView)
    Next
    $Label1 = GUICtrlCreateLabel("List of Available Drives to Import From", 60, 20, 275, 24)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $Label2 = GUICtrlCreateLabel("Select Drive from dropdown list below", 65, 230, 275, 24)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $Combo1 = GUICtrlCreateCombo("", 100, 260, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Button1 = GUICtrlCreateButton("OK", 100, 350, 75, 25)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Button2 = GUICtrlCreateButton("Cancel", 220, 350, 75, 25)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)
    For $i = 10 To 99
        If DriveStatus(Chr($i) & ':') = 'READY' Then
            If DriveGetType(Chr($i) & ":") = 'FIXED' Then GUICtrlSetData($Combo1, Chr($i) & ':')
        EndIf
    Next
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $Button2
                Exit
            Case $Button1
                $version = StringLeft(FileGetVersion(GUICtrlRead($Combo1) & "\Windows\system32\WinVer.exe"), 3)
                If StringLeft($version, 3) = "6.1" Then
                    $version = "WIN7"
                ElseIf StringLeft($version, 3) = "6.0" Then
                    $version = "VISTA"
                ElseIf StringLeft($version, 3) = "5.1" Then
                    $version = "XP"
                ElseIf Not FileExists($version) Then
                    MsgBox(262144, "No OS found", "No Windows OS found")
                    ContinueLoop
                EndIf
                $arch = (GUICtrlRead($Combo1) & "\Windows\system32\WinVer.exe")
                Local $stType = DllStructCreate("dword;")
                $aRet = DllCall("kernel32.dll", "hwnd", "GetBinaryType", "str", $arch, "ptr", DllStructGetPtr($stType))
                If DllStructGetData($stType, 1) = "0" Then
                    $arch = "_x32"
                ElseIf DllStructGetData($stType, 1) = "6" Then
                    $arch = "_x64"
                EndIf
                $1 = MsgBox(262144 + 4 + 32, "OSVersion & Arch", (GUICtrlRead($Combo1) & $version & $arch) & @CRLF & "Do you wish to continue?")
                If $1 = 6 Then
                    $hGUI = GUICreate("Test", 400, 40, -1, -1, $WS_POPUP, $WS_EX_TOPMOST, $WS_EX_LAYERED)
                    GUISetBkColor(0xABCDFF)
                    $Label3 = GUICtrlCreateLabel("Importing Drivers Please be Patient", 20, 0, 275, 24)
                    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                    $idProgress = GUICtrlCreateProgress(0, 18, 400, 20, BitOR($PBS_MARQUEE, $PBS_SMOOTH))
                    $hProgress = GUICtrlGetHandle($idProgress)
                    _SendMessage($hProgress, $PBM_SETMARQUEE, True, 20) ; final parameter is update time in ms
                    GUISetState()
                    Do
                        RunWait("Dpinst.exe /se /sw /s /path " & (GUICtrlRead($Combo1) & "\Windows"))
                        Exit
                    Until GUIGetMsg() = $GUI_EVENT_CLOSE
                    Exit
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>gui2
;~ ========================================================
;~ This thing is responcible for click events
;~ ========================================================
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $ListView
    If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $Index = DllStructGetData($tInfo, "Index")
                    If $Index <> -1 Then
                        MsgBox(262144, 'List View', "Please Select Drive from Drop Down List below")
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Edited by trashy
Link to comment
Share on other sites

Attempting to merge the two scripts.

Everything seems to work but needs further testing.

I made a few comments line 96 and 170 thru 175, these are my points of concerne.

Thanks

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Best Driver Import.ico
#AutoIt3Wrapper_Res_Description=Driver Import
#AutoIt3Wrapper_Res_Fileversion=2.0.0.0
#AutoIt3Wrapper_Add_Constants=n
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Tidy_Stop_OnError=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <SendMessage.au3>
#include <GuiListView.au3>

Opt("GUIOnEventMode", 1)

Global $Checkbox1, $Checkbox2, $Checkbox3, $Checkbox4, $Checkbox5, $Checkbox6, $hGUI1, $ListView, $hGUI2

gui1()

Func gui1()
    $hGUI1 = GUICreate("Driver Import", 450, 200, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
    GUISetBkColor(0xA6CAF0)
    $widthCell = 370
    GUICtrlCreateLabel("       Select the drivers you want and Click Import.", 40, 20, $widthCell)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUICtrlCreateLabel("      All Drivers Imports all MS and Non MS drivers.", 40, 40, $widthCell)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUICtrlCreateLabel("All non MS drivers should be sufficient in most cases.", 40, 60, $widthCell)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUISetOnEvent($GUI_EVENT_CLOSE, "ExitClick")
    $Checkbox1 = GUICtrlCreateCheckbox("Net/WiFi", 90, 90, 97, 17)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUICtrlSetOnEvent(-1, "Checkbox1Click")
    $Checkbox2 = GUICtrlCreateCheckbox("Video", 260, 90, 97, 17)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUICtrlSetOnEvent(-1, "Checkbox2Click")
    $Checkbox3 = GUICtrlCreateCheckbox("Audio", 90, 110, 97, 17)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUICtrlSetOnEvent(-1, "Checkbox3Click")
    $Checkbox4 = GUICtrlCreateCheckbox("Other", 260, 110, 97, 17)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUICtrlSetOnEvent(-1, "Checkbox4Click")
    GUICtrlSetState($Checkbox4, $GUI_DISABLE + $GUI_UNCHECKED)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $Checkbox5 = GUICtrlCreateCheckbox("All Non MS", 90, 130, 97, 17)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUICtrlSetOnEvent(-1, "Checkbox5Click")
    $Checkbox6 = GUICtrlCreateCheckbox("All Drivers", 260, 130, 97, 17)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUICtrlSetOnEvent(-1, "Checkbox6Click")
    $Import = GUICtrlCreateButton("Import", 100, 170, 75, 25)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetOnEvent($Import, "Import")
    $Exit = GUICtrlCreateButton("Exit", 270, 170, 75, 25)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetOnEvent($Exit, "ExitClick")
    GUISetState(@SW_SHOW)
EndFunc   ;==>gui1

While 1
    Sleep(100)

WEnd

Func Import()
    If GUICtrlRead($Checkbox1) = $GUI_CHECKED Or GUICtrlRead($Checkbox2) = $GUI_CHECKED Or GUICtrlRead($Checkbox3) = $GUI_CHECKED Or GUICtrlRead($Checkbox4) = $GUI_CHECKED Then
        GUISetState(@SW_HIDE, $hGUI1)
        RunWait("RunScanner.exe /t 10 /cp /sd /ac /m+ /y ddc.exe b /target:" & EnvGet("SYSTEMDRIVE") & "\driverbackup")
        RunWait(DirCreate(EnvGet("SYSTEMDRIVE") & "\driverbackup\Install\"))
    EndIf
    If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
        RunWait(DirMove(@HomeDrive & "\driverbackup\Net\", @HomeDrive & "\driverbackup\Install\", 1))
        RunWait(DirMove(@HomeDrive & "\driverbackup\Bluetooth\", @HomeDrive & "\driverbackup\Install\", 1))
    EndIf
    If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
        RunWait(DirMove(@HomeDrive & "\driverbackup\Display\", @HomeDrive & "\driverbackup\Install\", 1))
    EndIf
    If GUICtrlRead($Checkbox3) = $GUI_CHECKED Then
        RunWait(DirMove(@HomeDrive & "\driverbackup\MEDIA\", @HomeDrive & "\driverbackup\Install\", 1))
    EndIf
    If GUICtrlRead($Checkbox4) = $GUI_CHECKED Then

    EndIf
    If GUICtrlRead($Checkbox5) = $GUI_CHECKED Then
        GUISetState(@SW_HIDE, $hGUI1)
        RunWait("RunScanner.exe /t 10 /cp /sd /ac /m+ /y ddc.exe b /target:" & EnvGet("SYSTEMDRIVE") & "\driverbackup")
    EndIf
    If GUICtrlRead($Checkbox6) = $GUI_CHECKED Then
        GUIDelete($hGUI1)
        gui2()
        $GUI_ENABLE($hGUI2) ;not sure if this lne is necessary trying to pass control to $hGUI2 starts on line 172
    EndIf
    If GUICtrlRead($Checkbox1) = $GUI_CHECKED Or GUICtrlRead($Checkbox2) = $GUI_CHECKED Or GUICtrlRead($Checkbox3) = $GUI_CHECKED Or GUICtrlRead($Checkbox4) = $GUI_CHECKED Then
        RunWait("Dpinst.exe /path " & EnvGet("SYSTEMDRIVE") & "\driverbackup\Install\")
        GUISetState(@SW_SHOW, $hGUI1)
        DirRemove(EnvGet("SYSTEMDRIVE") & "\driverbackup", 1)
        Exit
    EndIf
    If GUICtrlRead($Checkbox5) = $GUI_CHECKED Then
        RunWait("Dpinst.exe /path " & EnvGet("SYSTEMDRIVE") & "\driverbackup\")
        GUISetState(@SW_SHOW, $hGUI1)
        DirRemove(EnvGet("SYSTEMDRIVE") & "\driverbackup", 1)
        Exit
    EndIf
EndFunc   ;==>Import

Func Checkbox1Click()
    If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
    EndIf
EndFunc   ;==>Checkbox1Click

Func Checkbox2Click()
    If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
    EndIf
EndFunc   ;==>Checkbox2Click

Func Checkbox3Click()
    If GUICtrlRead($Checkbox3) = $GUI_CHECKED Then
    EndIf
EndFunc   ;==>Checkbox3Click

Func Checkbox4Click()
    If GUICtrlRead($Checkbox4) = $GUI_CHECKED Then
    EndIf
EndFunc   ;==>Checkbox4Click

Func Checkbox5Click()
    If GUICtrlRead($Checkbox5) = $GUI_CHECKED Then
        GUICtrlSetState($Checkbox1, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox2, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox3, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox4, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox6, $GUI_DISABLE + $GUI_UNCHECKED)
    Else
        GUICtrlSetState($Checkbox1, $GUI_ENABLE)
        GUICtrlSetState($Checkbox2, $GUI_ENABLE)
        GUICtrlSetState($Checkbox3, $GUI_ENABLE)
        GUICtrlSetState($Checkbox4, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox6, $GUI_ENABLE)
    EndIf
EndFunc   ;==>Checkbox5Click

Func Checkbox6Click()
    If GUICtrlRead($Checkbox6) = $GUI_CHECKED Then
        GUICtrlSetState($Checkbox1, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox2, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox3, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox4, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox5, $GUI_DISABLE + $GUI_UNCHECKED)
    Else
        GUICtrlSetState($Checkbox1, $GUI_ENABLE)
        GUICtrlSetState($Checkbox2, $GUI_ENABLE)
        GUICtrlSetState($Checkbox3, $GUI_ENABLE)
        GUICtrlSetState($Checkbox4, $GUI_DISABLE + $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox5, $GUI_ENABLE)
    EndIf

EndFunc   ;==>Checkbox6Click

Func ExitClick()
    DirRemove(EnvGet("SYSTEMDRIVE") & "\driverbackup", 1)
    Exit
EndFunc   ;==>ExitClick

;begining of Import all Drivers
;gui1 "GUIOnEventMode" gui2 isn't

gui2()
Func gui2()
    Opt("GUIOnEventMode", 0)  ;I hope I got this right
    $hGUI2 = GUICreate("Import all Drivers", 400, 400, -1, -1, BitOR($WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU), BitOR($WS_EX_OVERLAPPEDWINDOW, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
    GUISetBkColor(0xABCDFF)
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;This is the required line I missed
    $cLabel = GUICtrlCreateLabel("", 10, 20, 100, 20)
    $ListView = GUICtrlCreateListView("FileSystem        | Drive | ", 50, 40, 300, 190)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUICtrlSetTip($ListView, "Please Select Drive from Drop Down List below")
    $aDrives = DriveGetDrive("Fixed")
    For $i = 1 To UBound($aDrives) - 1
        $sData = DriveGetFileSystem($aDrives[$i]) & " | " & StringUpper($aDrives[$i]) & "" & DriveGetLabel($aDrives[$i])
        GUICtrlCreateListViewItem($sData, $ListView)
    Next
    $Label1 = GUICtrlCreateLabel("List of Available Drives to Import From", 60, 20, 275, 24)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $Label2 = GUICtrlCreateLabel("Select Drive from dropdown list below", 65, 230, 275, 24)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    $Combo1 = GUICtrlCreateCombo("", 100, 260, 200, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Button1 = GUICtrlCreateButton("OK", 100, 350, 75, 25)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Button2 = GUICtrlCreateButton("Cancel", 220, 350, 75, 25)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)
    For $i = 10 To 99
        If DriveStatus(Chr($i) & ':') = 'READY' Then
            If DriveGetType(Chr($i) & ":") = 'FIXED' Then GUICtrlSetData($Combo1, Chr($i) & ':')
        EndIf
    Next
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $Button2
                Exit
            Case $Button1
                $version = StringLeft(FileGetVersion(GUICtrlRead($Combo1) & "\Windows\system32\WinVer.exe"), 3)
                If StringLeft($version, 3) = "6.1" Then
                    $version = "WIN7"
                ElseIf StringLeft($version, 3) = "6.0" Then
                    $version = "VISTA"
                ElseIf StringLeft($version, 3) = "5.1" Then
                    $version = "XP"
                ElseIf Not FileExists($version) Then
                    MsgBox(262144, "No OS found", "No Windows OS found")
                    ContinueLoop
                EndIf
                $arch = (GUICtrlRead($Combo1) & "\Windows\system32\WinVer.exe")
                Local $stType = DllStructCreate("dword;")
                $aRet = DllCall("kernel32.dll", "hwnd", "GetBinaryType", "str", $arch, "ptr", DllStructGetPtr($stType))
                If DllStructGetData($stType, 1) = "0" Then
                    $arch = "_x32"
                ElseIf DllStructGetData($stType, 1) = "6" Then
                    $arch = "_x64"
                EndIf
                $1 = MsgBox(262144 + 4 + 32, "OSVersion & Arch", (GUICtrlRead($Combo1) & $version & $arch) & @CRLF & "Do you wish to continue?")
                If $1 = 6 Then
                    $hGUI = GUICreate("Test", 400, 40, -1, -1, $WS_POPUP, $WS_EX_TOPMOST, $WS_EX_LAYERED)
                    GUISetBkColor(0xABCDFF)
                    $Label3 = GUICtrlCreateLabel("Importing Drivers Please be Patient", 20, 0, 275, 24)
                    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                    $idProgress = GUICtrlCreateProgress(0, 18, 400, 20, BitOR($PBS_MARQUEE, $PBS_SMOOTH))
                    $hProgress = GUICtrlGetHandle($idProgress)
                    _SendMessage($hProgress, $PBM_SETMARQUEE, True, 20) ; final parameter is update time in ms
                    GUISetState()
                    Do
                        RunWait("Dpinst.exe /se /sw /s /path " & (GUICtrlRead($Combo1) & "\Windows"))
                        Exit
                    Until GUIGetMsg() = $GUI_EVENT_CLOSE
                    Exit
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>gui2
;~ ========================================================
;~ This thing is responcible for click events
;~ ========================================================
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $ListView
    If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $Index = DllStructGetData($tInfo, "Index")
                    If $Index <> -1 Then
                        MsgBox(262144, 'List View', "Please Select Drive from Drop Down List below")
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...