Date: 02-16-2022
Return to Index
created by gbSnippets
'Target App
#Compile Exe "receiver.exe"
#Include "win32api.inc"
Function PBMain() As Long
Local hDlg As Dword, style&
style& = %WS_TabStop Or %WS_Border Or %ES_WantReturn Or _
%ES_AutoHScroll Or %ES_AutoVScroll Or %ES_MultiLine
Dialog New Pixels, 0, "Receiver App",300,700,220,100,%WS_OverlappedWindow To hDlg
Control Add TextBox, hDlg, 500, "<target>" + $CrLf, 10,10,200,80, style&
Control Post hDlg, 500, %EM_SetSel, 14,14
Dialog Show Modal hDlg
End Function
'Sending App
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe "sender.exe"
#Dim All
%Unicode=1 : %IDC_Button = 500 : %PasteText = 501
#Include "win32api.inc"
$Title = "Receiver App" '<--- title to look for in receiver app
Global hDlg,hFound As Dword, szText As WStringZ * %Max_Path
Function PBMain() As Long
Dialog New Pixels, 0, "Sending App",300,500,220,100,%WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button, "Find and Paste", 10,10,120,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Command
If Cb.Ctl = %IDC_Button And Cb.CtlMsg = %BN_Clicked Then
EnumWindows(CodePtr(EnumCallback), 0&)
If hFound Then Dialog End hDlg Else ? $Title + " not found!"
End If
Case %WM_Destroy
If hFound Then
'activate target application
SetForeGroundWindow hFound
'Send Ctrl V to paste clipboard text
Keybd_Event %VK_CONTROL, 0, 0, 0 '<--- Ctrl down
Keybd_Event 86, 0, 0, 0 '<--- V down 86
Keybd_Event %VK_CONTROL, 0, %KEYEVENTF_KEYUP, 0 '<--- Ctrl up
Keybd_Event 86, 0, %KEYEVENTF_KEYUP, 0 '<--- V up 86
End If
End Select
End Function
Function EnumCallback (ByVal hWnd As Long, lParam As Long) As Long
GetWindowText(hWnd, szText, SizeOf(szText))
If Left$(szText,Len($Title)) = $Title Then hFound = hWnd Else Function = 1
End Function
'gbs_01206
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm