Archived

This topic is now archived and is closed to further replies.

Ahmed Saleh

HOW PLZ !!!!!

Recommended Posts

this Code Make A Menu I need To Selcet an object With Keyboard EXAMPLE: In Start in need if i prees ENTER in it Go TO Star Gamed............. HI ALL I Make a Menu With This Code [/source] /*--------------------------------------------------------------------------*/ // ARAB SPACE // // By Ahmed Saleh Mohammed Tolba // // CopyRight(c) 2001 // // // /*--------------------------------------------------------------------------*/ //------ Include Files ------// #include #include #include #include #include #include #include "Fastfile.h" #include "stdafx.h" #define INITGUID #include #include "wave.h" #include "Main.h" #include "Ffent.h" //------ Window Class Information ------// static char szClass[] = "Arab Space"; static char szCaption[] = "ARAB SPACE"; //------ Global Interface Pointers ------// LPDIRECTDRAW7 lpDD=NULL; LPDIRECTDRAWSURFACE7 lpDDSPrimary=NULL; LPDIRECTDRAWSURFACE7 lpDDSBack=NULL; //------ Define Number of Sounds ------// #define NUMSOUNDS 1 //------ DirectSound Object and Buffers ------// //------Define number of images and set up list of file names ------// #define IMAGE_COUNT 5 char file_names[IMAGE_COUNT][256] = { "Start.bmp", "load.bmp,FFDATFILE", "cerdit.bmp,FFDATFILE", "exit.bmp,FFDATFILE", }; //------ DirectDraw Surfaces for Image Storage ------// LPDIRECTDRAWSURFACE7 lpSlides[IMAGE_COUNT]; //------ current image displayed------// int cur_image=0; //------ Error Return String ------// const char *ErrStr=NULL; //------ Error Messages ------// const char Err_Reg_Class[] = "Error Registering Window Class"; const char Err_Create_Win[] = "Error Creating Window"; const char Err_DirectDrawCreate[] = "DirectDrawCreate FAILED"; const char Err_Coop[] = "SetCooperativeLevel FAILED"; const char Err_CreateSurf[] = "CreateSurface FAILED"; const char Err_GetBack[] = "Error Retrieving Back Buffer"; const char Err_LoadBMP[] = "Error Loading Image"; const char Err_DispMode[] = "Error Setting Display Mode"; const char Err_LoadImage[] = "Error Loading Image"; const char Err_DirectSoundCreate[] = "DirectSoundCreate FAILED"; const char Err_CreateBuff[] = "CreateBuffer FAILED"; const char Err_LoadWAV[] = "Error Loading Sound"; //------ Function to Load a Bitmap into a DirectDraw Surface ------// LPDIRECTDRAWSURFACE7 bitmap_surface(LPCTSTR file_name,RECT *dims=NULL) { HDC hdc; HBITMAP bit; LPDIRECTDRAWSURFACE7 surf=NULL; // load the bitmap bit=(HBITMAP) LoadImage(NULL,file_name,IMAGE_BITMAP,0,0, LR_DEFAULTSIZE|LR_LOADFROMFILE); if (!bit) // failed to load, return failure to caller return NULL; // get bitmap dimensions BITMAP bitmap; GetObject( bit, sizeof(BITMAP), &bitmap ); int surf_width=bitmap.bmWidth; int surf_height=bitmap.bmHeight; // create surface HRESULT ddrval; DDSURFACEDESC2 ddsd; ZeroMemory(&ddsd,sizeof(ddsd)); ddsd.dwSize = sizeof(DDSURFACEDESC2); ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT ; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = surf_width; ddsd.dwHeight = surf_height; // attempt to create surface ddrval=lpDD->CreateSurface(&ddsd,&surf,NULL); // created ok? if (ddrval!=DD_OK) { // no, release the bitmap and return failure to caller DeleteObject(bit); return NULL; } else { // yes, get a DC for the surface surf->GetDC(&hdc); // generate a compatible DC HDC bit_dc=CreateCompatibleDC(hdc); // blit the interface to the surface SelectObject(bit_dc,bit); BitBlt(hdc,0,0,surf_width,surf_height,bit_dc,0,0,SRCCOPY); // release the DCs surf->ReleaseDC(hdc); DeleteDC(bit_dc); // save the dimensions if rectangle pointer provided if (dims) { dims->left=0; dims->top=0; dims->right=surf_width; dims->bottom=surf_height; } } // clear bitmap DeleteObject(bit); // return pointer to caller return surf; } //------ Cleanup Function to Release Objects ------// #define SafeRelease(x) if (x) { x->Release(); x=NULL;} void Cleanup() { // release loaded image surfaces for (int i=0;i); // release DirectDraw interfaces SafeRelease(lpDDSPrimary); SafeRelease(lpDD); // display error if one thrown if (ErrStr) { MessageBox(NULL, ErrStr, szCaption, MB_OK); ErrStr=NULL; } } //------ Function to Draw a Slide ------// void draw_slide() { // make sure we have the current image, don't draw if we fail if (!lpSlides[cur_image]) { lpSlides[cur_image]=bitmap_surface(file_names[cur_image]); if (!lpSlides[cur_image]) return; } // draw the object to the screen lpDDSBack->BltFast(0,0,lpSlides[cur_image],NULL,DDBLTFAST_WAIT); // draw instructions for slide show HDC hdc; if (DD_OK==lpDDSBack->GetDC(&hdc)) { TextOut(hdc,320,400,"Arab Space Ver 0,1",18); SetTextColor(hdc,0x0000ffff); lpDDSBack->ReleaseDC(hdc); } // flip to the primary surface lpDDSPrimary->Flip(0,DDFLIP_WAIT); // make sure we have the next and previous image // this insures that our next selection is quickly // available, while we only need to load one image // when the program starts. int next_slide=(cur_image>=IMAGE_COUNT-1) ? 0 : cur_image+1; if (!lpSlides[next_slide]) lpSlides[next_slide]=bitmap_surface(file_names[next_slide]); int prev_slide=(cur_image<1) ? IMAGE_COUNT-1 : cur_image-1; if (!lpSlides[prev_slide]) lpSlides[prev_slide]=bitmap_surface(file_names[prev_slide]); } //------ Windows Message Handler ------// LRESULT CALLBACK WindowProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: Cleanup(); PostQuitMessage(0); break; case WM_KEYDOWN: switch (wParam) { case VK_UP: // Process the LEFT ARROW key. cur_image--; if (cur_image<0) cur_image=IMAGE_COUNT-1; draw_slide(); break; case VK_DOWN: // Process the RIGHT ARROW key. cur_image++; if (cur_image>IMAGE_COUNT-1) cur_image=0; draw_slide(); break; case VK_ESCAPE: // exit the program on escape DestroyWindow(hWnd); break; // Process other non-character keystrokes. default: break; } default: return DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0L; } //------ Function to Initialize DirectDraw and the Application ------// static BOOL Init(HINSTANCE hInstance, int nCmdShow) { WNDCLASS wc; HRESULT ddrval; // Set up and register window class wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC) WindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = sizeof(DWORD); wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = szClass; if (!RegisterClass(&wc)) { ErrStr=Err_Reg_Class; return FALSE; } // Get dimensions of display int ScreenWidth = GetSystemMetrics(SM_CXSCREEN); int ScreenHeight = GetSystemMetrics(SM_CYSCREEN); // Create a window and display HWND hWnd; hWnd = CreateWindow(szClass, // class szCaption, // caption WS_VISIBLE|WS_POPUP, // style 0, // left 0, // top ScreenWidth, // width ScreenHeight, // height NULL, // parent window NULL, // menu hInstance, // instance NULL); // parms if (!hWnd) { ErrStr=Err_Create_Win; return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); // clear image pointers ZeroMemory(lpSlides,sizeof(lpSlides)); // Create the main DirectDraw object ddrval = DirectDrawCreateEx(NULL, (VOID **) &lpDD, IID_IDirectDraw7, NULL); if (ddrval != DD_OK) { ErrStr=Err_DirectDrawCreate; return FALSE; } // Set our cooperative level ddrval = lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN ); if (ddrval != DD_OK) { ErrStr=Err_Coop; return FALSE; } // Set the display mode ddrval = lpDD->SetDisplayMode( 640, 480, 16, 0, 0); if (ddrval !=DD_OK) { ErrStr=Err_DispMode; return FALSE; } // Create the primary surface with 1 back buffer DDSURFACEDESC2 ddsd; ZeroMemory(&ddsd,sizeof(ddsd)); ddsd.dwSize = sizeof( ddsd ); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; ddrval = lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL ); if (ddrval!=DD_OK) { ErrStr=Err_CreateSurf; return FALSE; } // Fetch back buffer interface DDSCAPS2 ddscaps; ZeroMemory(&ddscaps,sizeof(ddscaps)); ddscaps.dwCaps=DDSCAPS_BACKBUFFER; ddrval=lpDDSPrimary->GetAttachedSurface(&ddscaps,&lpDDSBack); if (ddrval!=DD_OK) { ErrStr=Err_GetBack; return FALSE; } // load the first image and display it lpSlides[0]=bitmap_surface(file_names[0]); if (!lpSlides[0]) return FALSE; draw_slide(); // return success to caller return TRUE; } //------ Application Loop ------// int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // initialize the application, exit on failure if (!Init(hInstance, nCmdShow)) { Cleanup(); return FALSE; } // run till completed MSG msg; while (GetMessage(&msg,NULL,0,0)) { // dispatch the message TranslateMessage(&msg); DispatchMessage(&msg); } // exit returning final message return (msg.wParam); } and THANKS *--------------------------------------------------------------------------*/ // ARAB SPACE // // By Ahmed Saleh Mohammed Tolba // // CopyRight(c) 2001 // // // /*--------------------------------------------------------------------------*/ //------ Include Files ------// #include #include #include #include #include #include #include "Fastfile.h" #include "stdafx.h" #define INITGUID #include #include "wave.h" #include "Main.h" #include "Ffent.h" //------ Window Class Information ------// static char szClass[] = "Arab Space"; static char szCaption[] = "ARAB SPACE"; //------ Global Interface Pointers ------// LPDIRECTDRAW7 lpDD=NULL; LPDIRECTDRAWSURFACE7 lpDDSPrimary=NULL; LPDIRECTDRAWSURFACE7 lpDDSBack=NULL; //------ Define Number of Sounds ------// #define NUMSOUNDS 1 //------ DirectSound Object and Buffers ------// //------Define number of images and set up list of file names ------// #define IMAGE_COUNT 5 char file_names[IMAGE_COUNT][256] = { "Start.bmp", "load.bmp,FFDATFILE", "cerdit.bmp,FFDATFILE", "exit.bmp,FFDATFILE", }; //------ DirectDraw Surfaces for Image Storage ------// LPDIRECTDRAWSURFACE7 lpSlides[IMAGE_COUNT]; //------ current image displayed------// int cur_image=0; //------ Error Return String ------// const char *ErrStr=NULL; //------ Error Messages ------// const char Err_Reg_Class[] = "Error Registering Window Class"; const char Err_Create_Win[] = "Error Creating Window"; const char Err_DirectDrawCreate[] = "DirectDrawCreate FAILED"; const char Err_Coop[] = "SetCooperativeLevel FAILED"; const char Err_CreateSurf[] = "CreateSurface FAILED"; const char Err_GetBack[] = "Error Retrieving Back Buffer"; const char Err_LoadBMP[] = "Error Loading Image"; const char Err_DispMode[] = "Error Setting Display Mode"; const char Err_LoadImage[] = "Error Loading Image"; const char Err_DirectSoundCreate[] = "DirectSoundCreate FAILED"; const char Err_CreateBuff[] = "CreateBuffer FAILED"; const char Err_LoadWAV[] = "Error Loading Sound"; //------ Function to Load a Bitmap into a DirectDraw Surface ------// LPDIRECTDRAWSURFACE7 bitmap_surface(LPCTSTR file_name,RECT *dims=NULL) { HDC hdc; HBITMAP bit; LPDIRECTDRAWSURFACE7 surf=NULL; // load the bitmap bit=(HBITMAP) LoadImage(NULL,file_name,IMAGE_BITMAP,0,0, LR_DEFAULTSIZE|LR_LOADFROMFILE); if (!bit) // failed to load, return failure to caller return NULL; // get bitmap dimensions BITMAP bitmap; GetObject( bit, sizeof(BITMAP), &bitmap ); int surf_width=bitmap.bmWidth; int surf_height=bitmap.bmHeight; // create surface HRESULT ddrval; DDSURFACEDESC2 ddsd; ZeroMemory(&ddsd,sizeof(ddsd)); ddsd.dwSize = sizeof(DDSURFACEDESC2); ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT ; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = surf_width; ddsd.dwHeight = surf_height; // attempt to create surface ddrval=lpDD->CreateSurface(&ddsd,&surf,NULL); // created ok? if (ddrval!=DD_OK) { // no, release the bitmap and return failure to caller DeleteObject(bit); return NULL; } else { // yes, get a DC for the surface surf->GetDC(&hdc); // generate a compatible DC HDC bit_dc=CreateCompatibleDC(hdc); // blit the interface to the surface SelectObject(bit_dc,bit); BitBlt(hdc,0,0,surf_width,surf_height,bit_dc,0,0,SRCCOPY); // release the DCs surf->ReleaseDC(hdc); DeleteDC(bit_dc); // save the dimensions if rectangle pointer provided if (dims) { dims->left=0; dims->top=0; dims->right=surf_width; dims->bottom=surf_height; } } // clear bitmap DeleteObject(bit); // return pointer to caller return surf; } //------ Cleanup Function to Release Objects ------// #define SafeRelease(x) if (x) { x->Release(); x=NULL;} void Cleanup() { // release loaded image surfaces for (int i=0;iBltFast(0,0,lpSlides[cur_image],NULL,DDBLTFAST_WAIT); // draw instructions for slide show HDC hdc; if (DD_OK==lpDDSBack->GetDC(&hdc)) { TextOut(hdc,320,400,"Arab Space Ver 0,1",18); SetTextColor(hdc,0x0000ffff); lpDDSBack->ReleaseDC(hdc); } // flip to the primary surface lpDDSPrimary->Flip(0,DDFLIP_WAIT); // make sure we have the next and previous image // this insures that our next selection is quickly // available, while we only need to load one image // when the program starts. int next_slide=(cur_image>=IMAGE_COUNT-1) ? 0 : cur_image+1; if (!lpSlides[next_slide]) lpSlides[next_slide]=bitmap_surface(file_names[next_slide]); int prev_slide=(cur_image<1) ? IMAGE_COUNT-1 : cur_image-1; if (!lpSlides[prev_slide]) lpSlides[prev_slide]=bitmap_surface(file_names[prev_slide]); } //------ Windows Message Handler ------// LRESULT CALLBACK WindowProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: Cleanup(); PostQuitMessage(0); break; case WM_KEYDOWN: switch (wParam) { case VK_UP: // Process the LEFT ARROW key. cur_image--; if (cur_image<0) cur_image=IMAGE_COUNT-1; draw_slide(); break; case VK_DOWN: // Process the RIGHT ARROW key. cur_image++; if (cur_image>IMAGE_COUNT-1) cur_image=0; draw_slide(); break; case VK_ESCAPE: // exit the program on escape DestroyWindow(hWnd); break; // Process other non-character keystrokes. default: break; } default: return DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0L; } //------ Function to Initialize DirectDraw and the Application ------// static BOOL Init(HINSTANCE hInstance, int nCmdShow) { WNDCLASS wc; HRESULT ddrval; // Set up and register window class wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC) WindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = sizeof(DWORD); wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = szClass; if (!RegisterClass(&wc)) { ErrStr=Err_Reg_Class; return FALSE; } // Get dimensions of display int ScreenWidth = GetSystemMetrics(SM_CXSCREEN); int ScreenHeight = GetSystemMetrics(SM_CYSCREEN); // Create a window and display HWND hWnd; hWnd = CreateWindow(szClass, // class szCaption, // caption WS_VISIBLE|WS_POPUP, // style 0, // left 0, // top ScreenWidth, // width ScreenHeight, // height NULL, // parent window NULL, // menu hInstance, // instance NULL); // parms if (!hWnd) { ErrStr=Err_Create_Win; return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); // clear image pointers ZeroMemory(lpSlides,sizeof(lpSlides)); // Create the main DirectDraw object ddrval = DirectDrawCreateEx(NULL, (VOID **) &lpDD, IID_IDirectDraw7, NULL); if (ddrval != DD_OK) { ErrStr=Err_DirectDrawCreate; return FALSE; } // Set our cooperative level ddrval = lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN ); if (ddrval != DD_OK) { ErrStr=Err_Coop; return FALSE; } // Set the display mode ddrval = lpDD->SetDisplayMode( 640, 480, 16, 0, 0); if (ddrval !=DD_OK) { ErrStr=Err_DispMode; return FALSE; } // Create the primary surface with 1 back buffer DDSURFACEDESC2 ddsd; ZeroMemory(&ddsd,sizeof(ddsd)); ddsd.dwSize = sizeof( ddsd ); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; ddrval = lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL ); if (ddrval!=DD_OK) { ErrStr=Err_CreateSurf; return FALSE; } // Fetch back buffer interface DDSCAPS2 ddscaps; ZeroMemory(&ddscaps,sizeof(ddscaps)); ddscaps.dwCaps=DDSCAPS_BACKBUFFER; ddrval=lpDDSPrimary->GetAttachedSurface(&ddscaps,&lpDDSBack); if (ddrval!=DD_OK) { ErrStr=Err_GetBack; return FALSE; } // load the first image and display it lpSlides[0]=bitmap_surface(file_names[0]); if (!lpSlides[0]) return FALSE; draw_slide(); // return success to caller return TRUE; } //------ Application Loop ------// int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // initialize the application, exit on failure if (!Init(hInstance, nCmdShow)) { Cleanup(); return FALSE; } // run till completed MSG msg; while (GetMessage(&msg,NULL,0,0)) { // dispatch the message TranslateMessage(&msg); DispatchMessage(&msg); } // exit returning final message return (msg.wParam); } [/source] and THANKS
          


/*--------------------------------------------------------------------------*/
// ARAB SPACE													
//																			
// By Ahmed Saleh Mohammed	Tolba															
//																			
// CopyRight(c) 2001
										
// 															
//																			
// 														
/*--------------------------------------------------------------------------*/

//------ Include Files ------//
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <winbase.h>
#include "Fastfile.h"
#include "stdafx.h"
#define INITGUID
#include <ddraw.h>
#include "wave.h"
#include "Main.h"
#include "Ffent.h"

//------ Window Class Information ------//

static char szClass[] = "Arab Space";
static char szCaption[] = "ARAB SPACE";

//------ Global Interface Pointers ------//

LPDIRECTDRAW7 lpDD=NULL;
LPDIRECTDRAWSURFACE7 lpDDSPrimary=NULL;
LPDIRECTDRAWSURFACE7 lpDDSBack=NULL;
//------ Define Number of Sounds ------//

#define NUMSOUNDS 1

//------ DirectSound Object and Buffers ------//

//------Define number of images and set up list of file names ------//

#define IMAGE_COUNT			5

char file_names[IMAGE_COUNT][256] = {  "Start.bmp",
									   "load.bmp,FFDATFILE",
									   
									   "cerdit.bmp,FFDATFILE",
									   "exit.bmp,FFDATFILE",
};

