BITMAP　파일 구조

#include<windows.h>

#include"resource.h"

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

BOOL CALLBACK InfoDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);

HINSTANCE g_hInst

HWND hWndMain

LPCTSTR lpszClass=TEXT("Bitmap");

int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance

,LPSTR lpszCmdParam,int nCmdShow)

{

HWND hWnd

MSG Message

WNDCLASS WndClass

g_hInst = hInstance

WndClass.cbClsExtra=0;

WndClass.cbWndExtra=0;

WndClass.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);

WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);

WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);

WndClass.hInstance=hInstance

WndClass.lpfnWndProc=WndProc

WndClass.lpszClassName=lpszClass

WndClass.lpszMenuName=NULL

WndClass.style=CS_HREDRAW | CS_VREDRAW

RegisterClass(&WndClass);

hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,

NULL,(HMENU)NULL,hInstance,NULL);

ShowWindow(hWnd,nCmdShow);

while(GetMessage(&Message,NULL,0,0)){

TranslateMessage(&Message);

DispatchMessage(&Message);

}

return (int)Message.wParam

}

char buf[200000];

PAINTSTRUCT ps

HANDLE hFile

DWORD dwRead

static int x,y

int iW, iH, iPad, iSize

int BitmapChange = 0;

TCHAR tt[200];

BITMAPFILEHEADER *BitmapH

BITMAPINFOHEADER *BitinfoH

LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)

{

HDC hdc

HDC hMemDC

switch(iMessage)

{

case WM_CREATE:

hWndMain = hWnd

hdc = GetDC(hWnd);

hMemDC = CreateCompatibleDC(hdc);

SelectObject(hMemDC,GetStockObject(WHITE_PEN));

Rectangle(hMemDC, 0,0,1024,768);

hFile=CreateFile(TEXT("1.bmp"),GENERIC_READ, 0, NULL,

OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

BitmapH = (BITMAPFILEHEADER *)buf

BitinfoH = (BITMAPINFOHEADER *)(buf+14);

if(INVALID_HANDLE_VALUE != hFile)

{

ReadFile(hFile, buf, 200000, &dwRead, NULL);

wsprintf(tt, TEXT("Magic Number [%c][%c][%d]")

, BitmapH->bfType&0xFF, BitmapH->bfType>>8, *(int *)(buf+18));

}

else

{

wsprintf(tt, TEXT("Error"));

}

SetWindowText(hWnd, tt);

CloseHandle(hFile);

DeleteDC(hMemDC);

return 0;

case WM_PAINT:

hdc	= BeginPaint(hWnd,&ps);

iW	= *(int *)(buf+18);

iW	= iW*3;

iH	= *(int *)(buf+22);

iPad	= *(int *)(buf+10);

iSize	= *(int *)(buf+34);

iSize	= (iSize - iW*iH)/iH

for(y = 0; iH > y y++)

{

for (x = 0; iW > x x+=3)

{

switch(BitmapChange)

{

case 0:

SetPixel(hdc ,x/3,iH-y-1,

RGB(buf[iPad+x+2+y*iW],buf[iPad+x+1+y*iW],buf[iPad+x+0+y*iW]));

break

case 1:

SetPixel(hdc ,iW/3-1-y,iH-x/3-1,

RGB(buf[iPad+x+2+y*iW],buf[iPad+x+1+y*iW],buf[iPad+x+0+y*iW]));

break

case 2:

SetPixel(hdc ,iW/3-x/3-1, y,

RGB(buf[iPad+x+2+y*iW],buf[iPad+x+1+y*iW],buf[iPad+x+0+y*iW]));

break

case 3:

SetPixel(hdc , y, x/3,

RGB(buf[iPad+x+2+y*iW],buf[iPad+x+1+y*iW],buf[iPad+x+0+y*iW]));

break

default:

break

}

}

iPad += iSize

}

if(DialogBox(g_hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, InfoDlgProc) == IDOK)

{

InvalidateRect(hWnd, NULL, TRUE);

}

EndPaint(hWnd,&ps);

return 0;

case WM_DESTROY:

PostQuitMessage(0);

return 0;

}

return(DefWindowProc(hWnd,iMessage,wParam,lParam));

}

BOOL CALLBACK InfoDlgProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)

{

switch(iMessage)

{

case WM_INITDIALOG:

wsprintf(tt, TEXT("%c%c"),BitmapH->bfType&0xFF,BitmapH->bfType>>8);

SetDlgItemText(hDlg, IDC_EDIT1, tt);

wsprintf(tt, TEXT("%d"),BitmapH->bfSize);

SetDlgItemText(hDlg, IDC_EDIT2, tt);

wsprintf(tt, TEXT("%d"),BitmapH->bfReserved1);

SetDlgItemText(hDlg, IDC_EDIT3, tt);

wsprintf(tt, TEXT("%d"),BitmapH->bfOffBits);

SetDlgItemText(hDlg, IDC_EDIT4, tt);

wsprintf(tt, TEXT("%d"),BitinfoH->biSize);

SetDlgItemText(hDlg, IDC_EDIT5, tt);

wsprintf(tt, TEXT("%d"),BitinfoH->biWidth);

SetDlgItemText(hDlg, IDC_EDIT6, tt);

wsprintf(tt, TEXT("%d"),BitinfoH->biHeight);

SetDlgItemText(hDlg, IDC_EDIT7, tt);

wsprintf(tt, TEXT("%d"),BitinfoH->biPlanes);

SetDlgItemText(hDlg, IDC_EDIT8, tt);

wsprintf(tt, TEXT("%d"),BitinfoH->biBitCount);

SetDlgItemText(hDlg, IDC_EDIT9, tt);

wsprintf(tt, TEXT("%d"),BitinfoH->biCompression);

SetDlgItemText(hDlg, IDC_EDIT10, tt);

wsprintf(tt, TEXT("%d"),BitinfoH->biSizeImage);

SetDlgItemText(hDlg, IDC_EDIT11, tt);

wsprintf(tt, TEXT("%d"),BitinfoH->biXPelsPerMeter);

SetDlgItemText(hDlg, IDC_EDIT12, tt);

wsprintf(tt, TEXT("%d"),BitinfoH->biYPelsPerMeter);

SetDlgItemText(hDlg, IDC_EDIT13, tt);

wsprintf(tt, TEXT("%d"),BitinfoH->biClrUsed);

SetDlgItemText(hDlg, IDC_EDIT14, tt);

wsprintf(tt, TEXT("%d"),BitinfoH->biClrImportant);

SetDlgItemText(hDlg, IDC_EDIT15, tt);

return TRUE

case WM_COMMAND:

switch(LOWORD(wParam))

{

case IDOK:

BitmapChange = (BitmapChange + 1) % 4;

InvalidateRect(hWndMain, NULL, FALSE);

break

case IDCANCEL:

EndDialog(hDlg, IDCANCEL);

DestroyWindow(hDlg);

return TRUE

}

break

case WM_DESTROY:

PostQuitMessage(0);

return 0;

}

return FALSE

}