Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

C++ console prog some questions


ghost's Avatar
0 0

hi, again need little help.. i hew few questions:

  1. how to change console appearance? i dont want black background and white font, i want.. for example blue background and yellow font (as award bios :)) can i do this in c++? i saw this in visual c++, but i dont know this… i need c++ and for this i havent found some good tuts
  2. how can i run my program every in fullscreen mode?? its every running in minimalized mode and i cant resize it…
  3. how can i do.. for example a question "Do you really want to delete this file?" and under this two buttons Yes and No, user must select one…
  4. how can i do a hotkey? a use example from 3, "Do you really want to delete this file?" and Yes and No, when user press y then yes, when n then no, else nothing thats all for now thx in advance for any help ;)

ghost's Avatar
0 0
  1. system("color 1e");

2)```markup void full() { CONSOLE_CURSOR_INFO cursor; HANDLE hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleCursorInfo(hConsoleOut,&cursor); cursor.bVisible = FALSE; SetConsoleCursorInfo(hConsoleOut,&cursor); keybd_event(VK_MENU, 0x38, 0, 0); keybd_event(VK_RETURN, 0x1c, 0, 1); keybd_event(VK_RETURN, 0x1c, KEYEVENTF_KEYUP, 1); keybd_event(VK_MENU, 0x38, KEYEVENTF_KEYUP, 1); }


3 and 4) You'll need to make a GUI application for that.

Edit: Damn smileys

ghost's Avatar
0 0

thanks mastergamer… to 3 and 4, for now i dont want know something about gui, this need time and i must learn how to program in console first… :D thanks again for help ;)


ghost's Avatar
0 0

Actually, I just had an idea. You know the message boxes that programs can bring up saying "Do you want to quit?", right?

Well, you can use them in console apps too, not just GUI apps.

Note: You need to include windows.h for this.

//Ask the user a question with a messagebox
if(MessageBoxA(NULL, "Do you really want to do this?", "Confirm", MB_YESNO + MB_ICONQUESTION) == 6)
{
//User clicked yes
}
else
{
//user clicked no
}

Hope that helps


ghost's Avatar
0 0

ok thanx much thats it!! :D


ghost's Avatar
0 0

another two questions for this thread, i have two probs:

  1. the first problem is with my Dev-C++, i have a project, because i decided that one file is hardest to orientation… so now i have this two source files and two header files: core.cpp, booltest.cpp, Globals.h and includes.h here are the basic content of each one: core.cpp
#include "includes.h"
int main()
{
cout <<......
booltest(); //here is called a void booltest function```
booltest.php
```markupvoid booltest()
{
     if (wasanywhere)
     cout << "\n";```
this two files are in project directory "Core"
now to the headers
Globals.h
```markup//GLOBAL VARIABLES
bool wasanywhere = true;
....
//PROTOTYPES
void booltest();
....```
includes.h
```markup#include <iostream>
#include <string>
#include <windows.h>
using namespace std;```
so to my problem. when i dont have a file core.cpp in my project, everything is fine and sources are successfully compiled, but when is this file included, i get this compiler error:
In function ´void sbin()´;
´wasanywhere´ undeclared (first use this function)
i dont know why i getting ths error, i have included Globals.h in file core.cpp... when i´ll try to include it in booltest.cpp, i get multiple declaration... i dont know what is wrong :(
2) i have problem with if, else statements, i have this source:
```markupif(perform){
//do something
}
if(test1){
//do something
}
if(test2){
//do something
}
else
{
//else do something
}```
with this is everything fine but i need to add a second condition..
```markupif(norpoblems){ //when there are no problems, and bool perform is true...
if(perform){
//do something
}
else{
//there are huge problems...
}
if(test1){
//do something
}
if(test2){
//do something
}
else
{
//else do something
}```
so to my problem, when are the problems detected... i get this output:
//there are huge problems
//else do something
so i get content of both elses, but i need content only frm that first there are huge problems, how can i do this?
thanks in advance for any help

ghost's Avatar
0 0

Hi, dancuc.

In order to allow a header file to be referenced from more than one file you'll need to add these lines at the top of the header file:

#define _globals_h_```

and also add this line at the end of the file:
```markup#endif```

This will cure your multiple declarations error.

I can't see a declaration for 'wasanywhere' in your code. What is it? A boolean variable?


For your if statements problem you could try the following:
```markupif(norpoblems){ //when there are no problems, and bool perform is true...
if(perform){
//do something
}
else{
//there are huge problems...
}

if (perform) {
 if(test1){
 //do something
 }
 if(test2){
 //do something
 }
 else
 {
 //else do something
 }
}

This way your second set of tests will only be carried out if perform is true. (i.e. if it didn't fail the first test)

Depending on what you're trying to do and whether it's appropriate you could include the tests inside the first if statement:

if(perform){
//do something
if(test1){
//do something
}
if(test2){
//do something
}
else
{
//else do something
}```

Hope this helps
}
else{
//there are huge problems...
}


ghost's Avatar
0 0

thank you very much for your help, for your question what is wasanywhere, it is a boolean, sorry, forget to declare it, i was write that code from head.. :( again thanks for your help