//------ DirectDraw Surfaces for Image Storage ------//

LPDIRECTDRAWSURFACE7 lpSlides[IMAGE_COUNT];

//------ current image displayed------//

int cur_image=0;

//------ Error Return String ------//

const char *ErrStr=NULL;	

//------ Error Messages ------//

const char Err_Reg_Class[]			= "Error Registering Window Class";
const char Err_Create_Win[]			= "Error Creating Window";
const char Err_DirectDrawCreate[]	= "DirectDrawCreate FAILED";
const char Err_Coop[]				= "SetCooperativeLevel FAILED";
const char Err_CreateSurf[]			= "CreateSurface FAILED";
const char Err_GetBack[]			= "Error Retrieving Back Buffer";
const char Err_LoadBMP[]			= "Error Loading Image";
const char Err_DispMode[]			= "Error Setting Display Mode";
const char Err_LoadImage[]			= "Error Loading Image";
const char Err_DirectSoundCreate[]  = "DirectSoundCreate FAILED";
const char Err_CreateBuff[]         = "CreateBuffer FAILED";
const char Err_LoadWAV[]			= "Error Loading Sound";
//------ Function to Load a Bitmap into a DirectDraw Surface ------//

LPDIRECTDRAWSURFACE7 bitmap_surface(LPCTSTR file_name,RECT *dims=NULL)
{
	HDC hdc;
	HBITMAP bit;
	LPDIRECTDRAWSURFACE7 surf=NULL;

	// load the bitmap

	bit=(HBITMAP) LoadImage(NULL,file_name,IMAGE_BITMAP,0,0,
								LR_DEFAULTSIZE|LR_LOADFROMFILE);
	if (!bit) 

		// failed to load, return failure to caller

		return NULL;

	// get bitmap dimensions

	BITMAP bitmap;
    GetObject( bit, sizeof(BITMAP), &bitmap );
	int surf_width=bitmap.bmWidth;
	int surf_height=bitmap.bmHeight;

	// create surface

	HRESULT ddrval;
	DDSURFACEDESC2 ddsd;
	ZeroMemory(&ddsd,sizeof(ddsd));
	ddsd.dwSize = sizeof(DDSURFACEDESC2);
	ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT ;
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; 
	ddsd.dwWidth = surf_width;
	ddsd.dwHeight = surf_height; 

	// attempt to create surface

	ddrval=lpDD->CreateSurface(&ddsd,&surf,NULL);

	// created ok?

	if (ddrval!=DD_OK) {

		// no, release the bitmap and return failure to caller

		DeleteObject(bit);
		return NULL;

	} else {

		// yes, get a DC for the surface

		surf->GetDC(&hdc);

		// generate a compatible DC

		HDC bit_dc=CreateCompatibleDC(hdc);

		// blit the interface to the surface

		SelectObject(bit_dc,bit);
		BitBlt(hdc,0,0,surf_width,surf_height,bit_dc,0,0,SRCCOPY);

		// release the DCs

		surf->ReleaseDC(hdc);
		DeleteDC(bit_dc);

		// save the dimensions if rectangle pointer provided

		if (dims) {
			dims->left=0;
			dims->top=0;
			dims->right=surf_width;
			dims->bottom=surf_height;
		}
	}

	// clear bitmap 

	DeleteObject(bit);

	// return pointer to caller

	return surf;
}

