SAKingdom
Messages postés
3212
Date d'inscription
lundi 7 novembre 2005
Statut
Membre
Dernière intervention
16 février 2009
15
18 mai 2006 à 21:36
En MFC, je sais pas trop mais normalement, on stock toute les données de couleur dans un tableau BYTE puis on utilise SetDIBitsToDevice pour l'affiche à l'écran. Tien voici un exemple d'un programme complet en Win32 API:
#include <windows.h>
BITMAPINFO dib;
HRESULT WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
switch(message)
{
case WM_CREATE:
ZeroMemory(&dib, sizeof(dib));
dib.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
dib.bmiHeader.biHeight = 150;
dib.bmiHeader.biWidth = 150;
dib.bmiHeader.biPlanes = 1;
dib.bmiHeader.biBitCount = 24;
dib.bmiHeader.biCompression = BI_RGB;
break;
case WM_PAINT:
{
HDC hDC=BeginPaint(hWnd, &ps);
DWORD bytewidth = 4*((3*150+3)/4);
LPBYTE lpBits = new BYTE[bytewidth*150];
if (!(lpBits)) { return NULL; }
int tmp = 0;
for (int y = 50; y < 100; y++)
{
for (int x = 50; x < 100; x++)
{
tmp = (150-y-1)*bytewidth+3*x;
lpBits[tmp]=0;
lpBits[tmp+1]=255;
lpBits[tmp+2]=0;
}
}
SetDIBitsToDevice(hDC, 0, 0, 150, 150, 0, 0, 0, 150, lpBits, &dib, DIB_RGB_COLORS);
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASSEX wcex;
MSG msg;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wcex.lpszMenuName = 0;
wcex.lpszClassName = "test";
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
HWND hWnd = CreateWindow("test", "test", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 150, 150, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
MessageBox(0, "Impossible", 0, 0);
return FALSE;
}
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
___________________________________________
Les plus grands esprits trouvent toujours une solution