MCPcopy Create free account
hub / github.com/GPUOpen-Effects/GeometryFX / DXUTSetWindow

Function DXUTSetWindow

framework/d3d11/dxut/Core/DXUT.cpp:1124–1179  ·  view source on GitHub ↗

-------------------------------------------------------------------------------------- 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. ------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1122// Instead of calling this, you can call DXUTCreateWindow() to create a new window.
1123//--------------------------------------------------------------------------------------
1124_Use_decl_annotations_
1125HRESULT WINAPI DXUTSetWindow( HWND hWndFocus, HWND hWndDeviceFullScreen, HWND hWndDeviceWindowed, bool bHandleMessages )
1126{
1127 HRESULT hr;
1128
1129 // Not allowed to call this from inside the device callbacks
1130 if( GetDXUTState().GetInsideDeviceCallback() )
1131 return DXUT_ERR_MSGBOX( L"DXUTCreateWindow", E_FAIL );
1132
1133 GetDXUTState().SetWindowCreateCalled( true );
1134
1135 // To avoid confusion, we do not allow any HWND to be nullptr here. The
1136 // caller must pass in valid HWND for all three parameters. The same
1137 // HWND may be used for more than one parameter.
1138 if( !hWndFocus || !hWndDeviceFullScreen || !hWndDeviceWindowed )
1139 return DXUT_ERR_MSGBOX( L"DXUTSetWindow", E_INVALIDARG );
1140
1141 // If subclassing the window, set the pointer to the local window procedure
1142 if( bHandleMessages )
1143 {
1144 // Switch window procedures
1145 LONG_PTR nResult = SetWindowLongPtr( hWndFocus, GWLP_WNDPROC, (LONG_PTR)DXUTStaticWndProc );
1146
1147 DWORD dwError = GetLastError();
1148 if( nResult == 0 )
1149 return DXUT_ERR_MSGBOX( L"SetWindowLongPtr", HRESULT_FROM_WIN32(dwError) );
1150 }
1151
1152 if( !GetDXUTState().GetDXUTInited() )
1153 {
1154 // If DXUTInit() was already called and failed, then fail.
1155 // DXUTInit() must first succeed for this function to succeed
1156 if( GetDXUTState().GetDXUTInitCalled() )
1157 return E_FAIL;
1158
1159 // If DXUTInit() hasn't been called, then automatically call it
1160 // with default params
1161 hr = DXUTInit();
1162 if( FAILED( hr ) )
1163 return hr;
1164 }
1165
1166 WCHAR* strCachedWindowTitle = GetDXUTState().GetWindowTitle();
1167 GetWindowText( hWndFocus, strCachedWindowTitle, 255 );
1168 strCachedWindowTitle[255] = 0;
1169
1170 HINSTANCE hInstance = ( HINSTANCE )( LONG_PTR )GetWindowLongPtr( hWndFocus, GWLP_HINSTANCE );
1171 GetDXUTState().SetHInstance( hInstance );
1172 GetDXUTState().SetWindowCreatedWithDefaultPositions( false );
1173 GetDXUTState().SetWindowCreated( true );
1174 GetDXUTState().SetHWNDFocus( hWndFocus );
1175 GetDXUTState().SetHWNDDeviceFullScreen( hWndDeviceFullScreen );
1176 GetDXUTState().SetHWNDDeviceWindowed( hWndDeviceWindowed );
1177
1178 return S_OK;
1179}
1180
1181

Callers

nothing calls this directly

Calls 1

DXUTInitFunction · 0.85

Tested by

no test coverage detected