//------ Cleanup Function to Release Objects ------//

#define SafeRelease(x) if (x) { x->Release(); x=NULL;}

void Cleanup()
{
	// release loaded image surfaces

	for (int i=0;i<IMAGE_COUNT;i++) 
		SafeRelease(lpSlides[i]);

	// release DirectDraw interfaces

	SafeRelease(lpDDSPrimary);
	SafeRelease(lpDD);
   
	// display error if one thrown

	if (ErrStr) {
		MessageBox(NULL, ErrStr, szCaption, MB_OK);
		ErrStr=NULL;
	}
}

//------ Function to Draw a Slide ------//

void draw_slide()
{
	// make sure we have the current image, don't draw if we fail

	if (!lpSlides[cur_image]) {
		lpSlides[cur_image]=bitmap_surface(file_names[cur_image]);
		if (!lpSlides[cur_image])
			return;
	}

	// draw the object to the screen

	lpDDSBack->BltFast(0,0,lpSlides[cur_image],NULL,DDBLTFAST_WAIT);

	// draw instructions for slide show

	HDC hdc;
	if (DD_OK==lpDDSBack->GetDC(&hdc)) {
		TextOut(hdc,320,400,"Arab Space Ver 0,1",18);
		SetTextColor(hdc,0x0000ffff);	
		lpDDSBack->ReleaseDC(hdc);
	}

	// flip to the primary surface

	lpDDSPrimary->Flip(0,DDFLIP_WAIT); 

	// make sure we have the next and previous image
	// this insures that our next selection is quickly
	// available, while we only need to load one image
	// when the program starts.

	int next_slide=(cur_image>=IMAGE_COUNT-1) ? 0 : cur_image+1;
	if (!lpSlides[next_slide]) 
		lpSlides[next_slide]=bitmap_surface(file_names[next_slide]);

	int prev_slide=(cur_image<1) ? IMAGE_COUNT-1 : cur_image-1;
	if (!lpSlides[prev_slide]) 
		lpSlides[prev_slide]=bitmap_surface(file_names[prev_slide]);
}

