/******************************************************************************* Tiedosto: wintext.c Tekijä: Mika Haasianlahti Tehty: 28.10.2001 Tarkoitus: Yksinkertainen Windows-ohjelma, joka tulostaa näytölle muutaman rivi tekstiä. Demotehtävä numero 5. *******************************************************************************/ #include #include LONG CALLBACK _export MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; char *sanat[] = { "Ensimmäinen rivi tekstiä" , "Toinen rivi tekstiä", "Kolmas rivi tekstiä", NULL }; switch( message ) { case WM_PAINT: if ( BeginPaint(hWnd, &ps) ) { // otetaan oikeasti dy GetTextExtent(ps.hdc,"M"); int i, y = 10, dy = 20; for (i=0; sanat[i]; i++) { TextOut(ps.hdc,10,y,sanat[i],strlen(sanat[i])); y += dy; } EndPaint(hWnd, &ps); } return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: break; } return DefWindowProc(hWnd, message, wParam, lParam); } #pragma argused WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASS wc; // Ikkunaluokka. HWND hWnd; // Pääikkunan kahva. MSG msg; // Viesti. if ( !hPrevInstance ) // Onko muita esiintymiä käynnissä? { wc.style = 0; wc.lpfnWndProc = MainWndProc; wc.cbClsExtra = 0; 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 = "WTextClass"; if ( !RegisterClass(&wc) ) return 1; } hWnd = CreateWindow("WTextClass","Some Text",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL, hInstance,NULL); if ( !hWnd ) return 1; ShowWindow(hWnd,nCmdShow); UpdateWindow(hWnd); while( GetMessage(&msg,NULL,0,0) ) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } //---------------------------------------------------------------------------