1

I’m trying to “link” my form to another window, like this. I’ve done this using the Form.Show(IWin32Window owner) method. This is working pretty good, with 1 exception… When the owner window has focus and I click its icon in the taskbar, the owner window (and my window) minimizes nicely.

However, when my Form has focus, and I click the icon of the owner window in the taskbar, I would expect the owner window to regain focus, but it doesn’t. My form’s border flickers indicating it has focus. I can take the focus away from my Form by clicking somewhere in the owner window’s bounds, but I would think clicking the icon in the taskbar would do the same?

Is there maybe a different way to “link” my form to the other window without this focus problem? .ShowDialog(IWin32Window) isn’t what I’m looking for I think because it wants focus all the time, I want my Form to always stay on top but not always have focus.

I’m using a borderless form, so I’m not seeing the “flicker” indicating my form has focus unless I turn borderless off. If there is no way to “link” my Form differently, is there maybe a way to catch this window message so I can implement my own “flicker”?

public class ParentWndWrapper : IWin32Window
{
    IntPtr m_Handle;

    public ParentWndWrapper(IntPtr pParent){m_Handle = pParent;}

    public IntPtr Handle{get { return m_Handle; }}
}

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        Process[] processArray = Process.GetProcessesByName("Photoshop");
        Process photoshopProcess = processArray[0];
        IntPtr photoshopHWND = photoshopProcess.MainWindowHandle;

        var win32Wrapper = new ParentWndWrapper(photoshopHWND);

        Show(win32Wrapper);
    }
}
Community
  • 1
  • 1
VincentC
  • 245
  • 4
  • 14
  • What is the purpose of *linking*? Why it can't be shown together, so you can have free control of either Photoshop window or your form? Regarding focus indication, you can provide something (to example, change background of your form or a label with text "activated") when it's *activated* (which you call *focused*). Look for [`Activated`](http://msdn.microsoft.com/en-us/library/system.windows.forms.form.activated.aspx) method. – Sinatr Feb 21 '14 at 12:26
  • @Sinatr Wouldn't Photoshop draw on top of my Form then? Making my form invisible? The reason I "link" it is because I want to be able to do this: [image](https://dl.dropboxusercontent.com/u/8801520/PhotoshopFocus.jpg). Is there maybe another way of doing this? – VincentC Feb 21 '14 at 12:36
  • Windows in Windows (sounds funny) can be *sized*, your form can be *on top* of other window or *near* it. It is not very clear what you are trying to do. – Sinatr Feb 21 '14 at 13:14
  • @Sinatr My program should behave as a floating child window of Photoshop. So when Photoshop is minimized, my Form should be minimized. It should always be on top of Photoshop but shouldn’t always have focus. The focus part is where the problem lies, because Photoshop is unable to take Focus back by clicking on the taskbar PS icon. I am however able to get Photoshop focus back by clicking inside Photoshop’s window. Everything is working apart from this Focus problem, it is pretty minor, but I thought I was maybe missing something simple :). I hope this made it somewhat clearer? – VincentC Feb 21 '14 at 14:51

0 Answers0