//------ Windows Message Handler ------//

LRESULT CALLBACK 
WindowProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {

        case WM_DESTROY:
			Cleanup();
            PostQuitMessage(0);
            break;

        case WM_KEYDOWN: 
            switch (wParam) 
            { 
                case VK_UP: 
                    
                    // Process the LEFT ARROW key. 
                    
					cur_image--;
					if (cur_image<0)
						cur_image=IMAGE_COUNT-1;
					draw_slide();
                    break; 
 
                case VK_DOWN: 
                    
                    // Process the RIGHT ARROW key. 
                     
					cur_image++;
					if (cur_image>IMAGE_COUNT-1)
						cur_image=0;
					draw_slide();
                    break; 
 
				case VK_ESCAPE:

					// exit the program on escape

					DestroyWindow(hWnd);
					break;

                // Process other non-character keystrokes. 
                 
                default: 
                    break; 
            }

        default:
            return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
	return 0L;
}











//------ Function to Initialize DirectDraw and the Application ------//

static BOOL Init(HINSTANCE hInstance, int nCmdShow)
{
    WNDCLASS                    wc;
    HRESULT                     ddrval;

    // Set up and register window class

    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = (WNDPROC) WindowProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = sizeof(DWORD);
    wc.hInstance = hInstance;
    wc.hIcon = NULL;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = szClass;
    if (!RegisterClass(&wc)) {
		ErrStr=Err_Reg_Class;
        return FALSE;
	}

    // Get dimensions of display

    int ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
    int ScreenHeight = GetSystemMetrics(SM_CYSCREEN);

    // Create a window and display

	HWND hWnd;

    hWnd = CreateWindow(szClass,							// class
                        szCaption,							// caption
						WS_VISIBLE|WS_POPUP,				// style 
						0,									// left
						0,									// top
						ScreenWidth,						// width
						ScreenHeight,						// height
                        NULL,								// parent window
                        NULL,								// menu 
                        hInstance,							// instance
                        NULL);								// parms
    if (!hWnd) {
		ErrStr=Err_Create_Win;
        return FALSE;
	}
    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);

	// clear image pointers

	ZeroMemory(lpSlides,sizeof(lpSlides));

    

	
	
	// Create the main DirectDraw object

    ddrval = DirectDrawCreateEx(NULL, (VOID **) &lpDD, IID_IDirectDraw7, NULL);
    if (ddrval != DD_OK) {
		ErrStr=Err_DirectDrawCreate;
		return FALSE;
	}

    // Set our cooperative level

    ddrval = lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN );
    if (ddrval != DD_OK) {
		ErrStr=Err_Coop;
		return FALSE;
	}

	// Set the display mode

	ddrval = lpDD->SetDisplayMode( 640, 480, 16, 0, 0);
	if (ddrval !=DD_OK) {
		ErrStr=Err_DispMode;
		return FALSE;
	}

    // Create the primary surface with 1 back buffer

    DDSURFACEDESC2 ddsd;
	ZeroMemory(&ddsd,sizeof(ddsd));
    ddsd.dwSize = sizeof( ddsd );
    ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
                          DDSCAPS_FLIP | 
                          DDSCAPS_COMPLEX;
    ddsd.dwBackBufferCount = 1;
    ddrval = lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL );
	if (ddrval!=DD_OK) {
		ErrStr=Err_CreateSurf;
		return FALSE;
	}

	// Fetch back buffer interface

	DDSCAPS2 ddscaps;
	ZeroMemory(&ddscaps,sizeof(ddscaps));
	ddscaps.dwCaps=DDSCAPS_BACKBUFFER;
	ddrval=lpDDSPrimary->GetAttachedSurface(&ddscaps,&lpDDSBack);
	if (ddrval!=DD_OK) {
		ErrStr=Err_GetBack;
		return FALSE;
	}

	// load the first image and display it

	lpSlides[0]=bitmap_surface(file_names[0]);
	if (!lpSlides[0])
		return FALSE;
	draw_slide();

	// return success to caller

	return TRUE;
}


	







