Page 1 of 1

Posted: Tue Aug 13, 2002 6:21 pm
by BackupUser
Restored from previous forum. Originally posted by pusztry.

Hi all,
I am new to text based programing and was wondering what a callback was. I know this is probably something that is stupid but I don't know what it is. I would really appreciate an explanation.

Ryan

WinXP, PIII 800 MHz, 512MB RAM, SB Live 5.1, NVidia TNT 2 Ultra

Posted: Wed Aug 14, 2002 10:12 am
by BackupUser
Restored from previous forum. Originally posted by freak.

A callback is a procedure that you provide, so that Windows can call it.

Like this one:

Code: Select all

  Procedure MyWindowCallback(WindowID, Message, wParam, lParam) 
    Result = #PB_ProcessPureBasicEvents 
    ; 
    ; you code here 
    ; 
    ProcedureReturn Result 
  EndProcedure 

SetWindowCallback(@MyWindowCallback() )   ; this sets the Procedure as callback
Now, everytime an Event occures in your Window, Windows calls the
Procedure MyWindowCallback().

I don't know if this one helps you, since it's a bit lowlevel you should have
some experience in Windows programming.
All PB events should be handled with the regulars WaitWindowEvent() or WindowEvent().

That's it, hope you got the point...

Timo

--
If it stinks, it's chemistry. If it moves, it's biology.
If it does not work, It's computer science.

Posted: Wed Aug 14, 2002 7:03 pm
by BackupUser
Restored from previous forum. Originally posted by ricardo.

In easy words, its the point in where windows tells your application if something happens related to your application. Could be some user input or action (the user click a button of your app p.e) or anyother thing that your app should know (repaint, etc).

Inside this loop (callback) you will receive all this information.

Posted: Thu Aug 15, 2002 2:11 am
by BackupUser
Restored from previous forum. Originally posted by pusztry.

This maybe stupid but doesn't PB do that when you look at the PB_EVENT,ect.
Just wondering the difference. I hope that made sense. Here is an example.

Code: Select all

 Repeat
  EventID=WaitWindowEvent()
  Select EventID
    Case #PB_EventGadget
      Select EventGadgetID()
        Case #BrowseButton : Gosub BrowseButton_Click
        Case #FilePath : Gosub FilePath_Click
        Case #HTMLOutPath : Gosub HTMLOutPath_Click
        Case #HTMLBrowseButton : Gosub HTMLBrowseButton_Click
        Case #ConvertButton : Gosub ConvertButton_Click
        Case #Combo1 : Gosub Combo1_Click
      EndSelect
    Case #PB_EventMenu
      Select EventMenuID()
        Case 1 : Gosub MenuItem1_Click
        Case 2 : Gosub MenuItem2_Click
        Case 3 : Gosub MenuItem3_Click
      EndSelect
  EndSelect
Until EventID=#PB_EventCloseWindow
Ryan

WinXP, PIII 800 MHz, 512MB RAM, SB Live 5.1, NVidia TNT 2 Ultra

Posted: Thu Aug 15, 2002 4:43 am
by BackupUser
Restored from previous forum. Originally posted by Danilo.

Yes, pusztry - thats right.

But you can only get few Windows messages with (Wait)WindowEvent().
The win-callback is needed for API programming
to catch all events.

But Hey, a CALLBACK isnt only for windows messages.

"CALLBACK"´s are called from another procedure/function in general.
Look at the PureBasic Packer commands: PackerCallback(@Procedure())
Or the Highresolution Timer: StartTimer(1,200,@Procedure()).

So you give a Procedure as parameter to the command/function
and the command/function calls your procedure - thats a CALL BACK.

cya,
...Danilo

(registered PureBasic user)