IonicWind Software

IWBasic => General Questions => Topic started by: talun on October 24, 2008, 04:09:15 AM

Title: ONCONTROL question
Post by: talun on October 24, 2008, 04:09:15 AM
Hi,

can anyone say me, what is the correct syntax for using the ONCONTROL statement with a button? I'm trying the below istruction with no result

ONCONTROL d1,BUTTON_2, BN_CLICKED,&MyButton

Thanks!  :)

Sergio
Title: Re: ONCONTROL question
Post by: LarryMc on October 24, 2008, 05:04:01 AM
Not absolutely sure because I haven't tried that functionality yet but I'd try this:

oncontrol d1, button_2, @IDLBUTTONUP, &Mybutton  <- doesn't work wrong constant

oncontrol d1, button_2, @IDCONTROL, &Mybutton  <- doesn't work but should(I think)

Larry
Title: Re: ONCONTROL question
Post by: LarryMc on October 24, 2008, 06:03:03 AM
If you use this:
OnMessage d1, @IDControl, &MyButton
and then do a Select @ControlIDin the MyButton sub to see which button it will work.

We'll just have to wait until Paul is on to find out how he intended it to work?

Larry
Title: Re: ONCONTROL question
Post by: talun on October 24, 2008, 06:22:20 AM
Hi Larry,
thanks for your suggestions but it doesn't work yet. We wait for the answer of Paul. 

cheers

Sergio
Title: Re: ONCONTROL question
Post by: Ionic Wind Support Team on October 24, 2008, 12:02:25 PM
ONCONTROL d1,BUTTON_2, BN_CLICKED,&MyButton

Is correct, but you have to have the statement in @IDINITDIALOG for a dialog.

Title: Re: ONCONTROL question
Post by: LarryMc on October 26, 2008, 06:13:11 PM
When using the old message handler you could declare local variables that could be used by any of the individual message routines.  Like capturing the size of a window in the idcreate and later on restoring  the resized window to it's original size via a buttonclick.

With the ONMESSAGE/ONCONTROL type setup does that old capability exist in some form or fashion other than just declaring a bunch of global variables?

Or would it call for the use of GWL_USERDATA and/or Set/GetPropA instead?

Larry
Title: Re: ONCONTROL question
Post by: Ionic Wind Support Team on October 26, 2008, 06:52:00 PM
Larry,
Not sure I am following you here.  You would have had to use global variables before if you were storing something between messages.

Local variables are only valid while the subroutine is executing.  OnMessage and OnControl just call separate subroutines instead of a single one, the rules of variables aren't any different.

And you can combine the two, or just use a single subroutine like you have always done.

Paul.

Title: Re: ONCONTROL question
Post by: LarryMc on October 26, 2008, 06:56:15 PM
Quote from: Paul Turley on October 26, 2008, 06:52:00 PM
Not sure I am following you here.
Me neither. ;D

I must have been in the middle of a "senior moment." :D

Larry
Title: Re: ONCONTROL question
Post by: talun on October 27, 2008, 06:34:32 AM
Paul,

thank you for the relpy, but unfortunately I'm not able to make a working sample (see below). Can you say me where is the mistake?


$include "windows.inc"
CONST BUTTON_1 = 1
CONST BUTTON_2 = 2
DIALOG d1
CREATEDIALOG d1,0,0,371,126,0x80C80080,0,"OnControl test",&d1_handler
CONTROL d1,@BUTTON,"Button1",53,42,108,42,0x50000000,BUTTON_1
CONTROL d1,@BUTTON,"Button2",210,42,108,42,0x50000000,BUTTON_2
domodal d1
end


SUB d1_handler

   SELECT @MESSAGE
      CASE @IDINITDIALOG
         CENTERWINDOW d1
         ONCONTROL d1,BUTTON_2, BN_CLICKED,&ButtonHnd1
         ONCONTROL d1,BUTTON_2, BN_CLICKED,&ButtonHnd2
      CASE @IDCLOSEWINDOW
         CLOSEDIALOG d1,@IDOK
    ENDSELECT

   RETURN

ENDSUB


sub ButtonHnd1(), int

   messagebox d1,"Button 1 pressed...",""
   return 0

end sub


sub ButtonHnd2(), int

    messagebox d1,"Button 2 pressed...",""
    return 0

end sub


thanks!

Sergio
Title: Re: ONCONTROL question
Post by: LarryMc on October 27, 2008, 07:23:50 AM
Sergio
You've got the same button id in both ONCONTROL statements but that isn't the real problem.

I don't understand why BN_CLICK isn't working.

