Where does the program code go? Does it go at the very end of the file after all of the winmain stuff? or does it go in between or below this:
// TODO: Place code here.
return 0;
Where does the program code go? Does it go at the very end of the file after all of the winmain stuff? or does it go in between or below this:
// TODO: Place code here.
return 0;
"A computer is this amazingly fast.....but stupid machine." - C++ for dummies
Your program will begin execution at your WinMain function...
I still don't understand. WHERE do I start coding?
(code)
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
(HERE)
{
// TODO: Place code here.
(OR HERE?)
return 0;
}
(/coding)
Do I still use int main() ofterwards or just start coding with things like cout <<"Some text here" ?
"A computer is this amazingly fast.....but stupid machine." - C++ for dummies
No....as I said, WinMain() is your code's point of entry for Win32 Applications.....its main() if you want to write console apps
Alos you cant use iostreams on a Win32 app......read Programming Windows by C Petzold or Windows Programming from the Ground Up by H Schildt.
Also go to;
[list=1][*]Sunlight's Site [*]Ken's Site [/list=1]
Last edited by Fordy; 04-18-2002 at 11:41 PM.
I found this place pretty useful too...
Forgers Win32 Tutorial
I STILL don't get it. Now what's wrong with my code? I get 2 errors.: confused:
#include "stdafx.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
cout << "My first windows program!";
return 0;
}
"A computer is this amazingly fast.....but stupid machine." - C++ for dummies
You can't use cout. That only outputs on command line (or a simulation of it). Instead, you have to explicitly create your own window and write to it.
You should check out the places mentioned by DominicTrix & Fordy. Winprog's tutorials are a useful introductory read if you are starting out.
'cout' - there is no std output unless you make a console wnd -using 'main'. With 'WinMain' you are more or less seting yourself up to do a gui app - which requires use of the win32 API or a class library that encapsulates it.
For your no-money-back-guaranteed 'hello world' windows gui:
Don't try to build on this as it does nothing - go to the sites suggested by Fordy, or do a search, to find explicit examples you feel more comfortable with.Code:#include <windows.h> int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { MessageBox(0,"hello world","Message Box - A simple window",MB_OK); return 0; }
(BTW thanks for the endorsement, Fordy - the cheque's in the post )
OOOOOOOOOOOOOOOOOOOOOOOOOO!
I was thinking about it all wrong. Does anyone know where I can find more info about creating a window and writting to it? I already checked the links, but I may have missed it.
This is a separate question. I started making this progrram in visual basic 5. It has 4 forms. 2 are what the user will work with and the other 2 were dialong boxes. My question is if I were to write this program in C++ and make each form a separate C++ file, do I have to include the windows header in all the C++ files, or just one? I plan to write the whole thing in 1 window since it's small anyway, but I was just wondering.
"A computer is this amazingly fast.....but stupid machine." - C++ for dummies
Jeez....read the links I gave earlier......if you arent prepared to read to get the info then dont bother going any further.......Originally posted by Cosmic Diva
OOOOOOOOOOOOOOOOOOOOOOOOOO!
I was thinking about it all wrong. Does anyone know where I can find more info about creating a window and writting to it? I already checked the links, but I may have missed it.
This is a separate question. I started making this progrram in visual basic 5. It has 4 forms. 2 are what the user will work with and the other 2 were dialong boxes. My question is if I were to write this program in C++ and make each form a separate C++ file, do I have to include the windows header in all the C++ files, or just one? I plan to write the whole thing in 1 window since it's small anyway, but I was just wondering.
I just asked a question. If you don't want to answer it, don't. I'm sorry if I haven't been programming as long as you Mr. smarty pants. Considering that I'm a beginner and don't know what I'm looking at it's easy for me to miss some coding.
"A computer is this amazingly fast.....but stupid machine." - C++ for dummies
So read the link until you understand......both of those links offer good starting info....I wouldnt have given them if I thought they wouldnt help a beginner......There is a lot of understanding needed to create and write to a window....you need to understand messages, GDI and loads of other stuff to work with windows, and the only way to get that is to sit back and read...........Originally posted by Cosmic Diva
I just asked a question. If you don't want to answer it, don't. I'm sorry if I haven't been programming as long as you Mr. smarty pants. Considering that I'm a beginner and don't know what I'm looking at it's easy for me to miss some coding.
Sorry, I didnt mean to snap......but you need to walk before running....
hehe she told youMr. smarty pants
I like her already....
My advice is limited, but I can tell you that these are the minimum requirements for a window.
1. an HWND variable (handle to your window)
2. an HINSTANCE variable (handle to the instance)
3. a WinMain function (api entry)
4. a WNDCLASS struct (filled with your windows properties)
5. a CreateWindow Function
6. a ShowWindow function
7. a GetMessage function
8. a TranslateMessage funtion
9. a DispatchMessage function
0. a CALLBACK function (to handle messages)
The Callback function is probably the most difficult concept to grasp. Basically, its a catch-all for the messages your window recieves from functions 7, 8, & 9 in a message loop .
These functions all take a pointer to a MSG structure.
The loop would look something like this:
Most confusing of all, the callback function is not declared in the main loop, instead it's declared as a long pointer to a function in your WNDCLASS struct like this:Code:MSG msg; while(GetMessage(&msg, NULL, 0, 0) { TranslateMessage(&msg); DispatchMessage(&msg) }
And here is the badboy function that does it all:Code:WNDCLASS WndClass; WndClass.lpfnWndClass = WndProc;
What makes it all so confusing? All the Types, Functions, and Stuctures have already been defined in the API. They are very complex and have been designed to be used in very specific ways. If you can understand this much then you are well on your way to programming Windows.Code:LRESULT CALLBACK WndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);
"The mind, like a parachute, only functions when open."
Hey Cosmic, I am pretty much a total beginner to Win32 too (as of this spring holiday). It took a while adjusting to the different concepts but sitting down and working through the Forgers tutorial (and several others) put me on the right track. You just have to sit through it for a several hours (or more) until you get the hang of it.
You can also download the documentation for most of the API functions etc. here:
CodingZone Win32 downloads
(you want the "Win API reference file", you may have to sign up as a member before you download).
Hope this helps
dt