How to make an image popup?

Hello, I have a School project that I need some help with. Our teacher wants us to make a timeline showing a picture from each year of our lives. I thought of a creative way of doing this in c++, make the user input the year they want to see, then make the image popup on the screen. Is this possible and how would I go about doing this? I am not very good at c++, so please explain things easily :]. Here is the code I have so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>

using namespace std;

int main()
{

int userInput;

cout << "Hello and welcome to my timeline!" << endl;
cout << "Please type in what year you would like to see and press enter" << endl;

cin >> userInput;

if(userInput == 0){
             // Show picture here
             }
             else if(userInput == 1)
             {
                  // Show picture here
                  }
                  else if(userInput == 2)
             {
                  // Show picture here
                  }
                  else if(userInput == 3)
             {
                  // Show picture here
                  }
                  else if(userInput == 4)
             {
                  // Show picture here
                  }
                  else if(userInput == 5)
             {
                  // Show picture here
                  }
                  else if(userInput == 6)
             {
                  // Show picture here
                  }
                  else if(userInput == 7)
             {
                  // Show picture here
                  }
                  else if(userInput == 8)
             {
                  // Show picture here
                  }
                  else if(userInput == 9)
             {
                  // Show picture here
                  }
                  else if(userInput == 10)
             {
                  // Show picture here
                  }
                  else if(userInput == 11)
             {
                  // Show picture here
                  }
                  else if(userInput == 12)
             {
                  // Show picture here
                  }
                  else
                  {
                      cout << "Invalid Number" << endl;
                      }
                      
             }

             

Thanks for your help!
a) i would use a switch over a long if/else-if chain like that
b) i would use a while loop with functions over (a)
c) the easiest (imo) is qtsdl. just have a text box, then whenever they input a number (that is checked to be valid first) draw the appropraite image to the screen
Last edited on
Thanks, how would I draw the image to the screen?
cant remember off the top of my head but when i learned sdl i used this site: http://lazyfoo.net/tutorials/SDL/01_hello_SDL/index.php and it will teach you what you want to know
It might be as simple as manipulating another application to display the image.

If you are on nixen (for school), look into xv for something simple. I'd be surprised if your school's system didn't have it (or something similar, such as Eye of Gnome). On Windows, check out IrfanView.

All work similarly -- start a child process with the file to display as command-line argument, and then watch for its termination (though that's not strictly necessary).


All other options involve a good deal more work. The SFML or SDL options are probably the simplest -- but your application would then be an SFML or SDL application, and you'd have to get user input in some way.

It might be a good idea, though, because you can "draw" a timeline (display a picture? that you can click to cause the picture to display).


In any case, good luck!
If you're using windows, you can do something to this effect.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <string>

int main(int argc, char* argv[]) {
	if (argc != 2) {
		return 1;
	}
	std::string filepath = argv[1];
	std::string _Command = "rundll32.exe \"%ProgramFiles%\\Windows Photo Viewer\\PhotoViewer.dll\", ImageView_Fullscreen ";

	_Command += filepath;

	system(_Command.c_str());

	return 0;
}


This program takes one (technically two) command line argument(s), namely the path of the image file you wish to open.
We store the path directory in a string named "filepath".
Then, we store a string, whose contents will be used as a command for the system() function. This particular command uses rundll32.exe from system32 to load the Windows Photo Viewer stock software (PhotoViewer.dll) with some parameters of its own.

I find this is easier to understand than to introduce some third party API.
I think in this case, it's not evil to recommend the usage of system() to a beginner, because - yes, there are security issues and whatnot, but it's highly unlikely that your professors computer will be compromised in such a way that your little software can cause any real damage. As long as you don't use it habitually, or because you aren't aware of any alternatives, or unaware of why you shouldn't be using it, I think this is fine.

Anyways, if you are using windows, you can modify this program to fit your needs - maybe by creating a vector or an array of file paths?
Last edited on
It's a valid use of system(). No one has given you guff for it, have they?

[edit]
I still think a picture of a timeline you can click on to bring up more pictures would be a cooler result, and learning SDL or SFML enough to do it isn't that difficult.

The hardest thing might actually be convincing the CS staff to install one on the PCs at school.
Last edited on
duoas youve disappointed me. you should never use system
http://www.cplusplus.com/forum/articles/11153/ you even wrote the article
Grow up.
Thanks for the help everyone. I will think about all of these options.
It's a valid use of system(). No one has given you guff for it, have they?

Haha! No. I was just setting up barricades in case I get hurricane'd.
Yeah, this creative thought may be realized if you set the year displaying in the image form, and use a compatible image opening , viewing and processing tool to set the image in popup form by programming a fixed poject.


http://www.rasteredge.com/how-to/vb-net-imaging/imaging-processing/


http://www.rasteredge.com/how-to/vb-net-imaging/sdk-programming/

Topic archived. No new replies allowed.