I found 'WaitDlg.h' in DirectX Sample Project.
and i want to use this, so i put it on my project.
but it isn't working.
This is my source.
****main.cpp****
#include "stdafx.h"
bool CALLBACK IsD3D9DeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat,
bool bWindowed, void* pUserContext )
{
IDirect3D9* pD3D = DXUTGetD3D9Object();
if( FAILED( pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, pCaps->DeviceType,
AdapterFormat, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING,
D3DRTYPE_TEXTURE, BackBufferFormat ) ) )
return false;
return true;
}
bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, void* pUserContext )
{
return true;
}
HRESULT CALLBACK OnD3D9CreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,
void* pUserContext )
{
return S_OK;
}
HRESULT CALLBACK OnD3D9ResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,
void* pUserContext )
{
return S_OK;
}
void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext )
{
}
void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
HRESULT hr;
V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 45, 50, 170 ), 1.0f, 0 ) );
if( SUCCEEDED( pd3dDevice->BeginScene() ) )
{
V( pd3dDevice->EndScene() );
}
}
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
bool* pbNoFurtherProcessing, void* pUserContext )
{
return 0;
}
void CALLBACK OnD3D9LostDevice( void* pUserContext )
{
}
void CALLBACK OnD3D9DestroyDevice( void* pUserContext )
{
}
INT WINAPI wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int )
{
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
DXUTSetCallbackD3D9DeviceAcceptable( IsD3D9DeviceAcceptable );
DXUTSetCallbackD3D9DeviceCreated( OnD3D9CreateDevice );
DXUTSetCallbackD3D9DeviceReset( OnD3D9ResetDevice );
DXUTSetCallbackD3D9FrameRender( OnD3D9FrameRender );
DXUTSetCallbackD3D9DeviceLost( OnD3D9LostDevice );
DXUTSetCallbackD3D9DeviceDestroyed( OnD3D9DestroyDevice );
DXUTSetCallbackDeviceChanging( ModifyDeviceSettings );
DXUTSetCallbackMsgProc( MsgProc );
DXUTSetCallbackFrameMove( OnFrameMove );
DXUTInit( true, true ); // Parse the command line and show msgboxes
DXUTSetHotkeyHandling( true, true, true ); // handle the default hotkeys
DXUTSetCursorSettings( true, true ); // Show the cursor and clip it when in full screen
DXUTCreateWindow( WINDOW_NAME );
CWaitDlg Load;
Load.ShowDialog(L"Loading...");
DXUTCreateDevice( WINDOW_MODE, SCREEN_WIDTH, SCREEN_HEIGHT );
Load.DestroyDialog();
DXUTMainLoop();
return DXUTGetExitCode();
}
**WaitDlg.h***
//--------------------------------------------------------------------------------------
// File: WaitDlg.h
//
// Wait dialog for shader compilation
//
// Copyright © Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include <process.h>
//--------------------------------------------------------------------------------------
INT_PTR CALLBACK WaitDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
unsigned int __stdcall WaitThread( void* pArg );
//--------------------------------------------------------------------------------------
class CWaitDlg
{
private:
HWND m_hDialogWnd;
HANDLE m_hThread;
HWND m_hProgressWnd;
int m_iProgress;
BOOL m_bDone;
RECT m_AppRect;
WCHAR m_szText[MAX_PATH];
public:
CWaitDlg() :
m_hDialogWnd( NULL ),
m_hThread( NULL ),
m_hProgressWnd( NULL ),
m_iProgress( 0 ),
m_bDone( FALSE )
{
}
~CWaitDlg() { DestroyDialog(); }
bool IsRunning() { return !m_bDone; }
void UpdateProgressBar()
{
m_iProgress ++;
if( m_iProgress > 110 )
m_iProgress = 0;
SendMessage( m_hProgressWnd, PBM_SETPOS, m_iProgress, 0 );
InvalidateRect( m_hDialogWnd, NULL, FALSE );
UpdateWindow( m_hDialogWnd );
}
bool GetDialogControls()
{
m_bDone = FALSE;
m_hDialogWnd = CreateDialog( DXUTGetHINSTANCE(), MAKEINTRESOURCE( IDD_COMPILINGSHADERS ), NULL, WaitDialogProc );
if( !m_hDialogWnd )
return false;
SetWindowLongPtr( m_hDialogWnd, GWLP_USERDATA, (LONG_PTR)this );
// Set the position
int left = ( m_AppRect.left + m_AppRect.right ) / 2;
int up = ( m_AppRect.top + m_AppRect.bottom ) / 2;
SetWindowPos( m_hDialogWnd, NULL, left, up, 0, 0, SWP_NOSIZE );
ShowWindow( m_hDialogWnd, SW_SHOW );
// Get the progress bar
m_hProgressWnd = GetDlgItem( m_hDialogWnd, IDC_PROGRESSBAR );
SendMessage( m_hProgressWnd, PBM_SETRANGE, 0, MAKELPARAM( 0, 100 ) );
// Update the static text
HWND hMessage = GetDlgItem( m_hDialogWnd, IDC_MESSAGE );
SetWindowText( hMessage, m_szText );
return true;
}
bool ShowDialog( WCHAR* pszInputText )
{
// Get the window rect
GetWindowRect( DXUTGetHWND(), &m_AppRect );
wcscpy_s( m_szText, MAX_PATH, pszInputText );
// spawn a thread that does nothing but update the progress bar
unsigned int threadAddr;
m_hThread = (HANDLE)_beginthreadex( NULL, 0, WaitThread, this, 0, &threadAddr );
return true;
}
void DestroyDialog()
{
m_bDone = TRUE;
WaitForSingleObject( m_hThread, INFINITE );
if( m_hDialogWnd )
DestroyWindow( m_hDialogWnd );
m_hDialogWnd = NULL;
}
};
//--------------------------------------------------------------------------------------
INT_PTR CALLBACK WaitDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
CWaitDlg* pThisDialog = (CWaitDlg*)GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
switch( uMsg )
{
case WM_INITDIALOG:
return TRUE;
case WM_CLOSE:
pThisDialog->DestroyDialog();
return TRUE;
}
return FALSE;
}
//--------------------------------------------------------------------------------------
unsigned int __stdcall WaitThread( void* pArg )
{
CWaitDlg* pThisDialog = (CWaitDlg*)pArg;
// We create the dialog in this thread, so we can call SendMessage without blocking on the
// main thread's message pump
pThisDialog->GetDialogControls();
while( pThisDialog->IsRunning() )
{
pThisDialog->UpdateProgressBar();
Sleep(100);
}
return 0;
}
What wrong?
Help me!