Laurens Posted June 18, 2011 Share Posted June 18, 2011 Thought I'd share this bit of code with you I found quite useful. It basically checks if your game has already been started to prevent players from going bananas on your executable. If your game has already been started, it brings it to the front. const bool Application::IsOnlyInstance(const std::string title) const { HANDLE h = CreateMutex(0, true, title.c_str()); if (GetLastError() != ERROR_SUCCESS) { HWND hWnd = FindWindow(title.c_str(), 0); if (hWnd != 0) { ShowWindow(hWnd, SW_SHOWNORMAL); SetFocus(hWnd); SetForegroundWindow(hWnd); SetActiveWindow(hWnd); } return false; } return true; } Title refers to the caption in the window's title bar so you do need to call this after having called SetAppTitle(...). From GameCode: http://code.google.com/p/gamecode3/ Cheers! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.