Embedding external applications within another application?

Just starting out? Need help? Post your questions and find answers here.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You can't subclass a window from another process flype - not unless you take the route of a global hook as suggested by Mistrel.

However, to get your re-painting working better, use #WM_PAINT in a callback - it's far better than the PB event when moving the window etc. Also, a slight modification to the RedrawWinwdow_() flags is required.

Code: Select all

#APPNAME1 = "Calculator" 

Define *Parent 
Global *Child 


Procedure MyWindowCallback(hWnd, uMsg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_PAINT
        RedrawWindow_(*Child, 0, 0, #RDW_INVALIDATE|#RDW_ERASE|#RDW_FRAME) 
  EndSelect
  ProcedureReturn Result
EndProcedure


*Child = FindWindow_(0, #APPNAME1) 
If Not *Child 
  RunProgram("calc.exe") : Delay(1000) 
  *Child = FindWindow_(0, #APPNAME1) 
  If Not *Child 
    MessageRequester("Error", #APPNAME1 + " must be running !") 
    End 
  EndIf 
EndIf 

*Parent = OpenWindow(0, 0, 0, 320, 240, "Master", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget) 

If *Parent 
  
  SetWindowColor(0, $AAAAAA) 
  
  CreateStatusBar(0, WindowID(0)) 
  
  SetParent_(*Child, WindowID(0)) 
  SetWindowPos_(*Child, 0, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_SHOWWINDOW) 
  SetWindowCallback(@MyWindowCallback())
  
  Repeat 
    
    Select WaitWindowEvent() 
        
      Case #PB_Event_CloseWindow 
        If IsWindow_(*Child) 
          SetParent_(*Child, 0) 
        EndIf 
        CloseWindow(0) 
        Break 
    EndSelect 
    
  ForEver 
  
EndIf 

End
I may look like a mule, but I'm not a complete ass.
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Stop it, you're way over my head here... :)

As to the communications: that I have covered.

It's the embedding of an external program that's giving me trouble. Perhaps I should use the kiosk system that was published elsewhere on this forum, although I'd rather have a tighter coupling between the main calling program and the other application that is being 'hosted' by the main program.

Srod & Flype: I ran both of your codes and the calculator was started allright, but the OpenWindow bit doesn't get displayed. The debugger isn't providing any additional information.

Thanks for responding!
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Thalius wrote:Am not sure what you want to achieve.
You could descibe it as an main application that can host another application (or perhaps only hosts/displays the output of that other application). Part of the main app should function as a 'presentation frame' that shows the output of that other app.

clear as mud?
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

and the childs apps are made by you (same conceptor as the main app) or by anybody else ?
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Flype wrote:and the childs apps are made by you (same conceptor as the main app) or by anybody else ?
both can happen, but either case, these apps will normally initialise a borderless window (either 800x600 or 1024x768 24/32bit graphics) and diplay their graphics there, much in the way full-screen games do.
I'm looking for a 'framework' in which to display/host such external applications.

Since these apps indeed open a borderless window (it's not full-screen graphics), one idea might be to use the kiosk-code mentioned before to start the external app, and somehow instruct that external application to start 'screen centered' and 'always on top'. This way, I could still have the hosting software active and still have the external app visible at all times. Within this setting I should rephrase my question: how to instruct an external program to initialise itself 'screen centered' and 'always on top'. Does this spark any new ideas?
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Post Reply