Help with Direct X and Win32......:D

This is a discussion on Help with Direct X and Win32......:D within the Windows Programming forums, part of the Platform Specific Boards category; Ok, I am going to make the part of the code that I am having problems with, Thank you in ...

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Help with Direct X and Win32......:D

    Ok, I am going to make the part of the code that I am having problems with, Thank you in advance.


    Code:
    /*****************************************************************************
    IsoHex5_1.cpp
    Ernest S. Pazera
    21MAY2000
    Start a WIN32 Application Workspace, add in this file
    Needs ddraw.lib and dxguid.lib
    *****************************************************************************/
    
    //////////////////////////////////////////////////////////////////////////////
    //INCLUDES
    //////////////////////////////////////////////////////////////////////////////
    #define WIN32_LEAN_AND_MEAN  
    
    #include <windows.h>   
    #include "ddraw.h"
    
    //////////////////////////////////////////////////////////////////////////////
    //DEFINES
    //////////////////////////////////////////////////////////////////////////////
    //name for our window class
    #define WINDOWCLASS "ISOHEX5"
    //title of the application
    #define WINDOWTITLE "IsoHex 5-1"
    
    //////////////////////////////////////////////////////////////////////////////
    //PROTOTYPES
    //////////////////////////////////////////////////////////////////////////////
    bool Prog_Init();//game data initalizer
    void Prog_Loop();//main game loop
    void Prog_Done();//game clean up
    
    //enumeration functions
    HRESULT WINAPI EnumModesCallbackCount(LPDDSURFACEDESC2 lpDDSurfaceDesc, LPVOID lpContext);
    HRESULT WINAPI EnumModesCallbackList(LPDDSURFACEDESC2 lpDDSurfaceDesc,LPVOID lpContext);
    
    
    //////////////////////////////////////////////////////////////////////////////
    //GLOBALS
    //////////////////////////////////////////////////////////////////////////////
    HINSTANCE hInstMain=NULL;//main application handle
    HWND hWndMain=NULL;//handle to our main window
    //IDirectDraw7 Pointer
    LPDIRECTDRAW7 lpdd=NULL;
    //display mode structure
    struct DisplayMode
    {
    	DWORD dwWidth;
    	DWORD dwHeight;
    	DWORD dwBPP;
    };
    //display mode enumeration variables
    DWORD dwDisplayModeCount=0;
    DisplayMode* DisplayModeList=NULL;
    
    //////////////////////////////////////////////////////////////////////////////
    //WINDOWPROC
    //////////////////////////////////////////////////////////////////////////////
    LRESULT CALLBACK TheWindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
    {
    	//which message did we get?
    	switch(uMsg)
    	{
    	case WM_KEYDOWN:
    		{
    			//check for escape key
    			if(wParam==VK_ESCAPE)
    			{
    				DestroyWindow(hWndMain);
    			}
    
    			return(0);//handled message
    		}break;
    	case WM_DESTROY://the window is being destroyed
    		{
    
    			//tell the application we are quitting
    			PostQuitMessage(0);
    
    			//handled message, so return 0
    			return(0);
    
    		}break;
    	case WM_PAINT://the window needs repainting
    		{
    			//a variable needed for painting information
    			PAINTSTRUCT ps;
    			
    			//start painting
    			HDC hdc=BeginPaint(hwnd,&ps);
    
    			/////////////////////////////
    			//painting code would go here
    			/////////////////////////////
    
    			//end painting
    			EndPaint(hwnd,&ps);
    						
    			//handled message, so return 0
    			return(0);
    		}break;
    	}
    
    	//pass along any other message to default message handler
    	return(DefWindowProc(hwnd,uMsg,wParam,lParam));
    }
    
    
    //////////////////////////////////////////////////////////////////////////////
    //WINMAIN
    //////////////////////////////////////////////////////////////////////////////
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
    {
    	//assign instance to global variable
    	hInstMain=hInstance;
    
    	//create window class
    	WNDCLASSEX wcx;
    
    	//set the size of the structure
    	wcx.cbSize=sizeof(WNDCLASSEX);
    
    	//class style
    	wcx.style=CS_OWNDC | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
    
    	//window procedure
    	wcx.lpfnWndProc=TheWindowProc;
    
    	//class extra
    	wcx.cbClsExtra=0;
    
    	//window extra
    	wcx.cbWndExtra=0;
    
    	//application handle
    	wcx.hInstance=hInstMain;
    
    	//icon
    	wcx.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    
    	//cursor
    	wcx.hCursor=LoadCursor(NULL,IDC_ARROW);
    
    	//background color
    	wcx.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
    
    	//menu
    	wcx.lpszMenuName=NULL;
    
    	//class name
    	wcx.lpszClassName=WINDOWCLASS;
    
    	//small icon
    	wcx.hIconSm=NULL;
    
    	//register the window class, return 0 if not successful
    	if(!RegisterClassEx(&wcx)) return(0);
    
    	//create main window
    	hWndMain=CreateWindowEx(0,WINDOWCLASS,WINDOWTITLE, WS_POPUP | WS_VISIBLE,0,0,320,240,NULL,NULL,hInstMain,NULL);
    
    	//error check
    	if(!hWndMain) return(0);
    
    	//if program initialization failed, then return with 0
    	if(!Prog_Init()) return(0);
    
    	//message structure
    	MSG msg;
    
    	//message pump
    	for(;;)	
    	{
    		//look for a message
    		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    		{
    			//there is a message
    
    			//check that we arent quitting
    			if(msg.message==WM_QUIT) break;
    			
    			//translate message
    			TranslateMessage(&msg);
    
    			//dispatch message
    			DispatchMessage(&msg);
    		}
    
    		//run main game loop
    		Prog_Loop();
    	}
    	
    	//clean up program data
    	Prog_Done();
    
    	//return the wparam from the WM_QUIT message
    	return(msg.wParam);
    }
    
    //////////////////////////////////////////////////////////////////////////////
    //INITIALIZATION
    //////////////////////////////////////////////////////////////////////////////
    bool Prog_Init()
    {
    	//error code 
    	HRESULT hr;
    
    	//initialize the dd pointer
    	hr=DirectDrawCreateEx(NULL,(void**)&lpdd,IID_IDirectDraw7,NULL);
    
    	//example for error handling
    	if(FAILED(hr))
    	{
    		//initialization failed
    		return(false);
    	}
    
    	//set the cooperative level
    	lpdd->SetCooperativeLevel(hWndMain,DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT);
    
    	//enumerate the displaymodes
    	dwDisplayModeCount=0;
    
    	lpdd->EnumDisplayModes(0,NULL,NULL,EnumModesCallbackCount);
    
    	DisplayModeList=new DisplayMode[dwDisplayModeCount];
    	dwDisplayModeCount=0;
    
    	lpdd->EnumDisplayModes (0,NULL,NULL,EnumModesCallbackList);
    
    	//pick a display mode
    	DisplayMode TestMode;
    	TestMode.dwWidth=0;
    	TestMode.dwHeight=0;
    	TestMode.dwBPP=0;
    	DWORD index;
    	bool found=false;
    
    	for(index=0;(index<dwDisplayModeCount);index++)
    	{
    		if(DisplayModeList[index].dwBPP==16)
    		{
    			if(DisplayModeList[index].dwWidth>TestMode.dwWidth)
    			{
    				TestMode.dwWidth=DisplayModeList[index].dwWidth;
    				TestMode.dwHeight=DisplayModeList[index].dwHeight;
    				TestMode.dwBPP=DisplayModeList[index].dwBPP;
    				found=true;
    			}
    		}
    	}
    
    	if(!found)
    	{
    		return(false);
    	}
    
    	//set the display mode
    	hr=lpdd->SetDisplayMode(TestMode.dwWidth,TestMode.dwHeight,TestMode.dwBPP,0,0);
    
    	return(true);//return success
    }
    
    //////////////////////////////////////////////////////////////////////////////
    //CLEANUP
    //////////////////////////////////////////////////////////////////////////////
    void Prog_Done()
    {
    	//clean up the dd pointer
    	if(lpdd)
    	{
    		lpdd->Release();
    		lpdd=NULL;
    	}
    
    	//get rid of enumeration stuff
    	delete [] DisplayModeList;
    }
    
    //////////////////////////////////////////////////////////////////////////////
    //MAIN GAME LOOP
    //////////////////////////////////////////////////////////////////////////////
    void Prog_Loop()
    {
    	///////////////////////////
    	//main game logic goes here
    	///////////////////////////
    }
    
    //enumeration-count
    HRESULT WINAPI EnumModesCallbackCount(
      LPDDSURFACEDESC2 lpDDSurfaceDesc,  
      LPVOID lpContext                   
    )
    {
    	//increment the count variable
    	dwDisplayModeCount++;
    
    	//continue the enumeration
    	return(DDENUMRET_OK);
    }
    
    //enumeration-list
    HRESULT WINAPI EnumModesCallbackList(
      LPDDSURFACEDESC2 lpDDSurfaceDesc,  
      LPVOID lpContext                   
    )
    {
    	//copy applicable information to the list
    	DisplayModeList[dwDisplayModeCount].dwWidth=lpDDSurfaceDesc->dwWidth;
    	DisplayModeList[dwDisplayModeCount].dwHeight=lpDDSurfaceDesc->dwHeight;
    	DisplayModeList[dwDisplayModeCount].dwBPP=lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount;
    
    	//increment the count variable
    	dwDisplayModeCount++;
    
    	//continue the enumeration
    	return(DDENUMRET_OK);
    }
    
    
    
    
    [b][i] is this like talking directly to your video card or something? Like here.......When this is called 
    
    
    HRESULT WINAPI EnumModesCallbackCount(
      LPDDSURFACEDESC2 lpDDSurfaceDesc,  
      LPVOID lpContext                   
    )
    {
    	//increment the count variable
    	dwDisplayModeCount++;
    
    	//continue the enumeration
    	return(DDENUMRET_OK);
    }
    
    Is this talking to your video card and "asking" it things? 
    Like here.....
    
    HRESULT WINAPI EnumModesCallbackList(
      LPDDSURFACEDESC2 lpDDSurfaceDesc,  
      LPVOID lpContext                   
    )
    {
    	//copy applicable information to the list
    	DisplayModeList[dwDisplayModeCount].dwWidth=lpDDSurfaceDesc->dwWidth;
    	DisplayModeList[dwDisplayModeCount].dwHeight=lpDDSurfaceDesc->dwHeight;
    	DisplayModeList[dwDisplayModeCount].dwBPP=lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount;
    
    	//increment the count variable
    	dwDisplayModeCount++;
    
    	//continue the enumeration
    	return(DDENUMRET_OK);
    }
    
    Is this "talking" to the video card and getting that information through LPDDSURFACEDESC2 lpDDSurfaceDesc or something? 
    
    Ok, if I am not making any sense, I won't blame, I am not sure I am even making sense to myself. Thank you once again.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    It's not getting the info "through" the DDSURFACEDESC2
    structure. It's getting the possible display modes from the video
    card and putting that data into the DDSURFACEDESC2.

    Then it runs through each DDSURFACEDESC2 structure to see if
    the a desired display mode is available. If so, it reset the display
    mode in DirectDraw to it.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21