[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

To output "Hello, World!" at window

Wonyong

4/13/2011 3:57:00 PM

#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. :)
53 Answers

China Blue Veins

4/13/2011 4:33:00 PM

0

In article <41eb260e-8d79-4034-920e-40bd21559230@q40g2000prh.googlegroups.com>,
Wonyong <ds1sku@gmail.com> wrote:

> #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.

It's operating system dependent, and in C code alone is going to be difficult.

> How to?
>
> I am begginer. :)

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.) In any
case you will need to learn a scripting language in addition to C, but they can
be simpler than C.

For Tcl/Tk, you can start Wish and get a main window and Console where you can
type Tcl commands.

text .t
pack .t
.t insert 1.0 [exec ls]

The "exec ..." executes a command and returns it stdout. In this way you can use
the scripting language to maintain the windows, and also exec your C programs.

This allows you to use a simpler, mostly platform independent scripts together
with standard C program. As you learn more and become more comfortable, you can
delve into your operating system.

--
Damn the living - It's a lovely life. I'm whoever you want me to be.
Silver silverware - Where is the love? At least I can stay in character.
Oval swimming pool - Where is the love? Annoying Usenet one post at a time.
Damn the living - It's a lovely life. I am in the Nile.

Bartc

4/13/2011 5:09:00 PM

0

"Wonyong" <ds1sku@gmail.com> wrote in message
news:41eb260e-8d79-4034-920e-40bd21559230@q40g2000prh.googlegroups.com...
> #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.

--
Bartc



Keith Thompson

4/13/2011 7:33:00 PM

0

"BartC" <bc@freeuk.com> writes:
> "Wonyong" <ds1sku@gmail.com> wrote in message
> news:41eb260e-8d79-4034-920e-40bd21559230@q40g2000prh.googlegroups.com...
>> #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.

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).

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.ne...
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

gw7rib

4/13/2011 9:26:00 PM

0

On Apr 13, 4:56 pm, Wonyong <ds1...@gmail.com> wrote:
> #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.


Malcolm McLean

4/14/2011 10:18:00 AM

0

On Apr 13, 8:09 pm, "BartC" <b...@freeuk.com> wrote:
>
> 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.

Chris H

4/14/2011 11:05:00 AM

0

In message <chine.bleu-DEC8AC.09331113042011@62-183-169-81.bb.dnainterne
t.fi>, China Blue Nile <chine.bleu@yahoo.com> writes
>In article <41eb260e-8d79-4034-920e-40bd21559230@q40g2000prh.googlegroups.com>,
> Wonyong <ds1sku@gmail.com> wrote:
>
>> #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.
>
>It's operating system dependent, and in C code alone is going to be difficult.
>
>> How to?
>>
>> I am begginer. :)
>
>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?



--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



gazelle

4/14/2011 11:41:00 AM

0

In article <mPwnbxBxTtpNFADY@phaedsys.demon.co.uk>,
Chris H <chris@phaedsys.org> wrote:
....
>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) ...

Chris H

4/14/2011 1:07:00 PM

0

In message <io6mfg$9j2$3@news.xmission.com>, Kenny McCormack
<gazelle@shell.xmission.com> writes
>In article <mPwnbxBxTtpNFADY@phaedsys.demon.co.uk>,
>Chris H <chris@phaedsys.org> wrote:
>...
>>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.

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.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



ram

4/14/2011 1:16:00 PM

0

Chris H <chris@phaedsys.org> writes:
>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 ); }

gazelle

4/14/2011 1:32:00 PM

0

In article <c9TJnBD+FvpNFAm4@phaedsys.demon.co.uk>,
Chris H <chris@phaedsys.org> wrote:
>In message <io6mfg$9j2$3@news.xmission.com>, Kenny McCormack
><gazelle@shell.xmission.com> writes
>>In article <mPwnbxBxTtpNFADY@phaedsys.demon.co.uk>,
>>Chris H <chris@phaedsys.org> wrote:
>>...
>>>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.
>
>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.

>>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.

Nope.

>>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.

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

--
They say compassion is a virtue, but I don't have the time!

- David Byrne -