コード例 #1
0
LRESULT CALLBACK MyWindow::wndProc(UINT message, WPARAM wParam, LPARAM lParam)
{
   HDC          hdc;
   PAINTSTRUCT  ps;
   BOOL ret;

   switch(message)
   {
   case WM_PAINT:
	   hdc = BeginPaint(this->hWnd, &ps);
		//disegno qualcosa...
	   if ( this->graphRoutine ) this->graphRoutine->onPaint(hdc, ps, NULL);
	   EndPaint(this->hWnd, &ps);
	   return 0;
   case WM_DESTROY:
	   this->onDestroy();
	   if ( this->isMainFlag ) PostQuitMessage(0);
	   return 0;
   default:
	   ret = DefWindowProc(this->hWnd, message, wParam, lParam);
	   if ( this->listener )
	   {

		   this->listener->executeMessage(getID(), getHWND(), message, wParam, lParam);
	   }
   }

   return ret;
}
コード例 #2
0
ファイル: xtail.cpp プロジェクト: alwynd/PublicGitRepo
LRESULT XTailForm::wndMsgProc(HWND hwndX2, UINT m, WPARAM w, LPARAM l, bool defaultX)
{
	ComponentContainer::wndMsgProc(hwndX2, m, w, l, false);

	int width, height;
	HWND hwndX = NULL;

	switch (m)
	{
	case WM_SIZE:
		height = HIWORD(l);
		width = LOWORD(l);
		if (height == 0)
			height = 1;

		//Resize the text component.
		hwndX = getHWND(TXT_OUTPUT);
		if (hwndX)
		{
			MoveWindow(hwndX, 3, 23, width-25, height-25, true);
		}

		return 0;
		break;
	default:
		break;
	};

	return DefWindowProc(hwndX2, m, w, l);
}
コード例 #3
0
bool IEView::setFocus(HWND prevFocus) {
	if (GetFocus() != hwnd && !getFocus) { // && IsChild(prevFocus, hwnd
		SetFocus(GetParent(getHWND()));
//		SetFocus(prevFocus);
		return true;
	}
	getFocus = false;
	return false;
}
コード例 #4
0
ファイル: IEView.cpp プロジェクト: kmdtukl/miranda-ng
bool IEView::setFocus(HWND)
{
	if (GetFocus() != hwnd && !getFocus) {
		SetFocus(GetParent(getHWND()));
		return true;
	}

	getFocus = false;
	return false;
}
コード例 #5
0
ファイル: D3DWindow.cpp プロジェクト: fearless40/gravwell-3
bool D3DWindow::initalize(bool VSync, bool FullScreen)
{
    setHWND( Window::createHWND( 0, L"D3DWindow" ) );
    D3D11::ScreenMode sm;

    // Get the screen mode settings
    d3d->getScreenSettings(sm ,1024,768);

    return d3d->initalizeDisplay( getHWND(), VSync, FullScreen, sm );
}
コード例 #6
0
void PowerWinApp::openLicence()
{
  auto exe_dir = Windows::Path(Windows::Application::getExecutablePath())
                 .getFolder();
  auto licence_path = exe_dir + L"\\" POWERWIN_LICENCE_PATH;
  if (Windows::Path::exists(licence_path))
  {
    ::ShellExecuteW(
      getHWND(),
      L"open", licence_path.c_str(), nullptr, nullptr,
      SW_SHOW);
  }
  else
  {
    ::ShellExecuteW(
      getHWND(),
      L"open", POWERWIN_LICENCE_URL, nullptr, nullptr,
      SW_SHOW);
  }
}
コード例 #7
0
GHOST_TSuccess GHOST_WindowWin32::initMultisample(PIXELFORMATDESCRIPTOR pfd)
{
	int pixelFormat;
	bool success = FALSE;
	UINT numFormats;
	HDC hDC = GetDC(getHWND());
	float fAttributes[] = {0, 0};
	UINT nMaxFormats = 1;

	// The attributes to look for
	int iAttributes[] = {
		WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
		WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
		WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
		WGL_COLOR_BITS_ARB, pfd.cColorBits,
		WGL_DEPTH_BITS_ARB, pfd.cDepthBits,
		WGL_ALPHA_BITS_ARB, pfd.cAlphaBits,
		WGL_STENCIL_BITS_ARB, pfd.cStencilBits,
		WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
		WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,
		WGL_SAMPLES_ARB, m_multisample,
		0, 0
	};

	// Get the function
	PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");

	if (!wglChoosePixelFormatARB)
	{
		m_multisampleEnabled = GHOST_kFailure;
		return GHOST_kFailure;
	}

	// iAttributes[17] is the initial multisample. If not valid try to use the closest valid value under it.
	while (iAttributes[17] > 0) {
		// See if the format is valid
		success = wglChoosePixelFormatARB(hDC, iAttributes, fAttributes, nMaxFormats, &pixelFormat, &numFormats);
		GHOST_PRINTF("WGL_SAMPLES_ARB = %i --> success = %i, %i formats\n", iAttributes[17], success, numFormats);

		if (success && numFormats >= 1 && m_multisampleEnabled == GHOST_kFailure) {
			GHOST_PRINTF("valid pixel format with %i multisamples\n", iAttributes[17]);
			m_multisampleEnabled = GHOST_kSuccess;
			m_msPixelFormat = pixelFormat;
		}
		iAttributes[17] -= 1;
		success = GHOST_kFailure;
	}
	if (m_multisampleEnabled == GHOST_kSuccess) {
		return GHOST_kSuccess;
	}
	GHOST_PRINT("no available pixel format\n");
	return GHOST_kFailure;
}
コード例 #8
0
ファイル: IEView.cpp プロジェクト: kmdtukl/miranda-ng
void IEView::setWindowPos(int x, int y, int cx, int cy)
{
	rcClient.left = x;
	rcClient.top = y;
	rcClient.right = cx;
	rcClient.bottom = cy;

	SetWindowPos(getHWND(), HWND_TOP, x, y, cx, cy, 0);
	/*
	CComPtr<IOleInPlaceObject> inPlaceObject;
	if (SUCCEEDED(pWebBrowser.QueryInterface(&inPlaceObject)))
		inPlaceObject->SetObjectRects(&rcClient, &rcClient);
	*/
}
コード例 #9
0
ファイル: IEView.cpp プロジェクト: kmdtukl/miranda-ng
void IEView::setBorder()
{
	LONG style = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
	LONG oldStyle = style;
	if (Options::getGeneralFlags() & Options::GENERAL_NO_BORDER) {
#ifndef GECKO
		style &= ~(WS_EX_STATICEDGE);
#endif
	}
	else style |= (WS_EX_STATICEDGE);

	if (oldStyle != style) {
		SetWindowLongPtr(hwnd, GWL_EXSTYLE, style);
		SetWindowPos(getHWND(), NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
	}
}
コード例 #10
0
void ApplicationWin32Imp::start() {
    if( false == createWindow() )
        throw exception();

    render_->setHWND( getHWND() );

    if( false == render_->createDevice( isWindowedMode(), getScreenWidth(), getScreenHeight() ) ) {
        destroyWindow();
        throw exception();
    }

    mainLoop();

    render_->destroyDevice();

    destroyWindow();
}
コード例 #11
0
void VLCHolderWnd::LibVlcAttach(libvlc_media_player_t* p_md)
{
    if(!_p_md){
        _p_md = p_md;
        libvlc_media_player_set_hwnd(p_md, getHWND());

        libvlc_event_manager_t* em = libvlc_media_player_event_manager(_p_md);
        if(em){
            //We need set hook to catch doubleclicking (to switch to fullscreen and vice versa).
            //But libvlc media window not exist yet,
            //and we don't know when it will be created, nor ThreadId of it.
            //So we try catch first libvlc_MediaPlayerPositionChanged event,
            //(suppose wnd will be created to that moment)),
            //and then try set mouse hook.
            _LibVlcESAttached =
                0==libvlc_event_attach(em, libvlc_MediaPlayerPositionChanged,
                                       OnLibVlcEvent, this);
        }
    }
}
コード例 #12
0
void PowerWinApp::onCreate() {
  print(L"PowerWin::start\n");
  log(Info) << L"ClassName: " << getClassName() << std::endl;

  configuration_.loadIniFile(
    Application::getExecutablePath() + L"\\config.ini"
  );

  // tray icon
  tray_icon_.setIcon(POWERWIN_ICON_SMALL);
  tray_icon_.setToolTip(POWERWIN_PACKAGE_NAME);
  tray_icon_.add(getHWND());

  // popup menu
  popup_menu_ = createPopupMenu();

  info_menu_ = createPopupMenu();
  info_menu_.addEntry(InfoEntry, POWERWIN_PACKAGE_NAME POWERWIN_PACKAGE_VERSION);
  info_menu_.addEntry(InfoEntry, _("Copyright © 2014-2016 R1tschY"));
  info_menu_.addEntry(InfoLicence, _("Licenced under GPL v3"));
  popup_menu_.addMenu(L"Info", info_menu_);

  popup_menu_.addSeperator();
  popup_menu_.addEntry(AutostartEntry, _("Start with Windows"));
  popup_menu_.check(AutostartEntry, isProgramInAutostart());
  popup_menu_.addSeperator();
  popup_menu_.addEntry(QuitEntry, _("Quit"));

  // hotkeys
  auto quit_shortcut = configuration_.readValue(L"powerwin", L"quit", L"Ctrl+F12");
  quit_shortcut_.setCallback([=](){ destroy(); });
  quit_shortcut_.setKey(quit_shortcut);

  // local modules
  modules_.loadModules();

  // hook modules
  hooklibs_.startLibs();
}
コード例 #13
0
ファイル: AppDelegate.cpp プロジェクト: adroitly/QtEdit
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
	auto director = Director::getInstance();
	auto glview = CCQGLView::getInstance();
	//glview->setBgColor(Color4B(50, 50, 50, 255));
	director->setOpenGLView(glview);
	_mainWindow.setGLView(glview->getGLWidget());
	_mainWindow.show();
	::SetParent(glview->getHWND(), _mainWindow.m_Parent);
    // turn on display FPS
    director->setDisplayStats(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    // create a scene. it's an autorelease object
    auto scene = HelloWorld::createScene();

    // run
    director->runWithScene(scene);

    return true;
}
コード例 #14
0
void IEView::setWindowPos(int x, int y, int cx, int cy) {
	rcClient.left = x;
	rcClient.top = y;
	rcClient.right = cx;
	rcClient.bottom = cy;//y + cy;
 	if (builder == NULL) {
		//scrollToTop();
	} else {
		scrollToBottomSoft();
	}
	SetWindowPos(getHWND(), HWND_TOP, x, y, cx, cy, 0);
	/*
    IOleInPlaceObject * inPlaceObject;
   	if (SUCCEEDED(pWebBrowser->QueryInterface(IID_IOleInPlaceObject, (void **)&inPlaceObject))) {
   		inPlaceObject->SetObjectRects(&rcClient, &rcClient);
   		inPlaceObject->Release();
	}
 	*/
 	if (builder == NULL) {
		//scrollToTop();
	} else {
		scrollToBottomSoft();
	}
}
コード例 #15
0
ファイル: xtail.cpp プロジェクト: alwynd/PublicGitRepo
///Button clicked.
void XTailForm::buttonClicked(int id)
{
	swprintf_s(tbuffer, L"XTailForm button clicked: %i\n", id);
	logger->debug(tbuffer);

	if (id == 99)
	{
		if (chunkCount < 1)
			return;
		current = -1;
		id = BTN_NEXT;
	}
	if (id == 98)
	{
		if (chunkCount < 1)
			return;
		current = chunkCount-1;
		id = BTN_NEXT;
	}

	if (id == BTN_PREV || id == BTN_NEXT)
	{
		if (id == BTN_PREV)
		{
			current -= 1;
			if (current < 0)
				current = 0L;
		}
		if (id == BTN_NEXT)
		{
			current += 1;
			if (current > chunkCount)
				current = chunkCount;
		}

		//Set the start/end chunks.
		__int64 len = getXTail()->len;

		__int64 startXX = (len/chunkCount) * current;
		__int64 endXX = startXX + MAX_FILE_BUFFER;
		if (startXX > len)
			startXX = len;
		if (endXX > len)
			endXX = len;

		swprintf_s(tbuffer, L"Current: %I64i, Start: %I64i, End: %I64i\n", current, startXX, endXX);
		logger->debug(tbuffer);

		swprintf_s(tbuffer, L"%I64i", startXX);
		SendMessageW(getHWND(TXT_BYTE_START), WM_SETTEXT, 2048, (LPARAM) tbuffer);

		swprintf_s(tbuffer, L"%I64i", endXX);
		SendMessageW(getHWND(TXT_BYTE_END), WM_SETTEXT, 2048, (LPARAM) tbuffer);

		id = BTN_LOAD;

	}


	if (id == BTN_LOAD)
	{
		chunkCount = 0l;


		ZeroMemory(tmp, sizeof(wchar_t) * 2048);
		getText(TXT_FILENAME, tmp, 2048);
		swprintf_s(tbuffer, L"Attempting to load file: %s\n", tmp);
		logger->debug(tbuffer);

		wchar_t fileName[2048];
		wcscpy_s(fileName, tmp);

		if (wcslen(tmp) < 1)
		{
			MessageBoxExW(hwnd, L"Please enter a valid filename.", L"Invalid Input", MB_OK, NULL);
			return;
		}

		ZeroMemory(tmp, sizeof(wchar_t) * 2048);
		getText(TXT_BYTE_START, tmp, 2048);
		swprintf_s(tbuffer, L"Start Pos: %s\n", tmp);
		logger->debug(tbuffer);
		if (wcslen(tmp) < 1)
		{
			MessageBoxExW(hwnd, L"Please enter a valid file start position.", L"Invalid Input", MB_OK, NULL);
			return;
		}

		wchar_t *tmpX;

		__int64 start = _wcstoi64(tmp, &tmpX, 10);
		swprintf_s(tbuffer, L"Got the start pos: %I64i\n", start);
		logger->debug(tbuffer);

		ZeroMemory(tmp, sizeof(wchar_t) * 2048);
		getText(TXT_BYTE_END, tmp, 2048);
		swprintf_s(tbuffer, L"End Pos: %s\n", tmp);
		logger->debug(tbuffer);
		if (wcslen(tmp) < 1)
		{
			MessageBoxExW(hwnd, L"Please enter a valid file end position.", L"Invalid Input", MB_OK, NULL);
			return;
		}

		__int64 end = _wcstoi64(tmp, &tmpX, 10);
		
		swprintf_s(tbuffer, L"Got the end pos: %I64i\n", end);
		logger->debug(tbuffer);

		if (start < 0 || end < 1 || (end < start))
		{
			swprintf_s(tbuffer, L"Invalid start(%I64i) and end(%I64i) pos", start, end);
			MessageBoxExW(hwnd, tbuffer, L"Invalid Input", MB_OK, NULL);
			return;
		}


		//Get the file/length.
		__int64 fileLength = getXTail()->getFileLength(fileName);
		swprintf_s(tbuffer, L"Got the file length: %I64i\n", fileLength);
		logger->debug(tbuffer);

		if (fileLength < 1)
		{
			swprintf_s(tbuffer, L"File (%s) is not valid.", fileName);
			MessageBoxExW(hwnd, tbuffer, L"Invalid Input", MB_OK, NULL);
			return;
		}

		if (start > fileLength)
		{
			swprintf_s(tbuffer, L"Start(%I64i) is > file length", start);
			MessageBoxExW(hwnd, tbuffer, L"Invalid Input", MB_OK, NULL);
			return;
		}

		if (end > fileLength)
			end = fileLength;

		//Update window caption.
		char fileNamea[2048];
		SendMessageA(getHWND(TXT_FILENAME), WM_GETTEXT, 2048, (LPARAM) fileNamea);

		wchar_t fmtFileLength[128];
		formatBytes(fileLength, fmtFileLength, 128);

		chunkCount = (fileLength / MAX_FILE_BUFFER);

		swprintf_s(tbuffer, L"Len(%s) - 63Kb Chunks(%I64i), Current: %I64i", fmtFileLength, chunkCount, current);
		logger->debug(tbuffer);

		SendMessageW(getHWND(LBL_CHUNKS), WM_SETTEXT, 2048, (LPARAM) tbuffer);

		//Attempt to load and display file.
		ZeroMemory(file_buffer, sizeof(wchar_t) * MAX_FILE_BUFFER);

		swprintf_s(tbuffer, L"going to call readChunk Start: %I64i, End: %I64i\n", start, end);
		logger->debug(tbuffer);

		if (!getXTail()->readChunk(start, end, file_buffer, MAX_FILE_BUFFER))
			return;
		setText(TXT_OUTPUT, file_buffer, MAX_FILE_BUFFER);
	}

}
コード例 #16
0
LRESULT PowerWinApp::onMessage(UINT msg, WPARAM wparam, LPARAM lparam)
{
  switch (msg)
  {
  // internal management messages
  case Messages::RegisterHooklib:
    hooklibs_.registerHookLib(reinterpret_cast<HWND>(wparam));
    return 0;

  // internal messages
  case WM_NCCREATE:
  case WM_CREATE:
  case WM_DESTROY:
  case WM_NCDESTROY:
    return Control::onMessage(msg, wparam, lparam);

  // filter meaningless messages
  case WM_MOVE:
  case WM_SIZE:
    return ::DefWindowProc(getHWND(), msg, wparam, lparam);

  // trayicon
  case TrayIcon::MessageId:
    return tray_icon_.handleMessage(wparam, lparam, [=](UINT ti_msg, Point pt)
    {
      pt = getCursorPosition();

      switch (ti_msg)
      {
//      case NIN_POPUPOPEN:
      case NIN_SELECT:
      case NIN_KEYSELECT:
      case WM_LBUTTONDOWN:
      case WM_RBUTTONDOWN:
      case WM_CONTEXTMENU:
        onContextMenu(pt);
        return 1;
      }
      return 0;
    });

  // Messages des PopupMenus
  case WM_COMMAND: {
    int id    = LOWORD(wparam);
    int event = HIWORD(wparam);
    // Menüauswahl bearbeiten:
    switch (id)
    {
    case InfoEntry:
      openProjectWebsite();
      return 0;

    case InfoLicence:
      openLicence();
      return 0;

    case AutostartEntry:
      onAutostartSet(!popup_menu_.isEntryChecked(AutostartEntry));
      return 0;

    case QuitEntry:
      destroy();
      return 0;
    }
    return 0;
  }
  }

  // pass message to modules
  auto result = global_events_.handleWindowsMessage(msg, wparam, lparam);
  return result ? result.value() : Control::onMessage(msg, wparam, lparam);
}
コード例 #17
0
void PowerWinApp::onContextMenu(Windows::Point pt)
{
  ::SetForegroundWindow(getHWND());
  openPopupMenu(popup_menu_, pt, getHWND());
}
コード例 #18
0
void PowerWinApp::openProjectWebsite()
{
  ::ShellExecuteW(getHWND(), L"open", POWERWIN_URL, nullptr, nullptr, SW_SHOW);
}
コード例 #19
0
ファイル: xapp.cpp プロジェクト: ClemensX/ShadedPath12
void XApp::init()
{
    //// Basic initialization
    if (initialized) return;
    initialized = true;

    if (!ovrRendering) ovrMirror = false;
    if (ovrRendering) vr.init();

    if (appName.length() == 0) {
        // no app name specified - just use first one from iterator
        auto it = appMap.begin();
        XAppBase *a = it->second;
        if (a != nullptr) {
            appName = it->first;
            Log("WARNING: xapp not specified, using this app: " << appName.c_str() << endl);
        }
    }
    //assert(appName.length() > 0);
    app = getApp(appName);
    if (app != nullptr) {
        //Log("initializing " << appName.c_str() << "\n");
        SetWindowText(getHWND(), string2wstring(app->getWindowTitle()));
    }
    else {
        Log("ERROR: xapp not available " << appName.c_str() << endl);
        // throw assertion error in debug mode
        assert(app != nullptr);
    }
#ifdef _DEBUG
    // Enable the D3D12 debug layer.
    {
        ComPtr<ID3D12Debug> debugController;
        if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController))))
        {
            debugController->EnableDebugLayer();
        }
        HRESULT getAnalysis = DXGIGetDebugInterface1(0, __uuidof(pGraphicsAnalysis), reinterpret_cast<void**>(&pGraphicsAnalysis));
    }
