Randy, I think if you're communicating between two applications then user defined messages are normally the way to go. For one thing this means you are only processing the messages, not constantly checking atom states. It'd also removes synchronisation issues I think. Anyway, I've wirtten a couple of little example programs to show you what I mean. Listening program:
Code: Select all
Global usermessage.l
Procedure Callback(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
If Message=usermessage
SetGadgetText(1,"Button "+Str(wParam))
EndIf
ProcedureReturn Result
EndProcedure
OpenWindow(0,0,0,200,70,#PB_Window_ScreenCentered | #PB_Window_SystemMenu,"Listening program")
CreateGadgetList(WindowID(0))
Frame3DGadget(0,5,5,190,60,"Last pressed button:")
StringGadget(1,10,20,180,40,"No buttons pressed yet",#PB_String_ReadOnly | #PB_String_Multiline | #ES_AUTOVSCROLL | #WS_VSCROLL | #ESB_DISABLE_LEFT| #ESB_DISABLE_RIGHT)
usermessage=RegisterWindowMessage_("comm")
SetWindowCallback(@Callback())
Repeat
ev=WaitWindowEvent()
If ev=#PB_Event_CloseWindow
quit=#True
EndIf
Until Quit=#True
And then a 'speaking' program.
Code: Select all
OpenWindow(0,0,0,160,60,#PB_Window_ScreenCentered | #PB_Window_SystemMenu,"Speaking program")
CreateGadgetList(WindowID(0))
ButtonGadget(1,10,10,40,40,"1")
ButtonGadget(2,60,10,40,40,"2")
ButtonGadget(3,110,10,40,40,"3")
usermessage=RegisterWindowMessage_("comm")
Repeat
ev=WaitWindowEvent()
If ev=#PB_Event_CloseWindow
quit=#True
EndIf
If ev=#PB_Event_Gadget
gad=EventGadgetID()
listener=FindWindow_(0,"Listening program")
If listener
SendMessage_(listener,usermessage,gad,0)
EndIf
EndIf
Until Quit=#True
Using this method you can safely communicate between as many programs as you like. Hope this is of some use to someone.
Edit: In case anyone's wondering why I need all those flags on the string gadget, I dont. I just started off with some other code that I adapted for this example.