aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-27 19:06:48 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-27 19:12:27 +0200
commit18f3ea2529365de54838b7a1a877322b3f98552d (patch)
tree5175d9e974a6d68a558d373281de1b56b2e6b78e
parentf7534e2524d4b14a457540a987e168bc28f61e5d (diff)
downloadEpisodeBrowser-18f3ea2529365de54838b7a1a877322b3f98552d.tar.gz
Change WM_MENUSELECT handling.
This has two benefits: 1. The for loop is avoided. 2. It is shorter. The drawback is that it is a bit opaque. The order of the array elements still matter, but now it is coupled to what is declared in resource.h, a completely separate file. This makes it harder to change resource.h.
-rw-r--r--c/main.cpp103
-rw-r--r--c/resource.h3
2 files changed, 44 insertions, 62 deletions
diff --git a/c/main.cpp b/c/main.cpp
index 0c82aa0..a9625c3 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -310,71 +310,50 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
}
case WM_MENUSELECT:
{
- static const int aId[] = {
- /*01*/IDM_FILE_EXIT,
- /*02*/IDM_FILE_REFRESH,
- /*03*/IDM_FILE_FETCH_DATA,
- /*04*/IDM_FILE_FETCH_SCREENWRITERS,
- /*05*/IDM_FILE_ABOUT,
- /*06*/IDM_WATCH_LOCALLY,
- /*07*/IDM_WATCH_ONLINE,
- /*08*/IDM_TOGGLE,
- /*09*/IDM_FORGET,
- /*10*/IDM_LOOKUP,
- /*11*/IDM_WIKI,
- /*12*/IDM_RATE10,
- /*13*/IDM_RATE9,
- /*14*/IDM_RATE8,
- /*15*/IDM_RATE7,
- /*16*/IDM_RATE6,
- /*17*/IDM_RATE5,
- /*18*/IDM_RATE4,
- /*19*/IDM_RATE3,
- /*20*/IDM_RATE2,
- /*21*/IDM_RATE1,
- /*22*/IDM_RATE0,
- /*23*/IDM_VIEW_WATCHED,
- /*24*/IDM_VIEW_TV_ORIGINAL,
- /*25*/IDM_VIEW_OTHERS
+ /* Look up status bar help for menu command. The help
+ * strings are stored in arrays, whose indices
+ * correspond to the IDM_ values (see resources.h). */
+
+ static const wchar_t* aWszMenu[] = {
+ /*IDM_FILE_EXIT*/L"Close Episode Browser.",
+ /*IDM_FILE_REFRESH*/L"Quickly refresh episode list.",
+ /*IDM_FILE_FETCH_DATA*/L"Fetch episode data from the web (may take a few seconds).",
+ /*IDM_FILE_FETCH_SCREENWRITERS*/L"Fetch screenwriters from the web (may take a minute).",
+ /*IDM_FILE_ABOUT*/L"Show information about Episode Browser.",
+ /*IDM_VIEW_WATCHED*/(g_bViewWatched? L"Click to hide watched episodes.":
+ L"Click to show watched episodes."),
+ /*IDM_VIEW_TV_ORIGINAL*/(g_bViewTVOriginal?
+ L"Click to hide TV original episodes.":
+ L"Click to show TV original episodes."),
+ /*IDM_VIEW_OTHERS*/(g_szLimitScreenwriter?
+ L"Click to hide episodes by other screenwriters.":
+ L"Click to show episodes by other screenwriters.")
};
- static const wchar_t* aWsz[] = {
- /*01*/L"Close Episode Browser.",
- /*02*/L"Quickly refresh episode list.",
- /*03*/L"Fetch episode data from the web (may take a few seconds).",
- /*04*/L"Fetch screenwriter data from the web (may take a minute).",
- /*05*/L"Show information about Episode Browser.",
- /*06*/L"Open local copy of episode, if available.",
- /*07*/L"Open episode in the web browser.",
- /*08*/L"Toggle watched/unwatched status.",
- /*09*/L"Reset watched/unwatched status.",
- /*10*/L"Fetch episode data from the web, such as date, source and hint.",
- /*11*/L"Show Detective Conan Wiki entry for episode.",
- /*12*/L"Rate episode 10/10.",
- /*13*/L"Rate episode 9/10.",
- /*14*/L"Rate episode 8/10.",
- /*15*/L"Rate episode 7/10.",
- /*16*/L"Rate episode 6/10.",
- /*17*/L"Rate episode 5/10.",
- /*18*/L"Rate episode 4/10.",
- /*19*/L"Rate episode 3/10.",
- /*20*/L"Rate episode 2/10.",
- /*21*/L"Rate episode 1/10.",
- /*22*/L"Remove episode rating.",
- /*23*/g_bViewWatched? L"Click to hide watched episodes.":
- L"Click to show watched episodes.",
- /*24*/g_bViewTVOriginal? L"Click to hide TV original episodes.":
- L"Click to show TV original episodes.",
- /*25*/g_szLimitScreenwriter? L"Click to hide episodes by other screenwriters.":
- L"Click to show episodes by other screenwriters."
+ static const wchar_t* aWszCtx[] = {
+ /*IDM_WATCH_LOCALLY*/L"Open local copy of episode, if available.",
+ /*IDM_WATCH_ONLINE*/L"Open episode in the web browser.",
+ /*IDM_TOGGLE*/L"Toggle watched/unwatched status.",
+ /*IDM_FORGET*/L"Reset watched/unwatched status.",
+ /*IDM_LOOKUP*/L"Fetch episode data from the web, such as date, source and hint.",
+ /*IDM_WIKI*/L"Show Detective Conan Wiki entry for episode.",
+ /*IDM_RATE0*/L"Remove episode rating.",
+ /*IDM_RATE1*/L"Rate episode 1/10.",
+ /*IDM_RATE2*/L"Rate episode 2/10.",
+ /*IDM_RATE3*/L"Rate episode 3/10.",
+ /*IDM_RATE4*/L"Rate episode 4/10.",
+ /*IDM_RATE5*/L"Rate episode 5/10.",
+ /*IDM_RATE6*/L"Rate episode 6/10.",
+ /*IDM_RATE7*/L"Rate episode 7/10.",
+ /*IDM_RATE8*/L"Rate episode 8/10.",
+ /*IDM_RATE9*/L"Rate episode 9/10.",
+ /*IDM_RATE10*/L"Rate episode 10/10."
};
+
const unsigned short wCommand = LOWORD(wParam);
- const wchar_t* wsz = L"";
- for (size_t i = 0; i < sizeof(aId)/sizeof(*aId); i++)
- if (aId[i] == wCommand) {
- wsz = aWsz[i];
- break;
- }
- SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(0,0), (LPARAM)wsz);
+ const unsigned short wGroup = ID_GROUP(wCommand);
+ if (!wGroup) break;
+ const wchar_t** aWsz = wGroup==IDG_MENU? aWszMenu: aWszCtx;
+ SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(0,0), (LPARAM)aWsz[ID_INDEX(wCommand)]);
break;
}
default:
diff --git a/c/resource.h b/c/resource.h
index fe0daa7..8cf2230 100644
--- a/c/resource.h
+++ b/c/resource.h
@@ -12,6 +12,9 @@
#define ID_SUBGROUP(i) ((i) & 0xf000)
#define IDG_CTX_RATE 0x1000
+/* Index within resource group. */
+#define ID_INDEX(i) ((i) & 0x00ff)
+
/* Resources, timers, menus. */
#define IDR_STATUS 0x0100
#define IDR_TIMER 0x0101