/* DIB(デバイス独立ビットマップ)テスト 1999/ 4/27 宍戸 輝光 */ #include LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); BITMAPINFO BmInfo; BITMAPINFOHEADER BmInfoHed; LPBYTE lpBMP; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){ HWND hwnd; MSG msg; WNDCLASSEX wndclass ; int i; wndclass.cbSize = sizeof(wndclass); 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 = "Test Window"; wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION); RegisterClassEx (&wndclass); hwnd = CreateWindow ("Test Window", "DIB Test", WS_OVERLAPPEDWINDOW, 32,32, 128,128, NULL, NULL, hInstance, NULL); BmInfoHed.biSize=sizeof(BITMAPINFOHEADER); /* 構造体の大きさ */ BmInfoHed.biWidth=64; /* 横幅 */ BmInfoHed.biHeight=64; /* 高さ */ BmInfoHed.biPlanes=1; /* プレーンの数 */ BmInfoHed.biBitCount=24; /* プレーンの色数 */ BmInfoHed.biCompression=BI_RGB; BmInfoHed.biSizeImage=0; BmInfoHed.biXPelsPerMeter=0; BmInfoHed.biYPelsPerMeter=0; BmInfoHed.biClrUsed=0; BmInfoHed.biClrImportant=0; BmInfo.bmiHeader=BmInfoHed; /* ビットマップ用バッファ */ lpBMP=(LPBYTE)GlobalAlloc(GPTR,64*64*3); for (i=0;i<64*64;i++) { /* 各ピクセルに色を付ける */ lpBMP[i*3]=0; /* 青成分 */ lpBMP[i*3+1]=128; /* 緑成分 */ lpBMP[i*3+2]=255; /* 赤成分 */ } ShowWindow (hwnd,iCmdShow); /* ウインドウを表示 */ UpdateWindow (hwnd); while (GetMessage (&msg,NULL,0,0)) { /* メッセージループ */ TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam ; } LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; switch (iMsg) { case WM_DESTROY : GlobalFree(lpBMP); /* ビットマップのバッファを解放 */ PostQuitMessage(0); return 0; case WM_PAINT: hdc=BeginPaint(hwnd,&ps); StretchDIBits(hdc,0,0,64,64,0,0,64,64,lpBMP,&BmInfo, DIB_RGB_COLORS,SRCCOPY); /* DIB表示 */ EndPaint(hwnd,&ps); } return DefWindowProc (hwnd, iMsg, wParam, lParam) ; }