Initial commit: ROW Client source code

Game client codebase including:
- CharacterActionControl: Character and creature management
- GlobalScript: Network, items, skills, quests, utilities
- RYLClient: Main client application with GUI and event handlers
- Engine: 3D rendering engine (RYLGL)
- MemoryManager: Custom memory allocation
- Library: Third-party dependencies (DirectX, boost, etc.)
- Tools: Development utilities

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-29 16:24:34 +09:00
commit e067522598
5135 changed files with 1745744 additions and 0 deletions

View File

@@ -0,0 +1,549 @@
//-----------------------------------------------------------------------------
// File: AnimatePalette.cpp
//
// Desc: This sample demonstrates how to do DirectDraw palette animatation
// when in full-screen mode.
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#define STRICT
#include <windows.h>
#include <ddraw.h>
#include <mmsystem.h>
#include <dxerr8.h>
#include "resource.h"
#include "ddutil.h"
//-----------------------------------------------------------------------------
// Defines, constants, and global variables
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 8
#define SPRITE_DIAMETER 48
#define NUM_SPRITES 25
#define HELPTEXT TEXT("Press Escape to quit.")
struct SPRITE_STRUCT
{
FLOAT fPosX;
FLOAT fPosY;
FLOAT fVelX;
FLOAT fVelY;
};
CDisplay* g_pDisplay = NULL;
CSurface* g_pLogoSurface = NULL;
CSurface* g_pTextSurface = NULL;
LPDIRECTDRAWPALETTE g_pDDPal = NULL;
PALETTEENTRY g_pe[256];
HWND g_hWnd = NULL;
BOOL g_bActive = FALSE;
DWORD g_dwLastTick;
SPRITE_STRUCT g_Sprite[NUM_SPRITES];
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
HRESULT WinInit( HINSTANCE hInst, int nCmdShow, HWND* phWnd, HACCEL* phAccel );
HRESULT InitDirectDraw( HWND hWnd );
VOID FreeDirectDraw();
HRESULT ProcessNextFrame();
VOID UpdateSprite( SPRITE_STRUCT* pSprite, FLOAT fTimeDelta );
HRESULT CyclePalette();
HRESULT DisplayFrame();
HRESULT RestoreSurfaces();
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything and calls
// UpdateFrame() when idle from the message pump.
//-----------------------------------------------------------------------------
int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int nCmdShow )
{
MSG msg;
HACCEL hAccel;
HRESULT hr;
if( FAILED( WinInit( hInst, nCmdShow, &g_hWnd, &hAccel ) ) )
return FALSE;
if( FAILED( hr = InitDirectDraw( g_hWnd ) ) )
{
DXTRACE_ERR( TEXT("InitDirectDraw"), hr );
MessageBox( g_hWnd, TEXT("DirectDraw init failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
// Display the sprites on the screen
DisplayFrame();
while( TRUE )
{
// Look for messages, if none are found then
// update the state and display it
if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if( 0 == GetMessage(&msg, NULL, 0, 0 ) )
{
// WM_QUIT was posted, so exit
return (int)msg.wParam;
}
// Translate and dispatch the message
if( 0 == TranslateAccelerator( g_hWnd, hAccel, &msg ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
else
{
if( g_bActive )
{
// Display the bitmap to the screen
if( FAILED( hr = ProcessNextFrame() ) )
{
SAFE_DELETE( g_pDisplay );
if( hr == E_NOTIMPL )
{
MessageBox( NULL, TEXT("The driver does not support waiting for vertical blank. ")
TEXT("This is expected if the HW acceleration is disabled. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
}
else
{
DXTRACE_ERR( TEXT("ProcessNextFrame"), hr );
MessageBox( g_hWnd, TEXT("Displaying the next frame failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
}
return FALSE;
}
}
else
{
// Make sure we go to sleep if we have nothing else to do
WaitMessage();
}
}
}
}
//-----------------------------------------------------------------------------
// Name: WinInit()
// Desc: Init the window
//-----------------------------------------------------------------------------
HRESULT WinInit( HINSTANCE hInst, int nCmdShow, HWND* phWnd, HACCEL* phAccel )
{
WNDCLASS wc;
HWND hWnd;
HACCEL hAccel;
// Register the Window Class
wc.lpszClassName = TEXT("AnimatePalette");
wc.lpfnWndProc = MainWndProc;
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInst;
wc.hIcon = LoadIcon( hInst, MAKEINTRESOURCE(IDI_MAIN) );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if( RegisterClass( &wc ) == 0 )
return E_FAIL;
// Load keyboard accelerators
hAccel = LoadAccelerators( hInst, MAKEINTRESOURCE(IDR_MAIN_ACCEL) );
// Create and show the main window
hWnd = CreateWindowEx( 0, TEXT("AnimatePalette"), TEXT("DirectDraw AnimatePalette Sample"),
WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL );
if( hWnd == NULL )
return E_FAIL;
ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );
*phWnd = hWnd;
*phAccel = hAccel;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InitDirectDraw()
// Desc: Create the DirectDraw object, and init the surfaces
//-----------------------------------------------------------------------------
HRESULT InitDirectDraw( HWND hWnd )
{
HRESULT hr;
int iSprite;
g_pDisplay = new CDisplay();
if( FAILED( hr = g_pDisplay->CreateFullScreenDisplay( hWnd, SCREEN_WIDTH,
SCREEN_HEIGHT, SCREEN_BPP ) ) )
{
MessageBox( hWnd, TEXT("This display card does not support 640x480x8. "),
TEXT("DirectDraw Sample"), MB_ICONERROR | MB_OK );
return DXTRACE_ERR( TEXT("CreateFullScreenDisplay"), hr );
}
// Create and set the palette when in palettized color
if( FAILED( hr = g_pDisplay->CreatePaletteFromBitmap( &g_pDDPal, MAKEINTRESOURCE( IDB_DIRECTX ) ) ) )
return DXTRACE_ERR( TEXT("CreatePaletteFromBitmap"), hr );
if( FAILED( hr = g_pDisplay->SetPalette( g_pDDPal ) ) )
return DXTRACE_ERR( TEXT("SetPalette"), hr );
// Store the palette entires in a global data structure
// so we can animate the palette
if( FAILED( hr = g_pDDPal->GetEntries(0, 0, 256, g_pe ) ) )
return DXTRACE_ERR( TEXT("GetEntries"), hr );
// Create a surface, and draw a bitmap resource on it.
if( FAILED( hr = g_pDisplay->CreateSurfaceFromBitmap( &g_pLogoSurface, MAKEINTRESOURCE( IDB_DIRECTX ),
SPRITE_DIAMETER, SPRITE_DIAMETER ) ) )
return DXTRACE_ERR( TEXT("CreateSurfaceFromBitmap"), hr );
// Create a surface, and draw text to it.
if( FAILED( hr = g_pDisplay->CreateSurfaceFromText( &g_pTextSurface, NULL, HELPTEXT,
RGB(0,0,0), RGB(255, 255, 0) ) ) )
return DXTRACE_ERR( TEXT("CreateSurfaceFromText"), hr );
// Set the color key for the logo sprite to black
if( FAILED( hr = g_pLogoSurface->SetColorKey( 0 ) ) )
return DXTRACE_ERR( TEXT("SetColorKey"), hr );
// Init all the sprites. All of these sprites look the same,
// using the g_pDDSLogo surface.
for( iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
{
// Set the sprite's position and velocity
g_Sprite[iSprite].fPosX = (float) (rand() % SCREEN_WIDTH);
g_Sprite[iSprite].fPosY = (float) (rand() % SCREEN_HEIGHT);
g_Sprite[iSprite].fVelX = 500.0f * rand() / RAND_MAX - 250.0f;
g_Sprite[iSprite].fVelY = 500.0f * rand() / RAND_MAX - 250.0f;
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: FreeDirectDraw()
// Desc: Release all the DirectDraw objects
//-----------------------------------------------------------------------------
VOID FreeDirectDraw()
{
SAFE_DELETE( g_pLogoSurface );
SAFE_DELETE( g_pTextSurface );
SAFE_DELETE( g_pDisplay );
}
//-----------------------------------------------------------------------------
// Name: MainWndProc()
// Desc: The main window procedure
//-----------------------------------------------------------------------------
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch (msg)
{
case WM_COMMAND:
switch( LOWORD(wParam) )
{
case IDM_EXIT:
// Received key/menu command to exit app
PostMessage( hWnd, WM_CLOSE, 0, 0 );
return 0L;
}
break; // Continue with default processing
case WM_SETCURSOR:
// Hide the cursor in fullscreen
SetCursor( NULL );
return TRUE;
case WM_SIZE:
// Check to see if we are losing our window...
if( SIZE_MAXHIDE==wParam || SIZE_MINIMIZED==wParam )
g_bActive = FALSE;
else
g_bActive = TRUE;
break;
case WM_SYSCOMMAND:
// Prevent moving/sizing and power loss in fullscreen mode
switch( wParam )
{
case SC_MOVE:
case SC_SIZE:
case SC_MAXIMIZE:
case SC_MONITORPOWER:
return TRUE;
}
break;
case WM_EXITMENULOOP:
// Ignore time spent in menu
g_dwLastTick = timeGetTime();
break;
case WM_EXITSIZEMOVE:
// Ignore time spent resizing
g_dwLastTick = timeGetTime();
break;
case WM_DESTROY:
// Cleanup and close the app
FreeDirectDraw();
PostQuitMessage( 0 );
return 0L;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
//-----------------------------------------------------------------------------
// Name: ProcessNextFrame()
// Desc: Move the sprites, blt them to the back buffer, then
// flips the back buffer to the primary buffer
//-----------------------------------------------------------------------------
HRESULT ProcessNextFrame()
{
HRESULT hr;
// Figure how much time has passed since the last time
DWORD dwCurrTick = timeGetTime();
DWORD dwTickDiff = dwCurrTick - g_dwLastTick;
// Don't update if no time has passed
if( dwTickDiff == 0 )
return S_OK;
g_dwLastTick = dwCurrTick;
// Move the sprites according to how much time has passed
for( int iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
UpdateSprite( &g_Sprite[ iSprite ], dwTickDiff / 1000.0f );
// Cycle the palette every frame
if( FAILED( hr = CyclePalette() ) )
return DXTRACE_ERR( TEXT("CyclePalette"), hr );
// Display the sprites on the screen
if( FAILED( hr = DisplayFrame() ) )
{
if( hr != DDERR_SURFACELOST )
{
FreeDirectDraw();
return DXTRACE_ERR( TEXT("DisplayFrame"), hr );
}
// The surfaces were lost so restore them
RestoreSurfaces();
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: CyclePalette()
// Desc: Cycle the palette colors 2 through 37 - this is
// will change the color for 'X' in the sprite.
//-----------------------------------------------------------------------------
HRESULT CyclePalette()
{
HRESULT hr;
for( int i = 2; i < 37; i++ )
{
// This just does something interesting but simple by shifting each
// color component independently
g_pe[ i ].peBlue += 8;
g_pe[ i ].peRed += 4;
g_pe[ i ].peGreen += 2;
}
// Wait until the screen is synchronzied at a vertical-blank interval.
// This may return E_NOTIMPL if the ddraw is not hardware accelerated
hr = g_pDisplay->GetDirectDraw()->WaitForVerticalBlank( DDWAITVB_BLOCKBEGIN, NULL );
if( FAILED( hr ) )
{
FreeDirectDraw();
return DXTRACE_ERR( TEXT("WaitForVerticalBlank"), hr );
}
// Now that we are synchronzied at a vertical-blank
// interval, update the palette
if( FAILED( hr = g_pDDPal->SetEntries( 0, 0, 256, g_pe ) ) )
{
FreeDirectDraw();
return DXTRACE_ERR( TEXT("SetEntries"), hr );
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: UpdateSprite()
// Desc: Move the sprite around and make it bounce based on how much time
// has passed
//-----------------------------------------------------------------------------
VOID UpdateSprite( SPRITE_STRUCT* pSprite, FLOAT fTimeDelta )
{
// Update the sprite position
pSprite->fPosX += pSprite->fVelX * fTimeDelta;
pSprite->fPosY += pSprite->fVelY * fTimeDelta;
// Clip the position, and bounce if it hits the edge
if( pSprite->fPosX < 0.0f )
{
pSprite->fPosX = 0;
pSprite->fVelX = -pSprite->fVelX;
}
if( pSprite->fPosX >= SCREEN_WIDTH - SPRITE_DIAMETER )
{
pSprite->fPosX = SCREEN_WIDTH - 1 - SPRITE_DIAMETER;
pSprite->fVelX = -pSprite->fVelX;
}
if( pSprite->fPosY < 0 )
{
pSprite->fPosY = 0;
pSprite->fVelY = -pSprite->fVelY;
}
if( pSprite->fPosY > SCREEN_HEIGHT - SPRITE_DIAMETER )
{
pSprite->fPosY = SCREEN_HEIGHT - 1 - SPRITE_DIAMETER;
pSprite->fVelY = -pSprite->fVelY;
}
}
//-----------------------------------------------------------------------------
// Name: DisplayFrame()
// Desc: Blts a the sprites to the back buffer, then flips the
// back buffer onto the primary buffer.
//-----------------------------------------------------------------------------
HRESULT DisplayFrame()
{
HRESULT hr;
if( NULL == g_pDisplay )
return S_OK;
// Fill the back buffer with black, ignoring errors until the flip
g_pDisplay->Clear( 0 );
// Blt the help text on the backbuffer, ignoring errors until the flip
g_pDisplay->Blt( 10, 10, g_pTextSurface, NULL );
// Blt all the sprites onto the back buffer using color keying,
// ignoring errors until the flip. Note that all of these sprites
// use the same DirectDraw surface.
for( int iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
{
g_pDisplay->Blt( (DWORD)g_Sprite[iSprite].fPosX,
(DWORD)g_Sprite[iSprite].fPosY,
g_pLogoSurface, NULL );
}
// We are in fullscreen mode, so perform a flip and return
// any errors like DDERR_SURFACELOST
if( FAILED( hr = g_pDisplay->Present() ) )
{
return hr;
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: RestoreSurfaces()
// Desc: Restore all the surfaces, and redraw the sprite surfaces.
//-----------------------------------------------------------------------------
HRESULT RestoreSurfaces()
{
HRESULT hr;
if( FAILED( hr = g_pDisplay->GetDirectDraw()->RestoreAllSurfaces() ) )
return DXTRACE_ERR( TEXT("RestoreAllSurfaces"), hr );
// No need to re-create the surface, just re-draw it.
if( FAILED( hr = g_pTextSurface->DrawText( NULL, HELPTEXT,
0, 0, RGB(0,0,0), RGB(255, 255, 0) ) ) )
return DXTRACE_ERR( TEXT("DrawText"), hr );
// We need to release and re-load, and set the palette again to
// redraw the bitmap on the surface. Otherwise, GDI will not
// draw the bitmap on the surface with the right palette
SAFE_RELEASE( g_pDDPal );
if( FAILED( hr = g_pDisplay->CreatePaletteFromBitmap( &g_pDDPal, MAKEINTRESOURCE( IDB_DIRECTX ) ) ) )
return DXTRACE_ERR( TEXT("CreatePaletteFromBitmap"), hr );
if( FAILED( hr = g_pDisplay->SetPalette( g_pDDPal ) ) )
return DXTRACE_ERR( TEXT("SetPalette"), hr );
// No need to re-create the surface, just re-draw it.
if( FAILED( hr = g_pLogoSurface->DrawBitmap( MAKEINTRESOURCE( IDB_DIRECTX ),
SPRITE_DIAMETER, SPRITE_DIAMETER ) ) )
return DXTRACE_ERR( TEXT("DrawBitmap"), hr );
return S_OK;
}

View File

@@ -0,0 +1,147 @@
# Microsoft Developer Studio Project File - Name="AnimatePalette" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=AnimatePalette - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "animatepalette.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "animatepalette.mak" CFG="AnimatePalette - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "AnimatePalette - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "AnimatePalette - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "AnimatePalette - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir ".\Release"
# PROP BASE Intermediate_Dir ".\Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ".\Release"
# PROP Intermediate_Dir ".\Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /GX /O2 /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386 /stack:0x200000,0x200000
!ELSEIF "$(CFG)" == "AnimatePalette - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir ".\Debug"
# PROP BASE Intermediate_Dir ".\Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ".\Debug"
# PROP Intermediate_Dir ".\Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386
# ADD LINK32 winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386 /stack:0x200000,0x200000
!ENDIF
# Begin Target
# Name "AnimatePalette - Win32 Release"
# Name "AnimatePalette - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90"
# Begin Source File
SOURCE=.\AnimatePalette.cpp
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\AnimatePalette.bmp
# End Source File
# Begin Source File
SOURCE=.\AnimatePalette.rc
# End Source File
# Begin Source File
SOURCE=.\directx.bmp
# End Source File
# Begin Source File
SOURCE=.\DirectX.ico
# End Source File
# Begin Source File
SOURCE=.\resource.h
# End Source File
# End Group
# Begin Group "Common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\common\src\ddutil.cpp
# End Source File
# Begin Source File
SOURCE=..\..\common\include\ddutil.h
# End Source File
# Begin Source File
SOURCE=..\..\common\src\dxutil.cpp
# End Source File
# Begin Source File
SOURCE=..\..\common\include\dxutil.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "AnimatePalette"=.\animatepalette.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,221 @@
# Microsoft Developer Studio Generated NMAKE File, Based on animatepalette.dsp
!IF "$(CFG)" == ""
CFG=AnimatePalette - Win32 Release
!MESSAGE No configuration specified. Defaulting to AnimatePalette - Win32 Release.
!ENDIF
!IF "$(CFG)" != "AnimatePalette - Win32 Release" && "$(CFG)" != "AnimatePalette - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "animatepalette.mak" CFG="AnimatePalette - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "AnimatePalette - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "AnimatePalette - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "AnimatePalette - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\animatepalette.exe"
CLEAN :
-@erase "$(INTDIR)\AnimatePalette.obj"
-@erase "$(INTDIR)\AnimatePalette.res"
-@erase "$(INTDIR)\ddutil.obj"
-@erase "$(INTDIR)\dxutil.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\animatepalette.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\animatepalette.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\AnimatePalette.res" /d "NDEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\animatepalette.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:no /pdb:"$(OUTDIR)\animatepalette.pdb" /machine:I386 /out:"$(OUTDIR)\animatepalette.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\AnimatePalette.obj" \
"$(INTDIR)\ddutil.obj" \
"$(INTDIR)\dxutil.obj" \
"$(INTDIR)\AnimatePalette.res"
"$(OUTDIR)\animatepalette.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "AnimatePalette - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\animatepalette.exe"
CLEAN :
-@erase "$(INTDIR)\AnimatePalette.obj"
-@erase "$(INTDIR)\AnimatePalette.res"
-@erase "$(INTDIR)\ddutil.obj"
-@erase "$(INTDIR)\dxutil.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\animatepalette.exe"
-@erase "$(OUTDIR)\animatepalette.ilk"
-@erase "$(OUTDIR)\animatepalette.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\animatepalette.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\AnimatePalette.res" /d "_DEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\animatepalette.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:yes /pdb:"$(OUTDIR)\animatepalette.pdb" /debug /machine:I386 /out:"$(OUTDIR)\animatepalette.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\AnimatePalette.obj" \
"$(INTDIR)\ddutil.obj" \
"$(INTDIR)\dxutil.obj" \
"$(INTDIR)\AnimatePalette.res"
"$(OUTDIR)\animatepalette.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("animatepalette.dep")
!INCLUDE "animatepalette.dep"
!ELSE
!MESSAGE Warning: cannot find "animatepalette.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "AnimatePalette - Win32 Release" || "$(CFG)" == "AnimatePalette - Win32 Debug"
SOURCE=.\AnimatePalette.cpp
"$(INTDIR)\AnimatePalette.obj" : $(SOURCE) "$(INTDIR)"
SOURCE=.\AnimatePalette.rc
"$(INTDIR)\AnimatePalette.res" : $(SOURCE) "$(INTDIR)"
$(RSC) $(RSC_PROJ) $(SOURCE)
SOURCE=..\..\common\src\ddutil.cpp
"$(INTDIR)\ddutil.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=..\..\common\src\dxutil.cpp
"$(INTDIR)\dxutil.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
!ENDIF

View File

@@ -0,0 +1,91 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include <windows.h>
#include <afxres.h>
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_MAIN ICON DISCARDABLE "DirectX.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include <windows.h>\r\n"
"#include <afxres.h>\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDR_MAIN_ACCEL ACCELERATORS DISCARDABLE
BEGIN
VK_ESCAPE, IDM_EXIT, VIRTKEY, NOINVERT
"X", IDM_EXIT, VIRTKEY, ALT, NOINVERT
END
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//
IDB_DIRECTX BITMAP DISCARDABLE "directx.bmp"
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,37 @@
//-----------------------------------------------------------------------------
//
// Sample Name: AnimatePalette Sample
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
Description
===========
AnimatePalette demonstrates DirectDraw palette animation when in full-screen
on a palettized surface.
Path
====
Source: DXSDK\Samples\Multimedia\DDraw\AnimatePalette
Executable: DXSDK\Samples\Multimedia\DDraw\Bin
User's Guide
============
AnimatePalette requires no user input. Press the ESC key to quit the program.
Programming Notes
=================
For details on how to setup a full-screen DirectDraw app, see the FullScreenMode
sample.
To animate the palette on a palettized DirectDraw surface, call
IDirectDrawPalette::GetEntries to retrieve the palette colors. Then every
frame (or as often as desired) alter this array as needed, then set the new palette
by first calling IDirectDraw::WaitForVerticalBlank( DDWAITVB_BLOCKBEGIN, NULL )
to synchronize the palette change to a vertical blank, then
call IDirectDrawPalette::SetEntries.

View File

@@ -0,0 +1,20 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by AnimatePalette.rc
//
#define IDI_MAIN 101
#define IDR_MAIN_ACCEL 103
#define IDB_DIRECTX 108
#define IDM_EXIT 1001
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 109
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 104
#endif
#endif

View File

@@ -0,0 +1,296 @@
//-----------------------------------------------------------------------------
// File: ddenum.cpp
//
// Desc: This sample demonstrates how to enumerate all of the devices and show
// the driver information about each.
//
//
// Copyright (c) 1998-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#define STRICT
#include <windows.h>
#include <ddraw.h>
#include "resource.h"
//-----------------------------------------------------------------------------
// Defines, constants, and global variables
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
#define MAX_DEVICES 32
struct DEVICEIDENT_STRUCT
{
DDDEVICEIDENTIFIER2 DeviceInfo;
DDDEVICEIDENTIFIER2 DeviceInfoHost;
};
DEVICEIDENT_STRUCT g_DeviceIdent[MAX_DEVICES];
int g_iMaxDevices = 0;
//-----------------------------------------------------------------------------
// Name: UpdateInfoDlgText()
// Desc: Update all of the text and buttons in the dialog
//-----------------------------------------------------------------------------
void UpdateInfoDlgText( HWND hDlg, int iCurrent, DWORD dwHost )
{
TCHAR strBuffer[128];
GUID* pGUID;
LPDDDEVICEIDENTIFIER2 pDI;
if( dwHost == DDGDI_GETHOSTIDENTIFIER )
CheckRadioButton( hDlg, IDC_RADIO_DEVICE, IDC_RADIO_HOST, IDC_RADIO_HOST );
else
CheckRadioButton( hDlg, IDC_RADIO_DEVICE, IDC_RADIO_DEVICE, IDC_RADIO_DEVICE );
pDI = &g_DeviceIdent[iCurrent].DeviceInfo;
if( dwHost == DDGDI_GETHOSTIDENTIFIER )
pDI = &g_DeviceIdent[iCurrent].DeviceInfoHost;
wsprintf( strBuffer, "Device information for device %d of %d",
iCurrent + 1, g_iMaxDevices );
SetDlgItemText( hDlg, IDC_RADIO_DEVICE, strBuffer );
// Device ID stuff:
wsprintf( strBuffer,"%08X",pDI->dwVendorId );
SetDlgItemText( hDlg, IDC_DWVENDORID, strBuffer );
wsprintf( strBuffer,"%08X",pDI->dwDeviceId );
SetDlgItemText( hDlg, IDC_DWDEVICEID, strBuffer );
wsprintf( strBuffer,"%08X",pDI->dwSubSysId );
SetDlgItemText( hDlg, IDC_DWSUBSYS, strBuffer );
wsprintf( strBuffer,"%08X",pDI->dwRevision );
SetDlgItemText( hDlg, IDC_DWREVISION, strBuffer );
// Driver version:
wsprintf( strBuffer, "%d.%02d.%02d.%04d",
HIWORD( pDI->liDriverVersion.u.HighPart ),
LOWORD( pDI->liDriverVersion.u.HighPart ),
HIWORD( pDI->liDriverVersion.u.LowPart ),
LOWORD( pDI->liDriverVersion.u.LowPart ) );
SetDlgItemText( hDlg, IDC_VERSION, strBuffer );
// Device description and HAL filename
SetDlgItemText( hDlg, IDC_DESCRIPTION, pDI->szDescription );
SetDlgItemText( hDlg, IDC_FILENAME, pDI->szDriver );
// Unique driver/device identifier:
pGUID = &pDI->guidDeviceIdentifier;
wsprintf( strBuffer, "%08X-%04X-%04X-%02X%02X%02X%02X%02X%02X%02X%02X",
pGUID->Data1,
pGUID->Data2,
pGUID->Data3,
pGUID->Data4[0], pGUID->Data4[1], pGUID->Data4[2], pGUID->Data4[3],
pGUID->Data4[4], pGUID->Data4[5], pGUID->Data4[6], pGUID->Data4[7] );
SetDlgItemText( hDlg, IDC_GUID, strBuffer );
// WHQL Level
wsprintf( strBuffer,"%08x", pDI->dwWHQLLevel );
SetDlgItemText( hDlg, IDC_STATIC_WHQLLEVEL, strBuffer );
// Change the state and style of the Prev and Next buttons if needed
HWND hNext = GetDlgItem( hDlg, IDC_NEXT );
HWND hPrev = GetDlgItem( hDlg, IDC_PREV );
if( 0 == iCurrent )
{
// The Prev button should be disabled
SetFocus( GetDlgItem( hDlg, IDOK ) );
SendDlgItemMessage( hDlg, IDC_PREV, BM_SETSTYLE, BS_PUSHBUTTON, TRUE );
SendMessage( hDlg, DM_SETDEFID, IDOK, 0 );
EnableWindow( hPrev, FALSE );
}
else
{
if( IsWindowEnabled( hPrev ) == FALSE )
EnableWindow( hPrev, TRUE );
}
if( iCurrent >= (g_iMaxDevices - 1) )
{
// The Next button should be disabled
SetFocus( GetDlgItem( hDlg, IDOK ) );
SendDlgItemMessage( hDlg, IDC_NEXT, BM_SETSTYLE, BS_PUSHBUTTON, TRUE );
SendMessage(hDlg, DM_SETDEFID, IDOK, 0 );
EnableWindow( hNext, FALSE );
}
else
{
if( IsWindowEnabled( hNext ) == FALSE)
EnableWindow( hNext, TRUE );
}
}
//-----------------------------------------------------------------------------
// Name: InfoDlgProc()
// Desc: The dialog window proc
//-----------------------------------------------------------------------------
BOOL CALLBACK InfoDlgProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
static int iCurrent = 0;
static DWORD dwHost = 0;
switch (message)
{
case WM_INITDIALOG:
// Setup the first devices text
UpdateInfoDlgText( hDlg, iCurrent, dwHost );
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
EndDialog( hDlg, TRUE );
break;
case IDC_PREV:
// Show the previous device
if( iCurrent )
iCurrent--;
UpdateInfoDlgText( hDlg, iCurrent, dwHost );
break;
case IDC_NEXT:
// Show the next device
if( iCurrent < g_iMaxDevices )
iCurrent++;
UpdateInfoDlgText( hDlg, iCurrent, dwHost );
break;
case IDC_RADIO_HOST:
dwHost = DDGDI_GETHOSTIDENTIFIER;
UpdateInfoDlgText( hDlg, iCurrent, dwHost );
break;
case IDC_RADIO_DEVICE:
dwHost = 0;
UpdateInfoDlgText( hDlg, iCurrent, dwHost );
break;
default:
return FALSE; // Message not handled
}
default:
return FALSE; // Message not handled
}
return TRUE; // Message handled
}
//-----------------------------------------------------------------------------
// Name: DDEnumCallbackEx()
// Desc: This callback gets the information for each device enumerated
//-----------------------------------------------------------------------------
BOOL WINAPI DDEnumCallbackEx( GUID *pGUID, LPSTR pDescription, LPSTR strName,
LPVOID pContext, HMONITOR hm )
{
LPDIRECTDRAW7 pDD = NULL;
HRESULT hr;
// Create a DirectDraw object using the enumerated GUID
if( FAILED( hr = DirectDrawCreateEx( pGUID, (VOID**)&pDD,
IID_IDirectDraw7, NULL ) ) )
return DDENUMRET_CANCEL;
// Get the device information and save it
pDD->GetDeviceIdentifier( &g_DeviceIdent[g_iMaxDevices].DeviceInfo, 0 );
pDD->GetDeviceIdentifier( &g_DeviceIdent[g_iMaxDevices].DeviceInfoHost,
DDGDI_GETHOSTIDENTIFIER );
// Finished with the DirectDraw object, so release it
SAFE_RELEASE( pDD );
// Bump to the next open slot or finish the callbacks if full
if( g_iMaxDevices < MAX_DEVICES )
g_iMaxDevices++;
else
return DDENUMRET_CANCEL;
return DDENUMRET_OK;
}
//-----------------------------------------------------------------------------
// Name: DDEnumCallback()
// Desc: Old style callback retained for backwards compatibility
//-----------------------------------------------------------------------------
BOOL WINAPI DDEnumCallback( GUID *pGUID, LPSTR pDescription,
LPSTR strName, LPVOID pContext )
{
return ( DDEnumCallbackEx( pGUID, pDescription, strName, pContext, NULL ) );
}
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything and calls
// DirectDrawEnumerateEx() to get all of the device info.
//-----------------------------------------------------------------------------
int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int nCmdShow )
{
LPDIRECTDRAWENUMERATEEX pDirectDrawEnumerateEx;
HINSTANCE hDDrawDLL = NULL;
// Do a GetModuleHandle and GetProcAddress in order to get the
// DirectDrawEnumerateEx function
hDDrawDLL = GetModuleHandle("DDRAW");
if( NULL == hDDrawDLL )
{
MessageBox( NULL, "LoadLibrary() FAILED",
"DirectDraw Sample", MB_OK | MB_ICONERROR );
return -1;
}
pDirectDrawEnumerateEx = (LPDIRECTDRAWENUMERATEEX) GetProcAddress( hDDrawDLL, "DirectDrawEnumerateExA" );
if( pDirectDrawEnumerateEx )
{
pDirectDrawEnumerateEx( DDEnumCallbackEx, NULL,
DDENUM_ATTACHEDSECONDARYDEVICES |
DDENUM_DETACHEDSECONDARYDEVICES |
DDENUM_NONDISPLAYDEVICES );
}
else
{
// Old DirectDraw, so do it the old way
DirectDrawEnumerate( DDEnumCallback, NULL );
}
if( 0 == g_iMaxDevices )
{
MessageBox( NULL, "No devices to enumerate.",
"DirectDraw Sample", MB_OK | MB_ICONERROR );
return -1;
}
// Bring up the dialog to show all the devices
DialogBox( hInst, MAKEINTRESOURCE(IDD_DRIVERINFO),
GetDesktopWindow(), (DLGPROC)InfoDlgProc );
return 0;
}

View File

@@ -0,0 +1,119 @@
# Microsoft Developer Studio Project File - Name="DDEnum" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=DDEnum - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "ddenum.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "ddenum.mak" CFG="DDEnum - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "DDEnum - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "DDEnum - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "DDEnum - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir ".\Release"
# PROP BASE Intermediate_Dir ".\Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ".\Release"
# PROP Intermediate_Dir ".\Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /GX /O2 /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386 /stack:0x200000,0x200000
!ELSEIF "$(CFG)" == "DDEnum - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir ".\Debug"
# PROP BASE Intermediate_Dir ".\Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ".\Debug"
# PROP Intermediate_Dir ".\Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386
# ADD LINK32 dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386 /stack:0x200000,0x200000
!ENDIF
# Begin Target
# Name "DDEnum - Win32 Release"
# Name "DDEnum - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90"
# Begin Source File
SOURCE=.\ddenum.cpp
# End Source File
# Begin Source File
SOURCE=.\ddenum.rc
# End Source File
# Begin Source File
SOURCE=.\resource.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\DirectX.ico
# End Source File
# End Group
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "DDEnum"=.\ddenum.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,201 @@
# Microsoft Developer Studio Generated NMAKE File, Based on ddenum.dsp
!IF "$(CFG)" == ""
CFG=DDEnum - Win32 Release
!MESSAGE No configuration specified. Defaulting to DDEnum - Win32 Release.
!ENDIF
!IF "$(CFG)" != "DDEnum - Win32 Release" && "$(CFG)" != "DDEnum - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "ddenum.mak" CFG="DDEnum - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "DDEnum - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "DDEnum - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "DDEnum - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\ddenum.exe"
CLEAN :
-@erase "$(INTDIR)\ddenum.obj"
-@erase "$(INTDIR)\ddenum.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\ddenum.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\ddenum.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\ddenum.res" /d "NDEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\ddenum.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:no /pdb:"$(OUTDIR)\ddenum.pdb" /machine:I386 /out:"$(OUTDIR)\ddenum.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\ddenum.obj" \
"$(INTDIR)\ddenum.res"
"$(OUTDIR)\ddenum.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "DDEnum - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\ddenum.exe"
CLEAN :
-@erase "$(INTDIR)\ddenum.obj"
-@erase "$(INTDIR)\ddenum.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\ddenum.exe"
-@erase "$(OUTDIR)\ddenum.ilk"
-@erase "$(OUTDIR)\ddenum.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\ddenum.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\ddenum.res" /d "_DEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\ddenum.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:yes /pdb:"$(OUTDIR)\ddenum.pdb" /debug /machine:I386 /out:"$(OUTDIR)\ddenum.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\ddenum.obj" \
"$(INTDIR)\ddenum.res"
"$(OUTDIR)\ddenum.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("ddenum.dep")
!INCLUDE "ddenum.dep"
!ELSE
!MESSAGE Warning: cannot find "ddenum.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "DDEnum - Win32 Release" || "$(CFG)" == "DDEnum - Win32 Debug"
SOURCE=.\ddenum.cpp
"$(INTDIR)\ddenum.obj" : $(SOURCE) "$(INTDIR)"
SOURCE=.\ddenum.rc
"$(INTDIR)\ddenum.res" : $(SOURCE) "$(INTDIR)"
$(RSC) $(RSC_PROJ) $(SOURCE)
!ENDIF

View File

@@ -0,0 +1,134 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include <windows.h>
#include <afxres.h>
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DRIVERINFO DIALOG DISCARDABLE 0, 0, 199, 188
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Device Information"
FONT 8, "MS Shell Dlg"
BEGIN
PUSHBUTTON "<< &Prev",IDC_PREV,7,167,50,14
DEFPUSHBUTTON "Close",IDOK,71,167,55,14
PUSHBUTTON "&Next >>",IDC_NEXT,142,167,50,14
RTEXT "Version:",IDC_STATIC,18,80,58,8
RTEXT "Description:",IDC_STATIC,7,33,42,20
RTEXT "File Name:",IDC_STATIC,10,90,66,8
LTEXT "4.00.00.0000",IDC_VERSION,81,80,109,8
LTEXT "This is a temp test driver id sttring that is very long and might go over two lines",
IDC_DESCRIPTION,52,33,140,24
LTEXT "Static",IDC_FILENAME,82,90,102,8
RTEXT "GUID:",IDC_STATIC,7,59,24,8
RTEXT "Vendor ID:",IDC_STATIC,10,115,49,8
LTEXT "00000000",IDC_DWVENDORID,65,115,34,8
GROUPBOX "Driver Properties",IDC_STATIC,7,70,185,33
GROUPBOX "Device Identifiers",IDC_STATIC,7,104,185,34
RTEXT "Device ID:",IDC_STATIC,10,125,49,8
LTEXT "00000000",IDC_DWDEVICEID,65,125,34,8
RTEXT "SubSys ID:",IDC_STATIC,105,115,40,8
RTEXT "Revision:",IDC_STATIC,105,125,40,8
LTEXT "00000000",IDC_DWSUBSYS,150,115,40,8
LTEXT "00000000",IDC_DWREVISION,150,125,40,8
LTEXT "00000000-0000-0000-00000000",IDC_GUID,36,59,156,8
CONTROL "Device information for device %d of %d",
IDC_RADIO_DEVICE,"Button",BS_AUTORADIOBUTTON,44,7,148,10
CONTROL "Host",IDC_RADIO_HOST,"Button",BS_AUTORADIOBUTTON,44,16,
78,10
RTEXT "Show",IDC_STATIC,7,7,34,8
GROUPBOX "WHQL Certification Level",IDC_STATIC,7,139,185,22
LTEXT "Level:",IDC_STATIC,56,148,20,8
LTEXT "00000000",IDC_STATIC_WHQLLEVEL,83,148,33,8
END
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_MAIN_ICON ICON DISCARDABLE "DirectX.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include <windows.h>\r\n"
"#include <afxres.h>\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_DRIVERINFO, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 192
TOPMARGIN, 7
BOTTOMMARGIN, 181
END
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,28 @@
//-----------------------------------------------------------------------------
//
// Sample Name: DDEnum Sample
//
// Copyright (c) 1998-2001 Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
Description
===========
This sample shows how to enumerate the current DirectDraw devices and how to
get information using the IDirectDraw4::GetDeviceIdentifier method.
Path
====
Source: DXSDK\Samples\Multimedia\DDraw\DDEnum
Executable: DXSDK\Samples\Multimedia\DDraw\Bin
User's Guide
============
The user interface is a simple dialog box. Two buttons, Prev and Next,
display information for the previous or next device that was enumerated.
Click the Close button to exit the application.

View File

@@ -0,0 +1,33 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by ddenum.rc
//
#define IDI_MAIN_ICON 101
#define IDD_DRIVERINFO 102
#define IDC_PREV 1001
#define IDC_NEXT 1002
#define IDC_DEVICEID 1003
#define IDC_VERSION 1004
#define IDC_DESCRIPTION 1005
#define IDC_FILENAME 1006
#define IDC_COUNT 1007
#define IDC_GUID 1010
#define IDC_DWVENDORID 1012
#define IDC_DWDEVICEID 1014
#define IDC_DWSUBSYS 1015
#define IDC_DWREVISION 1016
#define IDC_RADIO_DEVICE 1018
#define IDC_RADIO_HOST 1019
#define IDC_STATIC_WHQLLEVEL 1020
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1021
#define _APS_NEXT_SYMED_VALUE 103
#endif
#endif

View File

@@ -0,0 +1,551 @@
//-----------------------------------------------------------------------------
// File: DirectSurfaceWrite.cpp
//
// Desc: This sample demonstrates how to animate sprites using
// DirectDraw. The samples runs in full-screen mode. Pressing any
// key will exit the sample.
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#define STRICT
#include <windows.h>
#include <ddraw.h>
#include <mmsystem.h>
#include "resource.h"
#include "ddutil.h"
//-----------------------------------------------------------------------------
// Defines, constants, and global variables
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 16
#define SPRITE_DIAMETER 250
#define NUM_SPRITES 5
#define HELPTEXT TEXT("Press Escape to quit.")
struct SPRITE_STRUCT
{
FLOAT fPosX;
FLOAT fPosY;
FLOAT fVelX;
FLOAT fVelY;
};
CDisplay* g_pDisplay = NULL;
CSurface* g_pSpriteSurface = NULL;
CSurface* g_pTextSurface = NULL;
RECT g_rcViewport;
RECT g_rcScreen;
BOOL g_bActive = FALSE;
DWORD g_dwLastTick;
SPRITE_STRUCT g_Sprite[NUM_SPRITES];
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
HRESULT WinInit( HINSTANCE hInst, int nCmdShow, HWND* phWnd, HACCEL* phAccel );
HRESULT InitDirectDraw( HWND hWnd );
HRESULT DrawSprite();
VOID FreeDirectDraw();
HRESULT ProcessNextFrame();
VOID UpdateSprite( SPRITE_STRUCT* pSprite, FLOAT fTimeDelta );
HRESULT DisplayFrame();
HRESULT RestoreSurfaces();
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything and calls
// UpdateFrame() when idle from the message pump.
//-----------------------------------------------------------------------------
int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int nCmdShow )
{
MSG msg;
HWND hWnd;
HACCEL hAccel;
ZeroMemory( &g_Sprite, sizeof(SPRITE_STRUCT) * NUM_SPRITES );
srand( GetTickCount() );
if( FAILED( WinInit( hInst, nCmdShow, &hWnd, &hAccel ) ) )
return FALSE;
if( FAILED( InitDirectDraw( hWnd ) ) )
{
SAFE_DELETE( g_pDisplay );
MessageBox( hWnd, TEXT("DirectDraw init failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
g_dwLastTick = timeGetTime();
while( TRUE )
{
// Look for messages, if none are found then
// update the state and display it
if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if( 0 == GetMessage(&msg, NULL, 0, 0 ) )
{
// WM_QUIT was posted, so exit
return (int)msg.wParam;
}
// Translate and dispatch the message
if( 0 == TranslateAccelerator( hWnd, hAccel, &msg ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
else
{
if( g_bActive )
{
// Move the sprites, blt them to the back buffer, then
// flip or blt the back buffer to the primary buffer
if( FAILED( ProcessNextFrame() ) )
{
SAFE_DELETE( g_pDisplay );
MessageBox( hWnd, TEXT("Displaying the next frame failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
}
else
{
// Make sure we go to sleep if we have nothing else to do
WaitMessage();
// Ignore time spent inactive
g_dwLastTick = timeGetTime();
}
}
}
}
//-----------------------------------------------------------------------------
// Name: WinInit()
// Desc: Init the window
//-----------------------------------------------------------------------------
HRESULT WinInit( HINSTANCE hInst, int nCmdShow, HWND* phWnd, HACCEL* phAccel )
{
WNDCLASS wc;
HWND hWnd;
HACCEL hAccel;
// Register the Window Class
wc.lpszClassName = TEXT("DirectSurfaceWrite");
wc.lpfnWndProc = MainWndProc;
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInst;
wc.hIcon = LoadIcon( hInst, MAKEINTRESOURCE(IDI_MAIN) );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if( RegisterClass( &wc ) == 0 )
return E_FAIL;
// Load keyboard accelerators
hAccel = LoadAccelerators( hInst, MAKEINTRESOURCE(IDR_MAIN_ACCEL) );
// Create and show the main window
hWnd = CreateWindowEx( 0, TEXT("DirectSurfaceWrite"), TEXT("DirectDraw DirectSurfaceWrite Sample"),
WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL );
if( hWnd == NULL )
return E_FAIL;
ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );
*phWnd = hWnd;
*phAccel = hAccel;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InitDirectDraw()
// Desc: Create the DirectDraw object, and init the surfaces
//-----------------------------------------------------------------------------
HRESULT InitDirectDraw( HWND hWnd )
{
HRESULT hr;
g_pDisplay = new CDisplay();
if( FAILED( hr = g_pDisplay->CreateFullScreenDisplay( hWnd, SCREEN_WIDTH,
SCREEN_HEIGHT, SCREEN_BPP ) ) )
{
MessageBox( hWnd, TEXT("This display card does not support 640x480x8. "),
TEXT("DirectDraw Sample"), MB_ICONERROR | MB_OK );
return hr;
}
// Create a DirectDrawSurface for this bitmap
if( FAILED( hr = g_pDisplay->CreateSurface( &g_pSpriteSurface, SPRITE_DIAMETER, SPRITE_DIAMETER ) ) )
return hr;
if( FAILED( hr = DrawSprite() ) )
return hr;
// Create a surface, and draw text to it.
if( FAILED( hr = g_pDisplay->CreateSurfaceFromText( &g_pTextSurface, NULL, HELPTEXT,
RGB(0,0,0), RGB(255, 255, 0) ) ) )
return hr;
// Init all the sprites. All of these sprites using the
// same g_pDDSAnimationSheet surface, but depending on the
// sprite's lFrame value, it indexes a different rect on the
// surface.
for( int iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
{
// Set the sprite's position and velocity
g_Sprite[iSprite].fPosX = (float) (rand() % SCREEN_WIDTH);
g_Sprite[iSprite].fPosY = (float) (rand() % SCREEN_HEIGHT);
g_Sprite[iSprite].fVelX = 500.0f * rand() / RAND_MAX - 250.0f;
g_Sprite[iSprite].fVelY = 500.0f * rand() / RAND_MAX - 250.0f;
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DrawSprite()
// Desc: Draws a pattern of colors to a DirectDraw surface by directly writing
// to the surface memory. This function was designed to work only in
// 16-bit color.
//-----------------------------------------------------------------------------
HRESULT DrawSprite()
{
DDSURFACEDESC2 ddsd;
HRESULT hr;
DWORD dwShift;
DWORD dwBits;
DWORD dwRed;
DWORD dwGreen;
DWORD dwBlue;
FLOAT fPercentX;
FLOAT fPercentY;
FLOAT fPercentXY;
LPDIRECTDRAWSURFACE7 pDDS = g_pSpriteSurface->GetDDrawSurface();
ZeroMemory( &ddsd,sizeof(ddsd) );
ddsd.dwSize = sizeof(ddsd);
// Lock the surface to directly write to the surface memory
if( FAILED( hr = pDDS->Lock( NULL, &ddsd, DDLOCK_WAIT, NULL ) ) )
return hr;
// Get a pointer into the memory starting at ddsd.lpSurface. Cast this pointer to a
// 16-bit WORD since we are in 16 bit color, so each pixel has 16 bits of color information.
WORD* pDDSColor = (WORD*) ddsd.lpSurface;
for( DWORD iY = 0; iY < ddsd.dwHeight; iY++ )
{
for( DWORD iX = 0; iX < ddsd.dwWidth; iX++ )
{
// Figure out the red component as a function of the Y location of the pixel
CSurface::GetBitMaskInfo( ddsd.ddpfPixelFormat.dwRBitMask, &dwShift, &dwBits );
fPercentY = (float) abs( ddsd.dwHeight / 2 - iY ) / (float) ( ddsd.dwHeight / 2 ) + 0.25f;
if( fPercentY > 1.00f )
fPercentY = 1.00f;
dwRed = (DWORD) ( (ddsd.ddpfPixelFormat.dwRBitMask >> dwShift) * fPercentY) << dwShift;
// Figure out the green component as a function of the X location of the pixel
CSurface::GetBitMaskInfo( ddsd.ddpfPixelFormat.dwGBitMask, &dwShift, &dwBits );
fPercentX = (float) abs( ddsd.dwWidth / 2 - iX ) / (float) ( ddsd.dwWidth / 2 ) + 0.25f;
if( fPercentX > 1.00f )
fPercentX = 1.00f;
dwGreen = (DWORD) ( (ddsd.ddpfPixelFormat.dwGBitMask >> dwShift) * fPercentX) << dwShift;
// Figure out the blue component as a function of the X and Y location of the pixel
CSurface::GetBitMaskInfo( ddsd.ddpfPixelFormat.dwBBitMask, &dwShift, &dwBits );
fPercentX = (float) abs( ddsd.dwWidth / 2 - iX ) / (float) ( ddsd.dwWidth / 4 );
fPercentX = 1.0f - fPercentX * fPercentX;
fPercentY = (float) abs( ddsd.dwHeight / 2 - iY ) / (float) ( ddsd.dwHeight / 4 );
fPercentY = 1.0f - fPercentY * fPercentY;
fPercentXY = fPercentX + fPercentY;
if( fPercentXY > 1.0f )
fPercentXY = 1.0f;
if( fPercentXY < 0.0f )
fPercentXY = 0.0f;
dwBlue = (DWORD) ( (ddsd.ddpfPixelFormat.dwBBitMask >> dwShift) * fPercentXY ) << dwShift;
// Make the dwDDSColor by combining all the color components
*pDDSColor = (WORD) ( dwRed | dwGreen | dwBlue );
// Advance the surface pointer by 16 bits (one pixel)
pDDSColor++;
}
// Multiply ddsd.lPitch by iY to figure out offset needed to access
// the next scan line on the surface.
pDDSColor = (WORD*) ( (BYTE*) ddsd.lpSurface + ( iY + 1 ) * ddsd.lPitch );
}
// Unlock the surface
pDDS->Unlock(NULL);
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: FreeDirectDraw()
// Desc: Release all the DirectDraw objects
//-----------------------------------------------------------------------------
VOID FreeDirectDraw()
{
SAFE_DELETE( g_pSpriteSurface );
SAFE_DELETE( g_pTextSurface );
SAFE_DELETE( g_pDisplay );
}
//-----------------------------------------------------------------------------
// Name: MainWndProc()
// Desc: The main window procedure
//-----------------------------------------------------------------------------
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch (msg)
{
case WM_COMMAND:
switch( LOWORD(wParam) )
{
case IDM_EXIT:
// Received key/menu command to exit app
PostMessage( hWnd, WM_CLOSE, 0, 0 );
return 0L;
}
break; // Continue with default processing
case WM_SETCURSOR:
// Hide the cursor in fullscreen
SetCursor( NULL );
return TRUE;
case WM_SIZE:
// Check to see if we are losing our window...
if( SIZE_MAXHIDE==wParam || SIZE_MINIMIZED==wParam )
g_bActive = FALSE;
else
g_bActive = TRUE;
break;
case WM_EXITMENULOOP:
// Ignore time spent in menu
g_dwLastTick = timeGetTime();
break;
case WM_EXITSIZEMOVE:
// Ignore time spent resizing
g_dwLastTick = timeGetTime();
break;
case WM_SYSCOMMAND:
// Prevent moving/sizing and power loss in fullscreen mode
switch( wParam )
{
case SC_MOVE:
case SC_SIZE:
case SC_MAXIMIZE:
case SC_MONITORPOWER:
return TRUE;
}
break;
case WM_DESTROY:
// Cleanup and close the app
FreeDirectDraw();
PostQuitMessage( 0 );
return 0L;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
//-----------------------------------------------------------------------------
// Name: ProcessNextFrame()
// Desc: Move the sprites, blt them to the back buffer, then
// flips the back buffer to the primary buffer
//-----------------------------------------------------------------------------
HRESULT ProcessNextFrame()
{
HRESULT hr;
// Figure how much time has passed since the last time
DWORD dwCurrTick = timeGetTime();
DWORD dwTickDiff = dwCurrTick - g_dwLastTick;
// Don't update if no time has passed
if( dwTickDiff == 0 )
return S_OK;
g_dwLastTick = dwCurrTick;
// Update the sprites according to how much time has passed
for( int iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
UpdateSprite( &g_Sprite[ iSprite ], dwTickDiff / 1000.0f );
// Display the sprites on the screen
if( FAILED( hr = DisplayFrame() ) )
{
if( hr != DDERR_SURFACELOST )
return hr;
// The surfaces were lost so restore them
RestoreSurfaces();
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: UpdateSprite()
// Desc: Moves and bounces the sprite based on how much time has passed.
// It also changes the sprite state based on random values it gets
// from the array g_lRandTable
//-----------------------------------------------------------------------------
VOID UpdateSprite( SPRITE_STRUCT* pSprite, FLOAT fTimeDelta )
{
// Update the sprite position
pSprite->fPosX += pSprite->fVelX * fTimeDelta;
pSprite->fPosY += pSprite->fVelY * fTimeDelta;
// Clip the position, and bounce if it hits the edge
if( pSprite->fPosX < 0.0f )
{
pSprite->fPosX = 0;
pSprite->fVelX = -pSprite->fVelX;
}
if( pSprite->fPosX >= SCREEN_WIDTH - SPRITE_DIAMETER )
{
pSprite->fPosX = SCREEN_WIDTH - 1 - SPRITE_DIAMETER;
pSprite->fVelX = -pSprite->fVelX;
}
if( pSprite->fPosY < 0 )
{
pSprite->fPosY = 0;
pSprite->fVelY = -pSprite->fVelY;
}
if( pSprite->fPosY > SCREEN_HEIGHT - SPRITE_DIAMETER )
{
pSprite->fPosY = SCREEN_HEIGHT - 1 - SPRITE_DIAMETER;
pSprite->fVelY = -pSprite->fVelY;
}
}
//-----------------------------------------------------------------------------
// Name: DisplayFrame()
// Desc: Blts a the sprites to the back buffer, then flips the
// back buffer onto the primary buffer.
//-----------------------------------------------------------------------------
HRESULT DisplayFrame()
{
HRESULT hr;
// Fill the back buffer with black, ignoring errors until the flip
g_pDisplay->Clear( 0 );
// Blt the help text on the backbuffer, ignoring errors until the flip
g_pDisplay->Blt( 10, 10, g_pTextSurface, NULL );
// Blt all the sprites onto the back buffer using color keying,
// ignoring errors until the flip. Note that all of these sprites
// use the same DirectDraw surface.
for( int iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
{
g_pDisplay->Blt( (DWORD)g_Sprite[iSprite].fPosX,
(DWORD)g_Sprite[iSprite].fPosY,
g_pSpriteSurface, NULL );
}
// We are in fullscreen mode, so perform a flip and return
// any errors like DDERR_SURFACELOST
if( FAILED( hr = g_pDisplay->Present() ) )
return hr;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: RestoreSurfaces()
// Desc: Restore all the surfaces, and redraw the sprite surfaces.
//-----------------------------------------------------------------------------
HRESULT RestoreSurfaces()
{
HRESULT hr;
if( FAILED( hr = g_pDisplay->GetDirectDraw()->RestoreAllSurfaces() ) )
return hr;
// No need to re-create the surface, just re-draw it.
if( FAILED( hr = g_pTextSurface->DrawText( NULL, HELPTEXT,
0, 0, RGB(0,0,0), RGB(255, 255, 0) ) ) )
return hr;
// No need to re-create the surface, just re-draw it.
if( FAILED( hr = DrawSprite() ) )
return hr;
return S_OK;
}

View File

@@ -0,0 +1,147 @@
# Microsoft Developer Studio Project File - Name="DirectSurfaceWrite" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=DirectSurfaceWrite - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "directsurfacewrite.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "directsurfacewrite.mak" CFG="DirectSurfaceWrite - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "DirectSurfaceWrite - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "DirectSurfaceWrite - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "DirectSurfaceWrite - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir ".\Release"
# PROP BASE Intermediate_Dir ".\Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ".\Release"
# PROP Intermediate_Dir ".\Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /GX /O2 /I "..\common" /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 dxguid.lib winmm.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386 /stack:0x200000,0x200000
!ELSEIF "$(CFG)" == "DirectSurfaceWrite - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir ".\Debug"
# PROP BASE Intermediate_Dir ".\Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ".\Debug"
# PROP Intermediate_Dir ".\Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386
# ADD LINK32 winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386 /stack:0x200000,0x200000
!ENDIF
# Begin Target
# Name "DirectSurfaceWrite - Win32 Release"
# Name "DirectSurfaceWrite - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90"
# Begin Source File
SOURCE=.\DirectSurfaceWrite.cpp
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\animate.bmp
# End Source File
# Begin Source File
SOURCE=.\DirectSurfaceWrite.rc
# End Source File
# Begin Source File
SOURCE=.\directx.bmp
# End Source File
# Begin Source File
SOURCE=.\DirectX.ico
# End Source File
# Begin Source File
SOURCE=.\resource.h
# End Source File
# End Group
# Begin Group "Common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\common\src\ddutil.cpp
# End Source File
# Begin Source File
SOURCE=..\..\common\include\ddutil.h
# End Source File
# Begin Source File
SOURCE=..\..\common\src\dxutil.cpp
# End Source File
# Begin Source File
SOURCE=..\..\common\include\dxutil.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "DirectSurfaceWrite"=.\directsurfacewrite.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,221 @@
# Microsoft Developer Studio Generated NMAKE File, Based on directsurfacewrite.dsp
!IF "$(CFG)" == ""
CFG=DirectSurfaceWrite - Win32 Release
!MESSAGE No configuration specified. Defaulting to DirectSurfaceWrite - Win32 Release.
!ENDIF
!IF "$(CFG)" != "DirectSurfaceWrite - Win32 Release" && "$(CFG)" != "DirectSurfaceWrite - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "directsurfacewrite.mak" CFG="DirectSurfaceWrite - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "DirectSurfaceWrite - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "DirectSurfaceWrite - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "DirectSurfaceWrite - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\directsurfacewrite.exe"
CLEAN :
-@erase "$(INTDIR)\ddutil.obj"
-@erase "$(INTDIR)\DirectSurfaceWrite.obj"
-@erase "$(INTDIR)\DirectSurfaceWrite.res"
-@erase "$(INTDIR)\dxutil.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\directsurfacewrite.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "..\common" /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\directsurfacewrite.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\DirectSurfaceWrite.res" /d "NDEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\directsurfacewrite.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=dxguid.lib winmm.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:no /pdb:"$(OUTDIR)\directsurfacewrite.pdb" /machine:I386 /out:"$(OUTDIR)\directsurfacewrite.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\DirectSurfaceWrite.obj" \
"$(INTDIR)\ddutil.obj" \
"$(INTDIR)\dxutil.obj" \
"$(INTDIR)\DirectSurfaceWrite.res"
"$(OUTDIR)\directsurfacewrite.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "DirectSurfaceWrite - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\directsurfacewrite.exe"
CLEAN :
-@erase "$(INTDIR)\ddutil.obj"
-@erase "$(INTDIR)\DirectSurfaceWrite.obj"
-@erase "$(INTDIR)\DirectSurfaceWrite.res"
-@erase "$(INTDIR)\dxutil.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\directsurfacewrite.exe"
-@erase "$(OUTDIR)\directsurfacewrite.ilk"
-@erase "$(OUTDIR)\directsurfacewrite.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\directsurfacewrite.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\DirectSurfaceWrite.res" /d "_DEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\directsurfacewrite.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:yes /pdb:"$(OUTDIR)\directsurfacewrite.pdb" /debug /machine:I386 /out:"$(OUTDIR)\directsurfacewrite.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\DirectSurfaceWrite.obj" \
"$(INTDIR)\ddutil.obj" \
"$(INTDIR)\dxutil.obj" \
"$(INTDIR)\DirectSurfaceWrite.res"
"$(OUTDIR)\directsurfacewrite.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("directsurfacewrite.dep")
!INCLUDE "directsurfacewrite.dep"
!ELSE
!MESSAGE Warning: cannot find "directsurfacewrite.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "DirectSurfaceWrite - Win32 Release" || "$(CFG)" == "DirectSurfaceWrite - Win32 Debug"
SOURCE=.\DirectSurfaceWrite.cpp
"$(INTDIR)\DirectSurfaceWrite.obj" : $(SOURCE) "$(INTDIR)"
SOURCE=.\DirectSurfaceWrite.rc
"$(INTDIR)\DirectSurfaceWrite.res" : $(SOURCE) "$(INTDIR)"
$(RSC) $(RSC_PROJ) $(SOURCE)
SOURCE=..\..\common\src\ddutil.cpp
"$(INTDIR)\ddutil.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=..\..\common\src\dxutil.cpp
"$(INTDIR)\dxutil.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
!ENDIF

View File

@@ -0,0 +1,84 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include <windows.h>
#include <afxres.h>
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_MAIN ICON DISCARDABLE "DirectX.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include <windows.h>\r\n"
"#include <afxres.h>\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDR_MAIN_ACCEL ACCELERATORS DISCARDABLE
BEGIN
VK_ESCAPE, IDM_EXIT, VIRTKEY, NOINVERT
"X", IDM_EXIT, VIRTKEY, ALT, NOINVERT
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,37 @@
//-----------------------------------------------------------------------------
//
// Sample Name: DirectSurfaceWrite Sample
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
Description
===========
DirectSurfaceWrite demonstrates how to write directly to a DirectDraw surface.
Path
====
Source: DXSDK\Samples\Multimedia\DDraw\DirectSurfaceWrite
Executable: DXSDK\Samples\Multimedia\DDraw\Bin
User's Guide
============
DirectSurfaceWrite requires no user input. Press the ESC key to quit the program.
Programming Notes
=================
For details on how to setup a full-screen DirectDraw app, see the FullScreenMode
sample.
To write directly on a DirectDraw surface first call IDirectDrawSurface::Lock
to obtain a pointer directly into the memory of the DirectDraw surface. While
the surface is locked, the surface can not be blted or flipped onto other surfaces.
The surface's pixel format will tell you the data format the surface stores pixels
in. Be sure to advance the surface pointer by the surface pitch instead of the surface
width, since the surface may be wider than its width. After the drawing is finished
call IDirectDrawSurface::Unlock to allow the surface to blt to other surfaces. See
DrawSprite() in this sample for an example of how this is done.

View File

@@ -0,0 +1,19 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by DirectSurfaceWrite.rc
//
#define IDI_ICON1 101
#define IDI_MAIN 102
#define IDR_MAIN_ACCEL 103
#define IDM_EXIT 1001
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,555 @@
//-----------------------------------------------------------------------------
// File: FullScreenDialog.cpp
//
// Desc: This sample demonstrates how to bring up a dialog box, or any other
// type of window while running in DirectDraw full-screen exclusive mode.
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#define STRICT
#include <windows.h>
#include <basetsd.h>
#include <ddraw.h>
#include <mmsystem.h>
#include "resource.h"
#include "ddutil.h"
//-----------------------------------------------------------------------------
// Defines, constants, and global variables
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 16
#define SPRITE_DIAMETER 48
#define NUM_SPRITES 25
#define HELPTEXT TEXT("Press Escape to quit. Press F1 to bring up the dialog.")
struct SPRITE_STRUCT
{
FLOAT fPosX;
FLOAT fPosY;
FLOAT fVelX;
FLOAT fVelY;
};
CDisplay* g_pDisplay = NULL;
CSurface* g_pLogoSurface = NULL;
CSurface* g_pTextSurface = NULL;
BOOL g_bActive = FALSE;
DWORD g_dwLastTick;
SPRITE_STRUCT g_Sprite[NUM_SPRITES];
HWND g_hWndDlg = NULL;
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
INT_PTR CALLBACK SampleDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam );
HRESULT WinInit( HINSTANCE hInst, int nCmdShow, HWND* phWnd, HACCEL* phAccel );
HRESULT InitDirectDraw( HWND hWnd );
VOID FreeDirectDraw();
HRESULT ProcessNextFrame();
VOID UpdateSprite( SPRITE_STRUCT* pSprite, FLOAT fTimeDelta );
HRESULT DisplayFrame();
HRESULT RestoreSurfaces();
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything and calls
// UpdateFrame() when idle from the message pump.
//-----------------------------------------------------------------------------
int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int nCmdShow )
{
MSG msg;
HWND hWnd;
HACCEL hAccel;
ZeroMemory( &g_Sprite, sizeof(SPRITE_STRUCT) * NUM_SPRITES );
srand( GetTickCount() );
if( FAILED( WinInit( hInst, nCmdShow, &hWnd, &hAccel ) ) )
return FALSE;
if( FAILED( InitDirectDraw( hWnd ) ) )
{
MessageBox( hWnd, TEXT("DirectDraw init failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
// Show the dialog immediately
g_hWndDlg = CreateDialog( hInst, MAKEINTRESOURCE(IDD_DIALOG_SAMPLE),
hWnd, (DLGPROC) SampleDlgProc );
ShowWindow( g_hWndDlg, SW_SHOWNORMAL );
g_dwLastTick = timeGetTime();
while( TRUE )
{
// Look for messages, if none are found then
// update the state and display it
if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if( 0 == GetMessage(&msg, NULL, 0, 0 ) )
{
// WM_QUIT was posted, so exit
return (int)msg.wParam;
}
// Translate and dispatch the message. If the dialog is showing,
// translate messages for it since it's a modeless dialog.
if( g_hWndDlg == NULL || !IsDialogMessage( g_hWndDlg, &msg ) )
{
if( 0 == TranslateAccelerator( hWnd, hAccel, &msg ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
}
else
{
if( g_bActive )
{
// Move the sprites, blt them to the back buffer, then
// flip or blt the back buffer to the primary buffer
if( FAILED( ProcessNextFrame() ) )
{
SAFE_DELETE( g_pDisplay );
MessageBox( hWnd, TEXT("Displaying the next frame failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
}
else
{
// Make sure we go to sleep if we have nothing else to do
WaitMessage();
// Ignore time spent inactive
g_dwLastTick = timeGetTime();
}
}
}
}
//-----------------------------------------------------------------------------
// Name: WinInit()
// Desc: Init the window
//-----------------------------------------------------------------------------
HRESULT WinInit( HINSTANCE hInst, int nCmdShow, HWND* phWnd, HACCEL* phAccel )
{
WNDCLASS wc;
HWND hWnd;
HACCEL hAccel;
// Register the Window Class
wc.lpszClassName = TEXT("FullScreenDialog");
wc.lpfnWndProc = MainWndProc;
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInst;
wc.hIcon = LoadIcon( hInst, MAKEINTRESOURCE(IDI_MAIN) );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if( RegisterClass( &wc ) == 0 )
return E_FAIL;
// Load keyboard accelerators
hAccel = LoadAccelerators( hInst, MAKEINTRESOURCE(IDR_MAIN_ACCEL) );
// Create and show the main window
hWnd = CreateWindowEx( 0, TEXT("FullScreenDialog"), TEXT("DirectDraw FullScreenDialog Sample"),
WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL );
if( hWnd == NULL )
return E_FAIL;
ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );
*phWnd = hWnd;
*phAccel = hAccel;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InitDirectDraw()
// Desc: Create the DirectDraw object, and init the surfaces
//-----------------------------------------------------------------------------
HRESULT InitDirectDraw( HWND hWnd )
{
HRESULT hr;
int iSprite;
g_pDisplay = new CDisplay();
if( FAILED( hr = g_pDisplay->CreateFullScreenDisplay( hWnd, SCREEN_WIDTH,
SCREEN_HEIGHT, SCREEN_BPP ) ) )
{
MessageBox( hWnd, TEXT("This display card does not support 640x480x8. "),
TEXT("DirectDraw Sample"), MB_ICONERROR | MB_OK );
return hr;
}
// Check if the device supports DDCAPS2_CANRENDERWINDOWED.
// If it does, then it supports GDI writing directly to the primary surface
// Otherwise, to do GDI displaying on these cards, you you must create a
// bitmap of the GDI window and BitBlt the bitmap to the backbuffer
// then flip as normal. However, this sample does not show this.
DDCAPS ddcaps;
ZeroMemory( &ddcaps, sizeof(ddcaps) );
ddcaps.dwSize = sizeof(ddcaps);
g_pDisplay->GetDirectDraw()->GetCaps( &ddcaps, NULL );
if( (ddcaps.dwCaps2 & DDCAPS2_CANRENDERWINDOWED) == 0 )
{
MessageBox( hWnd, TEXT("This display card can not render GDI."),
TEXT("DirectDraw Sample"), MB_ICONERROR | MB_OK );
return E_FAIL;
}
// Create a clipper so DirectDraw will not blt over the GDI dialog
if( FAILED( hr = g_pDisplay->InitClipper() ) )
return hr;
// Create a surface, and draw text to it.
if( FAILED( hr = g_pDisplay->CreateSurfaceFromText( &g_pTextSurface, NULL, HELPTEXT,
RGB(0,0,0), RGB(255, 255, 0) ) ) )
return hr;
// Create a surface, and draw a bitmap resource on it.
if( FAILED( hr = g_pDisplay->CreateSurfaceFromBitmap( &g_pLogoSurface, MAKEINTRESOURCE( IDB_DIRECTX ),
SPRITE_DIAMETER, SPRITE_DIAMETER ) ) )
return hr;
// Set the color key for the logo sprite to black
if( FAILED( hr = g_pLogoSurface->SetColorKey( 0 ) ) )
return hr;
// Init all the sprites. All of these sprites look the same,
// using the g_pDDSLogo surface.
for( iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
{
// Set the sprite's position and velocity
g_Sprite[iSprite].fPosX = (float) (rand() % SCREEN_WIDTH);
g_Sprite[iSprite].fPosY = (float) (rand() % SCREEN_HEIGHT);
g_Sprite[iSprite].fVelX = 500.0f * rand() / RAND_MAX - 250.0f;
g_Sprite[iSprite].fVelY = 500.0f * rand() / RAND_MAX - 250.0f;
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: FreeDirectDraw()
// Desc: Release all the DirectDraw objects
//-----------------------------------------------------------------------------
VOID FreeDirectDraw()
{
SAFE_DELETE( g_pLogoSurface );
SAFE_DELETE( g_pTextSurface );
SAFE_DELETE( g_pDisplay );
}
//-----------------------------------------------------------------------------
// Name: MainWndProc()
// Desc: The main window procedure
//-----------------------------------------------------------------------------
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch (msg)
{
case WM_COMMAND:
switch( LOWORD(wParam) )
{
case IDM_EXIT:
// Received key/menu command to exit app
PostMessage( hWnd, WM_CLOSE, 0, 0 );
return 0L;
case IDM_SHOW_DIALOG:
{
HINSTANCE hInst;
#ifdef _WIN64
hInst = (HINSTANCE) GetWindowLongPtr( hWnd, GWLP_HINSTANCE );
#else
hInst = (HINSTANCE) GetWindowLong( hWnd, GWL_HINSTANCE );
#endif
g_hWndDlg = CreateDialog( hInst, MAKEINTRESOURCE(IDD_DIALOG_SAMPLE),
hWnd, (DLGPROC) SampleDlgProc );
ShowWindow( g_hWndDlg, SW_SHOWNORMAL );
}
break;
}
break; // Continue with default processing
case WM_SIZE:
// Check to see if we are losing our window...
if( SIZE_MAXHIDE==wParam || SIZE_MINIMIZED==wParam )
g_bActive = FALSE;
else
g_bActive = TRUE;
break;
case WM_EXITMENULOOP:
// Ignore time spent in menu
g_dwLastTick = timeGetTime();
break;
case WM_EXITSIZEMOVE:
// Ignore time spent resizing
g_dwLastTick = timeGetTime();
break;
case WM_SYSCOMMAND:
// Prevent moving/sizing and power loss in fullscreen mode
switch( wParam )
{
case SC_MOVE:
case SC_SIZE:
case SC_MAXIMIZE:
case SC_MONITORPOWER:
return TRUE;
}
break;
case WM_DESTROY:
// Cleanup and close the app
FreeDirectDraw();
PostQuitMessage( 0 );
return 0L;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
//-----------------------------------------------------------------------------
// Name: SampleDlgProc()
// Desc: A simple dialog that has some standard controls, so you can see that
// they update properly.
//-----------------------------------------------------------------------------
INT_PTR CALLBACK SampleDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
{
static TCHAR* pszCombo[] = {"One","Two","Three","Four","Five","Six"};
switch (msg)
{
case WM_INITDIALOG:
{
for( int i = 0; i < 6; i++ )
SendDlgItemMessage( hDlg, IDC_COMBO1, CB_ADDSTRING,
0, (LPARAM) pszCombo[i] );
SendDlgItemMessage( hDlg, IDC_COMBO1, CB_SETCURSEL, 0, 0 );
CheckDlgButton( hDlg, IDC_RADIO1, BST_CHECKED );
}
return TRUE;
case WM_COMMAND:
switch( LOWORD(wParam) )
{
case IDCANCEL:
case IDOK:
EndDialog( hDlg, TRUE );
return TRUE;
}
break;
case WM_MOVE:
// The window is moving around, so re-draw the backbuffer
DisplayFrame();
break;
case WM_DESTROY:
g_hWndDlg = NULL;
break;
}
return FALSE;
}
//-----------------------------------------------------------------------------
// Name: ProcessNextFrame()
// Desc: Move the sprites, blt them to the back buffer, then
// flips the back buffer to the primary buffer
//-----------------------------------------------------------------------------
HRESULT ProcessNextFrame()
{
HRESULT hr;
// Figure how much time has passed since the last time
DWORD dwCurrTick = timeGetTime();
DWORD dwTickDiff = dwCurrTick - g_dwLastTick;
// Don't update if no time has passed
if( dwTickDiff == 0 )
return S_OK;
g_dwLastTick = dwCurrTick;
// Move the sprites according to how much time has passed
for( int iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
UpdateSprite( &g_Sprite[ iSprite ], dwTickDiff / 1000.0f );
// Display the sprites on the screen
if( FAILED( hr = DisplayFrame() ) )
{
if( hr != DDERR_SURFACELOST )
return hr;
// The surfaces were lost so restore them
RestoreSurfaces();
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: UpdateSprite()
// Desc: Move the sprite around and make it bounce based on how much time
// has passed
//-----------------------------------------------------------------------------
VOID UpdateSprite( SPRITE_STRUCT* pSprite, FLOAT fTimeDelta )
{
// Update the sprite position
pSprite->fPosX += pSprite->fVelX * fTimeDelta;
pSprite->fPosY += pSprite->fVelY * fTimeDelta;
// Clip the position, and bounce if it hits the edge
if( pSprite->fPosX < 0.0f )
{
pSprite->fPosX = 0;
pSprite->fVelX = -pSprite->fVelX;
}
if( pSprite->fPosX >= SCREEN_WIDTH - SPRITE_DIAMETER )
{
pSprite->fPosX = SCREEN_WIDTH - 1 - SPRITE_DIAMETER;
pSprite->fVelX = -pSprite->fVelX;
}
if( pSprite->fPosY < 0 )
{
pSprite->fPosY = 0;
pSprite->fVelY = -pSprite->fVelY;
}
if( pSprite->fPosY > SCREEN_HEIGHT - SPRITE_DIAMETER )
{
pSprite->fPosY = SCREEN_HEIGHT - 1 - SPRITE_DIAMETER;
pSprite->fVelY = -pSprite->fVelY;
}
}
//-----------------------------------------------------------------------------
// Name: DisplayFrame()
// Desc: Blts a the sprites to the back buffer, then flips the
// back buffer onto the primary buffer.
//-----------------------------------------------------------------------------
HRESULT DisplayFrame()
{
HRESULT hr;
// Fill the back buffer with black, ignoring errors until the flip
g_pDisplay->Clear( 0 );
// Blt the help text on the backbuffer, ignoring errors until the flip
g_pDisplay->Blt( 10, 10, g_pTextSurface, NULL );
// Blt all the sprites onto the back buffer using color keying,
// ignoring errors until the last call. Note that all of these sprites
// use the same DirectDraw surface.
for( int iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
{
g_pDisplay->Blt( (DWORD)g_Sprite[iSprite].fPosX,
(DWORD)g_Sprite[iSprite].fPosY,
g_pLogoSurface, NULL );
}
// Updating the primary buffer with a blt
LPDIRECTDRAWSURFACE7 pddsFrontBuffer = g_pDisplay->GetFrontBuffer();
LPDIRECTDRAWSURFACE7 pddsBackBuffer = g_pDisplay->GetBackBuffer();
if( FAILED( hr = pddsFrontBuffer->Blt( NULL, pddsBackBuffer, NULL,
DDBLT_WAIT, NULL ) ) )
return hr;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: RestoreSurfaces()
// Desc: Restore all the surfaces, and redraw the sprite surfaces.
//-----------------------------------------------------------------------------
HRESULT RestoreSurfaces()
{
HRESULT hr;
if( FAILED( hr = g_pDisplay->GetDirectDraw()->RestoreAllSurfaces() ) )
return hr;
// No need to re-create the surface, just re-draw it.
if( FAILED( hr = g_pTextSurface->DrawText( NULL, HELPTEXT,
0, 0, RGB(0,0,0), RGB(255, 255, 0) ) ) )
return hr;
// No need to re-create the surface, just re-draw it.
if( FAILED( hr = g_pLogoSurface->DrawBitmap( MAKEINTRESOURCE( IDB_DIRECTX ),
SPRITE_DIAMETER, SPRITE_DIAMETER ) ) )
return hr;
return S_OK;
}

View File

@@ -0,0 +1,143 @@
# Microsoft Developer Studio Project File - Name="FullScreenDialog" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=FullScreenDialog - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "fullscreendialog.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "fullscreendialog.mak" CFG="FullScreenDialog - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "FullScreenDialog - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "FullScreenDialog - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "FullScreenDialog - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir ".\Release"
# PROP BASE Intermediate_Dir ".\Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ".\Release"
# PROP Intermediate_Dir ".\Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /GX /O2 /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386 /stack:0x200000,0x200000
!ELSEIF "$(CFG)" == "FullScreenDialog - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir ".\Debug"
# PROP BASE Intermediate_Dir ".\Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ".\Debug"
# PROP Intermediate_Dir ".\Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386
# ADD LINK32 winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386 /stack:0x200000,0x200000
!ENDIF
# Begin Target
# Name "FullScreenDialog - Win32 Release"
# Name "FullScreenDialog - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90"
# Begin Source File
SOURCE=.\FullScreenDialog.cpp
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\directx.bmp
# End Source File
# Begin Source File
SOURCE=.\DirectX.ico
# End Source File
# Begin Source File
SOURCE=.\FullScreenDialog.rc
# End Source File
# Begin Source File
SOURCE=.\resource.h
# End Source File
# End Group
# Begin Group "Common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\common\src\ddutil.cpp
# End Source File
# Begin Source File
SOURCE=..\..\common\include\ddutil.h
# End Source File
# Begin Source File
SOURCE=..\..\common\src\dxutil.cpp
# End Source File
# Begin Source File
SOURCE=..\..\common\include\dxutil.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "FullScreenDialog"=.\fullscreendialog.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,221 @@
# Microsoft Developer Studio Generated NMAKE File, Based on fullscreendialog.dsp
!IF "$(CFG)" == ""
CFG=FullScreenDialog - Win32 Release
!MESSAGE No configuration specified. Defaulting to FullScreenDialog - Win32 Release.
!ENDIF
!IF "$(CFG)" != "FullScreenDialog - Win32 Release" && "$(CFG)" != "FullScreenDialog - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "fullscreendialog.mak" CFG="FullScreenDialog - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "FullScreenDialog - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "FullScreenDialog - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "FullScreenDialog - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\fullscreendialog.exe"
CLEAN :
-@erase "$(INTDIR)\ddutil.obj"
-@erase "$(INTDIR)\dxutil.obj"
-@erase "$(INTDIR)\FullScreenDialog.obj"
-@erase "$(INTDIR)\FullScreenDialog.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\fullscreendialog.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\fullscreendialog.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\FullScreenDialog.res" /d "NDEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\fullscreendialog.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:no /pdb:"$(OUTDIR)\fullscreendialog.pdb" /machine:I386 /out:"$(OUTDIR)\fullscreendialog.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\FullScreenDialog.obj" \
"$(INTDIR)\ddutil.obj" \
"$(INTDIR)\dxutil.obj" \
"$(INTDIR)\FullScreenDialog.res"
"$(OUTDIR)\fullscreendialog.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "FullScreenDialog - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\fullscreendialog.exe"
CLEAN :
-@erase "$(INTDIR)\ddutil.obj"
-@erase "$(INTDIR)\dxutil.obj"
-@erase "$(INTDIR)\FullScreenDialog.obj"
-@erase "$(INTDIR)\FullScreenDialog.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\fullscreendialog.exe"
-@erase "$(OUTDIR)\fullscreendialog.ilk"
-@erase "$(OUTDIR)\fullscreendialog.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\fullscreendialog.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\FullScreenDialog.res" /d "_DEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\fullscreendialog.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:yes /pdb:"$(OUTDIR)\fullscreendialog.pdb" /debug /machine:I386 /out:"$(OUTDIR)\fullscreendialog.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\FullScreenDialog.obj" \
"$(INTDIR)\ddutil.obj" \
"$(INTDIR)\dxutil.obj" \
"$(INTDIR)\FullScreenDialog.res"
"$(OUTDIR)\fullscreendialog.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("fullscreendialog.dep")
!INCLUDE "fullscreendialog.dep"
!ELSE
!MESSAGE Warning: cannot find "fullscreendialog.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "FullScreenDialog - Win32 Release" || "$(CFG)" == "FullScreenDialog - Win32 Debug"
SOURCE=.\FullScreenDialog.cpp
"$(INTDIR)\FullScreenDialog.obj" : $(SOURCE) "$(INTDIR)"
SOURCE=.\FullScreenDialog.rc
"$(INTDIR)\FullScreenDialog.res" : $(SOURCE) "$(INTDIR)"
$(RSC) $(RSC_PROJ) $(SOURCE)
SOURCE=..\..\common\src\ddutil.cpp
"$(INTDIR)\ddutil.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=..\..\common\src\dxutil.cpp
"$(INTDIR)\dxutil.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
!ENDIF

View File

@@ -0,0 +1,138 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include <windows.h>
#include <afxres.h>
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_MAIN ICON DISCARDABLE "DirectX.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include <windows.h>\r\n"
"#include <afxres.h>\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDR_MAIN_ACCEL ACCELERATORS DISCARDABLE
BEGIN
VK_ESCAPE, IDM_EXIT, VIRTKEY, NOINVERT
VK_F1, IDM_SHOW_DIALOG, VIRTKEY, NOINVERT
"X", IDM_EXIT, VIRTKEY, ALT, NOINVERT
END
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//
IDB_DIRECTX BITMAP DISCARDABLE "directx.bmp"
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG_SAMPLE DIALOG DISCARDABLE 0, 0, 165, 145
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Sample Dialog"
FONT 8, "MS Shell Dlg"
BEGIN
DEFPUSHBUTTON "OK",IDOK,51,124,50,14
PUSHBUTTON "Cancel",IDCANCEL,108,124,50,14
CONTROL "Radio 1",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON,15,50,
40,10
CONTROL "Radio 2",IDC_RADIO2,"Button",BS_AUTORADIOBUTTON,15,65,
40,10
CONTROL "Radio 3",IDC_RADIO3,"Button",BS_AUTORADIOBUTTON,15,80,
40,10
LTEXT "This dialog has a few types of controls to show that everything can work on a non-GDI display as it does with a GDI based display.",
IDC_STATIC,5,5,160,25
EDITTEXT IDC_EDIT1,5,105,155,14,ES_AUTOHSCROLL
COMBOBOX IDC_COMBO1,110,40,50,60,CBS_DROPDOWN | WS_VSCROLL |
WS_TABSTOP
GROUPBOX "A Group of Radio Buttons",IDC_STATIC,5,35,100,65
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_DIALOG_SAMPLE, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 158
TOPMARGIN, 7
BOTTOMMARGIN, 138
END
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1,42 @@
//-----------------------------------------------------------------------------
//
// Sample Name: FullScreenDialog Sample
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
Description
===========
FullScreenDialog demonstrates how to display a GDI dialog while using DirectDraw
in full-screen exclusive mode.
Path
====
Source: DXSDK\Samples\Multimedia\DDraw\FullScreenDialog
Executable: DXSDK\Samples\Multimedia\DDraw\Bin
User's Guide
============
FullScreenDialog requires no user input. Press the ESC key to quit the program.
Programming Notes
=================
For details on how to setup a full-screen DirectDraw app, see the FullScreenMode
sample.
If the display device supports DDCAPS2_CANRENDERWINDOWED then to make GDI write to
a DirectDraw surface, call IDirectDraw::FlipToGDISurface, then create a clipper object
which GDI uses when drawing. To display a dialog, then simply create and show it
as normal.
If the display device does not support DDCAPS2_CANRENDERWINDOWED (some secondary
graphics cards are like this) then the card does not support FlipToGDISurface.
So it is necessary instead to have GDI make a bitmap of the dialog to be drawn,
then blt this bitmap to the back buffer. However, this sample does not show how to
do this technique,

View File

@@ -0,0 +1,27 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by FullScreenDialog.rc
//
#define IDI_MAIN 101
#define IDR_MAIN_ACCEL 103
#define IDD_DIALOG_SAMPLE 106
#define IDB_DIRECTX 107
#define IDM_EXIT 1001
#define IDC_RADIO1 1003
#define IDC_RADIO2 1004
#define IDC_RADIO3 1005
#define IDC_EDIT1 1006
#define IDC_COMBO1 1007
#define IDM_SHOW_DIALOG 40001
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 108
#define _APS_NEXT_COMMAND_VALUE 40002
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 104
#endif
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,492 @@
//-----------------------------------------------------------------------------
// File: FullScreenMode.cpp
//
// Desc: This sample demonstrates how to use DirectDraw full-screen mode
// using the exclusive DirectDraw cooperative level.
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#define STRICT
#include <windows.h>
#include <ddraw.h>
#include <mmsystem.h>
#include "resource.h"
#include "ddutil.h"
//-----------------------------------------------------------------------------
// Defines, constants, and global variables
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 8
#define SPRITE_DIAMETER 48
#define NUM_SPRITES 25
#define HELPTEXT TEXT("Press Escape to quit.")
struct SPRITE_STRUCT
{
FLOAT fPosX;
FLOAT fPosY;
FLOAT fVelX;
FLOAT fVelY;
};
CDisplay* g_pDisplay = NULL;
CSurface* g_pLogoSurface = NULL;
CSurface* g_pTextSurface = NULL;
BOOL g_bActive = FALSE;
DWORD g_dwLastTick;
SPRITE_STRUCT g_Sprite[NUM_SPRITES];
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
HRESULT WinInit( HINSTANCE hInst, int nCmdShow, HWND* phWnd, HACCEL* phAccel );
HRESULT InitDirectDraw( HWND hWnd );
VOID FreeDirectDraw();
HRESULT ProcessNextFrame();
VOID UpdateSprite( SPRITE_STRUCT* pSprite, FLOAT fTimeDelta );
HRESULT DisplayFrame();
HRESULT RestoreSurfaces();
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything and calls
// UpdateFrame() when idle from the message pump.
//-----------------------------------------------------------------------------
int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int nCmdShow )
{
MSG msg;
HWND hWnd;
HACCEL hAccel;
ZeroMemory( &g_Sprite, sizeof(SPRITE_STRUCT) * NUM_SPRITES );
srand( GetTickCount() );
if( FAILED( WinInit( hInst, nCmdShow, &hWnd, &hAccel ) ) )
return FALSE;
if( FAILED( InitDirectDraw( hWnd ) ) )
{
MessageBox( hWnd, TEXT("DirectDraw init failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
g_dwLastTick = timeGetTime();
while( TRUE )
{
// Look for messages, if none are found then
// update the state and display it
if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if( 0 == GetMessage(&msg, NULL, 0, 0 ) )
{
// WM_QUIT was posted, so exit
return (int)msg.wParam;
}
// Translate and dispatch the message
if( 0 == TranslateAccelerator( hWnd, hAccel, &msg ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
else
{
if( g_bActive )
{
// Move the sprites, blt them to the back buffer, then
// flip or blt the back buffer to the primary buffer
if( FAILED( ProcessNextFrame() ) )
{
SAFE_DELETE( g_pDisplay );
MessageBox( hWnd, TEXT("Displaying the next frame failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
}
else
{
// Make sure we go to sleep if we have nothing else to do
WaitMessage();
// Ignore time spent inactive
g_dwLastTick = timeGetTime();
}
}
}
}
//-----------------------------------------------------------------------------
// Name: WinInit()
// Desc: Init the window
//-----------------------------------------------------------------------------
HRESULT WinInit( HINSTANCE hInst, int nCmdShow, HWND* phWnd, HACCEL* phAccel )
{
WNDCLASS wc;
HWND hWnd;
HACCEL hAccel;
// Register the Window Class
wc.lpszClassName = TEXT("FullScreenMode");
wc.lpfnWndProc = MainWndProc;
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInst;
wc.hIcon = LoadIcon( hInst, MAKEINTRESOURCE(IDI_MAIN) );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if( RegisterClass( &wc ) == 0 )
return E_FAIL;
// Load keyboard accelerators
hAccel = LoadAccelerators( hInst, MAKEINTRESOURCE(IDR_MAIN_ACCEL) );
// Create and show the main window
hWnd = CreateWindowEx( 0, TEXT("FullScreenMode"), TEXT("DirectDraw FullScreenMode Sample"),
WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL );
if( hWnd == NULL )
return E_FAIL;
ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );
*phWnd = hWnd;
*phAccel = hAccel;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InitDirectDraw()
// Desc: Create the DirectDraw object, and init the surfaces
//-----------------------------------------------------------------------------
HRESULT InitDirectDraw( HWND hWnd )
{
HRESULT hr;
LPDIRECTDRAWPALETTE pDDPal = NULL;
int iSprite;
g_pDisplay = new CDisplay();
if( FAILED( hr = g_pDisplay->CreateFullScreenDisplay( hWnd, SCREEN_WIDTH,
SCREEN_HEIGHT, SCREEN_BPP ) ) )
{
MessageBox( hWnd, TEXT("This display card does not support 640x480x8. "),
TEXT("DirectDraw Sample"), MB_ICONERROR | MB_OK );
return hr;
}
// Create and set the palette when in palettized color
if( FAILED( hr = g_pDisplay->CreatePaletteFromBitmap( &pDDPal, MAKEINTRESOURCE( IDB_DIRECTX ) ) ) )
return hr;
if( FAILED( hr = g_pDisplay->SetPalette( pDDPal ) ) )
return hr;
SAFE_RELEASE( pDDPal );
// Create a surface, and draw a bitmap resource on it.
if( FAILED( hr = g_pDisplay->CreateSurfaceFromBitmap( &g_pLogoSurface, MAKEINTRESOURCE( IDB_DIRECTX ),
SPRITE_DIAMETER, SPRITE_DIAMETER ) ) )
return hr;
// Create a surface, and draw text to it.
if( FAILED( hr = g_pDisplay->CreateSurfaceFromText( &g_pTextSurface, NULL, HELPTEXT,
RGB(0,0,0), RGB(255, 255, 0) ) ) )
return hr;
// Set the color key for the logo sprite to black
if( FAILED( hr = g_pLogoSurface->SetColorKey( 0 ) ) )
return hr;
// Init all the sprites. All of these sprites look the same,
// using the g_pDDSLogo surface.
for( iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
{
// Set the sprite's position and velocity
g_Sprite[iSprite].fPosX = (float) (rand() % SCREEN_WIDTH);
g_Sprite[iSprite].fPosY = (float) (rand() % SCREEN_HEIGHT);
g_Sprite[iSprite].fVelX = 500.0f * rand() / RAND_MAX - 250.0f;
g_Sprite[iSprite].fVelY = 500.0f * rand() / RAND_MAX - 250.0f;
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: FreeDirectDraw()
// Desc: Release all the DirectDraw objects
//-----------------------------------------------------------------------------
VOID FreeDirectDraw()
{
SAFE_DELETE( g_pLogoSurface );
SAFE_DELETE( g_pTextSurface );
SAFE_DELETE( g_pDisplay );
}
//-----------------------------------------------------------------------------
// Name: MainWndProc()
// Desc: The main window procedure
//-----------------------------------------------------------------------------
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch (msg)
{
case WM_COMMAND:
switch( LOWORD(wParam) )
{
case IDM_EXIT:
// Received key/menu command to exit app
PostMessage( hWnd, WM_CLOSE, 0, 0 );
return 0L;
}
break; // Continue with default processing
case WM_SETCURSOR:
// Hide the cursor in fullscreen
SetCursor( NULL );
return TRUE;
case WM_SIZE:
// Check to see if we are losing our window...
if( SIZE_MAXHIDE==wParam || SIZE_MINIMIZED==wParam )
g_bActive = FALSE;
else
g_bActive = TRUE;
if( g_pDisplay )
g_pDisplay->UpdateBounds();
break;
case WM_EXITMENULOOP:
// Ignore time spent in menu
g_dwLastTick = timeGetTime();
break;
case WM_EXITSIZEMOVE:
// Ignore time spent resizing
g_dwLastTick = timeGetTime();
break;
case WM_MOVE:
if( g_pDisplay )
g_pDisplay->UpdateBounds();
break;
case WM_SYSCOMMAND:
// Prevent moving/sizing and power loss in fullscreen mode
switch( wParam )
{
case SC_MOVE:
case SC_SIZE:
case SC_MAXIMIZE:
case SC_MONITORPOWER:
return TRUE;
}
break;
case WM_DESTROY:
// Cleanup and close the app
FreeDirectDraw();
PostQuitMessage( 0 );
return 0L;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
//-----------------------------------------------------------------------------
// Name: ProcessNextFrame()
// Desc: Move the sprites, blt them to the back buffer, then
// flips the back buffer to the primary buffer
//-----------------------------------------------------------------------------
HRESULT ProcessNextFrame()
{
HRESULT hr;
// Figure how much time has passed since the last time
DWORD dwCurrTick = timeGetTime();
DWORD dwTickDiff = dwCurrTick - g_dwLastTick;
// Don't update if no time has passed
if( dwTickDiff == 0 )
return S_OK;
g_dwLastTick = dwCurrTick;
// Move the sprites according to how much time has passed
for( int iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
UpdateSprite( &g_Sprite[ iSprite ], dwTickDiff / 1000.0f );
// Display the sprites on the screen
if( FAILED( hr = DisplayFrame() ) )
{
if( hr != DDERR_SURFACELOST )
return hr;
// The surfaces were lost so restore them
RestoreSurfaces();
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: UpdateSprite()
// Desc: Move the sprite around and make it bounce based on how much time
// has passed
//-----------------------------------------------------------------------------
VOID UpdateSprite( SPRITE_STRUCT* pSprite, FLOAT fTimeDelta )
{
// Update the sprite position
pSprite->fPosX += pSprite->fVelX * fTimeDelta;
pSprite->fPosY += pSprite->fVelY * fTimeDelta;
// Clip the position, and bounce if it hits the edge
if( pSprite->fPosX < 0.0f )
{
pSprite->fPosX = 0;
pSprite->fVelX = -pSprite->fVelX;
}
if( pSprite->fPosX >= SCREEN_WIDTH - SPRITE_DIAMETER )
{
pSprite->fPosX = SCREEN_WIDTH - 1 - SPRITE_DIAMETER;
pSprite->fVelX = -pSprite->fVelX;
}
if( pSprite->fPosY < 0 )
{
pSprite->fPosY = 0;
pSprite->fVelY = -pSprite->fVelY;
}
if( pSprite->fPosY > SCREEN_HEIGHT - SPRITE_DIAMETER )
{
pSprite->fPosY = SCREEN_HEIGHT - 1 - SPRITE_DIAMETER;
pSprite->fVelY = -pSprite->fVelY;
}
}
//-----------------------------------------------------------------------------
// Name: DisplayFrame()
// Desc: Blts a the sprites to the back buffer, then flips the
// back buffer onto the primary buffer.
//-----------------------------------------------------------------------------
HRESULT DisplayFrame()
{
HRESULT hr;
// Fill the back buffer with black, ignoring errors until the flip
g_pDisplay->Clear( 0 );
// Blt the help text on the backbuffer, ignoring errors until the flip
g_pDisplay->Blt( 10, 10, g_pTextSurface, NULL );
// Blt all the sprites onto the back buffer using color keying,
// ignoring errors until the flip. Note that all of these sprites
// use the same DirectDraw surface.
for( int iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
{
g_pDisplay->Blt( (DWORD)g_Sprite[iSprite].fPosX,
(DWORD)g_Sprite[iSprite].fPosY,
g_pLogoSurface, NULL );
}
// We are in fullscreen mode, so perform a flip and return
// any errors like DDERR_SURFACELOST
if( FAILED( hr = g_pDisplay->Present() ) )
return hr;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: RestoreSurfaces()
// Desc: Restore all the surfaces, and redraw the sprite surfaces.
//-----------------------------------------------------------------------------
HRESULT RestoreSurfaces()
{
HRESULT hr;
LPDIRECTDRAWPALETTE pDDPal = NULL;
if( FAILED( hr = g_pDisplay->GetDirectDraw()->RestoreAllSurfaces() ) )
return hr;
// No need to re-create the surface, just re-draw it.
if( FAILED( hr = g_pTextSurface->DrawText( NULL, HELPTEXT,
0, 0, RGB(0,0,0), RGB(255, 255, 0) ) ) )
return hr;
// We need to release and re-load, and set the palette again to
// redraw the bitmap on the surface. Otherwise, GDI will not
// draw the bitmap on the surface with the right palette
if( FAILED( hr = g_pDisplay->CreatePaletteFromBitmap( &pDDPal, MAKEINTRESOURCE( IDB_DIRECTX ) ) ) )
return hr;
if( FAILED( hr = g_pDisplay->SetPalette( pDDPal ) ) )
return hr;
SAFE_RELEASE( pDDPal );
// No need to re-create the surface, just re-draw it.
if( FAILED( hr = g_pLogoSurface->DrawBitmap( MAKEINTRESOURCE( IDB_DIRECTX ),
SPRITE_DIAMETER, SPRITE_DIAMETER ) ) )
return hr;
return S_OK;
}

View File

@@ -0,0 +1,143 @@
# Microsoft Developer Studio Project File - Name="FullScreenMode" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=FullScreenMode - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "fullscreenmode.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "fullscreenmode.mak" CFG="FullScreenMode - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "FullScreenMode - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "FullScreenMode - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "FullScreenMode - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir ".\Release"
# PROP BASE Intermediate_Dir ".\Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ".\Release"
# PROP Intermediate_Dir ".\Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /GX /O2 /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386 /stack:0x200000,0x200000
!ELSEIF "$(CFG)" == "FullScreenMode - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir ".\Debug"
# PROP BASE Intermediate_Dir ".\Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ".\Debug"
# PROP Intermediate_Dir ".\Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386
# ADD LINK32 winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386 /stack:0x200000,0x200000
!ENDIF
# Begin Target
# Name "FullScreenMode - Win32 Release"
# Name "FullScreenMode - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90"
# Begin Source File
SOURCE=.\FullScreenMode.cpp
# End Source File
# Begin Source File
SOURCE=.\FullScreenMode.rc
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\directx.bmp
# End Source File
# Begin Source File
SOURCE=.\DirectX.ico
# End Source File
# Begin Source File
SOURCE=.\resource.h
# End Source File
# End Group
# Begin Group "Common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\common\src\ddutil.cpp
# End Source File
# Begin Source File
SOURCE=..\..\common\include\ddutil.h
# End Source File
# Begin Source File
SOURCE=..\..\common\src\dxutil.cpp
# End Source File
# Begin Source File
SOURCE=..\..\common\include\dxutil.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "FullScreenMode"=.\fullscreenmode.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,221 @@
# Microsoft Developer Studio Generated NMAKE File, Based on fullscreenmode.dsp
!IF "$(CFG)" == ""
CFG=FullScreenMode - Win32 Release
!MESSAGE No configuration specified. Defaulting to FullScreenMode - Win32 Release.
!ENDIF
!IF "$(CFG)" != "FullScreenMode - Win32 Release" && "$(CFG)" != "FullScreenMode - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "fullscreenmode.mak" CFG="FullScreenMode - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "FullScreenMode - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "FullScreenMode - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "FullScreenMode - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\fullscreenmode.exe"
CLEAN :
-@erase "$(INTDIR)\ddutil.obj"
-@erase "$(INTDIR)\dxutil.obj"
-@erase "$(INTDIR)\FullScreenMode.obj"
-@erase "$(INTDIR)\FullScreenMode.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\fullscreenmode.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\fullscreenmode.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\FullScreenMode.res" /d "NDEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\fullscreenmode.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:no /pdb:"$(OUTDIR)\fullscreenmode.pdb" /machine:I386 /out:"$(OUTDIR)\fullscreenmode.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\FullScreenMode.obj" \
"$(INTDIR)\ddutil.obj" \
"$(INTDIR)\dxutil.obj" \
"$(INTDIR)\FullScreenMode.res"
"$(OUTDIR)\fullscreenmode.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "FullScreenMode - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\fullscreenmode.exe"
CLEAN :
-@erase "$(INTDIR)\ddutil.obj"
-@erase "$(INTDIR)\dxutil.obj"
-@erase "$(INTDIR)\FullScreenMode.obj"
-@erase "$(INTDIR)\FullScreenMode.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\fullscreenmode.exe"
-@erase "$(OUTDIR)\fullscreenmode.ilk"
-@erase "$(OUTDIR)\fullscreenmode.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\fullscreenmode.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\FullScreenMode.res" /d "_DEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\fullscreenmode.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:yes /pdb:"$(OUTDIR)\fullscreenmode.pdb" /debug /machine:I386 /out:"$(OUTDIR)\fullscreenmode.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\FullScreenMode.obj" \
"$(INTDIR)\ddutil.obj" \
"$(INTDIR)\dxutil.obj" \
"$(INTDIR)\FullScreenMode.res"
"$(OUTDIR)\fullscreenmode.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("fullscreenmode.dep")
!INCLUDE "fullscreenmode.dep"
!ELSE
!MESSAGE Warning: cannot find "fullscreenmode.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "FullScreenMode - Win32 Release" || "$(CFG)" == "FullScreenMode - Win32 Debug"
SOURCE=.\FullScreenMode.cpp
"$(INTDIR)\FullScreenMode.obj" : $(SOURCE) "$(INTDIR)"
SOURCE=.\FullScreenMode.rc
"$(INTDIR)\FullScreenMode.res" : $(SOURCE) "$(INTDIR)"
$(RSC) $(RSC_PROJ) $(SOURCE)
SOURCE=..\..\common\src\ddutil.cpp
"$(INTDIR)\ddutil.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=..\..\common\src\dxutil.cpp
"$(INTDIR)\dxutil.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
!ENDIF

View File

@@ -0,0 +1,91 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include <windows.h>
#include <afxres.h>
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_MAIN ICON DISCARDABLE "DirectX.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include <windows.h>\r\n"
"#include <afxres.h>\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDR_MAIN_ACCEL ACCELERATORS DISCARDABLE
BEGIN
VK_ESCAPE, IDM_EXIT, VIRTKEY, NOINVERT
"X", IDM_EXIT, VIRTKEY, ALT, NOINVERT
END
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//
IDB_DIRECTX BITMAP DISCARDABLE "directx.bmp"
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1,63 @@
//-----------------------------------------------------------------------------
//
// Sample Name: FullScreenMode Sample
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
Description
===========
FullScreenMode demonstrates the tasks required to initialize and run
a full-screen DirectDraw application.
Path
====
Source: DXSDK\Samples\Multimedia\DDraw\FullScreenMode
Executable: DXSDK\Samples\Multimedia\DDraw\Bin
User's Guide
============
FullScreenMode requires no user input. Press the ESC key to quit the program.
Programming Notes
=================
The basic tasks to author a simple full-screen DirectDraw application are as follows:
Initialize DirectDraw:
1. Register a window class and create a window.
2. Call DirectDrawCreateEx to create a DirectDraw object
3. Call SetCooperativeLevel to set the DirectDraw cooperative level
to exclusive and full-screen.
4. Call SetDisplayMode to set the display mode, for example 640x480x8.
5. Call CreateSurface to create a flipable primary surface with 1 back buffer.
6. Call GetAttachedSurface to obtain a pointer to the back buffer.
7. If the display mode was set to palettized color, a palette is needs
to be created. This sample displays a single bitmap so it can read the
bitmap palette info to read and create a DirectDraw palette. After a palette
is created, call SetPalette to set the palette for the primary surface.
8. Create an off-screen plain DirectDraw surface, and load media content into it.
For example, this sample calls DDUtil_CreateSurfaceFromBitmap() to do just
this.
When the app is idle, and it is not hidden or minimized then render the next
frame as follows:
1. If movement or animation is involved in the app, then calculate how much
time has passed since the last time the frame was displayed.
2. Move or animate the app state based on how much time has passed.
3. Draw the current state into the backbuffer.
4. Call Flip to flip the contents of the backbuffer into the primary surface.
If the user alt-tabs away from the app, then the DirectDraw surface may be lost
(resulting in a DirectDraw call returning DDERR_SURFACELOST), then handle it by:
1. Call RestoreAllSurfaces to have DirectDraw restore all the surfaces.
2. Restoring a surface doesn't reload any content that existed in the surface
prior to it being lost. So you must now redraw the graphics the surfaces
once held. For example, this sample handles this by calling
DDUtil_ReDrawBitmapOnDDS()

View File

@@ -0,0 +1,20 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by FullScreenMode.rc
//
#define IDI_MAIN 101
#define IDR_MAIN_ACCEL 103
#define IDB_DIRECTX 107
#define IDM_EXIT 1001
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 108
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 104
#endif
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,571 @@
//-----------------------------------------------------------------------------
// File: GammaControl.cpp
//
// Desc: This sample demonstrates how to use DirectDraw full-screen mode
// using the exclusive DirectDraw cooperative level.
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#define STRICT
#include <windows.h>
#include <ddraw.h>
#include <mmsystem.h>
#include "resource.h"
#include "ddutil.h"
//-----------------------------------------------------------------------------
// Defines, constants, and global variables
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 32
#define NUM_COLOR_BARS 63
#define HELPTEXT TEXT("Adjust the gamma level by clicking either mouse button. Press Escape to quit.")
#define GAMMATEXT TEXT("Displaying with linear gamma ramp between 0 and %0.5d")
CDisplay* g_pDisplay = NULL;
CSurface* g_pLogoSurface = NULL;
CSurface* g_pHelpTextSurface = NULL;
CSurface* g_pGammaTextSurface = NULL;
LPDIRECTDRAWGAMMACONTROL g_pGammaControl = NULL;
BOOL g_bActive = FALSE;
LONG g_lGammaRamp = 256;
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
HRESULT WinInit( HINSTANCE hInst, int nCmdShow, HWND* phWnd, HACCEL* phAccel );
HRESULT InitDirectDraw( HWND hWnd );
VOID FreeDirectDraw();
BOOL HasGammaSupport();
HRESULT UpdateGammaRamp();
HRESULT ProcessNextFrame();
HRESULT DisplayFrame();
HRESULT RestoreSurfaces();
HRESULT DrawGammaText();
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything and calls
// UpdateFrame() when idle from the message pump.
//-----------------------------------------------------------------------------
int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int nCmdShow )
{
MSG msg;
HWND hWnd;
HACCEL hAccel;
HRESULT hr;
if( FAILED( WinInit( hInst, nCmdShow, &hWnd, &hAccel ) ) )
return FALSE;
if( FAILED( InitDirectDraw( hWnd ) ) )
{
SAFE_DELETE( g_pDisplay );
MessageBox( hWnd, TEXT("DirectDraw init failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
if( HasGammaSupport() == FALSE )
{
SAFE_DELETE( g_pDisplay );
MessageBox( hWnd, TEXT("The primary surface does not support gamma control. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
if( FAILED( hr = g_pDisplay->GetFrontBuffer()->QueryInterface( IID_IDirectDrawGammaControl,
(LPVOID*) &g_pGammaControl ) ) )
{
SAFE_DELETE( g_pDisplay );
MessageBox( hWnd, TEXT("The primary surface does not support IDirectDrawGammaControl. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
while( TRUE )
{
// Look for messages, if none are found then
// update the state and display it
if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if( 0 == GetMessage(&msg, NULL, 0, 0 ) )
{
// WM_QUIT was posted, so exit
return (int)msg.wParam;
}
// Translate and dispatch the message
if( 0 == TranslateAccelerator( hWnd, hAccel, &msg ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
else
{
if( g_bActive )
{
// Move the sprites, blt them to the back buffer, then
// flip or blt the back buffer to the primary buffer
if( FAILED( ProcessNextFrame() ) )
{
SAFE_DELETE( g_pDisplay );
MessageBox( hWnd, TEXT("Displaying the next frame failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
}
else
{
// Make sure we go to sleep if we have nothing else to do
WaitMessage();
}
}
}
}
//-----------------------------------------------------------------------------
// Name: WinInit()
// Desc: Init the window
//-----------------------------------------------------------------------------
HRESULT WinInit( HINSTANCE hInst, int nCmdShow, HWND* phWnd, HACCEL* phAccel )
{
WNDCLASS wc;
HWND hWnd;
HACCEL hAccel;
// Register the Window Class
wc.lpszClassName = TEXT("GammaControl");
wc.lpfnWndProc = MainWndProc;
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInst;
wc.hIcon = LoadIcon( hInst, MAKEINTRESOURCE(IDI_MAIN) );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if( RegisterClass( &wc ) == 0 )
return E_FAIL;
// Load keyboard accelerators
hAccel = LoadAccelerators( hInst, MAKEINTRESOURCE(IDR_MAIN_ACCEL) );
// Create and show the main window
hWnd = CreateWindowEx( 0, TEXT("GammaControl"), TEXT("DirectDraw GammaControl Sample"),
WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL );
if( hWnd == NULL )
return E_FAIL;
ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );
*phWnd = hWnd;
*phAccel = hAccel;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InitDirectDraw()
// Desc: Create the DirectDraw object, and init the surfaces
//-----------------------------------------------------------------------------
HRESULT InitDirectDraw( HWND hWnd )
{
HRESULT hr;
g_pDisplay = new CDisplay();
if( FAILED( hr = g_pDisplay->CreateFullScreenDisplay( hWnd, SCREEN_WIDTH,
SCREEN_HEIGHT, SCREEN_BPP ) ) )
{
MessageBox( hWnd, TEXT("This display card does not support 640x480x8. "),
TEXT("DirectDraw Sample"), MB_ICONERROR | MB_OK );
return hr;
}
// Create a surface, and draw text to it.
if( FAILED( hr = g_pDisplay->CreateSurfaceFromText( &g_pHelpTextSurface, NULL, HELPTEXT,
RGB(0,0,0), RGB(255, 255, 0) ) ) )
return hr;
TCHAR strGammaText[256];
wsprintf( strGammaText, GAMMATEXT, g_lGammaRamp * 256 );
if( FAILED( hr = g_pDisplay->CreateSurfaceFromText( &g_pGammaTextSurface, NULL, strGammaText,
RGB(0,0,0), RGB(255, 255, 0) ) ) )
return hr;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: FreeDirectDraw()
// Desc: Release all the DirectDraw objects
//-----------------------------------------------------------------------------
VOID FreeDirectDraw()
{
SAFE_DELETE( g_pHelpTextSurface );
SAFE_DELETE( g_pGammaTextSurface );
SAFE_DELETE( g_pDisplay );
}
//-----------------------------------------------------------------------------
// Name: MainWndProc()
// Desc: The main window procedure
//-----------------------------------------------------------------------------
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch (msg)
{
case WM_LBUTTONDOWN:
g_lGammaRamp -= 8;
if( g_lGammaRamp < 0 )
g_lGammaRamp = 0;
if( FAILED( UpdateGammaRamp() ) )
{
SAFE_DELETE( g_pDisplay );
MessageBox( hWnd, TEXT("Failed setting the new gamma level. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
PostQuitMessage( 0 );
}
break;
case WM_RBUTTONDOWN:
g_lGammaRamp += 8;
if( g_lGammaRamp > 256 )
g_lGammaRamp = 256;
if( FAILED( UpdateGammaRamp() ) )
{
SAFE_DELETE( g_pDisplay );
MessageBox( hWnd, TEXT("Failed setting the new gamma level. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
PostQuitMessage( 0 );
}
break;
case WM_COMMAND:
switch( LOWORD(wParam) )
{
case IDM_EXIT:
// Received key/menu command to exit app
PostMessage( hWnd, WM_CLOSE, 0, 0 );
return 0L;
}
break; // Continue with default processing
case WM_SETCURSOR:
// Hide the cursor in fullscreen
SetCursor( NULL );
return TRUE;
case WM_SIZE:
// Check to see if we are losing our window...
if( SIZE_MAXHIDE==wParam || SIZE_MINIMIZED==wParam )
g_bActive = FALSE;
else
g_bActive = TRUE;
break;
case WM_SYSCOMMAND:
// Prevent moving/sizing and power loss in fullscreen mode
switch( wParam )
{
case SC_MOVE:
case SC_SIZE:
case SC_MAXIMIZE:
case SC_MONITORPOWER:
return TRUE;
}
break;
case WM_DESTROY:
// Cleanup and close the app
FreeDirectDraw();
PostQuitMessage( 0 );
return 0L;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
//-----------------------------------------------------------------------------
// Name: HasGammaSupport()
// Desc: Returns TRUE if the device supports gamma control, FALSE otherwise
//-----------------------------------------------------------------------------
BOOL HasGammaSupport()
{
// Get driver capabilities to determine gamma support.
DDCAPS ddcaps;
ZeroMemory( &ddcaps, sizeof(ddcaps) );
ddcaps.dwSize = sizeof(ddcaps);
g_pDisplay->GetDirectDraw()->GetCaps( &ddcaps, NULL );
// Does the driver support gamma?
// The DirectDraw emulation layer does not support overlays
// so gamma related APIs will fail without hardware support.
if( ddcaps.dwCaps2 & DDCAPS2_PRIMARYGAMMA )
return TRUE;
else
return FALSE;
}
//-----------------------------------------------------------------------------
// Name: UpdateGammaRamp()
// Desc:
//-----------------------------------------------------------------------------
HRESULT UpdateGammaRamp()
{
HRESULT hr;
DDGAMMARAMP ddgr;
WORD dwGamma;
ZeroMemory( &ddgr, sizeof(ddgr) );
if( FAILED( hr = g_pGammaControl->GetGammaRamp( 0, &ddgr ) ) )
return hr;
dwGamma = 0;
for( int iColor = 0; iColor < 256; iColor++ )
{
ddgr.red[iColor] = dwGamma;
ddgr.green[iColor] = dwGamma;
ddgr.blue[iColor] = dwGamma;
dwGamma += (WORD) g_lGammaRamp;
}
if( FAILED( hr = g_pGammaControl->SetGammaRamp( 0, &ddgr ) ) )
return hr;
if( FAILED( hr = DrawGammaText() ) )
return hr;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: ProcessNextFrame()
// Desc: Move the sprites, blt them to the back buffer, then
// flips the back buffer to the primary buffer
//-----------------------------------------------------------------------------
HRESULT ProcessNextFrame()
{
HRESULT hr;
// Display the sprites on the screen
if( FAILED( hr = DisplayFrame() ) )
{
if( hr != DDERR_SURFACELOST )
return hr;
// The surfaces were lost so restore them
RestoreSurfaces();
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DisplayFrame()
// Desc: Blts a the color bars to the back buffer, then flips the
// back buffer onto the primary buffer.
//-----------------------------------------------------------------------------
HRESULT DisplayFrame()
{
DDSURFACEDESC2 ddsd;
HRESULT hr;
DDBLTFX ddbltfx;
RECT rctDest;
DWORD dwRShift;
DWORD dwGShift;
DWORD dwBShift;
DWORD dwRColorLevels;
DWORD dwGColorLevels;
DWORD dwBColorLevels;
DWORD dwBits;
DWORD dwColor;
LPDIRECTDRAWSURFACE7 pFrontBuffer;
LPDIRECTDRAWSURFACE7 pBackBuffer;
pFrontBuffer = g_pDisplay->GetFrontBuffer();
pBackBuffer = g_pDisplay->GetBackBuffer();
ZeroMemory( &ddsd,sizeof(ddsd) );
ddsd.dwSize = sizeof(ddsd);
if( FAILED( hr = pFrontBuffer->GetSurfaceDesc( &ddsd ) ) )
return hr;
// Fill the back buffer with black, ignoring errors until the flip
g_pDisplay->Clear(0);
CSurface::GetBitMaskInfo( ddsd.ddpfPixelFormat.dwRBitMask, &dwRShift, &dwBits );
CSurface::GetBitMaskInfo( ddsd.ddpfPixelFormat.dwGBitMask, &dwGShift, &dwBits );
CSurface::GetBitMaskInfo( ddsd.ddpfPixelFormat.dwBBitMask, &dwBShift, &dwBits );
dwRColorLevels = ddsd.ddpfPixelFormat.dwRBitMask >> dwRShift;
dwGColorLevels = ddsd.ddpfPixelFormat.dwGBitMask >> dwGShift;
dwBColorLevels = ddsd.ddpfPixelFormat.dwBBitMask >> dwBShift;
ZeroMemory( &ddbltfx, sizeof(ddbltfx) );
ddbltfx.dwSize = sizeof(ddbltfx);
for( DWORD i = 0; i <= NUM_COLOR_BARS; i++ )
{
rctDest.left = SCREEN_WIDTH / (NUM_COLOR_BARS + 1) * (i + 0);
rctDest.right = SCREEN_WIDTH / (NUM_COLOR_BARS + 1) * (i + 1);
// Figure out the color for the red color bar
dwColor = (DWORD) ( dwRColorLevels * i / (float) NUM_COLOR_BARS );
ddbltfx.dwFillColor = dwColor << dwRShift;
rctDest.top = SCREEN_HEIGHT / 3 * 0;
rctDest.bottom = SCREEN_HEIGHT / 3 * 1;
pBackBuffer->Blt( &rctDest, NULL, NULL,
DDBLT_COLORFILL | DDBLT_WAIT,
&ddbltfx );
// Figure out the color for the green color bar
dwColor = (DWORD) ( dwGColorLevels * i / (float) NUM_COLOR_BARS );
ddbltfx.dwFillColor = dwColor << dwGShift;
rctDest.top = SCREEN_HEIGHT / 3 * 1;
rctDest.bottom = SCREEN_HEIGHT / 3 * 2;
pBackBuffer->Blt( &rctDest, NULL, NULL,
DDBLT_COLORFILL | DDBLT_WAIT,
&ddbltfx );
// Figure out the color for the blue color bar
dwColor = (DWORD) ( dwBColorLevels * i / (float) NUM_COLOR_BARS );
ddbltfx.dwFillColor = dwColor << dwBShift;
rctDest.top = SCREEN_HEIGHT / 3 * 2;
rctDest.bottom = SCREEN_HEIGHT / 3 * 3;
pBackBuffer->Blt( &rctDest, NULL, NULL,
DDBLT_COLORFILL | DDBLT_WAIT,
&ddbltfx );
}
// Blt the help text on the backbuffer, ignoring errors until the flip
g_pDisplay->Blt( 10, 10, g_pHelpTextSurface, NULL );
g_pDisplay->Blt( 10, 30, g_pGammaTextSurface, NULL );
// We are in fullscreen mode, so perform a flip and return
// any errors like DDERR_SURFACELOST
if( FAILED( hr = g_pDisplay->Present() ) )
return hr;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: RestoreSurfaces()
// Desc: Restore all the surfaces, and redraw the sprite surfaces.
//-----------------------------------------------------------------------------
HRESULT RestoreSurfaces()
{
HRESULT hr;
if( FAILED( hr = g_pDisplay->GetDirectDraw()->RestoreAllSurfaces() ) )
return hr;
// No need to re-create the surface, just re-draw it.
if( FAILED( hr = g_pHelpTextSurface->DrawText( NULL, HELPTEXT,
0, 0, RGB(0,0,0), RGB(255, 255, 0) ) ) )
return hr;
DrawGammaText();
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DrawGammaText()
// Desc:
//-----------------------------------------------------------------------------
HRESULT DrawGammaText()
{
HRESULT hr;
TCHAR strGammaText[256];
wsprintf( strGammaText, GAMMATEXT, g_lGammaRamp * 256 );
if( FAILED( hr = g_pGammaTextSurface->DrawText( NULL, strGammaText,
0, 0, RGB(0,0,0), RGB(255, 255, 0) ) ) )
return hr;
return S_OK;
}

View File

@@ -0,0 +1,143 @@
# Microsoft Developer Studio Project File - Name="GammaControl" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=GammaControl - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "gammacontrol.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "gammacontrol.mak" CFG="GammaControl - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "GammaControl - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "GammaControl - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "GammaControl - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir ".\Release"
# PROP BASE Intermediate_Dir ".\Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ".\Release"
# PROP Intermediate_Dir ".\Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /GX /O2 /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386 /stack:0x200000,0x200000
!ELSEIF "$(CFG)" == "GammaControl - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir ".\Debug"
# PROP BASE Intermediate_Dir ".\Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ".\Debug"
# PROP Intermediate_Dir ".\Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386
# ADD LINK32 winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386 /stack:0x200000,0x200000
!ENDIF
# Begin Target
# Name "GammaControl - Win32 Release"
# Name "GammaControl - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90"
# Begin Source File
SOURCE=.\GammaControl.cpp
# End Source File
# Begin Source File
SOURCE=.\GammaControl.rc
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\directx.bmp
# End Source File
# Begin Source File
SOURCE=.\DirectX.ico
# End Source File
# Begin Source File
SOURCE=.\resource.h
# End Source File
# End Group
# Begin Group "Common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\common\src\ddutil.cpp
# End Source File
# Begin Source File
SOURCE=..\..\common\include\ddutil.h
# End Source File
# Begin Source File
SOURCE=..\..\common\src\dxutil.cpp
# End Source File
# Begin Source File
SOURCE=..\..\common\include\dxutil.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "GammaControl"=.\gammacontrol.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,221 @@
# Microsoft Developer Studio Generated NMAKE File, Based on gammacontrol.dsp
!IF "$(CFG)" == ""
CFG=GammaControl - Win32 Release
!MESSAGE No configuration specified. Defaulting to GammaControl - Win32 Release.
!ENDIF
!IF "$(CFG)" != "GammaControl - Win32 Release" && "$(CFG)" != "GammaControl - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "gammacontrol.mak" CFG="GammaControl - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "GammaControl - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "GammaControl - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "GammaControl - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\gammacontrol.exe"
CLEAN :
-@erase "$(INTDIR)\ddutil.obj"
-@erase "$(INTDIR)\dxutil.obj"
-@erase "$(INTDIR)\GammaControl.obj"
-@erase "$(INTDIR)\GammaControl.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\gammacontrol.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\gammacontrol.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\GammaControl.res" /d "NDEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\gammacontrol.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:no /pdb:"$(OUTDIR)\gammacontrol.pdb" /machine:I386 /out:"$(OUTDIR)\gammacontrol.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\GammaControl.obj" \
"$(INTDIR)\ddutil.obj" \
"$(INTDIR)\dxutil.obj" \
"$(INTDIR)\GammaControl.res"
"$(OUTDIR)\gammacontrol.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "GammaControl - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\gammacontrol.exe"
CLEAN :
-@erase "$(INTDIR)\ddutil.obj"
-@erase "$(INTDIR)\dxutil.obj"
-@erase "$(INTDIR)\GammaControl.obj"
-@erase "$(INTDIR)\GammaControl.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\gammacontrol.exe"
-@erase "$(OUTDIR)\gammacontrol.ilk"
-@erase "$(OUTDIR)\gammacontrol.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\gammacontrol.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\GammaControl.res" /d "_DEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\gammacontrol.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:yes /pdb:"$(OUTDIR)\gammacontrol.pdb" /debug /machine:I386 /out:"$(OUTDIR)\gammacontrol.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\GammaControl.obj" \
"$(INTDIR)\ddutil.obj" \
"$(INTDIR)\dxutil.obj" \
"$(INTDIR)\GammaControl.res"
"$(OUTDIR)\gammacontrol.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("gammacontrol.dep")
!INCLUDE "gammacontrol.dep"
!ELSE
!MESSAGE Warning: cannot find "gammacontrol.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "GammaControl - Win32 Release" || "$(CFG)" == "GammaControl - Win32 Debug"
SOURCE=.\GammaControl.cpp
"$(INTDIR)\GammaControl.obj" : $(SOURCE) "$(INTDIR)"
SOURCE=.\GammaControl.rc
"$(INTDIR)\GammaControl.res" : $(SOURCE) "$(INTDIR)"
$(RSC) $(RSC_PROJ) $(SOURCE)
SOURCE=..\..\common\src\ddutil.cpp
"$(INTDIR)\ddutil.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=..\..\common\src\dxutil.cpp
"$(INTDIR)\dxutil.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
!ENDIF

View File

@@ -0,0 +1,84 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include <windows.h>
#include <afxres.h>
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_MAIN ICON DISCARDABLE "DirectX.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include <windows.h>\r\n"
"#include <afxres.h>\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDR_MAIN_ACCEL ACCELERATORS DISCARDABLE
BEGIN
VK_ESCAPE, IDM_EXIT, VIRTKEY, NOINVERT
"X", IDM_EXIT, VIRTKEY, ALT, NOINVERT
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1,40 @@
//-----------------------------------------------------------------------------
//
// Sample Name: GammaControl Sample
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
Description
===========
GammaControl demonstrates how to use IDirectDrawGammaControl to adjust
how bright the system displays the DirectDraw surface.
Path
====
Source: DXSDK\Samples\Multimedia\DDraw\GammaControl
Executable: DXSDK\Samples\Multimedia\DDraw\Bin
User's Guide
============
Click the left mouse button to decrease the gamma ramp or the right mouse button
to increase it. Press the ESC key to quit the program.
Programming Notes
=================
For details on how to setup a full-screen DirectDraw app, see the FullScreenMode
sample.
To adjust the gamma, first check to see if the device supports it. Call
IDirectDraw::GetCaps to check if DDCAPS2_PRIMARYGAMMA is set. If it is, then
you can set the gamma ramp by calling IDirectDrawGammaControl::SetGammaRamp.
For simplicity this sample creates a gamma ramp which is linear for all
color components. The ramp runs from 0 at index 0 linearly up to a user
defined number at index 255 for each of the color components. However, the ramp
does not need to be linear.

View File

@@ -0,0 +1,20 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by GammaControl.rc
//
#define IDI_MAIN 101
#define IDR_MAIN_ACCEL 103
#define IDB_DIRECTX 107
#define IDM_EXIT 1001
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 108
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 104
#endif
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@@ -0,0 +1,965 @@
//-----------------------------------------------------------------------------
// File: Multimon.cpp
//
// Desc: This sample demonstrates the following programming concepts:
// Writing code for a multi-monitor program that works on both Windows 95
// (which does not support multiple monitors) and later Windows versions
// (which do support it).
// Using DirectDrawEnumerateEx to enumerate displays.
// Working with separate device and focus windows.
// Creating a video-memory sprite that spans multiple screens using multiple
// copies of the image data.
// Creating a system-memory sprite that spans multiple screens using a shared
// copy of the image data.
//
// Copyright (c) 1998-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
// Multimon.h implements support of the multimon APIs for when your program
// runs on Windows 95 systems. You can #include multimon.h in all your source
// files that use multimon APIs, and you should #define COMPILE_MULTIMON_STUBS
// in only one of your source files.
#define COMPILE_MULTIMON_STUBS
#include <windows.h>
#include <multimon.h>
#include <ddraw.h>
#include "resource.h"
//-----------------------------------------------------------------------------
// Defines, constants, and global variables
//-----------------------------------------------------------------------------
#define NAME TEXT("MultiMon DirectDraw Sample")
#define TITLE TEXT("MultiMon DirectDraw Sample")
// An EnumInfo contains extra enumeration information that is passed
// into the the DDEnumCallbackEx function.
struct EnumInfo
{
BOOL bMultimonSupported;
HRESULT hr;
};
// A Screen represents one display that images can be drawn to.
struct Screen
{
GUID guid;
TCHAR szDesc[200];
HMONITOR hmon;
LPDIRECTDRAW7 pDD;
LPDIRECTDRAWSURFACE7 pDDSFront;
LPDIRECTDRAWSURFACE7 pDDSBack;
Screen* pScreenNext; // For linked list
};
// A ScreenSurface holds a DirectDrawSurface that can be used on a
// particular screen.
struct ScreenSurface
{
Screen* pScreen;
LPDIRECTDRAWSURFACE7 pDDS;
ScreenSurface* pScreenSurfaceNext; // For linked list
// Could add a "last used time" field, which could be used to
// determine whether this ScreenSurface should be
// removed to free up video memory for another surface
};
// A Sprite holds generic information about a drawable image, and
// a linked list of ScreenSurfaces (one per screen).
struct Sprite
{
TCHAR szName[64]; // Name of this Sprite
BOOL bForceSystem; // If TRUE, don't try to create video memory surfaces
RECT rcSrc; // Dimensions of the image
RECT rcDest; // Destination rectangle to draw image into
LONG xVel; // X-Velocity for animation
LONG yVel; // Y-Velocity for animation
HBITMAP hbmImage; // Loaded bitmap image
BYTE* pImageData; // Sharable pointer to DD surface data
DDSURFACEDESC2 ddsd; // Holds pitch and pixel format of pImageData
ScreenSurface* pScreenSurfaceFirst; // Linked list of ScreenSurfaces
};
Screen* g_pScreenFirst = NULL; // Linked list of Screens
Sprite* g_pSprite1 = NULL; // A sprite that uses video memory where possible
Sprite* g_pSprite2 = NULL; // A sprite that always uses system memory
HWND g_hWnd = NULL; // Main app focus HWND
BOOL g_bActive = TRUE; // Whether app is actively drawing
//-----------------------------------------------------------------------------
// Function prototypes
//-----------------------------------------------------------------------------
INT APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, INT nCmdShow );
HRESULT CreateFocusWindow( HINSTANCE hInstance );
HRESULT EnumerateScreens( VOID );
BOOL WINAPI DDEnumCallback( GUID* pGuid, LPTSTR pszDesc, LPTSTR pszDriverName, VOID* pContext );
BOOL WINAPI DDEnumCallbackEx( GUID* pGuid, LPTSTR pszDesc, LPTSTR pszDriverName, VOID* pContext, HMONITOR hmon );
HRESULT InitScreens( VOID );
HRESULT InitSprites( VOID );
HRESULT MainLoop( VOID );
LRESULT CALLBACK WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
VOID UpdateFrame( VOID );
BOOL RectIntersectsMonitor( RECT* prcSrc, HMONITOR hmon, RECT* prcScreen );
HRESULT FindOrBuildScreenSurface( Sprite* pSprite, Screen* pScreen, ScreenSurface** ppScreenSurface );
HRESULT SetupScreenSurfaceDDS( Sprite* pSprite, ScreenSurface* pScreenSurface );
VOID DestroyScreenSurfaces( Sprite* pSprite );
VOID Cleanup( VOID );
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Initializes the application, then starts the main application loop.
//-----------------------------------------------------------------------------
INT APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, INT nCmdShow )
{
HRESULT hr;
if( FAILED( hr = CreateFocusWindow(hInst) ) )
return 0;
if( FAILED( hr = EnumerateScreens() ) )
return 0;
if( FAILED( hr = InitScreens() ) )
return 0;
if( FAILED( hr = InitSprites() ) )
return 0;
if( FAILED( hr = MainLoop() ) )
return 0;
return 0;
}
//-----------------------------------------------------------------------------
// Name: CreateFocusWindow()
// Desc: Creates the focus window, which is the window which will receive user
// input.
//-----------------------------------------------------------------------------
HRESULT CreateFocusWindow( HINSTANCE hInstance )
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE(IDI_ICON1) );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = NAME;
RegisterClass( &wc );
// Window style and dimensions are not important,
// since they will be adjusted elsewhere.
g_hWnd = CreateWindowEx( 0, NAME, TITLE, 0, 0, 0, 0, 0,
NULL, NULL, hInstance, NULL );
// It is important to call ShowWindow on this window to ensure
// that any activity from other windows is obscured.
ShowWindow( g_hWnd, SW_SHOW );
if( g_hWnd == NULL )
return E_FAIL;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: EnumerateScreens()
// Desc: Creates a Screen structure for every appropriate screen in the user's
// computer.
//-----------------------------------------------------------------------------
HRESULT EnumerateScreens()
{
HRESULT hr;
EnumInfo enumInfo;
ZeroMemory( &enumInfo, sizeof(enumInfo) );
enumInfo.bMultimonSupported = TRUE;
if( FAILED( hr = DirectDrawEnumerateEx( DDEnumCallbackEx,
&enumInfo,
DDENUM_ATTACHEDSECONDARYDEVICES ) ) )
return hr;
// If something failed inside the enumeration, be sure to return that HRESULT
if( FAILED(enumInfo.hr) )
return enumInfo.hr;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DDEnumCallbackEx()
// Desc: This callback function is called by DirectDraw once for each
// available DirectDraw device. In this implementation, it saves the
// GUID, device description, and hmon in a Screen structure for later use.
//-----------------------------------------------------------------------------
BOOL WINAPI DDEnumCallbackEx( GUID* pGuid, LPTSTR pszDesc, LPTSTR pszDriverName,
VOID* pContext, HMONITOR hmon )
{
Screen* pScreenNew;
EnumInfo* pEnumInfo = (EnumInfo*)pContext;
GUID guidNull;
ZeroMemory( &guidNull, sizeof(GUID) );
if( g_pScreenFirst != NULL &&
g_pScreenFirst->guid == guidNull )
{
// We must be running on a multimon system, so get rid of the
// guidNull Screen -- we want Screens with specific GUIDs.
delete g_pScreenFirst;
g_pScreenFirst = NULL;
}
// Store all the info in a Screen structure
pScreenNew = new Screen;
if( pScreenNew == NULL )
{
pEnumInfo->hr = E_OUTOFMEMORY;
return FALSE; // fatal error, stop enumerating
}
ZeroMemory( pScreenNew, sizeof(Screen) );
if( pGuid == NULL )
pScreenNew->guid = guidNull;
else
pScreenNew->guid = *pGuid;
lstrcpy( pScreenNew->szDesc, pszDesc );
pScreenNew->hmon = hmon;
// Insert Screen into global linked list
if( g_pScreenFirst == NULL )
{
g_pScreenFirst = pScreenNew;
}
else
{
// Insert at end of list
Screen* pScreen = g_pScreenFirst;
while( pScreen->pScreenNext != NULL )
pScreen = pScreen->pScreenNext;
pScreen->pScreenNext = pScreenNew;
}
return TRUE; // Keep enumerating
}
//-----------------------------------------------------------------------------
// Name: InitScreens()
// Desc: For each Screen, this function initializes DirectDraw and sets up the
// front buffer, back buffer, and a clipper. Many fullscreen DirectDraw
// programs don't need to create clippers, but this one does so to allow
// the sprites to be automatically clipped to each display.
//-----------------------------------------------------------------------------
HRESULT InitScreens( VOID )
{
HRESULT hr;
Screen* pScreen = NULL;
GUID* pGuid = NULL;
DWORD dwFlags;
DDSURFACEDESC2 ddsd;
LPDIRECTDRAWCLIPPER pClip = NULL;
DDSCAPS2 ddsCaps;
RECT rc;
HRGN hrgn;
BYTE rgnDataBuffer[1024];
GUID guidNull;
ZeroMemory( &guidNull, sizeof(GUID) );
for( pScreen = g_pScreenFirst; pScreen != NULL; pScreen = pScreen->pScreenNext )
{
if( pScreen->guid == guidNull )
pGuid = NULL;
else
pGuid = &pScreen->guid;
if( FAILED(hr = DirectDrawCreateEx( pGuid, (VOID**) &(pScreen->pDD),
IID_IDirectDraw7, NULL ) ) )
return hr;
if( pScreen == g_pScreenFirst)
{
dwFlags = DDSCL_SETFOCUSWINDOW;
if( FAILED( hr = pScreen->pDD->SetCooperativeLevel( g_hWnd, dwFlags ) ) )
return hr;
dwFlags = DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
if( FAILED( hr = pScreen->pDD->SetCooperativeLevel(g_hWnd, dwFlags ) ) )
return hr;
}
else
{
dwFlags = DDSCL_SETFOCUSWINDOW | DDSCL_CREATEDEVICEWINDOW |
DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
if( FAILED( hr = pScreen->pDD->SetCooperativeLevel(g_hWnd, dwFlags ) ) )
return hr;
}
if( FAILED( hr = pScreen->pDD->SetDisplayMode( 640, 480, 16, 0, 0 ) ) )
return hr;
}
// Note: It is recommended that programs call SetDisplayMode on all screens
// before creating/acquiring any DirectDrawSurfaces.
for( pScreen = g_pScreenFirst; pScreen != NULL; pScreen = pScreen->pScreenNext )
{
ZeroMemory( &ddsd, sizeof(ddsd) );
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_BACKBUFFERCOUNT | DDSD_CAPS;
ddsd.dwBackBufferCount = 1;
ddsd.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_PRIMARYSURFACE;
if( FAILED( hr = pScreen->pDD->CreateSurface( &ddsd,
&pScreen->pDDSFront, NULL ) ) )
{
return hr;
}
ZeroMemory( &ddsCaps, sizeof(ddsCaps) );
ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
if( FAILED( hr = pScreen->pDDSFront->GetAttachedSurface( &ddsCaps,
&pScreen->pDDSBack ) ) )
return hr;
ZeroMemory( &ddsd, sizeof(ddsd) );
ddsd.dwSize = sizeof(ddsd);
if( FAILED( hr = pScreen->pDDSFront->GetSurfaceDesc( &ddsd ) ) )
return hr;
SetRect( &rc, 0, 0, ddsd.dwWidth, ddsd.dwHeight );
hrgn = CreateRectRgn( 0, 0, ddsd.dwWidth, ddsd.dwHeight );
GetRegionData( hrgn, sizeof(rgnDataBuffer), (RGNDATA*)rgnDataBuffer );
DeleteObject( hrgn );
if( FAILED( hr = pScreen->pDD->CreateClipper( 0, &pClip, 0 ) ) )
return hr;
if( FAILED( hr = pClip->SetClipList( (RGNDATA*)rgnDataBuffer, 0 ) ) )
{
pClip->Release();
return hr;
}
if( FAILED( hr = pScreen->pDDSFront->SetClipper( pClip ) ) )
{
pClip->Release();
return hr;
}
if( FAILED( hr = pScreen->pDDSBack->SetClipper( pClip ) ) )
{
pClip->Release();
return hr;
}
pClip->Release();
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InitSprites()
// Desc: Initializes the objects that will be drawn and animated. Note that
// the ScreenSurfaces are created when they are first needed, not here.
//-----------------------------------------------------------------------------
HRESULT InitSprites( VOID )
{
BITMAP bm;
// Initialize the first Sprite. This sprite will try to use video memory
// on each Screen.
g_pSprite1 = new Sprite;
if( g_pSprite1 == NULL )
return E_OUTOFMEMORY;
ZeroMemory( g_pSprite1, sizeof(Sprite) );
lstrcpy( g_pSprite1->szName, TEXT("Sprite 1") );
g_pSprite1->bForceSystem = FALSE; // This sprite will try to use video memory
g_pSprite1->hbmImage = (HBITMAP) LoadImage( GetModuleHandle(NULL),
MAKEINTRESOURCE(IDB_BITMAP1),
IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION );
if( g_pSprite1->hbmImage == NULL )
return E_FAIL;
GetObject( g_pSprite1->hbmImage, sizeof(bm), &bm ); // get size of bitmap
SetRect( &g_pSprite1->rcSrc, 0, 0, bm.bmWidth, bm.bmHeight );
g_pSprite1->rcDest = g_pSprite1->rcSrc;
g_pSprite1->xVel = 2; // Animation velocity
g_pSprite1->yVel = 1;
// Initialize the second Sprite. This sprite will use system memory (and
// share that memory between ScreenSurfaces whenever possible).
g_pSprite2 = new Sprite;
if( g_pSprite2 == NULL )
return E_OUTOFMEMORY;
ZeroMemory( g_pSprite2, sizeof(Sprite) );
lstrcpy(g_pSprite2->szName, TEXT("Sprite 2"));
g_pSprite2->bForceSystem = TRUE; // This sprite will always use system memory
g_pSprite2->hbmImage = (HBITMAP) LoadImage( GetModuleHandle(NULL),
MAKEINTRESOURCE(IDB_BITMAP2),
IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION );
if( g_pSprite2->hbmImage == NULL )
return E_FAIL;
GetObject( g_pSprite2->hbmImage, sizeof(bm), &bm ); // get size of bitmap
SetRect( &g_pSprite2->rcSrc, 0, 0, bm.bmWidth, bm.bmHeight );
g_pSprite2->rcDest = g_pSprite1->rcSrc;
g_pSprite2->xVel = -1; // Animation velocity
g_pSprite2->yVel = -2;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: MainLoop()
// Desc: The main window message pump. When the application is active (not
// minimized), it uses PeekMessage so that UpdateFrame can be called
// frequently once all window messages are handled. When it is not
// active, GetMessage is used instead to give more processing time to
// other running programs.
//-----------------------------------------------------------------------------
HRESULT MainLoop( VOID )
{
MSG msg;
BOOL bGotMsg;
while( TRUE )
{
if( g_bActive)
bGotMsg = PeekMessage( &msg, NULL, 0, 0, PM_REMOVE );
else
bGotMsg = GetMessage( &msg, NULL, 0, 0);
if( msg.message == WM_QUIT)
return S_OK;
if( bGotMsg)
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else if( g_bActive)
{
UpdateFrame();
}
}
}
//-----------------------------------------------------------------------------
// Name: WindowProc()
// Desc: Handler for window messages.
//-----------------------------------------------------------------------------
LRESULT CALLBACK WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch(uMsg)
{
case WM_SIZE:
if( SIZE_MAXHIDE == wParam || SIZE_MINIMIZED == wParam )
{
g_bActive = FALSE;
// Give window an icon and system menu on the taskbar when minimized
SetWindowLong(hWnd, GWL_STYLE, WS_SYSMENU);
}
else
{
g_bActive = TRUE;
// Remove any window "decoration" when fullscreen
SetWindowLong(hWnd, GWL_STYLE, WS_POPUP);
}
return DefWindowProc( hWnd, uMsg, wParam, lParam );
case WM_CLOSE:
return DefWindowProc( hWnd, uMsg, wParam, lParam );
case WM_CHAR:
DestroyWindow( hWnd );
return 0;
case WM_DESTROY:
Cleanup();
PostQuitMessage( 0 );
return 0;
default:
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
}
//-----------------------------------------------------------------------------
// Name: UpdateFrame()
// Desc: Renders one frame of animation, then updates the sprites for the next
// frame.
//-----------------------------------------------------------------------------
VOID UpdateFrame( VOID )
{
HRESULT hr;
Screen* pScreen;
RECT rcScreen;
ScreenSurface* pScreenSurface;
DDBLTFX ddbltfx;
for( pScreen = g_pScreenFirst; pScreen != NULL; pScreen = pScreen->pScreenNext )
{
// Handle lost surfaces
if( pScreen->pDDSFront->IsLost() == DDERR_SURFACELOST )
{
// Though surface memory can be reaquired via RestoreAllSurfaces, the
// image contents will be undefined. So we destroy all the ScreenSurfaces
// and let them be recreated as needed. Calling RestoreAllSurfaces
// takes care of the remaining surfaces (the front and back buffers).
DestroyScreenSurfaces( g_pSprite1 );
DestroyScreenSurfaces( g_pSprite2 );
hr = pScreen->pDD->RestoreAllSurfaces();
}
// Clear the back buffer for this Screen
ZeroMemory( &ddbltfx, sizeof(ddbltfx) );
ddbltfx.dwSize = sizeof(ddbltfx);
ddbltfx.dwFillColor = 0; // Black
hr = pScreen->pDDSBack->Blt( NULL, NULL, NULL,
DDBLT_COLORFILL | DDBLT_WAIT,
&ddbltfx );
// Draw first sprite
if( RectIntersectsMonitor( &g_pSprite1->rcDest, pScreen->hmon, &rcScreen ) )
{
hr = FindOrBuildScreenSurface( g_pSprite1, pScreen, &pScreenSurface );
if( SUCCEEDED(hr) )
{
hr = pScreen->pDDSBack->Blt( &rcScreen, pScreenSurface->pDDS,
&g_pSprite1->rcSrc,
DDBLT_WAIT, NULL );
}
}
// Draw second sprite
if( RectIntersectsMonitor( &g_pSprite2->rcDest, pScreen->hmon, &rcScreen ) )
{
hr = FindOrBuildScreenSurface( g_pSprite2, pScreen, &pScreenSurface );
if( SUCCEEDED( hr ) )
{
hr = pScreen->pDDSBack->Blt( &rcScreen, pScreenSurface->pDDS,
&g_pSprite2->rcSrc, DDBLT_WAIT, NULL );
}
}
}
// Flip all screens. This is done in a separate loop to make the flips happen
// as close together in time as possible
for( pScreen = g_pScreenFirst; pScreen != NULL; pScreen = pScreen->pScreenNext )
{
hr = pScreen->pDDSFront->Flip( NULL, DDFLIP_WAIT );
}
// Animate Sprites for the next frame. The sprites are bounced against the
// virtual desktop, which may cause them to partially or totally disappear
// if your screens are set up in a way that is non-rectangular. Since the
// animation is not the purpose of this demo, this simplified approach is used.
RECT rcDesktop;
rcDesktop.left = GetSystemMetrics(SM_XVIRTUALSCREEN);
rcDesktop.right = rcDesktop.left + GetSystemMetrics(SM_CXVIRTUALSCREEN);
rcDesktop.top = GetSystemMetrics(SM_YVIRTUALSCREEN);
rcDesktop.bottom = rcDesktop.top + GetSystemMetrics(SM_CYVIRTUALSCREEN);
// Animate first sprite
OffsetRect( &g_pSprite1->rcDest, g_pSprite1->xVel, g_pSprite1->yVel );
if( ( g_pSprite1->rcDest.right > rcDesktop.right && g_pSprite1->xVel > 0 ) ||
( g_pSprite1->rcDest.left < rcDesktop.left && g_pSprite1->xVel < 0 ) )
{
g_pSprite1->xVel = -g_pSprite1->xVel;
}
if( ( g_pSprite1->rcDest.bottom > rcDesktop.bottom && g_pSprite1->yVel > 0 ) ||
( g_pSprite1->rcDest.top < rcDesktop.top && g_pSprite1->yVel < 0 ) )
{
g_pSprite1->yVel = -g_pSprite1->yVel;
}
// Animate second sprite
OffsetRect( &g_pSprite2->rcDest, g_pSprite2->xVel, g_pSprite2->yVel );
if( ( g_pSprite2->rcDest.right > rcDesktop.right && g_pSprite2->xVel > 0 ) ||
( g_pSprite2->rcDest.left < rcDesktop.left && g_pSprite2->xVel < 0 ) )
{
g_pSprite2->xVel = -g_pSprite2->xVel;
}
if( ( g_pSprite2->rcDest.bottom > rcDesktop.bottom && g_pSprite2->yVel > 0 ) ||
( g_pSprite2->rcDest.top < rcDesktop.top && g_pSprite2->yVel < 0 ) )
{
g_pSprite2->yVel = -g_pSprite2->yVel;
}
}
//-----------------------------------------------------------------------------
// Name: RectIntersectsMonitor()
// Desc: Returns TRUE if prcSrc intersects the monitor hmon, and uses prcScreen
// to store prcSrc in that monitor's local coordinate system.
//-----------------------------------------------------------------------------
BOOL RectIntersectsMonitor( RECT* prcSrc, HMONITOR hmon, RECT* prcScreen )
{
MONITORINFO mi;
RECT rcIntersection;
BOOL bIntersects;
ZeroMemory( &mi, sizeof(mi) );
mi.cbSize = sizeof(mi);
if( hmon == NULL )
{
SetRect( &mi.rcMonitor, 0, 0, GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN) );
}
else
{
GetMonitorInfo(hmon, &mi);
}
bIntersects = IntersectRect( &rcIntersection, prcSrc, &mi.rcMonitor );
if( !bIntersects)
return FALSE;
*prcScreen = *prcSrc;
OffsetRect( prcScreen, -mi.rcMonitor.left, -mi.rcMonitor.top );
return TRUE;
}
//-----------------------------------------------------------------------------
// Name: FindOrBuildScreenSurface()
// Desc: This is called when UpdateFrame needs to draw the image of a Sprite
// onto a particular Screen. If a ScreenSurface already exists for this
// Screen and Sprite, a pointer to it is returned. Otherwise, a new
// ScreenSurface is created (and stored for future reuse).
//-----------------------------------------------------------------------------
HRESULT FindOrBuildScreenSurface( Sprite* pSprite, Screen* pScreen,
ScreenSurface** ppScreenSurface )
{
HRESULT hr;
ScreenSurface* pScreenSurface;
for( pScreenSurface = pSprite->pScreenSurfaceFirst;
pScreenSurface != NULL;
pScreenSurface = pScreenSurface->pScreenSurfaceNext )
{
if( pScreenSurface->pScreen == pScreen )
{
// ScreenSurface exists for this Screen, so return a pointer to it
*ppScreenSurface = pScreenSurface;
return S_OK;
}
}
// No ScreenSurface for this Screen exists yet, so build one.
pScreenSurface = new ScreenSurface;
if( pScreenSurface == NULL )
return E_OUTOFMEMORY;
ZeroMemory( pScreenSurface, sizeof(ScreenSurface) );
pScreenSurface->pScreen = pScreen;
if( FAILED( hr = SetupScreenSurfaceDDS(pSprite, pScreenSurface ) ) )
{
delete pScreenSurface;
return hr;
}
// Insert this new ScreenSurface in the Sprite's list:
pScreenSurface->pScreenSurfaceNext = pSprite->pScreenSurfaceFirst;
pSprite->pScreenSurfaceFirst = pScreenSurface;
*ppScreenSurface = pScreenSurface;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: SetupScreenSurfaceDDS()
// Desc: Generates the DirectDrawSurface for a new ScreenSurface, and draws
// the appropriate image into it.
//-----------------------------------------------------------------------------
HRESULT SetupScreenSurfaceDDS( Sprite* pSprite, ScreenSurface* pScreenSurface )
{
HRESULT hr;
DDSURFACEDESC2 ddsd;
TCHAR sz[200];
Screen* pScreen = pScreenSurface->pScreen;
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
ddsd.dwWidth = pSprite->rcSrc.right - pSprite->rcSrc.left;
ddsd.dwHeight = pSprite->rcSrc.bottom - pSprite->rcSrc.top;
ddsd.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
// Try to create the surface in video memory, unless the bForceSystem flag
// is set on the Sprite.
if( pSprite->bForceSystem ||
FAILED( hr = pScreen->pDD->CreateSurface( &ddsd, &pScreenSurface->pDDS, NULL ) ) )
{
// Either this sprite has the bForceSystem flag, or creation in video
// memory failed, so try to create the surface in system memory.
ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;
if( FAILED( hr = pScreen->pDD->CreateSurface( &ddsd, &pScreenSurface->pDDS, NULL ) ) )
return hr;
}
if( ddsd.ddsCaps.dwCaps == DDSCAPS_SYSTEMMEMORY &&
pSprite->pImageData != NULL )
{
// See if we can reuse the image data that is stored in the Sprite.
// As long as the pixel formats match, the image is reusable.
ZeroMemory( &ddsd, sizeof(ddsd) );
ddsd.dwSize = sizeof(ddsd);
if( FAILED( hr = pScreenSurface->pDDS->GetSurfaceDesc( &ddsd ) ) )
return hr;
if( ddsd.ddpfPixelFormat.dwRGBBitCount == pSprite->ddsd.ddpfPixelFormat.dwRGBBitCount &&
ddsd.ddpfPixelFormat.dwRBitMask == pSprite->ddsd.ddpfPixelFormat.dwRBitMask &&
ddsd.ddpfPixelFormat.dwGBitMask == pSprite->ddsd.ddpfPixelFormat.dwGBitMask &&
ddsd.ddpfPixelFormat.dwBBitMask == pSprite->ddsd.ddpfPixelFormat.dwBBitMask )
{
// Make the DDS use the Sprite's pImageData for its surface contents
if( FAILED( hr = pScreenSurface->pDDS->SetSurfaceDesc( &pSprite->ddsd, 0 ) ) )
return hr;
return S_OK; // All done! This DDS is ready to use.
}
// Otherwise, we can't share image data, and this system memory surface
// will be for this Screen only.
}
// Copy image data from the Sprite to this ScreenSurface:
HDC hdc;
if( FAILED( hr = pScreenSurface->pDDS->GetDC( &hdc ) ) )
return hr;
HDC hdcImage;
HGDIOBJ hgdiobjOld;
DWORD dwWidth = pSprite->rcSrc.right - pSprite->rcSrc.left;
DWORD dwHeight = pSprite->rcSrc.bottom - pSprite->rcSrc.top;
hdcImage = CreateCompatibleDC(NULL);
hgdiobjOld = SelectObject(hdcImage, pSprite->hbmImage);
StretchBlt( hdc, 0, 0, dwWidth, dwHeight,
hdcImage, 0, 0, dwWidth, dwHeight, SRCCOPY );
SelectObject( hdcImage, hgdiobjOld ); // restore previously selected object
DeleteDC( hdcImage );
TextOut( hdc, 0, 0, pSprite->szName, lstrlen(pSprite->szName) );
pScreenSurface->pDDS->ReleaseDC(hdc);
if( ddsd.ddsCaps.dwCaps == DDSCAPS_VIDEOMEMORY )
{
if( FAILED( hr = pScreenSurface->pDDS->GetDC( &hdc ) ) )
return hr;
wsprintf( sz, TEXT("Video memory copy") );
TextOut( hdc, 0, 20, sz, lstrlen(sz) );
wsprintf( sz, TEXT("for %s"), pScreen->szDesc );
TextOut( hdc, 0, 40, sz, lstrlen(sz) );
pScreenSurface->pDDS->ReleaseDC(hdc);
}
else if( pSprite->pImageData == NULL )
{
// No shared copy exists yet, so create one using data in this
// system memory surface.
if( FAILED( hr = pScreenSurface->pDDS->GetDC( &hdc ) ) )
return hr;
wsprintf(sz, TEXT("Shared System memory copy") );
TextOut(hdc, 0, 20, sz, lstrlen(sz) );
pScreenSurface->pDDS->ReleaseDC( hdc );
// Copy image to pImageData so it can be shared among ScreenSurfaces:
if( SUCCEEDED( hr = pScreenSurface->pDDS->Lock( NULL, &ddsd,
DDLOCK_READONLY | DDLOCK_WAIT,
NULL ) ) )
{
pSprite->pImageData = new BYTE[ ddsd.lPitch * ddsd.dwHeight ];
if( pSprite->pImageData != NULL )
{
// Store size, pitch, pixel format, and surface pointer info in Sprite
pSprite->ddsd = ddsd;
pSprite->ddsd.lpSurface = pSprite->pImageData;
pSprite->ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH |
DDSD_PIXELFORMAT | DDSD_LPSURFACE;
// Copy image data from DDS's surface memory to Sprite's buffer
CopyMemory( pSprite->pImageData, ddsd.lpSurface,
ddsd.lPitch * ddsd.dwHeight );
}
pScreenSurface->pDDS->Unlock(NULL);
if( pSprite->pImageData != NULL )
{
// May as well make this ScreenSurface use the sharable copy too:
if( FAILED( hr = pScreenSurface->pDDS->SetSurfaceDesc( &pSprite->ddsd, 0 ) ) )
return hr;
}
}
}
else
{
// Shared copy exists, but attempt to use it failed (probably due to
// mismatched pixel format), so indicate that this as a non-shared sysmem copy:
if( FAILED( hr = pScreenSurface->pDDS->GetDC( &hdc ) ) )
return hr;
wsprintf( sz, TEXT("System memory copy") );
TextOut( hdc, 0, 20, sz, lstrlen(sz) );
wsprintf( sz, TEXT("for %s"), pScreen->szDesc );
TextOut( hdc, 0, 40, sz, lstrlen(sz) );
pScreenSurface->pDDS->ReleaseDC( hdc );
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DestroyScreenSurfaces()
// Desc: Destroys all ScreenSurfaces attached to the given Sprite. This is
// called after restoring all surfaces (since image data may be lost) and
// when preparing to exit the program.
//-----------------------------------------------------------------------------
VOID DestroyScreenSurfaces( Sprite* pSprite )
{
ScreenSurface* pScreenSurface;
ScreenSurface* pScreenSurfaceNext;
pScreenSurface = pSprite->pScreenSurfaceFirst;
pSprite->pScreenSurfaceFirst = NULL;
while( pScreenSurface != NULL )
{
pScreenSurfaceNext = pScreenSurface->pScreenSurfaceNext;
pScreenSurface->pDDS->Release();
delete pScreenSurface;
pScreenSurface = pScreenSurfaceNext;
}
if( pSprite->pImageData != NULL )
{
delete pSprite->pImageData;
pSprite->pImageData = NULL;
}
ZeroMemory( &pSprite->ddsd, sizeof(pSprite->ddsd) );
}
//-----------------------------------------------------------------------------
// Name: Cleanup()
// Desc: Releases all resources allocated during this program.
//-----------------------------------------------------------------------------
VOID Cleanup( VOID )
{
if( g_pSprite1 != NULL )
{
DestroyScreenSurfaces(g_pSprite1);
delete g_pSprite1;
g_pSprite1 = NULL;
}
if( g_pSprite2 != NULL )
{
DestroyScreenSurfaces(g_pSprite2);
delete g_pSprite2;
g_pSprite2 = NULL;
}
Screen* pScreen;
Screen* pScreenNext;
pScreen = g_pScreenFirst;
g_pScreenFirst = NULL;
while( pScreen != NULL )
{
pScreenNext = pScreen->pScreenNext;
pScreen->pDDSBack->Release();
pScreen->pDDSFront->Release();
pScreen->pDD->RestoreDisplayMode();
pScreen->pDD->SetCooperativeLevel(g_hWnd, DDSCL_NORMAL);
pScreen->pDD->Release();
delete pScreen;
pScreen = pScreenNext;
}
}

View File

@@ -0,0 +1,127 @@
# Microsoft Developer Studio Project File - Name="multimon" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=multimon - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "multimon.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "multimon.mak" CFG="multimon - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "multimon - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "multimon - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "multimon - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 dxguid.lib odbc32.lib odbccp32.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386 /stack:0x200000,0x200000
!ELSEIF "$(CFG)" == "multimon - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR /YX /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 dxguid.lib odbc32.lib odbccp32.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept /stack:0x200000,0x200000
!ENDIF
# Begin Target
# Name "multimon - Win32 Release"
# Name "multimon - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\multimon.cpp
# End Source File
# Begin Source File
SOURCE=.\multimon.rc
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\directx.ico
# End Source File
# Begin Source File
SOURCE=.\image1.bmp
# End Source File
# Begin Source File
SOURCE=.\image2.bmp
# End Source File
# Begin Source File
SOURCE=.\resource.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "multimon"=.\multimon.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,220 @@
# Microsoft Developer Studio Generated NMAKE File, Based on multimon.dsp
!IF "$(CFG)" == ""
CFG=multimon - Win32 Debug
!MESSAGE No configuration specified. Defaulting to multimon - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "multimon - Win32 Release" && "$(CFG)" != "multimon - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "multimon.mak" CFG="multimon - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "multimon - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "multimon - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "multimon - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\multimon.exe"
CLEAN :
-@erase "$(INTDIR)\multimon.obj"
-@erase "$(INTDIR)\multimon.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\multimon.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /Fp"$(INTDIR)\multimon.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\multimon.res" /d "NDEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\multimon.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=dxguid.lib odbc32.lib odbccp32.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:no /pdb:"$(OUTDIR)\multimon.pdb" /machine:I386 /out:"$(OUTDIR)\multimon.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\multimon.obj" \
"$(INTDIR)\multimon.res"
"$(OUTDIR)\multimon.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "multimon - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\multimon.exe" "$(OUTDIR)\multimon.bsc"
CLEAN :
-@erase "$(INTDIR)\multimon.obj"
-@erase "$(INTDIR)\multimon.res"
-@erase "$(INTDIR)\multimon.sbr"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\multimon.bsc"
-@erase "$(OUTDIR)\multimon.exe"
-@erase "$(OUTDIR)\multimon.ilk"
-@erase "$(OUTDIR)\multimon.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /FR"$(INTDIR)\\" /Fp"$(INTDIR)\multimon.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\multimon.res" /d "_DEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\multimon.bsc"
BSC32_SBRS= \
"$(INTDIR)\multimon.sbr"
"$(OUTDIR)\multimon.bsc" : "$(OUTDIR)" $(BSC32_SBRS)
$(BSC32) @<<
$(BSC32_FLAGS) $(BSC32_SBRS)
<<
LINK32=link.exe
LINK32_FLAGS=dxguid.lib odbc32.lib odbccp32.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:yes /pdb:"$(OUTDIR)\multimon.pdb" /debug /machine:I386 /out:"$(OUTDIR)\multimon.exe" /pdbtype:sept /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\multimon.obj" \
"$(INTDIR)\multimon.res"
"$(OUTDIR)\multimon.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("multimon.dep")
!INCLUDE "multimon.dep"
!ELSE
!MESSAGE Warning: cannot find "multimon.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "multimon - Win32 Release" || "$(CFG)" == "multimon - Win32 Debug"
SOURCE=.\multimon.cpp
!IF "$(CFG)" == "multimon - Win32 Release"
"$(INTDIR)\multimon.obj" : $(SOURCE) "$(INTDIR)"
!ELSEIF "$(CFG)" == "multimon - Win32 Debug"
"$(INTDIR)\multimon.obj" "$(INTDIR)\multimon.sbr" : $(SOURCE) "$(INTDIR)"
!ENDIF
SOURCE=.\multimon.rc
"$(INTDIR)\multimon.res" : $(SOURCE) "$(INTDIR)"
$(RSC) $(RSC_PROJ) $(SOURCE)
!ENDIF

View File

@@ -0,0 +1,7 @@
#include "resource.h"
IDI_ICON1 ICON DISCARDABLE "directx.ico"
IDB_BITMAP1 BITMAP DISCARDABLE "image1.bmp"
IDB_BITMAP2 BITMAP DISCARDABLE "image2.bmp"

View File

@@ -0,0 +1,74 @@
//-----------------------------------------------------------------------------
//
// Sample Name: Multimon Sample
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
Description
===========
Multimon demonstrates some of the techniques that can be used in writing
an application that takes advantage of multiple monitors.
Path
====
Source: DXSDK\Samples\Multimedia\DDraw\Multimon
Executable: DXSDK\Samples\Multimedia\DDraw\Bin
User's Guide
============
Multimon requires no user input. Press the ESC key to quit the program. Two
"sprites" (moving surfaces) are created. "Sprite 1" uses video memory
whenever possible. "Sprite 2" always uses system memory.
Programming Notes
=================
Multimon shows examples of a variety of topics:
- To use the multimonitor APIs such as GetMonitorInfo and MonitorFromRect
on Windows 95, you can include the file multimon.h. In addition, in one
of the C or C++ files, you need to #define COMPILE_MULTIMON_STUBS before
including multimon.h. This allows the multimon APIs to return reasonable
values when running on Windows 95. If your program does not need to be
compatible with Windows 95, or if you do not use any of the multimonitor
APIs, you do not need to include multimon.h or #define
COMPILE_MULTIMON_STUBS.
- When enumerating DirectDraw devices, you can use either DirectDrawEnumerate
or DirectDrawEnumerateEx. DirectDrawEnumerateEx is available on Windows 98
systems with DX5 and later, and all other systems with DX6 or later.
Because not all systems can be assumed to have DirectDrawEnumerateEx,
DirectDraw was set up so programmers had to use LoadLibrary and
GetProcAddress to check for its presence. In DX7, this restriction has
been removed, so you can call DirectDrawEnumerateEx directly in code, but
you should note that this will prevent your program from running on a system
which does not have at least DX7 installed. This sample shows how to do the
LoadLibrary/GetProcAddress technique, and how to fall back on
DirectDrawEnumerate if DirectDrawEnumerateEx is not available.
- Fullscreen, multimonitor apps need to deal with focus and device windows.
The focus window receives user input messages, and the device windows are
used to cover each screen. This program shows how to call
SetCooperativeLevel to properly create and assign these windows.
- Each screen gets its own DirectDraw interface, and DirectDrawSurfaces created
on one DD interface cannot be used by any other DD interface. So creating
graphics that span multiple monitors takes some extra work. This sample
demonstrates two techniques. For best performance, video memory surfaces
should be used. A separate video memory DirectDrawSurface must be created
on each screen. For the cases where a system memory surface is required or
desired, one must still create separate DirectDrawSurfaces for each screen,
but they can be configured to point to the same surface data memory. The
SetSurfaceDesc API can be used to accomplish this. Doing this has no
performance impact, but it avoids unnecessary consumption of system memory.
- Blt calls usually fail when they would cause data to be written outside the
borders of the destination surface. This failure can be avoided by attaching
clipper objects to the destinations. This sample shows how to create a
clipper for each screen and attach it to the front and back buffers so that
the sprite surfaces can be blitted without being manually clipped by the
application first.

View File

@@ -0,0 +1,3 @@
#define IDI_ICON1 100
#define IDB_BITMAP1 101
#define IDB_BITMAP2 102

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,786 @@
//-----------------------------------------------------------------------------
// File: OverlayAnimate.cpp
//
// Desc: This sample demonstrates how to animate using DirectDraw overlays
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#define STRICT
#include <windows.h>
#include <ddraw.h>
#include <mmsystem.h>
#include "resource.h"
#include "ddutil.h"
#include "dxutil.h"
//-----------------------------------------------------------------------------
// Defines, constants, and global variables
//-----------------------------------------------------------------------------
#define WINDOW_WIDTH 128
#define WINDOW_HEIGHT 128
#define SPRITE_DIAMETER 48
#define NUM_FRAMES 30
LPDIRECTDRAW7 g_pDD = NULL;
LPDIRECTDRAWSURFACE7 g_pDDSPrimary = NULL;
LPDIRECTDRAWSURFACE7 g_pDDSOverlay = NULL;
LPDIRECTDRAWSURFACE7 g_pDDSOverlayBack = NULL;
LPDIRECTDRAWSURFACE7 g_pDDSAnimationSheet = NULL;
DDOVERLAYFX g_OverlayFX;
DWORD g_dwOverlayFlags = 0;
DWORD g_dwFrame = 0;
DDCAPS g_ddcaps;
BOOL g_bActive = FALSE;
RECT g_rcSrc = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
RECT g_rcDst = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
DWORD g_dwXRatio;
DWORD g_dwYRatio;
// This will be used as the color key, so try to make it something
// that doesn't appear in the source image.
COLORREF g_dwBackgroundColor = RGB(10, 0, 10);
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
HRESULT WinInit( HINSTANCE hInst, int nCmdShow, HWND* phWnd, HACCEL* phAccel );
HRESULT InitDirectDraw( HWND hWnd );
BOOL HasOverlaySupport();
VOID FreeDirectDraw();
HRESULT CreateDirectDrawSurfaces( HWND hWnd );
VOID AdjustSizeForHardwareLimits();
HRESULT ProcessNextFrame( HWND hWnd );
HRESULT DisplayFrame();
HRESULT RestoreSurfaces();
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything and calls
// UpdateFrame() when idle from the message pump.
//-----------------------------------------------------------------------------
int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int nCmdShow )
{
HRESULT hr;
MSG msg;
HWND hWnd;
HACCEL hAccel;
if( FAILED( WinInit( hInst, nCmdShow, &hWnd, &hAccel ) ) )
return FALSE;
if( FAILED( InitDirectDraw( hWnd ) ) )
{
MessageBox( hWnd, TEXT("DirectDraw init failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
if( HasOverlaySupport() == FALSE )
{
MessageBox( hWnd, TEXT("This DirectDraw device does not support overlays. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
// Create the DirectDraw surfaces needed
if( FAILED( hr = CreateDirectDrawSurfaces( hWnd ) ) )
{
MessageBox( hWnd, TEXT("Failed to create surfaces. This DirectDraw device may not support overlays. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
ShowWindow( hWnd, SW_SHOW );
while( TRUE )
{
// Look for messages, if none are found then
// update the state and display it
if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if( 0 == GetMessage(&msg, NULL, 0, 0 ) )
{
// WM_QUIT was posted, so exit
return (int)msg.wParam;
}
// Translate and dispatch the message
if( 0 == TranslateAccelerator( hWnd, hAccel, &msg ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
else
{
if( g_bActive )
{
// Move the sprites, blt them to the back buffer, then
// flip or blt the back buffer to the primary buffer
if( FAILED( ProcessNextFrame( hWnd ) ) )
{
g_pDD->SetCooperativeLevel( NULL, DDSCL_NORMAL );
MessageBox( hWnd, TEXT("Displaying the next frame failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
}
else
{
// Make sure we go to sleep if we have nothing else to do
WaitMessage();
}
}
}
}
//-----------------------------------------------------------------------------
// Name: WinInit()
// Desc: Init the window
//-----------------------------------------------------------------------------
HRESULT WinInit( HINSTANCE hInst, int nCmdShow, HWND* phWnd, HACCEL* phAccel )
{
WNDCLASSEX wc;
HWND hWnd;
HACCEL hAccel;
// If we are in 8 bit mode, then we need to choose a system palette
// color because most colors will be dithered expect ones in the palette
HDC hDC = GetDC( NULL );
if( GetDeviceCaps( hDC, NUMCOLORS ) != -1 )
g_dwBackgroundColor = RGB( 255, 0, 255 );
ReleaseDC( NULL, hDC );
// Register the Window Class
wc.cbSize = sizeof(wc);
wc.lpszClassName = TEXT("OverlayAnimate");
wc.lpfnWndProc = MainWndProc;
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInst;
wc.hIcon = LoadIcon( hInst, MAKEINTRESOURCE(IDI_MAIN) );
wc.hIconSm = LoadIcon( hInst, MAKEINTRESOURCE(IDI_MAIN) );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
// Let windows paint the colorkey'ed background which our overlay will use
wc.hbrBackground = CreateSolidBrush( g_dwBackgroundColor );
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if( RegisterClassEx( &wc ) == 0 )
return E_FAIL;
// Load keyboard accelerators
hAccel = LoadAccelerators( hInst, MAKEINTRESOURCE(IDR_MAIN_ACCEL) );
// Calculate the proper size for the window given a client of 640x480
DWORD dwFrameWidth = GetSystemMetrics( SM_CXSIZEFRAME );
DWORD dwFrameHeight = GetSystemMetrics( SM_CYSIZEFRAME );
DWORD dwMenuHeight = GetSystemMetrics( SM_CYMENU );
DWORD dwCaptionHeight = GetSystemMetrics( SM_CYCAPTION );
DWORD dwWindowWidth = WINDOW_WIDTH + dwFrameWidth * 2;
DWORD dwWindowHeight = WINDOW_HEIGHT + dwFrameHeight * 2 +
dwMenuHeight + dwCaptionHeight;
// Create and show the main window
hWnd = CreateWindow( TEXT("OverlayAnimate"), TEXT("DirectDraw OverlayAnimate Sample"),
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
dwWindowWidth, dwWindowHeight, NULL, NULL, hInst, NULL );
if( hWnd == NULL )
return E_FAIL;
*phWnd = hWnd;
*phAccel = hAccel;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InitDirectDraw()
// Desc: Create the DirectDraw object, and init the surfaces
//-----------------------------------------------------------------------------
HRESULT InitDirectDraw( HWND hWnd )
{
DDSURFACEDESC2 ddsd;
HRESULT hr;
// Create the main DirectDraw object
if( FAILED( hr = DirectDrawCreateEx( NULL, (VOID**)&g_pDD,
IID_IDirectDraw7, NULL ) ) )
return hr;
// Request normal cooperative level to put us in windowed mode
if( FAILED( hr = g_pDD->SetCooperativeLevel( hWnd, DDSCL_NORMAL ) ) )
return hr;
// Get driver capabilities to determine Overlay support.
ZeroMemory( &g_ddcaps, sizeof(g_ddcaps) );
g_ddcaps.dwSize = sizeof(g_ddcaps);
if( FAILED( hr = g_pDD->GetCaps( &g_ddcaps, NULL ) ) )
return hr;
// Create the primary surface, which in windowed mode is the desktop.
ZeroMemory(&ddsd,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
if( FAILED( hr = g_pDD->CreateSurface( &ddsd, &g_pDDSPrimary, NULL ) ) )
return hr;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: CreateDirectDrawSurfaces()
// Desc: Creates the DirectDraw surfaces
//-----------------------------------------------------------------------------
HRESULT CreateDirectDrawSurfaces( HWND hWnd )
{
DDSURFACEDESC2 ddsd;
DDPIXELFORMAT ddpfOverlayFormat;
DDSCAPS2 ddscaps;
HRESULT hr;
// Release any previous surfaces
SAFE_RELEASE( g_pDDSOverlay );
// Set the overlay format to 16 bit RGB 5:6:5
ZeroMemory( &ddpfOverlayFormat, sizeof(ddpfOverlayFormat) );
ddpfOverlayFormat.dwSize = sizeof(ddpfOverlayFormat);
ddpfOverlayFormat.dwFlags = DDPF_RGB;
ddpfOverlayFormat.dwRGBBitCount = 16;
ddpfOverlayFormat.dwRBitMask = 0xF800;
ddpfOverlayFormat.dwGBitMask = 0x07E0;
ddpfOverlayFormat.dwBBitMask = 0x001F;
// Setup the overlay surface's attributes in the surface descriptor
ZeroMemory( &ddsd, sizeof(ddsd) );
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH |
DDSD_BACKBUFFERCOUNT | DDSD_PIXELFORMAT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_FLIP |
DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY;
ddsd.dwBackBufferCount = 1;
ddsd.dwWidth = WINDOW_WIDTH;
ddsd.dwHeight = WINDOW_HEIGHT;
ddsd.ddpfPixelFormat = ddpfOverlayFormat; // Use 16 bit RGB 5:6:5 pixel format
// Attempt to create the surface with theses settings
if( FAILED( hr = g_pDD->CreateSurface( &ddsd, &g_pDDSOverlay, NULL ) ) )
return hr;
ZeroMemory(&ddscaps, sizeof(ddscaps));
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
if( FAILED( hr = g_pDDSOverlay->GetAttachedSurface( &ddscaps, &g_pDDSOverlayBack ) ) )
return hr;
// Setup effects structure
ZeroMemory( &g_OverlayFX, sizeof(g_OverlayFX) );
g_OverlayFX.dwSize = sizeof(g_OverlayFX);
// Setup overlay flags.
g_dwOverlayFlags = DDOVER_SHOW;
// Check for destination color keying capability
if (g_ddcaps.dwCKeyCaps & DDCKEYCAPS_DESTOVERLAY)
{
// Using a color key will clip the overlay
// when the mouse or other windows go on top of us.
DWORD dwDDSColor;
// The color key can be any color, but a near black (not exactly) allows
// the cursor to move around on the window without showing off the
// color key, and also clips windows with exactly black text.
CSurface frontSurface;
frontSurface.Create( g_pDDSPrimary );
dwDDSColor = frontSurface.ConvertGDIColor( g_dwBackgroundColor );
g_OverlayFX.dckDestColorkey.dwColorSpaceLowValue = dwDDSColor;
g_OverlayFX.dckDestColorkey.dwColorSpaceHighValue = dwDDSColor;
g_dwOverlayFlags |= DDOVER_DDFX | DDOVER_KEYDESTOVERRIDE;
}
else
{
LPDIRECTDRAWCLIPPER pClipper = NULL;
// If not, we'll setup a clipper for the window. This will fix the
// problem on a few video cards - but the ones that don't shouldn't
// care.
if( FAILED( hr = g_pDD->CreateClipper(0, &pClipper, NULL) ) )
return hr;
if( FAILED( hr = pClipper->SetHWnd(0, hWnd ) ) )
return hr;
if( FAILED( hr = g_pDDSPrimary->SetClipper( pClipper ) ) )
return hr;
SAFE_RELEASE( pClipper );
}
ZeroMemory( &ddsd, sizeof(ddsd) );
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = SPRITE_DIAMETER * 5;
ddsd.dwHeight = SPRITE_DIAMETER * 6;
ddsd.ddpfPixelFormat = ddpfOverlayFormat; // Use 16 bit RGB 5:6:5 pixel format
// Attempt to create the surface with theses settings
if( FAILED( hr = g_pDD->CreateSurface( &ddsd, &g_pDDSAnimationSheet, NULL ) ) )
return hr;
CSurface animateSurface;
animateSurface.Create( g_pDDSAnimationSheet );
if( FAILED( hr = animateSurface.DrawBitmap( MAKEINTRESOURCE( IDB_ANIMATE_SHEET ),
SPRITE_DIAMETER * 5, SPRITE_DIAMETER * 6 ) ) )
return hr;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: HasOverlaySupport()
// Desc: Returns TRUE if the device supports overlays, FALSE otherwise
//-----------------------------------------------------------------------------
BOOL HasOverlaySupport()
{
// Get driver capabilities to determine overlay support.
ZeroMemory( &g_ddcaps, sizeof(g_ddcaps) );
g_ddcaps.dwSize = sizeof(g_ddcaps);
g_pDD->GetCaps( &g_ddcaps, NULL );
// Does the driver support overlays in the current mode?
// The DirectDraw emulation layer does not support overlays
// so overlay related APIs will fail without hardware support.
if( g_ddcaps.dwCaps & DDCAPS_OVERLAY )
{
// Make sure it supports stretching (scaling)
if ( g_ddcaps.dwCaps & DDCAPS_OVERLAYSTRETCH )
return TRUE;
else
return FALSE;
}
else
{
return FALSE;
}
}
//-----------------------------------------------------------------------------
// Name: FreeDirectDraw()
// Desc: Release all the DirectDraw objects
//-----------------------------------------------------------------------------
VOID FreeDirectDraw()
{
SAFE_RELEASE( g_pDDSOverlay ); // g_pDDSOverlayBack will be automatically released here
SAFE_RELEASE( g_pDDSPrimary );
SAFE_RELEASE( g_pDDSAnimationSheet );
SAFE_RELEASE( g_pDD );
}
//-----------------------------------------------------------------------------
// Name: MainWndProc()
// Desc: The main window procedure
//-----------------------------------------------------------------------------
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch (msg)
{
case WM_COMMAND:
switch( LOWORD(wParam) )
{
case IDM_EXIT:
// Received key/menu command to exit app
PostMessage( hWnd, WM_CLOSE, 0, 0 );
return 0L;
}
break; // Continue with default processing
case WM_PAINT:
// Update the screen if we need to refresh. This case occurs
// when in windowed mode and the window is behind others.
// The app will not be active, but it will be visible.
if( g_pDDSPrimary )
{
// UpdateOverlay is how we put the overlay on the screen.
if( g_rcDst.top == g_rcDst.bottom )
{
g_pDDSOverlay->UpdateOverlay( NULL, g_pDDSPrimary, NULL,
DDOVER_HIDE, NULL );
}
else
{
g_pDDSOverlay->UpdateOverlay( &g_rcSrc, g_pDDSPrimary,
&g_rcDst, g_dwOverlayFlags,
&g_OverlayFX);
}
}
break; // Continue with default processing to validate the region
case WM_QUERYNEWPALETTE:
if( g_pDDSPrimary )
{
// If we are in windowed mode with a desktop resolution in 8 bit
// color, then the palette we created during init has changed
// since then. So get the palette back from the primary
// DirectDraw surface, and set it again so that DirectDraw
// realises the palette, then release it again.
LPDIRECTDRAWPALETTE pDDPal = NULL;
g_pDDSPrimary->GetPalette( &pDDPal );
g_pDDSPrimary->SetPalette( pDDPal );
SAFE_RELEASE( pDDPal );
}
break;
case WM_MOVE:
// Make sure we're not moving to be minimized - because otherwise
// our ratio varialbes (g_dwXRatio and g_dwYRatio) will end up
// being 0, and once we hit CheckBoundries it divides by 0.
if (!IsIconic(hWnd))
{
POINT p = {0, 0}; // Translation point for the window's client region
g_rcSrc.left = 0;
g_rcSrc.right = WINDOW_WIDTH;
g_rcSrc.top = 0;
g_rcSrc.bottom = WINDOW_HEIGHT;
GetClientRect(hWnd, &g_rcDst);
g_dwXRatio = (g_rcDst.right - g_rcDst.left) * 1000 /
(g_rcSrc.right - g_rcSrc.left);
g_dwYRatio = (g_rcDst.bottom - g_rcDst.top) * 1000 /
(g_rcSrc.bottom - g_rcSrc.top);
ClientToScreen( hWnd, &p );
g_rcDst.left = p.x;
g_rcDst.top = p.y;
g_rcDst.bottom += p.y;
g_rcDst.right += p.x;
if( g_pDD )
AdjustSizeForHardwareLimits();
}
else
{
// Else, hide the overlay... just in case we can't do
// destination color keying, this will pull the overlay
// off of the screen for the user.
if (g_pDDSOverlay && g_pDDSPrimary)
g_pDDSOverlay->UpdateOverlay( NULL, g_pDDSPrimary, NULL,
DDOVER_HIDE, NULL);
}
// Check to make sure our window exists before we tell it to
// repaint. This will fail the first time (while the window is
// being created).
if (hWnd)
{
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
}
return 0L;
case WM_SIZE:
// Another check for the minimization action. This check is
// quicker though...
// Check to see if we are losing our window...
if( SIZE_MAXHIDE==wParam || SIZE_MINIMIZED==wParam )
g_bActive = FALSE;
else
g_bActive = TRUE;
if( g_bActive )
{
POINT p = {0, 0}; // Translation point for the window's client region
GetClientRect(hWnd, &g_rcDst);
ClientToScreen(hWnd, &p);
g_rcDst.left = p.x;
g_rcDst.top = p.y;
g_rcDst.bottom += p.y;
g_rcDst.right += p.x;
g_rcSrc.left = 0;
g_rcSrc.right = WINDOW_WIDTH;
g_rcSrc.top = 0;
g_rcSrc.bottom = WINDOW_HEIGHT;
// Here we multiply by 1000 to preserve 3 decimal places in the
// division opperation (we picked 1000 to be on the same order
// of magnitude as the stretch factor for easier comparisons)
g_dwXRatio = (g_rcDst.right - g_rcDst.left) * 1000 /
(g_rcSrc.right - g_rcSrc.left);
g_dwYRatio = (g_rcDst.bottom - g_rcDst.top) * 1000 /
(g_rcSrc.bottom - g_rcSrc.top);
AdjustSizeForHardwareLimits();
}
return 0L;
case WM_DISPLAYCHANGE:
// This not only checks for overlay support in the new video mode -
// but gets the new caps for the new display settings. That way we
// have more accurate info about min/max stretch factors, color
// keying
if( HasOverlaySupport() == FALSE)
{
MessageBox( hWnd, "You have changed your adapter settings such "
" that you no longer support this overlay.", "Overlay", MB_OK );
PostMessage( hWnd, WM_CLOSE, 0, 0 );
}
return 0L;
case WM_DESTROY:
// Cleanup and close the app
FreeDirectDraw();
PostQuitMessage( 0 );
return 0L;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
//-----------------------------------------------------------------------------
// Name: AdjustSizeForHardwareLimits()
// Desc: Checks and corrects all boundries for alignment and stretching
//-----------------------------------------------------------------------------
VOID AdjustSizeForHardwareLimits()
{
// Setup effects structure
// Make sure the coordinates fulfill the stretching requirements. Often
// the hardware will require a certain ammount of stretching to do
// overlays. This stretch factor is held in dwMinOverlayStretch as the
// stretch factor multiplied by 1000 (to keep an accuracy of 3 decimal
// places).
if( (g_ddcaps.dwCaps & DDCAPS_OVERLAYSTRETCH) &&
(g_ddcaps.dwMinOverlayStretch) &&
(g_dwXRatio < g_ddcaps.dwMinOverlayStretch) )
{
// Window is too small
g_rcDst.right = 2 * GetSystemMetrics(SM_CXSIZEFRAME) + g_rcDst.left + (WINDOW_WIDTH
* (g_ddcaps.dwMinOverlayStretch + 1)) / 1000;
}
if( (g_ddcaps.dwCaps & DDCAPS_OVERLAYSTRETCH) &&
(g_ddcaps.dwMaxOverlayStretch) &&
(g_dwXRatio > g_ddcaps.dwMaxOverlayStretch) )
{
// Window is too large
g_rcDst.right = 2 * GetSystemMetrics(SM_CXSIZEFRAME) + g_rcDst.left + (WINDOW_HEIGHT
* (g_ddcaps.dwMaxOverlayStretch + 999)) / 1000;
}
// Recalculate the ratio's for the upcoming calculations
g_dwXRatio = (g_rcDst.right - g_rcDst.left) * 1000 / (g_rcSrc.right - g_rcSrc.left);
g_dwYRatio = (g_rcDst.bottom - g_rcDst.top) * 1000 / (g_rcSrc.bottom - g_rcSrc.top);
// Check to make sure we're within the screen's boundries, if not then fix
// the problem by adjusting the source rectangle which we draw from.
if (g_rcDst.left < 0)
{
g_rcSrc.left = -g_rcDst.left * 1000 / g_dwXRatio;
g_rcDst.left = 0;
}
if (g_rcDst.right > GetSystemMetrics(SM_CXSCREEN))
{
g_rcSrc.right = WINDOW_WIDTH - ((g_rcDst.right - GetSystemMetrics(SM_CXSCREEN)) *
1000 / g_dwXRatio);
g_rcDst.right = GetSystemMetrics(SM_CXSCREEN);
}
if (g_rcDst.bottom > GetSystemMetrics(SM_CYSCREEN))
{
g_rcSrc.bottom = WINDOW_HEIGHT - ((g_rcDst.bottom - GetSystemMetrics(SM_CYSCREEN))
* 1000 / g_dwYRatio);
g_rcDst.bottom = GetSystemMetrics(SM_CYSCREEN);
}
if (g_rcDst.top < 0)
{
g_rcSrc.top = -g_rcDst.top * 1000 / g_dwYRatio;
g_rcDst.top = 0;
}
// Make sure the coordinates fulfill the alignment requirements
// these expressions (x & -y) just do alignment by dropping low order bits...
// so to round up, we add first, then truncate.
if( (g_ddcaps.dwCaps & DDCAPS_ALIGNBOUNDARYSRC) &&
(g_ddcaps.dwAlignBoundarySrc) )
{
g_rcSrc.left = (g_rcSrc.left + g_ddcaps.dwAlignBoundarySrc / 2) &
-(signed) (g_ddcaps.dwAlignBoundarySrc);
}
if( (g_ddcaps.dwCaps & DDCAPS_ALIGNSIZESRC) &&
(g_ddcaps.dwAlignSizeSrc) )
{
g_rcSrc.right = g_rcSrc.left + (g_rcSrc.right - g_rcSrc.left + g_ddcaps.dwAlignSizeSrc / 2) &
-(signed) (g_ddcaps.dwAlignSizeSrc);
}
if( (g_ddcaps.dwCaps & DDCAPS_ALIGNBOUNDARYDEST) &&
(g_ddcaps.dwAlignBoundaryDest) )
{
g_rcDst.left = ( g_rcDst.left + g_ddcaps.dwAlignBoundaryDest / 2 ) &
-(signed) (g_ddcaps.dwAlignBoundaryDest);
}
if( (g_ddcaps.dwCaps & DDCAPS_ALIGNSIZEDEST) &&
(g_ddcaps.dwAlignSizeDest) )
{
g_rcDst.right = g_rcDst.left + (g_rcDst.right - g_rcDst.left) &
-(signed) (g_ddcaps.dwAlignSizeDest);
}
}
//-----------------------------------------------------------------------------
// Name: ProcessNextFrame()
// Desc: Move the sprites, blt them to the back buffer, then
// flip or blt the back buffer to the primary buffer
//-----------------------------------------------------------------------------
HRESULT ProcessNextFrame( HWND hWnd )
{
static s_dwFrameSkip = 0;
HRESULT hr;
// Only advance the frame animation number every 5th frame
s_dwFrameSkip++;
s_dwFrameSkip %= 5;
if( s_dwFrameSkip == 0 )
{
g_dwFrame++;
g_dwFrame %= NUM_FRAMES;
}
// Check the cooperative level before rendering
if( FAILED( hr = g_pDD->TestCooperativeLevel() ) )
{
switch( hr )
{
case DDERR_EXCLUSIVEMODEALREADYSET:
// Do nothing because some other app has exclusive mode
Sleep(10);
return S_OK;
case DDERR_WRONGMODE:
// The display mode changed on us. Update the
// DirectDraw surfaces accordingly
return CreateDirectDrawSurfaces( hWnd );
}
return hr;
}
// Display the sprites on the screen
if( FAILED( hr = DisplayFrame() ) )
{
if( hr != DDERR_SURFACELOST )
return hr;
// The surfaces were lost so restore them
RestoreSurfaces();
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DisplayFrame()
// Desc: Blts a the sprites to the back buffer, then flips the
// back buffer onto the primary buffer.
//-----------------------------------------------------------------------------
HRESULT DisplayFrame()
{
HRESULT hr;
RECT rcSrc;
rcSrc.left = (g_dwFrame % 5) * SPRITE_DIAMETER;
rcSrc.top = (g_dwFrame / 5) * SPRITE_DIAMETER;
rcSrc.right = rcSrc.left + SPRITE_DIAMETER;
rcSrc.bottom = rcSrc.top + SPRITE_DIAMETER;
g_pDDSOverlayBack->Blt( NULL, g_pDDSAnimationSheet,
&rcSrc, DDBLT_WAIT, NULL );
if( FAILED( hr = g_pDDSOverlay->Flip( NULL, DDFLIP_WAIT ) ) )
return hr;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: RestoreSurfaces()
// Desc: Restore all the surfaces, and redraw the sprite surfaces.
//-----------------------------------------------------------------------------
HRESULT RestoreSurfaces()
{
HRESULT hr;
if( FAILED( hr = g_pDD->RestoreAllSurfaces() ) )
return hr;
// No need to re-create the surface, just re-draw it.
CSurface animateSurface;
animateSurface.Create( g_pDDSAnimationSheet );
if( FAILED( hr = animateSurface.DrawBitmap( MAKEINTRESOURCE( IDB_ANIMATE_SHEET ),
SPRITE_DIAMETER * 5, SPRITE_DIAMETER * 6 ) ) )
return hr;
return S_OK;
}

View File

@@ -0,0 +1,147 @@
# Microsoft Developer Studio Project File - Name="OverlayAnimate" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=OverlayAnimate - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "overlayanimate.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "overlayanimate.mak" CFG="OverlayAnimate - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "OverlayAnimate - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "OverlayAnimate - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "OverlayAnimate - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir ".\Release"
# PROP BASE Intermediate_Dir ".\Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ".\Release"
# PROP Intermediate_Dir ".\Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /GX /O2 /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386 /stack:0x200000,0x200000
!ELSEIF "$(CFG)" == "OverlayAnimate - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir ".\Debug"
# PROP BASE Intermediate_Dir ".\Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ".\Debug"
# PROP Intermediate_Dir ".\Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386
# ADD LINK32 winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386 /stack:0x200000,0x200000
!ENDIF
# Begin Target
# Name "OverlayAnimate - Win32 Release"
# Name "OverlayAnimate - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90"
# Begin Source File
SOURCE=.\OverlayAnimate.cpp
# End Source File
# Begin Source File
SOURCE=.\OverlayAnimate.rc
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\animate.bmp
# End Source File
# Begin Source File
SOURCE=.\directx.bmp
# End Source File
# Begin Source File
SOURCE=.\DirectX.ico
# End Source File
# Begin Source File
SOURCE=.\resource.h
# End Source File
# End Group
# Begin Group "Common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\common\src\ddutil.cpp
# End Source File
# Begin Source File
SOURCE=..\..\common\include\ddutil.h
# End Source File
# Begin Source File
SOURCE=..\..\common\src\dxutil.cpp
# End Source File
# Begin Source File
SOURCE=..\..\common\include\dxutil.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "OverlayAnimate"=.\overlayanimate.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,221 @@
# Microsoft Developer Studio Generated NMAKE File, Based on overlayanimate.dsp
!IF "$(CFG)" == ""
CFG=OverlayAnimate - Win32 Release
!MESSAGE No configuration specified. Defaulting to OverlayAnimate - Win32 Release.
!ENDIF
!IF "$(CFG)" != "OverlayAnimate - Win32 Release" && "$(CFG)" != "OverlayAnimate - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "overlayanimate.mak" CFG="OverlayAnimate - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "OverlayAnimate - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "OverlayAnimate - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "OverlayAnimate - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\overlayanimate.exe"
CLEAN :
-@erase "$(INTDIR)\ddutil.obj"
-@erase "$(INTDIR)\dxutil.obj"
-@erase "$(INTDIR)\OverlayAnimate.obj"
-@erase "$(INTDIR)\OverlayAnimate.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\overlayanimate.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\overlayanimate.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\OverlayAnimate.res" /d "NDEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\overlayanimate.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:no /pdb:"$(OUTDIR)\overlayanimate.pdb" /machine:I386 /out:"$(OUTDIR)\overlayanimate.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\OverlayAnimate.obj" \
"$(INTDIR)\ddutil.obj" \
"$(INTDIR)\dxutil.obj" \
"$(INTDIR)\OverlayAnimate.res"
"$(OUTDIR)\overlayanimate.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "OverlayAnimate - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\overlayanimate.exe"
CLEAN :
-@erase "$(INTDIR)\ddutil.obj"
-@erase "$(INTDIR)\dxutil.obj"
-@erase "$(INTDIR)\OverlayAnimate.obj"
-@erase "$(INTDIR)\OverlayAnimate.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\overlayanimate.exe"
-@erase "$(OUTDIR)\overlayanimate.ilk"
-@erase "$(OUTDIR)\overlayanimate.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\overlayanimate.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\OverlayAnimate.res" /d "_DEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\overlayanimate.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:yes /pdb:"$(OUTDIR)\overlayanimate.pdb" /debug /machine:I386 /out:"$(OUTDIR)\overlayanimate.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\OverlayAnimate.obj" \
"$(INTDIR)\ddutil.obj" \
"$(INTDIR)\dxutil.obj" \
"$(INTDIR)\OverlayAnimate.res"
"$(OUTDIR)\overlayanimate.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("overlayanimate.dep")
!INCLUDE "overlayanimate.dep"
!ELSE
!MESSAGE Warning: cannot find "overlayanimate.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "OverlayAnimate - Win32 Release" || "$(CFG)" == "OverlayAnimate - Win32 Debug"
SOURCE=.\OverlayAnimate.cpp
"$(INTDIR)\OverlayAnimate.obj" : $(SOURCE) "$(INTDIR)"
SOURCE=.\OverlayAnimate.rc
"$(INTDIR)\OverlayAnimate.res" : $(SOURCE) "$(INTDIR)"
$(RSC) $(RSC_PROJ) $(SOURCE)
SOURCE=..\..\common\src\ddutil.cpp
"$(INTDIR)\ddutil.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=..\..\common\src\dxutil.cpp
"$(INTDIR)\dxutil.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
!ENDIF

View File

@@ -0,0 +1,105 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include <windows.h>
#include <afxres.h>
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_MAIN ICON DISCARDABLE "DirectX.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include <windows.h>\r\n"
"#include <afxres.h>\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDR_MAIN_ACCEL ACCELERATORS DISCARDABLE
BEGIN
VK_ESCAPE, IDM_EXIT, VIRTKEY, NOINVERT
"X", IDM_EXIT, VIRTKEY, ALT, NOINVERT
END
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//
IDB_ANIMATE_SHEET BITMAP DISCARDABLE "animate.bmp"
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
IDR_MENU MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit\tAlt+X", IDM_EXIT
END
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1,48 @@
//-----------------------------------------------------------------------------
//
// Sample Name: OverlayAnimate Sample
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
Description
===========
OverlayAnimate demonstrates how to use DirectDraw overlays.
Path
====
Source: DXSDK\Samples\Multimedia\DDraw\OverlayAnimate
Executable: DXSDK\Samples\Multimedia\DDraw\Bin
User's Guide
============
OverlayAnimate requires no user input. Press the ESC key to quit the program.
Programming Notes
=================
For details on how to setup a windowed mode DirectDraw app, see the WindowedMode
sample.
To use overlays in general do the following steps in addition to those needed to
author a windowed mode DirectDraw app:
1. Check to see if hardware supports overlays - check IDirectDraw::GetCaps
for DDCAPS_OVERLAY.
2. Size the window to meet the hardware overlay size restrictions.
3. Create an overlay surface (create it with 1 backbuffer if needed), and
set its pixel format to a desired format that is supported by the device.
4. Set the dest color key on the overlay to the background color of the window.
Be sure to choose a color for the background of the window that Windows typically
does not use otherwise, the overlay will be drawn on top of overlapping windows.
5. Call UpdateOverlay to display or hide the overlay on the desktop. WM_PAINT is
a good place for this.
6. When WM_SIZE or WM_MOVE is sent, then update the src and dest rects and
check to make sure that they are within the hardware limits.
To animate the overlay, instead of drawing to the off-screen plain back buffer as
in windowed mode case, just draw to the the overlay's backbuffer then flip it.

View File

@@ -0,0 +1,22 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by OverlayAnimate.rc
//
#define IDI_MAIN 101
#define IDR_MENU 102
#define IDR_MAIN_ACCEL 103
#define IDB_DIRECTX 107
#define IDB_ANIMATE_SHEET 108
#define IDM_EXIT 1001
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 110
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 104
#endif
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,61 @@
//-----------------------------------------------------------------------------
//
// Sample Name: RefreshRate Sample
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
Description
===========
This example demonstrates basic usage of the IDirectDraw7::StartRefreshRate
and IDirectDraw7::EvaluateMode methods. Together, these methods allow an
application to explore what display modes and refresh rates the monitor
connected to this display device is able to display, though a manual
user-controlled process. The application will present the UI that asks
the user if the current mode under test is being displayed correctly by
the monitor.
Applications should use these methods when they are interested in using
higher refresh rates.
The basic idea is that DirectDraw will setup a list of modes to be tested
(based on the list the app passed in), and then sequentially test them
under application control. The app starts the test process, and then
calls IDirectDraw7::EvaluateMode continuously. DirectDraw will take care
of settings the modes. All the app has to do is SetCooperativeLevel
beforehand, and then handle surface loss and drawing the UI that asks the
user if they can see the current mode under test. DirectDraw returns
enough information from IDirectDraw7::EvalulateMode to allow the app to
know when to do these things, and when to stop testing. The app can pass
a flag to IDirectDraw7::EvaluateMode if the user happened to say they
could see the mode corretly, which will cause DirectDraw to mark the mode
as good and move on. DirectDraw may also decide that time as run out and
give up on a certain mode.
DirectDraw uses information at its disposal from any automated means to
make the testing process as short as possible, and applications only need
to test modes they are interested in.
Path
====
Source: DXSDK\Samples\Multimedia\DDraw\RefreshRate
Executable: DXSDK\Samples\Multimedia\DDraw\Bin
User's Guide
============
The user interface is a simple dialog box. First select the DirectDraw display
device. Then select which modes you would like to test, and click 'Test'.
Each display mode will be tested, and the user can select if the mode appears
correctly or not.
If the user makes a mistake, and accidently says YES when a mode cannot be seen,
or NO when a mode really can be seen (thus ending up with a lower refresh rate than
possible) this allows the user to reset the test results and try again.
Click the Exit button to exit the application.

View File

@@ -0,0 +1,770 @@
//-----------------------------------------------------------------------------
// File: RefreshRate.cpp
//
// Desc: This example demonstrates basic usage of the IDirectDraw7::StartRefreshRate
// and IDirectDraw7::EvaluateMode methods. Together, these methods allow an
// application to explore what display modes and refresh rates the monitor
// connected to this display device is able to display, through a manual
// user-controlled process. The application will present the UI that asks
// the user if the current mode under test is being displayed correctly by
// the monitor.
//
// Applications should use these methods when they are interested in using
// higher refresh rates.
//
// The basic idea is that DirectDraw will setup a list of modes to be tested
// (based on the list the app passed in), and then sequentially test them
// under application control. The app starts the test process, and then
// calls IDirectDraw7::EvaluateMode continuously. DirectDraw will take care
// of setting the modes. All the app has to do is SetCooperativeLevel
// beforehand, and then handle surface loss and drawing the UI that asks the
// user if they can see the current mode under test. DirectDraw returns
// enough information from IDirectDraw7::EvaluateMode to allow the app to
// know when to do these things, and when to stop testing. The app can pass
// a flag to IDirectDraw7::EvaluateMode if the user happened to say they
// could see the mode corretly, which will cause DirectDraw to mark the mode
// as good and move on. DirectDraw may also decide that time as run out and
// give up on a certain mode.
//
// DirectDraw uses information at its disposal from any automated means to
// make the testing process as short as possible, and applications only need
// to test modes they are interested in.
//
// Copyright (c) 1999-2001 Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
#define STRICT
#include <windows.h>
#include <basetsd.h>
#include <commdlg.h>
#include <initguid.h>
#include <ddraw.h>
#include "resource.h"
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam );
HRESULT GetDirectDrawDevices();
VOID OnInitDialog();
HRESULT ResetDeviceModes( DWORD dwDeviceIndex );
HRESULT UpdateModesListBox( DWORD dwDeviceIndex );
BOOL WINAPI DDEnumCallbackEx( GUID*, LPSTR, LPSTR, LPVOID, HMONITOR );
HRESULT WINAPI EnumModesCallback( LPDDSURFACEDESC pddsd, LPVOID pContext );
HRESULT WINAPI EnumAllModesCallback( LPDDSURFACEDESC2 pddsd, LPVOID pContext );
HRESULT OnRefreshRate();
HRESULT PerformDirectDrawRefreshRate( LPDIRECTDRAW7 pDD, SIZE* aTestModes,
DWORD dwTestModes );
//-----------------------------------------------------------------------------
// Defines, constants, and global variables
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
struct DDRAW_DEVICE_STRUCT
{
GUID guid;
CHAR strDescription[256];
CHAR strDriverName[64];
DWORD dwModeCount;
SIZE aModeSize[256];
};
HWND g_hDlg = NULL;
LPDIRECTDRAW g_pDD = NULL;
DDRAW_DEVICE_STRUCT g_aDevices[16];
DWORD g_dwDeviceCount;
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point for the application. Since we use a simple dialog for
// user interaction we don't need to pump messages.
//-----------------------------------------------------------------------------
INT APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine,
INT nCmdShow )
{
if( FAILED( GetDirectDrawDevices() ) )
return FALSE;
// Display the main dialog box.
DialogBox( hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, MainDlgProc );
return TRUE;
}
//-----------------------------------------------------------------------------
// Name: MainDlgProc()
// Desc: Handles dialog messages
//-----------------------------------------------------------------------------
INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_INITDIALOG:
// Store HWND in global
g_hDlg = hDlg;
OnInitDialog();
break;
case WM_COMMAND:
switch( LOWORD(wParam) )
{
case IDCANCEL:
EndDialog( hDlg, IDCANCEL );
break;
case IDC_TEST:
if( FAILED( OnRefreshRate() ) )
{
MessageBox( g_hDlg, "Error doing starting mode test. "
"Sample will now exit.", "DirectDraw Sample",
MB_OK | MB_ICONERROR );
EndDialog( g_hDlg, IDABORT );
}
break;
case IDC_RESET:
HWND hWndDeviceList;
DWORD dwDeviceIndex;
// Get the currently selected DirectDraw device
hWndDeviceList = GetDlgItem( hDlg, IDC_DDRAW_DEVICE_LIST );
dwDeviceIndex = (DWORD)SendMessage( hWndDeviceList, LB_GETCURSEL, 0, 0 );
// Reset the modes for it
if( FAILED( ResetDeviceModes( dwDeviceIndex ) ) )
{
MessageBox( g_hDlg, "Error reset DirectDraw device. "
"Sample will now exit.", "DirectDraw Sample",
MB_OK | MB_ICONERROR );
EndDialog( g_hDlg, IDABORT );
}
break;
case IDC_DDRAW_DEVICE_LIST:
switch( HIWORD(wParam) )
{
case LBN_SELCHANGE:
// Get the currently selected DirectDraw device
DWORD dwDeviceIndex;
dwDeviceIndex = (DWORD)SendMessage( (HWND) lParam,
LB_GETCURSEL, 0, 0 );
// Update the list boxes using it
if( FAILED( UpdateModesListBox( dwDeviceIndex ) ) )
{
MessageBox( g_hDlg, "Error enumerating DirectDraw modes."
"Sample will now exit.", "DirectDraw Sample",
MB_OK | MB_ICONERROR );
EndDialog( g_hDlg, IDABORT );
}
break;
default:
return FALSE;
}
break;
default:
return FALSE; // Didn't handle message
}
break;
default:
return FALSE; // Didn't handle message
}
return TRUE; // Handled message
}
//-----------------------------------------------------------------------------
// Name: GetDirectDrawDevices()
// Desc: Retrieves all available DirectDraw devices and stores the information
// in g_aDevices[]
//-----------------------------------------------------------------------------
HRESULT GetDirectDrawDevices()
{
return DirectDrawEnumerateEx( DDEnumCallbackEx,
NULL,
DDENUM_ATTACHEDSECONDARYDEVICES |
DDENUM_DETACHEDSECONDARYDEVICES |
DDENUM_NONDISPLAYDEVICES );
}
//-----------------------------------------------------------------------------
// Name: DDEnumCallbackEx()
// Desc: Enumerates all available DirectDraw devices
//-----------------------------------------------------------------------------
BOOL WINAPI DDEnumCallbackEx( GUID* pGUID,
LPSTR strDriverDescription,
LPSTR strDriverName,
LPVOID pContext,
HMONITOR hm )
{
HRESULT hr;
LPDIRECTDRAW pDD = NULL;
// Create a DirectDraw device using the enumerated guid
hr = DirectDrawCreateEx( pGUID, (VOID**)&pDD, IID_IDirectDraw7, NULL );
if( SUCCEEDED(hr) )
{
if( pGUID )
{
// Add it to the global storage structure
g_aDevices[ g_dwDeviceCount ].guid = *pGUID;
}
else
{
// Clear the guid from the global storage structure
ZeroMemory( &g_aDevices[ g_dwDeviceCount ].guid,
sizeof(GUID) );
}
// Copy the description of the driver into the structure
lstrcpyn( g_aDevices[ g_dwDeviceCount ].strDescription,
strDriverDescription, 256 );
lstrcpyn( g_aDevices[ g_dwDeviceCount ].strDriverName,
strDriverName, 64 );
// Retrive the modes this device can support
g_aDevices[ g_dwDeviceCount ].dwModeCount = 0;
hr = pDD->EnumDisplayModes( 0, NULL, NULL, EnumModesCallback );
// Increase the counter for the number of devices found
g_dwDeviceCount++;
// Release this device
SAFE_RELEASE( pDD );
}
// Continue looking for more devices
return TRUE;
}
//-----------------------------------------------------------------------------
// Name: EnumModesCallback()
// Desc: Enumerates the available modes for the device from which
// EnumDisplayModes() was called. It records the unique mode sizes in
// the g_aDevices[g_dwDeviceCount].aModeSize array
//-----------------------------------------------------------------------------
HRESULT WINAPI EnumModesCallback( LPDDSURFACEDESC pddsd,
LPVOID pContext )
{
DWORD i;
DWORD dwModeSizeX;
DWORD dwModeSizeY;
DWORD dwModeCount;
// For each mode, look through all previously found modes
// to see if this mode has already been added to the list
dwModeCount = g_aDevices[ g_dwDeviceCount ].dwModeCount;
for( i = 0; i < dwModeCount; i ++ )
{
dwModeSizeX = g_aDevices[ g_dwDeviceCount ].aModeSize[i].cx;
dwModeSizeY = g_aDevices[ g_dwDeviceCount ].aModeSize[i].cy;
if ( ( dwModeSizeX == pddsd->dwWidth ) &&
( dwModeSizeY == pddsd->dwHeight ) )
{
// If this mode has been added, then stop looking
break;
}
}
// If this mode was not in g_aDevices[g_dwDeviceCount].aModeSize[]
// then added it.
if( i == g_aDevices[ g_dwDeviceCount ].dwModeCount )
{
g_aDevices[ g_dwDeviceCount ].aModeSize[i].cx = pddsd->dwWidth;
g_aDevices[ g_dwDeviceCount ].aModeSize[i].cy = pddsd->dwHeight;
// Increase the number of modes found for this device
g_aDevices[ g_dwDeviceCount ].dwModeCount++;
}
return TRUE;
}
//-----------------------------------------------------------------------------
// Name: OnInitDialog()
// Desc: Initializes the dialogs (sets up UI controls, etc.)
//-----------------------------------------------------------------------------
VOID OnInitDialog()
{
// Load the icon
#ifdef _WIN64
HINSTANCE hInst = (HINSTANCE) GetWindowLongPtr( g_hDlg, GWLP_HINSTANCE );
#else
HINSTANCE hInst = (HINSTANCE) GetWindowLong( g_hDlg, GWL_HINSTANCE );
#endif
HICON hIcon = LoadIcon( hInst, MAKEINTRESOURCE( IDI_ICON1 ) );
// Set the icon for this dialog.
PostMessage( g_hDlg, WM_SETICON, ICON_BIG, (LPARAM) hIcon ); // Set big icon
PostMessage( g_hDlg, WM_SETICON, ICON_SMALL, (LPARAM) hIcon ); // Set small icon
// Show all available DirectDraw devices in the listbox
HWND hWndDeviceList = GetDlgItem( g_hDlg, IDC_DDRAW_DEVICE_LIST );
for( UINT i = 0; i < g_dwDeviceCount; i++ )
{
SendMessage( hWndDeviceList, LB_ADDSTRING, 0,
(LPARAM) g_aDevices[i].strDescription );
SendMessage( hWndDeviceList, LB_SETITEMDATA, i, (LPARAM) i);
}
// Select the first device by default
DWORD dwCurrentSelect = 0;
SendMessage( hWndDeviceList, LB_SETCURSEL, dwCurrentSelect, 0);
if( FAILED( UpdateModesListBox( dwCurrentSelect ) ) )
{
MessageBox( g_hDlg, "Error enumerating DirectDraw modes."
"Sample will now exit.", "DirectDraw Sample",
MB_OK | MB_ICONERROR );
EndDialog( g_hDlg, IDABORT );
}
SetFocus( hWndDeviceList );
}
//-----------------------------------------------------------------------------
// Name: ResetDeviceModes()
// Desc: If the user makes a mistake, and accidently says YES when a mode
// cannot be seen, or NO when a mode really can be seen (thus ending up
// with a lower refresh rate than possible) this allows the user to reset
// the test results and try again.
//-----------------------------------------------------------------------------
HRESULT ResetDeviceModes( DWORD dwDeviceIndex )
{
LPDIRECTDRAW7 pDD = NULL;
HRESULT hr;
// Create a DirectDraw device based using the selected device guid
hr = DirectDrawCreateEx( &g_aDevices[dwDeviceIndex].guid,
(VOID**) &pDD, IID_IDirectDraw7, NULL);
if( SUCCEEDED(hr) )
{
// Set the cooperative level to normal
if( SUCCEEDED( hr = pDD->SetCooperativeLevel( g_hDlg, DDSCL_NORMAL ) ) )
{
// Clear the previous mode tests
//
// We ignore the return code, since we would do nothing different on error returns.
// Note that most applications would never need to call StartRefreshRate this way.
// The reset functionality is intended to be used when a user accidentally accepted
// a mode that didn't actually display correctly.
pDD->StartModeTest( NULL, 0, 0 );
}
// Release this device
SAFE_RELEASE( pDD );
}
hr = UpdateModesListBox( dwDeviceIndex );
return hr;
}
//-----------------------------------------------------------------------------
// Name: UpdateModesListBox()
// Desc: Updates the "modes to test" and "all modes" list boxes
//-----------------------------------------------------------------------------
HRESULT UpdateModesListBox( DWORD dwDeviceIndex )
{
LPDIRECTDRAW7 pDD = NULL;
HRESULT hr;
HWND hWndModesToTest = GetDlgItem( g_hDlg, IDC_TEST_MODES_LIST );
SendMessage( hWndModesToTest, LB_RESETCONTENT, 0, 0 );
// Update the "modes to test" list box based on the display device selected
for( DWORD i = 0; i < g_aDevices[dwDeviceIndex].dwModeCount; i++ )
{
CHAR strMode[64];
// Make a string based on the this mode's size
wsprintf( strMode, TEXT("%u x %u"),
g_aDevices[dwDeviceIndex].aModeSize[i].cx,
g_aDevices[dwDeviceIndex].aModeSize[i].cy );
// Add it to the list box
SendMessage( hWndModesToTest, LB_ADDSTRING, 0, (LPARAM) strMode );
SendMessage( hWndModesToTest, LB_SETITEMDATA, i, (LPARAM) i );
}
// Create a DirectDraw device based using the selected device guid
if( SUCCEEDED( hr = DirectDrawCreateEx( &g_aDevices[dwDeviceIndex].guid,
(VOID**) &pDD, IID_IDirectDraw7, NULL) ) )
{
HWND hWndAllModes = GetDlgItem( g_hDlg, IDC_ALL_MODES_LIST );
SendMessage( hWndAllModes, LB_RESETCONTENT, 0, 0 );
// Enumerate and display all supported modes along
// with supported bit depth, and refresh rates
// in the "All Modes" listbox
hr = pDD->EnumDisplayModes( DDEDM_REFRESHRATES, NULL,
(VOID*) hWndAllModes,
EnumAllModesCallback );
// Release this device
SAFE_RELEASE( pDD );
}
return hr;
}
//-----------------------------------------------------------------------------
// Name: EnumAllModesCallback()
// Desc: For each mode enumerated, it adds it to the "All Modes" listbox.
//-----------------------------------------------------------------------------
HRESULT WINAPI EnumAllModesCallback( LPDDSURFACEDESC2 pddsd,
LPVOID pContext )
{
CHAR strMode[64];
HWND hWnd = (HWND) pContext;
wsprintf( strMode, TEXT("%ux%ux%u - %u Hz"),
pddsd->dwWidth,
pddsd->dwHeight,
pddsd->ddpfPixelFormat.dwRGBBitCount,
pddsd->dwRefreshRate );
SendMessage( hWnd, LB_ADDSTRING, 0, (LPARAM) strMode );
return TRUE;
}
//-----------------------------------------------------------------------------
// Name: OnRefreshRate()
// Desc: User hit the "Test" button
//-----------------------------------------------------------------------------
HRESULT OnRefreshRate()
{
HWND hWndModesToTest = GetDlgItem( g_hDlg, IDC_TEST_MODES_LIST );
DWORD dwSelectCount = (DWORD)SendMessage( hWndModesToTest, LB_GETSELCOUNT, 0, 0 );
if( dwSelectCount > 0 )
{
LPDIRECTDRAW7 pDD = NULL;
HRESULT hr;
HWND hWndDeviceList;
DWORD dwDeviceIndex;
// Get the currently selected DirectDraw device
hWndDeviceList = GetDlgItem( g_hDlg, IDC_DDRAW_DEVICE_LIST );
dwDeviceIndex = (DWORD)SendMessage( hWndDeviceList, LB_GETCURSEL, 0, 0 );
// Create a DirectDraw device based using the selected device guid
if( FAILED( hr = DirectDrawCreateEx( &g_aDevices[dwDeviceIndex].guid,
(VOID**) &pDD, IID_IDirectDraw7, NULL) ) )
return hr;
// This is a good usage of DDSCL_CREATEDEVICEWINDOW: DirectDraw will create a window that covers
// the monitor, and won't mess around with our dialog box. Any mouse clicks on the cover window
// will therefore not be received and misinterpreted by the dialog box, since such clicks will
// be sent to DirectDraw's internal message procedure and therein ignored.
if( FAILED( hr = pDD->SetCooperativeLevel( g_hDlg,
DDSCL_EXCLUSIVE |
DDSCL_FULLSCREEN |
DDSCL_CREATEDEVICEWINDOW |
DDSCL_SETFOCUSWINDOW ) ) )
{
SAFE_RELEASE( pDD );
return hr;
}
SIZE aTestModes[256];
DWORD dwTestModes = 0;
// Find out which modes are selected, then just test those
for( DWORD i = 0; i < g_aDevices[dwDeviceIndex].dwModeCount; i++ )
{
if( SendMessage( hWndModesToTest, LB_GETSEL, i, 0 ) )
{
// Record the selected modes in aTestModes[]
aTestModes[dwTestModes] = g_aDevices[dwDeviceIndex].aModeSize[i];
dwTestModes++;
}
}
// Perform test on each of the selected modes on the selected device
hr = PerformDirectDrawRefreshRate( pDD, aTestModes, dwTestModes );
// Release this device
SAFE_RELEASE( pDD );
switch (hr)
{
case DDERR_NOMONITORINFORMATION:
// No EDID data is present for the current monitor.
MessageBox(g_hDlg,
"The current monitor cannot be identified electronically.\n"
"High refresh rates are not allowed on such monitors, so the test will not be performed.",
"Testing Will Not Proceed", MB_OK | MB_ICONINFORMATION);
break;
case DDERR_NODRIVERSUPPORT:
// The driver cannot support refresh rate testing.
MessageBox(g_hDlg,
"This driver does not support the refresh rate feature of DirectDraw. Test cannot be performed.",
"Testing Cannot Proceed", MB_OK | MB_ICONINFORMATION);
break;
default:
if( SUCCEEDED(hr) )
{
MessageBox( g_hDlg, TEXT("Mode test completed"), TEXT("Result"), MB_OK );
break;
}
else
{
// A StartRefreshRate error occurred.
MessageBox(g_hDlg,
"StartRefreshRate returned an unexpected value when called with the DDSMT_ISTESTREQUIRED flag.",
"StartRefreshRate Error", MB_OK | MB_ICONEXCLAMATION);
return hr;
}
}
// Update the mode list boxes based on the device selected
if( FAILED( hr = UpdateModesListBox( dwDeviceIndex ) ) )
return hr;
}
else
{
// There weren't any modes selected to test
MessageBox( g_hDlg,
TEXT("Select one or more modes to test from the list box"),
TEXT("No modes selected"), MB_OK );
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: SetupPrimarySurface()
// Desc: Setups a primary DirectDraw surface
//-----------------------------------------------------------------------------
HRESULT SetupPrimarySurface( LPDIRECTDRAW7 pDD, LPDIRECTDRAWSURFACE7* ppDDS )
{
DDSURFACEDESC2 ddsd;
ZeroMemory( &ddsd, sizeof(ddsd) );
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
return pDD->CreateSurface(&ddsd, ppDDS, NULL);
}
//-----------------------------------------------------------------------------
// Name: UpdatePrimarySurface()
// Desc: Fills the primary surface with white, and diplays the timeout value
// on screen
//-----------------------------------------------------------------------------
HRESULT UpdatePrimarySurface( LPDIRECTDRAWSURFACE7 pDDS, DWORD dwTimeout )
{
DDBLTFX ddbltfx;
HDC hDC;
char strTimeout[128];
RECT rect;
HRESULT hr;
// Clear the screen:
ZeroMemory( &ddbltfx, sizeof(ddbltfx) );
ddbltfx.dwSize = sizeof(ddbltfx);
ddbltfx.dwFillColor = 0xFFFFFFFF;
hr = pDDS->Blt( NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx );
if( FAILED( hr ) )
return hr;
// Display the timeout value
if( FAILED( hr = pDDS->GetDC( &hDC ) ) )
return hr;
GetWindowRect( g_hDlg, &rect );
wsprintf( strTimeout, TEXT("Press space to accept or escape to reject. ")
TEXT("%2d seconds until timeout"), dwTimeout );
DrawText( hDC, strTimeout, strlen(strTimeout), &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
// Cleanup
pDDS->ReleaseDC( hDC );
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: PerformDirectDrawRefreshRate()
// Desc: Perform the IDirectDraw7::StartRefreshRate and IDirectDraw7::EvaluateMode
// tests
// Returns: S_OK if no modes needed testing, or all modes tested successfully,
// informative error code otherwise.
//-----------------------------------------------------------------------------
HRESULT PerformDirectDrawRefreshRate( LPDIRECTDRAW7 pDD, SIZE* aTestModes,
DWORD dwTestModes )
{
LPDIRECTDRAWSURFACE7 pDDSPrimary = NULL;
HRESULT hr;
MSG msg;
DWORD dwFlags = 0;
DWORD dwTimeout;
BOOL bMsgReady;
// First call StartRefreshRate with the DDSMT_ISTESTREQUIRED flag to determine
// whether the tests can be performed and need to be performed.
hr = pDD->StartModeTest( aTestModes, dwTestModes, DDSMT_ISTESTREQUIRED);
switch (hr)
{
case DDERR_NEWMODE:
// DDERR_NEWMODE means that there are modes that need testing.
break;
case DDERR_TESTFINISHED:
// DDERR_TESTFINISHED means that all the modes that we wish to test have already been tested correctly
return S_OK;
default:
//Possible return codes here include DDERR_NOMONITORINFORMATION or DDERR_NODRIVERSUPPORT or
//other fatal error codes (DDERR_INVALIDPARAMS, DDERR_NOEXCLUSIVEMODE, etc.)
return hr;
}
hr = pDD->StartModeTest( aTestModes, dwTestModes, 0 );
if( hr == DDERR_TESTFINISHED )
{
// The tests completed early, so return
return S_OK;
}
// Create the primary DirectDraw surface
if( FAILED( SetupPrimarySurface( pDD, &pDDSPrimary ) ) )
return hr;
// Loop until the mode tests are complete
while( TRUE )
{
bMsgReady = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
if( bMsgReady )
{
if (msg.message == WM_KEYDOWN)
{
switch (msg.wParam)
{
case VK_SPACE:
dwFlags = DDEM_MODEPASSED;
break;
case VK_ESCAPE:
dwFlags = DDEM_MODEFAILED;
break;
}
}
else
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
else
{
// This method will only succeed with monitors that contain EDID data.
// If the monitor is not EDID compliant, then the method will return
// DDERR_TESTFINISHED without testing any modes. If the EDID table does not
// contain values higher than 60hz, no modes will tested. Refresh rates
// higher than 100 hz will only be tested if the EDID table contains values
// higher than 85hz.
hr = pDD->EvaluateMode(dwFlags, &dwTimeout);
if( hr == DD_OK )
{
if( pDDSPrimary )
{
// Clear the screen, and display the timeout value
UpdatePrimarySurface( pDDSPrimary, dwTimeout );
}
}
else if( hr == DDERR_NEWMODE )
{
// Cleanup the last DirectDraw surface, and create
// a new one for the new mode
SAFE_RELEASE( pDDSPrimary );
if( FAILED( SetupPrimarySurface( pDD, &pDDSPrimary ) ) )
return hr;
dwFlags = 0;
}
else if( hr == DDERR_TESTFINISHED )
{
// Test complete, so stop looping
break;
}
Sleep( 100 );
}
}
// Cleanup
SAFE_RELEASE( pDDSPrimary );
return S_OK;
}

View File

@@ -0,0 +1,119 @@
# Microsoft Developer Studio Project File - Name="RefreshRate" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=RefreshRate - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "RefreshRate.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "RefreshRate.mak" CFG="RefreshRate - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "RefreshRate - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "RefreshRate - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "RefreshRate - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /I "..\wavutil" /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 odbc32.lib odbccp32.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386 /stack:0x200000,0x200000
!ELSEIF "$(CFG)" == "RefreshRate - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 odbc32.lib odbccp32.lib comctl32.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept /stack:0x200000,0x200000
!ENDIF
# Begin Target
# Name "RefreshRate - Win32 Release"
# Name "RefreshRate - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\RefreshRate.cpp
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\directx.ico
# End Source File
# Begin Source File
SOURCE=.\RefreshRate.rc
# End Source File
# Begin Source File
SOURCE=.\resource.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "RefreshRate"=.\refreshrate.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,201 @@
# Microsoft Developer Studio Generated NMAKE File, Based on refreshrate.dsp
!IF "$(CFG)" == ""
CFG=RefreshRate - Win32 Debug
!MESSAGE No configuration specified. Defaulting to RefreshRate - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "RefreshRate - Win32 Release" && "$(CFG)" != "RefreshRate - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "refreshrate.mak" CFG="RefreshRate - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "RefreshRate - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "RefreshRate - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "RefreshRate - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\refreshrate.exe"
CLEAN :
-@erase "$(INTDIR)\RefreshRate.obj"
-@erase "$(INTDIR)\RefreshRate.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\refreshrate.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "..\wavutil" /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /Fp"$(INTDIR)\refreshrate.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\RefreshRate.res" /d "NDEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\refreshrate.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=odbc32.lib odbccp32.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:no /pdb:"$(OUTDIR)\refreshrate.pdb" /machine:I386 /out:"$(OUTDIR)\refreshrate.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\RefreshRate.obj" \
"$(INTDIR)\RefreshRate.res"
"$(OUTDIR)\refreshrate.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "RefreshRate - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\refreshrate.exe"
CLEAN :
-@erase "$(INTDIR)\RefreshRate.obj"
-@erase "$(INTDIR)\RefreshRate.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\refreshrate.exe"
-@erase "$(OUTDIR)\refreshrate.ilk"
-@erase "$(OUTDIR)\refreshrate.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Fp"$(INTDIR)\refreshrate.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\RefreshRate.res" /d "_DEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\refreshrate.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=odbc32.lib odbccp32.lib comctl32.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:yes /pdb:"$(OUTDIR)\refreshrate.pdb" /debug /machine:I386 /out:"$(OUTDIR)\refreshrate.exe" /pdbtype:sept /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\RefreshRate.obj" \
"$(INTDIR)\RefreshRate.res"
"$(OUTDIR)\refreshrate.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("refreshrate.dep")
!INCLUDE "refreshrate.dep"
!ELSE
!MESSAGE Warning: cannot find "refreshrate.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "RefreshRate - Win32 Release" || "$(CFG)" == "RefreshRate - Win32 Debug"
SOURCE=.\RefreshRate.cpp
"$(INTDIR)\RefreshRate.obj" : $(SOURCE) "$(INTDIR)"
SOURCE=.\RefreshRate.rc
"$(INTDIR)\RefreshRate.res" : $(SOURCE) "$(INTDIR)"
$(RSC) $(RSC_PROJ) $(SOURCE)
!ENDIF

View File

@@ -0,0 +1,151 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
"\r\n"
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
"#ifdef _WIN32\r\n"
"LANGUAGE 9, 1\r\n"
"#pragma code_page(1252)\r\n"
"#endif\r\n"
"#include ""afxres.rc"" // Standard components\r\n"
"#endif\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_MAIN DIALOG DISCARDABLE 0, 0, 292, 174
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "DirectDraw RefreshRate Sample"
FONT 8, "MS Shell Dlg"
BEGIN
LTEXT "Select DirectDraw display device:",IDC_STATIC,7,7,107,8
LISTBOX IDC_DDRAW_DEVICE_LIST,7,17,278,34,LBS_DISABLENOSCROLL |
WS_VSCROLL | WS_TABSTOP
LTEXT "Select display modes to test:",IDC_STATIC,7,58,90,8
LISTBOX IDC_TEST_MODES_LIST,7,68,105,75,LBS_MULTIPLESEL |
LBS_NOINTEGRALHEIGHT | LBS_DISABLENOSCROLL | WS_VSCROLL |
WS_TABSTOP
LTEXT "All display modes:",IDC_STATIC,118,58,56,8
LISTBOX IDC_ALL_MODES_LIST,117,68,168,75,LBS_NOINTEGRALHEIGHT |
LBS_MULTICOLUMN | LBS_DISABLENOSCROLL | LBS_NOSEL |
WS_HSCROLL | WS_TABSTOP
PUSHBUTTON "&Test",IDC_TEST,7,153,50,14
PUSHBUTTON "&Reset",IDC_RESET,61,153,50,14
DEFPUSHBUTTON "E&xit",IDCANCEL,235,153,50,14
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_MAIN, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 285
TOPMARGIN, 7
BOTTOMMARGIN, 167
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON DISCARDABLE "directx.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDR_ACCELERATOR1 ACCELERATORS DISCARDABLE
BEGIN
"R", IDC_RESET, VIRTKEY, ALT, NOINVERT
"T", IDC_TEST, VIRTKEY, ALT, NOINVERT
"X", IDCANCEL, VIRTKEY, ALT, NOINVERT
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE 9, 1
#pragma code_page(1252)
#endif
#include "afxres.rc" // Standard components
#endif
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1,24 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by RefreshRate.rc
//
#define IDC_TEST 3
#define IDC_RESET 4
#define IDI_ICON1 103
#define IDD_MAIN 130
#define IDR_ACCELERATOR1 132
#define IDC_DDRAW_DEVICE_LIST 1000
#define IDC_TEST_MODES_LIST 1001
#define IDC_ALL_MODES_LIST 1002
#define IDC_CLOSE 1017
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 133
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1019
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,40 @@
//-----------------------------------------------------------------------------
// Sample Name: SpriteAnimate Sample
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
Description
===========
SpriteAnimate demonstrates a simple technique to animate DirectDraw surfaces.
Path
====
Source: DXSDK\Samples\Multimedia\DDraw\SpriteAnimate
Executable: DXSDK\Samples\Multimedia\DDraw\Bin
User's Guide
============
SpriteAnimate requires no user input. Press the ESC key to quit the program.
Programming Notes
=================
For details on how to setup a full-screen DirectDraw app, see the FullScreenMode
sample.
One simple method to animate sprites in DirectDraw is author a single bitmap
file to contain many frames of animation. The program then stores the current frame
indicator in each sprite's state. From this current frame indicator, it can
progmatically derive a src rect that encompasses only a single frame
of animation in the off-screen plain surface. The rect then is blited from the
off-screen plain surface to the back buffer.
InitDirectDraw() in the sample shows how to build an cached array of these source rects.
DisplayFrame() then access this array based on each sprite's current frame.

View File

@@ -0,0 +1,20 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by SpriteAnimate.rc
//
#define IDI_MAIN 101
#define IDR_MAIN_ACCEL 103
#define IDB_ANIMATE_SHEET 108
#define IDM_EXIT 1001
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 109
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 104
#endif
#endif

View File

@@ -0,0 +1,532 @@
//-----------------------------------------------------------------------------
// File: SpriteAnimate.cpp
//
// Desc: This sample demonstrates how to animate sprites using
// DirectDraw. The samples runs in full-screen mode. Pressing any
// key will exit the sample.
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#define STRICT
#include <windows.h>
#include <ddraw.h>
#include <mmsystem.h>
#include "resource.h"
#include "ddutil.h"
//-----------------------------------------------------------------------------
// Defines, constants, and global variables
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 16
#define SPRITE_DIAMETER 48
#define NUM_SPRITES 25
#define NUM_FRAMES 30
#define NUM_RAND 100
struct SPRITE_STRUCT
{
FLOAT fRotationSpeed;
FLOAT fRotationTick;
LONG lFrame;
BOOL bClockwise;
FLOAT fPosX;
FLOAT fPosY;
FLOAT fVelX;
FLOAT fVelY;
};
CDisplay* g_pDisplay = NULL;
CSurface* g_pAnimationSurface = NULL;
RECT g_rcViewport;
RECT g_rcScreen;
BOOL g_bActive = FALSE;
DWORD g_dwLastTick;
SPRITE_STRUCT g_Sprite[NUM_SPRITES];
RECT g_rcFrame[NUM_FRAMES];
LONG g_lRandTable[NUM_RAND];
DWORD g_dwRandIndex;
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
HRESULT WinInit( HINSTANCE hInst, int nCmdShow, HWND* phWnd );
HRESULT InitDirectDraw( HWND hWnd );
VOID FreeDirectDraw();
HRESULT ProcessNextFrame();
VOID UpdateSprite( SPRITE_STRUCT* pSprite, FLOAT fTimeDelta );
HRESULT DisplayFrame();
HRESULT RestoreSurfaces();
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything and calls
// UpdateFrame() when idle from the message pump.
//-----------------------------------------------------------------------------
int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int nCmdShow )
{
MSG msg;
HWND hWnd;
ZeroMemory( &g_Sprite, sizeof(SPRITE_STRUCT) * NUM_SPRITES );
srand( GetTickCount() );
if( FAILED( WinInit( hInst, nCmdShow, &hWnd ) ) )
return FALSE;
// Make a timer go off to re-init the table of random values every once in a while
SetTimer( hWnd, 0, 1500, NULL );
if( FAILED( InitDirectDraw( hWnd ) ) )
{
if( g_pDisplay )
g_pDisplay->GetDirectDraw()->SetCooperativeLevel( NULL, DDSCL_NORMAL );
MessageBox( hWnd, TEXT("DirectDraw init failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
g_dwLastTick = timeGetTime();
while( TRUE )
{
// Look for messages, if none are found then
// update the state and display it
if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if( 0 == GetMessage(&msg, NULL, 0, 0 ) )
{
// WM_QUIT was posted, so exit
return (int)msg.wParam;
}
// Translate and dispatch the message
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
if( g_bActive )
{
// Move the sprites, blt them to the back buffer, then
// flip or blt the back buffer to the primary buffer
if( FAILED( ProcessNextFrame() ) )
{
SAFE_DELETE( g_pDisplay );
MessageBox( hWnd, TEXT("Displaying the next frame failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
}
else
{
// Make sure we go to sleep if we have nothing else to do
WaitMessage();
// Ignore time spent inactive
g_dwLastTick = timeGetTime();
}
}
}
}
//-----------------------------------------------------------------------------
// Name: WinInit()
// Desc: Init the window
//-----------------------------------------------------------------------------
HRESULT WinInit( HINSTANCE hInst, int nCmdShow, HWND* phWnd )
{
WNDCLASS wc;
HWND hWnd;
// Register the Window Class
wc.lpszClassName = TEXT("SpriteAnimate");
wc.lpfnWndProc = MainWndProc;
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInst;
wc.hIcon = LoadIcon( hInst, MAKEINTRESOURCE(IDI_MAIN) );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if( RegisterClass( &wc ) == 0 )
return E_FAIL;
// Create and show the main window
hWnd = CreateWindowEx( 0, TEXT("SpriteAnimate"), TEXT("DirectDraw SpriteAnimate Sample"),
WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL );
if( hWnd == NULL )
return E_FAIL;
ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );
*phWnd = hWnd;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InitDirectDraw()
// Desc: Create the DirectDraw object, and init the surfaces
//-----------------------------------------------------------------------------
HRESULT InitDirectDraw( HWND hWnd )
{
HRESULT hr;
g_pDisplay = new CDisplay();
if( FAILED( hr = g_pDisplay->CreateFullScreenDisplay( hWnd, SCREEN_WIDTH,
SCREEN_HEIGHT, SCREEN_BPP ) ) )
{
MessageBox( hWnd, TEXT("This display card does not support 640x480x16. "),
TEXT("DirectDraw Sample"), MB_ICONERROR | MB_OK );
return hr;
}
// Create a surface, and draw a bitmap resource on it.
if( FAILED( hr = g_pDisplay->CreateSurfaceFromBitmap( &g_pAnimationSurface,
MAKEINTRESOURCE( IDB_ANIMATE_SHEET ),
SPRITE_DIAMETER * 5,
SPRITE_DIAMETER * 6 ) ) )
return hr;
// Set the color key for the logo sprite to black
if( FAILED( hr = g_pAnimationSurface->SetColorKey( 0 ) ) )
return hr;
// Init all the sprites. All of these sprites using the
// same g_pDDSAnimationSheet surface, but depending on the
// sprite's lFrame value, it indexes a different rect on the
// surface.
for( int iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
{
// Set the sprite's position and velocity
g_Sprite[iSprite].fPosX = (float) (rand() % SCREEN_WIDTH);
g_Sprite[iSprite].fPosY = (float) (rand() % SCREEN_HEIGHT);
g_Sprite[iSprite].fVelX = 500.0f * rand() / RAND_MAX - 250.0f;
g_Sprite[iSprite].fVelY = 500.0f * rand() / RAND_MAX - 250.0f;
g_Sprite[iSprite].lFrame = rand() % NUM_FRAMES;
g_Sprite[iSprite].fRotationTick = 0.0f;
g_Sprite[iSprite].fRotationSpeed = (rand() % 50 + 25 ) / 1000.0f;
g_Sprite[iSprite].bClockwise = rand() % 2;
}
// Precompute the source rects for g_pDDSAnimateSheet. The source rects
// are used during the blt of the dds to the backbuffer.
for( int iFrame = 0; iFrame < NUM_FRAMES; iFrame++ )
{
g_rcFrame[iFrame].top = (iFrame / 5) * SPRITE_DIAMETER;
g_rcFrame[iFrame].left = (iFrame % 5) * SPRITE_DIAMETER;
g_rcFrame[iFrame].bottom = g_rcFrame[iFrame].top + SPRITE_DIAMETER;
g_rcFrame[iFrame].right = g_rcFrame[iFrame].left + SPRITE_DIAMETER;
}
// Init a array of random values. This array is used to create the
// 'flocking' effect the seen in the sample.
g_dwRandIndex = 0;
for( int iRand = 0; iRand < NUM_RAND; iRand++ )
g_lRandTable[ iRand ] = rand();
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: FreeDirectDraw()
// Desc: Release all the DirectDraw objects
//-----------------------------------------------------------------------------
VOID FreeDirectDraw()
{
SAFE_DELETE( g_pAnimationSurface );
SAFE_DELETE( g_pDisplay );
}
//-----------------------------------------------------------------------------
// Name: MainWndProc()
// Desc: The main window procedure
//-----------------------------------------------------------------------------
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch (msg)
{
case WM_KEYDOWN:
PostMessage( hWnd, WM_CLOSE, 0, 0 );
return 0L;
case WM_TIMER:
{
// The timer triggered, so re-init table of random values
g_dwRandIndex = 0;
for( int iRand = 0; iRand < NUM_RAND; iRand++ )
g_lRandTable[ iRand ] = rand();
}
break;
case WM_SETCURSOR:
// Hide the cursor in fullscreen
SetCursor( NULL );
return TRUE;
case WM_SIZE:
// Check to see if we are losing our window...
if( SIZE_MAXHIDE==wParam || SIZE_MINIMIZED==wParam )
g_bActive = FALSE;
else
g_bActive = TRUE;
break;
case WM_EXITMENULOOP:
// Ignore time spent in menu
g_dwLastTick = timeGetTime();
break;
case WM_EXITSIZEMOVE:
// Ignore time spent resizing
g_dwLastTick = timeGetTime();
break;
case WM_SYSCOMMAND:
// Prevent moving/sizing and power loss in fullscreen mode
switch( wParam )
{
case SC_MOVE:
case SC_SIZE:
case SC_MAXIMIZE:
case SC_MONITORPOWER:
return TRUE;
}
break;
case WM_DESTROY:
// Cleanup and close the app
FreeDirectDraw();
PostQuitMessage( 0 );
return 0L;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
//-----------------------------------------------------------------------------
// Name: ProcessNextFrame()
// Desc: Move the sprites, blt them to the back buffer, then
// flips the back buffer to the primary buffer
//-----------------------------------------------------------------------------
HRESULT ProcessNextFrame()
{
HRESULT hr;
// Figure how much time has passed since the last time
DWORD dwCurrTick = timeGetTime();
DWORD dwTickDiff = dwCurrTick - g_dwLastTick;
// Don't update if no time has passed
if( dwTickDiff == 0 )
return S_OK;
g_dwLastTick = dwCurrTick;
// Update the sprites according to how much time has passed
for( int iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
UpdateSprite( &g_Sprite[ iSprite ], dwTickDiff / 1000.0f );
// Display the sprites on the screen
if( FAILED( hr = DisplayFrame() ) )
{
if( hr != DDERR_SURFACELOST )
return hr;
// The surfaces were lost so restore them
RestoreSurfaces();
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: GetNextRand()
// Desc: Gets the next element from the circular array of random values
//-----------------------------------------------------------------------------
LONG GetNextRand()
{
LONG lRand = g_lRandTable[ g_dwRandIndex++ ];
g_dwRandIndex %= NUM_RAND;
return lRand;
}
//-----------------------------------------------------------------------------
// Name: UpdateSprite()
// Desc: Moves and bounces the sprite based on how much time has passed.
// It also changes the sprite state based on random values it gets
// from the array g_lRandTable
//-----------------------------------------------------------------------------
VOID UpdateSprite( SPRITE_STRUCT* pSprite, FLOAT fTimeDelta )
{
// Update the sprite position
pSprite->fPosX += pSprite->fVelX * fTimeDelta;
pSprite->fPosY += pSprite->fVelY * fTimeDelta;
// See if its time to advance the sprite to the next frame
pSprite->fRotationTick += fTimeDelta;
if( pSprite->fRotationTick > pSprite->fRotationSpeed )
{
// If it is, then either change the frame clockwise or counter-clockwise
if( pSprite->bClockwise )
{
pSprite->lFrame++;
pSprite->lFrame %= NUM_FRAMES;
}
else
{
pSprite->lFrame--;
if( pSprite->lFrame < 0 )
pSprite->lFrame = NUM_FRAMES - 1;
}
pSprite->fRotationTick = 0;
}
// Using the next element from the random arry,
// randomize the velocity of the sprite
if( GetNextRand() % 100 < 2 )
{
pSprite->fVelX = 500.0f * GetNextRand() / RAND_MAX - 250.0f;
pSprite->fVelY = 500.0f * GetNextRand() / RAND_MAX - 250.0f;
}
// Using the next element from the random arry,
// randomize the rotational speed of the sprite
if( GetNextRand() % 100 < 5 )
pSprite->fRotationSpeed = ( GetNextRand() % 50 + 5 ) / 1000.0f;
// Clip the position, and bounce if it hits the edge
if( pSprite->fPosX < 0.0f )
{
pSprite->fPosX = 0;
pSprite->fVelX = -pSprite->fVelX;
}
if( pSprite->fPosX >= SCREEN_WIDTH - SPRITE_DIAMETER )
{
pSprite->fPosX = SCREEN_WIDTH - 1 - SPRITE_DIAMETER;
pSprite->fVelX = -pSprite->fVelX;
}
if( pSprite->fPosY < 0 )
{
pSprite->fPosY = 0;
pSprite->fVelY = -pSprite->fVelY;
}
if( pSprite->fPosY > SCREEN_HEIGHT - SPRITE_DIAMETER )
{
pSprite->fPosY = SCREEN_HEIGHT - 1 - SPRITE_DIAMETER;
pSprite->fVelY = -pSprite->fVelY;
}
}
//-----------------------------------------------------------------------------
// Name: DisplayFrame()
// Desc: Blts a the sprites to the back buffer, then flips the
// back buffer onto the primary buffer.
//-----------------------------------------------------------------------------
HRESULT DisplayFrame()
{
HRESULT hr;
// Fill the back buffer with black, ignoring errors until the flip
g_pDisplay->Clear( 0 );
// Blt all the sprites onto the back buffer using color keying,
// ignoring errors until the flip. Note that all of these sprites
// use the same DirectDraw surface.
for( int iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
{
g_pDisplay->Blt( (DWORD)g_Sprite[iSprite].fPosX,
(DWORD)g_Sprite[iSprite].fPosY,
g_pAnimationSurface,
&g_rcFrame[ g_Sprite[iSprite].lFrame ] );
}
// We are in fullscreen mode, so perform a flip and return
// any errors like DDERR_SURFACELOST
if( FAILED( hr = g_pDisplay->Present() ) )
return hr;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: RestoreSurfaces()
// Desc: Restore all the surfaces, and redraw the sprite surfaces.
//-----------------------------------------------------------------------------
HRESULT RestoreSurfaces()
{
HRESULT hr;
if( FAILED( hr = g_pDisplay->GetDirectDraw()->RestoreAllSurfaces() ) )
return hr;
// No need to re-create the surface, just re-draw it.
if( FAILED( hr = g_pAnimationSurface->DrawBitmap( MAKEINTRESOURCE( IDB_ANIMATE_SHEET ),
SPRITE_DIAMETER * 5,
SPRITE_DIAMETER * 6 ) ) )
return hr;
return S_OK;
}

View File

@@ -0,0 +1,135 @@
# Microsoft Developer Studio Project File - Name="SpriteAnimate" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=SpriteAnimate - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "spriteanimate.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "spriteanimate.mak" CFG="SpriteAnimate - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "SpriteAnimate - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "SpriteAnimate - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "SpriteAnimate - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir ".\Release"
# PROP BASE Intermediate_Dir ".\Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ".\Release"
# PROP Intermediate_Dir ".\Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /GX /O2 /I "..\common" /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 dxguid.lib winmm.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386 /stack:0x200000,0x200000
!ELSEIF "$(CFG)" == "SpriteAnimate - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir ".\Debug"
# PROP BASE Intermediate_Dir ".\Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ".\Debug"
# PROP Intermediate_Dir ".\Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386
# ADD LINK32 winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386 /stack:0x200000,0x200000
!ENDIF
# Begin Target
# Name "SpriteAnimate - Win32 Release"
# Name "SpriteAnimate - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90"
# Begin Source File
SOURCE=.\spriteanimate.cpp
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\resource.h
# End Source File
# Begin Source File
SOURCE=.\spriteanimate.rc
# End Source File
# End Group
# Begin Group "Common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\common\src\ddutil.cpp
# End Source File
# Begin Source File
SOURCE=..\..\common\include\ddutil.h
# End Source File
# Begin Source File
SOURCE=..\..\common\src\dxutil.cpp
# End Source File
# Begin Source File
SOURCE=..\..\common\include\dxutil.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "SpriteAnimate"=.\spriteanimate.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,221 @@
# Microsoft Developer Studio Generated NMAKE File, Based on spriteanimate.dsp
!IF "$(CFG)" == ""
CFG=SpriteAnimate - Win32 Release
!MESSAGE No configuration specified. Defaulting to SpriteAnimate - Win32 Release.
!ENDIF
!IF "$(CFG)" != "SpriteAnimate - Win32 Release" && "$(CFG)" != "SpriteAnimate - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "spriteanimate.mak" CFG="SpriteAnimate - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "SpriteAnimate - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "SpriteAnimate - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "SpriteAnimate - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\spriteanimate.exe"
CLEAN :
-@erase "$(INTDIR)\ddutil.obj"
-@erase "$(INTDIR)\dxutil.obj"
-@erase "$(INTDIR)\spriteanimate.obj"
-@erase "$(INTDIR)\spriteanimate.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\spriteanimate.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "..\common" /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\spriteanimate.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\spriteanimate.res" /d "NDEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\spriteanimate.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=dxguid.lib winmm.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:no /pdb:"$(OUTDIR)\spriteanimate.pdb" /machine:I386 /out:"$(OUTDIR)\spriteanimate.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\spriteanimate.obj" \
"$(INTDIR)\ddutil.obj" \
"$(INTDIR)\dxutil.obj" \
"$(INTDIR)\spriteanimate.res"
"$(OUTDIR)\spriteanimate.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "SpriteAnimate - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\spriteanimate.exe"
CLEAN :
-@erase "$(INTDIR)\ddutil.obj"
-@erase "$(INTDIR)\dxutil.obj"
-@erase "$(INTDIR)\spriteanimate.obj"
-@erase "$(INTDIR)\spriteanimate.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\spriteanimate.exe"
-@erase "$(OUTDIR)\spriteanimate.ilk"
-@erase "$(OUTDIR)\spriteanimate.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\spriteanimate.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\spriteanimate.res" /d "_DEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\spriteanimate.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:yes /pdb:"$(OUTDIR)\spriteanimate.pdb" /debug /machine:I386 /out:"$(OUTDIR)\spriteanimate.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\spriteanimate.obj" \
"$(INTDIR)\ddutil.obj" \
"$(INTDIR)\dxutil.obj" \
"$(INTDIR)\spriteanimate.res"
"$(OUTDIR)\spriteanimate.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("spriteanimate.dep")
!INCLUDE "spriteanimate.dep"
!ELSE
!MESSAGE Warning: cannot find "spriteanimate.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "SpriteAnimate - Win32 Release" || "$(CFG)" == "SpriteAnimate - Win32 Debug"
SOURCE=.\spriteanimate.cpp
"$(INTDIR)\spriteanimate.obj" : $(SOURCE) "$(INTDIR)"
SOURCE=.\spriteanimate.rc
"$(INTDIR)\spriteanimate.res" : $(SOURCE) "$(INTDIR)"
$(RSC) $(RSC_PROJ) $(SOURCE)
SOURCE=..\..\common\src\ddutil.cpp
"$(INTDIR)\ddutil.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=..\..\common\src\dxutil.cpp
"$(INTDIR)\dxutil.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
!ENDIF

View File

@@ -0,0 +1,79 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include <windows.h>
#include <afxres.h>
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_MAIN ICON DISCARDABLE "DirectX.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include <windows.h>\r\n"
"#include <afxres.h>\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//
IDB_ANIMATE_SHEET BITMAP DISCARDABLE "animate.bmp"
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,37 @@
//-----------------------------------------------------------------------------
//
// Sample Name: SwitchScreenMode Sample
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
Description
===========
SwitchScreenMode demonstrates how to author a DirectDraw application to handle
switching between both full-screen and windowed DirectDraw modes.
Path
====
Source: DXSDK\Samples\Multimedia\DDraw\SwitchScreenMode
Executable: DXSDK\Samples\Multimedia\DDraw\Bin
User's Guide
============
Press Alt-Enter to switch from windowed mode to full-screen and back again.
Press the ESC key to quit the program.
Programming Notes
=================
For details on how to setup a full-screen DirectDraw app, see the FullScreenMode
sample.
For details on how to setup a windowed mode DirectDraw app, see the WindowedMode
sample.
When combining these the two mode, be sure to re-create all DirectDraw surfaces
since the pixel format for full-screen mode typically does not match the
desktop pixel format.

View File

@@ -0,0 +1,24 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by SwitchScreenMode.rc
//
#define IDI_MAIN_ICON 101
#define IDI_MAIN 101
#define IDR_MENU 102
#define IDR_MAIN_ACCEL 103
#define IDB_DIRECTX 107
#define IDM_ABOUT 1000
#define IDM_EXIT 1001
#define IDM_TOGGLEFULLSCREEN 1002
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 108
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 104
#endif
#endif

View File

@@ -0,0 +1,674 @@
//-----------------------------------------------------------------------------
// File: SwitchScreenMode.cpp
//
// Desc: This sample demonstrates how to switch between windowed and
// full-screen exclusive DDraw cooperative levels.
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#define STRICT
#include <windows.h>
#include <ddraw.h>
#include <mmsystem.h>
#include "resource.h"
#include "ddutil.h"
//-----------------------------------------------------------------------------
// Defines, constants, and global variables
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 8
#define SPRITE_DIAMETER 48
#define NUM_SPRITES 25
#define WINDOWED_HELPTEXT TEXT("Press Escape to quit. Press Alt-Enter to switch to Full-Screen mode.")
#define FULLSCREEN_HELPTEXT TEXT("Press Escape to quit. Press Alt-Enter to switch to Windowed mode.")
struct SPRITE_STRUCT
{
FLOAT fPosX;
FLOAT fPosY;
FLOAT fVelX;
FLOAT fVelY;
};
CDisplay* g_pDisplay = NULL;
CSurface* g_pLogoSurface = NULL;
CSurface* g_pTextSurface = NULL;
RECT g_rcWindow;
RECT g_rcViewport;
RECT g_rcScreen;
BOOL g_bWindowed = TRUE;
BOOL g_bActive = FALSE;
DWORD g_dwLastTick;
SPRITE_STRUCT g_Sprite[NUM_SPRITES];
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
HRESULT WinInit( HINSTANCE hInst, int nCmdShow, HWND* phWnd, HACCEL* phAccel );
HRESULT InitDirectDraw( HWND hWnd );
VOID FreeDirectDraw();
HRESULT InitDirectDrawMode( HWND hWnd, BOOL bWindowed );
HRESULT ProcessNextFrame( HWND hWnd );
VOID UpdateSprite( SPRITE_STRUCT* pSprite, FLOAT fTimeDelta );
HRESULT DisplayFrame();
HRESULT RestoreSurfaces();
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything and calls
// UpdateFrame() when idle from the message pump.
//-----------------------------------------------------------------------------
int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int nCmdShow )
{
MSG msg;
HWND hWnd;
HACCEL hAccel;
ZeroMemory( &g_Sprite, sizeof(SPRITE_STRUCT) * NUM_SPRITES );
srand( GetTickCount() );
if( FAILED( WinInit( hInst, nCmdShow, &hWnd, &hAccel ) ) )
return FALSE;
if( FAILED( InitDirectDraw( hWnd ) ) )
{
MessageBox( hWnd, TEXT("DirectDraw init failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
g_dwLastTick = timeGetTime();
while( TRUE )
{
// Look for messages, if none are found then
// update the state and display it
if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if( 0 == GetMessage(&msg, NULL, 0, 0 ) )
{
// WM_QUIT was posted, so exit
return (int)msg.wParam;
}
// Translate and dispatch the message
if( 0 == TranslateAccelerator( hWnd, hAccel, &msg ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
else
{
if( g_bActive )
{
// Move the sprites, blt them to the back buffer, then
// flip or blt the back buffer to the primary buffer
if( FAILED( ProcessNextFrame( hWnd ) ) )
{
SAFE_DELETE( g_pDisplay );
MessageBox( hWnd, TEXT("Displaying the next frame failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
return FALSE;
}
}
else
{
// Go to sleep if we have nothing else to do
WaitMessage();
// Ignore time spent inactive
g_dwLastTick = timeGetTime();
}
}
}
}
//-----------------------------------------------------------------------------
// Name: WinInit()
// Desc: Init the window
//-----------------------------------------------------------------------------
HRESULT WinInit( HINSTANCE hInst, int nCmdShow, HWND* phWnd, HACCEL* phAccel )
{
WNDCLASSEX wc;
HWND hWnd;
HACCEL hAccel;
// Register the window class
wc.cbSize = sizeof(wc);
wc.lpszClassName = TEXT("SwitchScreenMode");
wc.lpfnWndProc = MainWndProc;
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInst;
wc.hIcon = LoadIcon( hInst, MAKEINTRESOURCE(IDI_MAIN_ICON) );
wc.hIconSm = LoadIcon( hInst, MAKEINTRESOURCE(IDI_MAIN_ICON) );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if( RegisterClassEx( &wc ) == 0 )
return E_FAIL;
// Load keyboard accelerators
hAccel = LoadAccelerators( hInst, MAKEINTRESOURCE(IDR_MAIN_ACCEL) );
// Calculate the proper size for the window given a client of 640x480
DWORD dwFrameWidth = GetSystemMetrics( SM_CXSIZEFRAME );
DWORD dwFrameHeight = GetSystemMetrics( SM_CYSIZEFRAME );
DWORD dwMenuHeight = GetSystemMetrics( SM_CYMENU );
DWORD dwCaptionHeight = GetSystemMetrics( SM_CYCAPTION );
DWORD dwWindowWidth = SCREEN_WIDTH + dwFrameWidth * 2;
DWORD dwWindowHeight = SCREEN_HEIGHT + dwFrameHeight * 2 +
dwMenuHeight + dwCaptionHeight;
// Create and show the main window
DWORD dwStyle = WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX;
hWnd = CreateWindowEx( 0, TEXT("SwitchScreenMode"),
TEXT("DirectDraw SwitchScreenMode Sample"),
dwStyle, CW_USEDEFAULT, CW_USEDEFAULT,
dwWindowWidth, dwWindowHeight, NULL, NULL, hInst, NULL );
if( hWnd == NULL )
return E_FAIL;
ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );
// Save the window size/pos for switching modes
GetWindowRect( hWnd, &g_rcWindow );
*phWnd = hWnd;
*phAccel = hAccel;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InitDirectDraw()
// Desc: Create the DirectDraw object, and init the surfaces
//-----------------------------------------------------------------------------
HRESULT InitDirectDraw( HWND hWnd )
{
HRESULT hr;
// Initialize all the surfaces we need
if( FAILED( hr = InitDirectDrawMode( hWnd, g_bWindowed ) ) )
return hr;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InitDirectDrawMode()
// Desc: Called when the user wants to toggle between full-screen and windowed
// to create all the needed DDraw surfaces and set the coop level
//-----------------------------------------------------------------------------
HRESULT InitDirectDrawMode( HWND hWnd, BOOL bWindowed )
{
HRESULT hr;
LPDIRECTDRAWPALETTE pDDPal = NULL;
int iSprite;
// Release all existing surfaces
SAFE_DELETE( g_pLogoSurface );
SAFE_DELETE( g_pTextSurface );
SAFE_DELETE( g_pDisplay );
// The back buffer and primary surfaces need to be created differently
// depending on if we are in full-screen or windowed mode
g_pDisplay = new CDisplay();
if( bWindowed )
{
if( FAILED( hr = g_pDisplay->CreateWindowedDisplay( hWnd, SCREEN_WIDTH,
SCREEN_HEIGHT ) ) )
return hr;
// Add the system menu to the window's style
DWORD dwStyle = GetWindowLong( hWnd, GWL_STYLE );
dwStyle |= WS_SYSMENU;
SetWindowLong( hWnd, GWL_STYLE, dwStyle );
// Show the menu in windowed mode
#ifdef _WIN64
HINSTANCE hInst = (HINSTANCE) GetWindowLongPtr( hWnd, GWLP_HINSTANCE );
#else
HINSTANCE hInst = (HINSTANCE) GetWindowLong( hWnd, GWL_HINSTANCE );
#endif
HMENU hMenu = LoadMenu( hInst, MAKEINTRESOURCE( IDR_MENU ) );
SetMenu( hWnd, hMenu );
}
else
{
if( FAILED( hr = g_pDisplay->CreateFullScreenDisplay( hWnd, SCREEN_WIDTH,
SCREEN_HEIGHT, SCREEN_BPP ) ) )
{
MessageBox( hWnd, TEXT("This display card does not support 640x480x8. "),
TEXT("DirectDraw Sample"), MB_ICONERROR | MB_OK );
return hr;
}
// Disable the menu in full-screen since we are
// using a palette and a menu would look bad
SetMenu( hWnd, NULL );
// Remove the system menu from the window's style
DWORD dwStyle = GetWindowLong( hWnd, GWL_STYLE );
dwStyle &= ~WS_SYSMENU;
SetWindowLong( hWnd, GWL_STYLE, dwStyle );
}
// We need to release and re-load, and set the palette again to
// redraw the bitmap on the surface. Otherwise, GDI will not
// draw the bitmap on the surface with the right palette
if( FAILED( hr = g_pDisplay->CreatePaletteFromBitmap( &pDDPal, MAKEINTRESOURCE( IDB_DIRECTX ) ) ) )
return hr;
g_pDisplay->SetPalette( pDDPal );
SAFE_RELEASE( pDDPal );
if( g_bWindowed )
{
// Create a surface, and draw text to it.
if( FAILED( hr = g_pDisplay->CreateSurfaceFromText( &g_pTextSurface, NULL, WINDOWED_HELPTEXT,
RGB(0,0,0), RGB(255, 255, 0) ) ) )
return hr;
}
else
{
// Create a surface, and draw text to it.
if( FAILED( hr = g_pDisplay->CreateSurfaceFromText( &g_pTextSurface, NULL, FULLSCREEN_HELPTEXT,
RGB(0,0,0), RGB(255, 255, 0) ) ) )
return hr;
}
// Create a surface, and draw a bitmap resource on it. The surface must
// be newly created every time the screen mode is switched since it
// uses the pixel format of the primary surface
if( FAILED( hr = g_pDisplay->CreateSurfaceFromBitmap( &g_pLogoSurface, MAKEINTRESOURCE( IDB_DIRECTX ),
SPRITE_DIAMETER, SPRITE_DIAMETER ) ) )
return hr;
// Set the color key for the logo sprite to black
if( FAILED( hr = g_pLogoSurface->SetColorKey( 0 ) ) )
return hr;
// Init all the sprites. All of these sprites look the same,
// using the g_pDDSLogo surface.
for( iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
{
// Set the sprite's position and velocity
g_Sprite[iSprite].fPosX = (float) (rand() % SCREEN_WIDTH);
g_Sprite[iSprite].fPosY = (float) (rand() % SCREEN_HEIGHT);
g_Sprite[iSprite].fVelX = 500.0f * rand() / RAND_MAX - 250.0f;
g_Sprite[iSprite].fVelY = 500.0f * rand() / RAND_MAX - 250.0f;
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: FreeDirectDraw()
// Desc: Release all the DirectDraw objects
//-----------------------------------------------------------------------------
VOID FreeDirectDraw()
{
SAFE_DELETE( g_pLogoSurface );
SAFE_DELETE( g_pTextSurface );
SAFE_DELETE( g_pDisplay );
}
//-----------------------------------------------------------------------------
// Name: MainWndProc()
// Desc: The main window procedure
//-----------------------------------------------------------------------------
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch (msg)
{
case WM_COMMAND:
switch( LOWORD(wParam) )
{
case IDM_TOGGLEFULLSCREEN:
// Toggle the fullscreen/window mode
if( g_bWindowed )
GetWindowRect( hWnd, &g_rcWindow );
g_bWindowed = !g_bWindowed;
if( FAILED( InitDirectDrawMode( hWnd, g_bWindowed ) ) )
{
SAFE_DELETE( g_pDisplay );
MessageBox( hWnd, TEXT("InitDirectDraw() failed. ")
TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),
MB_ICONERROR | MB_OK );
PostMessage( hWnd, WM_CLOSE, 0, 0 );
}
return 0L;
case IDM_EXIT:
// Received key/menu command to exit app
PostMessage( hWnd, WM_CLOSE, 0, 0 );
return 0L;
}
break; // Continue with default processing
case WM_GETMINMAXINFO:
{
// Don't allow resizing in windowed mode.
// Fix the size of the window to 640x480 (client size)
MINMAXINFO* pMinMax = (MINMAXINFO*) lParam;
DWORD dwFrameWidth = GetSystemMetrics( SM_CXSIZEFRAME );
DWORD dwFrameHeight = GetSystemMetrics( SM_CYSIZEFRAME );
DWORD dwMenuHeight = GetSystemMetrics( SM_CYMENU );
DWORD dwCaptionHeight = GetSystemMetrics( SM_CYCAPTION );
pMinMax->ptMinTrackSize.x = SCREEN_WIDTH + dwFrameWidth * 2;
pMinMax->ptMinTrackSize.y = SCREEN_HEIGHT + dwFrameHeight * 2 +
dwMenuHeight + dwCaptionHeight;
pMinMax->ptMaxTrackSize.x = pMinMax->ptMinTrackSize.x;
pMinMax->ptMaxTrackSize.y = pMinMax->ptMinTrackSize.y;
}
return 0L;
case WM_MOVE:
// Retrieve the window position after a move.
if( g_pDisplay )
g_pDisplay->UpdateBounds();
return 0L;
case WM_SIZE:
// Check to see if we are losing our window...
if( SIZE_MAXHIDE==wParam || SIZE_MINIMIZED==wParam )
g_bActive = FALSE;
else
g_bActive = TRUE;
if( g_pDisplay )
g_pDisplay->UpdateBounds();
break;
case WM_SETCURSOR:
// Hide the cursor if in fullscreen
if( !g_bWindowed )
{
SetCursor( NULL );
return TRUE;
}
break; // Continue with default processing
case WM_QUERYNEWPALETTE:
if( g_pDisplay && g_pDisplay->GetFrontBuffer() )
{
// If we are in windowed mode with a desktop resolution in 8 bit
// color, then the palette we created during init has changed
// since then. So get the palette back from the primary
// DirectDraw surface, and set it again so that DirectDraw
// realises the palette, then release it again.
LPDIRECTDRAWPALETTE pDDPal = NULL;
g_pDisplay->GetFrontBuffer()->GetPalette( &pDDPal );
g_pDisplay->GetFrontBuffer()->SetPalette( pDDPal );
SAFE_RELEASE( pDDPal );
}
break;
case WM_EXITMENULOOP:
// Ignore time spent in menu
g_dwLastTick = timeGetTime();
break;
case WM_EXITSIZEMOVE:
// Ignore time spent resizing
g_dwLastTick = timeGetTime();
break;
case WM_SYSCOMMAND:
// Prevent moving/sizing and power loss in fullscreen mode
switch( wParam )
{
case SC_MOVE:
case SC_SIZE:
case SC_MAXIMIZE:
case SC_MONITORPOWER:
if( !g_bWindowed )
return TRUE;
}
break;
case WM_DESTROY:
// Cleanup and close the app
FreeDirectDraw();
PostQuitMessage( 0 );
return 0L;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
//-----------------------------------------------------------------------------
// Name: ProcessNextFrame()
// Desc: Move the sprites, blt them to the back buffer, then
// flip or blt the back buffer to the primary buffer
//-----------------------------------------------------------------------------
HRESULT ProcessNextFrame( HWND hWnd )
{
HRESULT hr;
// Figure how much time has passed since the last time
DWORD dwCurrTick = timeGetTime();
DWORD dwTickDiff = dwCurrTick - g_dwLastTick;
// Don't update if no time has passed
if( dwTickDiff == 0 )
return S_OK;
g_dwLastTick = dwCurrTick;
// Move the sprites according to how much time has passed
for( int iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
UpdateSprite( &g_Sprite[ iSprite ], dwTickDiff / 1000.0f );
// Check the cooperative level before rendering
if( FAILED( hr = g_pDisplay->GetDirectDraw()->TestCooperativeLevel() ) )
{
switch( hr )
{
case DDERR_EXCLUSIVEMODEALREADYSET:
case DDERR_NOEXCLUSIVEMODE:
// Do nothing because some other app has exclusive mode
Sleep(10);
return S_OK;
case DDERR_WRONGMODE:
// The display mode changed on us. Update the
// DirectDraw surfaces accordingly
return InitDirectDrawMode( hWnd, g_bWindowed );
}
return hr;
}
// Display the sprites on the screen
if( FAILED( hr = DisplayFrame() ) )
{
if( hr != DDERR_SURFACELOST )
return hr;
// The surfaces were lost so restore them
RestoreSurfaces();
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: UpdateSprite()
// Desc: Move the sprite around and make it bounce based on how much time
// has passed
//-----------------------------------------------------------------------------
VOID UpdateSprite( SPRITE_STRUCT* pSprite, FLOAT fTimeDelta )
{
// Update the sprite position
pSprite->fPosX += pSprite->fVelX * fTimeDelta;
pSprite->fPosY += pSprite->fVelY * fTimeDelta;
// Clip the position, and bounce if it hits the edge
if( pSprite->fPosX < 0.0f )
{
pSprite->fPosX = 0;
pSprite->fVelX = -pSprite->fVelX;
}
if( pSprite->fPosX >= SCREEN_WIDTH - SPRITE_DIAMETER )
{
pSprite->fPosX = SCREEN_WIDTH - 1 - SPRITE_DIAMETER;
pSprite->fVelX = -pSprite->fVelX;
}
if( pSprite->fPosY < 0 )
{
pSprite->fPosY = 0;
pSprite->fVelY = -pSprite->fVelY;
}
if( pSprite->fPosY > SCREEN_HEIGHT - SPRITE_DIAMETER )
{
pSprite->fPosY = SCREEN_HEIGHT - 1 - SPRITE_DIAMETER;
pSprite->fVelY = -pSprite->fVelY;
}
}
//-----------------------------------------------------------------------------
// Name: DisplayFrame()
// Desc: Blts a the sprites to the back buffer, then it blts or flips the
// back buffer onto the primary buffer.
//-----------------------------------------------------------------------------
HRESULT DisplayFrame()
{
HRESULT hr;
// Fill the back buffer with black, ignoring errors until the flip
g_pDisplay->Clear( 0 );
// Blt the help text on the backbuffer, ignoring errors until the flip
g_pDisplay->Blt( 10, 10, g_pTextSurface, NULL );
// Blt all the sprites onto the back buffer using color keying,
// ignoring errors until the flip. Note that all of these sprites
// use the same DirectDraw surface.
for( int iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
{
g_pDisplay->Blt( (DWORD)g_Sprite[iSprite].fPosX,
(DWORD)g_Sprite[iSprite].fPosY,
g_pLogoSurface, NULL );
}
// Flip or blt the back buffer onto the primary buffer
if( FAILED( hr = g_pDisplay->Present() ) )
return hr;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: RestoreSurfaces()
// Desc: Restore all the surfaces, and redraw the sprite surfaces.
//-----------------------------------------------------------------------------
HRESULT RestoreSurfaces()
{
HRESULT hr;
LPDIRECTDRAWPALETTE pDDPal = NULL;
if( FAILED( hr = g_pDisplay->GetDirectDraw()->RestoreAllSurfaces() ) )
return hr;
// No need to re-create the surface, just re-draw it.
// We need to release and re-load, and set the palette again to
if( FAILED( hr = g_pDisplay->CreatePaletteFromBitmap( &pDDPal, MAKEINTRESOURCE( IDB_DIRECTX ) ) ) )
return hr;
g_pDisplay->SetPalette( pDDPal );
SAFE_RELEASE( pDDPal );
// No need to re-create the surface, just re-draw it.
if( FAILED( hr = g_pLogoSurface->DrawBitmap( MAKEINTRESOURCE( IDB_DIRECTX ),
SPRITE_DIAMETER, SPRITE_DIAMETER ) ) )
return hr;
if( g_bWindowed )
{
// No need to re-create the surface, just re-draw it.
if( FAILED( hr = g_pTextSurface->DrawText( NULL, WINDOWED_HELPTEXT,
0, 0, RGB(0,0,0), RGB(255, 255, 0) ) ) )
return hr;
}
else
{
// No need to re-create the surface, just re-draw it.
if( FAILED( hr = g_pTextSurface->DrawText( NULL, FULLSCREEN_HELPTEXT,
0, 0, RGB(0,0,0), RGB(255, 255, 0) ) ) )
return hr;
}
return S_OK;
}

View File

@@ -0,0 +1,143 @@
# Microsoft Developer Studio Project File - Name="SwitchScreenMode" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=SwitchScreenMode - Win32 Release
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "switchscreenmode.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "switchscreenmode.mak" CFG="SwitchScreenMode - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "SwitchScreenMode - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "SwitchScreenMode - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "SwitchScreenMode - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir ".\Release"
# PROP BASE Intermediate_Dir ".\Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir ".\Release"
# PROP Intermediate_Dir ".\Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /GX /O2 /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /machine:I386 /stack:0x200000,0x200000
!ELSEIF "$(CFG)" == "SwitchScreenMode - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir ".\Debug"
# PROP BASE Intermediate_Dir ".\Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir ".\Debug"
# PROP Intermediate_Dir ".\Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386
# ADD LINK32 winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /debug /machine:I386 /stack:0x200000,0x200000
!ENDIF
# Begin Target
# Name "SwitchScreenMode - Win32 Release"
# Name "SwitchScreenMode - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90"
# Begin Source File
SOURCE=.\SwitchScreenMode.cpp
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
# Begin Source File
SOURCE=.\directx.bmp
# End Source File
# Begin Source File
SOURCE=.\DirectX.ico
# End Source File
# Begin Source File
SOURCE=..\SpriteAnimate\resource.h
# End Source File
# Begin Source File
SOURCE=.\SwitchScreenMode.rc
# End Source File
# End Group
# Begin Group "Common"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\common\src\ddutil.cpp
# End Source File
# Begin Source File
SOURCE=..\..\common\include\ddutil.h
# End Source File
# Begin Source File
SOURCE=..\..\common\src\dxutil.cpp
# End Source File
# Begin Source File
SOURCE=..\..\common\include\dxutil.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "SwitchScreenMode"=.\switchscreenmode.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,221 @@
# Microsoft Developer Studio Generated NMAKE File, Based on switchscreenmode.dsp
!IF "$(CFG)" == ""
CFG=SwitchScreenMode - Win32 Release
!MESSAGE No configuration specified. Defaulting to SwitchScreenMode - Win32 Release.
!ENDIF
!IF "$(CFG)" != "SwitchScreenMode - Win32 Release" && "$(CFG)" != "SwitchScreenMode - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "switchscreenmode.mak" CFG="SwitchScreenMode - Win32 Release"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "SwitchScreenMode - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "SwitchScreenMode - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "SwitchScreenMode - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\switchscreenmode.exe"
CLEAN :
-@erase "$(INTDIR)\ddutil.obj"
-@erase "$(INTDIR)\dxutil.obj"
-@erase "$(INTDIR)\SwitchScreenMode.obj"
-@erase "$(INTDIR)\SwitchScreenMode.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\switchscreenmode.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "..\..\common\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\switchscreenmode.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\SwitchScreenMode.res" /d "NDEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\switchscreenmode.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:no /pdb:"$(OUTDIR)\switchscreenmode.pdb" /machine:I386 /out:"$(OUTDIR)\switchscreenmode.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\SwitchScreenMode.obj" \
"$(INTDIR)\ddutil.obj" \
"$(INTDIR)\dxutil.obj" \
"$(INTDIR)\SwitchScreenMode.res"
"$(OUTDIR)\switchscreenmode.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "SwitchScreenMode - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\switchscreenmode.exe"
CLEAN :
-@erase "$(INTDIR)\ddutil.obj"
-@erase "$(INTDIR)\dxutil.obj"
-@erase "$(INTDIR)\SwitchScreenMode.obj"
-@erase "$(INTDIR)\SwitchScreenMode.res"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\switchscreenmode.exe"
-@erase "$(OUTDIR)\switchscreenmode.ilk"
-@erase "$(OUTDIR)\switchscreenmode.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /I "..\..\common\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /Fp"$(INTDIR)\switchscreenmode.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR)\SwitchScreenMode.res" /d "_DEBUG"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\switchscreenmode.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=winmm.lib dxguid.lib dxerr8.lib ddraw.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:windows /incremental:yes /pdb:"$(OUTDIR)\switchscreenmode.pdb" /debug /machine:I386 /out:"$(OUTDIR)\switchscreenmode.exe" /stack:0x200000,0x200000
LINK32_OBJS= \
"$(INTDIR)\SwitchScreenMode.obj" \
"$(INTDIR)\ddutil.obj" \
"$(INTDIR)\dxutil.obj" \
"$(INTDIR)\SwitchScreenMode.res"
"$(OUTDIR)\switchscreenmode.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("switchscreenmode.dep")
!INCLUDE "switchscreenmode.dep"
!ELSE
!MESSAGE Warning: cannot find "switchscreenmode.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "SwitchScreenMode - Win32 Release" || "$(CFG)" == "SwitchScreenMode - Win32 Debug"
SOURCE=.\SwitchScreenMode.cpp
"$(INTDIR)\SwitchScreenMode.obj" : $(SOURCE) "$(INTDIR)"
SOURCE=.\SwitchScreenMode.rc
"$(INTDIR)\SwitchScreenMode.res" : $(SOURCE) "$(INTDIR)"
$(RSC) $(RSC_PROJ) $(SOURCE)
SOURCE=..\..\common\src\ddutil.cpp
"$(INTDIR)\ddutil.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
SOURCE=..\..\common\src\dxutil.cpp
"$(INTDIR)\dxutil.obj" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) $(SOURCE)
!ENDIF

View File

@@ -0,0 +1,108 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include <windows.h>
#include <afxres.h>
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
IDR_MENU MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "Toggle Full-Screen\tAlt+Enter", IDM_TOGGLEFULLSCREEN
MENUITEM SEPARATOR
MENUITEM "E&xit\tAlt+X", IDM_EXIT
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_MAIN ICON DISCARDABLE "DirectX.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include <windows.h>\r\n"
"#include <afxres.h>\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDR_MAIN_ACCEL ACCELERATORS DISCARDABLE
BEGIN
VK_ESCAPE, IDM_EXIT, VIRTKEY, NOINVERT
VK_RETURN, IDM_TOGGLEFULLSCREEN, VIRTKEY, ALT, NOINVERT
"X", IDM_EXIT, VIRTKEY, ALT, NOINVERT
END
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//
IDB_DIRECTX BITMAP DISCARDABLE "directx.bmp"
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,85 @@
//-----------------------------------------------------------------------------
//
// Sample Name: WindowedMode Sample
//
// Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
Description
===========
WindowedMode demonstrates the tasks required to initialize and run
a windowed DirectDraw application.
Path
====
Source: DXSDK\Samples\Multimedia\DDraw\WindowedMode
Executable: DXSDK\Samples\Multimedia\DDraw\Bin
User's Guide
============
WindowedMode requires no user input. Press the ESC key to quit the program.
Programming Notes
=================
The basic tasks to author a simple windowed DirectDraw application are as follows:
Initialize DirectDraw:
1. Register a window class and create a window.
2. Call DirectDrawCreateEx to create a DirectDraw object
3. Call SetCooperativeLevel to set the DirectDraw cooperative level
to normal.
4. Call CreateSurface to obtain a pointer to the primary surface. In windowed mode,
the primary surface is also the desktop window. So the pixel format for the
primary surface is based on the user's selection of display resolution.
5. Create a back-buffer. In windowed mode, this is should be an off-screen
plain buffer. The back buffer is typically the same size as the window's
client rect, but could be created with any size.
6. Test to see if the display mode is in palettized color (8-bit or less).
If it is then a palette needs to be created. This sample displays a single
bitmap so it can read the bitmap palette info to read and create a DirectDraw
palette. After a palette is created, call SetPalette to set the palette for
the primary surface.
7. Call CreateClipper and SetClipper to create a clipper object, and attach it
to the primary surface. This will keep DirectDraw from blting on top of
any windows which happen to overlap.
8. Create an off-screen plain DirectDraw surface, and load media content into it.
For example, this sample calls DDUtil_CreateSurfaceFromBitmap() to do just
this.
When the app is idle, and it is not hidden or minimized then render the
next frame by:
1. If movement or animation is involved in the app, then calculate how much
time has passed since the last time the frame was displayed.
2. Move or animate the app state based on how much time has passed.
3. Draw the current state into the off-screen plain backbuffer.
4. Call Blt to blt the contents of the off-screen plain backbuffer into
the primary surface.
If the display resolution changes or an exclusive mode DirectDraw app is run, then
the DirectDraw surface may be lost (resulting in a DirectDraw call returning
DDERR_SURFACELOST), then handle it by:
1. Call RestoreAllSurfaces to have DirectDraw restore all the surfaces.
2. Restoring a surface doesn't reload any content that existed in the surface
prior to it being lost. So you must now redraw the graphics the surfaces
once held. For example, this sample handles this by calling
DDUtil_ReDrawBitmapOnDDS()
In windowed mode, handle the following windows messages:
1. WM_PAINT: This is sent when all or a part of the window is needs to be
redrawn. The app may not be active at the time this is called, so if this
is not handled then the window will appear blank. To avoid this, make a
call to draw the next frame here.
2. WM_QUERYNEWPALETTE: This is sent when in a 8-bit desktop and the another
window set a new palette, but now this window has control so it needs to reset
its palette. The easy way to make this happen in DirectDraw is just to call
SetPalette. This will force DirectDraw to realize the DirectDrawPalette
attached to it.
3. WM_MOVE: This is sent when the window is moving. Record the new window position
here since the blt to the primary surface needs to know the window position.

View File

@@ -0,0 +1,21 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by WindowedMode.rc
//
#define IDI_MAIN 101
#define IDR_MENU 102
#define IDR_MAIN_ACCEL 103
#define IDB_DIRECTX 107
#define IDM_EXIT 1001
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 108
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 104
#endif
#endif

Some files were not shown because too many files have changed in this diff Show More