Jump to content

calling functions from a child window


Recommended Posts

is there something different i need to do when calling functions from a child window? the msgbox isnt coming up at all.

Func Ask_User()

Global $string=""

GUICreate("Enter Username:", 100,80, -1, -1, $WS_EX_MDICHILD)

$user=GUICtrlCreateInput("",10,10,70,25)

$btn2 = GUICtrlCreateButton ("OK", 90,13,40,20,0x0300)

GUICtrlSetOnEvent($btn2, "Set_User")

GUISetState()

while 1

If $string<>GUICtrlRead($user) Then

GUICtrlSetData($user,StringUpper(GUICtrlRead($user)))

$string=GUICtrlRead($user)

EndIf

sleep(10)

WEnd

EndFunc

Func Set_User ()

MsgBox(0,"", GUICtrlRead($user))

Exit

EndFunc

Edited by gcue
Link to comment
Share on other sites

This works for me... didn't really do anything except changed where the global vars were (added $user to global var)

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

Opt("GUIOnEventMode", 1)

Global $string=""
Global $user

Ask_User()

Func Ask_User()

GUICreate("Enter Username:", 100,80, -1, -1, $WS_EX_MDICHILD)
$user=GUICtrlCreateInput("",10,10,70,25)

$btn2 = GUICtrlCreateButton ("OK", 90,13,40,20,0x0300)
GUICtrlSetOnEvent($btn2, "Set_User")

GUISetState()
while 1
If $string<>GUICtrlRead($user) Then
GUICtrlSetData($user,StringUpper(GUICtrlRead($user)))
$string=GUICtrlRead($user)
EndIf

sleep(10)
WEnd
EndFunc


Func Set_User ()
MsgBox(0,"", GUICtrlRead($user))
Exit
EndFunc

You did remember Opt("GUIOnEventMode", 1) right?

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to comment
Share on other sites

yep i have it all there..

but the msgbox doesnt pop up

bah!

This works for me... didn't really do anything except changed where the global vars were (added $user to global var)

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

Opt("GUIOnEventMode", 1)

Global $string=""
Global $user

Ask_User()

Func Ask_User()

GUICreate("Enter Username:", 100,80, -1, -1, $WS_EX_MDICHILD)
$user=GUICtrlCreateInput("",10,10,70,25)

$btn2 = GUICtrlCreateButton ("OK", 90,13,40,20,0x0300)
GUICtrlSetOnEvent($btn2, "Set_User")

GUISetState()
while 1
If $string<>GUICtrlRead($user) Then
GUICtrlSetData($user,StringUpper(GUICtrlRead($user)))
$string=GUICtrlRead($user)
EndIf

sleep(10)
WEnd
EndFunc


Func Set_User ()
MsgBox(0,"", GUICtrlRead($user))
Exit
EndFunc

You did remember Opt("GUIOnEventMode", 1) right?

Link to comment
Share on other sites

Is there more to your code? If you run just what I posted it doesn't work? I'm running autoit ver 3.2.12, win xp...hmm... restart your computer maybe...

What about the example for GUICtrlSetOnEvent in the help file, does that run?

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to comment
Share on other sites

actually it works.. the small snipet i sent you.. but something else is affecting it.. dunno:

Opt("GUIOnEventMode", 1)

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#Include <Constants.au3>

#include <file.au3>

Global $AD_file, $NDS_file, $initials, $group

$toolsdir="C:\CRS\Tools"

If Not FileExists($toolsdir) Then

DirCreate($toolsdir)

EndIf

If Not FileExists($toolsdir & "\Account_Info") Then

DirCreate($toolsdir & "\Account_Info")

EndIf

GUICreate("Account Info v0.1", 320,40); WS_EX_ACCEPTFILES

$lookupmenu = GUICtrlCreateMenu ("&Lookup")

$byuseritem = GUICtrlCreateMenuitem ("By User",$lookupmenu)

GUICtrlSetOnEvent(-1,"By_User1")

$bygroupitem = GUICtrlCreateMenuitem ("By Group",$lookupmenu)

GUICtrlSetOnEvent(-1,"By_Group")

