@@ -138,3 +138,128 @@ int PromptForPath(const wchar_t *title, const wchar_t *defPath) {
138138
139139 return DialogBoxIndirectW (g_hInst , & dlg .tmpl , g_hwndMain , PathDlgProc ) == IDOK ;
140140}
141+
142+ /*============================================================================
143+ ** Options Dialog
144+ **============================================================================*/
145+
146+ #define IDC_OPT_CLEAREXEC 1001
147+ #define IDC_OPT_EXECATCURSOR 1002
148+ #define IDC_OPT_LINENUMS 1003
149+ #define IDC_OPT_ERRORMSGBOX 1004
150+ #define IDC_OPT_DBPATH 1005
151+
152+ static int g_optClearExec , g_optExecAtCursor , g_optLineNums , g_optErrorMsgBox ;
153+ static wchar_t g_optDbPath [MAX_PATH ];
154+ static HWND g_hwndOptions = NULL ;
155+ static int g_optResult = 0 ;
156+
157+ static void ApplyOptions (HWND hwnd ) {
158+ g_optClearExec = SendMessage (GetDlgItem (hwnd , IDC_OPT_CLEAREXEC ), BM_GETCHECK , 0 , 0 );
159+ g_optExecAtCursor = SendMessage (GetDlgItem (hwnd , IDC_OPT_EXECATCURSOR ), BM_GETCHECK , 0 , 0 );
160+ g_optLineNums = SendMessage (GetDlgItem (hwnd , IDC_OPT_LINENUMS ), BM_GETCHECK , 0 , 0 );
161+ g_optErrorMsgBox = SendMessage (GetDlgItem (hwnd , IDC_OPT_ERRORMSGBOX ), BM_GETCHECK , 0 , 0 );
162+ GetWindowTextW (GetDlgItem (hwnd , IDC_OPT_DBPATH ), g_optDbPath , MAX_PATH );
163+ g_optResult = 1 ;
164+ }
165+
166+ static LRESULT CALLBACK OptionsWndProc (HWND hwnd , UINT msg , WPARAM wParam , LPARAM lParam ) {
167+ switch (msg ) {
168+ case WM_CREATE : {
169+ /* Left column - checkboxes */
170+ CreateWindowW (L"BUTTON" , L"Clear results on execute" ,
171+ WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX ,
172+ 10 , 10 , 165 , 20 , hwnd , (HMENU )IDC_OPT_CLEAREXEC , g_hInst , NULL );
173+ CreateWindowW (L"BUTTON" , L"Execute at cursor" ,
174+ WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX ,
175+ 10 , 32 , 165 , 20 , hwnd , (HMENU )IDC_OPT_EXECATCURSOR , g_hInst , NULL );
176+ CreateWindowW (L"BUTTON" , L"Show line numbers" ,
177+ WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX ,
178+ 10 , 54 , 165 , 20 , hwnd , (HMENU )IDC_OPT_LINENUMS , g_hInst , NULL );
179+ CreateWindowW (L"BUTTON" , L"Message box on error" ,
180+ WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX ,
181+ 10 , 76 , 165 , 20 , hwnd , (HMENU )IDC_OPT_ERRORMSGBOX , g_hInst , NULL );
182+
183+ /* Right column - paths */
184+ CreateWindowW (L"STATIC" , L"Default database path:" ,
185+ WS_CHILD | WS_VISIBLE ,
186+ 185 , 10 , 150 , 16 , hwnd , NULL , g_hInst , NULL );
187+ CreateWindowW (L"EDIT" , g_optDbPath ,
188+ WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL ,
189+ 185 , 28 , 180 , 22 , hwnd , (HMENU )IDC_OPT_DBPATH , g_hInst , NULL );
190+
191+ SendMessage (GetDlgItem (hwnd , IDC_OPT_CLEAREXEC ), BM_SETCHECK , g_optClearExec , 0 );
192+ SendMessage (GetDlgItem (hwnd , IDC_OPT_EXECATCURSOR ), BM_SETCHECK , g_optExecAtCursor , 0 );
193+ SendMessage (GetDlgItem (hwnd , IDC_OPT_LINENUMS ), BM_SETCHECK , g_optLineNums , 0 );
194+ SendMessage (GetDlgItem (hwnd , IDC_OPT_ERRORMSGBOX ), BM_SETCHECK , g_optErrorMsgBox , 0 );
195+ return 0 ;
196+ }
197+ case WM_COMMAND :
198+ if (LOWORD (wParam ) == IDOK ) {
199+ ApplyOptions (hwnd );
200+ DestroyWindow (hwnd );
201+ return 0 ;
202+ }
203+ break ;
204+ case WM_CLOSE :
205+ DestroyWindow (hwnd );
206+ return 0 ;
207+ case WM_DESTROY :
208+ g_hwndOptions = NULL ;
209+ SetFocus (g_viewMode == 0 ? g_hwndQuery : g_hwndResult );
210+ return 0 ;
211+ }
212+ return DefWindowProc (hwnd , msg , wParam , lParam );
213+ }
214+
215+ void DoOptions (void ) {
216+ WNDCLASSW wc = {0 };
217+ RECT rc ;
218+ MSG msg ;
219+
220+ if (g_hwndOptions ) {
221+ SetFocus (g_hwndOptions );
222+ return ;
223+ }
224+
225+ g_optClearExec = g_clearOnExec ;
226+ g_optExecAtCursor = g_execAtCursor ;
227+ g_optLineNums = g_showLineNumbers ;
228+ g_optErrorMsgBox = g_showErrorMsgBox ;
229+ lstrcpyW (g_optDbPath , g_szDefaultDbPath );
230+ g_optResult = 0 ;
231+
232+ wc .lpfnWndProc = OptionsWndProc ;
233+ wc .hInstance = g_hInst ;
234+ wc .hbrBackground = (HBRUSH )(COLOR_BTNFACE + 1 );
235+ wc .lpszClassName = L"SQLiteCEOptions" ;
236+ RegisterClassW (& wc );
237+
238+ GetWindowRect (g_hwndMain , & rc );
239+ g_hwndOptions = CreateWindowExW (WS_EX_CAPTIONOKBTN ,
240+ L"SQLiteCEOptions" , L"Options" ,
241+ WS_POPUP | WS_CAPTION | WS_SYSMENU ,
242+ rc .left + 20 , rc .top + 30 , 380 , 125 ,
243+ g_hwndMain , NULL , g_hInst , NULL );
244+ ShowWindow (g_hwndOptions , SW_SHOW );
245+
246+ /* Modal message loop */
247+ while (g_hwndOptions && GetMessage (& msg , NULL , 0 , 0 )) {
248+ TranslateMessage (& msg );
249+ DispatchMessage (& msg );
250+ }
251+
252+ if (g_optResult ) {
253+ g_clearOnExec = g_optClearExec ;
254+ g_execAtCursor = g_optExecAtCursor ;
255+ g_showErrorMsgBox = g_optErrorMsgBox ;
256+ lstrcpyW (g_szDefaultDbPath , g_optDbPath );
257+
258+ /* Handle line numbers toggle */
259+ if (g_optLineNums != g_showLineNumbers ) {
260+ g_showLineNumbers = g_optLineNums ;
261+ ShowWindow (g_hwndLineNum , (g_viewMode == 0 && g_showLineNumbers ) ? SW_SHOW : SW_HIDE );
262+ SendMessage (g_hwndMain , WM_SIZE , 0 , 0 );
263+ }
264+ }
265+ }
0 commit comments