//------ Application Loop ------//

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	// initialize the application, exit on failure

    if (!Init(hInstance, nCmdShow)) {
		Cleanup();
        return FALSE;
	}

	// run till completed 

	MSG msg;                 
	while (GetMessage(&msg,NULL,0,0)) {

			// dispatch the message 

			TranslateMessage(&msg);
			DispatchMessage(&msg); 
	}

	// exit returning final message

    return (msg.wParam);
}/*--------------------------------------------------------------------------*/
// ARAB SPACE													
//																			
// By Ahmed Saleh Mohammed	Tolba															
//																			
// CopyRight(c) 2001
										
// 															
//																			
// 														
/*--------------------------------------------------------------------------*/

//------ Include Files ------//

#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <winbase.h>
#include "Fastfile.h"
#include "stdafx.h"
#define INITGUID
#include <ddraw.h>
#include "wave.h"
#include "Main.h"
#include "Ffent.h"

//------ Window Class Information ------//


static char szClass[] = "Arab Space";
static char szCaption[] = "ARAB SPACE";

//------ Global Interface Pointers ------//


LPDIRECTDRAW7 lpDD=NULL;
LPDIRECTDRAWSURFACE7 lpDDSPrimary=NULL;
LPDIRECTDRAWSURFACE7 lpDDSBack=NULL;
//------ Define Number of Sounds ------//


#define NUMSOUNDS 1

//------ DirectSound Object and Buffers ------//


//------Define number of images and set up list of file names ------//


#define IMAGE_COUNT			5

char file_names[IMAGE_COUNT][256] = {  "Start.bmp",
									   "load.bmp,FFDATFILE",
									   
									   "cerdit.bmp,FFDATFILE",
									   "exit.bmp,FFDATFILE",
};

//------ DirectDraw Surfaces for Image Storage ------//


LPDIRECTDRAWSURFACE7 lpSlides[IMAGE_COUNT];

//------ current image displayed------//


int cur_image=0;

//------ Error Return String ------//


const char *ErrStr=NULL;	

//------ Error Messages ------//


const char Err_Reg_Class[]			= "Error Registering Window Class";
const char Err_Create_Win[]			= "Error Creating Window";
const char Err_DirectDrawCreate[]	= "DirectDrawCreate FAILED";
const char Err_Coop[]				= "SetCooperativeLevel FAILED";
const char Err_CreateSurf[]			= "CreateSurface FAILED";
const char Err_GetBack[]			= "Error Retrieving Back Buffer";
const char Err_LoadBMP[]			= "Error Loading Image";
const char Err_DispMode[]			= "Error Setting Display Mode";
const char Err_LoadImage[]			= "Error Loading Image";
const char Err_DirectSoundCreate[]  = "DirectSoundCreate FAILED";
const char Err_CreateBuff[]         = "CreateBuffer FAILED";
const char Err_LoadWAV[]			= "Error Loading Sound";
//------ Function to Load a Bitmap into a DirectDraw Surface ------//