$byuserlistitem = GUICtrlCreateMenuitem ("By User List",$lookupmenu)

GUICtrlSetOnEvent(-1,"By_UserList")

$seperatoritem = GUICtrlCreateMenuitem ("--------",$lookupmenu)

$bydgrouplistitem = GUICtrlCreateMenuitem ("By Domain Group List",$lookupmenu)

GUICtrlSetOnEvent(-1,"By_dGroupList")

$byngrouplistitem = GUICtrlCreateMenuitem ("By Novell Group List",$lookupmenu)

GUICtrlSetOnEvent(-1,"By_nGroupList")

$helpmenu = GUICtrlCreateMenu ("&Help")

$changeitem = GUICtrlCreateMenuitem ("Change Log",$helpmenu)

GUICtrlSetOnEvent(-1,"Change")

$helpitem = GUICtrlCreateMenuitem ("About",$helpmenu)

GUICtrlSetOnEvent(-1,"About")

GUISetOnEvent($GUI_EVENT_CLOSE, "Xbutton")

GUISetState()

while 1

sleep(10)

WEnd

Func By_User1()

Global $string=""

GUICreate("Enter Username:", 100,80, -1, -1, $WS_EX_MDICHILD)

$initials=GUICtrlCreateInput("",10,10,70,25)

$btn2 = GUICtrlCreateButton ("OK", 90,13,40,20,0x0300)

GUICtrlSetOnEvent($btn2, "By_User2")

GUISetState()

while 1

If $string<>GUICtrlRead($initials) Then

GUICtrlSetData($initials,StringUpper(GUICtrlRead($initials)))

$string=GUICtrlRead($initials)

EndIf

sleep(10)

WEnd

EndFunc

Func By_User2()

