Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,912 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,193 people online right now. Registration is fast and FREE... Join Now!




[C Graphics] How do I create a "window opening"?

 
Reply to this topicStart new topic

[C Graphics] How do I create a "window opening"?, more details inside

ISAI
31 Jan, 2008 - 12:18 AM
Post #1

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 41


My Contributions
Hi.
I'm creating a game, and I want when the user pressed on the Quit button,
a window will appear asking the user if he is sure he wishes to quit the game (Are You Sure? Yes/No buttons).
I don't really know how to approach creating this window..
Note that I wrote Yes/No buttons using the mouse, not with the keyboard..
I'm not asking that someone will write me the entire code,
but advices or some guidance would be much appreciated.

Thanks.

Heres the page where I want to write this code:
(I'll do this window opening on both Quit buttons on the two different functions.. is it a problem that I want to do it in the same page?)

CODE
#include <graphics.h>
#include <string.h>
#include <alloc.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include "d:\1vs100\button.h"
#include "d:\1vs100\mouse.h"
#include "d:\1vs100\screens.h"
#include "d:\1vs100\high.h"
#include "d:\1vs100\game.h"
#include "d:\1vs100\ins.h"

void start()
{
  int c,d,i,status,places=2;
  int color,k,x1_coords=237,x2_coords=231,x3_coords=237;
  char a1[8]="",a2[9]="",a3[9]="",name[8],id[9],school[9];
  button *array;


     array=(button*)malloc(places*sizeof(button)); // array of button
     if (array==NULL) // if memory=not enough room > NULL
    {
       printf("Not enough memory to allocate buffer!\n");
       getch();
       exit(0);
    }
     array[0]=InitButton(245,115,340,145,0,13,"Menu");
     array[1]=InitButton(245,155,340,185,0,13,"Quit");

     setfillstyle(8,9); // s,c
     bar(15,480,0,0); // left frame
     bar(0,15,640,0); // up frame
     bar(623,480,640,0); // right frame
     bar(0,480,640,465); // down frame
     setcolor(9); // light blue
     settextstyle(4,0,4); // f,d,s
     outtextxy(187,50,"1 Against 100");
     setcolor(13); // purple
     line(248,275,339,275); // seperate line
     rectangle(247,205,339,340); // box
     delay(1800);
     circle(293,219,10); // stick head
     delay(450);
     line(293,229,293,252); // stick body
     delay(450);
     line(314,230,294,240); // stick right arm
     line(271,230,292,240); // stick left arm
     delay(450);
     line(293,253,300,272); // stick right leg
     line(293,253,286,272); // stick left leg
     delay(590);
     line(260,290,260,324); // (1) digget one
     circle(284,310,13); // (0) first digget zero
     circle(317,310,13); // (0) second digget zero
     delay(500);
     randomize();
     settextstyle(7,0,3); // f,d,s
     strcpy(name,"Oren Paz");
     strcpy(id,"201447281");
     strcpy(school,"Ort Holon");
     for(k=0;k<4;k++)
       {
      color = ( color + rand() ) %15 +1;
      setcolor(color);
      a1[k]+=name[k];
      outtextxy(x1_coords,350,name);
      x1_coords+=1.5;
      delay(74);
      setcolor(15);
      outtextxy(x1_coords,350,name);
       }
     for(k=0;k<4;k++)
       {
      color = ( color + rand() ) %15 +1;
      setcolor(color);
      a2[k]+=id[k];
      outtextxy(x2_coords,380,id);
      x2_coords+=1.5;
      delay(74);
      setcolor(15);
      outtextxy(x2_coords,380,id);
       }
     for(k=0;k<4;k++)
       {
      color = ( color + rand() ) %15 +1;
      setcolor(color);
      a3[k]+=school[k];
      outtextxy(x3_coords,410,school);
      x3_coords+=1.5;
      delay(74);
      setcolor(15);
      outtextxy(x3_coords,410,school);
       }

     for(i=0;i<places;i++) DrawButton(array[i]);
     mouse_cursor_on();
     while(1)
    {
       for (i=0;i<places;i++)
          {
         read_mouse(&c,&d,&status); // coords&click type
         if ((c>=array[i].x1)&&(c<=array[i].x2)&&(d>=array[i].y1)&&(d<=array[i].y2)&&(status&0x01))
            {
               sound(250);
               delay(50);
               nosound();
               if (BPos(array[i])==0) // if not pressed
              {
                 array[i].pos=1;
                 DrawButton(array[i]);
                 delay(200); // illusion of button being pressed
                 array[i].pos=0;
                 DrawButton(array[i]);
                 if (i==0) // Start
                {
                   mouse_cursor_off();
                   clearviewport();
                   free(array);
                   menu();
                }
                 if (i==1) // Exit
                {
                   closegraph();
                   free(array);
                   sound(250);
                   delay(4);
                   nosound();
                   exit(1);
                }
              } // end if
               if (BPos(array[i])==1)
              {
                 array[i].pos=0;
                 DrawButton(array[i]);
                 if (i==2)
                {
                   closegraph();
                   free(array);
                   sound(250);
                   delay(4);
                   nosound();
                   exit(1);
                } // end if
                 break;
              } // end if
            } // end if
          } // end for
    } // end while
} // end start

void menu()
{
  int c,d,i,status,places=5;
  button *array;
  char name[16]="\0";

     array=(button*)malloc(places*sizeof(button)); // array of button
     if (array==NULL) // if memory=not enough room > NULL
    {
       printf("Not enough memory to allocate buffer!\n");
       getch();
       exit(0);
    }
     array[0]=InitButton(245,110,340,145,0,13,"Start");
     array[1]=InitButton(245,180,340,215,0,13,"Load Game");
     array[2]=InitButton(245,250,340,285,0,13,"Instructions");
     array[3]=InitButton(245,320,340,355,0,13,"High Scores");
     array[4]=InitButton(245,390,340,425,0,13,"Quit");

     setfillstyle(8,9); // s,c
     bar(15,480,0,0); // left frame
     bar(0,15,640,0); // up frame
     bar(623,480,640,0); // right frame
     bar(0,480,640,465); // down frame
     setcolor(9); // light blue
     settextstyle(4,0,4); // f,d,s
     outtextxy(187,50,"1 Against 100");

     for(i=0;i<places;i++) DrawButton(array[i]);
     mouse_cursor_on();
     while(1)
    {
       for (i=0;i<places;i++)
          {
         read_mouse(&c,&d,&status);
         if ((c>=array[i].x1)&&(c<=array[i].x2)&&(d>=array[i].y1)&&(d<=array[i].y2)&&(status&0x01))
            {
               sound(250);
               delay(50);
               nosound();
               if (BPos(array[i])==0) // if not pressed
              {
                 array[i].pos=1;
                 DrawButton(array[i]);
                 delay(200); // illusion of button being pressed
                 array[i].pos=0;
                 DrawButton(array[i]);
                 if (i==0) // Start
                {
                   mouse_cursor_off();
                   clearviewport();
                   free(array);
                   game1(1,name);
                }
                 if (i==1) // Load Game
                {
                   mouse_cursor_off();
                   clearviewport();
                   free(array);
                   ins();
                }
                 if (i==2) // Instructions
                {
                   mouse_cursor_off();
                   clearviewport();
                   free(array);
                   ins();
                }
                 if (i==3) // High Score
                {
                   mouse_cursor_off();
                   clearviewport();
                   free(array);
                   high();
                }
                 if (i==4) // Exit
                {
                   closegraph();
                   free(array);
                   sound(250);
                   delay(4);
                   nosound();
                   exit(1);
                }
              } // end if
               if (BPos(array[i])==1)
              {
                 array[i].pos=0;
                 DrawButton(array[i]);
                 if (i==2)
                {
                   closegraph();
                   free(array);
                   sound(250);
                   delay(4);
                   nosound();
                   exit(1);
                } // if
                break;
              } // if
            } // if
          } // for
    } // while
} // menu func

User is offlineProfile CardPM
+Quote Post

no2pencil
RE: [C Graphics] How Do I Create A "window Opening"?
31 Jan, 2008 - 04:59 AM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 7,143



Thanked: 77 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
Check the MSND documentation for the function MessageBox.

CODE

/*
* Example MessageBox Return Value,
* This code is untested!
*/
#include <stdio.h>

int main(void) {
  int yesno=0;

  yesno = MessageBox(,"Select Yes No or Cancel","Selection",MB_ICONHAND | MB_YESNOCANCEL);

  if(yesno==IDYES) {
    MessageBox(,"Yay!","Yes",MB_ICONHAND)
  }

  return 0;
}

User is online!Profile CardPM
+Quote Post

ISAI
RE: [C Graphics] How Do I Create A "window Opening"?
31 Jan, 2008 - 06:03 AM
Post #3

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 41


My Contributions
QUOTE(no2pencil @ 31 Jan, 2008 - 05:59 AM) *

Check the MSND documentation for the function MessageBox.

CODE

/*
* Example MessageBox Return Value,
* This code is untested!
*/
#include <stdio.h>

int main(void) {
  int yesno=0;

  yesno = MessageBox(,"Select Yes No or Cancel","Selection",MB_ICONHAND | MB_YESNOCANCEL);

  if(yesno==IDYES) {
    MessageBox(,"Yay!","Yes",MB_ICONHAND)
  }

  return 0;
}



It doesn't work.. the compiler is asking for a prototype for MessageBox and it doesn't have one in the compiler..
Is there another way?
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: [C Graphics] How Do I Create A "window Opening"?
31 Jan, 2008 - 06:10 AM
Post #4

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 7,143



Thanked: 77 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(ISAI @ 31 Jan, 2008 - 07:03 AM) *

QUOTE(no2pencil @ 31 Jan, 2008 - 05:59 AM) *

Check the MSND documentation for the function MessageBox.

CODE

/*
* Example MessageBox Return Value,
* This code is untested!
*/
#include <stdio.h>

int main(void) {
  int yesno=0;

  yesno = MessageBox(,"Select Yes No or Cancel","Selection",MB_ICONHAND | MB_YESNOCANCEL);

  if(yesno==IDYES) {
    MessageBox(,"Yay!","Yes",MB_ICONHAND)
  }

  return 0;
}



It doesn't work.. the compiler is asking for a prototype for MessageBox and it doesn't have one in the compiler..
Is there another way?

Check the MSDN... I was unable to compile the example b/c I am at work. All of the information is available on the link provided.

QUOTE

Check the MSND documentation for the function MessageBox.

User is online!Profile CardPM
+Quote Post

ISAI
RE: [C Graphics] How Do I Create A "window Opening"?
31 Jan, 2008 - 06:22 AM
Post #5

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 41


My Contributions
I visited the link you provided, but I don't think you know what I mean by a window opening so much..
I hope this will clear it up:

IPB Image

*clicking Quit button*

IPB Image

If the user pressed the Quit button, I want that the buttons will disappear and display that message..

This post has been edited by ISAI: 31 Jan, 2008 - 06:23 AM
User is offlineProfile CardPM
+Quote Post

ISAI
RE: [C Graphics] How Do I Create A "window Opening"?
3 Feb, 2008 - 02:22 AM
Post #6

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 41


My Contributions
please someone help me :'[
User is offlineProfile CardPM
+Quote Post

WXY
RE: [C Graphics] How Do I Create A "window Opening"?
3 Feb, 2008 - 03:47 AM
Post #7

D.I.C Head
Group Icon

Joined: 2 Jan, 2008
Posts: 85


Dream Kudos: 50
My Contributions
So you want an in application UI system? From what I can see, you could add a new property to your structure named "button" and make the function "DrawButton" reject drawing buttons that don't have the property set (or the inverse if you decide to name it hide) from there on you should be able to remember which buttons you've hidden by a dynamically allocated array (since your buttons seems to be stored that way anyways) and unhide them if the user clicks no in your exit confirm message.
User is offlineProfile CardPM
+Quote Post

ISAI
RE: [C Graphics] How Do I Create A "window Opening"?
3 Feb, 2008 - 11:01 AM
Post #8

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 41


My Contributions
QUOTE(WXY @ 3 Feb, 2008 - 04:47 AM) *

So you want an in application UI system? From what I can see, you could add a new property to your structure named "button" and make the function "DrawButton" reject drawing buttons that don't have the property set (or the inverse if you decide to name it hide) from there on you should be able to remember which buttons you've hidden by a dynamically allocated array (since your buttons seems to be stored that way anyways) and unhide them if the user clicks no in your exit confirm message.


I have no idea what's a UI system..
Could you be more spesific? or show me a code example?

Thanks.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 02:04PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month