May 08, 2024, 04:58:04 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


ONCONTROL question

Started by talun, October 24, 2008, 04:09:15 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

talun

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

LarryMc

October 24, 2008, 05:04:01 AM #1 Last Edit: October 24, 2008, 05:31:23 AM by Larry McCaughn
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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

talun

Hi Larry,
thanks for your suggestions but it doesn't work yet. We wait for the answer of Paul. 

cheers

Sergio

Ionic Wind Support Team

ONCONTROL d1,BUTTON_2, BN_CLICKED,&MyButton

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

Ionic Wind Support Team

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

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.

Ionic Wind Support Team

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

talun

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

LarryMc

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

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

talun

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

Ionic Wind Support Team

Its a bug.  Which I will have fixed in a day or so.

Thanks,
Paul.
Ionic Wind Support Team

talun

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

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

dossic

I had the same.  BN_CLICK (0) works fine, 5 does crash the system!

Yours   Carlo

Ionic Wind Support Team

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.
Ionic Wind Support Team

Ionic Wind Support Team

ok. Fixed.  I'll update the downloads shortly.

Paul.
Ionic Wind Support Team

talun

Thanks! All works fine! :D

bye

Sergio