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
|
#include <stdio.h>
#include <windows.h>
#include <conio.c>
#pragma hdrstop
static char g_szClassName[] = "MyWindowClass";
static HINSTANCE g_hInst = NULL;
HBITMAP hb1,hb2,hb3,hb4,hb5,hb6;
BITMAP bm[5];
int winX = 0, winY = 0, winfX = 900, winfY = 700, i, j, X, Y;
int bx[] = {0, 663, 663, 663, 663};
int by[] = {0, 71, 142, 213, 526};
void DrawBall(HDC hdc)
{
HDC hdcMemory;
hdcMemory = CreateCompatibleDC(hdc);
SelectObject(hdcMemory, hb1);
BitBlt(hdc, bx[0], by[0], bm[1].bmWidth, bm[1].bmHeight, hdcMemory, 0, 0, SRCAND);
SelectObject(hdcMemory, hb2);
BitBlt(hdc, bx[1], by[1], bm[2].bmWidth, bm[2].bmHeight, hdcMemory, 0, 0, SRCAND);
SelectObject(hdcMemory, hb3);
BitBlt(hdc, bx[2], by[2], bm[3].bmWidth, bm[3].bmHeight, hdcMemory, 0, 0, SRCAND);
SelectObject(hdcMemory, hb4);
BitBlt(hdc, bx[3], by[3], bm[4].bmWidth, bm[4].bmHeight, hdcMemory, 0, 0, SRCAND);
SelectObject(hdcMemory, hb5);
BitBlt(hdc, bx[4], by[4], bm[5].bmWidth, bm[5].bmHeight, hdcMemory, 0, 0, SRCAND);
DeleteDC(hdcMemory);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_CREATE:
hb1 = LoadBitmap(g_hInst, "TITRE");
GetObject(hb1, sizeof(bm[1]), &bm[1]);
hb2 = LoadBitmap(g_hInst, "BTSOLO");
GetObject(hb2, sizeof(bm[2]), &bm[2]);
hb3 = LoadBitmap(g_hInst, "BTOPTIONS");
GetObject(hb3, sizeof(bm[3]), &bm[3]);
hb4 = LoadBitmap(g_hInst, "BTCREDITS");
GetObject(hb4, sizeof(bm[4]), &bm[4]);
hb5 = LoadBitmap(g_hInst, "BTQUITTER");
GetObject(hb5, sizeof(bm[5]), &bm[5]);
break;
case WM_PAINT:
if(hb1 && hb2 && hb3 && hb4 && hb5)
{
PAINTSTRUCT ps;
HDC hdcWindow;
hdcWindow = BeginPaint(hwnd, &ps);
DrawBall(hdcWindow);
EndPaint(hwnd, &ps);
}
break;
case WM_CHAR:
switch (wParam)
{
default:
break;
}
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
DeleteObject(hb1);
DeleteObject(hb2);
DeleteObject(hb3);
DeleteObject(hb4);
DeleteObject(hb5);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndClass;
HWND hwnd;
MSG Msg;
g_hInst = hInstance;
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = g_hInst;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = g_szClassName;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&WndClass))
{
MessageBox(0, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"A Bitmap Program",
WS_OVERLAPPEDWINDOW,
winX, winY, winfX, winfY,
NULL, NULL, g_hInst, NULL);
if(hwnd == NULL)
{
MessageBox(0, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
} |
Partager