/* 24ビットDIB 2004/ 3/ 8 宍戸 輝光 */ #include HINSTANCE g_hInstance; HWND g_hwMain; /* DIB用変数 */ BITMAPINFO g_biDIB; LPBYTE g_lpbyDIB; int g_iWidth, g_iLength; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { MSG msg; WNDCLASS wndclass; g_hInstance = hInstance; /* DIB用BITMAPINFOをクリア */ ZeroMemory(&g_biDIB, sizeof(g_biDIB)); g_iWidth = 255; /* DIB用BITMAPINFO設定 */ g_biDIB.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); g_biDIB.bmiHeader.biWidth = g_iWidth; g_biDIB.bmiHeader.biHeight = 256; g_biDIB.bmiHeader.biPlanes = 1; g_biDIB.bmiHeader.biBitCount = 24; g_biDIB.bmiHeader.biCompression = BI_RGB; /* ピクセル列用バッファの横幅算出 */ if (g_iWidth % 4 == 0) { g_iLength = g_iWidth * 3; } else { g_iLength = g_iWidth * 3 + (4 - (g_iWidth * 3) % 4); } /* DIBピクセル列用バッファ確保 */ g_lpbyDIB = (LPBYTE)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 256 * g_iLength); /* (16, 31)に赤い点(0x00ff0000)を打つ */ g_lpbyDIB[16 * 3 + 31 * g_iLength + 2] = 0xff; /* (16, 32)に赤い点(0x00ff0000)を打つ */ g_lpbyDIB[16 * 3 + 32 * g_iLength + 2] = 0xff; /* ウインドウクラス設定 */ wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = "24BitDIB"; RegisterClass(&wndclass); /* ウインドウ作成 */ g_hwMain = CreateWindow("24BitDIB", "24ビットDIB", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 320, 320, NULL, NULL, hInstance, NULL); /* ウインドウを表示 */ ShowWindow(g_hwMain, iCmdShow); UpdateWindow(g_hwMain); /* メインループ */ do { /* メッセージ処理 */ if (GetMessage(&msg,NULL,0,0) == 0) { break; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } while (TRUE); /* DIBピクセル列用バッファ解放 */ HeapFree(GetProcessHeap(), 0, g_lpbyDIB); return (int)msg.wParam; } /* ウインドウプロシージャー */ LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; switch (iMsg) { case WM_PAINT: /* 描画処理 */ hdc = BeginPaint(hwnd, &ps); /* DIB描画 */ StretchDIBits(hdc, 0, 0, g_iWidth, 256, 0, 0, g_iWidth, 256, g_lpbyDIB, &g_biDIB, DIB_RGB_COLORS, SRCCOPY); EndPaint(hwnd, &ps); return 0; case WM_DESTROY: /* 終了処理 */ PostQuitMessage(0); return 0; } return DefWindowProc (hwnd, iMsg, wParam, lParam) ; }