Sign in to follow this  
Followers 0
Cha0sBG

What's Wrong Here ?

14 posts in this topic

Hello again guys,

Umm anyone can tell me what's wrong here?

My script is sapouse to get the title of an active window from PID.

And to minimize , maximize , hide , show that window ^^ from tray menu ^^

So here is my script:

#Include <Constants.au3>
#include <WindowsConstants.au3>
#include <Process.au3>
#include <Array.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)
$exe_name = "sro_client.exe"
$winlist = ProcessList ($exe_name)

GLOBAL $combo

$settingsitem   = TrayCreateMenu("Functions")
$hidesro = TrayCreateItem("Hide Silkroad", $settingsitem)
$showsro = TrayCreateItem("Show Silkroad", $settingsitem)
$minsro = TrayCreateItem("Minimize Silkroad", $settingsitem)
$maxsro = TrayCreateItem("Maximize Silkroad", $settingsitem)
TrayCreateItem("")
$aboutitem      = TrayCreateItem("About")
TrayCreateItem("")
$exititem       = TrayCreateItem("Exit")

For $i = 1 To $winlist[0][0]
    GUICtrlSetData ($combo, WinGetTitle(_ProcessGetWinEx($winlist[$i][0],"","","",True)))
Next

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $aboutitem
            Msgbox(0,"Credits:","Made By Cha0sBG®")
        Case $msg = $exititem
            ExitLoop
        Case $msg = $hidesro
            WinSetState($combo, "", @SW_HIDE)
        Case $msg = $showsro
            WinSetState($combo, "", @SW_SHOW)
        Case $msg = $minsro
            WinSetState($combo, "", @SW_MINIMIZE)
        Case $msg = $maxsro
            WinSetState($combo, "", @SW_MAXIMIZE)
    EndSelect
WEnd

Exit

Func _ProcessGetWinEx($ivPid, $svClass = "", $svTitle = "", $svText = "", $ivReturnOnlyFirstMatch = False)
    $ivPid = ProcessExists($ivPid)
    If Not $ivPid Then Return(SetError(1, 0, 0))
   
    Local $avwArray = WinList()
    Local $avRet[1] = [0]
 
    For $i = 1 To $avwArray[0][0]
        $avClass = DllCall("User32.dll", "int", "GetClassName", "hwnd", $avwArray[$i][1], "str", "", "int", 4096)
        If WinGetProcess($avwArray[$i][1]) = $ivPid Then
            If $svClass = "" Or (IsArray($avClass) And $avClass[2] = $svClass) Then
                If ($svTitle = "" Or StringInStr($avwArray[$i][0], $svTitle)) And ($svText = "" Or StringInStr(WinGetText($avwArray[$i][1]), $svText)) Then
                    $avRet[0] += 1
                    ReDim $avRet[$avRet[0]+1]
                    $avRet[$avRet[0]] = $avwArray[$i][1]
                    If $ivReturnOnlyFirstMatch Then
                        $avRet = $avret[1]
                        ExitLoop
                    EndIf
                EndIf
            EndIf
        EndIf
    Next
 
    Return $avRet

EndFunc

If anyone can help i will be grateful ^^


Have Questions About GUI (Graphical User Interface) ? Post Them Here :GUI Help And Support ForumHave Questions About General AutoIt ? Post Them Here : General Help And Support ForumNew To AutoIt ? Be Shure To Check Out The FaQ's (Frequently Asked Questions) Or FaQ ¹ There You May Find Great Help That Will Guide You True The Wonderful Programming Language AutoItOthere Good Place To Get Some Knolage Of AutoIt Is The Example Script ForumNotice A Bug ? Please Go And Report it At Bug Report Section And Help The Devolepers Of AutoIt Update And Fix The Programming LanguageWant To Thank The People For This Great Forum And Programming Language ? Then DonateWhen You Found The Answer Your Looking For Please Add [Resolved] To The Thread's Name That Will Show Otheres That You Have Found What Your Looking For And They Whount Have To Enter The Thread.

Share this post


Link to post
Share on other sites



Try

Return $avRet[0]


When the words fail... music speaks

Share this post


Link to post
Share on other sites

umm

AutoIt Error:

Return $avRet[0]

Subcript used with non-array variable :S