#endif

    //// Viewport and Scissor
    /*	D3D12_RECT rect;
    	if (GetWindowRect(getHWND(), &rect))
    	{
    		int width = rect.right - rect.left;
    		int height = rect.bottom - rect.top;
    		viewport.MinDepth = 0.0f;
    		viewport.TopLeftX = 0.0f;
    		viewport.TopLeftY = 0.0f;
    		viewport.Width = static_cast<float>(width);
    		viewport.Height = static_cast<float>(height);
    		viewport.MaxDepth = 1.0f;

    		scissorRect.left = 0;
    		scissorRect.top = 0;
    		scissorRect.right = static_cast<LONG>(width);
    		scissorRect.bottom = static_cast<LONG>(height);
    		vr.adaptViews(viewport, scissorRect);
    	}
    */
    //// Pipeline

    ComPtr<IDXGIFactory4> factory;
    ThrowIfFailed(CreateDXGIFactory2(0
#ifdef _DEBUG
                                     | DXGI_CREATE_FACTORY_DEBUG
#endif
                                     , IID_PPV_ARGS(&factory)));

    if (warp)
    {
        ComPtr<IDXGIAdapter> warpAdapter;
        ThrowIfFailed(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));

        ThrowIfFailed(D3D12CreateDevice(
                          warpAdapter.Get(),
                          D3D_FEATURE_LEVEL_11_0,
                          IID_PPV_ARGS(&device)
                      ));
    }
    else {
        ThrowIfFailed(D3D12CreateDevice(
                          nullptr,
                          D3D_FEATURE_LEVEL_11_0,
                          IID_PPV_ARGS(&device)
                      ));
    }

    // disable auto alt-enter fullscreen switch (does leave an unresponsive window during debug sessions)
    ThrowIfFailed(factory->MakeWindowAssociation(getHWND(), DXGI_MWA_NO_ALT_ENTER));
    //IDXGIFactory4 *parentFactoryPtr = nullptr;
    //if (SUCCEEDED(swapChain->GetParent(__uuidof(IDXGIFactory4), (void **)&parentFactoryPtr))) {
    //	parentFactoryPtr->MakeWindowAssociation(getHWND(), DXGI_MWA_NO_ALT_ENTER);
    //	parentFactoryPtr->Release();
    //}

    // Describe and create the command queue.
    D3D12_COMMAND_QUEUE_DESC queueDesc = {};
    queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
    queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;

    ThrowIfFailed(device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&commandQueue)));
    commandQueue->SetName(L"commandQueue_xapp");

    calcBackbufferSizeAndAspectRatio();
    camera.aspectRatio = aspectRatio;
    if (ovrRendering) {
        camera.aspectRatio /= 2.0f;
    }
    camera.projectionTransform();
    // Describe the swap chain.
    DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
    swapChainDesc.BufferCount = FrameCount;
    swapChainDesc.BufferDesc.Width = backbufferWidth;
    swapChainDesc.BufferDesc.Height = backbufferHeight;
    swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
    swapChainDesc.OutputWindow = getHWND();
    swapChainDesc.SampleDesc.Count = 1;
    swapChainDesc.Windowed = TRUE;

    ComPtr<IDXGISwapChain> swapChain0; // we cannot use create IDXGISwapChain3 directly - create IDXGISwapChain, then call As() to map to IDXGISwapChain3
    ThrowIfFailed(factory->CreateSwapChain(
                      commandQueue.Get(),		// Swap chain needs the queue so that it can force a flush on it.
                      &swapChainDesc,
                      &swapChain0
                  ));

    ThrowIfFailed(swapChain0.As(&swapChain));
    //swapChain = nullptr;
    frameIndex = xapp().swapChain->GetCurrentBackBufferIndex();

    if (ovrRendering) {
        vr.initD3D();
    }

    // Create descriptor heaps.
    {
        // Describe and create a render target view (RTV) descriptor heap.

        D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
        rtvHeapDesc.NumDescriptors = FrameCount;
        rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
        rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
        ThrowIfFailed(device->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(&rtvHeap)));
        rtvHeap->SetName(L"rtvHeap_xapp");

        rtvDescriptorSize = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
    }

    // Create frame resources.
    {
        CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(rtvHeap->GetCPUDescriptorHandleForHeapStart());

        // Create a RTV for each frame.
        for (UINT n = 0; n < FrameCount; n++)
        {
            ThrowIfFailed(swapChain->GetBuffer(n, IID_PPV_ARGS(&renderTargets[n])));
            device->CreateRenderTargetView(renderTargets[n].Get(), nullptr, rtvHandle);
            wstringstream s;
            s << L"renderTarget_xapp[" << n << "]";
            renderTargets[n]->SetName(s.str().c_str());
            rtvHandle.Offset(1, rtvDescriptorSize);
            //ThrowIfFailed(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&commandAllocators[n])));

            // Describe and create a depth stencil view (DSV) descriptor heap.
            D3D12_DESCRIPTOR_HEAP_DESC dsvHeapDesc = {};
            dsvHeapDesc.NumDescriptors = 1;
            dsvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
            dsvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
            ThrowIfFailed(device->CreateDescriptorHeap(&dsvHeapDesc, IID_PPV_ARGS(&dsvHeaps[n])));
        }
        // Create the depth stencil view for each frame
        for (UINT n = 0; n < FrameCount; n++)
        {
            D3D12_DEPTH_STENCIL_VIEW_DESC depthStencilDesc = {};
            depthStencilDesc.Format = DXGI_FORMAT_D32_FLOAT;
            depthStencilDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D;
            depthStencilDesc.Flags = D3D12_DSV_FLAG_NONE;

            D3D12_CLEAR_VALUE depthOptimizedClearValue = {};
            depthOptimizedClearValue.Format = DXGI_FORMAT_D32_FLOAT;
            depthOptimizedClearValue.DepthStencil.Depth = 1.0f;
            depthOptimizedClearValue.DepthStencil.Stencil = 0;

            ThrowIfFailed(device->CreateCommittedResource(
                              &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
                              D3D12_HEAP_FLAG_NONE,
                              &CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_D32_FLOAT, backbufferWidth, backbufferHeight, 1, 0, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL),
                              D3D12_RESOURCE_STATE_DEPTH_WRITE,
                              &depthOptimizedClearValue,
                              IID_PPV_ARGS(&depthStencils[n])
                          ));

            //NAME_D3D12_OBJECT(m_depthStencil);

            device->CreateDepthStencilView(depthStencils[n].Get(), &depthStencilDesc, dsvHeaps[n]->GetCPUDescriptorHandleForHeapStart());
            wstringstream s;
            s << L"depthStencil_xapp[" << n << "]";
            depthStencils[n]->SetName(s.str().c_str());
        }
    }

    //// Assets

    // Create an empty root signature.
    {
        CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
        rootSignatureDesc.Init(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);

        ComPtr<ID3DBlob> signature;
        ComPtr<ID3DBlob> error;
        ThrowIfFailed(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
        ThrowIfFailed(device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&rootSignature)));
    }
    // 11 on 12 device support
    UINT d3d11DeviceFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#if defined(_DEBUG)
    if (disableDX11Debug == false) {
        d3d11DeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
    }
