好了,所以谷歌是不是我的朋友今晚...如何知道何时在显示属性对话框中选择了不同的屏幕保护程序?
我有一个屏幕保护程序,CC.Votd (Full source on Codeplex),和我刚开始实施预览模式(/ P参数),这是工作确定。当它处于预览模式时,我的表单成为小电脑显示器窗口的一个孩子,并且在那里绘制。
这工作得很好,我的应用程序退出时,如果显示属性对话框消失。
的问题是,如果我从列表中选择我的屏幕保护程序,然后选择不同的屏幕保护程序矿继续运行,并绘制了新选择屏幕保护程序的预览。
那我怎么知道什么时候选择不同的屏幕保护程序和矿应该关闭?
编辑:对于匿名,这里是我使用,使我的形式预览窗口的子代码:
P /调用:
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern bool GetClientRect(IntPtr hWnd, out Rectangle lpRect);
的代码:
SetParent(Handle, _PreviewHandle);
SetWindowLong(Handle, -16, new IntPtr(GetWindowLong(Handle, -16) | 0x40000000));
Rectangle parentRectangle;
GetClientRect(_PreviewHandle, out parentRectangle);
Size = parentRectangle.Size;
Location = new Point(0, 0);
填写表单代码:http://ccvotd.codeplex.com/SourceControl/changeset/view/40085#862458
忘了提,我尝试使用IsWindowVisible()
并没有奏效,因为预览窗口仍然可见并且具有相同的手柄时选择了我的屏幕保护程序的。
编辑:我加入了SetParent()
和相关的调用之前我的应用程序将继续运行显示对话框关闭后,所以我认为这部分工作,当用户选择不同的屏幕保护程序不同的东西发生。
正如John K建议我一直在用Spy ++来查看我的表格。我从来没有看到应用WS_CHILD样式。不过,我所有的调试都表明它应该是。我修改了代码:
long style = GetWindowLong(Handle, -16);
System.Diagnostics.Trace.WriteLine("Original Style: " + style);
style &= ~0x800000000;
style |= 0x40000000;
System.Diagnostics.Trace.WriteLine("Adjusted Style: " + style);
SetWindowLong(Handle, -16, new IntPtr(style));
System.Diagnostics.Trace.WriteLine("After Set Style: " + GetWindowLong(Handle, -16));
SetParent(Handle, _PreviewHandle);
System.Diagnostics.Trace.WriteLine("After Set Parent: " + GetWindowLong(Handle, -16));
而且款式是在最后三个痕迹,其中两个应该从窗体本身来获取值相同。将研究我的本地API调用并清理它们的声明以了解我能弄清楚的内容。
感谢所有帮助迄今为止!
解决方案:问题结束了,我被设置,导致潜在的.NET控件覆盖我的新的风格形式的几个属性。所以改变:
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
Capture = true;
if (!_IsPreview)
{
// Removed ...
}
else
{
SetWindowLong(Handle, -16, new IntPtr(GetWindowLong(Handle, -16) | 0x40000000));
SetParent(Handle, _PreviewHandle);
Rectangle parentRectangle;
GetClientRect(_PreviewHandle, out parentRectangle);
Size = parentRectangle.Size;
Location = new Point(0, 0);
}
ShowInTaskbar = false;
DoubleBuffered = true;
BackgroundImageLayout = ImageLayout.Stretch;
要:
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
BackgroundImageLayout = ImageLayout.Stretch;
Capture = true;
DoubleBuffered = true;
ShowInTaskbar = false;
if (!_IsPreview)
{
// Removed ...
}
else
{
SetWindowLong(Handle, -16, new IntPtr(GetWindowLong(Handle, -16) | 0x40000000));
SetParent(Handle, _PreviewHandle);
Rectangle parentRectangle;
GetClientRect(_PreviewHandle, out parentRectangle);
Size = parentRectangle.Size;
Location = new Point(0, 0);
}
解决了这一问题。简单的错误:-)
正确的方法来解决它......覆盖的CreateParams:
protected override CreateParams CreateParams
{
get
{
CreateParams createParams = base.CreateParams;
if (!DesignMode && _IsPreview)
{
createParams.Style |= 0x40000000;
}
return createParams;
}
}
您可以发布您用于创建预览窗口的代码作为传入HWND的子代吗? – 2010-02-08 02:14:50
@Anon:当然,我从一个例子中发现它,并没有真正检查过它似乎为我工作的事实:-) – 2010-02-08 02:21:35
屏幕保护程序对话会在用户切换屏幕保护程序时破坏预览窗口 - 您是否听这个? – 2010-02-08 02:35:51