LPDIRECTDRAWSURFACE7 bitmap_surface(LPCTSTR file_name,RECT *dims=NULL)
{
	HDC hdc;
	HBITMAP bit;
	LPDIRECTDRAWSURFACE7 surf=NULL;

	// load the bitmap


	bit=(HBITMAP) LoadImage(NULL,file_name,IMAGE_BITMAP,0,0,
								LR_DEFAULTSIZE|LR_LOADFROMFILE);
	if (!bit) 

		// failed to load, return failure to caller


		return NULL;

	// get bitmap dimensions


	BITMAP bitmap;
    GetObject( bit, sizeof(BITMAP), &bitmap );
	int surf_width=bitmap.bmWidth;
	int surf_height=bitmap.bmHeight;

	// create surface


	HRESULT ddrval;
	DDSURFACEDESC2 ddsd;
	ZeroMemory(&ddsd,sizeof(ddsd));
	ddsd.dwSize = sizeof(DDSURFACEDESC2);
	ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT ;
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; 
	ddsd.dwWidth = surf_width;
	ddsd.dwHeight = surf_height; 

	// attempt to create surface


	ddrval=lpDD->CreateSurface(&ddsd,&surf,NULL);

	// created ok?


	if (ddrval!=DD_OK) {

		// no, release the bitmap and return failure to caller


		DeleteObject(bit);
		return NULL;

	} else {

		// yes, get a DC for the surface


		surf->GetDC(&hdc);

		// generate a compatible DC


		HDC bit_dc=CreateCompatibleDC(hdc);

		// blit the interface to the surface


		SelectObject(bit_dc,bit);
		BitBlt(hdc,0,0,surf_width,surf_height,bit_dc,0,0,SRCCOPY);

		// release the DCs


		surf->ReleaseDC(hdc);
		DeleteDC(bit_dc);

		// save the dimensions if rectangle pointer provided


		if (dims) {
			dims->left=0;
			dims->top=0;
			dims->right=surf_width;
			dims->bottom=surf_height;
		}
	}

	// clear bitmap 


	DeleteObject(bit);

	// return pointer to caller


	return surf;
}

//------ Cleanup Function to Release Objects ------//


#define SafeRelease(x) if (x) { x->Release(); x=NULL;}

void Cleanup()
{
	// release loaded image surfaces


	for (int i=0;i<IMAGE_COUNT;i++) 
		SafeRelease(lpSlides[i]);

	// release DirectDraw interfaces


	SafeRelease(lpDDSPrimary);
	SafeRelease(lpDD);
   
	// display error if one thrown


	if (ErrStr) {
		MessageBox(NULL, ErrStr, szCaption, MB_OK);
		ErrStr=NULL;
	}
}

//------ Function to Draw a Slide ------//


void draw_slide()
{
	// make sure we have the current image, don't draw if we fail


	if (!lpSlides[cur_image]) {
		lpSlides[cur_image]=bitmap_surface(file_names[cur_image]);
		if (!lpSlides[cur_image])
			return;
	}

	// draw the object to the screen


	lpDDSBack->BltFast(0,0,lpSlides[cur_image],NULL,DDBLTFAST_WAIT);

	// draw instructions for slide show


	HDC hdc;
	if (DD_OK==lpDDSBack->GetDC(&hdc)) {
		TextOut(hdc,320,400,"Arab Space Ver 0,1",18);
		SetTextColor(hdc,0x0000ffff);	
		lpDDSBack->ReleaseDC(hdc);
	}

	// flip to the primary surface


	lpDDSPrimary->Flip(0,DDFLIP_WAIT); 

	// make sure we have the next and previous image

	// this insures that our next selection is quickly

	// available, while we only need to load one image

	// when the program starts.


	int next_slide=(cur_image>=IMAGE_COUNT-1) ? 0 : cur_image+1;
	if (!lpSlides[next_slide]) 
		lpSlides[next_slide]=bitmap_surface(file_names[next_slide]);

	int prev_slide=(cur_image<1) ? IMAGE_COUNT-1 : cur_image-1;
	if (!lpSlides[prev_slide]) 
		lpSlides[prev_slide]=bitmap_surface(file_names[prev_slide]);
}

//------ Windows Message Handler ------//


LRESULT CALLBACK 
WindowProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {

        case WM_DESTROY:
			Cleanup();
            PostQuitMessage(0);
            break;

        case WM_KEYDOWN: 
            switch (wParam) 
            { 
                case VK_UP: 
                    
                    // Process the LEFT ARROW key. 

                    
					cur_image--;
					if (cur_image<0)
						cur_image=IMAGE_COUNT-1;
					draw_slide();
                    break; 
 
                case VK_DOWN: 
                    
                    // Process the RIGHT ARROW key. 

                     
					cur_image++;
					if (cur_image>IMAGE_COUNT-1)
						cur_image=0;
					draw_slide();
                    break; 
 
				case VK_ESCAPE:

					// exit the program on escape


					DestroyWindow(hWnd);
					break;

                // Process other non-character keystrokes. 

                 
                default: 
                    break; 
            }

        default:
            return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
	return 0L;
}











//------ Function to Initialize DirectDraw and the Application ------//


