#include #define WIDTH 197 #define HEIGHT 100 LRESULT CALLBACK WindowProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; static LPBYTE lpPixel; static LPBITMAPINFO lpBmpInfo; static HDC hMemDC; HBITMAP hBitmap,hOldBitmap; int x,y; static int length; switch(uMsg) { case WM_CREATE: //DDB作成 hdc=GetDC(hWnd); hMemDC=CreateCompatibleDC(hdc); hBitmap=CreateCompatibleBitmap(hdc,WIDTH,HEIGHT); //グラデーションで塗りつぶす hOldBitmap=(HBITMAP)SelectObject(hMemDC,hBitmap); for(y=0;ybmiHeader.biSize=sizeof(BITMAPINFOHEADER); lpBmpInfo->bmiHeader.biWidth=WIDTH; lpBmpInfo->bmiHeader.biHeight=HEIGHT; lpBmpInfo->bmiHeader.biPlanes=1; lpBmpInfo->bmiHeader.biBitCount=8; lpBmpInfo->bmiHeader.biCompression=BI_RGB; //DDB→DIB変換 GetDIBits(hdc,hBitmap,0,HEIGHT,lpPixel,lpBmpInfo,DIB_RGB_COLORS); SelectObject(hMemDC,hBitmap); DeleteObject(hBitmap); ReleaseDC(hWnd,hdc); for(y=25;y<50;y++){ //DIBに描画 for(x=25;x<50;x++){ lpPixel[x+y*length]=( (x-25)+(y-25)*25 )%256; } } Rectangle(hMemDC,25,25,50,50); //DDBに描画 return 0; case WM_DESTROY: DeleteDC(hMemDC); //DDB削除 HeapFree(GetProcessHeap(),0,lpPixel); //DIB削除 PostQuitMessage(0); return 0; case WM_PAINT: hdc=BeginPaint(hWnd,&ps); BitBlt(hdc,0,0,WIDTH,HEIGHT,hMemDC,0,0,SRCCOPY); //DDBを表画面へ転送 StretchDIBits(hdc,250,0,WIDTH,HEIGHT, //DIBを表画面へ転送 0,0,WIDTH,HEIGHT,lpPixel,lpBmpInfo,DIB_RGB_COLORS,SRCCOPY); EndPaint(hWnd,&ps); return 0; } return DefWindowProc(hWnd,uMsg,wParam,lParam); } int WINAPI WinMain( HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR lpCmdLine,int nCmdShow) { WNDCLASS wc; MSG msg; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL,IDI_APPLICATION); wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = __FILE__; if(!RegisterClass(&wc)) return 0; HWND hWnd=CreateWindow( __FILE__,"DDB→8ビットDIB変換", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, NULL,NULL,hInstance,NULL); if(hWnd==NULL) return 0; BOOL bRet; while((bRet=GetMessage(&msg,NULL,0,0))!=0){ if(bRet==-1) break; DispatchMessage(&msg); } return (int)msg.wParam; }