0
votes

My WinForm dialog is attached to a 3rd party window (SolidWorks) via a call to SetParent (p/invoke). My dialog is in the 3rd parties process as an add-in.

When my user has given my dialog/widget focus by clicking on it, if they then press Ctrl+Tab to switch views in the parent application, my dialog receives the key stroke sequence - I can see this by overriding ProcessCmdKey. The command is not passed to the parent window, and hence does nothing.

How can I pass this key sequence to the parent HWND?

It's not just Ctrl+Tab I need to forward, it's all key's including Alt+F4, F1, etc. etc.

1
You'd be far better off removing the C# tag and replacing it with windows and winapi tags.David Heffernan

1 Answers

0
votes

Use FindWindow to get the handle of your parent window. (Pass null for lpClassName) (More info: http://www.pinvoke.net/default.aspx/user32.FindWindow)

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

Forward the captured messages using SendMessageW (more info: http://www.pinvoke.net/default.aspx/user32.SendMessage)

// Works for unicode. One can also 
// use CharSet = CharSet.Unicode instead of [MarshalAs(UnmanagedType.LPWStr)] 
[DllImport("user32.dll", EntryPoint = "SendMessageW")]
static extern IntPtr SendMessageW(IntPtr hWnd, 
                                  UInt32 Msg, 
                                  IntPtr wParam, 
[MarshalAs(UnmanagedType.LPWStr)] string lParam);