www.pudn.com > bmp24.rar > mainTestWin.cpp
/*main test for bmp parse program*/ #include "FileFormat.h" #include#include #include #include char* inputFileName="bmpName.txt"; char* inputBMPFileName; #define MAXNAMELEN 32 long WINAPI WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam); BOOL InitWindowsClass(HINSTANCE hInstance); BOOL InitWindows(HINSTANCE hInstance,int nCmdShow); HWND hWndMain; LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); //program starting. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow) { MSG msg; if(!InitWindowsClass(hInstance)) return FALSE; if(!InitWindows(hInstance,nCmdShow)) return FALSE; //Core message looping while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } //main wndProc function: message looping long WINAPI WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam) { HDC hDC; HBRUSH hBrush; HPEN hPen; PAINTSTRUCT PtStr; FILE* inputFile,* inputBMPFile; if((inputFile=fopen(inputFileName,"rb"))==NULL) { MessageBox(hWnd,"open inputfile error!","Msg Box",MB_OK); //return 0; } inputBMPFileName=(char*)malloc(sizeof(char)*MAXNAMELEN); fscanf(inputFile,"%s\r\n",inputBMPFileName); inputBMPFileName[strlen(inputBMPFileName)+1]='\0'; if((inputBMPFile=fopen(inputBMPFileName,"rb"))==NULL) { MessageBox(hWnd,"open input bmp file error!","Msg Box",MB_OK); // return 0; } BMParse tBMParse(inputBMPFile); tBMParse.setReadInFile(inputBMPFile); tBMParse.showHeadInfo(); tBMParse.parseBMPMatrix(); switch(iMessage) { case WM_PAINT: //First draw,a black line hDC=BeginPaint(hWnd,&PtStr); hPen=(HPEN)GetStockObject(NULL_PEN);//get empty brush SelectObject(hDC,hPen); hBrush=(HBRUSH)GetStockObject(BLACK_BRUSH); SelectObject(hDC,hBrush); hPen=CreatePen(PS_SOLID,2,RGB(255,0,0));//create pen SelectObject(hDC,hPen); tBMParse.showBMP(hDC); //tBMParse.linearInsertTrial(hDC); DeleteObject(hPen); DeleteObject(hBrush); EndPaint(hWnd,&PtStr); // MessageBox(hWnd,"HelloWorld!","Msg Box",MB_OK); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc(hWnd,iMessage,wParam,lParam); } } //Init the Window to show out. BOOL InitWindows(HINSTANCE hInstance,int nCmdShow) { HWND hWnd; hWnd=CreateWindow("WinFill", "test program for parse bmp file.", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL ); if(!hWnd) return FALSE; hWndMain=hWnd; ShowWindow(hWnd,nCmdShow); UpdateWindow(hWnd); return TRUE; } //Set wndClass Propertity BOOL InitWindowsClass(HINSTANCE hInstance) { WNDCLASS wndClass; wndClass.cbClsExtra=0; wndClass.cbWndExtra=0; wndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wndClass.hCursor=LoadCursor(NULL,IDC_ARROW); wndClass.hIcon=LoadIcon(NULL,"END"); wndClass.hInstance=hInstance; wndClass.lpfnWndProc=WndProc; wndClass.lpszClassName="WinFill"; wndClass.lpszMenuName=NULL; wndClass.style=CS_HREDRAW|CS_VREDRAW; return RegisterClass(&wndClass); }