I ended up creating some events, im not sure if is the way to use in C++ but good for some testing.
bool onLoad;
void on_Load();
bool onClosing;
void on_Closing();
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if(onLoad == false)
{
onLoad = true;
on_Load();
}
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
onClosing = true;
on_Closing();
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
void on_Load()
{
ofstream myFile;
myFile.open("C:\\Loading.txt", ios::out | ios::app);
myFile << "Loading!";
myFile.close();
}
void on_Closing()
{
ofstream myFile;
myFile.open("C:\\Closing.txt", ios::out | ios::app);
myFile << "Closing!";
myFile.close();
}