• Advertisement

Archived

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

windows program

This topic is 5069 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just tried to write a simple "Hello Windows" program and am having a lot of problems. I have my WinMain() with a message loop; functions to register, create, update and show windows; I have a (blank) resource.h included with the main cpp file. Am I missing a vital component here? Do I need to include stdafx.h and/or any others? And if I do include stdafx.h, is this where I am supposed to include all other header files that the program uses?

Share this post


Link to post
Share on other sites
Advertisement
It''s hard to give any advice when all you say is that you''re "having a lot of problems". Exactly what kind of problems are you having?

Oh, and stdafx.h isn''t required in any project, though it does speed compile times if you use it right. If you generated the project by hand, leave it out for now. If the IDE spat one out for you, leave it in for now.

Share this post


Link to post
Share on other sites
Here''s a quick hello world example, you just need to set up a Win32 project, create a cpp file and paste the following code...


//------------------------------------------------------------------------

// A Windows Application

//

//------------------------------------------------------------------------


#include <windows.h>

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
HDC hdc;
PAINTSTRUCT ps;

case WM_DESTROY:
PostQuitMessage(0);
return 0;

case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
return 0;
}

return DefWindowProc(hwnd, msg, wparam, lparam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, char*, int)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(0, IDI_APPLICATION);
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = "HelloWin";
wc.hIconSm = LoadIcon(0, IDI_APPLICATION);

RegisterClassEx(&wc);

HWND hwnd;
hwnd= CreateWindowEx( 0, "HelloWin", "Hello World", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, 0, 0, hInstance, 0);

ShowWindow(hwnd, SW_SHOWDEFAULT);
UpdateWindow(hwnd);

MSG msg;
while(true)
{
if(GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

if(msg.message == WM_QUIT)
break;

HDC hdc = GetDC(hwnd);

SetTextColor(hdc, RGB(0, 255, 0));
SetBkMode(hdc, TRANSPARENT);
TextOut(hdc, 0, 0, "Hello, world!", strlen("Hello, world!"));

ReleaseDC(hwnd, hdc);
}

return 0;
}

Share this post


Link to post
Share on other sites
quote:
Original post by simon10k
Here''s a quick hello world example, you just need to set up a Win32 project, create a cpp file and paste the following code...
...code...

I think normally you would want to put the drawing functions (SetTextColor(), SetBkMode(), TextOut()) under the WM_PAINT scope, and use the hdc returned by BeginPaint() instead.

Share this post


Link to post
Share on other sites
I could of, but I don''t think in terms of events. I am more of a procedural type of person.

Share this post


Link to post
Share on other sites
Would you like that? No, then it''s mean. And I''m pretty sure he knows that.

GameDev''s supposed to be a kind and helpfull community, if someone in this rooms thinks otherwise then let him speak today!! Or forever think in silence..

Or whatever..

--
You''re Welcome,
Rick Wong

- sitting in his chair doing the most time-consuming thing..

Share this post


Link to post
Share on other sites
quote:
Original post by Pipo DeClown
Would you like that? No, then it''s mean. And I''m pretty sure he knows that.

GameDev''s supposed to be a kind and helpfull community, if someone in this rooms thinks otherwise then let him speak today!! Or forever think in silence..
Rubbish.

Is blatantly giving bad adviced, based on ignorance and bad practice (ignoring the Windows event model and performing painting, etc every cycle even if it''s not necessary) "kind" or "helpful"? Don''t get touchy-feely; revere fact over feeling and truth over "everybody getting along."

I''m brutal in the For Beginners forum because experience has shown that a lot of unskilled/ignorant people will come in here to answer questions and thus feel more "competent." It''s an ego thing. I don''t like answering beginner questions, but I hate having to re-teach so-called "intermediates" their fundamentals.

Capice?

Share this post


Link to post
Share on other sites
This might sound dumb and stupid, and it is. It is also the truth: "U where an n00b 2."

IMO, the only reason you can act bitchy against n00bs is when they ask you to help them in private. That's when it is annoying.
WHY THE HELL would he be posting in the 'For Beginners' forum?