Have Questions About GUI (Graphical User Interface) ? Post Them Here :GUI Help And Support ForumHave Questions About General AutoIt ? Post Them Here : General Help And Support ForumNew To AutoIt ? Be Shure To Check Out The FaQ's (Frequently Asked Questions) Or FaQ ¹ There You May Find Great Help That Will Guide You True The Wonderful Programming Language AutoItOthere Good Place To Get Some Knolage Of AutoIt Is The Example Script ForumNotice A Bug ? Please Go And Report it At Bug Report Section And Help The Devolepers Of AutoIt Update And Fix The Programming LanguageWant To Thank The People For This Great Forum And Programming Language ? Then DonateWhen You Found The Answer Your Looking For Please Add [Resolved] To The Thread's Name That Will Show Otheres That You Have Found What Your Looking For And They Whount Have To Enter The Thread.

Share this post


Link to post
Share on other sites

And for you what don't work? I can't test because $exe_name = "sro_client.exe"


When the words fail... music speaks

Share this post


Link to post
Share on other sites

well just change "sro_client.exe" with notepad.exe :P


Have Questions About GUI (Graphical User Interface) ? Post Them Here :GUI Help And Support ForumHave Questions About General AutoIt ? Post Them Here : General Help And Support ForumNew To AutoIt ? Be Shure To Check Out The FaQ's (Frequently Asked Questions) Or FaQ ¹ There You May Find Great Help That Will Guide You True The Wonderful Programming Language AutoItOthere Good Place To Get Some Knolage Of AutoIt Is The Example Script ForumNotice A Bug ? Please Go And Report it At Bug Report Section And Help The Devolepers Of AutoIt Update And Fix The Programming LanguageWant To Thank The People For This Great Forum And Programming Language ? Then DonateWhen You Found The Answer Your Looking For Please Add [Resolved] To The Thread's Name That Will Show Otheres That You Have Found What Your Looking For And They Whount Have To Enter The Thread.

Share this post


Link to post
Share on other sites

Work fine for me (notepad.exe)


When the words fail... music speaks

Share this post


Link to post
Share on other sites
:P well can u give me bug free script with all fixed so i can try ? :P

Have Questions About GUI (Graphical User Interface) ? Post Them Here :GUI Help And Support ForumHave Questions About General AutoIt ? Post Them Here : General Help And Support ForumNew To AutoIt ? Be Shure To Check Out The FaQ's (Frequently Asked Questions) Or FaQ ¹ There You May Find Great Help That Will Guide You True The Wonderful Programming Language AutoItOthere Good Place To Get Some Knolage Of AutoIt Is The Example Script ForumNotice A Bug ? Please Go And Report it At Bug Report Section And Help The Devolepers Of AutoIt Update And Fix The Programming LanguageWant To Thank The People For This Great Forum And Programming Language ? Then DonateWhen You Found The Answer Your Looking For Please Add [Resolved] To The Thread's Name That Will Show Otheres That You Have Found What Your Looking For And They Whount Have To Enter The Thread.

Share this post


Link to post
Share on other sites

:P well can u give me bug free script with all fixed so i can try ? :P

Hey I replace only sro_client.exe with notepad.exe and script run without error and I can use all tray menu functions.


When the words fail... music speaks

Share this post


Link to post
Share on other sites

Hey I replace only sro_client.exe with notepad.exe and script run without error and I can use all tray menu functions.

Your PC is very different to mine then :P

There are a number of things wrong with the script.

There is no gui created to hold the combo and no combo is created.

The Global variable $combo will be initialized to "". Therefore, when you say WinsetState($combo,"",@SW_SHOW) you will be saying WInSEtSTate("","",@SW_SHOW) which means show the currently active window.

The function _ProcessGetWinEx is being passed the name of the process when it should be passed the PID of the process.

Here's a quick correction

#Include <Constants.au3>
#include <WindowsConstants.au3>
#include <Process.au3>
#include <Array.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)
$exe_name = "notepad.exe"
$winlist = ProcessList ($exe_name)

GLOBAL $gui,$combo;<----------------------------------added
$gui = GUICreate("");<----------------------------------added
$combo = GUICtrlCreateCombo("",10,10,180,25);<--------------added
$settingsitem   = TrayCreateMenu("Functions")
$hidesro = TrayCreateItem("Hide Silkroad", $settingsitem)
$showsro = TrayCreateItem("Show Silkroad", $settingsitem)
$minsro = TrayCreateItem("Minimize Silkroad", $settingsitem)
$maxsro = TrayCreateItem("Maximize Silkroad", $settingsitem)
TrayCreateItem("")
$aboutitem    = TrayCreateItem("About")
TrayCreateItem("")
$exititem      = TrayCreateItem("Exit")

