Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use powershell to send a message to the QM window
#3
@kevin
I am trying to interact between powershell and Qm Smile
Using the code below, I can set the text content to QM's title bar, which I need to set to the QM Editor. Shy


Out-qm.ps1
Code:
Copy      Help
function Out-qm
{
  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 qm -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, "QM_Editor", $null)
    $null = $type::SendMessage($child, 0x000C, 0, $text)
  }



Get-Content -Path c:\test.txt | Out-String | Out-qm

RegisterNetComComponent  Also called user32.dll

I think it's easier to use powershell. I wrote the following code, but there is no result.
Huh

 
Code:
Copy      Help
 
$code = @'
[DllImport("user32.dll", EntryPoint = "SendMessageW", CharSet = CharSet.Unicode)] public static extern IntPtr SendMessageS(IntPtr hWnd, int Msg, uint wParam, string lParam);
[DllImport("user32.dll", EntryPoint = "FindWindowW", CharSet = CharSet.Unicode)] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
'@
$myAPI = Add-Type -MemberDefinition $code -Name API -PassThru
$myAPI::SendMessageS($myAPI::FindWindow("QM_Editor", $null), 12, 1, "Q ' M 'func8'");


Messages In This Thread
RE: Use powershell to send a message to the QM window - by win - 05-11-2019, 12:08 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)