Start med at downloade og instalere Dev-Cpp (inklusive kompiler) fra:
http://www.bloodshed.net/devcpp.html(Jeg bruger version 4.xx)
Så kører du programmet (devcpp.exe) og vælger "New Source File".
Så sletter du den kode den laver og indsætter denne:
#include <windows.h>
#include <scrnsave.h>
BITMAPINFOHEADER CreateHeader(int aWidth, int aHeight, WORD aBitPixel)
{
BITMAPINFOHEADER BitmapInfoHeader;
BitmapInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
BitmapInfoHeader.biWidth = aWidth;
BitmapInfoHeader.biHeight = aHeight;
BitmapInfoHeader.biPlanes = 1;
BitmapInfoHeader.biBitCount = aBitPixel;
BitmapInfoHeader.biCompression = BI_RGB;
BitmapInfoHeader.biSizeImage = 0;
BitmapInfoHeader.biXPelsPerMeter = 0;
BitmapInfoHeader.biYPelsPerMeter = 0;
BitmapInfoHeader.biClrUsed = 0;
BitmapInfoHeader.biClrImportant = 0;
return BitmapInfoHeader;
}
BITMAPINFOHEADER Header;
char *Buffer;
int Width, Height, BytesPixel;
unsigned int Idx;
void Draw(HDC dc)
{
StretchDIBits(dc,
0, Idx, Width, Height - Idx, // Dest
0, Idx, Width, Height - Idx, // Src
Buffer,
(LPBITMAPINFO)&Header, DIB_RGB_COLORS, SRCCOPY);
StretchDIBits(dc,
0, 0, Width, Idx, // Dest
0, 0, Width, Idx, // Src
Buffer,
(LPBITMAPINFO)&Header, DIB_RGB_COLORS, SRCCOPY);
}
LRESULT WINAPI ScreenSaverProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_CREATE:
{
HDC dc = GetDC(0);
Width = GetDeviceCaps(dc, HORZRES);
Height = GetDeviceCaps(dc, VERTRES);
HDC MemDc = CreateCompatibleDC(dc);
HBITMAP BitMap = CreateCompatibleBitmap(dc, Width, Height);
SelectObject(MemDc, BitMap);
BitBlt(MemDc, 0, 0, Width, Height, dc, 0, 0, SRCCOPY);
BITMAP Bm;
GetObject(BitMap, sizeof(Bm), &Bm);
Header = CreateHeader(Width, Height, Bm.bmBitsPixel);
Buffer = new char [Width*Height*Bm.bmBitsPixel/8];
BytesPixel = Bm.bmBitsPixel/8;
GetDIBits(MemDc, BitMap, 0, Height, Buffer, (BITMAPINFO *)&Header, DIB_RGB_COLORS);
ReleaseDC(0, dc);
ReleaseDC(0, MemDc);
DeleteObject(BitMap);
SetTimer(hwnd, 1025, 100, 0);
}
break;
case WM_DESTROY:
delete Buffer;
PostQuitMessage(0);
break;
case WM_TIMER:
{
HDC dc = GetDC(0);
Idx = (Idx + 2)%Height;
Draw(dc);
ReleaseDC(0, dc);
}
break;
case WM_PAINT:
{
BITMAP bm; /* Bitmap structure as seen in bmWidth & bmHeight */
PAINTSTRUCT ps;
HDC dc = BeginPaint(hwnd, &ps);
Draw(dc);
EndPaint(hwnd, &ps);
}
break;
default:
return DefScreenSaverProc(hwnd, message, wParam, lParam);
}
return 0;
}
BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
return FALSE;
}
BOOL WINAPI RegisterDialogClasses(HANDLE hInst)
{
return TRUE;
}
Så vælger du Options->Compiler Options i menu'en
På directories tabben sætter du X ud for "Add the following commands when calling the compiler" Og i boxen under skriver du: -lscrnsave
På Linker tabben sætter du X i "Compile for Win32 (no console)"
Så trykker du Ctrl+F9 for at kompilere.
Når det er overstået skal du omdøbe programmet fra xxx.exe til xxx.scr og køre programmet. Jeg har ikke regnet ud om man kan gøre dette fra DevCpp.
ScreenSaveren skulle gerne scrolle skærmen.