For $i = 1 To $winlist[0][0]
    $title = WinGetTitle(_ProcessGetWinEx($winlist[$i][1],"","","",true));<-----------changed
    ConsoleWrite($title & @CRLF)
    GUICtrlSetData ($combo, $title)
Next

TraySetState()

While guigetmsg() <> -3
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $aboutitem
            Msgbox(0,"Credits:","Made By Cha0sBG®")
        Case $msg = $exititem
            ExitLoop
        Case $msg = $hidesro
            WinSetState($gui, "", @SW_HIDE);<----------changed
        Case $msg = $showsro
            WinSetState($gui, "", @SW_SHOW);<----------changed
        Case $msg = $minsro
            WinSetState($gui, "", @SW_MINIMIZE);<----------changed
        Case $msg = $maxsro
            WinSetState($gui, "", @SW_MAXIMIZE);<----------changed
    EndSelect
WEnd

Exit

Func _ProcessGetWinEx($ivPid, $svClass = "", $svTitle = "", $svText = "", $ivReturnOnlyFirstMatch = False)
    $ivPid = ProcessExists($ivPid)
    If Not $ivPid Then Return(SetError(1, 0, 0))
   
    Local $avwArray = WinList()
    Local $avRet[1] = [0]
 
    For $i = 1 To $avwArray[0][0]
        $avClass = DllCall("User32.dll", "int", "GetClassName", "hwnd", $avwArray[$i][1], "str", "", "int", 4096)
        If WinGetProcess($avwArray[$i][1]) = $ivPid Then
            If $svClass = "" Or (IsArray($avClass) And $avClass[2] = $svClass) Then
                If ($svTitle = "" Or StringInStr($avwArray[$i][0], $svTitle)) And ($svText = "" Or StringInStr(WinGetText($avwArray[$i][1]), $svText)) Then
                    $avRet[0] += 1
                    ReDim $avRet[$avRet[0]+1]
                    $avRet[$avRet[0]] = $avwArray[$i][1]
                    If $ivReturnOnlyFirstMatch Then
                        $avRet = $avret[1]
                        ExitLoop
                    EndIf
                EndIf
            EndIf
        EndIf
    Next
 
    Return $avRet

EndFunc

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

Your PC is very different to mine then :o

There are a number of things wrong with the script.

There is no gui created to hold the combo and no combo is created.

The Global variable $combo will be initialized to "". Therefore, when you say WinsetState($combo,"",@SW_SHOW) you will be saying WInSEtSTate("","",@SW_SHOW) which means show the currently active window.

The function _ProcessGetWinEx is being passed the name of the process when it should be passed the PID of the process.

Here's a quick correction

#Include <Constants.au3>
#include <WindowsConstants.au3>
#include <Process.au3>
#include <Array.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)
$exe_name = "notepad.exe"
$winlist = ProcessList ($exe_name)

GLOBAL $gui,$combo;<----------------------------------added
$gui = GUICreate("");<----------------------------------added
$combo = GUICtrlCreateCombo("",10,10,180,25);<--------------added
$settingsitem   = TrayCreateMenu("Functions")
$hidesro = TrayCreateItem("Hide Silkroad", $settingsitem)
$showsro = TrayCreateItem("Show Silkroad", $settingsitem)
$minsro = TrayCreateItem("Minimize Silkroad", $settingsitem)
$maxsro = TrayCreateItem("Maximize Silkroad", $settingsitem)
TrayCreateItem("")
$aboutitem    = TrayCreateItem("About")
TrayCreateItem("")
$exititem      = TrayCreateItem("Exit")

For $i = 1 To $winlist[0][0]
    $title = WinGetTitle(_ProcessGetWinEx($winlist[$i][1],"","","",true));<-----------changed
    ConsoleWrite($title & @CRLF)
    GUICtrlSetData ($combo, $title)
Next

TraySetState()