-
quote:
unskilled/ignorant people will come in here to answer questions and thus feel more "competent." It's an ego thing.

-
quote:
In short, a terrible Windows programmer.


Being nice is hard, but being brutal is bad.

quote:
From Nehe Welcome to my OpenGL tutorials. I am an average guy with a passion for OpenGL! The first time I heard about OpenGL was back when 3Dfx released their Hardware accelerated OpenGL driver for the Voodoo 1 card. Immediately I knew OpenGL was something I had to learn. Unfortunately, it was very hard to find any information about OpenGL in books or on the net. I spent hours trying to make code work and even more time begging people for help in email and on IRC. I found that those people that understood OpenGL considered themselves elite, and had no interest in sharing their knowledge. VERY frustrating!




--
You're Welcome,
Rick Wong

- sitting in his chair doing the most time-consuming thing..

[edited by - Pipo DeClown on April 10, 2004 3:45:00 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Pipo DeClown
This might sound dumb and stupid, and it is. It is also the truth: "U where an n00b 2."
Yes, I was a beginner once. Would you like me to enumerate the difference? Do I have to rehash the reasons why I have no compunctions about pointing such things out? Do I need to reiterate that the fact that we all started somewhere is no excuse for blatant misinformation and a disregard for correction?

Stop crusading. It''s irritating (because, in this case, you have no point). simon10k was told that his example was flawed; rather than seizing the opportunity to improve, he rationalizes his approach. And that''s the guy - the "n00b" - you''re defending?

Further, if you have a problem with me, email me about it. Taking it to the forums doesn''t help and only serves to derail the thread.

quote:
quote:
I don''t like answering beginner questions..
Then don''t!
Did you not read the reason why I do it? Is it so foreign to you that I might be doing it not out of a generous heart but out of purely selfish motivation? I''d rather not have to reiterate foundational issues in advanced discourse, and since I have a vested interest in this site, I''ll make the investment - the sacrifice - to dispense accurate information here.

Are you saying I should let bullshit get passed around just so nobody''s feelings get hurt?

Get over it.

Share this post


Link to post
Share on other sites
Oluseyi, I''m more skilled then you could ever dream to be (and not just as programming). Get real, not everyone sees the world through your eyes.

My example is not flawed, it illustrates the fact that you don''t need to use the event model, this is a games forum and most games are not event based, depending on Windows to notify you of what''s happening is a petty approach and encouraging event based examples doesn''t help you when you’re using real-time style coding.

I''m not posting in these forums anymore; I don''t need to be criticized for helping. Oluseyi your not “mean” you’re just a whining bitch. I don''t have a problem with you, I''m just observant.

*out*

Share this post


Link to post
Share on other sites
quote:
Original post by simon10k
My example is not flawed, it illustrates the fact that you don''t need to use the event model
But you should, if you are not programming games in Windows. If you do not want to use WM_PAINT at all, you should have removed it from code because that does nothing.

Share this post


Link to post
Share on other sites
quote:
Original post by Pipo DeClown
This might sound dumb and stupid, and it is. It is also the truth: "U where an n00b 2."



Nope. You'll never be able to prove I was ever a n00b. ever.

The only argument you have is that I'm knowledgable NOW, so at some point I must not have been. Which makes sense, but you'd still never be able to prove it.

You know why? because when I was a n00b (oh crap, I admitted it!) I never asked questions. EVER. (and I'm sure some dill-hole will go find the search button and spend half an hour trying to find a n00by question i've asked...)

[edited by - C-Junkie on April 10, 2004 9:08:39 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by simon10k
<Stupid invective>
Don''t take it personally. I''m not assaulting your character or anything; it''s a statement of fact based on your comments. Want me to think more highly of you? Post correct information.

I don''t give a fuck if you don''t post here, btw. Martyrs don''t impress me. If that disappoints you, feel free to whine to Dave.

Share this post


Link to post
Share on other sites

  • Advertisement