Programm starten, zu einem nicht benutztem IDE Tab wechseln , Cursor plazieren und Button drücken
der Text Hallo wird dann dort eingefügt
Wer das Modul benutzen will, muß naturlich den Democode (OpenWindow Teil ) löschen und als PBI speichern
und dann mit z.B. XIncludeFile "..\inc\SendTextToPBIDE.pbi" einbinden
Code: Alles auswählen
;by HJBremer 20.10.2022/2020 - Windows 10, PB 570 x86, 572 x64, 600 x64
;Hinweis: GetHwnd_Purebasic() muß vor Openwindow() aufgerufen werden, sonst wird dessen hwnd zurück gegeben
; bedeutet das Modul muß ganz am Codeanfang eingebunden werden vor irgendeiner Fenstererstellung etc.
; jeder IDE-Tab hat sein eigenes Scintilla Handle, wird darum vor jedem SendText() ermittelt
;Codes aus dem Forum und angepasst
;Quelle: GetProcess_ + SendText_ ts-soft, STARGÅTE http://forums.purebasic.com/german/viewtopic.php?t=24684
;Quelle: GetHwnd_ von Axolotl http://forums.purebasic.com/english/viewtopic.php?f=13&t=68266
DeclareModule SendTextToPBIDE
Declare.i GetHwnd_Purebasic()
Declare.i GetHwnd_Scintilla(hwnd)
Declare.i SendText_toPBIDE(text.s)
EndDeclareModule
;-
Module SendTextToPBIDE
EnableExplicit
Global purebasic_hwnd = GetHwnd_Purebasic() : ;Debug "PB Fenster " + purebasic_hwnd
Procedure.i GetHwnd_Purebasic()
;muß vor Openwindow() aufgerufen werden,
ProcedureReturn FindWindow_("WindowClass_2", 0)
EndProcedure
Procedure.i GetHwnd_Scintilla(hwnd)
;hwnd ist das PurebasicWindow
hWnd = FindWindowEx_(hWnd, 0, "PureSplitter", 0) :;Debug hwnd
hWnd = FindWindowEx_(hWnd, 0, "PureSplitter", 0) :;Debug hwnd
hWnd = FindWindowEx_(hWnd, 0, "PureContainer", 0):;Debug hwnd
hWnd = FindWindowEx_(hWnd, 0, "Scintilla", 0) :;Debug hwnd: Debug "---"
ProcedureReturn hWnd
EndProcedure
Procedure.i GetProcess_FromWindow(hwnd)
Protected processID
If GetWindowThreadProcessId_(hwnd, @processID)
ProcedureReturn OpenProcess_(#PROCESS_ALL_ACCESS, #False, processID)
EndIf
EndProcedure
Procedure.i SendText_toPBIDE(text.s)
Protected *memoryID, *buffer, codepage, codeformat, length
Protected scintilla_hwnd = GetHwnd_Scintilla(purebasic_hwnd) ;handle vom PB IDE Tab
Protected processID = GetProcess_FromWindow(scintilla_hwnd)
If processID
codepage = SendMessage_(scintilla_hwnd, #SCI_GETCODEPAGE, #Null, #Null)
Select codepage
Case 0 : codeformat = #PB_Ascii
Case 65001 : codeformat = #PB_UTF8
EndSelect
length = StringByteLength(text, codeformat)
*buffer = AllocateMemory(length + SizeOf(Character))
If *buffer
PokeS(*buffer, text, #PB_Default, codeformat)
*memoryID = VirtualAllocEx_(processID, #Null, length, #MEM_RESERVE|#MEM_COMMIT, #PAGE_EXECUTE_READWRITE)
If *memoryID
WriteProcessMemory_(processID, *memoryID, *buffer, length, #Null)
;SendMessage_(scintilla_hwnd, #SCI_ADDTEXT, length, *memoryID)
SendMessage_(scintilla_hwnd, #SCI_REPLACESEL, #Null, *memoryID) ;Text einfügen
VirtualFreeEx_(processID, *memoryID, length, #MEM_RELEASE)
EndIf
FreeMemory(*buffer)
EndIf
CloseHandle_(processID)
EndIf
ProcedureReturn purebasic_hwnd
EndProcedure
EndModule
UseModule SendTextToPBIDE
OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ButtonGadget(1, 10, 10, 200, 20, "Send Hallo")
StickyWindow(0,1)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 1 :
text$ = "Hallo"
hwnd = SendText_toPBIDE(text$)
SetActiveWindow_(hwnd)
SetForegroundWindow_(hwnd)
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow