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
explain Callback
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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:
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.
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
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.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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.
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.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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.
Ryan
WinXP, PIII 800 MHz, 512MB RAM, SB Live 5.1, NVidia TNT 2 Ultra
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
WinXP, PIII 800 MHz, 512MB RAM, SB Live 5.1, NVidia TNT 2 Ultra
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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)
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)