Page 1 of 1

Controlling windows from external app

Posted: Thu Feb 09, 2006 6:41 pm
by einander

Code: Select all

;Controlling windows From external app
;By einander
;feb 9 - 2006
;PB 3.94 beta 2 - Updated for PB 4.6
;RECEIVER APP
#SEP=Chr(215)  ; field separator
;
Structure ATOM   ; structure containing fields to Control Selected window
  String.S           ; you can Add/replace with your own fields
  TextRGB.L
  WinRGB.L
  FontName.S
  FontSize.L
EndStructure
;
Global List.ATOM
;
Macro StripAtom  ; replaces the identifier (atom)  with the string and strip the fields to LIST\
  Buff$ = Space($400)
  GlobalGetAtomName_(WParam,Buff$,Len(Buff$)) ; buff$ is the string with fields
  List\String = StringField(Buff$, 1, #SEP)
  List\TextRGB=Val(StringField(Buff$,2,#SEP))
  List\WinRGB=Val(StringField(Buff$,3,#SEP))
  List\FontName=StringField(Buff$,4,#SEP)
  List\FontSize=Val(StringField(Buff$,5,#SEP))
EndMacro
;Msg receives the destination Window
;wParam receives the identifier for the string that contains the fields to Control the destination window
Procedure CallBack(HWnd, Msg, WParam, LParam)
  Result = #PB_ProcessPureBasicEvents
  If Msg=100 Or Msg=200 Or Msg=300   ; destination Window
    StripAtom  ; now  LIST\ have the Control values
    LoadFont(0,List\FontName,List\FontSize)
    StartDrawing(WindowOutput(Msg))
    StickyWindow(Msg, #True)     
    Box(0,0,WindowWidth(Msg),WindowHeight(Msg),List\WinRGB)
    DrawingMode(1)
    DrawingFont(FontID(0))
    DrawText(10,10,List\String,List\TextRGB)
    GlobalDeleteAtom_(WParam)
    StopDrawing()
    FreeFont(0)
  EndIf
  ProcedureReturn Result
EndProcedure
;
OpenWindow(100, 80, 100, 300, 100, "Receiver Window 1", #PB_Window_SystemMenu )
OpenWindow(200, 80, 250, 300, 100, "Receiver Window 2", #PB_Window_SystemMenu )
OpenWindow(300, 80, 400, 300, 100, "Receiver Window 3", #PB_Window_SystemMenu )
SetWindowCallback(@CallBack())
Repeat
  Ev = WaitWindowEvent()
Until Ev = #PB_Event_CloseWindow 

Re: Controlling windows from external app

Posted: Wed Jan 11, 2012 1:47 pm
by einander

Code: Select all

;Controlling windows From external app
;By einander
;feb 9 - 2006
;PB 3.94 beta 2 - Updated for PB 4.6
;SENDER APP
#SEP=Chr(215)   ; string separator
If OpenWindow(0, 400, 200, 210, 140, "Sender App", #PB_Window_SystemMenu )
  StickyWindow(0, #True)
  ButtonGadget(1,10,10,190,30,"Message to Win 1")
  ButtonGadget(2,10,50,190,30,"Message to Win 2")
  ButtonGadget(3,10,90,190,30,"Message to Win 3")
  Repeat
    Ev = WaitWindowEvent()
    If Ev = #PB_Event_Gadget
      EvID=EventGadget()
      If EvID>0 And EvID<4
        String$="Message sent to Receiver App - Win "
        TextRGB=Random($FFFFFF)
        WinRGB=Random($FFFFFF)
        String$+Str(EvID)+#SEP+Str(TextRGB)+#SEP+Str(WinRGB)+#SEP+"arial"+#SEP+"12"
        Msg=GlobalAddAtom_(String$)   ; GlobalAddAtom_ replaces the string with a unique identifier
        Hnd=FindWindow_(0,"Receiver Window "+Str(EvID))  ; handle to destination Window
        SendMessage_(Hnd,EvID*100,Msg ,0)          ; evid*100=destination Window param
      EndIf
    EndIf
  Until Ev = #PB_Event_CloseWindow
EndIf
End

Re: Controlling windows from external app

Posted: Wed Jan 11, 2012 9:42 pm
by rsts
Hello :shock:

Very nice. Many thanks for sharing - and the example. :)

cheers

Re: Controlling windows from external app

Posted: Sat Sep 15, 2012 7:38 pm
by Kwai chang caine
Yes a "little bit" later, but i discover this code now, when i search other thing :oops:
Thanks for sharing 8)