ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 비트맵 출력 (사이즈 상관없음)
    Programming/WPF, WIN32API, MFC 2008. 10. 1. 09:36
    #include <windows.h>

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

    LPCTSTR lpszClass=TEXT("First");


    char buf[50000];
    BITMAPFILEHEADER Fihd;
    BITMAPINFOHEADER Imhd;


    int APIENTRY WinMain(HINSTANCE hlnstance,HINSTANCE hPrevlnstance,LPSTR lpszCmdParam,int nCmdShow)
    {
      HWND hWnd;
      MSG Message;
      WNDCLASS WndClass;
      g_hlnst=hlnstance;

      WndClass.cbClsExtra=0;
      WndClass.cbWndExtra=0;
      WndClass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);

      WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
      WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
      WndClass.hInstance=hlnstance;
      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,300,300,NULL,(HMENU)NULL,hlnstance,NULL);
      ShowWindow(hWnd,nCmdShow);

      while(GetMessage(&Message,NULL,0,0))
      {
        TranslateMessage(&Message);
        DispatchMessage(&Message);
      }

      return (int)Message.wParam;
    }


    LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
    {
      HDC hdc;
      PAINTSTRUCT ps;
      HANDLE hFile;
      DWORD dwRead;
      RECT rt;

      TCHAR kk[100];
     
      int iCntX;
      int iCntY;


      int Jump;

     



      switch(iMessage)
      {
      case WM_SIZE:
        hFile=CreateFile(TEXT("test1.bmp"), GENERIC_READ, 0, NULL, OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL, NULL);

        if(hFile != INVALID_HANDLE_VALUE)
        {
          ReadFile(hFile, buf, 50000, &dwRead, NULL);
          memcpy(&Fihd, &buf[0], sizeof(Fihd));
          memcpy(&Imhd, &buf[14], sizeof(Imhd));
          CloseHandle(hFile);
          InvalidateRect(hWnd,NULL,TRUE);


          //wsprintf(kk,TEXT("%c%c"),buf[0],buf[1]);
          wsprintf(kk,TEXT("가로 - %d , 세로 - %d"),Imhd.biWidth, Imhd.biHeight);

     
          SetWindowText(hWnd, kk);
         
        }
        else
        {
         
          SetWindowText(hWnd,TEXT("File Open 실패") );  
        }
        return 0;


      case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        GetClientRect(hWnd, &rt);


    // 핵심부분
        Jump=0x36
    ;    

       
    for(iCntY= 0; iCntY <
     Imhd.biHeight ; ++iCntY)
        {       
         
    for(iCntX=0; iCntX  <
     Imhd.biWidth  ; ++iCntX )
          {
            SetPixel(hdc,iCntX, Imhd.biHeight-iCntY,RGB(buf[Jump+
    2], buf[Jump+1], buf[Jump+0
    ]));
            Jump+
    =3
    ;
             
          } 
          
    if(iCntX % 4 !=0
    )
           {
            Jump+
    =iCntX%4
    ;

          }
         
        }


         
        EndPaint(hWnd, &ps);
        return 0;


      case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
      }
      return(DefWindowProc(hWnd,iMessage,wParam,lParam));
    }

    TAG

    댓글 0

Designed by Tistory.