@@ -211,7 +211,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
211211 case IDM_EXPORTDB : DoExportDb (); break ;
212212 case IDM_IMPORTCSV : DoImportCSV (); break ;
213213 case IDM_IMPORTCEDB : DoImportCEDB (); break ;
214- case IDM_EXIT : DestroyWindow (hwnd ); break ;
214+ case IDM_EXIT : SendMessage (hwnd , WM_CLOSE , 0 , 0 ); break ;
215215 case IDM_EXECUTE : ExecuteQuery (); break ;
216216 case IDM_FIND : DoFind (); break ;
217217 case IDM_FINDNEXT : DoFindNext (); break ;
@@ -239,10 +239,12 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
239239 case IDM_FONTSIZE :
240240 CycleFontSize ();
241241 break ;
242- case IDOK : DestroyWindow (hwnd ); break ;
242+ case IDOK : SendMessage (hwnd , WM_CLOSE , 0 , 0 ); break ;
243243 case 1001 :
244- if (HIWORD (wParam ) == EN_CHANGE && g_viewMode == 0 )
244+ if (HIWORD (wParam ) == EN_CHANGE && g_viewMode == 0 ) {
245245 UpdateLineCount ();
246+ if (!g_showingHint ) g_queryDirty = 1 ;
247+ }
246248 break ;
247249 }
248250 return 0 ;
@@ -257,7 +259,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
257259
258260 case WM_SYSKEYDOWN :
259261 if (wParam == 'X' && GetKeyState (VK_MENU ) < 0 ) {
260- DestroyWindow (hwnd );
262+ SendMessage (hwnd , WM_CLOSE , 0 , 0 );
261263 return 0 ;
262264 }
263265 break ;
@@ -275,6 +277,16 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
275277 }
276278 break ;
277279
280+ case WM_CLOSE :
281+ if (g_queryDirty ) {
282+ int r = MessageBoxW (hwnd , L"Save changes to query?" , L"SQLite/CE" ,
283+ MB_YESNOCANCEL | MB_ICONQUESTION );
284+ if (r == IDCANCEL ) return 0 ;
285+ if (r == IDYES ) DoSaveQuery ();
286+ }
287+ DestroyWindow (hwnd );
288+ return 0 ;
289+
278290 case WM_DESTROY :
279291 CloseDatabase ();
280292 if (g_hFontQuery ) DeleteObject (g_hFontQuery );
0 commit comments