我试图使powershell windows窗体完全透明,因为我能够让aero样式的控件工作,并隐藏powershell控制台窗口这是唯一缺少的。
我试图在powershell中实现的教程如下:
http://blogs.msdn.com/b/tims/archive/2006/04/18/578637.aspx但它在c_中,有帮助吗?
最佳答案
通过在powershell中编译/加载,您可以使用c示例本身。样品(未测试):
$def = @"
[StructLayout(LayoutKind.Sequential)]
public struct MARGINS
{
public int left;
public int right;
public int top;
public int bottom;
}
[DllImport("dwmapi.dll")]
public static extern bool DwmIsCompositionEnabled();
[DllImport("dwmapi.dll")]
public static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
"@
#Load/Compile C# P/Invoke code
Add-Type -Namespace stackoverflow -Name Aero -MemberDefinition $def
#Check if Aero is enabled on this computer
If([stackoverflow.Aero]::DwmIsCompositionEnabled()) {
#Get mainwindowhandle for powershell console process
$hwnd = (Get-Process -Id $pid).MainWindowHandle
#Define margins = how much extra space to make transparent
$margins = New-Object -TypeName 'stackoverflow.Aero+MARGINS'
$margins.top = 50
$margins.bottom = 0
$margins.left = 0
$margins.right = 0
#Make powershell-console partly aero.
[stackoverflow.Aero]::DwmExtendFrameIntoClientArea($hwnd, $margins)
}