Click here to Skip to main content
15,916,600 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC Question Pin
Bob Stanneveld20-Jul-03 22:19
Bob Stanneveld20-Jul-03 22:19 
GeneralRe: MFC Question Pin
DaveE9th21-Jul-03 6:45
DaveE9th21-Jul-03 6:45 
GeneralRe: MFC Question Pin
Bob Stanneveld21-Jul-03 8:25
Bob Stanneveld21-Jul-03 8:25 
GeneralRe: MFC Question Pin
DaveE9th21-Jul-03 20:28
DaveE9th21-Jul-03 20:28 
Questionhow to generate GUID programatically in VC6 Pin
Anonymous20-Jul-03 21:28
Anonymous20-Jul-03 21:28 
AnswerRe: how to generate GUID programatically in VC6 Pin
Dominik Reichl20-Jul-03 21:38
Dominik Reichl20-Jul-03 21:38 
GeneralRe: how to generate GUID programatically in VC6 Pin
Ryan Binns20-Jul-03 22:31
Ryan Binns20-Jul-03 22:31 
GeneralNeed help with program Pin
DaveE9th20-Jul-03 21:10
DaveE9th20-Jul-03 21:10 
I have two questions:

First, I'm trying to get the following program to work. I keep getting an error message that the "DDRAW.LIB" include file cannot be found. I did go into TOOLS/OPTIONS to specify the WINDOWS/SYSTEM directory where the Ddraw.dll is located. What am I doing wrong? The compiler still can't find DDRAW.LIB.

Second, I can see in the program below that there are definitions that need to go into a header file, but I'm not sure what to place in the header file. COuld someone please help me out with this? Thanks much, Dave


<br />
// LISTING 1.0 - DIRECT X 5.0 GAME CONSOLE ////////////////////////////////////<br />
<br />
// INCLUDES ///////////////////////////////////////////////////////////////////<br />
<br />
#define WIN32_LEAN_AND_MEAN // make sure certain headers are included correctly<br />
<br />
#include windows.h  // include the standard windows stuff<br />
#include windowsx.h // include the 32 bit stuff<br />
#include mmsystem.h // include the multi media stuff<br />
                            // note you need winmm.lib also<br />
#include ddraw.h    // include direct draw components<br />
<br />
#include stdlib.h   // include all the good stuff<br />
#include stdio.h<br />
#include math.h<br />
#include float.h<br />
<br />
// DEFINES ////////////////////////////////////////////////////////////////////<br />
<br />
#define WINDOW_CLASS_NAME "WINDOW_CLASS" // this is the name of the window class<br />
<br />
// defines for screen parameters<br />
<br />
#define SCREEN_WIDTH 640   // the width of the viewing surface<br />
#define SCREEN_HEIGHT 480  // the height of the viewing surface<br />
#define SCREEN_BPP 8       // the bits per pixel<br />
#define MAX_COLORS 256     // the maximum number of colors<br />
<br />
// TYPES //////////////////////////////////////////////////////////////////////<br />
<br />
typedef unsigned char UCHAR;<br />
<br />
// MACROS /////////////////////////////////////////////////////////////////////<br />
<br />
// these query the keyboard in real-time<br />
<br />
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)<br />
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)<br />
<br />
// PROTOTYPES /////////////////////////////////////////////////////////////////<br />
<br />
int DD_Init(HWND hwnd);<br />
int DD_Shutdown(void);<br />
int Set_Pal_Entry(int index, int red, int green, int blue);<br />
<br />
void Game_Init(void);<br />
void Game_Main(void);<br />
void Game_Shutdown(void);<br />
<br />
// DIRECTDRAW GLOBALS ////////////////////////////////////////////////////////<br />
<br />
LPDIRECTDRAW lpdd = NULL;                // dd object<br />
LPDIRECTDRAWSURFACE lpddsprimary = NULL; // dd primary surface<br />
LPDIRECTDRAWPALETTE lpddpal = NULL;      // a pointer to the created dd palette<br />
PALETTEENTRY color_palette[256];         // holds the shadow palette entries<br />
DDSURFACEDESC ddsd;               // a direct draw surface description struct<br />
DDSCAPS ddscaps;                  // a direct draw surface capabilities struct<br />
HRESULT ddrval;                   // result back from dd calls<br />
HWND main_window_handle = NULL;   // used to store the window handle<br />
UCHAR *video_buffer = NULL;       // pointer to video ram<br />
<br />
<br />
// GAME GLOBALS GO HERE ///////////////////////////////////////////////////// <br />
<br />
// DIRECT X FUNCTIONS /////////////////////////////////////////////////////////<br />
<br />
int DD_Init(HWND hwnd)<br />
{<br />
    // this function is responsible for initializing direct draw, it creates a<br />
    // primary surface <br />
<br />
    int index; // looping index<br />
<br />
    // now that the windows portion is complete, start up direct draw<br />
    if (DirectDrawCreate(NULL,&lpdd,NULL)!=DD_OK)<br />
    {<br />
        // shutdown any other dd objects and kill window<br />
        DD_Shutdown();<br />
        return(0);<br />
    } // end if<br />
<br />
    // now set the coop level to exclusive and set for full screen and mode x<br />
    if (lpdd->SetCooperativeLevel(hwnd, DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE |<br />
        DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX)!=DD_OK)<br />
    {<br />
        // shutdown any other dd objects and kill window<br />
        DD_Shutdown();<br />
        return(0);<br />
    } // end if<br />
<br />
    // now set the display mode<br />
    if (lpdd->SetDisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP)!=DD_OK)<br />
    {<br />
        // shutdown any other dd objects and kill window<br />
        DD_Shutdown();<br />
        return(0);<br />
    } // end if<br />
