PB Editor auslesen

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
Benutzeravatar
Scarabol
Beiträge: 1427
Registriert: 30.11.2005 21:00

PB Editor auslesen

Beitrag von Scarabol »

Hi Leute,

das folgende Beispiel zeigt, wie ihr den aktuellen Quelltext aus der PB IDE auslest, solange diese den Focus hat.

Code: Alles auswählen

Global parent
Global child

Procedure.s GadgetText(GadgetID)
  Protected buffer$, num
  num = SendMessage_(GadgetID, #WM_GETTEXTLENGTH, 0, 0)
  buffer$ = Space(num+1)
  SendMessage_(GadgetID, #WM_GETTEXT, num+1, @buffer$)
  ProcedureReturn buffer$
EndProcedure

Procedure.s GetWindowText(hwnd)
  Protected l.l, buffer$
  l = GetWindowTextLength_(hwnd)+1
  buffer$ = Space(l)
  If GetWindowText_(hwnd, buffer$, l)
    ProcedureReturn buffer$
  EndIf
EndProcedure

OpenWindow(1, 0, 0, 400, 300, "PB Dir Helper", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CreateGadgetList(WindowID(1))
  EditorGadget(3, 10, 10, 380, 250)

SetWindowPos_(WindowID(1), #HWND_TOPMOST, WindowX(1), WindowY(1), WindowWidth(1), WindowHeight(1), 0)

Repeat
  event = WaitWindowEvent(50)
  
  parent = 0
  hwnd = GetForegroundWindow_()
  If Mid(GetWindowText(hwnd), 0, 9) = "PureBasic"
    parent = hwnd
  EndIf
  If parent
    AttachThreadInput_(GetWindowThreadProcessId_(parent, 0), GetWindowThreadProcessId_(WindowID(1), 0), 1)
    child = GetFocus_()
    AttachThreadInput_(GetWindowThreadProcessId_(parent, 0), GetWindowThreadProcessId_(WindowID(1), 0), 0)
    SetGadgetText(3, GadgetText(child))
  EndIf
  
Until event = #PB_Event_CloseWindow
Gruß
Scarabol
Abgeschlossen Projekte:
Schreibmaschine, Bildschirmlupe, Wings3DtoOgreMeshConverter
Watch: PureArea

PB-V: 4
WinXP