Working on new editor enhancements?
the.weavster
Addict
Posts: 1531 Joined: Thu Jul 03, 2003 6:53 pm
Location: England
Post
by the.weavster » Wed Sep 07, 2016 9:37 pm
I've created a console app/tool that on compile/run generates Declares for all files that are currently open in the IDE (including
Modules using a naming convention *). I had hoped that I would be able to output narrative using PrintN() and it would appear in the lower pane of the IDE but it doesn't. Is there a way to send strings from a tool for the IDE to display?
*The convention is simple.
For a Module:
Code: Select all
;-mod-name.pb
DeclareModule myModule
XIncludeFile "mod-name-public.pb" ; this file is generated by the tool
EndDeclareModule
Module myModule
XIncludeFile "mod-name-private.pb" ; this file is generated by the tool
; leading underscore means private, declare is created in *-private.pb
Procedure.i _MyPrivateFunction()
; ...
EndProcedure
; no leading underscore, declare is created in *-public.pb
Procedure.i MyPublicFunction()
; ...
EndProcedure
EndModule
And for a standard source file:
Code: Select all
;-my-code.pb
XIncludeFile "my-code-declares.pb" ; this file is generated by the tool
freak
PureBasic Team
Posts: 5929 Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany
Post
by freak » Thu Sep 08, 2016 6:55 pm
I don't think i ever officially documented this, but the following code works with any recent PB version (Windows only):
Compile this and run it as a tool:
Code: Select all
Procedure WriteIDELog(Message$)
Protected CopyData.COPYDATASTRUCT
Protected IDEWindow = Val(GetEnvironmentVariable("PB_Tool_MainWindow"))
If IDEWindow And Message$
CopyData\dwData = ('L' << 16) | ('O' << 8) | 'G'
CopyData\cbData = StringByteLength(Message$, #PB_Ascii)
CopyData\lpData = AllocateMemory(CopyData\cbData + 1)
If CopyData\lpData
PokeS(CopyData\lpData, Message$, -1, #PB_Ascii)
SendMessage_(IDEWindow, #WM_COPYDATA, #Null, @CopyData)
FreeMemory(CopyData\lpData)
EndIf
EndIf
EndProcedure
WriteIDELog("This is the tool speaking!")
WriteIDELog("Another message from the tool.")
quidquid Latine dictum sit altum videtur
bbanelli
Enthusiast
Posts: 543 Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:
Post
by bbanelli » Thu Sep 08, 2016 10:12 pm
IDEWindow is 0 for both x86 and x64 PB 5.5, W7 x64.
Bisonte
Addict
Posts: 1226 Joined: Tue Oct 09, 2007 2:15 am
Post
by Bisonte » Thu Sep 08, 2016 10:20 pm
bbanelli wrote: IDEWindow is 0 for both x86 and x64 PB 5.5, W7 x64.
This will only work if you compile it and execute it from the IDE as a tool....
P ureB asic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom
English is not my native language...
(I often use DeepL to translate my texts.)
bbanelli
Enthusiast
Posts: 543 Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:
Post
by bbanelli » Thu Sep 08, 2016 10:35 pm
Bisonte wrote: bbanelli wrote: IDEWindow is 0 for both x86 and x64 PB 5.5, W7 x64.
This will only work if you compile it and execute it from the IDE as a tool....
Oh. I see. So this can't really be used instead of somewhat annoying feature of DebuggerWarning() which switches IDE's tab to the line warning occurred, instead of only displaying it in message box of PB's IDE? Since this is quite inconvenient feature while testing software and having multiple IDE tabs opened, only to be forcefully switched to DebuggerWarning() line...
http://imgur.com/a/yCAq5
freak
PureBasic Team
Posts: 5929 Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany
Post
by freak » Thu Sep 08, 2016 10:47 pm
It also works if it is not a tool. You just need another way to find the target IDE window in this case as the environment variable is only available for tools.
quidquid Latine dictum sit altum videtur
infratec
Always Here
Posts: 6810 Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany
Post
by infratec » Fri Sep 09, 2016 9:49 am
Code: Select all
Procedure.l EnumWindowCallback(hWnd.l, lParam.l)
Protected Result.l
Protected CopyData.COPYDATASTRUCT
Protected Message$
Result = #True
If hWnd
*Buffer = AllocateMemory(256)
If *Buffer
GetWindowText_(hWnd, *Buffer, MemorySize(*Buffer))
WindowTitle$ = PeekS(*Buffer)
;Debug WindowTitle$
If FindString(WindowTitle$, "PureBasic " + Left(Str(#PB_Compiler_Version), 1))
Message$ = PeekS(lParam)
CopyData\dwData = ('L' << 16) | ('O' << 8) | 'G'
CopyData\cbData = StringByteLength(Message$, #PB_Ascii)
CopyData\lpData = AllocateMemory(CopyData\cbData + 1)
If CopyData\lpData
PokeS(CopyData\lpData, Message$, -1, #PB_Ascii)
SendMessage_(hWnd, #WM_COPYDATA, #Null, @CopyData)
FreeMemory(CopyData\lpData)
EndIf
Result = #False
EndIf
FreeMemory(*Buffer)
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Procedure WriteIDELog(Message$)
EnumWindows_(@EnumWindowCallback(), @Message$)
EndProcedure
WriteIDELog("Hello World!")
Bernd
Taz
User
Posts: 52 Joined: Sat Jan 20, 2018 5:28 pm
Location: Germany
Post
by Taz » Wed Jan 31, 2018 11:46 am
freak wrote: I don't think i ever officially documented this, but the following code works with any recent PB version (Windows only):
Compile this and run it as a tool:
Code: Select all
Procedure WriteIDELog(Message$)
Protected CopyData.COPYDATASTRUCT
Protected IDEWindow = Val(GetEnvironmentVariable("PB_Tool_MainWindow"))
If IDEWindow And Message$
CopyData\dwData = ('L' << 16) | ('O' << 8) | 'G'
CopyData\cbData = StringByteLength(Message$, #PB_Ascii)
CopyData\lpData = AllocateMemory(CopyData\cbData + 1)
If CopyData\lpData
PokeS(CopyData\lpData, Message$, -1, #PB_Ascii)
SendMessage_(IDEWindow, #WM_COPYDATA, #Null, @CopyData)
FreeMemory(CopyData\lpData)
EndIf
EndIf
EndProcedure
WriteIDELog("This is the tool speaking!")
WriteIDELog("Another message from the tool.")
Thank you .
I searched/tried for hours for this possibility.
Maybe you should do it natively as a function in PB?
One question: How can I delete the log from a tool?
oO0XX0Oo
User
Posts: 78 Joined: Thu Aug 10, 2017 7:35 am
Post
by oO0XX0Oo » Wed Jan 31, 2018 2:29 pm
@infratec
When I compile your code and start the exe while the PureBasic IDE
is NOT running, I get a windows message dialog:
"...exe doesn't work anymore"
Code: Select all
Problemsignatur:
Problemereignisname: APPCRASH
Anwendungsname: Test.exe
Anwendungsversion: 0.0.0.0
Anwendungszeitstempel: 5a71c278
Fehlermodulname: ntdll.dll
Fehlermodulversion: 6.3.9600.17415
Fehlermodulzeitstempel: 54504b0d
Ausnahmecode: c0000005
Ausnahmeoffset: 0004298d
Betriebsystemversion: 6.3.9600.2.0.0.400.8
Gebietsschema-ID: 1031
Zusatzinformation 1: 5861
Zusatzinformation 2: 5861822e1919d7c014bbb064c64908b2
Zusatzinformation 3: a10f
Zusatzinformation 4: a10ff7d2bb2516fdc753f9c34fc3b069
Lesen Sie unsere Datenschutzbestimmungen online:
http://go.microsoft.com/fwlink/?linkid=280262
Wenn die Onlinedatenschutzbestimmungen nicht verfügbar sind, lesen Sie unsere Datenschutzbestimmungen offline:
C:\Windows\system32\de-DE\erofflps.txt
If the IDE IS running, everything works fine
Kwai chang caine
Always Here
Posts: 5342 Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France
Post
by Kwai chang caine » Wed Jan 31, 2018 8:18 pm
Too much strong FREAK and INFRATEC, that works for me (W10 x86 v5.61 x86)
Thanks for sharing
The happiness is a road...
Not a destination
Taz
User
Posts: 52 Joined: Sat Jan 20, 2018 5:28 pm
Location: Germany
Post
by Taz » Sun Mar 11, 2018 8:13 am
freak wrote: I don't think i ever officially documented this, but the following code works with any recent PB version (Windows only):
Compile this and run it as a tool:
Code: Select all
Procedure WriteIDELog(Message$)
Protected CopyData.COPYDATASTRUCT
Protected IDEWindow = Val(GetEnvironmentVariable("PB_Tool_MainWindow"))
If IDEWindow And Message$
CopyData\dwData = ('L' << 16) | ('O' << 8) | 'G'
CopyData\cbData = StringByteLength(Message$, #PB_Ascii)
CopyData\lpData = AllocateMemory(CopyData\cbData + 1)
If CopyData\lpData
PokeS(CopyData\lpData, Message$, -1, #PB_Ascii)
SendMessage_(IDEWindow, #WM_COPYDATA, #Null, @CopyData)
FreeMemory(CopyData\lpData)
EndIf
EndIf
EndProcedure
WriteIDELog("This is the tool speaking!")
WriteIDELog("Another message from the tool.")
How can this be done with Linux?