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
| //Global :
HBITMAP g_hBitmap;
BITMAP g_bm;
BITMAPINFOHEADER g_bmInfoHead;
LPVOID g_lpvImg;
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
//...
// Set the class with the properties of the window :
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
//...
// Register the window :
RegisterClassEx(&wcex);
// Creating the window :
HWND MainWnd = CreateWindow("MyWindowClass", "Hello World", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT, 808, 650, NULL, NULL, hInstance, NULL);
// Bitmap initialisation :
HDC hdc = GetDC(MainWnd); // [ICI]
g_hBitmap = CreateCompatibleBitmap(hdc, g_PixelBuffer->SizeW(), g_PixelBuffer->SizeH());
int result = GetObject(g_hBitmap, sizeof(g_bm), &g_bm);
LPVOID g_lpvImg = new char[ g_bm.bmWidth * g_bm.bmHeight * g_bm.bmBitsPixel ];
g_bmInfoHead.biSize = sizeof(BITMAPINFOHEADER);
g_bmInfoHead.biWidth = g_bm.bmWidth;
g_bmInfoHead.biHeight = g_bm.bmHeight;
g_bmInfoHead.biPlanes = g_bm.bmPlanes;
g_bmInfoHead.biBitCount = g_bm.bmBitsPixel;
g_bmInfoHead.biCompression = BI_RGB;
result = GetDIBits(hdc, g_hBitmap, 0, g_bm.bmHeight, g_lpvImg, (LPBITMAPINFO)&g_bmInfoHead, DIB_RGB_COLORS);
// Show and update the window :
ShowWindow(MainWnd, nCmdShow);
UpdateWindow(MainWnd);
// Loop :
MSG msg;
ZeroMemory( &msg, sizeof(msg) );
while( msg.message != WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
delete[] g_lpvImg;
//quit the program :
return (int)msg.wParam;
} |
Partager