<br />
    // Create the primary surface<br />
    ddsd.dwSize = sizeof(ddsd);<br />
    ddsd.dwFlags = DDSD_CAPS;<br />
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;<br />
<br />
    if<br />
    (lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL)!=DD_OK)<br />
    {<br />
        // shutdown any other dd objects and kill window<br />
        DD_Shutdown();<br />
        return(0);<br />
    } // end if<br />
<br />
    // create the palette and attach it to the primary surface<br />
<br />
    // clear all the palette entries to RGB 0,0,0<br />
    memset(color_palette,0,256*sizeof(PALETTEENTRY));<br />
    <br />
    // set all of the flags to the correct value<br />
    for (index=0; index<256; index++)<br />
    {<br />
        // create the GRAY/RED/GREEN/BLUE palette, 64 shades of each<br />
        if ((index / 64)==0)<br />
        {<br />
            color_palette[index].peRed = index*4;<br />
            color_palette[index].peGreen = index*4;<br />
            color_palette[index].peBlue = index*4;<br />
        } // end if<br />
        else<br />
        if ((index / 64)==1)<br />
            color_palette[index].peRed = (index%64)*4;<br />
        else<br />
        if ((index / 64)==2) <br />
            color_palette[index].peGreen = (index%64)*4;<br />
        else<br />
        if ((index / 64)==3)<br />
            color_palette[index].peBlue = (index%64)*4;<br />
<br />
        // set the no collapse flag<br />
        color_palette[index].peFlags = PC_NOCOLLAPSE;<br />
<br />
    } // end for index<br />
<br />
    // now create the palette object, note that it is a member of the dd object itself<br />
    if (lpdd->CreatePalette((DDPCAPS_8BIT | DDPCAPS_INITIALIZE),color_palette,&lpddpal,NULL)!=DD_OK)<br />
    {<br />
        // shutdown any other dd objects and kill window<br />
        DD_Shutdown();<br />
        return(0);<br />
    } // end if<br />
<br />
    // now attach the palette to the primary surface<br />
    lpddsprimary->SetPalette(lpddpal);<br />
<br />
    // return success if we got this far<br />
    return(1);<br />
