These two programs: I would like to combine them. I wish to have an image shown under one of the menu choices. :D
Gingras_Man 0 Newbie Poster
This attachment is potentially unsafe to open. It may be an executable that is capable of making changes to your file system, or it may require specific software to open. Use caution and only open this attachment if you are comfortable working with zip files.
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// << DISPLAY 4-Bit BMP (16 colors) >>
// This program shows how to display a 16 color bitmap.
// I am not using palettes for bmp,hence all default 16 colors are used.
// If you know BMP structure you can try to add palettes.
// For my other programs you can visit this link :
// -> http://www.geocities.com/neerajnsharma
// - Neeraj Sharma
// n21@indiatimes.com
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#include <alloc.h>
#include <conio.h>
#include <graphics.h>
#include <stdio.h>
#include <stdlib.h>
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#define UL unsigned long
#define UI unsigned int
#define UC unsigned char
//+-+-+-+-+-+-+-+-+-+-+-+-+-+< BMP Structures >+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
typedef struct
{
char Type[2];
UL Size;
UI R1;
UI R2;
UL OffSet;
}BMP1;
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
typedef struct
{
UL headsize;
UL Hlen;
UL Vlen;
UI planes;
UI BPP;
UL Method;
UL BmpSize;
UL HRes;
UL VRes;
UL Colors;
UL IColors;
}BMP2;
//+-+-+-+-+-+-+-+-+-+-+-+-+-< Display BMP >+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
int ShowBMP(int x, int y, char* FileName)
{
int b,a;
BMP1 Obj1;
BMP2 Obj2;
UC * Holder;
int in=0;
UC c=0;
FILE * fp;
fp = fopen(FileName,"rb");
if(fp==NULL)
return 0;
fread(&Obj1, sizeof(Obj1), 1, fp);
fread(&Obj2, sizeof(Obj2), 1, fp);
if(Obj2.BPP!=4) // This isn't a 16 color bmp we can read;
{
fclose(fp);
return 0;
};
fseek(fp,Obj1.OffSet,SEEK_SET);
Holder=(UC *) calloc(Obj2.Hlen/2+1, sizeof(UC));
for(b=Obj2.Vlen;b>=0;b--)
{
fread(Holder, sizeof(UC), Obj2.Hlen/2, fp);
c=0;
in=0;
for(a=0;a<=Obj2.Hlen;a+=2)
{
c = (Holder[in] | 0x00) >>4;
putpixel(a+x,b+y,c);
c = (Holder[in] | 0xF0) & 0x0F;
putpixel(a+1+x,b+y,c);
in++;
}
}
free (Holder);
fclose(fp);
return 1;
}
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-< **** >+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Two bmp demo.bmp & demo1.bmp are provided.
// open these bmp in windows paint & change.(do not change size of bmp)
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-< Main >+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
void main()
{
int color,D=DETECT,E;
// registerfarbgidriver(EGAVGA_driver_far);
initgraph(&D,&E,"");
E=0;
if(!ShowBMP(0,0,"neeraj.bmp")) E=1;
getch();
closegraph();
if(E) printf("\nError : Unable to open file.");
else printf("Sucess !");
}
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#include<iostream.h>
#include <stdlib.h>
//function prototypes
void DisplayMenu();
int main()
{
//variable declarations
char menuChoice;
//while loop to display menu until user exits
while(menuChoice != 5)
{
DisplayMenu();
cin >> menuChoice;
switch(menuChoice)
{
case '1':
system("cls");
cout << "Option 1 code goes here \n";
cout << endl;
system("pause");
system("cls");
break;
case '2':
system("cls");
cout << "Option 2 code goes here \n";
cout << endl;
system("pause");
system("cls");
break;
case '3':
system("cls");
cout << "Option 3 code goes here \n";
cout << endl;
system("pause");
system("cls");
break;
case '4':
system("cls");
cout << "Option 4 code goes here \n";
cout << endl;
system("pause");
system("cls");
break;
case '5':
cout << "\n*THANK YOU HAVE A NICE DAY*\n";
return 1;
default:
system("cls");
cout << "\n*YOU DID NOT ENTER A VALID MENU OPTION. PLEASE TRY AGAIN* \n \n";
cout << endl;
system("pause");
system("cls");
break;
}//ends switch
}//ends while
return 0;
}//ends main
//========================================================================================
//Displays User Options Menu
void DisplayMenu()
{
cout << "=============================================== \n";
cout << "|| please choose an item on the menu below || \n";
cout << "||-------------------------------------------|| \n";
cout << "|| (1) Option 1 || \n";
cout << "|| (2) Option 2 || \n";
cout << "|| (3) Option 3 || \n";
cout << "|| (4) Option 4 || \n";
cout << "|| (5) Quit || \n";
cout << "=============================================== \n";
cout << "Your Choice: ";
}
//========================================================================================
Gingras_Man 0 Newbie Poster
I either want these two combined, or another way to display simple bmp graphics within the program.
Thanks in advance.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.