1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
| #include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <ddraw.h>
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY
WinMain (HINSTANCE hinstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND window;
WNDCLASS wc;
MSG msg;
int width;
int height;
int running;
/* Create the main window */
width = 320;
height = 200;
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 = (HBRUSH)(1 + COLOR_BTNFACE);
wc.lpszMenuName = NULL;
wc.lpszClassName = "MaWinClass";
if(!RegisterClass(&wc)) return -1;
window = CreateWindow("MaWinClass", "Titre",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
width, height,
NULL, NULL, hinstance, NULL);
if (!window) return -1;
ShowWindow(window, nCmdShow);
UpdateWindow(window);
{
LPDIRECTDRAW lpDD;
HRESULT res;
DDSURFACEDESC ddsd;
LPDIRECTDRAWSURFACE lpDDS;
int *surf, *tmp;
int w, h, depth, pitch, r, g;
res = DirectDrawCreate (NULL, &lpDD, NULL);
if (FAILED (DD_OK)) {
printf ("DirectDrawCreate fails\n");
return EXIT_FAILURE;
}
res = lpDD->SetCooperativeLevel (window, DDSCL_NORMAL);
if (FAILED (res)) {
printf ("SetCooperativeLevel fails\n");
lpDD->Release ();
return EXIT_FAILURE;
}
w = 64;
h = 64;
depth = 3;
pitch = depth * w;
surf = (int *)malloc (sizeof (int) * depth * w * h);
if (!surf) {
lpDD->Release ();
return EXIT_FAILURE;
}
ZeroMemory (surf, depth * w * h * sizeof (int));
tmp = surf;
for (r = 0; r < w; r++) {
for (g = 0; g < h; g++, tmp += 3) {
tmp[0] = (r * 2) % 256;
tmp[1] = g % 256;
tmp[2] = (w - 1 - g) * 4;
}
}
ZeroMemory (&ddsd, sizeof (DDSURFACEDESC));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_LPSURFACE |
DDSD_PITCH | DDSD_PIXELFORMAT | DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
DDSCAPS_SYSTEMMEMORY;
ddsd.dwWidth = w;
ddsd.dwHeight= h;
ddsd.lPitch = pitch;
ddsd.lpSurface = surf;
// Set up the pixel format for 24-bit RGB (8-8-8).
ZeroMemory (&ddsd.ddpfPixelFormat, sizeof (DDPIXELFORMAT));
ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
ddsd.ddpfPixelFormat.dwFlags= DDPF_RGB;
ddsd.ddpfPixelFormat.dwRGBBitCount = (DWORD)depth * 8;
ddsd.ddpfPixelFormat.dwRBitMask = 0x00FF0000;
ddsd.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
ddsd.ddpfPixelFormat.dwBBitMask = 0x000000FF;
// Create the surface
res = lpDD->CreateSurface(&ddsd, &lpDDS, NULL);
if (FAILED (res))
{
printf ("Damned\n");
lpDD->Release ();
free (surf);
return EXIT_SUCCESS;
}
}
/* the main loop */
running = 1;
while (running) {
while (PeekMessage (&msg, window, 0, 0, PM_NOREMOVE)) {
int res;
res = GetMessage (&msg, NULL, 0, 0);
TranslateMessage (&msg);
DispatchMessage (&msg);
if (res == 0)
running = 0;
}
}
return 0;
}
LRESULT CALLBACK
MainWndProc(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
} |
Partager