C++ Learning Community Forum
August 01, 2010, 03:19:21 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Hello. Smiley
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Creating a Window  (Read 793 times)
Garfeld55
N00b!!1
*
Posts: 10


View Profile
« on: November 04, 2009, 02:03:56 AM »

Hi everybody!

I started learning programming in my web design class in high school. I realized that I could do wonderful things with HTML and Javascript! I barrowed a friend's book on Java and quickly learned Java up to GUI. I stopped because I had to return the book. I decided to take C++ in college but I am stuck learning newbie things like ifs fors and switches...basic things. I read my textbook and learned about Object Orientation (which I previously new from Java) and I created a console application. I expanded this application to a point where now, in order to make it so that it is user-friendly, I must now move on to making a GUI for it.

I researched Win32 API and watched a few videos, browsed a few forums but they all give me the same code for creating a window. It's called the skeleton of a window. I was told that all windows start with that exact code, unfortunatly nobody says anything in all the places that I searched what any of that means to me as a programmer. I cannot see the correlation between my code that I have made for my program and how it will work within the window. (understanding that I have much to learn about GUI) They don't give you a list of functions that do stuff, they tell you where to put the PAINT stuff but it doesn't give you the means to do that. I know C++ - not the machine language to do that.

Furthermore, when browsing some topics on this forum I saw a post that printed the skeleton code and basically said: wth is this and what do I do with it? - it sounded exactly like my question. So I followed some links but, they did not 'click' for me. //no pun intended (the links worked  Wink )

So, basically my question is can anybody explain to me how to make a simple window and give me (or point me to) a list of functions that the computer will understand that make buttons and such. Maybe if you have a simple program you wrote that you could show me and point out things in the code? If you want me to, I can post the Skeleton code here and maybe you can tell me what each part means.

Through basic looking through that code, I understand that all Win API programs have a WinMain function, I understand it calls WinProc etc., but what does that mean to me as a programmer? I know it is constantly looking for events I understand that.

I'm not really sure if I am being clear about my question because it seems everywhere I go they are telling me the same thing, which I don't GET so it can be a little frustrating. If you would like to ask me questions I gladly answer them. Any help would be much appreciated - even if you tell me something I already know, it might help me narrow down my question.

Thank-you to anyone who replies.
Logged
ih8censorship
Megalomaniac!!!
Administrator
C++ guru
*****
Posts: 1236



View Profile
« Reply #1 on: November 04, 2009, 05:21:43 AM »

On the windows api level (XP and before, as I have 0 experience with Vista or 7) buttons are created by calling the same function you used to create the window in the first place CreateWindowEx (with different arguments of course) I know it seems strange, but look at your browser window. Now look at the edit boxes, menus and tabs. Those are windows too!  Smiley They are children of your browser window, and your browser window is a child of the desktop (which is why it appears on the taskbar)

a WndProc is a callback function. I don't know if java has that. Its a function that is passed as a function pointer to something else, which uses it. You don't ever use the WndProc directly. The WndProc is where you specify what buttons do what, or what gets drawn on the screen, or what happens when a person uses some menu option.

I'd make you an example, but it's getting pretty late for me :-/ I know you have already probably gotten sent to the forgers tutorial a dozen times allready, but here it is just in case you didnt http://winprog.org/tutorial/
Logged

PC==perfect_companion

Knowledge cannot come packaged and predigested; it must be chewed over carefully before swallowed.

What have you tried?
Garfeld55
N00b!!1
*
Posts: 10


View Profile
« Reply #2 on: November 05, 2009, 12:37:58 AM »

Ok, so I researched for a couple more hours tonight and came up with a program (Based on the skeleton code) that opens a window and I can add my own Title to the window using TEXT("My Title") in one of the arguements.

So, now I want to try to put an image into my program just to see what will happen Like a jpeg of a card or something. I am under the impression that I have to use resources? Not too sure.
I am using MSVC++.

I am wondering where would I put code to add a JPEG image of a card for my deck. For example (i'm not asking for code just telling you what I plan on doing) I want to have it draw a card and a new card appears next to the other card in a HAND section.

Also I am wondering how I can incorporate my code from my console program into this Window? I don't know any functions to do anything where do you learn it all?
Logged
Garfeld55
N00b!!1
*
Posts: 10


View Profile
« Reply #3 on: November 06, 2009, 02:14:45 AM »

Guys I have a question. (I know I have a lot)

Basically I am trying to make a game that I can just play with my friend over LAN or hamachi or something? idk anything about how to do that.

Do you think it would be better for me to get my console application to work over the internet with another computer (if that's even possible) or should I learn to create the window and GUI for my game first.

If you suggest the first choice, can you give me some idea on how to do that or place i can go to learn how to do that.

If you suggest the second choice, I still am completely lost with making my window. I can open a window and make a custom title. I understand the switch statement and how messages are recieved. But what are the names of all the messages. Where can I learn all the functions? (example:  WM_LBUTTONDOWN) stuff like that.
Logged
ih8censorship
Megalomaniac!!!
Administrator
C++ guru
*****
Posts: 1236



View Profile
« Reply #4 on: November 06, 2009, 04:16:39 AM »

I generally do backend stuff first, and then do the front end. Mostly because I have more fun with the backend. Also, GUI's are easier to design once than add things in, so if you have a working backend you know exactly what you'll need.

To do a network game, you'll need to learn to use sockets. There is Winsock which is built into Windows operating systems, look for Johnnies winsock tutorial, that was a good one.

really though, you could do whatever you want. If you want a console program to communicate over the net, fine, if you don't, thats fine too Smiley
Logged

PC==perfect_companion

Knowledge cannot come packaged and predigested; it must be chewed over carefully before swallowed.

What have you tried?
Garfeld55
N00b!!1
*
Posts: 10


View Profile
« Reply #5 on: November 06, 2009, 04:53:11 AM »

I read the socket tutorial. How would a socket enable me to communicate? I don't understand.

Would I create a listening socket on both computers, then have my computer do something and send (what would i send?) something to his computer to tell him what i did.

wouldn't that have a chance of making the program go out of sync. I can't comprehend this.

P.S. Thank you for the information. I truly do appreciate any help I get.
« Last Edit: November 06, 2009, 04:56:21 AM by Garfeld55 » Logged
ih8censorship
Megalomaniac!!!
Administrator
C++ guru
*****
Posts: 1236



View Profile
« Reply #6 on: November 06, 2009, 05:56:43 AM »

You can think of Sockets, as well, sockets. Say you have a couple of computers, some network cables, and a hub or router. The "sockets" here would be all the places where you plug a network cable into, In otherwords the endpoints where the network cables hook into.

The sockets you use in programming are a lot like that- they are end points that you can send and receive data with. Typically one computer has a listening socket (the server) and the other computer(s) have connecting sockets that "make some noise" to the one that is listening for them. Both the listening side, and the side requesting the connection can send and receive data.

One thing you could do, is research different protocols. HTTP and IRC protocol aren't too hard to understand, and once you do you will know more about what is going on behind the scenes of network programming.
Logged

PC==perfect_companion

Knowledge cannot come packaged and predigested; it must be chewed over carefully before swallowed.

What have you tried?
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!