Got some C# forms/controls that can be called up either from a C# control on a Winform in a Winforms MDI app OR the same C# control used by a PowerBuilder MDI app via COM.
I've been using the WinAPI call SetParent to attach forms to the MDI.
- It works (or seemed to) in both environments.
- It lets the child window have its own WindowState (Normal, Maximised) instead of taking on that of the child windows already open (which was a real pain).
Say the control is called T. Code on control T calls up form D.
Control T is on form X.
Control T is also on form Y.
In .Net all is well, and form D stays within the MDI.
in PB:
Control T is on PB control PX.
Control T is also on PB control PY.
For PX all is well.
For PY, however, there is a problem - form D does not seem to become an MDI child - it can go outside the app and has a taskbar icon. I stress that this is using same objects as the ones that do work. The SetParent is literally the same line of code.
Further research has revealed that SetParent doesn't really work for proper MDI childing - but that's OK(ish) cos we don't need to merge menus etc.
Interestingly, have found that though SetParent seems to 'work', you don't get the handle back if you try GetParent...
Form form = new MyForm();
WindowsMessageHelper.SetParent(form.Handle, MDIParentHandle); //passed down
int parentHandle = WindowsMessageHelper.GetParent(form.Handle);
parentHandle will always be 0....
Is there any way of making form D behave under all circumstances? My own researches have not been promising. I don't really want to go back and rewrite my forms as controls and have PowerBuilder manage them - mainly becasue there can be multiple instances of each form and PowerBuilder would have to handle that (instead of the controller class/base class I've got doing it in the .net app).
Can I stress that there is NO problem within .Net, the problem only shows up in the PowerBuilder app