Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use powershell to send a message to the QM window
#1
I need to send the contents of the test.txt file to the QM Editor window via powershell and then run the macro.

I think this is achievable. I won't set the relevant parameters. I hope someone can provide some suggestions. Thanks in advance.
Heart

I found a powershell sample file that can send text content to the Notepad window.


Out-Notepad.ps1​​​​​​​:
Code:
Copy      Help
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 c:\test.txt | Out-String | Out-Notepad


Attached Files
.txt   test.txt (Size: 18 bytes / Downloads: 267)
#2
What are you really trying to accomplish? There are examples in the forum on how to call qm.for instance
http://www.quickmacros.com/forum/showthr...9#pid32229
#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'");
#4
I use the following powershell code to run the c# code, but it doesn't work, why?
http://www.quickmacros.com/forum/showthr...2#pid32622

 
Code:
Copy      Help
 
$code = @'
using System;
using System.Runtime.InteropServices;

public class Mystuff{
    [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);

    public static void TestQm2SendMessage() {
        var hwnd = FindWindow("QM_Editor", null);
        if (hwnd == default(IntPtr)) return;
        SendMessageS(hwnd, 12, 1, "Q ' M 'Macro8'");
    }
}
'@


Add-Type $code

[Mystuff]::TestQm2SendMessage

How to directly use the QmSendMessage.dll file to call?
The code below does not work

————————————————————————————————————————

[Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Quick Macros 2\QmSendMessage.dll")

$q = new-object Class.Methods

$q.Run("Q ' M 'Macro8'")
#5
Powershell call succeeded Smile
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", "Quick Macros - Main - [func8]"), 12, 1, "Q ' M 'func8'");


Forum Jump:


Users browsing this thread: 1 Guest(s)