Doe wrote:
> Hvis jeg skal gøre følgende (udelukkende til Windows):
>
> Køre grafik mode (jeg går ud fra, at det skal være med DirectX?)
Det behøver ikke være DirectX, man kan godt lave sjov med mindre:
#include <windows.h>
HINSTANCE InstanceHandle;
HWND MainWindow;
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 MainWndProc(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_LBUTTONDOWN:
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:
{
PAINTSTRUCT ps;
HDC dc = BeginPaint(hwnd, &ps);
Draw(dc);
EndPaint(hwnd, &ps);
}
break;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
HWND CreateMainWindow()
{
WNDCLASS wc;
memset(&wc, 0, sizeof(WNDCLASS));
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ;
wc.lpfnWndProc = (WNDPROC )MainWndProc;
wc.hInstance = InstanceHandle;
wc.hbrBackground = (HBRUSH )(COLOR_WINDOW + 1);
wc.lpszClassName = "SimpleWinWndClass";
wc.lpszMenuName = 0;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClass(&wc))
return 0;
return CreateWindow("SimpleWinWndClass",
"Simple-Window",
WS_MINIMIZEBOX | WS_VISIBLE |
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_MAXIMIZEBOX |
WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_THICKFRAME,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
0,
0,
InstanceHandle,
0);
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
INT nCmdShow)
{
InstanceHandle = hInstance;
if((MainWindow = CreateMainWindow()) == (HWND )0)
{
MessageBox(0, "Failed to create MainWindow!", "Warning", MB_OK);
return 0;
}
ShowWindow(MainWindow, SW_SHOW);
MSG Msg;
while(GetMessage(&Msg, 0, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
InvalidateRect(0, 0, TRUE);
return Msg.wParam;
}
Tryk på vinduet for at få den til at holde op.
> Afspille musik (f.eks. XM eller MP3 m.v.)
Se den anden tråd.
> Lave lidt flydende grafik og en scrolltekst
> Kompilere det hele til én EXE fil
Se den anden tråd.
>
> .. hvilke gode bøger kan I så anbefale?
Det ved jeg ikke, jeg er ikke så meget til bøger.
--
Absolutely not the best homepage on the net:
http://home20.inet.tele.dk/midgaard
But it's mine - Bertel