|
| 1 | +/* |
| 2 | +** SQLiteCEdit - Dialogs (About, Path prompt) |
| 3 | +*/ |
| 4 | + |
| 5 | +#include "globals.h" |
| 6 | + |
| 7 | +/*============================================================================ |
| 8 | +** About Dialog |
| 9 | +**============================================================================*/ |
| 10 | + |
| 11 | +static HBITMAP g_hLogo = NULL; |
| 12 | + |
| 13 | +static LRESULT CALLBACK AboutWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { |
| 14 | + switch (msg) { |
| 15 | + case WM_CREATE: { |
| 16 | + wchar_t text[256]; |
| 17 | + wchar_t ver[32], built[32]; |
| 18 | + const char *sv = sqlite_libversion(); |
| 19 | + const char *bd = __DATE__; |
| 20 | + int i, j; |
| 21 | + for (i = 0; sv[i] && i < 31; i++) ver[i] = sv[i]; |
| 22 | + ver[i] = 0; |
| 23 | + for (i = 0, j = 0; bd[i] && j < 31; i++) { |
| 24 | + if (bd[i] == ' ' && bd[i+1] == ' ') continue; |
| 25 | + built[j++] = bd[i]; |
| 26 | + } |
| 27 | + built[j] = 0; |
| 28 | + wsprintfW(text, |
| 29 | + L"SQLite/CEdit " SQLITECEDIT_VERSION L" (using SQLite %s)\n" |
| 30 | + L"(C) Intermountain Systems\n" |
| 31 | + L"Build date: %s", ver, built); |
| 32 | + CreateWindowW(L"STATIC", NULL, WS_CHILD | WS_VISIBLE | SS_BITMAP, |
| 33 | + 61, 10, 128, 64, hwnd, (HMENU)100, g_hInst, NULL); |
| 34 | + SendDlgItemMessage(hwnd, 100, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)g_hLogo); |
| 35 | + CreateWindowW(L"STATIC", text, WS_CHILD | WS_VISIBLE | SS_CENTER, |
| 36 | + 5, 80, 240, 50, hwnd, NULL, g_hInst, NULL); |
| 37 | + return 0; |
| 38 | + } |
| 39 | + case WM_COMMAND: |
| 40 | + if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { |
| 41 | + DestroyWindow(hwnd); |
| 42 | + SetFocus(g_viewMode == 0 ? g_hwndQuery : g_hwndResult); |
| 43 | + return 0; |
| 44 | + } |
| 45 | + break; |
| 46 | + case WM_KEYDOWN: |
| 47 | + if (wParam == VK_ESCAPE || wParam == VK_RETURN) { |
| 48 | + DestroyWindow(hwnd); |
| 49 | + SetFocus(g_viewMode == 0 ? g_hwndQuery : g_hwndResult); |
| 50 | + return 0; |
| 51 | + } |
| 52 | + break; |
| 53 | + case WM_CLOSE: |
| 54 | + DestroyWindow(hwnd); |
| 55 | + SetFocus(g_viewMode == 0 ? g_hwndQuery : g_hwndResult); |
| 56 | + return 0; |
| 57 | + } |
| 58 | + return DefWindowProc(hwnd, msg, wParam, lParam); |
| 59 | +} |
| 60 | + |
| 61 | +void DoAbout(void) { |
| 62 | + WNDCLASSW wc = {0}; |
| 63 | + RECT rc; |
| 64 | + HWND hwndAbout; |
| 65 | + |
| 66 | + if (!g_hLogo) |
| 67 | + g_hLogo = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_LOGO)); |
| 68 | + |
| 69 | + wc.lpfnWndProc = AboutWndProc; |
| 70 | + wc.hInstance = g_hInst; |
| 71 | + wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); |
| 72 | + wc.lpszClassName = L"SQLiteCEAbout"; |
| 73 | + RegisterClassW(&wc); |
| 74 | + |
| 75 | + GetWindowRect(g_hwndMain, &rc); |
| 76 | + hwndAbout = CreateWindowW(L"SQLiteCEAbout", L"About", |
| 77 | + WS_POPUP | WS_CAPTION | WS_SYSMENU, |
| 78 | + rc.left + 30, rc.top + 30, 250, 160, |
| 79 | + g_hwndMain, NULL, g_hInst, NULL); |
| 80 | + ShowWindow(hwndAbout, SW_SHOW); |
| 81 | +} |
| 82 | + |
| 83 | +/*============================================================================ |
| 84 | +** Simple Path Input Dialog |
| 85 | +**============================================================================*/ |
| 86 | + |
| 87 | +static wchar_t g_szPathBuf[MAX_PATH]; |
| 88 | +static HWND g_hwndPathEdit; |
| 89 | + |
| 90 | +static LRESULT CALLBACK PathDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { |
| 91 | + switch (msg) { |
| 92 | + case WM_INITDIALOG: { |
| 93 | + RECT rc; |
| 94 | + GetClientRect(hwnd, &rc); |
| 95 | + g_hwndPathEdit = CreateWindowW(L"EDIT", g_szPathBuf, |
| 96 | + WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL, |
| 97 | + 10, 10, rc.right - 20, 26, |
| 98 | + hwnd, (HMENU)101, g_hInst, NULL); |
| 99 | + CreateWindowW(L"BUTTON", L"OK", |
| 100 | + WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, |
| 101 | + 10, 46, 60, 26, hwnd, (HMENU)IDOK, g_hInst, NULL); |
| 102 | + CreateWindowW(L"BUTTON", L"Cancel", |
| 103 | + WS_CHILD | WS_VISIBLE, |
| 104 | + 80, 46, 60, 26, hwnd, (HMENU)IDCANCEL, g_hInst, NULL); |
| 105 | + SetFocus(g_hwndPathEdit); |
| 106 | + return FALSE; |
| 107 | + } |
| 108 | + case WM_COMMAND: |
| 109 | + if (LOWORD(wParam) == IDOK) { |
| 110 | + GetWindowTextW(g_hwndPathEdit, g_szPathBuf, MAX_PATH); |
| 111 | + EndDialog(hwnd, IDOK); |
| 112 | + } else if (LOWORD(wParam) == IDCANCEL) { |
| 113 | + EndDialog(hwnd, IDCANCEL); |
| 114 | + } |
| 115 | + return TRUE; |
| 116 | + case WM_CLOSE: |
| 117 | + EndDialog(hwnd, IDCANCEL); |
| 118 | + return TRUE; |
| 119 | + } |
| 120 | + return FALSE; |
| 121 | +} |
| 122 | + |
| 123 | +int PromptForPath(const wchar_t *title, const wchar_t *defPath) { |
| 124 | + struct { |
| 125 | + DLGTEMPLATE tmpl; |
| 126 | + WORD menu, wndclass, title; |
| 127 | + } dlg; |
| 128 | + |
| 129 | + (void)title; /* TODO: use title in dialog */ |
| 130 | + lstrcpyW(g_szPathBuf, defPath); |
| 131 | + |
| 132 | + memset(&dlg, 0, sizeof(dlg)); |
| 133 | + dlg.tmpl.style = WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_MODALFRAME; |
| 134 | + dlg.tmpl.cx = 160; |
| 135 | + dlg.tmpl.cy = 50; |
| 136 | + dlg.tmpl.x = 20; |
| 137 | + dlg.tmpl.y = 20; |
| 138 | + |
| 139 | + return DialogBoxIndirectW(g_hInst, &dlg.tmpl, g_hwndMain, PathDlgProc) == IDOK; |
| 140 | +} |
0 commit comments