#include "stdafx.h"
#include "loadbmp.h"
#include <windows.h>
        
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
        PSTR szCmdLine, int iCmdShow)
{
        static TCHAR szAppName [] = TEXT ("Demo") ;
        HWND    hwnd ;
        MSG     msg ;
        WNDCLASS    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 = szAppName ;
        
   
        if (!RegisterClass (&wndclass))
        {
              MessageBox (NULL, TEXT ("This program requires Windows!"),
szAppName, MB_ICONERROR) ;
  return 0 ;
        }
        
hwnd = CreateWindow ( szAppName, TEXT ("LoadBitmap Demo"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;        ShowWindow (hwnd, iCmdShow) ;
        UpdateWindow (hwnd) ;
        
while (GetMessage (&msg, NULL, 0, 0))
        {
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
        }
        return msg.wParam ;
}
  
LRESULT CALLBACK WndProc ( HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam)
{
        static HBITMAP hbmp;
        static int  cxClient,  cyClient,  cxSource, cySource;
        BITMAP   bitmap;
        HDC  hdc, hdcMem;
        HINSTANCE  hInstance;
        PAINTSTRUCT  ps;
        BYTE  *   bits;
        BITMAPINFO   bh   =   {0};
        int  x, y;
int BytesPerLine;

switch (message)
        {
            case WM_CREATE:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
hbmp = LoadBitmap (hInstance, MAKEINTRESOURCE(IDB_BITMAP1));
GetObject (hbmp, sizeof (BITMAP), &bitmap) ;
cxSource = bitmap.bmWidth ;
cySource=  bitmap.bmHeight ;
return 0 ; case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
hdcMem = CreateCompatibleDC (hdc) ;
                SelectObject (hdcMem, hbmp) ;
//StretchBlt (hdc, 0, 0,cxSource, cySource, hdcMem, 0, 0, cxSource, cySource, MERGECOPY) ;
                GetObject (hbmp, sizeof (BITMAP), &bitmap) ;
               
                bh.bmiHeader.biSize   =   sizeof(bh.bmiHeader);
    GetDIBits(hdc, hbmp, 0, 0, NULL, &bh, DIB_RGB_COLORS);   //   查询BITMAPINFO  
                BytesPerLine = 4*((bitmap.bmWidth*24+31)/32);                bh.bmiHeader.biBitCount = 24;
bh.bmiHeader.biCompression = BI_RGB;
                bh.bmiHeader.biSizeImage = BytesPerLine * bitmap.bmHeight;
                bh.bmiHeader.biHeight = bitmap.bmHeight;//高度
                bh.bmiHeader.biPlanes = 1;
                bh.bmiHeader.biWidth = bitmap.bmWidth;//宽度
 
     
bits  = new   BYTE[bh.bmiHeader.biSizeImage]; 
GetDIBits(hdc,   hbmp,   0,  bh.bmiHeader.biHeight ,   bits,   &bh,   DIB_RGB_COLORS); 
                //   获得整张位图的数据,保存到bits指向的空间
               
for(y=bh.bmiHeader.biHeight-1; y>=0; y--)
               {
                     for(x=0; x<bh.bmiHeader.biWidth; x++)
                     {
                           BYTE bBlue = bits[3*bh.bmiHeader.biWidth*y+ 3*x+0];   
                           BYTE bGreen = bits[3*bh.bmiHeader.biWidth*y+3*x+1];   
                           BYTE bRed = bits[3*bh.bmiHeader.biWidth*y+ 3*x+2];  
   SetPixel(hdc, x, bh.bmiHeader.biHeight-y-1,  RGB(bBlue,   bGreen,   bRed));
}
    }
    
             
DeleteDC (hdcMem) ;
EndPaint (hwnd, &ps) ;
return 0 ; case  WM_DESTROY:
DeleteObject (hbmp) ;
PostQuitMessage (0) ;
return 0 ;
}
        return DefWindowProc (hwnd, message, wParam, lParam) ;
}图片变斜了,对其问题不太懂