Get IDE text of current tab [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Get IDE text of current tab [Resolved]

Post by Kwai chang caine »

Hello at all :D

Thanks to the splendid code of SPARKIE, i can obtain all the source code of all the tab of the IDE 8)
http://www.purebasic.fr/english/viewtop ... 67#p122167

Code: Select all

Procedure.l enumChildren(hwnd.l, lParam.l) 
  
 If hwnd  
 
  parentText.s = Space(256) 
  childText.s = Space(2000) ; <==== KCC augment this value too
  classText.s = Space(256) 
  childID = GetDlgCtrlID_(hwnd) 
  SendMessage_(hwnd, #WM_GETTEXT, 2000, @childText)  ; <==== KCC augment this value too
  GetClassName_(hwnd, @classText, 256) 
  GetWindowRect_(hwnd, @winRc.RECT) 
  winW.s = Str(winRc\right - winRc\left) 
  winH.s = Str(winRc\bottom - winRc\top) 

  If classText = "Scintilla" ; <======  KCC have adding this lines HERE
   Debug childText 
  EndIf 
  
  ProcedureReturn #True

 Else 
 
  ProcedureReturn #False
 
 EndIf
   
EndProcedure 
But my problem, i have all the source text and his HANDLE, and i don't know how, i can obtain the handle of the CURRENT tab, for just have the source code of him, and compare with my handle list :|

Someone know how do that ?

Have a good day
Last edited by Kwai chang caine on Mon Apr 10, 2017 1:54 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

Re: Get IDE text of current tab

Post by wombats »

The PureBasic IDE uses the TabBarGadget for its tabs, which is based on the Canvas gadget. I'm not sure you could identify the tabs using Windows API functions. The best I can personally think of is to detect which ScintillaGadget is the active one.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Get IDE text of current tab

Post by Kwai chang caine »

Hello WOMBATS :D

Aaahhh !!! it's a pity, i like the API :cry:

I have thinking to use Scintilla, but several code about this subject not works :|
In fact, all the code using

Code: Select all

GetEnvironmentVariable("PB_TOOL_Scintilla")
i don't know why :|

Thanks to your answer 8) and also your link, i don't know this nice site :shock:
ImageThe happiness is a road...
Not a destination
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Get IDE text of current tab

Post by ChrisR »

Hi KCC,

You could also find the great TabBarGadget here http://www.purebasic.fr/english/viewtop ... 12&t=47588

In the ~same subject, I'm looking if there is a way to open a new tab from outside and to copy the ClipboardText in it
without going through a %temp% file. Let me know if you see something about.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Get IDE text of current tab

Post by Kwai chang caine »

Hello ChrisR :)

In fact, i not search about TabBarGadget, but just know the handle of the CURRENT tab in the PB IDE for capture the source code in it :wink:

Apparently, it's impossible to do with the API :|
ImageThe happiness is a road...
Not a destination
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 794
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Re: Get IDE text of current tab

Post by Zebuddi123 »

