I have defined a WndProc
which looks similar to below (the code is written in C++Builder, but it applies in similar form to Delphi as well):
#define WM_SETTINGS_UPDATE WM_APP + 1234
#define WM_GUI_UPDATE WM_APP + 1235
void __fastcall TForm1::WndProc(TMessage &fMessage)
{
switch (fMessage.Msg)
{
default: break;
case WM_SETTINGS_UPDATE: ProcessMySettingsUpdate();
fMessage.Result = 1;
return;
break; // I know this is not needed, I do this purely for aesthetics
case WM_GUI_UPDATE: ProcessMyGUIUpdate();
fMessage.Result = 1;
return;
break; // I know this is not needed, I do this purely for aesthetics
}
TForm::WndProc(fMessage);
}
So in essence this:
checks for my custom
WM_APP
range messages (WM_SETTINGS_UPDATE
andWM_GUI_UPDATE
) in this case.processes those messages and then sets
fMessage.Result
to1
indicating message was processed and returns (avoidingTForm:WndProc(fMessage)
, which I understand is the same asinherited
in Delphi, and not needed if the message is processed).if my messages are not processed, it just calls
TForm:WndProc(fMessage)
(orinherited
) to do the default processing.
My concern is this - what if there is a situation where the application is shutting down, and there are still some messages being unprocessed (left in the message queue by PostMessage()
)?
What I'd like to do in such a situation is to avoid calling my own processing, as it might result in some uninitialized memory Access Violations or similar. Is this basically enough, or do I need to apply some special processing to avoid that kind of situation, or process some "application shutting down" code?
And also - do I need to call inherited
/ TForm:WndProc(fMessage)
after I am done with my processing, or is it safe to do it like above (set Result
to 1 and return)?
Note - this does not necessarily apply to the MainForm
(the first Form being created).