Archived

This topic is now archived and is closed to further replies.

kirby92

I HATE WINDOWS PROGRAMMING!!!

Recommended Posts

Every time i look at a tutorial or something on the net for the win32 api i get confused. i can''t understand anything. nothing makes sense. please help if you can. I''m programming in c++, that might make a difference.

Share this post


Link to post
Share on other sites
I know what you''re talking about I used to think i would never get it, but then one day it clicked, i don''t know why but it did. i may one day write tutorials with many many comments that explain what everything is doing and why but i don''t have time right now, sorry i can''t help now, don''t know of any tutorials that explain stuff really well at the moment.

Share this post


Link to post
Share on other sites
Sadly, you won't find anything on the Internet that'll be much help. When I first started learning Windows programming I looked and was equally disappointed. I ended up figuring it out, but it took quite some time.

The best advice I can give you is to take a trip down to your local Barnes & Noble and take a look at the book Programming Windows, The Definitive Guide to the Win32 API by Charles Petzold. It's the best Win32 API book I've ever come across, and covers everything from the basics to just about anything you might want to do in Windows. If you have the funds, you can also find it on this page at Amazon.


Edited by - merlin9x9 on July 27, 2001 10:36:05 PM

Share this post


Link to post
Share on other sites
Even though you guys couldn''t directly help, I know you''re busy, I really appreciate the suggestion. I''ll have to take a look at that book even though I don''t have the money as of yet.
Thanks

Share this post


Link to post
Share on other sites
hey,

if you want to learn the basics of creating a window in Windows, then check out one of the first tutorials on NeHe''s site. That is what i looked at first, before i got a windows programming book. i think he does a good job at explaining what everything does. but to get deeper into windows programming you will probably want to pick up a book.

later,

DarkMonkey

Share this post


Link to post
Share on other sites
It''s actually pretty simple once you get used to it. I suggest just copying the code for a basic window, and messing around with stuff. The window initialization code will always be pretty much the same (and games tend not to use more complex GUI functions.) The hungarian notation is a bitch, and it seems like it takes tons of code to just get a simple window running, but the simpliest windows program is pretty small. Here''s the smallest windows program I could write that will run (and display a real window, not a messagebox.):

#include

//Window Procedure function, windows uses an event messaging system, this is used to process events (in this case quiting)
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
case WM_CLOSE:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd,msg,wparam,lparam);
}

//The main of a Win32 app
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevInst, LPSTR CmdLine, int nShowCmd)
{
HWND hwnd;
MSG msg;

WNDCLASS simpleclass;

//This structure is used to describe the properties of the window, most of the fields are pretty self explainatory

simpleclass.cbClsExtra = 0;
simpleclass.cbWndExtra = 0;
simpleclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
simpleclass.hCursor = LoadCursor(NULL,IDC_ARROW);
simpleclass.hIcon= LoadIcon(NULL,IDI_APPLICATION);
simpleclass.hInstance = hinstance;
simpleclass.lpfnWndProc = (WNDPROC)WndProc;
simpleclass.lpszClassName = "simpleclass";
simpleclass.lpszMenuName = NULL;
simpleclass.style = CS_HREDRAW | CS_VREDRAW;



RegisterClass(&simpleclass);

//The numbers are x,y, width height

hwnd = CreateWindow("simpleclass","Simple Win32 example", WS_OVERLAPPEDWINDOW,10,10,100,100,NULL,NULL,hinstance,NULL);

ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);

//handles any messages the window may receive

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}


I wrote that "off the top of my head", btw (with the help of VC''s tooltips to give me the correct function parameters and structure fields.)

It doesn''t really do anything (just creates a window) but it''s something to start with (and only 44 lines without comments!)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I highly recommend Tricks of the Windows Game Programming Gurus by Andre LaMothe. Pick it up, worth every penny.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
this is pitiful. for fucks sake, th compiler comes w/ sample applications you know?!? I went from VB->VC w/o any complaint. I don''t see how going from C/C++->VCcould be aas difficult....goddamn

Share this post


Link to post
Share on other sites
Anonymous, directly above me, you are full of shit.

Kirby: People have already suggested books and web sites that will help. I'm just going to remind you to *not give up*. This stuff is hard for everyone when they first start out, especially moving from DOS or something equivalent.

You'll get it, it'll just take some time. Just like pointers

Good luck!

Edited by - Qoy on July 28, 2001 4:42:42 AM

Share this post


Link to post
Share on other sites
You might also want to try the Game Programming Genesis by Joseph Farrell right here at GameDev.

Just go to Articles & Resources section and you can find it on Programming\Game Programming.

The first few articles are oriented to guide you throw GDI and DirectDraw. I''ve learned a lot from them.

Hope it helps you.

Share this post


Link to post
Share on other sites
Windows Game programming for dummmies...read it 6 chapters dedicated to windows programming (and the rest to directx and game programming). It will teach you all you need to know. At least the basics anyway....

Share this post


Link to post
Share on other sites
If you just want to get the basics, then go with the game programming books and tutorials mentioned above. If you want more than that, get Programming Windows, 5th edition, by Charles Petzold. It is the book when it comes to windows programming, and anybody that knows anything about windows programming will tell you so. It covers almost everything you''ll ever need to do with Win32, the books over 1400 pages, also comes in E-book form on the included cd-rom, that has all the sample apps. Anyways, that''s my suggestion.



"We are the music makers, and we are the dreamers of the dreams."
- Willy Wonka