<br />
} // end DD_Init<br />
<br />
///////////////////////////////////////////////////////////////////////////////<br />
<br />
int DD_Shutdown(void)<br />
{<br />
    // this function tests for dd components that have been created and releases<br />
    // them back to the operating system<br />
<br />
    // test if the dd object exists<br />
    if (lpdd)<br />
    {<br />
        // test if there is a primary surface<br />
        if(lpddsprimary)<br />
        {<br />
            // release the memory and set pointer to NULL<br />
            lpddsprimary->Release();<br />
            lpddsprimary = NULL;<br />
        } // end if<br />
<br />
        // now release the dd object itself<br />
        lpdd->Release();<br />
        lpdd = NULL;<br />
<br />
        // return success<br />
        return(1);<br />
<br />
    } // end if<br />
    else<br />
        return(0);<br />
<br />
} // end DD_Shutdown<br />
<br />
//////////////////////////////////////////////////////////////////////////////<br />
<br />
int Set_Pal_Entry(int index, int red, int green, int blue)<br />
{<br />
    // this function sets a palette entry with the sent color<br />
<br />
    PALETTEENTRY color; // used to build up color<br />
<br />
    // set RGB value in structure<br />
    color.peRed = (BYTE)red;<br />
    color.peGreen = (BYTE)green;<br />
    color.peBlue = (BYTE)blue;<br />
    color.peFlags = PC_NOCOLLAPSE;<br />
<br />
    // set the color palette entry<br />
    lpddpal->SetEntries(0,index,1,&color);<br />
<br />
    // make copy in shadow palette<br />
    memcpy(&color_palette[index],<br />
        &color,<br />
        sizeof(PALETTEENTRY));<br />
<br />
    // return success<br />
    return(1);<br />
<br />
} // end Set_Pal_Entry<br />
<br />
// WINDOWS CALLBACK FUNCTION ////////////////////////////////////////////////// <br />
<br />
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)<br />
{<br />
    // this is the main message handler of the system<br />
<br />
    HDC hdc; // handle to graphics context<br />
    PAINTSTRUCT ps; // used to hold the paint info<br />
<br />
    // what is the message?<br />
<br />
    switch(msg)<br />
    { <br />
    case WM_CREATE:<br />
        {<br />
            // do windows inits here<br />
            return(0);<br />
        } break;<br />
<br />
    case WM_PAINT:<br />
        {<br />
            // this message occurs when your window needs repainting<br />
            hdc = BeginPaint(hwnd,&ps); <br />
            EndPaint(hdc,&ps);<br />
<br />
            return(0);<br />
        } break;<br />
<br />
    case WM_DESTROY:<br />
        {<br />
            // this message is sent when your window is destroyed<br />
            PostQuitMessage(0);<br />
            return(0);<br />
        } break;<br />
<br />
    default:break;<br />
<br />
    } // end switch<br />
<br />
    // let windows process any messages that we didn't take care of <br />
    return (DefWindowProc(hwnd, msg, wparam, lparam));<br />
<br />
} // end WinProc<br />
<br />
// WINMAIN ////////////////////////////////////////////////////////////////////<br />
<br />
int WINAPI WinMain( HINSTANCE hinstance,<br />
                    HINSTANCE hprevinstance,<br />
                    LPSTR lpcmdline,<br />
                    int ncmdshow)<br />
{<br />
    WNDCLASSEX winclass;  // this holds the windows class info<br />
    HWND hwnd;            // this holds the handle of our new window<br />
    MSG msg;              // this holds a generic message<br />
<br />
    // first fill in the window class stucture<br />
<br />
    winclass.cbSize = sizeof(WNDCLASSEX);<br />
    winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;<br />
    winclass.lpfnWndProc = WindowProc;<br />
    winclass.cbClsExtra = 0;<br />
    winclass.cbWndExtra = 0;<br />
    winclass.hInstance = hinstance;<br />
    winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);<br />
    winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);<br />
    winclass.hCursor = LoadCursor(NULL, IDC_ARROW);<br />
    winclass.hbrBackground = GetStockObject(BLACK_BRUSH);<br />
    winclass.lpszMenuName = NULL;<br />
    winclass.lpszClassName = WINDOW_CLASS_NAME;<br />