#endif
    ThrowIfFailed(D3D11On12CreateDevice(
                      device.Get(),
                      d3d11DeviceFlags,
                      nullptr,
                      0,
                      reinterpret_cast<IUnknown**>(commandQueue.GetAddressOf()),
                      1,
                      0,
                      &d3d11Device,
                      &d3d11DeviceContext,
                      nullptr
                  ));

    // Query the 11On12 device from the 11 device.
    ThrowIfFailed(d3d11Device.As(&d3d11On12Device));
    // feature levels: we need DX 10.1 as minimum
    D3D_FEATURE_LEVEL out_level;
    array<D3D_FEATURE_LEVEL, 3> levels{ {
            D3D_FEATURE_LEVEL_11_1,
            D3D_FEATURE_LEVEL_11_0,
            D3D_FEATURE_LEVEL_10_1
        } };
    //ID3D11DeviceContext* context = nullptr;
    UINT flags = disableDX11Debug ? 0 : D3D11_CREATE_DEVICE_DEBUG;
    ThrowIfFailed(D3D11CreateDevice(nullptr,
                                    D3D_DRIVER_TYPE_HARDWARE,
                                    nullptr,
                                    flags,
                                    &levels[0],
                                    (UINT)levels.size(),
                                    D3D11_SDK_VERSION,
                                    &reald3d11Device,
                                    &out_level,
                                    &reald3d11DeviceContext));

    // 11 on 12 end

    camera.ovrCamera = true;
    if (!ovrRendering) camera.ovrCamera = false;

    gametime.init(1); // init to real time
    camera.setSpeed(1.0f);

    initPakFiles();

    app->init();
    app->update();
}