Servus-Woid-Programm
Erscheinungsbild
S' "Servus Woid"-Programm is a Tradition in da Litaratur iaba Programmiersprachn. Do hoasts in deitsche Biacha "Hallo-Welt-Programm" und in de englischn "Hello-World-Program". S' is a oanfachs Programm, des den Text "Servus Woid" aufn Buidschirm schreibt. Ma ko damit zoang, was ma auf jedn Foi in da jeweilign Sproch bracht um iabahaupt a lauffähigs Programm zum schreim. Normalaweis stehts in am jedn Lehrbuach iabas Programmiern glei ganz am Ofang. S'werd a gern heagnumma um zum iabapriafn ob a Compiler oda Interpreter iabahaupt richtig funktioniert. De Tradition gehd aufn Kernighan Brian zruck, der's 1974 in am internen Handbuach iaba C bei Bell Laboratories gschribn hod.
Beispui
10 PRINT "Servus Woid!"
#include <stdio.h>
int main(void)
{
printf("Servus Woid!\n");
return 0;
}
=== [[Object Pascal]] (Delphi) ===
<source lang="delphi">
program ServusWoid;
{$APPTYPE CONSOLE}
begin
writeln('Servus Woid!');
end.
Windows API (in C)
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(0, "Servus Woid!", "Mei ersts Programm", MB_OK);
return 0;
}
Oder mit am eignem Fensta
#include <windows.h>
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
char szClassName[] = "MainWnd";
HINSTANCE hInstance;
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wincl;
hInstance = hInst;
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.style = 0;
wincl.hInstance = hInstance;
wincl.lpszClassName = szClassName;
wincl.lpszMenuName = NULL; //No menu
wincl.lpfnWndProc = WindowProcedure;
wincl.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); //Color of the window
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION); //EXE icon
wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION); //Small program icon
wincl.hCursor = LoadCursor(NULL, IDC_ARROW); //Cursor
if (!RegisterClassEx(&wincl))
return 0;
hwnd = CreateWindowEx(0, //No extended window styles
szClassName, //Class name
"", //Window caption
WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, //Let Windows decide the left and top positions of the window
120, 50, //Width and height of the window,
NULL, NULL, hInstance, NULL);
//Make the window visible on the screen
ShowWindow(hwnd, nCmdShow);
//Run the message loop
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
TextOut(hdc, 15, 3, "Servus Woid!", 13);
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}