Sign in to follow this  
Followers 0
Mat

wingethandle doesn't find the window title I'd generated by winlist

9 posts in this topic

I have a problem with this part of my script, the window title returns fine, but when I try to use it, it decides that actually it doesn't exist... It's not wingethandles fault, I tried it with winsettitle, winlist the lot, and not one recognised the title that winlist had generated. this script might not work, as it is only a small part of a script that was supposed to be a small project of concenience to make my life a bit easier...

$Window = GUICreate ("Please select a window.", 344, 333)
            GUISetState ()
            $Winlist = GUICtrlCreateListView ("Window Title | Process", 10, 40, 330, 279)
               _GUICtrlListView_SetColumnWidth($Winlist, 0, 240)
            $Button = GUICtrlCreateButton ("Select", 260, 10, 80, 20)
            GuiCtrlCreateLabel("Please select a window to use.", 10, 10, 240, 20)
            $Array = WinList ()
            For $i = 1 To $Array[0][0]
               If $array[$i][0] <> "" AND IsVisible($array[$i][1]) Then
                  GUICtrlCreateListViewItem ($Array[$i][0] & " | " & _ProcessGetName (WinGetProcess ($Array[$i][0])), $Winlist)
               EndIf
            Next
            Do 
               $Msg = GUIGetMsg ()
            Until $Msg = $Button or $Msg = $GUI_EVENT_CLOSE
            GUICtrlSetState ($Window, $GUI_HIDE)
            $Selected = FindSelected ($Winlist)
            MsgBox (48, "Test", $Selected)
            $handle = WinGetHandle ($Selected)
            MsgBox (48, "Test", $Handle)

and this is my findselected func

Func Findselected ($Winlist)
   Local $Count, $i, $Selected, $Select[4]
   
   $Count = _GUICtrlListView_GetItemCount($winlist)
   $i = 1
   Do
      $Selected = _GUICtrlListView_GetItemSelected($Winlist, $i)
      $i = $i + 1
   Until $Selected = true or $i = $Count + 1
   If $Selected = true Then 
      $Select = _GUICtrlListView_GetItemTextArray($Winlist, $i - 1)
      Return $Select[1]
   ElseIf $i = $Count + 1 Then
      Return 1
   ElseIf _GUICtrlListView_GetSelectedCount($Winlist) > 1 Then
      Return 2
   Else
      Return 3
   EndIf
EndFunc

2 things

1) Is my findselected method the best method to use, I hope not.

2) Why won't wingethandle work?

sorry for the bad explanation,

MDiesel

Share this post


Link to post
Share on other sites



I didn't see a window title in your descrip or your code , so I'm shooting in the dark here.

But if this happens to be for a game, alot of times they have something working against scripts that wont let them get the handle of the window. I've come across several situations from gaming to just reg apps.

I did however look over your code, but no error's or anything jumped out at me. So this could be the case.

