Pelles C forum

Pelles C => Add-ins => Topic started by: John Z on February 11, 2025, 01:30:38 AM

Title: DeleteMode
Post by: John Z on February 11, 2025, 01:30:38 AM
When I created the Add-In to create a new mode by copying and existing one - https://forum.pellesc.de/index.php?topic=10590.0 I didn't think to add a method to delete/remove them too.

When Pelle incorporated his method to do the same thing into the IDE he did not overlook this feature.  However his delete does not work.  Bug report https://forum.pellesc.de/index.php?topic=11410.0 It removes the mode name from the list of modes, but when the project is reopened, or the list is refreshed, the removed mode is still there.  View the ppj file and it shows it has not been deleted.  With Pelle stepping out for a while, or forever, the IDE method to delete won't be fixed.

So - here is an Add-In DeleteMode to enable the deletion of Modes easily. Back-up is performed unless selected to not back-up the ppj file.

John Z

Project code, reasonably commented, is included as is a readme.txt with more information. The DeleteMode.dll is ready to be copied into the AddIns64 subdirectory.  Or build it as you wish.

Any bug reports are appreciated - no messenger will perish...
Title: Re: DeleteMode
Post by: TimoVJL on February 11, 2025, 01:58:44 PM
Time to test deleting mode, like deleting mode Debug
Test it only with test project.
As example don't have icon, button is empty in Toolbar, but show Delete Mode Debug, when cursor is over it.
#define WIN32_LEAN_AND_MEAN
#define UNICODE /* for Windows API */
#include <windows.h>
#include <commctrl.h>
#include <addin.h>

// Private command ID - any number will do.
#define ID_TEST  1

void PrjTest(void);

// Locals.
static HANDLE g_hmod = NULL;
static HWND g_hwndMain = NULL;
static HWND g_hwndProj = NULL;

BOOL WINAPI DllMainCRTStartup(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved)
//BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved)
{
if (dwReason == DLL_PROCESS_ATTACH) g_hmod = hDLL;
return TRUE;
}

ADDINAPI BOOL WINAPI AddInMain(HWND hwnd, ADDIN_EVENT eEvent)
{
switch (eEvent)
{
case AIE_APP_CREATE:
{
ADDIN_ADD_COMMAND AddCmd = {0};

/* Save handle of main IDE window */
g_hwndMain = hwnd;

/* Add command to project context menu */
AddCmd.cbSize = sizeof(AddCmd);
AddCmd.pszText = L"Delete Mode Debug";  // button text.
AddCmd.hIcon = LoadImage(g_hmod, MAKEINTRESOURCE(8001), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR|LR_SHARED);  // button icon.
AddCmd.id = ID_TEST;
AddCmd.idMenu = AIM_MENU_NOTHING; // Toolbar button
if (!AddIn_AddCommand(hwnd, &AddCmd))
return FALSE;
return TRUE;
}
case AIE_PRJ_CREATE:
AddIn_WriteOutput(g_hwndMain, L"AIE_PRJ_CREATE");
g_hwndProj = hwnd;
return TRUE;

case AIE_PRJ_DESTROY:
g_hwndProj = NULL;
AddIn_WriteOutput(g_hwndMain, L"AIE_PRJ_DESTROY");
return TRUE;

case AIE_APP_DESTROY:
return AddIn_RemoveCommand(hwnd, ID_TEST);

default:
return TRUE;
}
}

ADDINAPI void WINAPI AddInCommandEx(int idCmd, LPCVOID pcvData)
{
if (idCmd == ID_TEST)
PrjTest();
}

void PrjTest(void)
{
AddIn_WriteOutput(g_hwndMain, L"PrjDelMode");
if (AddIn_DeleteProjectMode(g_hwndProj, L"Debug"))
{
AddIn_WriteOutput(g_hwndMain, L"Debug Mode Deleted");
}
}


When it  works, in Output windowAIE_PRJ_CREATE
PrjDelMode
Debug Mode Deleted
AIE_PRJ_DESTROY

Hopefully we hear, if there are any problems with Windows 10, 11,...

Works in Windows 10
Title: Re: DeleteMode
Post by: John Z on February 12, 2025, 01:42:46 AM
Worked with the new code base. Much simpler than mine....
My system is WIN11 23H2 - -

I'll try Pelle's Mode box again but .... several tries did not work.  Maybe API call not attached to the button.

John Z


AIE_PRJ_CREATE
PrjDelMode
Debug Mode Deleted
Title: Re: DeleteMode
Post by: TimoVJL on February 12, 2025, 01:15:14 PM
Good to know, that poide Add-In API still works in Windows 11 in this part.
Exceptions can ruin many things, like locking shared files issues.
Title: Re: DeleteMode
Post by: John Z on February 14, 2025, 11:01:30 PM
After the gentle hint by TimoVJL that the API still works - and unsaid but meant that I should use it, I have rewritten the DeleteMode add-in using the API capabilities, instead of doing it all from scratch like the first version.  Attached here is the version 2 using api calls.  It is also my first ever time using a callback function  :).

So - here is the revised Add-In DeleteMode version 2, to enable the deletion of Modes easily. Back-up is performed unless selected to not back-up the ppj file.

John Z

Project code, reasonably commented, is included as is a readme.txt with more information. The DeleteMode.dll is ready to be copied into the AddIns64 subdirectory.  Or build it, revise it, as you wish.

As before any bug reports are appreciated - no messenger will perish...
Title: Re: DeleteMode
Post by: John Z on May 16, 2025, 03:19:00 PM
Tested under Pelles C V13 RC3 works well no code changes.

John Z

Update - This is not needed anymore. Pelles v13 is working fine.