Search notes:

Powershell module WinGUI: send-windowMessage

The send-windowMessage cmdlet of the WinGUI module wraps the WinAPI function SendMessage.

WM_SETTEXT

This example sends a WM_SETTEXT message to a notepad's Edit window:
#
#  make sure exactly one process of notepad is running
#
get-process   notepad -errorAction ignore | stop-process
start-process notepad

start-sleep 1

$hwnd_notepad     = find-window  'notepad'
$hwnd_notepadEdit = find-windowEx $hwnd_notepad 0 'Edit'

$WM_SETTEXT = 0x000C

$ret = send-windowMessage $hwnd_notepadEdit $WM_SETTEXT 0 "This text was`ninserted with`nsend-windowMessage."
"send message returned $ret"
Github repository ps-modules-WinGUI, path: /_examples/send-windowMessage.ps1

BM_CLICK

This example sends BM_CLICK to a button so that it is pressed:
$winTitle = 'Button press test'

start-process  C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  "-c `"Add-Type -AssemblyName PresentationFramework;[System.Windows.MessageBox]::Show('Let the script press OK', '$winTitle')`""

while ( ($hwndMsgBox = find-window -windowTitle $winTitle) -eq 0 ) {
   write-host "No window with title '$winTitle' found, sleeping for a second"
   start-sleep 1
}

write-host "hwndMsgBox = $hwndMsgBox"

$callback = {

   param (
      [IntPtr] $hWnd,
      [IntPtr] $unused_in_this_example
   )

   $className = get-windowClassName $hWnd

   if ($className -eq 'Button') {
      $winTxt    = get-windowText      $hWnd

      if ($winTxt -eq 'Ok') {
         $script:hwndOk = $hwnd
      }
   }

   return $true
}

enum-childWindows $callback $hwndMsgBox

write-host "Clicking OK on hwndMsgBox = $hwndMsgBox in three seconds"
start-sleep 3

$BM_CLICK = 0x00F5
$null = send-windowMessage $hwndOK $BM_CLICK 0 0
Github repository ps-modules-WinGUI, path: /_examples/press-button.ps1

See also

This function is found in the PowerShell module WinGUI

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:51 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(51): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(66): id_of(Object(PDO), 'uri', '/notes/Windows/...') #2 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Windows/...', 1759398443, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #3 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Windows/PowerShell/modules/personal/WinGUI/send-windowMessage(101): insert_webrequest() #4 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 51