$initials_AD_file = ($toolsdir & "\Account_Info\" & GUICtrlRead($initials) & "_DOMAIN.txt")

$initials_NDS_file = ($toolsdir & "\Account_Info\" & GUICtrlRead($initials) & "_NOVELL.txt")

RunWait(@ComSpec & " /c " & "net user " & GUICtrlRead($initials) & " /domain > " & $initials_AD_file)

RunWait(@ComSpec & " /c " & "cx .OU=NA.CAPGROUP /r")

RunWait(@ComSpec & " /c " & "nlist user=" & GUICtrlRead($initials) & " /d /s > " & $initials_NDS_file)

Run(@WindowsDir & "\explorer.exe " & $toolsdir & "\Account_Info")

EndFunc

Func By_Group()

Global $string=""

GUICreate("Enter Group:", 100,80, -1, -1, $WS_EX_MDICHILD)

$group=GUICtrlCreateInput("",10,10,70,25)

$btn2 = GUICtrlCreateButton ("OK", 90,13,40,20,0x0300)

GUICtrlSetOnEvent($btn2, "By_Group2")

GUISetState()

while 1

If $string<>GUICtrlRead($group) Then

GUICtrlSetData($group,StringUpper(GUICtrlRead($group)))

$string=GUICtrlRead($group)

EndIf

sleep(10)

WEnd

EndFunc

Func By_Group2()

$group_AD_file = ($toolsdir & "\Account_Info\" & GUICtrlRead($group) & "_DOMAIN.txt")

$group_NDS_file = ($toolsdir & "\Account_Info\" & GUICtrlRead($group) & "_NOVELL.txt")

RunWait(@ComSpec & " /c " & "net group " & GUICtrlRead($group) & " /domain > " & $AD_file)

RunWait(@ComSpec & " /c " & "cx .OU=NA.CAPGROUP /r")

RunWait(@ComSpec & " /c " & "nlist group=" & GUICtrlRead($group) & " /d /s > " & $NDS_file)

Run(@WindowsDir & "\explorer.exe " & $toolsdir & "\Account_Info")

EndFunc

Func By_UserList()

$message = "Please choose your user list."

$afile = FileOpenDialog($message, @DesktopDir & "\", "Text Files (*.txt)", 1 + 4 )

If @error Then

MsgBox(262144,"Account Info v0.1","No file was chosen")

Return

EndIf

Dim $users

If Not _FileReadToArray($afile,$users) Then

Exit

EndIf

For $x = 1 to $users[0]

$stats=GUICtrlCreateLabel("Gathering Results for " & $users[$x] & " ", 10, 55)

$initials_AD_file = ($toolsdir & "\Account_Info\" & $users[$x] & "_DOMAIN.txt")

$initials_NDS_file = ($toolsdir & "\Account_Info\" & $users[$x] & "_NOVELL.txt")

RunWait(@ComSpec & " /c " & "net user " & $users[$x] & " /domain > " & $initials_AD_file)

RunWait(@ComSpec & " /c " & "nlist user=" & $users[$x] & " /d > " & $initials_NDS_file)

Next

$stats=GUICtrlCreateLabel("Complete. ", 10, 55)

Run(@WindowsDir & "\explorer.exe " & $toolsdir & "\Account_Info")

EndFunc

Func By_dGroupList()

$message = "Please choose your group list."

$afile = FileOpenDialog($message, @DesktopDir & "\", "Text Files (*.txt)", 1 + 4 )

If @error Then

MsgBox(262144,"Account Info v0.1","No file was chosen")

Return

EndIf

Dim $dgroups

If Not _FileReadToArray($afile,$dgroups) Then

Exit

EndIf

For $x = 1 to $dgroups[0]

$stats=GUICtrlCreateLabel("Gathering Results from " & $dgroups[$x] & " ", 10, 55)

$initials_AD_file = ($toolsdir & "\Account_Info\" & $dgroups[$x] & "_DOMAIN.txt")

RunWait(@ComSpec & " /c " & "net user " & $dgroups[$x] & " /domain > " & $initials_AD_file)

Next

$stats=GUICtrlCreateLabel("Complete. ", 10, 55)

Run(@WindowsDir & "\explorer.exe " & $toolsdir & "\Account_Info")

EndFunc

Func By_nGroupList()

$message = "Please choose your group list."

$afile = FileOpenDialog($message, @DesktopDir & "\", "Text Files (*.txt)", 1 + 4 )

If @error Then

MsgBox(262144,"Account Info v0.1","No file was chosen")

Return

EndIf

Dim $ngroups

If Not _FileReadToArray($afile,$ngroups) Then

Exit

EndIf

For $x = 1 to $ngroups[0]

$stats=GUICtrlCreateLabel("Gathering Results from " & $ngroups[$x] & " ", 10, 55)

$initials_NDS_file = ($toolsdir & "\Account_Info\" & $ngroups[$x] & "_NOVELL.txt")

RunWait(@ComSpec & " /c " & "nlist group=" & $ngroups[$x] & " /d > " & $initials_NDS_file)

Next

$stats=GUICtrlCreateLabel("Complete. ", 10, 55)

Run(@WindowsDir & "\explorer.exe " & $toolsdir & "\Account_Info")

EndFunc

Func Change()

EndFunc

Func About()

EndFunc

Func Xbutton()

Exit

EndFunc

Edited by gcue
Link to comment
Share on other sites

I couldn't run the entire code so I kinda hacked it down to size a little, but I believe the problem is in your While loops inside the function...

this is the code I'm using

Opt("GUIOnEventMode", 1)
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Constants.au3>
;#include <file.au3>
Global Const $ES_UPPERCASE = 0x0008
Global $AD_file, $NDS_file, $initials, $group

;$toolsdir="C:\CRS\Tools"

;~ If Not FileExists($toolsdir) Then
;~ DirCreate($toolsdir)
;~ EndIf

;~ If Not FileExists($toolsdir & "\Account_Info") Then
;~ DirCreate($toolsdir & "\Account_Info")
;~ EndIf

GUICreate("Account Info v0.1", 320,40); WS_EX_ACCEPTFILES

$lookupmenu = GUICtrlCreateMenu ("&Lookup")
$byuseritem = GUICtrlCreateMenuitem ("By User",$lookupmenu)
GUICtrlSetOnEvent(-1,"By_User1")
$bygroupitem = GUICtrlCreateMenuitem ("By Group",$lookupmenu)
;GUICtrlSetOnEvent(-1,"By_Group")
$byuserlistitem = GUICtrlCreateMenuitem ("By User List",$lookupmenu)
;GUICtrlSetOnEvent(-1,"By_UserList")

$seperatoritem = GUICtrlCreateMenuitem ("--------",$lookupmenu)

$bydgrouplistitem = GUICtrlCreateMenuitem ("By Domain Group List",$lookupmenu)
;GUICtrlSetOnEvent(-1,"By_dGroupList")
$byngrouplistitem = GUICtrlCreateMenuitem ("By Novell Group List",$lookupmenu)
;GUICtrlSetOnEvent(-1,"By_nGroupList")

$helpmenu = GUICtrlCreateMenu ("&Help")
$changeitem = GUICtrlCreateMenuitem ("Change Log",$helpmenu)
;GUICtrlSetOnEvent(-1,"Change")
$helpitem = GUICtrlCreateMenuitem ("About",$helpmenu)
;GUICtrlSetOnEvent(-1,"About")

;GUISetOnEvent($GUI_EVENT_CLOSE, "Xbutton")

GUISetState()
while 1
sleep(10)
WEnd

Func By_User1()
    ;MsgBox(0, "", "its working")
Global $string=""
GUICreate("Enter Username:", 100,80, -1, -1, $WS_EX_MDICHILD)
$initials=GUICtrlCreateInput("",10,10,70,25, $ES_UPPERCASE)

$btn2 = GUICtrlCreateButton ("OK", 90,13,40,20,0x0300)
GUICtrlSetOnEvent($btn2, "By_User2")

GUISetState()
;~ while 1
;~ If $string<>GUICtrlRead($initials) Then
;~ GUICtrlSetData($initials,StringUpper(GUICtrlRead($initials)))
;~ $string=GUICtrlRead($initials)
;~ EndIf
;~ sleep(10)
;~ WEnd
EndFunc


Func By_User2()
    MsgBox(0,"", GUICtrlRead($initials))
EndFunc

Do you only have that to ensure the input is uppercase? If so you can use $ES_UPPERCASE instead. The constant isn't included in any of your includes so just add Global Const $ES_UPPERCASE = 0x0008.

Hopefully this helps!

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to comment
Share on other sites

u were right it was in stuck in teh while loop

thanks for giving me a work around for the the CAPS!!

now im trying to close out that child window.. exit takes out the parent and child.

any ideas?

Edited by gcue
Link to comment
Share on other sites

Hard to take your code and just add to it since I half mangled it to be able to run it. Instead look at this...

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

Opt("GUIOnEventMode", 1)

Global Const $ES_UPPERCASE = 0x0008
Global $initials
Global $parent1
Global $child1

$parent1 = GUICreate("Parent1")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
$spawnchild = GUICtrlCreateButton("Child", 10, 30, 50)
GUICtrlSetOnEvent(-1, "spawnchild")

GUISetState()
While 1
    Sleep(10)
WEnd


Func spawnchild()
    $child1 = GUICreate("Enter Username:", 150,80, -1, -1, $WS_EX_MDICHILD) ;works with/without $WS_EX_MDICHILD
    ;$child1 = GUICreate("Enter Username:", 150,80, -1, -1)
    $initials = GUICtrlCreateInput("",10,10,70,25, $ES_UPPERCASE)
    $btn2 = GUICtrlCreateButton ("OK", 90,13,40,20,0x0300)
    GUICtrlSetOnEvent($btn2, "By_User2")
    GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
    GUISetState()
EndFunc


Func SpecialEvents()
    Select
        Case @GUI_WinHandle = $parent1
            MsgBox(0, "Close Pressed", "This will exit the script.")
            Exit            
        Case @GUI_WinHandle = $child1
            MsgBox(0, "Close Pressed", "This will close(GUIDelete) ONLY the child GUI.")
            GUISetState($child1, GUIDelete($child1))
    EndSelect
EndFunc

Func By_User2()
    MsgBox(0,"", GUICtrlRead($initials))
EndFunc

I wanted to make the code stand-alone; but essentially you just have to check what the @GUI_WinHandle is to see what gui spawned the event close, and then take the appropriate action.

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
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...