( Note: I didn't test or really even thoroughly look over the script. Just a quick scan over.)

Share this post


Link to post
Share on other sites

It's not for a game, It will actually end up as my version of a screenshot thing - but with windows supported too... It doesn't work with the 5 or so windows i've tried, including the script window and firefox and file explorer....

the problem is, although at face value technicaly the title never changes, it is used though. through this use, wingethandle doesn't recognise it.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

On second thaughts....

heres the full script

the wingethandle is the only bit not working

;47 @ 150---------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------| M@'s WinCapture |-----------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------

#include <File.au3>
#Include <ScreenCapture.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <StaticConstants.au3>
#include <Process.au3>

Opt ('MustDeclareVars', 1)
Opt ("TrayIconHide", 1)

Winshot ()
IsVisible($handle)
Findselected ()
_FileSaveDialog ($sTitle, $sInitDir, $sFilter = 'All (*.*)', $iOpt = 0, $sDefaultFile = "", $sDefaultExt = "", $mainGUI = 0)

Func Winshot ()
   Local $File, $Complete, $szDrive, $szDir, $szFName, $szExt, $Split, $Cursor, $Cursorbox, $Winlist, $Window, $Array, $Button, $Msg, $Handle, $Selected

$File = _FileSaveDialog ("Save WinShot", @HomeDrive, 'Jpeg (*.jpg) | Bitmap (*.bmp) | png (*.png)', 16, "Winshot", ".Jpg", 0)
      If @Error Then 
         MsgBox (48, "Error", "Error saving the file.") and exit
      EndIf
         $Cursorbox = MsgBox (52, "Cursor", "Do you want the image to include the cursor?")
            If $Cursorbox = 6 Then
               $Cursor = True
            Else
               $Cursor = False
            Endif
         $Window = GUICreate ("Please select a window.", 344, 333)
            GUISetState ()
            $Winlist = GUICtrlCreateListView ("Window Title | Process", 10, 40, 330, 279)
               _GUICtrlListView_SetColumnWidth($Winlist, 0, 240)
            $Button = GUICtrlCreateButton ("Select", 260, 10, 80, 20)
            GuiCtrlCreateLabel("Please select a window to use.", 10, 10, 240, 20)
            $Array = WinList ()
            For $i = 1 To $Array[0][0]
               If $array[$i][0] <> "" AND IsVisible($array[$i][1]) Then
                  GUICtrlCreateListViewItem ($Array[$i][0] & " | " & _ProcessGetName (WinGetProcess ($Array[$i][0])), $Winlist)
               EndIf
            Next
            Do 
               $Msg = GUIGetMsg ()
            Until $Msg = $Button or $Msg = $GUI_EVENT_CLOSE
            GUICtrlSetState ($Window, $GUI_HIDE)
            $Selected = FindSelected ($Winlist)
            MsgBox (48, "Test", $Selected)
            $handle = WinGetHandle ($Selected)
            MsgBox (48, "Test", $Handle)
            Sleep (100)
            _ScreenCapture_CaptureWnd ($File, $Handle,  0, 0, -1, -1, $Cursor)
            Sleep (100)
            If @Error Then
               MsgBox (48, "Error", "Error capturing the window.")
            Else
               $Complete = MsgBox (52, "Operation Complete", "Window captured successfully, Do you want to open the containing folder?.")
                  If $Complete = 6 Then
                     $Split = _PathSplit($File, $szDrive, $szDir, $szFName, $szExt)
                     ShellExecute ($Split[2])
                  Endif
            EndIf
EndFunc

;-----------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------| Save |----------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------

Func _FileSaveDialog ($sTitle, $sInitDir, $sFilter = 'All (*.*)', $iOpt = 0, $sDefaultFile = "", $sDefaultExt = "", $mainGUI = 0)
    Local $iFileLen = 65536
    Local $iFlag = BitOR (BitShift (BitAND ($iOpt, 2),-10), BitShift (BitAND ($iOpt,16), 3 ))
    Local $asFLines = StringSplit ( $sFilter, '|'), $asFilter [$asFLines [0] *2+1]
    Local $i, $iStart, $iFinal, $suFilter = '', $ret
    $asFilter [0] = $asFLines [0] *2
    For $i=1 To $asFLines [0]
        $iStart = StringInStr ($asFLines [$i], '(', 0, 1)
        $iFinal = StringInStr ($asFLines [$i], ')', 0,-1)
        $asFilter [$i*2-1] = StringStripWS (StringLeft ($asFLines [$i], $iStart-1), 3)
        $asFilter [$i*2] = StringStripWS (StringTrimRight (StringTrimLeft ($asFLines [$i], $iStart), StringLen ($asFLines [$i]) -$iFinal+1), 3)
        $suFilter = $suFilter & 'byte[' & StringLen ($asFilter [$i*2-1])+1 & '];byte[' & StringLen ($asFilter [$i*2])+1 & '];'
    Next
    Local $uOFN = DllStructCreate ('dword;int;int;ptr;ptr;dword;dword;ptr;dword' & _
        ';ptr;int;ptr;ptr;dword;short;short;ptr;ptr;ptr;ptr;ptr;dword;dword' )
    Local $usTitle  = DllStructCreate ('byte[' & StringLen ($sTitle) +1 & ']')
    Local $usInitDir= DllStructCreate ('byte[' & StringLen ($sInitDir) +1 & ']')
    Local $usFilter = DllStructCreate ($suFilter & 'byte')
    Local $usFile   = DllStructCreate ('char[' & $iFileLen & ']')
    Local $usExtn   = DllStructCreate ('byte[' & StringLen ($sDefaultExt) +1 & ']')
    For $i=1 To $asFilter [0]
        DllStructSetData ($usFilter, $i, $asFilter [$i])
    Next
    DllStructSetData ($usTitle, 1, $sTitle)
    DllStructSetData ($usInitDir, 1, $sInitDir)
    DllStructSetData ($usFile, 1, $sDefaultFile)
    DllStructSetData ($usExtn, 1, $sDefaultExt)
    DllStructSetData ($uOFN,  1, DllStructGetSize($uOFN))
    DllStructSetData ($uOFN,  2, $mainGUI)
    DllStructSetData ($uOFN,  4, DllStructGetPtr ($usFilter))
    DllStructSetData ($uOFN,  7, 1)
    DllStructSetData ($uOFN,  8, DllStructGetPtr ($usFile))
    DllStructSetData ($uOFN,  9, $iFileLen)
    DllStructSetData ($uOFN, 12, DllStructGetPtr ($usInitDir))
    DllStructSetData ($uOFN, 13, DllStructGetPtr ($usTitle))
    DllStructSetData ($uOFN, 14, $iFlag)
    DllStructSetData ($uOFN, 17, DllStructGetPtr ($usExtn))
    DllStructSetData ($uOFN, 23, BitShift (BitAND ($iOpt, 32), 5))
    $ret = DllCall ('comdlg32.dll', 'int', 'GetSaveFileName', _
            'ptr', DllStructGetPtr ($uOFN) )
    If $ret [0] Then
        Return StringStripWS(DllStructGetData ($usFile, 1),3)
    Else
        SetError (1)
        Return ""
    EndIf
EndFunc


;-----------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------| Findselected |--------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------

Func Findselected ($Winlist)
   Local $Count, $i, $Selected, $Select[4]
   
   $Count = _GUICtrlListView_GetItemCount($winlist)
   $i = 1
   Do
      $Selected = _GUICtrlListView_GetItemSelected($Winlist, $i)
      $i = $i + 1
   Until $Selected = true or $i = $Count + 1
   If $Selected = true Then 
      $Select = _GUICtrlListView_GetItemTextArray($Winlist, $i - 1)
      Return $Select[1]
   ElseIf $i = $Count + 1 Then
      Return 1
   ElseIf _GUICtrlListView_GetSelectedCount($Winlist) > 1 Then
      Return 2
   Else
      Return 3
   EndIf
EndFunc
   
;-----------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------| IsVisible? |----------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------

Func IsVisible($handle)
   
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc

;-----------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------| Script End |----------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------
Edited by mdiesel

Share this post


Link to post
Share on other sites

Now I REALLY don't wanna give a full look through on that.

What I would suggest is a test script that would get the handle of a window triggered off a hotkey.

This would pinpoint the problem to either the Window itself or something in the code.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Now I REALLY don't wanna give a full look through on that.

What I would suggest is a test script that would get the handle of a window triggered off a hotkey.

This would pinpoint the problem to either the Window itself or something in the code.

:P Its not the wingethandle that is the problem, or the window, its the bit inbetween that does something to the title to make wingethandle not like it...

looking at it, I can't see any reason for the title to change...

Don't worry about it, just run it through and see what you get, I get a blank for handle - which means no windows match the title... I'm not asking you to debug the script and rearrange the whole thing.

MDiesel

ps shutting down and going to bed :unsure: I won't be replying till tomorrow, I'm not ignoring you don't worry :D

Edited by mdiesel

Share this post


Link to post
Share on other sites

On second thaughts....

heres the full script

the wingethandle is the only bit not working

;47 @ 150---------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------| M@'s WinCapture |-----------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------
 
 #include <File.au3>
 #Include <ScreenCapture.au3>
 #include <GUIConstantsEx.au3>
 #include <WindowsConstants.au3>
 #include <GUIListView.au3>
 #include <StaticConstants.au3>
 #include <Process.au3>
 
 Opt ('MustDeclareVars', 1)
 Opt ("TrayIconHide", 1)
 
 Winshot ()
 IsVisible($handle)
 Findselected ()
 _FileSaveDialog ($sTitle, $sInitDir, $sFilter = 'All (*.*)', $iOpt = 0, $sDefaultFile = "", $sDefaultExt = "", $mainGUI = 0)
 
 Func Winshot ()
    Local $File, $Complete, $szDrive, $szDir, $szFName, $szExt, $Split, $Cursor, $Cursorbox, $Winlist, $Window, $Array, $Button, $Msg, $Handle, $Selected
 
 $File = _FileSaveDialog ("Save WinShot", @HomeDrive, 'Jpeg (*.jpg) | Bitmap (*.bmp) | png (*.png)', 16, "Winshot", ".Jpg", 0)
       If @Error Then 
          MsgBox (48, "Error", "Error saving the file.") and exit
       EndIf
          $Cursorbox = MsgBox (52, "Cursor", "Do you want the image to include the cursor?")
             If $Cursorbox = 6 Then
                $Cursor = True
             Else
                $Cursor = False
             Endif
          $Window = GUICreate ("Please select a window.", 344, 333)
             GUISetState ()
             $Winlist = GUICtrlCreateListView ("Window Title | Process", 10, 40, 330, 279)
                _GUICtrlListView_SetColumnWidth($Winlist, 0, 240)
             $Button = GUICtrlCreateButton ("Select", 260, 10, 80, 20)
             GuiCtrlCreateLabel("Please select a window to use.", 10, 10, 240, 20)
             $Array = WinList ()
             For $i = 1 To $Array[0][0]
                If $array[$i][0] <> "" AND IsVisible($array[$i][1]) Then
                   GUICtrlCreateListViewItem ($Array[$i][0] & " | " & _ProcessGetName (WinGetProcess ($Array[$i][0])), $Winlist)
                EndIf
             Next
             Do 
                $Msg = GUIGetMsg ()
             Until $Msg = $Button or $Msg = $GUI_EVENT_CLOSE
             GUICtrlSetState ($Window, $GUI_HIDE)
             $Selected = FindSelected ($Winlist)
             MsgBox (48, "Test", $Selected)
             $handle = WinGetHandle ($Selected)
             MsgBox (48, "Test", $Handle)
             Sleep (100)
             _ScreenCapture_CaptureWnd ($File, $Handle,  0, 0, -1, -1, $Cursor)
             Sleep (100)
             If @Error Then
                MsgBox (48, "Error", "Error capturing the window.")
             Else
                $Complete = MsgBox (52, "Operation Complete", "Window captured successfully, Do you want to open the containing folder?.")
                   If $Complete = 6 Then
                      $Split = _PathSplit($File, $szDrive, $szDir, $szFName, $szExt)
                      ShellExecute ($Split[2])
                   Endif
             EndIf
 EndFunc
 
;-----------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------| Save |----------------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------
 
 Func _FileSaveDialog ($sTitle, $sInitDir, $sFilter = 'All (*.*)', $iOpt = 0, $sDefaultFile = "", $sDefaultExt = "", $mainGUI = 0)
     Local $iFileLen = 65536
     Local $iFlag = BitOR (BitShift (BitAND ($iOpt, 2),-10), BitShift (BitAND ($iOpt,16), 3 ))
     Local $asFLines = StringSplit ( $sFilter, '|'), $asFilter [$asFLines [0] *2+1]
     Local $i, $iStart, $iFinal, $suFilter = '', $ret
     $asFilter [0] = $asFLines [0] *2
     For $i=1 To $asFLines [0]
         $iStart = StringInStr ($asFLines [$i], '(', 0, 1)
         $iFinal = StringInStr ($asFLines [$i], ')', 0,-1)
         $asFilter [$i*2-1] = StringStripWS (StringLeft ($asFLines [$i], $iStart-1), 3)
         $asFilter [$i*2] = StringStripWS (StringTrimRight (StringTrimLeft ($asFLines [$i], $iStart), StringLen ($asFLines [$i]) -$iFinal+1), 3)
         $suFilter = $suFilter & 'byte[' & StringLen ($asFilter [$i*2-1])+1 & '];byte[' & StringLen ($asFilter [$i*2])+1 & '];'
     Next
     Local $uOFN = DllStructCreate ('dword;int;int;ptr;ptr;dword;dword;ptr;dword' & _
         ';ptr;int;ptr;ptr;dword;short;short;ptr;ptr;ptr;ptr;ptr;dword;dword' )
     Local $usTitle  = DllStructCreate ('byte[' & StringLen ($sTitle) +1 & ']')
     Local $usInitDir= DllStructCreate ('byte[' & StringLen ($sInitDir) +1 & ']')
     Local $usFilter = DllStructCreate ($suFilter & 'byte')
     Local $usFile   = DllStructCreate ('char[' & $iFileLen & ']')
     Local $usExtn   = DllStructCreate ('byte[' & StringLen ($sDefaultExt) +1 & ']')
     For $i=1 To $asFilter [0]
         DllStructSetData ($usFilter, $i, $asFilter [$i])
     Next
     DllStructSetData ($usTitle, 1, $sTitle)
     DllStructSetData ($usInitDir, 1, $sInitDir)
     DllStructSetData ($usFile, 1, $sDefaultFile)
     DllStructSetData ($usExtn, 1, $sDefaultExt)
     DllStructSetData ($uOFN,  1, DllStructGetSize($uOFN))
     DllStructSetData ($uOFN,  2, $mainGUI)
     DllStructSetData ($uOFN,  4, DllStructGetPtr ($usFilter))
     DllStructSetData ($uOFN,  7, 1)
     DllStructSetData ($uOFN,  8, DllStructGetPtr ($usFile))
     DllStructSetData ($uOFN,  9, $iFileLen)
     DllStructSetData ($uOFN, 12, DllStructGetPtr ($usInitDir))
     DllStructSetData ($uOFN, 13, DllStructGetPtr ($usTitle))
     DllStructSetData ($uOFN, 14, $iFlag)
     DllStructSetData ($uOFN, 17, DllStructGetPtr ($usExtn))
     DllStructSetData ($uOFN, 23, BitShift (BitAND ($iOpt, 32), 5))
     $ret = DllCall ('comdlg32.dll', 'int', 'GetSaveFileName', _
             'ptr', DllStructGetPtr ($uOFN) )
     If $ret [0] Then
         Return StringStripWS(DllStructGetData ($usFile, 1),3)
     Else
         SetError (1)
         Return ""
     EndIf
 EndFunc
 
 
;-----------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------| Findselected |--------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------
 
 Func Findselected ($Winlist)
    Local $Count, $i, $Selected, $Select[4]
    
    $Count = _GUICtrlListView_GetItemCount($winlist)
    $i = 1
    Do
       $Selected = _GUICtrlListView_GetItemSelected($Winlist, $i)
       $i = $i + 1
    Until $Selected = true or $i = $Count + 1
    If $Selected = true Then 
       $Select = _GUICtrlListView_GetItemTextArray($Winlist, $i - 1)
       Return $Select[1]
    ElseIf $i = $Count + 1 Then
       Return 1
    ElseIf _GUICtrlListView_GetSelectedCount($Winlist) > 1 Then
       Return 2
    Else
       Return 3
    EndIf
 EndFunc
    
;-----------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------| IsVisible? |----------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------
 
 Func IsVisible($handle)
    
   If BitAnd( WinGetState($handle), 2 ) Then 
     Return 1
   Else
     Return 0
   EndIf
 
 EndFunc
 
;-----------------------------------------------------------------------------------------------------------------------------------------------------
;-----------------------------------------------| Script End |----------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------------------------------------------------------------------
It looks to me like Findselected is returning the process name not the window title.

Return $Select[1];should be [0]?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Works as expected when you clean it up and take a few of the errors out:

CODE
#include <guilistview.au3>

#include <guiconstantsex.au3>

#include <process.au3>

#include <ScreenCapture.au3>

#include <file.au3>

Opt('MustDeclareVars', 1)

Opt("TrayIconHide", 1)

Winshot()

Func Winshot()

Local $File, $Complete, $szDrive, $szDir, $szFName, $szExt, $Split, $Cursor, $Cursorbox, $Winlist, $Window, $Array, $Button, $Msg, $Handle, $Selected

$File = _FileSaveDialog("Save WinShot", @HomeDrive, 'Jpeg (*.jpg) | Bitmap (*.bmp) | png (*.png)', 16, "Winshot", ".Jpg", 0)

If @error Then

MsgBox(48, "Error", "Error saving the file.")

Exit

EndIf

$Cursorbox = MsgBox(52, "Cursor", "Do you want the image to include the cursor?")

If $Cursorbox = 6 Then

$Cursor = True

Else

$Cursor = False

EndIf

$Window = GUICreate("Please select a window.", 344, 333)

GUISetState()

$Winlist = GUICtrlCreateListView("Window Title | Process", 10, 40, 330, 279)

_GUICtrlListView_SetColumnWidth($Winlist, 0, 240)

$Button = GUICtrlCreateButton("Select", 260, 10, 80, 20)

GUICtrlCreateLabel("***Please select a window to use.***", 10, 10, 240, 20)

$Array = WinList()

For $i = 1 To $Array[0][0]

If $Array[$i][0] <> "" And BitAND(WinGetState($Array[$i][1]), 2) Then

GUICtrlCreateListViewItem($Array[$i][0] & "|" & _ProcessGetName(WinGetProcess($Array[$i][0])), $Winlist)

EndIf

Next

Do

$Msg = GUIGetMsg()

Until $Msg = $Button Or $Msg = $GUI_EVENT_CLOSE

GUICtrlSetState($Window, $GUI_HIDE)

$Selected = Findselected($Winlist)

MsgBox(48, "Test", $Selected)

$Handle = WinGetHandle($Selected)

MsgBox(48, "Test", $Handle)

Sleep(100)

_ScreenCapture_CaptureWnd($File, $Handle, 0, 0, -1, -1, $Cursor)

Sleep(100)

If @error Then

MsgBox(48, "Error", "Error capturing the window.")

Else

$Complete = MsgBox(52, "Operation Complete", "Window captured successfully, Do you want to open the containing folder?.")

If $Complete = 6 Then

$Split = _PathSplit($File, $szDrive, $szDir, $szFName, $szExt)

ShellExecute($Split[2])

EndIf

EndIf

EndFunc ;==>Winshot

;-----------------------------------------------------------------------------------------------------------------------------------------------------

;-----------------------------------------------| Save |----------------------------------------------------------------------------------------------

;-----------------------------------------------------------------------------------------------------------------------------------------------------

Func _FileSaveDialog($sTitle, $sInitDir, $sFilter = 'All (*.*)', $iOpt = 0, $sDefaultFile = "", $sDefaultExt = "", $mainGUI = 0)

Local $iFileLen = 65536

Local $iFlag = BitOR(BitShift(BitAND($iOpt, 2), -10), BitShift(BitAND($iOpt, 16), 3))

Local $asFLines = StringSplit($sFilter, '|'), $asFilter[$asFLines[0] * 2 + 1]

Local $i, $iStart, $iFinal, $suFilter = '', $ret

$asFilter[0] = $asFLines[0] * 2

For $i = 1 To $asFLines[0]

$iStart = StringInStr($asFLines[$i], '(', 0, 1)

$iFinal = StringInStr($asFLines[$i], ')', 0, -1)

$asFilter[$i * 2 - 1] = StringStripWS(StringLeft($asFLines[$i], $iStart - 1), 3)

$asFilter[$i * 2] = StringStripWS(StringTrimRight(StringTrimLeft($asFLines[$i], $iStart), StringLen($asFLines[$i]) - $iFinal + 1), 3)

$suFilter = $suFilter & 'byte[' & StringLen($asFilter[$i * 2 - 1]) + 1 & '];byte[' & StringLen($asFilter[$i * 2]) + 1 & '];'

Next

Local $uOFN = DllStructCreate('dword;int;int;ptr;ptr;dword;dword;ptr;dword' & _

';ptr;int;ptr;ptr;dword;short;short;ptr;ptr;ptr;ptr;ptr;dword;dword')

Local $usTitle = DllStructCreate('byte[' & StringLen($sTitle) + 1 & ']')

Local $usInitDir = DllStructCreate('byte[' & StringLen($sInitDir) + 1 & ']')

Local $usFilter = DllStructCreate($suFilter & 'byte')

Local $usFile = DllStructCreate('char[' & $iFileLen & ']')

Local $usExtn = DllStructCreate('byte[' & StringLen($sDefaultExt) + 1 & ']')

For $i = 1 To $asFilter[0]

DllStructSetData($usFilter, $i, $asFilter[$i])

Next

DllStructSetData($usTitle, 1, $sTitle)

DllStructSetData($usInitDir, 1, $sInitDir)

DllStructSetData($usFile, 1, $sDefaultFile)

DllStructSetData($usExtn, 1, $sDefaultExt)

DllStructSetData($uOFN, 1, DllStructGetSize($uOFN))

DllStructSetData($uOFN, 2, $mainGUI)

DllStructSetData($uOFN, 4, DllStructGetPtr($usFilter))

DllStructSetData($uOFN, 7, 1)

DllStructSetData($uOFN, 8, DllStructGetPtr($usFile))

DllStructSetData($uOFN, 9, $iFileLen)

DllStructSetData($uOFN, 12, DllStructGetPtr($usInitDir))

DllStructSetData($uOFN, 13, DllStructGetPtr($usTitle))

DllStructSetData($uOFN, 14, $iFlag)

DllStructSetData($uOFN, 17, DllStructGetPtr($usExtn))

DllStructSetData($uOFN, 23, BitShift(BitAND($iOpt, 32), 5))

$ret = DllCall('comdlg32.dll', 'int', 'GetSaveFileName', _

'ptr', DllStructGetPtr($uOFN))

If $ret[0] Then

Return StringStripWS(DllStructGetData($usFile, 1), 3)

Else

SetError(1)

Return ""

EndIf

EndFunc ;==>_FileSaveDialog

;-----------------------------------------------------------------------------------------------------------------------------------------------------

;-----------------------------------------------| Findselected |--------------------------------------------------------------------------------------

;-----------------------------------------------------------------------------------------------------------------------------------------------------

Func Findselected($Winlist)

Local $Count, $i, $Selected, $Select[4]

$Count = _GUICtrlListView_GetItemCount($Winlist)

$i = 1

Do

$Selected = _GUICtrlListView_GetItemSelected($Winlist, $i)

$i = $i + 1

Until $Selected = True Or $i = $Count + 1

If $Selected Then

$Select = _GUICtrlListView_GetItemTextArray($Winlist, $i - 1)

Return $Select[1]

ElseIf $i = $Count + 1 Then

Return 1

ElseIf _GUICtrlListView_GetSelectedCount($Winlist) > 1 Then

Return 2

Else

Return 3

EndIf

ConsoleWrite("WTF" & @CRLF)

EndFunc ;==>Findselected

;-----------------------------------------------------------------------------------------------------------------------------------------------------

;-----------------------------------------------| Script End |----------------------------------------------------------------------------------------

;-----------------------------------------------------------------------------------------------------------------------------------------------------

Edit:

You have to take the space out of " | " here:

GUICtrlCreateListViewItem($Array[$i][0] & " | " & _ProcessGetName(WinGetProcess($Array[$i][0])), $Winlist)

So it should look like:

GUICtrlCreateListViewItem($Array[$i][0] & "|" & _ProcessGetName(WinGetProcess($Array[$i][0])), $Winlist)

Because that space is included in the window handle search, so the result will always be negative.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I haven't been able to try it out as I'm on a school computer , but I can see what you mean and I guessed it might be something like that!

Thanks for the reply, When I finish touching up the other functions I'll put that in the example scripts... see what feedback that gets me...

Thanks!

MDiesel

Share this post


Link to post
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
Sign in to follow this  
Followers 0