Jump to content
Sign in to follow this  
closeupman

Doing Events

Recommended Posts

closeupman

I followed the help files example, but nothing happens when I click on a button or the close button. The script just stays paused.

If I use the regular method of get message then it's ok.

Any ideas?

Thanks

:idiot:

#include <guiconstants.au3>
#include <string.au3>
#include <Array.au3>
;use _ArrayInsert to put letters in array...had problems using subscripting

;used to hold the control id of the button of each letter
dim $letter[26]

;used to center window
$centered=-1

;used to place buttons (i.e. letters)
$Xstart=10
$Ystart=10
$Xoffset=50
$Yoffset=35

;used to let us know when to go to the next line
;to place another row of buttons
$count=0

$mywindow=GUICreate("My 1st Window",400,400,$centered,$centered)


;create the alphabet using buttons
;each letter is a button
;use 65-90 and Chr to turn into a Capital Letter for the button
;index starts at 0 so first letter will be A (i.e. 65+0)

For $index=0 to 25
  
  if $count=5 then
;display 5 letters per line
  ;when count = 5, indicates that you need to go to the next line
  ;and start over
  ;so reset xstart and count
;and move to the next line (increase $YStart)   
    $count=0
    $xstart=10
    $Ystart=$YStart+$Yoffset
  endif ;$count=5
   
 ;create the letter button and place it on the child GUI
 ;and put it in the $letter array
 ;increase the $count 
 ;increase $xstart for the next button

  $letter_id=GUICtrlCreateButton (Chr(65+$index),$Xstart+$Xoffset, $Ystart, 50)
  _ArrayInsert ( $letter, $index,$letter_id )
  GUICtrlSetOnEvent(-1, "LetterChosen")
  $count=$count+1
  $xstart=$xstart+$xoffset

Next;$index=0 to 25

_ArrayDisplay( $letter, "_ArrayDisplay() Test" )

GUISetState (@SW_SHOW)
GuiSetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

While 1
    sleep(10)
;  $msg = GUIGetMsg()

; If $msg = $GUI_EVENT_CLOSE Then
;ExitLoop
 ;else
;if ($msg >= 3) and ($msg <= 28) then
    ;tell which letter was chosen
    ;LetterChosen($msg)
    ;SpeakLetter($msg)
;endif
 ;endif
Wend

Func LetterChosen()
;Function doesn't return any value
;it just displays the letter chosen
;from the display (A-Z)
  msgbox(0,"","HI",2)
  MyCreateLetterChosenGUI(@Gui_CtrlId)
    
 ;msgbox(0,"","You Chose ME " & ConvertToLetter($chosen),3)
 ;SoundPlay("C:\WINNT\Profiles\dfriedman\Desktop\Goofybu.wav",1)
  
EndFunc

Func MyCreateLetterChosenGUI($id)
 ;display the letter by itself
 ;display a pic too with a label
  $myhandle=GUICreate("Fun Time Learning",800,600,0,0,$mywindow)
  $mylabeel=GUICtrlCreateLabel(ConvertToLetter($id),200,200,400,500)
  GUISetState (@SW_SHOW)
  
EndFunc

Func ConvertToLetter($chosenletter)
dim $x
  For $x=0 to 25
    if ($letter[$x]>0) and ($chosenletter > 0) then
; if the two values(button control id)
; are equal then that is the letter chosen.
;so do whatever you want associated with that letter
;and get out of this For..Next by setting $x to the
;end value
    if $letter[$x] = $chosenletter then
      return Chr(65+$x)
      $x=25
        endif
    endif
   Next
EndFunc

Func SpecialEvents()
;if user click X or right click and close 
;then exit program
    If $msg = $GUI_EVENT_CLOSE Then
        Exit
    EndIf
EndFunc

Share this post


Link to post
Share on other sites
killaz219

Maybe it's because the

;  $msg = GUIGetMsg()

; If $msg = $GUI_EVENT_CLOSE Then
;ExitLoop

Is commented out

And same with the button one.

Edited by killaz219

Share this post


Link to post
Share on other sites
closeupman

I commented it out to try the SetOnEvent's. the regular guiget message works when I uncomment it. Didn't ask that.

What I'm asking is I used the help files

While 1

Sleep (10)

Wend

and the SetOnEvents, but it seems like nothing happens

Maybe it's because the

;  $msg = GUIGetMsg()

; If $msg = $GUI_EVENT_CLOSE Then
;ExitLoop

Is commented out

And same with the button one.

<{POST_SNAPBACK}>

Share this post


Link to post
Share on other sites
killaz219

Well maybe it's because in the function "specialevents" it checks

If $msg = $GUI_EVENT_CLOSE Then

but you are not getting the message with GUIGetMsg

Edited by killaz219

Share this post


Link to post
Share on other sites
jpm

When you use event the GuiGetMsg never work so inside the functions you have to use @GUI_CONTROLID instead of your $msg :idiot:

reread the doc about event don't forget OPt('GUIOnEventMode ',1) if you use events

OnEvent functions are only called when the option GUIOnEventMode is set to 1 - when in this mode GUIGetMsg is NOT used at all.

Share this post


Link to post
Share on other sites
closeupman

Well maybe it's because in the function "specialevents" it checks

If $msg = $GUI_EVENT_CLOSE Then

but you are not getting the message with GUIGetMsg

<{POST_SNAPBACK}>

There's no need for that....if I uncomment it's find....but if I want to use the real windows way of events. It just seems to pause. Here's the example from the help file...no GuiGetMsg used....Nevermind....I looked at the help file and saw the difference. I forgot the

Opt("GuiOnEventMode", 1)

dang little things.... :idiot:

Share this post


Link to post
Share on other sites
closeupman

When you use event the GuiGetMsg never work so inside the functions you have to use @GUI_CONTROLID instead of your $msg :D

reread the doc about event don't forget OPt('GUIOnEventMode ',1) if you use events

<{POST_SNAPBACK}>

Yep, didn't read the part b4..Just saw about events and wanting to do it....Sometimes miss the small things...

Thanks for your reply. :idiot:

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.