While guigetmsg() <> -3
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $aboutitem
            Msgbox(0,"Credits:","Made By Cha0sBG®")
        Case $msg = $exititem
            ExitLoop
        Case $msg = $hidesro
            WinSetState($gui, "", @SW_HIDE);<----------changed
        Case $msg = $showsro
            WinSetState($gui, "", @SW_SHOW);<----------changed
        Case $msg = $minsro
            WinSetState($gui, "", @SW_MINIMIZE);<----------changed
        Case $msg = $maxsro
            WinSetState($gui, "", @SW_MAXIMIZE);<----------changed
    EndSelect
WEnd

Exit

Func _ProcessGetWinEx($ivPid, $svClass = "", $svTitle = "", $svText = "", $ivReturnOnlyFirstMatch = False)
    $ivPid = ProcessExists($ivPid)
    If Not $ivPid Then Return(SetError(1, 0, 0))
   
    Local $avwArray = WinList()
    Local $avRet[1] = [0]
 
    For $i = 1 To $avwArray[0][0]
        $avClass = DllCall("User32.dll", "int", "GetClassName", "hwnd", $avwArray[$i][1], "str", "", "int", 4096)
        If WinGetProcess($avwArray[$i][1]) = $ivPid Then
            If $svClass = "" Or (IsArray($avClass) And $avClass[2] = $svClass) Then
                If ($svTitle = "" Or StringInStr($avwArray[$i][0], $svTitle)) And ($svText = "" Or StringInStr(WinGetText($avwArray[$i][1]), $svText)) Then
                    $avRet[0] += 1
                    ReDim $avRet[$avRet[0]+1]
                    $avRet[$avRet[0]] = $avwArray[$i][1]
                    If $ivReturnOnlyFirstMatch Then
                        $avRet = $avret[1]
                        ExitLoop
                    EndIf
                EndIf
            EndIf
        EndIf
    Next
 
    Return $avRet

EndFunc
I don't see that combo :P but the script was running. :P only that without combo :D

When the words fail... music speaks

Share this post


Link to post
Share on other sites

now when i hit maximize it maximizes the gui oO


Have Questions About GUI (Graphical User Interface) ? Post Them Here :GUI Help And Support ForumHave Questions About General AutoIt ? Post Them Here : General Help And Support ForumNew To AutoIt ? Be Shure To Check Out The FaQ's (Frequently Asked Questions) Or FaQ ¹ There You May Find Great Help That Will Guide You True The Wonderful Programming Language AutoItOthere Good Place To Get Some Knolage Of AutoIt Is The Example Script ForumNotice A Bug ? Please Go And Report it At Bug Report Section And Help The Devolepers Of AutoIt Update And Fix The Programming LanguageWant To Thank The People For This Great Forum And Programming Language ? Then DonateWhen You Found The Answer Your Looking For Please Add [Resolved] To The Thread's Name That Will Show Otheres That You Have Found What Your Looking For And They Whount Have To Enter The Thread.

Share this post


Link to post
Share on other sites

now when i hit maximize it maximizes the gui oO

What do you want it to do?

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

as i sayd it's sapous to get the title from procces id of a game i play and i want it to minimize the game ...


Have Questions About GUI (Graphical User Interface) ? Post Them Here :GUI Help And Support ForumHave Questions About General AutoIt ? Post Them Here : General Help And Support ForumNew To AutoIt ? Be Shure To Check Out The FaQ's (Frequently Asked Questions) Or FaQ ¹ There You May Find Great Help That Will Guide You True The Wonderful Programming Language AutoItOthere Good Place To Get Some Knolage Of AutoIt Is The Example Script ForumNotice A Bug ? Please Go And Report it At Bug Report Section And Help The Devolepers Of AutoIt Update And Fix The Programming LanguageWant To Thank The People For This Great Forum And Programming Language ? Then DonateWhen You Found The Answer Your Looking For Please Add [Resolved] To The Thread's Name That Will Show Otheres That You Have Found What Your Looking For And They Whount Have To Enter The Thread.

Share this post


Link to post
Share on other sites

as i sayd it's sapous to get the title from procces id of a game i play and i want it to minimize the game ...

Better make sure I understand before I put any more time into an answer!

When you click on maximize your first script requested the $combo to maxiimize, but you want it to minimze the game. I assume you mean that the Minimize and Maximize options are for minimizing and maximizing the game, the title of which has been selected in the combo. Is that correct?


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

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