📄 dxut.cpp
字号:
}
wcscpy( strFlag, L"height" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
if( DXUTGetCmdParam( strCmdLine, strFlag, nFlagLen ) )
{
int nHeight = _wtoi(strFlag);
GetDXUTState().SetOverrideHeight( nHeight );
}
continue;
}
wcscpy( strFlag, L"startx" );
nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
if( DXUTGetCmdParam( strCmdLine, strFlag, nFlagLen ) )
{
int nX = _wtoi(strFlag);
GetDXUTState().SetOverrideStartX( nX );
}
continue;
}
wcscpy( strFlag, L"starty" );
nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
if( DXUTGetCmdParam( strCmdLine, strFlag, nFlagLen ) )
{
int nY = _wtoi(strFlag);
GetDXUTState().SetOverrideStartY( nY );
}
continue;
}
wcscpy( strFlag, L"constantframetime" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
float fTimePerFrame;
if( DXUTGetCmdParam( strCmdLine, strFlag, nFlagLen ) )
fTimePerFrame = (float)wcstod( strFlag, NULL );
else
fTimePerFrame = 0.0333f;
GetDXUTState().SetOverrideConstantFrameTime( true );
GetDXUTState().SetOverrideConstantTimePerFrame( fTimePerFrame );
DXUTSetConstantFrameTime( true, fTimePerFrame );
continue;
}
wcscpy( strFlag, L"quitafterframe" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
if( DXUTGetCmdParam( strCmdLine, strFlag, nFlagLen ) )
{
int nFrame = _wtoi(strFlag);
GetDXUTState().SetOverrideQuitAfterFrame( nFrame );
}
continue;
}
wcscpy( strFlag, L"noerrormsgboxes" ); nFlagLen = (int) wcslen(strFlag);
if( _wcsnicmp( strCmdLine, strFlag, nFlagLen ) == 0 )
{
GetDXUTState().SetShowMsgBoxOnError( false );
strCmdLine += nFlagLen;
continue;
}
// Unrecognized flag
wcsncpy( strFlag, strCmdLine, 256 ); strFlag[255] = 0;
WCHAR* strSpace = strFlag;
while (*strSpace && (*strSpace > L' '))
strSpace++;
*strSpace = 0;
DXUTOutputDebugString( L"Unrecognized flag: %s", strFlag );
strCmdLine += wcslen(strFlag);
}
}
//--------------------------------------------------------------------------------------
// Helper function for DXUTParseCommandLine. Updates strCmdLine and strFlag
// Example: if strCmdLine=="-width:1024 -forceref"
// then after: strCmdLine==" -forceref" and strFlag=="1024"
//--------------------------------------------------------------------------------------
bool DXUTGetCmdParam( WCHAR*& strCmdLine, WCHAR* strFlag, int nFlagLen )
{
strCmdLine += nFlagLen;
if( *strCmdLine == L':' )
{
strCmdLine++; // Skip ':'
// Place NULL terminator in strFlag after current token
wcsncpy( strFlag, strCmdLine, 256 );
strFlag[255] = 0;
WCHAR* strSpace = strFlag;
while (*strSpace && (*strSpace > L' '))
strSpace++;
*strSpace = 0;
// Update strCmdLine
strCmdLine += wcslen(strFlag);
return true;
}
else
{
strFlag[0] = 0;
return false;
}
}
//--------------------------------------------------------------------------------------
// Creates a window with the specified window title, icon, menu, and
// starting position. If DXUTInit() has not already been called, it will
// call it with the default parameters. Instead of calling this, you can
// call DXUTSetWindow() to use an existing window.
//--------------------------------------------------------------------------------------
HRESULT DXUTCreateWindow( const WCHAR* strWindowTitle, HINSTANCE hInstance,
HICON hIcon, HMENU hMenu, int x, int y )
{
HRESULT hr;
// Not allowed to call this from inside the device callbacks
if( GetDXUTState().GetInsideDeviceCallback() )
return DXUT_ERR_MSGBOX( L"DXUTCreateWindow", E_FAIL );
GetDXUTState().SetWindowCreateCalled( true );
if( !GetDXUTState().GetDXUTInited() )
{
// If DXUTInit() was already called and failed, then fail.
// DXUTInit() must first succeed for this function to succeed
if( GetDXUTState().GetDXUTInitCalled() )
return E_FAIL;
// If DXUTInit() hasn't been called, then automatically call it
// with default params
hr = DXUTInit();
if( FAILED(hr) )
return hr;
}
if( DXUTGetHWNDFocus() == NULL )
{
if( hInstance == NULL )
hInstance = (HINSTANCE)GetModuleHandle(NULL);
WCHAR szExePath[MAX_PATH];
GetModuleFileName( NULL, szExePath, MAX_PATH );
if( hIcon == NULL ) // If the icon is NULL, then use the first one found in the exe
hIcon = ExtractIcon( hInstance, szExePath, 0 );
// Register the windows class
WNDCLASS wndClass;
wndClass.style = CS_DBLCLKS;
wndClass.lpfnWndProc = DXUTStaticWndProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = hIcon;
wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
wndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = L"Direct3DWindowClass";
if( !RegisterClass( &wndClass ) )
{
DWORD dwError = GetLastError();
if( dwError != ERROR_CLASS_ALREADY_EXISTS )
return DXUT_ERR_MSGBOX( L"RegisterClass", HRESULT_FROM_WIN32(dwError) );
}
// Set the window's initial style. It is invisible initially since it might
// be resized later
DWORD dwWindowStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME |
WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
GetDXUTState().SetWinStyle( dwWindowStyle );
RECT rc;
// Override the window's initial & size position if there were cmd line args
if( GetDXUTState().GetOverrideStartX() != -1 )
x = GetDXUTState().GetOverrideStartX();
if( GetDXUTState().GetOverrideStartY() != -1 )
y = GetDXUTState().GetOverrideStartY();
GetDXUTState().SetWindowCreatedWithDefaultPositions( false );
if( x == CW_USEDEFAULT && y == CW_USEDEFAULT )
GetDXUTState().SetWindowCreatedWithDefaultPositions( true );
// Find the window's initial size, but it might be changed later
int nDefaultWidth = 640;
int nDefaultHeight = 480;
if( GetDXUTState().GetOverrideWidth() != 0 )
nDefaultWidth = GetDXUTState().GetOverrideWidth();
if( GetDXUTState().GetOverrideHeight() != 0 )
nDefaultHeight = GetDXUTState().GetOverrideHeight();
SetRect( &rc, 0, 0, nDefaultWidth, nDefaultHeight );
AdjustWindowRect( &rc, dwWindowStyle, ( hMenu != NULL ) ? true : false );
WCHAR* strCachedWindowTitle = GetDXUTState().GetWindowTitle();
wcsncpy( strCachedWindowTitle, strWindowTitle, 256 );
strCachedWindowTitle[255] = 0;
// Create the render window
HWND hWnd = CreateWindow( L"Direct3DWindowClass", strWindowTitle, dwWindowStyle,
x, y, (rc.right-rc.left), (rc.bottom-rc.top), 0,
hMenu, hInstance, 0 );
if( hWnd == NULL )
{
DWORD dwError = GetLastError();
return DXUT_ERR_MSGBOX( L"CreateWindow", HRESULT_FROM_WIN32(dwError) );
}
// Record the window's client & window rect
RECT rcWindowClient;
GetClientRect( hWnd, &rcWindowClient );
GetDXUTState().SetWindowClientRect( rcWindowClient );
RECT rcWindowBounds;
GetWindowRect( hWnd, &rcWindowBounds );
GetDXUTState().SetWindowBoundsRect( rcWindowBounds );
GetDXUTState().SetWindowCreated( true );
GetDXUTState().SetHWNDFocus( hWnd );
GetDXUTState().SetHWNDDeviceFullScreen( hWnd );
GetDXUTState().SetHWNDDeviceWindowed( hWnd );
}
return S_OK;
}
//--------------------------------------------------------------------------------------
// Sets a previously created window for the framework to use. If DXUTInit()
// has not already been called, it will call it with the default parameters.
// Instead of calling this, you can call DXUTCreateWindow() to create a new window.
//--------------------------------------------------------------------------------------
HRESULT DXUTSetWindow( HWND hWndFocus, HWND hWndDeviceFullScreen, HWND hWndDeviceWindowed, bool bHandleMessages )
{
HRESULT hr;
// Not allowed to call this from inside the device callbacks
if( GetDXUTState().GetInsideDeviceCallback() )
return DXUT_ERR_MSGBOX( L"DXUTCreateWindow", E_FAIL );
GetDXUTState().SetWindowCreateCalled( true );
// To avoid confusion, we do not allow any HWND to be NULL here. The
// caller must pass in valid HWND for all three parameters. The same
// HWND may be used for more than one parameter.
if( hWndFocus == NULL || hWndDeviceFullScreen == NULL || hWndDeviceWindowed == NULL )
return DXUT_ERR_MSGBOX( L"DXUTSetWindow", E_INVALIDARG );
// If subclassing the window, set the pointer to the local window procedure
if( bHandleMessages )
{
// Switch window procedures
#ifdef _WIN64
LONG_PTR nResult = SetWindowLongPtr( hWndFocus, GWLP_WNDPROC, (LONG_PTR)DXUTStaticWndProc );
#else
LONG_PTR nResult = SetWindowLongPtr( hWndFocus, GWLP_WNDPROC, (LONG)(LONG_PTR)DXUTStaticWndProc );
#endif
DWORD dwError = GetLastError();
if( nResult == 0 )
return DXUT_ERR_MSGBOX( L"SetWindowLongPtr", HRESULT_FROM_WIN32(dwError) );
}
if( !GetDXUTState().GetDXUTInited() )
{
// If DXUTInit() was already called and failed, then fail.
// DXUTInit() must first succeed for this function to succeed
if( GetDXUTState().GetDXUTInitCalled() )
return E_FAIL;
// If DXUTInit() hasn't been called, then automatically call it
// with default params
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -