To output "Hello, World!" at window

W

Wonyong

#include <stdio.h>
int main()
{
printf("Hello, World!\n");
system("Pause");
return 0;
}

I install Visual C++ 2010 Express, now.

And, I test above source.

So, I want to output "Hello, World!" at window (such as Notepad), not
commandline.

How to?

I am begginer. :)
 
B

BartC

Wonyong said:
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
system("Pause");
return 0;
}

I install Visual C++ 2010 Express, now.

And, I test above source.

So, I want to output "Hello, World!" at window (such as Notepad), not
commandline.

How to?

Try:

#include <windows.h>

int main(void){
MessageBox(0,"Hello World!","Caption",0);
}

But in general, graphical work using Windows, and C, is difficult, without
using extra layers of software (gui libraries and such). Even then, it's
still difficult!

Try googling "hello world windows" and similar phrases.

Or, your VC++ IDE might already have a project template for Windows
applications.
 
K

Keith Thompson

BartC said:
Try:

#include <windows.h>

int main(void){
MessageBox(0,"Hello World!","Caption",0);
}

But in general, graphical work using Windows, and C, is difficult, without
using extra layers of software (gui libraries and such). Even then, it's
still difficult!

Try googling "hello world windows" and similar phrases.

Or, your VC++ IDE might already have a project template for Windows
applications.

And if you want more information about this, try
comp.os.ms-windows.programmer.win32 or some other Windows-specific forum
(primarily because you're more likely to find people who can answer your
questions).
 
P

Paul N

#include <stdio.h>
int main()
{
 printf("Hello, World!\n");
 system("Pause");
 return 0;

}

I install Visual C++ 2010 Express, now.

And, I test above source.

So, I want to output "Hello, World!" at window (such as Notepad), not
commandline.

How to?

I am begginer. :)

As Keith has said, this is more to do with Windows than with the C
language, and so you are likely to get better answers in a Windows
newsgroup. I use comp.os.ms-windows.programmer.win32 as well, though
I'm not sure if it's the best one (there seems an awful lot of them).

But, to whet your appetite...

I think what you are asking is how to write a proper Windows program
rather than a console application. (I could be wrong here - I've never
written a console application myself.) Anyhow, to do this (at least in
Visual C++ 2005, I hope it's not too different now) do:

File > New > Project

Select "Win32" and "Win32 console application" and choose a suitable
name
Click OK, then Next
Select "Windows application" and click "Finish"

This will give you a sample application - it will put up a window, and
let you select File > Exit or Help > About.

To print "Hello world!", look through the code until you find a
function WndProc with the following in it:

case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;

and where the comment is, add:

TextOut(hdc, 10, 10, _TEXT("Hello world!"), 11);

(The 10s are the position, the 11 is the length of text to print.)

And you're done!

But writing a proper Windows program does need a lot of effort,
including in finding out how the program is supposed to work. I'd
recommend a good book, such as Programming Windows by Charles Petzold.

Hope this is useful.
Paul.
 
M

Malcolm McLean

But in general, graphical work using Windows, and C, is difficult, without
using extra layers of software (gui libraries and such). Even then, it's
still difficult!
It depends what you want to do.

Most of my Windows programs use a few trivial buttons or menus, easy
enough to knock up in C, and one or two big widows which I treat as
rasters for drawing graphics.

The advantage of C over many other languages is that you can usually
fill the window using looped setpixel() routines fast enough.
 
C

Chris H

In message <[email protected]
t.fi> said:
It's operating system dependent, and in C code alone is going to be difficult.


For a beginner I would suggest learn a script language that includes a window
component, such as Tcl/Tk, which I am familar with. There are others
around. (I
think Python, Ruby, and Perl are script languages with windows
support.)

And how will that will help him learn C?
 
K

Kenny McCormack

Chris H said:
And how will that will help him learn C?

According to the religion here, stuff having to do with windows and graphics
is not C. I guess that means that it is some other language. Because if it
isn't covered in the C standards documents, then it is not C.

Therefore, if one's interest is in windows or graphics, one is not learning
C anyway. So, your question is moot.

--
"The anti-regulation business ethos is based on the charmingly naive notion
that people will not do unspeakable things for money." - Dana Carpender

Quoted by Paul Ciszek (pciszek at panix dot com). But what I want to know
is why is this diet/low-carb food author doing making pithy political/economic
statements?

Nevertheless, the above quote is dead-on, because, the thing is - business
in one breath tells us they don't need to be regulated (which is to say:
that they can morally self-regulate), then in the next breath tells us that
corporations are amoral entities which have no obligations to anyone except
their officers and shareholders, then in the next breath they tell us they
don't need to be regulated (that they can morally self-regulate) ...
 
C

Chris H

Kenny McCormack said:
According to the religion here, stuff having to do with windows and graphics
is not C.

Not at all. You can do both in C. In fact I have a complete graphics
library written in C
I guess that means that it is some other language. Because if it
isn't covered in the C standards documents, then it is not C.

Then you are completely wrong.. Not only in fact but in concept.
Therefore, if one's interest is in windows or graphics, one is not learning
C anyway. So, your question is moot.

As I said you are completely wrong. Graphics can and is often done in
C.
 
S

Stefan Ram

Chris H said:
As I said you are completely wrong. Graphics can and is often done in
C.

#include <assert.h>
#include <ctype.h>
#include <stdio.h>

int main( void )
{ int c = 'A';
assert( isgraph( c ));
putchar( c ); }
 
K

Kenny McCormack

Not at all. You can do both in C. In fact I have a complete graphics
library written in C

Of course you can - in reality land. I obviously agree 100%.

But in clc-land (which is *not* reality land), you can't.

I'm really surprised I have to explain this to you.
Then you are completely wrong.. Not only in fact but in concept.
Nope.


As I said you are completely wrong. Graphics can and is often done in
C.

Nope. Not in "C" as defined by the solons of CLC.
 
C

Chris H

Kenny McCormack said:
Of course you can - in reality land. I obviously agree 100%.

But in clc-land (which is *not* reality land), you can't.

I'm really surprised I have to explain this to you.

I most humbly apologise. You are of course correct. :)))))

My problem is I live in reality and have to do engineering on a daily
basis.
 
C

Chris H

In message <[email protected]
t.fi> said:
And how will that will help him learn C?

By letting him do some applications by a beginner without throwing him into
extreme C coding.[/QUOTE]

C isn't extreme
Reduce the frustration of getting started by not having to
learn an entire graphics systems when you still don't know what -lm means.

By learning a load of other stuff he may never need again?
 
K

Keith Thompson

Chris H said:
In message <[email protected]


And how will that will help him learn C?

It won't, at least not directly. Do we know that that's his goal?
If is goal is to learn the most straightforward way to create
windows, then a scripting language may be the best choice. If,
on the other hand, his goal is to learn C, then he's certainly been
given enough advice here to start doing that.

One might argue that the fact that he posted here indicates that
he's interested in learning C, and one might very well be correct,
but perhaps he's assumed that C is the answer and is asking the
wrong question.
 
C

Chris H

Kenneth Brody said:
I'm not sure why I'm taking my time to respond, but...

Neither am I but keep digging.
You _can't_ do things like "windows" and "graphics" (as used in this
context) in "Standard C", which is what is discussed here.

Yes you can.
Sure, you can write platform-specific code using platform-specific
extensions, or call third-party libraries, but then you are no longer
dealing with the C language itself.

And if those 3rd party graphics libraries are written in standard C?
(Other than the drivers onto the hardware)

In fact, the mere use of such an extension/library doesn't make a
posting here off-topic.

Doesn't make it off topic at all. More to the point it is not up to you
to say what is or is not on/off topic.
 
M

Malcolm McLean

If is goal is to learn the most straightforward way to create
windows, then a scripting language may be the best choice.
Or maybe he has a complex program written with a C-callable interface,
and wants to hook it up to a simple GUI.

Learning the MS Windows C application interface is probably his best
bet.
 
S

Sjouke Burry

Kenneth Brody wrote:
cut
You _can't_ do things like "windows" and "graphics" (as used in this
context) in "Standard C", which is what is discussed here.

Hmm....

COMPUTER.LANGUAGE.C I dont see the "Standard C" anywhere in the name.

Only a number of goeroes trying to kill 95 % of the questions
people have, and using threads of 20+ to explain it to
ordinary programmers.
 
J

Joachim Schmitz

Sjouke said:
Kenneth Brody wrote:
cut

Hmm....

COMPUTER.LANGUAGE.C I dont see the "Standard C" anywhere in the
name.

I don't see 'non-standard' in the name either. So what is C? Obviously the
language described by K&R, later standardardized into the ANSI/ISO C89- and
the C99-standard.
Neither of which mentions graphics or windows.
There are, however, newsgroups with windows and graphics in their names...

Bye, Jojo
 
C

Chris H

Sjouke Burry said:
Kenneth Brody wrote:
cut

Hmm....

COMPUTER.LANGUAGE.C I dont see the "Standard C" anywhere in the name.

It isn't... There is a separate group for discussing the C language
standard.
Only a number of goeroes trying to kill 95 % of the questions
people have, and using threads of 20+ to explain it to
ordinary programmers.

Quite.

There are a small group who want to re-define very narrowly the remit of
the group. All it does is create a lot of fuss and the group looses
more participants.

I have stopped posting as much these days
 
C

Chris H

Joachim Schmitz said:
I don't see 'non-standard' in the name either.

Correct. It says nothing about standard or non standard C... just C

IF you want Standard C I assume you mean ISO9899:1999+TC's only.

Otherwise if it is any "standard" C including K&R then it includes any
defacto C such as Keil's C51 as used on 20 % of the MCU's in the world.
So what is C? Obviously the language described by K&R, later
standardardized into the ANSI/ISO C89- and the C99-standard.

NO. K&R was NEVER standard C. ANSI 89 was not either. That was a
local US standard.

ISO C 90 *WAS* a standard it is now obsolete and withdrawn (despite the
fact that most of the worlds compilers still use it)

the ONLY standards C is C99 (and that is hardly used)

As I said: if it is any "standard" C including K&R then it includes any
defacto C such as Keil's C51 as used on 20 % of the MCU's in the world.
Neither of which mentions graphics or windows.

Or hardware or IO or in fact anything much. It does not mention
Standard C which has it's own group.

Which makes any discussion of what is left pointless.
There are, however, newsgroups with windows and graphics in their names...

But not C....

Please take your problem to a physician and let the rest of us get on
with discussing the real world use of C
 
B

BartC

Malcolm McLean said:
It depends what you want to do.

Most of my Windows programs use a few trivial buttons or menus, easy
enough to knock up in C, and one or two big widows which I treat as
rasters for drawing graphics.

The advantage of C over many other languages is that you can usually
fill the window using looped setpixel() routines fast enough.

Using the old GDI API directly *is* difficult.

Example 1: try drawing a graphic element in a certain colour. You can't just
select an RGB colour as you might expect; you have to create and allocate a
special 'pen' object, apply a colour to it, attach it to a device context,
use it, then deattach it, and deallocate it when you don't need that colour
anymore! (Or something along those lines.)

Example 2: once you've managed to draw your graphics, and then the window is
obscured then uncovered, or minimised/restored, then your graphics will have
disappeared and have to be recreated! The original source data (random
numbers, arbitrary input from a stream, etc) no longer exists.

Your application has to written around always being able to *quickly*
recreate whatever is in any window. Which is a complete pain.

And that's true of pretty much everything in GDI. (And trying to use GDI+
from C is a magnitude or so worse, because it assumes C++)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top