/***************************************************************************** PROGRAM: Mhello.c PURPOSE: "Pienin Windows-ohjelma". Tulostaa näyttöön tekstin Hello World Editor: ??? typistänyt malliohjelmista. Project: mhello.c, mhello.def *****************************************************************************/ #include /* Tarvitaan kaikissa Windows C-ohjelmissa */ void tulosta(HDC hdc, const char *s, int x, int y) { static int oldx=0,oldy=0; // Pitäsi olla ikkunakohtaisia SIZE d; if ( x < 0 ) x = oldx; if ( y < 0 ) y = oldy; TextOut(hdc,x,y,s,strlen(s)); oldx = x; GetTextExtentPoint(hdc,"M",1,&d); oldy = y + (int)(d.cy*1.1); } LONG CALLBACK _export MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; switch (message) { case WM_PAINT: /* Viesti: Piirrä ikkuna uudelleen */ if ( BeginPaint(hWnd,&ps) ) { tulosta(ps.hdc,"Hello World!", 10, 10); tulosta(ps.hdc,"Anu Saukko" , -1, -1); tulosta(ps.hdc,"Jyväskylä" , -1, -1); tulosta(ps.hdc,"JEE JEE, JOO JOO", -1, -1); tulosta(ps.hdc, "TESTING..., JOO JOO", 200, 200); } EndPaint(hWnd,&ps); return 0; case WM_DESTROY: /* Viesti: ikkuna hävitetään */ PostQuitMessage(0); return 0; default: /* Antaa Windowsin käsitellä muut */ break; } return DefWindowProc(hWnd, message, wParam, lParam); } int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASS wc; /* Ikkunaluokka */ HWND hWnd; /* Pääikkunan kahva */ MSG msg; /* Viesti */ (void)lpCmdLine; /* Hämäystä, jottei valitusta param. käytt. */ if (!hPrevInstance) { /* Onko muita esiintymiä käynnisssä? */ wc.style = 0 ; wc.lpfnWndProc = MainWndProc; wc.cbClsExtra = 1; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "WHelloWClass"; if (!RegisterClass(&wc)) return 1; } hWnd = CreateWindow("WHelloWClass","Windows Hello",WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, NULL,NULL,hInstance,NULL); if ( !hWnd ) return 1; ShowWindow(hWnd, nCmdShow); /* Näytetään ikkuna */ UpdateWindow(hWnd); /* Lähetetään WM_PAINT viesti */ while (GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); /* Tulkitaan virtuaaliset näp. koodit */ DispatchMessage(&msg); /* Lähetetään viesti ikkunalle */ } return msg.wParam; /* Palautetaan PostQuitMessage-funktion arvo */ }