如何使用Powershell向窗口控件发送消息?我在C#下有一个发送示例,但是我不知道如何在Powershell中编写代码。
<!-- hero -->
<?php if(have_rows('hero')):?>
<?php while(have_rows('hero')): the_row(); ?>
<div class="hero-carousel">
<?php if(have_rows('slide')): ?>
<div class="hero-slides">
<?php while(have_rows('slide')): the_row();?>
<div class="hero">
<div style="background:url(<?php echo get_sub_field('hero_background');?>);">
</div>
</div>
<?php endwhile;?>
</div>
<?php endif;?>
</div>
<?php endwhile;?>
<?php endif;?>
<!-- /hero -->
// hero styles
.hero-carousel{
.hero-slides{
.hero{
width: 100%;
div {
height: 700px;
width: 100%;
background-size: cover !important;
background-position: center !important;
}
}
}
}
// hero slick gallery
$('.hero-slides').slick({
infinite: true,
slidesToShow: 1,
autoplay: true,
arrows: false,
// dots: true,
});
我试图将C#代码转换为Powershell代码,但是没有用。欢迎任何建议
//using System.Runtime.InteropServices;
[DllImport("user32.dll", EntryPoint = "SendMessageW", CharSet = CharSet.Unicode)]
internal static extern IntPtr SendMessageS(IntPtr hWnd, int Msg, uint wParam, string lParam);
[DllImport("user32.dll", EntryPoint = "FindWindowW", CharSet = CharSet.Unicode)]
internal static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
static void TestQm2SendMessage()
{
var hwnd = FindWindow("QM_Editor", null);
if(hwnd == default(IntPtr)) return;
SendMessageS(hwnd, 12, 1, "Q ' M 'Macro295' C test C#");
}
答案 0 :(得分:0)
您可以使用.NET System.Windows.Forms.MessageBox。在Powershell中也可以使用。
[System.Windows.Forms.MessageBox]::Show("Your message here!", 'This is my title', 'YesNo', 'Information')
答案 1 :(得分:0)
在Internet上找到
function Out-Notepad
{
param
(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[String]
[AllowEmptyString()]
$Text
)
begin
{
$sb = New-Object System.Text.StringBuilder
}
process
{
$null = $sb.AppendLine($Text)
}
end
{
$text = $sb.ToString()
$process = Start-Process notepad -PassThru
$null = $process.WaitForInputIdle()
$sig = '
[DllImport("user32.dll", EntryPoint = "FindWindowEx")] public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll")] public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);
'
$type = Add-Type -MemberDefinition $sig -Name APISendMessage -PassThru
$hwnd = $process.MainWindowHandle
[IntPtr]$child = $type::FindWindowEx($hwnd, [IntPtr]::Zero, "Edit", $null)
$null = $type::SendMessage($child, 0x000C, 0, $text)
}
}
#Get-Content -Path 'С:\Folder\File.txt' | Out-String | Out-Notepad
'Send this text to Notepad' | Out-Notepad