If I change BN_CLICK to BN_DOUBLECLICKED then I can double click on the buttons and they work.

BN_CLICK is = to 0
BN_DOUBLECLICKED is = to 5

Paul will have to answer this one.

Larry

Title: Re: ONCONTROL question
Post by: talun on October 27, 2008, 08:20:47 AM
QuoteYou've got the same button id in both ONCONTROL statements...

Yes you are right, it was a cut and paste problem... ::)

We will wait Paul

bye

Sergio
Title: Re: ONCONTROL question
Post by: Ionic Wind Support Team on October 27, 2008, 09:40:05 AM
Its a bug.  Which I will have fixed in a day or so.

Thanks,
Paul.
Title: Re: ONCONTROL question
Post by: talun on October 29, 2008, 04:24:52 AM
Thank you for the update.

Unfortunately in the sample below, something don't works, but if you disable the Oncontrol.. command and use the "standard" @IDCONTROL block (now disabled), all works fine.


$include "windows.inc"

string mask, filename
file fhnd

mask = "TXT file (*.txt)|*.txt||"

CONST BUTTON_1 = 1
CONST BUTTON_2 = 2
DIALOG d1
CREATEDIALOG d1,0,0,371,126,0x80C80080,0,"OnControl test",&d1_handler
CONTROL d1,@BUTTON,"Button1",53,42,108,42,0x50000000,BUTTON_1
CONTROL d1,@BUTTON,"Button2",210,42,108,42,0x50000000,BUTTON_2
domodal d1
end


SUB d1_handler

   int result

   SELECT @MESSAGE
      CASE @IDINITDIALOG
         CENTERWINDOW d1
         ONCONTROL d1,BUTTON_1, BN_CLICKED,&ButtonHnd1
         ONCONTROL d1,BUTTON_2, BN_CLICKED,&ButtonHnd2
      CASE @IDCLOSEWINDOW
         CLOSEDIALOG d1,@IDOK
/*
    ------ this block works fine... ------

     CASE @IDCONTROL
        if @CONTROLID = BUTTON_2
          IF @NOTIFYCODE = 0
             result = ButtonHnd2()
          ENDIF
        endif
*/
    ENDSELECT

   RETURN

ENDSUB


sub ButtonHnd1(), int

   messagebox d1,"Button 1 pressed...",""
   return 0

end sub


sub ButtonHnd2(), int

   filename = FILEREQUEST("Save the TXT file...",d1,0,mask,"txt")
   if(len(filename))
      if(OPENFILE(fhnd,filename,"W")=0)
        write fhnd, "abcdeghijklmnopqrstuvwxyz"
        closefile fhnd
      endif
    endif

   messagebox d1,"File created...",""

   return 0

end sub



It's a bug or I make a mistake in my code?

bye

Sergio
Title: Re: ONCONTROL question
Post by: LarryMc on October 29, 2008, 07:21:30 AM
Sergio
I get the same problem you do.

I also created a completely separate sub that contained the fileopen code and had the button2 routine call that sub.

Same result as the other.

Summary is that if you have the filerequest called either directly or indirectly via the oncontrol button2 routine the program immediately closes.

Also discovered that 1.66 now allows bn_click (0) to work properly but if you put in a 5 (BN_DOUBLECLICK), which worked before, or any other value than 0 the program crashes with the "tell MS all about it" message.

We'll have to see what Paul can tell us.

Larry
Title: Re: ONCONTROL question
Post by: dossic on October 29, 2008, 07:42:21 AM
I had the same.  BN_CLICK (0) works fine, 5 does crash the system!

Yours   Carlo
Title: Re: ONCONTROL question
Post by: Ionic Wind Support Team on October 29, 2008, 09:34:11 AM
It's Microsoft for you.  As a workaround, if you really need a dblclick on a button, add a NULL handler for the click.

         ONCONTROL d1,BUTTON_1, BN_CLICKED,NULL
         ONCONTROL d1,BUTTON_1, 5,&ButtonHnd1
         ONCONTROL d1,BUTTON_2, BN_CLICKED,&ButtonHnd2


That's because a double click message sends a click message first.  As to why its crashing?  Talun's example doesn't crash for me, only when I try and intercept the doubleclick message.

Paul.
Title: Re: ONCONTROL question
Post by: Ionic Wind Support Team on October 29, 2008, 10:03:19 AM
ok. Fixed.  I'll update the downloads shortly.

Paul.
Title: Re: ONCONTROL question
Post by: talun on October 29, 2008, 12:14:07 PM
Thanks! All works fine! :D

bye

Sergio