Share this post


Link to post
Share on other sites
Windows programing is confusing at the beginning.. learn how windows messageing works and why.. that is the best place to start!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I have the Charles Petzold''s e-book should I upload it for you?

Share this post


Link to post
Share on other sites
Windows 98 Programming From the Ground Up is the easiest book to read IMO. I picked it up and instantly learned. Very quickly too. It will tell you EVERYTHING you need and dont need to know about programming in windows 98. There is also one for Windows Me....or 2000. But if you already know how to program in any version of windows there will only be very miniscule difference between them.

Explaining the setup of a normal window(using the code previosly posted:

-First you need to set up a window(for the program to look like something or course!) You do that by declaring an instance of a window class which is the WNDCLASSEX.
-You define some of the properties of the window.(a book should say what the properties do)
-You register that window with the operating system(basically its like making sure its going to be a valid window to show)
-Then you actually create a physical window to be shown by calling a CreateWindow or CreateWindowEx function and storing it to a handle for a window - thats what the HWND is. It literally a handle to a window so Windows can grab it and use it(well not literally). In that function call you define how the window will be shown and other properties.

Then you need to actually show the window by calling ShowWindow, and for reasons that I dont really know yet you call UpdateWindow right after you show it.

Then after that you need to establish a message loop. A message loop basically is a loop that will allow you program to pick up any input and process it within the program or decide to let it go and windows will handle it - i.e. Windows handles its own CTRL+ALT+DEL presses. One thing you need to know is that your program will receive input before windows does. I guess most people think windows gets a message and decides that its for your program - not exactly true. Let me write a commented loop out so it will be easier to understand:

while(GetMessage(&msg, NULL, 0, 0) ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}

The first parameter in get message is the structure for whatever input came in, the data for it will be stored here. At the time I forget what all the other paramters do. GetMessage also has a return type of BOOL. If a quit message(WM_QUIT) is received GetMessage returns false and that loop will exit. Inside the loop there are two function calls. TranslateMessage is for the virtual keys. Like F1, F2, F3, F4, escape, alt, control, and shift and other keys that dont have an ASCII code. If you dont know what ASCII code is then you probably dont know enought C++ to be starting windows programming - though just because you know it doesn''t mean you are ready either... DispatchMessage tells window to call your Window Function or your Window Procedure function. In that function your program should: one, handle what it needs to get from the user and process it; two, decide if messages shouldn''t be dealth with and let windows do something about it; and three, if a quit message comes in the program should exit.

Thats all I can share for now, I hope what I said if of some help.

Hint: Try not to let all the code overwhelm you if it looks cryptic.

P.S. Also you may need more C++ experience in general before you program in windows. I think you should know:
-Pointer and how they work
-Classes and structs
-All the basics relating to conditionals and loops
-Been programming in C++ for at least 3 months understanding all of it of course. If you still need to use a book to type programs often then you need more practice.

"Ogun''s Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
all you have to do is look at the MSDN samples - namely to get started, look at the GENERIC sample. that should get you started...

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
this is pitiful. for fucks sake, th compiler comes w/ sample applications you know?!? I went from VB->VC w/o any complaint. I don''t see how going from C/C++->VCcould be aas difficult....goddamn


Very intelligent and helpfull!
Do you think, that you''re in the right place. I thought, that this is a place you can easily find some help and not stupid answers like this one...

Share this post


Link to post
Share on other sites
I agree alfthegeek, it''s inane comments like this that make me wonder how this guy can even turn a computer on. And as my old mum says - if you can''t post something nice, don''t post anything at all (poetic license taken here). Also I totally agree with kirby92, windows programming is generally a pain in the arse - but until big bill dies we''re going to have to do it. Does anyone know of APIs out there that wrap up the WIN32 API (and I mean better than the shite that MFC is).
Also, remember that we can make things better - windows isn''t always best all the time, linux can be used to make good cross platform apps. Also I think SDL is pretty good too. If you want to learn the WIN32 API for games only, then learn a wrapper API (ie SDL, Glut) so that your games will be cross-platform & run on linux.

Just my thoughts
Brad

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I agree. Windows is an enormous pain in the ass. It just doesn''t make sense to anyone who''s big into OOP, since it was originally written to be compatible with C programmers I think... As soon as I got the thing working, I immediately set to wrapping it up so I didn''t have to deal with as much of the details as possible. The message callback system makes wrapping an even bigger pain in the ass though.

MFC is widely regarded to be crap, though i''ve never used it myself. I''ve heard good things about the WTL - the Windows Template Library. It''s basicly a win32 wrapper that just uses standard win32 calls. No MFC. Microsoft doesn''t support it anymore, prefferring to pimp MFC in it''s place. It''s still downloadable from somewhere, but I dunno where. Search for it.

Share this post


Link to post
Share on other sites
mm .. a few years ago i said that .. and now suddenly i want to program again ..

there are very good windows tutorials out there .. i went through 2 of them and they taught me a lot and i was able to understand what they were all about .. not bad for trying to get back into programming after years ..

i''m with a lot of prehatewindows programmers, its easier than you think after you''ve gotten past the first step ..

i haven''t coded anything fantastic yet .. but after having my skills and confidence shot, and later regaining them week by week, i know i could get into hectic programming again .. when .. i get a 3d card *lololololo* ..

when i find out which sites i went to, i''ll try and remember to edit this post and put the links in ..

Share this post


Link to post
Share on other sites