Skip to content

Commit d427f41

Browse files
committed
Implemented keyboard accelerator for better shortcut handling
1 parent 3f53c53 commit d427f41

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/sqlite-ce-edit/main.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static HWND g_hwndMain;
5757
static HWND g_hwndCB;
5858
static HWND g_hwndStatus;
5959
static HMENU g_hMenu;
60+
static HACCEL g_hAccel;
6061
static HWND g_hwndQuery; /* SQL input */
6162
static HWND g_hwndResult; /* Results output */
6263
static sqlite *g_db = NULL;
@@ -2026,12 +2027,23 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmd, int nShow) {
20262027
WNDCLASSW wc = {0};
20272028
MSG msg;
20282029
RECT rcWork;
2030+
ACCEL accel[10];
2031+
int nAccel = 0;
20292032

20302033
(void)hPrev; (void)lpCmd; (void)nShow;
20312034

20322035
g_hInst = hInst;
20332036
InitCommonControls();
20342037

2038+
/* Build accelerator table */
2039+
accel[nAccel].fVirt = FCONTROL | FVIRTKEY; accel[nAccel].key = 'O'; accel[nAccel].cmd = IDM_OPENQUERY; nAccel++;
2040+
accel[nAccel].fVirt = FCONTROL | FVIRTKEY; accel[nAccel].key = 'S'; accel[nAccel].cmd = IDM_SAVEQUERY; nAccel++;
2041+
accel[nAccel].fVirt = FCONTROL | FVIRTKEY; accel[nAccel].key = 'F'; accel[nAccel].cmd = IDM_FIND; nAccel++;
2042+
accel[nAccel].fVirt = FVIRTKEY; accel[nAccel].key = VK_F3; accel[nAccel].cmd = IDM_FINDNEXT; nAccel++;
2043+
accel[nAccel].fVirt = FVIRTKEY; accel[nAccel].key = VK_F5; accel[nAccel].cmd = IDM_EXECUTE; nAccel++;
2044+
accel[nAccel].fVirt = FVIRTKEY; accel[nAccel].key = VK_F6; accel[nAccel].cmd = IDM_VIEWRESULT; nAccel++;
2045+
g_hAccel = CreateAcceleratorTableW(accel, nAccel);
2046+
20352047
SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWork, 0);
20362048

20372049
wc.lpfnWndProc = WndProc;
@@ -2055,9 +2067,12 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmd, int nShow) {
20552067
OpenDatabase(L":memory:");
20562068

20572069
while (GetMessage(&msg, NULL, 0, 0)) {
2058-
TranslateMessage(&msg);
2059-
DispatchMessage(&msg);
2070+
if (!TranslateAccelerator(g_hwndMain, g_hAccel, &msg)) {
2071+
TranslateMessage(&msg);
2072+
DispatchMessage(&msg);
2073+
}
20602074
}
20612075

2076+
if (g_hAccel) DestroyAcceleratorTable(g_hAccel);
20622077
return (int)msg.wParam;
20632078
}

0 commit comments

Comments
 (0)