C++ Close the J2Play community wrapper
From J2Play
C++ ScoreController::SetScores() > Flash Challenge.getPlayerNumber() > Flash Access Basic User Info > C++ Secure Section > C++ Close the J2Play community wrapper
Close the J2Play community wrapper
If you provide a EXIT button in your game except the standard window 'X' close button on topright, call the CloseGameCommunity() API in the button handler to close the playground.
CGDKInstance* j2play = CGDKInstance::GetInstance(); j2play->CloseGameCommunity();
Side effect
Because the game window has become a child window of the J2Play Community, the playground close process may have some side effects on game window.
Usually, the normal process of window game close is
MFC:
1) User clicks EXIT button (or similar opreation); 2) OnLButtonUp() handler (or other similar handler like CWnd::OnCommand(), CDialog::OnOK() and CDialog::OnCancel() ) (Cleanup code 1); 3) The handler function sends WM_CLOSE to the game main window (it is default action for CDialog::OnOK() and CDialog::OnCancel() ); 4) OnClose() handler (Cleanup code 2); 5) Call DestroyWindow() to send WM_DESTROY explicitly (or let CWnd::OnClose() handle it by default) 6) OnDestroy() handler (Cleanup code 3); 7) Call PostQuitMessage() to send WM_QUIT explicitly (or let CWnd::OnDestroy() handle it by default) 8) WM_QUIT message terminates message loop; 9) CWinApp::ExitInstance() (Cleanup code 4).
WIN32:
1) User clicks EXIT button (or similar opreation); 2) WM_LBUTTONUP case of WndProc (or other similar user operation handler) (Cleanup code 1) 3) The operation handler sends WM_CLOSE to the game main window; 4) WM_CLOSE case of WndProc (Cleanup code 2); 5) Call DestroyWindow() explicitly, or call DefaultWndProc to handle WM_CLOSE, both sends WM_DESTROY; 6) WM_DESTROY case of WndProc (Cleanup code 3); 7) Call PostQuitMessage() explicitly, or call DefaultWndProc to handle WM_DESOTRY, both send WM_QUIT; 8) WM_QUIT terminates message loop; 9) Cleanup after message loop (Cleanup code 4).
You may not have all these steps, for example, if your game don't have anything in place of Cleanup code 1 & 2, you may call DestroyWindow() in your code directly when user clicks EXIT button.
However, close through CloseGameCommunity(), the process will becomes
1) User clicks EXIT button (or similar opreation); 2) Your button handler(Cleanup code 1) 3) The handler calls CloseGameCommunity(); 4) CloseGameCommunity() sends WM_CLOSE to the game window; 5) OnClose() or other WM_CLOSE handler (Cleanup code 2); 6) CloseGameCommunity() sends WM_DESTROY to the game window; 7) OnDestry() or other WM_DESTROY handler (Cleanup code 3); 8) CloseGameCommunity() sends WM_QUIT to the message loop; 9) WM_QUIT message terminates message loop; 10) Cleanup after message loop (Cleanup code 4).
So, you need
- check all API calls relates to closing in your code, like SendMessage(WM_CLOSE,0,0), DestroyWindow(), PostQuitMessage(), OnOK() and OnCancel()
- replace the original call(s) with CloseGameCommunity()
- remove other unnecessary close message processing, rely on the CloseGameCommunity() to dispatch all window close messages
