I guess it's harder than the simple attempt below. I am not sure how to "put the structures used with the messages into the memory of the remote process".
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases
#SingleInstance Force ; Replaces the old instance automatically (same as Reload)
Gui, New, +HwndhGui
ControlGet, hEdit, Hwnd,, Edit1, ahk_class Notepad
Return
#f::
IfWinNotExist ahk_id %hFindDialog%
hFindDialog := FindText(hGui,hEdit)
WinActivate ahk_id %hFindDialog%
Return
FindText(hGui,hEdit) { ; Find dialog box
; ===================================================================================================================
; RE : RichEdit object
Static FINDMSGSTRING := "commdlg_FindReplace"
, FR_DOWN := 1, FR_MATCHCASE := 4, FR_WHOLEWORD := 2
, Buf := "", FR := "", Len := 256
, FR_Size := A_PtrSize * 10
; Text := RE.GetSelText()
VarSetCapacity(FR, FR_Size, 0)
NumPut(FR_Size, FR, 0, "UInt")
VarSetCapacity(Buf, Len, 0)
If (Text && !RegExMatch(Text, "\W"))
Buf := Text
Offset := A_PtrSize
NumPut(hGui, FR, Offset, "UPtr") ; hwndOwner
OffSet += A_PtrSize * 2
NumPut(FR_DOWN, FR, Offset, "UInt") ; Flags
OffSet += A_PtrSize
NumPut(&Buf, FR, Offset, "UPtr") ; lpstrFindWhat
OffSet += A_PtrSize * 2
NumPut(Len, FR, Offset, "Short") ; wFindWhatLen
FindTextProc("Init", hEdit, "")
OnMessage(DllCall("User32.dll\RegisterWindowMessage", "Str", FINDMSGSTRING), "FindTextProc")
Return DllCall("Comdlg32.dll\FindTextW", "Ptr", &FR, "UPtr")
}
; -------------------------------------------------------------------------------------------------------------------
FindTextProc(L, M, H) { ; skipped wParam, can be found in "This" when called by system
; Find dialog callback procedure
; EM_FINDTEXTEXW = 0x047C, EM_EXGETSEL = 0x0434, EM_EXSETSEL = 0x0437, EM_SCROLLCARET = 0x00B7
; FR_DOWN = 1, FR_WHOLEWORD = 2, FR_MATCHCASE = 4,
Static FINDMSGSTRING := "commdlg_FindReplace"
, FR_DOWN := 1, FR_MATCHCASE := 4, FR_WHOLEWORD := 2 , FR_FINDNEXT := 0x8, FR_DIALOGTERM := 0x40
, HWND := 0
If (L = "Init") {
HWND := M
Return True
}
Flags := NumGet(L + 0, A_PtrSize * 3, "UInt")
If (Flags & FR_DIALOGTERM) {
OnMessage(DllCall("User32.dll\RegisterWindowMessage", "Str", FINDMSGSTRING), "")
ControlFocus, , ahk_id %HWND%
HWND := 0
Return
}
VarSetCapacity(CR, 8, 0)
SendMessage, 0x0434, 0, &CR, , ahk_id %HWND%
Min := (Flags & FR_DOWN) ? NumGet(CR, 4, "Int") : NumGet(CR, 0, "Int")
Max := (Flags & FR_DOWN) ? -1 : 0
OffSet := A_PtrSize * 4
Find := StrGet(NumGet(L + Offset, 0, "UPtr"))
VarSetCapacity(FTX, 16 + A_PtrSize, 0)
NumPut(Min, FTX, 0, "Int")
NumPut(Max, FTX, 4, "Int")
NumPut(&Find, FTX, 8, "Ptr")
SendMessage, 0x047C, %Flags%, &FTX, , ahk_id %HWND%
S := NumGet(FTX, 8 + A_PtrSize, "Int"), E := NumGet(FTX, 12 + A_PtrSize, "Int")
If (S = -1) && (E = -1)
MsgBox, 262208, Find, No (further) occurence found!
Else {
Min := (Flags & FR_DOWN) ? E : S
SendMessage, 0x0437, 0, % (&FTX + 8 + A_PtrSize), , ahk_id %HWND%
SendMessage, 0x00B7, 0, 0, , ahk_id %HWND%
}
}