Find the screen position and size of all the menus. Then do a simple check for if number one Form1 is the form on top and if any of the other menus are covered. You can do this by doing:
for the 4 corners of smaller menu
is corner on the right of left side of Form1
is corner on the left of right side of Form1
is corner above the bottom side of Form1
is corner below the top side of Form1
then it is inside
else it's not inside
You can find formulas for that kind of thing online.
Ok, thanks. :smile:
Okay guys, I've just started with learning C, so don't mind me for stupid questions. Anyway, here's this code:
[code]#include <stdio.h>
main()
{
int c;
while (c != EOF)
{
c = getchar();
putchar(c);
}
}[/code]
The "c != EOF" part doesn't seem to have a point, since the program never stops anyway, and acts the same if I put, say, "c = "r"", or even "c [b]=[/b] EOF". Something wrong, or is the program supposed to repeat this input/output infinitely? If so, what is the point of that "c != EOF)"?
I'm reading "The C Programming Language" book, and it doesn't really explain stuff very well. Some other good C book to read?
Well, that would let you quit by pressing Ctrl-Z.
[QUOTE=shill le 2nd;22252706]Well, that would let you quit by pressing Ctrl-Z.[/QUOTE]
If I put "while (c = EOF)", the program continues running, even if in the input there's no EOF. Also, the book says that the variable (c) must me declared as [i]int[/i] because [i]char[/i] isn't big enough to hold EOF, which is wrong, it's working the same when I use char.
Yeah, you do need to use int if you want to catch EOF, but if your book said char "isn't big enough" to hold EOF, that a horrible way to word it, since EOF on most compilers is -1. char is usually an unsigned byte, so it can't hold any negative numbers.
The technical explanation is:
[quote]If the integer value returned by getchar() is stored into a variable of
type char and then compared against the integer constant EOF, the
comparison may never succeed, because sign-extension of a variable of type
char on widening to integer is implementation-defined[/quote]
edit: actually, whether char is signed or unsigned is also implementation-defined
[QUOTE=EdoI;22252509]
I'm reading "The C Programming Language" book, and it doesn't really explain stuff very well. Some other good C book to read?[/QUOTE]
First or second edition? Either way, one is from the late 70's and the other is from the late 80's. They're not good references for contemporary C. One example is your main function prototype; it should be "int main()", not just "main()", which is the old style.
Checking for EOF is also pretty archaic, there are only a few ways for stdin (standard input pipe) to close on a modern system, and even less for a read operation to error (which would also cause EOF to be returned).
Second edition. How about the book "Let us C"? I googled a bit, and found this book getting mentioned a few times. Is it more up-to-date when it comes to contemporary C, and is it beginner-friendly?
I'm trying to get SFML working on Ubuntu and sfml-system works fine, but as soon as I link sfml-window, I'm getting a segfault. The code file contains the basic SFML example.
[code]overv@overv-desktop:~/Development/SFMLTest$ g++ -c main.cpp
overv@overv-desktop:~/Development/SFMLTest$ g++ -o main main.o -lsfml-system
overv@overv-desktop:~/Development/SFMLTest$ ./main
1.96032e-06
0.500192
1.00028
1.50035
2.00042
2.5005
3.00058
3.50065
4.00073
4.50081
overv@overv-desktop:~/Development/SFMLTest$ g++ -o main main.o -lsfml-window -lsfml-system
overv@overv-desktop:~/Development/SFMLTest$ ./main
Segmentation fault[/code]
Is my library broken or did I forget something?
Okay, so I want to have a two-word string to read, but it doesn't work.
[code]
#include <stdio.h>
#include <tchar.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
string name;
string reply;
char strnew[255];
// Death func
int death();
// The sections
int s1();
int s1torch();
int s1zombie();
int s1pit();
int s1as();
int s2();
int s2back();
int s2wall();
int s2eatbrick();
int s2pushbrick();
int s2pullbrick();
int s3();
// Deciders
int retID(string caseR);
int retID2(string caseR);
int retID3(string caseR);
int retID4(string caseR);
int retID5(string caseR);
int retID(string caseR)
{
if (caseR == "NORTH" || caseR == "north" || caseR == "North") {
return 1;}
if (caseR == "SOUTH" || caseR == "south" || caseR == "South") {
return 2; }
if (caseR == "WEST" || caseR == "west" || caseR == "WEST") {
return 3; }
}
int retID2(string caseR)
{
if (caseR == "TORCH" || caseR == "Torch" || caseR == "torch") {
return 1;}
if (caseR == "SOUTH" || caseR == "South" || caseR == "south") {
return 2; }
if (caseR == "WEST" || caseR == "West" || caseR == "west") {
return 3; }
if (caseR == "NORTH" || caseR == "North" || caseR == "north") {
return 4;
}
}
int retID3(string caseR)
{
if (caseR == "SOUTH" || caseR == "South" || caseR == "south") {
return 1; }
if (caseR == "WEST" || caseR == "West" || caseR == "west") {
return 2; }
if (caseR == "NORTH" || caseR == "North" || caseR == "north") {
return 3; }
}
int retID4(string caseR)
{
if (caseR == "SOUTH" || caseR == "South" || caseR == "south") {
return 1; }
if (caseR == "WEST" || caseR == "West" || caseR == "west") {
return 2; }
if (caseR == "WALL" || caseR == "Wall" || caseR == "wall") {
return 3; }
}
int retID5(string caseR)
{
if (caseR == "VERB BRICK" || caseR == "Verb Brick" || caseR == "verb brick" || caseR == "verb Brick" || caseR == "Verb brick") {
return 1; }
if (caseR == "EAT BRICK" || caseR == "Eat Brick" || caseR == "eat brick" || caseR == "eat Brick" || caseR == "Eat brick" ) {
return 2; }
if (caseR == "PUSH BRICK" || caseR == "Push Brick" || caseR == "push brick" || caseR == "push Brick" || caseR == "Push brick") {
return 3; }
if (caseR == "PULL BRICK" || caseR == "Pull Brick" || caseR == "pull brick" || caseR == "pull Brick" || caseR == "Pull brick" ) {
return 4; }
}
// greeting
int main()
{
cout << "Greetings! Welcome to the Turnip Role Playing Game! \n I am the Dungeon Master! Let's begin! \n What is your first name? \n";
cin >> name;
system("cls");
cout << "Okay, " << name << ", let's get down to buisness! \n PRESS ENTER TO CONTINUE";
system("pause >Nul");
s1();
}
// First part of the adventure
int s1()
{
system("cls");
cout << "You awake in a dark area. The drip of water fills echos throughout the dark corridor. Your choices to move are North, South, or West.\n <ANSWER IN ALL CAPS, ONE WORD> \n";
cin >> reply;
switch(retID(reply))
{
case 1:
s1torch();
break;
case 2:
s1zombie();
break;
case 3:
s1pit();
break;
default:
cout << "You can't do that!";
system("pause >Nul");
s1();
}
return 0;
}
// TORCH GET :D
int s1torch()
{
system("cls");
cout << "You stumble northward, only to trip on a long object. Upon further investigation, you find out that it is a TORCH. \n You can go NORTH, WEST, SOUTH, or TORCH.\n";
cin >> reply;
switch(retID2(reply))
{
case 1:
s2();
break;
case 2:
s1();
break;
case 3:
s1as();
break;
default:
cout << "You cannot do that!";
system("pause >Nul");
s1torch();
}
return 0;
}
int s2()
{
system("cls");
cout << "You grab the torch and it magically lights up. You can see the stone walls and floors, signifying you're in a dungeon. \n Your options are NORTH, WEST, and SOUTH. \n";
cin >> reply;
switch(retID3(reply))
{
case 1:
s2back();
break;
case 2:
s1pit();
case 3:
s1as();
break;
default:
cout << "You cannot do that!";
}
return 0;
}
int s2back()
{
cout << "You return back to the room you originally started in. You see a strange indentation in the EAST WALL. \n Your options are SOUTH, WEST, or WALL. \n";
cin >> reply;
switch(retID4(reply))
{
case 1:
s1zombie();
break;
case 2:
s1pit();
break;
case 3:
s2wall();
break;
default:
cout << "You cannot do that!";
}
return 0;
}
int s2wall()
{
system("cls");
cout << "You investigate the strange indentation in the wall. To the left lies a loose BRICK. The BRICK is jutting out of the wall about two inches, enough to push or pull it. What do you do with BRICK? \n (Use two words: IE verb brick) \n";
cin >> reply;
switch(retID5(reply))
{
// Smart-Aleck response
case 1:
cout << "Silly " << name << "! That was an example. Now go back there and do it right!";
s2wall();
break;
case 2:
s2eatbrick();
break;
case 3:
s2pushbrick();
break;
case 4:
s2pullbrick();
break;
default:
system("cls");
cout << "You can't do that!";
system("pause >Nul");
s2wall();
}
return 0;
}
int s2pushbrick()
{
}
// Death
int s1as()
{
cout << "You head west, leaving the torch behind. You begin to explore the area you are in. Suddenly you hear the sound of a sword unsheathing, and feel someone - or something's - presence. A katana rips through your abdomen, leaving our halved on the floor.";
system("pause >Nul");
death();
return 0;
}
int s1zombie()
{
system("cls");
cout << "You cautiously walk southbound. You hear a strange moaning from behind you. Before you have a chance to react, a ZOMBIE jumps on top of you. You can feel the flesh being ripped from your bones as you draw your last breath...";
system("pause >Nul");
death();
return 0;
}
int s1pit()
{
system("cls");
cout << "You walk towards the West. You begin to hear the crunch of leaves. \n Just as you begin to wonder why you hear the crunch of leaves in a dark area, you begin to fall. And fall... And fall. \n Your screams of both terror and joy (You did enjoy Ye Olde Rollercoasters as a child) are quashed by spikes at the bottom of the pit.";
system("pause >Nul");
death();
return 0;
}
int s2eatbrick()
{
system("cls");
cout << "You eat the brick. It tastes brick-like. You realize you made a stupid mistake (which is true) and fall on the floor dead. Wow, you're an idiot.";
system("pause >Nul");
death();
return 0;
}
int s2pullbrick()
{
system("cls");
cout << "You pull on the brick with all of your might. Since you skipped out on Ye Olde Architecture Class in school, you didn't realize it was a load bearing brick. \n The entire wall falls on you, instantly killing you";
system ("pause >Nul");
death();
return 0;
}
// Death Func
int death()
{
system("cls");
cout << "Congratulations! You have died. Press enter to return to the beginning!";
system("pause >Nul");
system("cls");
s1();
return 0;
}
/* CREDITS:
Lead programmer: ME
Troubleshooter: Firehawk
Beta Testers: ME , Michael "Meow" Gervais
*/
[/code]
It's under s2wall and it won't work. It gives me the "Cannot do that" message twice! My friend said to tokenize the string, but he doesn't know how to do that! Help!
use cin.getline()
[url]http://www.cplusplus.com/reference/iostream/istream/getline/[/url]
For some reason, I'm getting a linker error after creating a global vector, says it's already defined in main.obj
[code] error LNK2005: "class std::vector<struct VertexList,class std::allocator<struct VertexList> > render_meshes" (?render_meshes@@3V?$vector@UVertexList@@V?$allocator@UVertexList@@@std@@@std@@A) already defined in main.obj[/code]
And yes, I do already have an #ifndef
[QUOTE=ryandaniels;22267430]For some reason, I'm getting a linker error after creating a global vector, says it's already defined in main.obj
[code] error LNK2005: "class std::vector<struct VertexList,class std::allocator<struct VertexList> > render_meshes" (?render_meshes@@3V?$vector@UVertexList@@V?$allocator@UVertexList@@@std@@@std@@A) already defined in main.obj[/code]
And yes, I do already have an #ifndef[/QUOTE]
Use the extern keyword in the header, then define it in exactly one of your .cpp files.
[quote]Since the compiler translates each source file on its own...in a so-called translation unit, preprocessor directives such as inclusion guards (that are supposed to prevent multiplu defined symbols) are not stored across different translation units, thus, it won't prevent multiple inclusions of the file in different units. Inclusion guards only prevent the inclusion of the same header more than once in the same compilation unit.[/quote]
[url]http://www.codeguru.com/forum/showthread.php?t=371833[/url]
Perfect, thanks
[QUOTE=jA_cOp;22255997]First or second edition? Either way, one is from the late 70's and the other is from the late 80's. They're not good references for contemporary C. One example is your main function prototype; it should be "int main()", not just "main()", which is the old style.
Checking for EOF is also pretty archaic, there are only a few ways for stdin (standard input pipe) to close on a modern system, and even less for a read operation to error (which would also cause EOF to be returned).[/QUOTE]
I'm still looking for a decent book on C99. I don't think there is one. I found out yesterday that there is a C1x standard in development too.
[QUOTE=blankthemuffin;22268409]I'm still looking for a decent book on C99. I don't think there is one. I found out yesterday that there is a C1x standard in development too.[/QUOTE]
We had a discussion in IRC about C1X a while ago. Remember the wikipedia article had a revision concerning wise bearded guru's?
[url]http://en.wikipedia.org/w/index.php?title=C1X&oldid=342050501[/url]
[QUOTE=Chandler;22268551]We had a discussion in IRC about C1X a while ago. Remember the wikipedia article had a revision concerning wise bearded guru's?
[url]http://en.wikipedia.org/w/index.php?title=C1X&oldid=342050501[/url][/QUOTE]
Oh I do remember that now.
[QUOTE=blankthemuffin;22268409]I'm still looking for a decent book on C99. I don't think there is one. I found out yesterday that there is a C1x standard in development too.[/QUOTE]
Yeah, but "The C Programming Language" doesn't even cover C89 completely as far as I know. It is based on a draft of what became C89.
Even then, I am surprised it uses a main function prototype without a return value.
[QUOTE=jA_cOp;22268888]Yeah, but "The C Programming Language" doesn't even cover C89 completely as far as I know. It is based on a draft of what became C89.
Even then, I am surprised it uses a main function prototype without a return value.[/QUOTE]
On Plan 9 from Bell labs, the successor to Unix which no one really cares about, they removed the use of int main, and you're required to actually use void main, since you can check the process in /proc/ which is something that Linux borrowed.
[QUOTE=Chandler;22270289]On Plan 9 from Bell labs, the successor to Unix which no one really cares about, they removed the use of int main, and you're required to actually use void main, since you can check the process in /proc/ which is something that Linux borrowed.[/QUOTE]
void main is one thing - that just means you forfeit the ability to return a specific error code from main. That's ok - sometimes. Like code for embedded systems. But main without a return value at all is just not sanitary and I don't know the logic or grammatical rule behind it - and I'm not sure if I even want to know :v:
[QUOTE=jA_cOp;22270355]void main is one thing - that just means you forfeit the ability to return a specific error code from main. That's ok - sometimes. Like code for embedded systems. But main without a return value at all is just not sanitary and I don't know the logic or grammatical rule behind it - and I'm not sure if I even want to know :v:[/QUOTE]
the use of an int main is so that you can determine if something went wrong with a programs execution. If you can inspect the state of the program (in this case via /proc/) then effectively, there is no need to know what the program is returning since you can just SEE what the program is doing in real time.
[QUOTE=Chandler;22270407]the use of an int main is so that you can determine if something went wrong with a programs execution. If you can inspect the state of the program (in this case via /proc/) then effectively, there is no need to know what the program is returning since you can just SEE what the program is doing in real time.[/QUOTE]
Yeah, I know, that's exactly what I'm saying. "void main(...)" is often fine. No special case, no inferred void (if that is what it even is), no unnecessary magic. A conscious decision that makes your program less portable.
[QUOTE=jA_cOp;22255997]Checking for EOF is also pretty archaic, there are only a few ways for stdin (standard input pipe) to close on a modern system, and even less for a read operation to error (which would also cause EOF to be returned).[/QUOTE]
That's not the best advice, checking for EOF is necessary if you want your program to be able to be piped input.
The book for my course at college says VB.net is NOT an imperative language but it IS event-driven.
I'd have thought VB.net IS imperative in that you basically have a main() function and procedures (Please correct me if I've misunderstood what this means). Also Wikipedia lists VB.net under imperative languages.
What do we think? I'd like to be clear on this in case a question comes up in the exam.
Is there any efficient way of capturing the screen, based on a window handle?
Right now I'm doing it with basic bitmap capturing, so GDI, but that eats like 20% of cpu power....
I mean you can capture directX applications via the graphics adapter, but I need to capture the desktop.
Because I want to make a program where you choose a window, then a source rectangle of that window, and overlay that resulting stream via directx.
i.e. A picture in picture program, f.e. to watch videos while playing games.
[QUOTE=s0ul0r;22283889]Is there any efficient way of capturing the screen, based on a window handle?
Right now I'm doing it with basic bitmap capturing, so GDI, but that eats like 20% of cpu power....
I mean you can capture directX applications via the graphics adapter, but I need to capture the desktop.
Because I want to make a program where you choose a window, then a source rectangle of that window, and overlay that resulting stream via directx.
i.e. A picture in picture program, f.e. to watch videos while playing games.[/QUOTE]
I think this would be pretty easy to do in Vista/7, you just need to find where DWM stores the buffer of the window.
[url]http://msdn.microsoft.com/en-us/library/aa969540%28VS.85%29.aspx[/url] ?
[QUOTE=turb_;22274379]That's not the best advice, checking for EOF is necessary if you want your program to be able to be piped input.[/QUOTE]
Good point, checking for EOF in a console application sounds like pretty good practice.
[QUOTE=Vampired;22280015]The book for my course at college says VB.net is NOT an imperative language but it IS event-driven.
I'd have thought VB.net IS imperative in that you basically have a main() function and procedures (Please correct me if I've misunderstood what this means). Also Wikipedia lists VB.net under imperative languages.
What do we think? I'd like to be clear on this in case a question comes up in the exam.[/QUOTE]
Here we go again with vague language categories. "Imperative" is more vague than "procedural". It's very easy to argue that VB.net fulfils both imperative and event-driven paradigms. No language is entirely bound to just one. Imperative can simply mean that a program can change its own state, e.g. change the value of a global variable. The contrast to imperative is not event-driven, but functional. In functional programming, everything is a function that has to return one value, and can't change any other location in memory. The contrast to event-driven programming is batch programming. So I'd say that VB.net is an imperative, event-driven language.
Although, you could probably use VB.net as a functional batch language if you wanted to. It's very versatile. It supports lambda expressions for functional programming, and you can ignore events and make a batch program.
[QUOTE=shill le 2nd;22286079]Here we go again with vague language categories. "Imperative" is more vague than "procedural". It's very easy to argue that VB.net fulfils both imperative and event-driven paradigms. No language is entirely bound to just one. Imperative can simply mean that a program can change its own state, e.g. change the value of a global variable. The contrast to imperative is not event-driven, but functional. In functional programming, everything is a function that has to return one value, and can't change any other location in memory. The contrast to event-driven programming is batch programming. So I'd say that VB.net is an imperative, event-driven language.
Although, you could probably use VB.net as a functional batch language if you wanted to. It's very versatile. It supports lambda expressions for functional programming, and you can ignore events and make a batch program.[/QUOTE]
Thankyou for the answer, it cleared everything up for me
Working with opengl and sfml; After changing the clear color to grey rather than black, and enabling scissor testing, the area outside my viewport flashes back and forth between black and grey, this happening every time I render.
I accidentally stumbled upon the a spot that controls this behavior:
[code]
Window::Window() {
this->app= new sf::Window(sf::VideoMode(INIT_W, INIT_H, BPP), "Settlers", sf::Style::Close);
glEnable(GL_SCISSOR_TEST);
glClearColor(0.3f, 0.2f, .1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
[/code]
If I comment out glClear(), then the area that was flashing remains black. It seems that whatever color I clear the screen to before using scissor boxes, the screen will flip between it and black every time I render.
Sorry, you need to Log In to post a reply to this thread.