Hi Kcc If you use ms spy++ 14 you will se all of pbs windows classes handle tabs all the info you need here`s a link https://www.dropbox.com/s/m2c2fosj2u46k ... 4.rar?dl=0 just a plain folder with a 32 and 64 bit version just run from folder :)
Zebuddi. Have Fun .....
malleo, caput, bang. Ego, comprehendunt in tempore
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Get IDE text of current tab

Post by Josh »

Did you have a look to 'external tools'? With %File you will not get the active tab, but you can get the filename of the active source code. Maybe this will help.
sorry for my bad english
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Get IDE text of current tab

Post by Kwai chang caine »

Thanks at you two for your help 8)

@Zebuddi
Interesting tool, i keep it 8)
But i want to have this handle all the time i need
And with the digger tool of Netmaestro i have already see, each tab, so each source code have his personal handle, and i see also that with the sparkie code :D
The problem is just know what is the good code, so the good handle in all them, i want to say the current code :wink:

@Josh
Yes you have totalely right, they are also another way for obtain the source file code.
The constante #pb_sourcefile.
With her, i can also open the file and read all the code recorded.

If i not found better way, i use this one.
But i think they are surely other method...finally i hope :lol:

The scintilla method appears good, but i don't know if we can sending message to it from another application :|
ImageThe happiness is a road...
Not a destination
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: Get IDE text of current tab

Post by Bisonte »

@KCC: Always use Integer to hold handles ! NOT Long !
If you have an os-handle = ALWAYS use integer like hWnd.i or hFont.i ....
This prevents you to spend hours on bugsearching.
PureBasic 6.10 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.)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Get IDE text of current tab

Post by Kwai chang caine »

Hello BISONTE :D

Again a time you surprising me :shock:
Since the begining, i always believe it's obligatory to use long for handle :oops:
Because handle can be a long number and not truncate it...
Then since all this time i convert all my handle of all my code in long :lol:

So again thank you very much of this second tips 8)

Good, i'm ready...
i know now never i use a long for my current handle
Remain more than found this current handle :lol:
ImageThe happiness is a road...
Not a destination
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: Get IDE text of current tab

Post by Bisonte »

Hi KCC. Very funny... I found a post from Axolotl, that is the answer
of your topic... and the second post of this thread is from KCC :D
PureBasic 6.10 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.)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Get IDE text of current tab

Post by Kwai chang caine »

Hi BISONTE :shock:

I search also my cord and a good and strong tree :oops:
And i ensure you, i have searching in all the code i take each day before asking this... :|
And also searching in the forum about scintilla, found several with this famous environnement variable who not works...

Decidedly, BISONTE never you finish to surprising me in this time :wink:
In other side, this Kcc that i don't who is it, he not so stupid, because he have right...
This code can be very usefull a day .. :lol:

I test it tommorow, now i answer you with the green alien :mrgreen:

Again thanks for all your precious help, you are a mother for me 8)
Have the best week end of the world
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Get IDE text of current tab

Post by Kwai chang caine »

Yeeees !!!!
Thanks to BISONTE, SPARKIE, AXOLOTL so..... a real army of programmers for just one KCC :oops:
I have found exactely what i want 8)

In fact the code of AXOLOTL not return the handle of Scintilla...i don't know why :oops:
Then i have use the SPARKIE code for enumerate all the windows named PureBasic, and search the Scintilla classe, take his handle for give it to Axolotl code :lol:

I put my cowpat here, if she can be usefull for someone (Like say a certain KCC a day of full moon :mrgreen:)
Again thanks for all try to help me, and have a good day 8)

Code: Select all

Global hwndPb.i
Global hSciWnd.i

Procedure.s Scintilla_GetText()
 
 Protected Result$, ProcessID, PID
 Protected *MemoryID, *Buffer, Format, Length, BytesRead
 
 If hSciWnd And GetWindowThreadProcessId_(hSciWnd, @PID)
  ProcessID = OpenProcess_(#PROCESS_ALL_ACCESS, #False, PID)
 EndIf
 
 If ProcessID
  Select SendMessage_(hSciWnd, #SCI_GETCODEPAGE, #Null, #Null)
   Case 0     : Format = #PB_Ascii
   Case 65001 : Format = #PB_UTF8
  EndSelect
  
  Length = SendMessage_(hSciWnd, #SCI_GETTEXTLENGTH, 0, 0) 
  Length * StringByteLength("A", Format)
  
  *Buffer = AllocateMemory(Length+SizeOf(Character))
  If *Buffer
   *MemoryID = VirtualAllocEx_(ProcessID, #Null, Length, #MEM_RESERVE|#MEM_COMMIT, #PAGE_EXECUTE_READWRITE)
   If *MemoryID
    SendMessage_(hSciWnd, #SCI_GETTEXT, Length, *MemoryID)
    ReadProcessMemory_(ProcessID, *MemoryID, *Buffer, Length, @BytesRead)
    Result$ = PeekS(*Buffer, BytesRead)
    VirtualFreeEx_(ProcessID, *MemoryID, Length, #MEM_RELEASE)
   EndIf
   FreeMemory(*Buffer)
  EndIf
  CloseHandle_(ProcessID)
 EndIf
 ProcedureReturn Result$ 
EndProcedure

Procedure.l enumChildren(hwnd.l, lParam.l) 
 
 If hwnd
  
  classText.s = Space(256) 
  GetClassName_(hwnd, @classText, 256) 
  
  If classText = "Scintilla"
   hSciWnd = hwnd
   ProcedureReturn #False
  EndIf
  
  ProcedureReturn #True
  
 Else 
  
  ProcedureReturn #False
  
 EndIf
 
EndProcedure

Procedure.l enumWins(hwnd.l, lParam.l)
 
 If hwnd
 
  If IsWindowVisible_(hwnd)
  
   pText.s = Space(256)
   SendMessage_(hwnd, #WM_GETTEXT, 256, @pText)
   
   If FindString(pText, "PureBasic", 1, #PB_String_NoCase) And FindString(pText, ".")
    hwndPb = hwnd
    ProcedureReturn #False
   EndIf
   
  EndIf
 
  ProcedureReturn #True
 
 Else
 
  ProcedureReturn #False
 
 EndIf
 
EndProcedure

EnumWindows_(@enumWins(), 0) 
EnumChildWindows_(hwndPb, @enumChildren(), 0)
MessageRequester("", Scintilla_GetText())
ImageThe happiness is a road...
Not a destination
Axolotl
Enthusiast
Enthusiast
Posts: 446
Joined: Wed Dec 31, 2008 3:36 pm

Re: Get IDE text of current tab [Resolved]

Post by Axolotl »

Hi KCC,

my code is not bullet proofed. So some changes on the z-order and no more handle....
To use enumwindows is the recommended way to do so, otherwise the code below covers the current situation.

Code: Select all

Procedure.i Scintilla_GetHandle()  ;' returns hWnd of the 'Scintilla Control'
  Protected hWnd
  hWnd = FindWindowEx_(GetDesktopWindow_(), 0, "WindowClass_2", 0)    :Debug "WindowClass_2, hWnd="+Str(hWnd)
  hWnd = FindWindowEx_(hWnd, 0, "PureSplitter", 0)                    :Debug "PureSplitter, hWnd="+Str(hWnd)
  hWnd = FindWindowEx_(hWnd, 0, "PureSplitter", 0)                    :Debug "PureSplitter, hWnd="+Str(hWnd)
  hWnd = FindWindowEx_(hWnd, 0, "PureContainer", 0)                   :Debug "PureContainer, hWnd="+Str(hWnd)
  hWnd = FindWindowEx_(hWnd, 0, "Scintilla", 0)                       :Debug "Scintilla, hWnd="+Str(hWnd)
  ProcedureReturn hWnd
EndProcedure


BTW:
There is another small bug (UTF8, unicode, x64) inside the code.
Please change as follows:

Code: Select all

Result$ = PeekS(*Buffer, BytesRead)   -->  Result$ = PeekS(*Buffer, BytesRead, Format)
Happy coding.
Take care.
Andreas
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Get IDE text of current tab [Resolved]

Post by Kwai chang caine »

Thanks Axolotl for your bug fix
That's works now with W10 X64 8)
ImageThe happiness is a road...
Not a destination
Post Reply