Page 1 of 1
Special Question about IDE-Tools
Posted: Mon Dec 30, 2024 10:08 am
by Bisonte
Is it possible to trigger a menu item of the IDE, from an external tool ( e.g. "Restart Compiler" ) ?
And if the answer is yes... How ?

Re: Special Question about IDE-Tools
Posted: Wed Jan 01, 2025 4:34 pm
by Axolotl
@Bisonte,
you can try this on your own risk.
Code: Select all
EnableExplicit
; Edit: Windows only solution:
; Easy MenuItem Constants
;
#MENUINDEX_Compiler = 4 ; "Compiler"
#MENUINDEX_RestartCompiler = 7 ; "Re&start Compiler" ..... this is the correct menu item for Restart Compiler
;#MENUINDEX_RestartCompiler = 9 ; "Compiler Options..." ..... for test reasons -> this shows the Options Dialog
; ---
Procedure GetPureBasicMainWindowHandle()
Protected hwndMain
;
; simplified version
;
hwndMain = FindWindow_("WindowClass_2", #Null) ; handle of Purebasic main window
ProcedureReturn hwndMain
EndProcedure
; ---
Procedure.s ReadMenuItemText(hMenu, Index)
Protected mii.MENUITEMINFO
Protected text$
mii\cbSize = SizeOf(MENUITEMINFO)
mii\fMask = #MIIM_STRING
mii\fType = #MFT_STRING
mii\dwTypeData = 0 ; <= get the needed length
If GetMenuItemInfo_(hMenu, Index, #True, @mii) ; : Debug "cch = " + mii\cch
text$ = Space(mii\cch)
mii\dwTypeData = @text$
If GetMenuItemInfo_(hMenu, Index, #True, @mii)
text$ = PeekS(mii\dwTypeData, mii\cch) ; success
Else
text$ = "" ; failure
EndIf
EndIf
ProcedureReturn text$
EndProcedure
; ---
Procedure GetMenuItemSubMenu(hMenu, Index)
Protected result, mii.MENUITEMINFO
mii\cbSize = SizeOf(MENUITEMINFO)
mii\fMask = #MIIM_SUBMENU
If GetMenuItemInfo_(hMenu, Index, #True, @mii)
ProcedureReturn mii\hSubMenu
EndIf
ProcedureReturn 0
EndProcedure
; ---
Procedure SendMenuItemClick(hWnd, hMenu, Index)
Protected nMenuID
nMenuID = GetMenuItemID_(hMenu, Index)
PostMessage_(hWnd, #WM_COMMAND, nMenuID, #Null) ; hit the menu...
EndProcedure
; ---
Procedure SendRestartCompilerClick()
Protected hwndPB, hMenu, hSubMenu
Protected text$
hwndPB = GetPurebasicMainWindowHandle()
If hwndPB
hMenu = GetMenu_(hwndPB)
If hMenu
; text$ = ReadMenuItemText(hMenu, #MENUINDEX_Compiler)
; Debug " MenuItem [" + #MENUINDEX_Compiler + "] = '" + text$ + "'"
hSubmenu = GetMenuItemSubMenu(hMenu, #MENUINDEX_Compiler)
If hSubmenu
; text$ = ReadMenuItemText(hSubMenu, #MENUINDEX_RestartCompiler)
; Debug " MenuItem [" + #MENUINDEX_RestartCompiler + "] = '" + text$ + "'"
SendMenuItemClick(hwndPB, hSubmenu, #MENUINDEX_RestartCompiler)
EndIf
EndIf
EndIf
EndProcedure
SendRestartCompilerClick()
Re: Special Question about IDE-Tools
Posted: Thu Jan 02, 2025 2:00 am
by Bisonte
Nice approach, but unfortunately this will only work on Windows.
At some point freak had mentioned making IDE functions accessible
via external tools (unfortunately I can't find the post at the moment)
and it could have been that it somehow slipped past me unnoticed...
Re: Special Question about IDE-Tools
Posted: Thu Jan 02, 2025 12:21 pm
by Sicro
Bisonte wrote: Thu Jan 02, 2025 2:00 am
At some point freak had mentioned making IDE functions accessible
via external tools (unfortunately I can't find the post at the moment)
Here is freak's feature thread:
viewtopic.php?t=44895
The feature was canceled:
https://github.com/fantaisie-software/p ... c/pull/169
Re: Special Question about IDE-Tools
Posted: Thu Jan 02, 2025 2:26 pm
by Axolotl
Yeah, sorry. I am on windows, only.
Trying Linux, but still not sure if I stay with PB on Linux.
So another answer to your Question: Maybe this is available on Linux and MacOS:
1. Create a shortcut
2. Call the shortcut by (I dont know) SendKeys() or similar.
BTW: Is this section only intended for platform-independent solutions?