windowswinapiuser32comdlg32

Close Find/Replace Dialog programmatically


How do I close the Windows Find and Replace dialog boxes programmatically ensuring the FINDMSGSTRING message is sent so I can get the settings to save them? DestroyWindow does not send the message.


Solution

  • FindText() and ReplaceText() both return an HWND for the dialog. If you want to close that HWND yourself programmably, send it a WM_CLOSE message. That is the same message the dialog receives if the user dismisses the dialog. It will destroy itself after closing, but this gives it the opportunity to send the final FINDMSGSTRING message to you.