📄 duel.c
字号:
case WM_ERASEBKGND:
return 1;
case WM_PAINT:
hdc = BeginPaint( hWnd, &ps );
if (gnProgramState == PS_SPLASH)
{
// display the splash screen
bltSplash(NULL);
}
EndPaint( hWnd, &ps );
return 1;
case UM_LAUNCH:
// cleanup the wizard thread
if (ghThread)
{
// wait for thread to exit
while (!GetExitCodeThread(ghThread, &dwRetCode));
CloseHandle(ghThread);
}
// start the game in rest mode
gnProgramState = PS_REST;
LaunchGame();
return 1;
case UM_ABORT:
// cleanup the wizard thread
if (ghThread)
{
// wait for thread to exit
while (!GetExitCodeThread(ghThread, &dwRetCode));
CloseHandle(ghThread);
}
ExitGame();
return 1;
case WM_TIMER:
ReceiveMessages();
break;
case WM_DESTROY:
// if gbReinitialize is TRUE don't quit, we are just switching display modes
if (!gbReinitialize)
{
CleanupApplication();
PostQuitMessage( 0 );
}
return 0;
default:
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
} /* MainWndproc */
/*
* InitApplication
*
* Do that initialization stuff...
*/
BOOL InitApplication( HINSTANCE hinst )
{
WNDCLASS wc;
BOOL rc;
glpGuid = (LPGUID) &DUEL_GUID;
LoadString(ghinst, IDS_DUEL_CLASSNAME, gtszClassName, MAX_CLASSNAME);
wc.style = CS_DBLCLKS;
wc.lpfnWndProc = MainWndproc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hinst;
wc.hIcon = LoadIcon( hinst, MAKEINTRESOURCE(DUEL_ICON));
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = GetStockObject( BLACK_BRUSH );
wc.lpszMenuName = NULL;
wc.lpszClassName = gtszClassName;
rc = RegisterClass( &wc );
if( !rc )
{
return FALSE;
}
// Initialize all components
if ((!InitGraphics()) || (!InitInput()) || (!InitSfx()))
{
return FALSE;
}
// start in splash mode
gnProgramState = PS_SPLASH;
return TRUE;
} /* initApplication */
/*
* CleanupApplication
*
* Calls clean up on all components
*/
void CleanupApplication( void )
{
CleanupComm();
CleanupSfx();
CleanupGraphics();
CleanupInput();
}
/*
* LaunchedByLobby
*
* Determines if we were launched by a lobby. If so, gets the connection settings
* and creates our player using the information from the lobby
*/
BOOL LaunchedByLobby(void)
{
HRESULT hr;
HWND hwndStatus;
// create a lobby object
hr = DPLobbyCreate();
if (FAILED(hr))
{
ShowError(IDS_DPLOBBY_ERROR_C);
return FALSE;
}
// get connection settings from the lobby (into glpdplConnection)
hr = DPLobbyGetConnectionSettings();
if (FAILED(hr))
{
if (DPERR_NOTLOBBIED == hr)
{
// we were not lobbied - start up game normally
hr = DPLobbyRelease();
if (FAILED(hr))
{
ShowError(IDS_DPLOBBY_ERROR_R);
goto FAIL;
}
// move on
return FALSE;
}
else
{
ShowError(IDS_DPLOBBY_ERROR_GCS);
goto FAIL;
}
}
// are we hosting or joining ?
if (glpdplConnection->dwFlags & DPLCONNECTION_CREATESESSION)
{
gbIsHost = TRUE;
}
// set our session flags
glpdplConnection->lpSessionDesc->dwFlags = DPSESSION_MIGRATEHOST |
DPSESSION_KEEPALIVE;
// let lobby know our connection flags
hr = DPLobbySetConnectionSettings();
if (FAILED(hr))
{
ShowError(IDS_DPLOBBY_ERROR_SCS);
goto FAIL;
}
if ( !gbIsHost )
{
// show splash screen and
// connection status if we are joining a game
UpdateWindow(ghWndMain);
hwndStatus = ShowConnectStatus();
}
else
{
// we are hosting, don't need connection status
hwndStatus = NULL;
}
// connect to the lobby
hr = DPLobbyConnect();
if ( hwndStatus )
{
// get rid of the connectino status window
DestroyWindow(hwndStatus);
}
if (FAILED(hr))
{
ShowError(IDS_DPLOBBY_ERROR_CONNECT);
goto FAIL;
}
// create our player
hr = DPlayCreatePlayer(
&gOurID,
#ifdef UNICODE
glpdplConnection->lpPlayerName->lpszShortName,
#else
glpdplConnection->lpPlayerName->lpszShortNameA,
#endif
NULL,
NULL,
0
);
if (FAILED(hr))
{
ShowError(IDS_DPLAY_ERROR_CP);
goto FAIL;
}
// cleanup
hr = DPLobbyRelease();
if (FAILED(hr))
{
ShowError(IDS_DPLOBBY_ERROR_R);
goto FAIL;
}
// we were lobbied
return TRUE;
FAIL:
// cleanup and exit
DPLobbyRelease();
ExitGame();
return FALSE;
}
/*
* Displays error to the user
*/
BOOL ShowError( int iStrID )
{
TCHAR tszMsg[MAX_ERRORMSG];
TCHAR tszTitle[MAX_WINDOWTITLE];
LoadString(ghinst, iStrID, tszMsg, MAX_ERRORMSG);
LoadString(ghinst, IDS_DUEL_ERROR_TITLE, tszTitle, MAX_WINDOWTITLE);
MessageBox( ghWndMain, tszMsg, tszTitle, MB_OK );
return FALSE;
}
/*
* Displays connection status to the user
*/
HWND ShowConnectStatus(void)
{
HWND hwnd;
hwnd = CreateDialog( ghinst, MAKEINTRESOURCE(IDD_CONNECT_STATUS), ghWndMain, NULL);
return hwnd;
}
/*
* UpdateTitle
*
* Updates the window title based on application status
*/
void UpdateTitle(void)
{
DWORD dwFeatures;
TCHAR tszTitle[MAX_WINDOWTITLE];
UINT iStringID;
// calculate title features
dwFeatures = 0;
if (gbReliable)
dwFeatures |= 1;
if (gbIsHost)
dwFeatures |= 2;
switch (dwFeatures)
{
case 0:
iStringID = IDS_DUEL_TITLE;
break;
case 1:
iStringID = IDS_DUEL_RELIABLE_TITLE;
break;
case 2:
iStringID = IDS_DUEL_HOST_TITLE;
break;
case 3:
iStringID = IDS_DUEL_HOST_RELIABLE_TITLE;
break;
}
// get appropriate window title for these features
LoadString(ghinst, iStringID, tszTitle, MAX_WINDOWTITLE);
// change window title
SetWindowText(ghWndMain, tszTitle);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -