Normally I don't use the GUI-On-Event-Mode. But you could try this, if you want to solve the problem with GUI-On-Event-Mode:
....
GUICtrlSetOnEvent ( $Button1, "ok" )
GUICtrlSetOnEvent ( $Button2, "close" )
while 1
Sleep(1000)
WEnd
Func ok()
Do what you want
EndFunc
Func close()
Do what you want 2
EndFunc