static BOOL Init(HINSTANCE hInstance, int nCmdShow)
{
    WNDCLASS                    wc;
    HRESULT                     ddrval;

    // Set up and register window class


    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = (WNDPROC) WindowProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = sizeof(DWORD);
    wc.hInstance = hInstance;
    wc.hIcon = NULL;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = szClass;
    if (!RegisterClass(&wc)) {
		ErrStr=Err_Reg_Class;
        return FALSE;
	}

    // Get dimensions of display


    int ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
    int ScreenHeight = GetSystemMetrics(SM_CYSCREEN);

    // Create a window and display


	HWND hWnd;

    hWnd = CreateWindow(szClass,							// class

                        szCaption,							// caption

						WS_VISIBLE|WS_POPUP,				// style 

						0,									// left

						0,									// top

						ScreenWidth,						// width

						ScreenHeight,						// height

                        NULL,								// parent window

                        NULL,								// menu 

                        hInstance,							// instance

                        NULL);								// parms

    if (!hWnd) {
		ErrStr=Err_Create_Win;
        return FALSE;
	}
    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);

	// clear image pointers


	ZeroMemory(lpSlides,sizeof(lpSlides));

    

	
	
	// Create the main DirectDraw object


    ddrval = DirectDrawCreateEx(NULL, (VOID **) &lpDD, IID_IDirectDraw7, NULL);
    if (ddrval != DD_OK) {
		ErrStr=Err_DirectDrawCreate;
		return FALSE;
	}

    // Set our cooperative level


    ddrval = lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN );
    if (ddrval != DD_OK) {
		ErrStr=Err_Coop;
		return FALSE;
	}

	// Set the display mode


	ddrval = lpDD->SetDisplayMode( 640, 480, 16, 0, 0);
	if (ddrval !=DD_OK) {
		ErrStr=Err_DispMode;
		return FALSE;
	}

    // Create the primary surface with 1 back buffer


    DDSURFACEDESC2 ddsd;
	ZeroMemory(&ddsd,sizeof(ddsd));
    ddsd.dwSize = sizeof( ddsd );
    ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
                          DDSCAPS_FLIP | 
                          DDSCAPS_COMPLEX;
    ddsd.dwBackBufferCount = 1;
    ddrval = lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL );
	if (ddrval!=DD_OK) {
		ErrStr=Err_CreateSurf;
		return FALSE;
	}

	// Fetch back buffer interface


	DDSCAPS2 ddscaps;
	ZeroMemory(&ddscaps,sizeof(ddscaps));
	ddscaps.dwCaps=DDSCAPS_BACKBUFFER;
	ddrval=lpDDSPrimary->GetAttachedSurface(&ddscaps,&lpDDSBack);
	if (ddrval!=DD_OK) {
		ErrStr=Err_GetBack;
		return FALSE;
	}

	// load the first image and display it


	lpSlides[0]=bitmap_surface(file_names[0]);
	if (!lpSlides[0])
		return FALSE;
	draw_slide();

	// return success to caller


	return TRUE;
}


	







//------ Application Loop ------//


int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	// initialize the application, exit on failure


    if (!Init(hInstance, nCmdShow)) {
		Cleanup();
        return FALSE;
	}

	// run till completed 


	MSG msg;                 
	while (GetMessage(&msg,NULL,0,0)) {

			// dispatch the message 


			TranslateMessage(&msg);
			DispatchMessage(&msg); 
	}

	// exit returning final message


    return (msg.wParam);
}


        
/[/source] Edited by - ahmed saleh on June 23, 2001 7:12:50 PM Edited by - ahmed saleh on June 23, 2001 7:17:14 PM

Share this post


Link to post
Share on other sites
Don''t post huge amounts of source code. No one is going to look through all that and find whatever problem you''re having. I have enough of my own source code to look through all the time without having to read pages and pages of other peoples. I notice you''re asking about menu, but the first two pages of your post are include files and a function to load a bitmap into a DDSURFACE. I didn''t read past that.

If you have to post code, at least work out where your problem is, narrow it down to a function or a few lines, and then post.


War Worlds - A 3D Real-Time Strategy game in development.

Share this post


Link to post
Share on other sites
Well in your WindowProc function you will see some things like:

case WM_KEYDOWN:
switch (wParam)
{
case VK_UP:
cur_image--; if (cur_image<0) cur_image=IMAGE_COUNT-1; draw_slide();
break;

etc...

to handle the Enter key, add a case like:

case VK_ENTER:
//do something
break;

and replace //do something with whatever you want to happen when you hit the enter key... lol

I don''t know if this is what you were looking for. If not you might want to try again explaining what you need as it was a little rough the first time

Seeya
Krippy

Share this post


Link to post
Share on other sites
HI
download this
www.alsindibad.com/users/digiarab/menu.zip

this the menu not Include the Code the Code is up
see this menu
i need To select from the Menu
if i was in the Load game
i want if i press on it Enter go to the load game();
and if i was in the Start Game i want if i press
enter on it go to Start Game();
are understand me
I NEED TO SELECT FROM THIS MENU
if i want to start game and if i want to Exit the Game
i hope u understand me
and thanks for Help Me
Thanks

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
MY GOD MAN do you honestly expect people to go through PAGES AND PAGES AND PAGES of code? Please TRY and narrow down the code to the part you need help with!

Share this post


Link to post
Share on other sites