<br />
    // register the window class<br />
    if (!RegisterClassEx(&winclass))<br />
        return(0);<br />
<br />
    // create the window<br />
    if (!(hwnd = CreateWindowEx(WS_EX_TOPMOST,<br />
            WINDOW_CLASS_NAME,      // class<br />
            "You can't See This!",  // title<br />
            WS_VISIBLE | WS_POPUP,<br />
            0,0, // x,y<br />
            GetSystemMetrics(SM_CXSCREEN),<br />
            GetSystemMetrics(SM_CYSCREEN), <br />
            NULL,           // parent<br />
            NULL,           // menu<br />
            hinstance,      // instance<br />
            NULL)))         // creation parms<br />
        return(0);<br />
<br />
    // hide the mouse cursor<br />
    ShowCursor(0);<br />
<br />
    // save the window handle<br />
    main_window_handle = hwnd;<br />
<br />
    // initialize direct draw<br />
    if (!DD_Init(hwnd))<br />
    {<br />
        DestroyWindow(hwnd);<br />
        return(0);<br />
    } // end if<br />
<br />
    // initialize game<br />
    Game_Init();<br />
<br />
    // enter main event loop<br />
    while(1)<br />
    {<br />
        if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))<br />
        { <br />
            // test if this is a quit<br />
            if (msg.message == WM_QUIT)<br />
                break;<br />
<br />
            // translate any accelerator keys<br />
            TranslateMessage(&msg);<br />
<br />
            // send the message to the window proc<br />
            DispatchMessage(&msg);<br />
        } // end if<br />
        else<br />
        {<br />
            // do asynchronous processing here<br />
<br />
            // acquire pointer to video ram, note it is always linear<br />
            memset(&ddsd,0,sizeof(ddsd));<br />
            ddsd.dwSize = sizeof(ddsd);<br />
            lpddsprimary->Lock(NULL,&ddsd,DDLOCK_SURFACEMEMORYPTR,NULL);<br />
            video_buffer = (UCHAR *)ddsd.lpSurface;<br />
<br />
            // call main logic module<br />
            Game_Main();<br />
<br />
            // release pointer to video ram<br />
            lpddsprimary->Unlock(ddsd.lpSurface);<br />
<br />
        } // end else<br />
<br />
    } // end while<br />
<br />
    // shut down direct draw<br />
    DD_Shutdown();<br />
<br />
    // shutdown game<br />
    Game_Shutdown();<br />
<br />
    // return to Windows<br />
    return(msg.wParam);<br />
