忘记密码
 新成员注册
查看: 1399|回复: 2

[分享]几种高级语言下的"Hello World"程序

[复制链接]
我的人缘0
发起活动
0 次
参加活动
0 次
杨德坤 发表于 2007-5-6 23:44 | 显示全部楼层 |阅读模式

你还没有登录,登录后可以看到更多精彩内容

您需要 登录 才可以下载或查看,没有账号?新成员注册

×
c语言win32控制台下的"hello world":

#include <stdio.h>

int main()
{
      printf("hello world&nbsp;");
      return 0;
}
_______________________________________________

c++语言win32控制台下的"hello world":

#include <iostream>

int main()
{
      cout << "hello world&nbsp;" << endl;
      return 0;
}
_______________________________________________

vc++语言win32控制台下的"hello world":

#include "stdafx.h"

#using <mscorlib.dll>

using namespace system;

int _tmain()
{
      console::writeline( s"hello world&nbsp;" );
      return 0;
}
_______________________________________________

c#语言win32控制台下的"hello world":

using system;

namespace hello_world
{
      class class1
      {
            [stathread]
            static void main(string[] args)
            {
                  console.writeline("hello world&nbsp;");
            }
       }
}
_______________________________________________

java语言win32控制台下的"hello world":

public class hello_world
{
      public static void main(string[] args)
      {
            system.out.print("hello world&nbsp;");
      }
}
_______________________________________________

最后来个刺激点的,win32环境下的"hello world"(c+win32api):

#include <windows.h>

lresult callback wndproc (hwnd, uint, wparam, lparam) ;

int winapi winmain (hinstance hinstance,
                                 hinstance hprevinstance,
                                 pstr szcmdline,
                                 int icmdshow)
{
     static tchar szappname[] = text ("Hello World&nbsp;") ;
     hwnd             hwnd ;
     msg                msg ;
     wndclass     wndclass ;

     wndclass.style         = cs_hredraw | cs_vredraw ;
     wndclass.lpfnwndproc   = wndproc ;
     wndclass.cbcl***tra    = 0 ;
     wndclass.cbwndextra    = 0 ;
     wndclass.hinstance     = hinstance ;
     wndclass.hicon         = loadicon (null, idi_application) ;
     wndclass.hcursor       = loadcursor (null, idc_arrow) ;
     wndclass.hbrbackground = (hbrush) getstockobject (white_brush) ;
     wndclass.lpszmenuname  = null ;
     wndclass.lpszclassname = szappname ;

     if (&nbsp;registerclass (&wndclass))
     {
          messagebox (null, text ("this program requires windows nt&nbsp;"),
                      szappname, mb_iconerror) ;
          return 0 ;
     }
     
     hwnd = createwindow (szappname,                  // window class name
                          text ("the hello program"), // window caption
                          ws_overlappedwindow,        // window style
                          cw_usedefault,              // initial x position
                          cw_usedefault,              // initial y position
                          cw_usedefault,              // initial x size
                          cw_usedefault,              // initial y size
                          null,                       // parent window handle
                          null,                       // window menu handle
                          hinstance,                  // program instance handle
                          null) ;                     // creation parameters
     
     showwindow (hwnd, icmdshow) ;
     updatewindow (hwnd) ;
     
     while (getmessage (&msg, null, 0, 0))
     {
          translatemessage (&msg) ;
          dispatchmessage (&msg) ;
     }
     return msg.wparam ;
}

lresult callback wndproc (hwnd hwnd,
                                                uint message,
                                                wparam wparam,
                                                lparam lparam)
{
     hdc         hdc ;
     paintstruct ps ;
     rect        rect ;
     
     switch (message)
     {
     case wm_create:
          playsound (text ("hellowin.wav"), null, snd_filename | snd_async) ;
          return 0 ;
         
     case wm_paint:
          hdc = beginpaint (hwnd, &ps) ;
         
          getclientrect (hwnd, &rect) ;
         
          drawtext (hdc, text ("Hello World&nbsp;&nbsp;"), -1, &rect,
                    dt_singleline | dt_center | dt_vcenter) ;
         
          endpaint (hwnd, &ps) ;
          return 0 ;
         
     case wm_destroy:
          postquitmessage (0) ;
          return 0 ;
     }
     return defwindowproc (hwnd, message, wparam, lparam) ;
}
注:由于本程序有些代码应涉及论坛禁止显示的内容被屏蔽掉了,故附上源文件以共分享
_______________________________________________









本贴已被 作者 于 2007年05月18日 16时40分44秒 编辑过
踩过的脚印
充实自我,展现自我!没有完美的个人,只有优秀的团队!计协我的家,建设靠大家!只有真正的融入了,你才会体会快乐哦~
我的人缘1
发起活动
0 次
参加活动
0 次
方文裕 发表于 2019-11-27 12:51 | 显示全部楼层
学长是工程师??
充实自我,展现自我!没有完美的个人,只有优秀的团队!计协我的家,建设靠大家!只有真正的融入了,你才会体会快乐哦~
我的人缘0
发起活动
0 次
参加活动
0 次
施沛新 发表于 2019-12-28 06:50 | 显示全部楼层
感觉什么也不懂                                                
充实自我,展现自我!没有完美的个人,只有优秀的团队!计协我的家,建设靠大家!只有真正的融入了,你才会体会快乐哦~
您需要登录后才可以回帖 登录 | 新成员注册

本版积分规则

QQ|手机版|CA之家 ( 桂ICP备07006672号-6 )

GMT+8, 2025-9-16 05:56

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表