我正在制作一个Excel插件,其中点击菜单项或工具栏按钮会打开表单。我已将表单的“置顶”属性设置为true,但它仍然在Windows XP的所有应用程序中保持置顶。我只需要它在Microsoft Excel中保持置顶。
我选择了Visual Studio 2008中的项目,在Excel -> 2003中进行。
请告诉我如何以任何方式实现这一点........
[编辑 - 更改代码]
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
void func()
{
Form1 f = new Form1();
SetParent(f.Handle, (IntPtr)ThisAddIn.ExcelApplication.Hwnd);
f.Show();
}