You could make arrays with the ID numbers and names and then run a loop
to create the items, sort of like this:
int i, ret;
UINT ids[]={1001,1002,1003,1004,0};
TCHAR* names[]={L"&Import", L"&Export", L"&Backup", L"E&xit"};
i=0;
while(ids[i])
{
ret = AppendMenu(this->hFileMenu, MF_ENABLED | MF_STRING, ids[i], names[i]);
if (ret == 0)
{
while(GetMenuItemCount(this->hFileMenu) > 0)
DeleteMenu(this->hFileMenu, 0, MF_BYPOSITION);
break;
}
i++;
}
Afaik Winapi functions don't throw C++ exceptions, except when you
crash the function by passing it an invalid pointer or something like that,
but I'm not entirely sure of this.