<br />
} // end WinMain<br />
<br />
// HERE ARE OUR GAME CONSOLE FUNCTIONS ///////////////////////////////////////////////////////<br />
<br />
void Game_Init(void)<br />
{<br />
    // do any initialization here<br />
} // end Game_Init<br />
<br />
/////////////////////////////////////////////////////////////////////////////////////////////<br />
<br />
void Game_Shutdown(void)<br />
{<br />
    // cleanup and release all resources here<br />
} // end Game_Shutdown<br />
<br />
/////////////////////////////////////////////////////////////////////////////////////////////<br />
<br />
void Game_Main(void)<br />
{<br />
    // process your game logic and draw next frame<br />
    // this function must exit each frame and return back to windows<br />
    // also this function is responsible for controlling the frame rate<br />
    // therefore, if you want the game to run at 30fps, then the function should<br />
    // take 1/30th of a second before returning<br />
<br />
    static int px = SCREEN_WIDTH/2,  // position of player<br />
    py = SCREEN_HEIGHT/2,<br />
    color = 0;                       // color of blob 0..3, gray, red, green, blue<br />
<br />
    // on entry video_buffer is valid<br />
<br />
    // get input, note how keyboard is accessed with constants<br />
    "VK_"<br />
    // these are defined in "winuser.h" are basically the<br />
    scan codes<br />
    // for letters just use capital ASCII codes<br />
<br />
    if (KEY_DOWN(VK_ESCAPE))<br />
        PostMessage(main_window_handle,WM_CLOSE,0,0); // this is how you exit you game<br />
<br />
    // which way is player moving<br />
    if (KEY_DOWN(VK_RIGHT))<br />
        if (++px>SCREEN_WIDTH-8) px=8;<br />
<br />
    if (KEY_DOWN(VK_LEFT))<br />
        if (--px<8) px=SCREEN_WIDTH-8;<br />
<br />
    if (KEY_DOWN(VK_UP))<br />
        if (--py<8) py=SCREEN_HEIGHT-8;<br />
<br />
    if (KEY_DOWN(VK_DOWN))<br />
        if (++py>SCREEN_HEIGHT-8) py=8;<br />
<br />
    // adjust color, notice <br />
    if (KEY_DOWN('C'))<br />
    {<br />
        if (++color>=4)<br />
        color=0;<br />
        Sleep(100);<br />
    } // end if<br />
<br />
    // draw graphics<br />
    for (int pixels=0; pixels<32; pixels++)<br />
    video_buffer[(px-4+rand()%8)+(py-4+rand()%8)*SCREEN_WIDTH] = (color*64)+rand()%64;<br />
<br />
    // sync time (optional)<br />
<br />
    // use sleep to slow system down to 70ish fps<br />
    Sleep(14); // note that Sleep is extremly inaccurate, IRL you would use something more robust<br />
<br />
    // return and let windows have some time<br />
<br />
} // end Game_Main<br />


Big Grin | :-D

"The man who reads nothing is better educated than the man who reads nothing but newspapers."- Thomas Jefferson


GeneralRe: Need help with program Pin
Bob Stanneveld20-Jul-03 22:33
Bob Stanneveld20-Jul-03 22:33 
GeneralRe: Need help with program Pin
DaveE9th21-Jul-03 7:21
DaveE9th21-Jul-03 7:21 
GeneralRe: Need help with program Pin
Ryan Binns20-Jul-03 22:36
Ryan Binns20-Jul-03 22:36 
GeneralRe: Need help with program Pin
DaveE9th21-Jul-03 20:33
DaveE9th21-Jul-03 20:33 
GeneralEmails tracing!!! Pin
xxhimanshu20-Jul-03 19:52
xxhimanshu20-Jul-03 19:52 
QuestionHow to search and download the Platform SDK containing GDI+? Pin
pani6820-Jul-03 19:43
pani6820-Jul-03 19:43 
AnswerRe: How to search and download the Platform SDK containing GDI+? Pin
Ryan Binns20-Jul-03 20:02
Ryan Binns20-Jul-03 20:02 
GeneralRe: How to search and download the Platform SDK containing GDI+? Pin
J. Dunlap20-Jul-03 20:04
J. Dunlap20-Jul-03 20:04 
AnswerRe: How to search and download the Platform SDK containing GDI+? Pin
J. Dunlap20-Jul-03 20:04
J. Dunlap20-Jul-03 20:04 
GeneralJavascripts Pin
henli20-Jul-03 19:02
henli20-Jul-03 19:02 
GeneralRe: Javascripts Pin
Toni7820-Jul-03 19:22
Toni7820-Jul-03 19:22 
GeneralRe: Javascripts Pin
Ryan Binns20-Jul-03 19:26
Ryan Binns20-Jul-03 19:26 
GeneralRe: Javascripts Pin
henli20-Jul-03 19:50
henli20-Jul-03 19:50 
GeneralRe: Javascripts Pin
Ryan Binns20-Jul-03 19:52
Ryan Binns20-Jul-03 19:52 
GeneralRe: Javascripts Pin
Ryan Binns20-Jul-03 19:25
Ryan Binns20-Jul-03 19:25 
GeneralABOUT COFF AND OMF Pin
gdzfy20-Jul-03 17:43
gdzfy20-Jul-03 17:43 
QuestionHow do you get the number of colors displayed? Pin
Terry O'Nolley20-Jul-03 15:04
Terry O'Nolley20-Jul-03 15:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.