位图和位块传输(2)压缩拉伸之StretchBlt函数
2012-08-10 20:14 java线程例子 阅读(360) 评论(0) 编辑 收藏 举报在BitBlt函数中,目标图像和源图像的大小一样,是因为函数只有两个参数来指定宽和高,如果想要复制是拉伸或压缩图像的大小,可以使用StretchBlt函数
StretchBlt(hdcDst,xDst,yDst,cxDst,cyDst,hdcSrc,xSrc,ySrc,cxSrc,cySrc,dwRop);
下面这个程序展示了一下StretchBlt函数的功能,它把整个客户区填满成系统菜单图标了,改变某些参数的值,可以使得图标上下或左右颠倒
#include<windows.h> LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ); int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow // show state ) { static TCHAR szAppName[]=TEXT("leidemingzi"); HWND hwnd; MSG msg; WNDCLASS wndclass; wndclass.cbClsExtra=0; wndclass.cbWndExtra=0; wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.hCursor=LoadCursor(NULL,IDC_ARROW); wndclass.hIcon=LoadIcon(NULL,IDI_ERROR); wndclass.hInstance=hInstance; wndclass.lpfnWndProc=WindowProc; wndclass.lpszClassName=szAppName; wndclass.lpszMenuName=NULL; wndclass.style=CS_HREDRAW|CS_VREDRAW; if(!RegisterClass(&wndclass)) { MessageBox(NULL,TEXT("the program require the windows nt"),TEXT("tips"),MB_ICONERROR); return 0; } hwnd=CreateWindow( szAppName, // registered class name TEXT("this is title"), // window name WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // horizontal position of window CW_USEDEFAULT, // vertical position of window CW_USEDEFAULT, // window width CW_USEDEFAULT, // window height NULL, // handle to parent or owner window NULL, // menu handle or child identifier hInstance, // handle to application instance NULL // window-creation data ); ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ) { static int cxClient,cyClient,cxSource,cySource; HDC hdcClient,hdcWindow; PAINTSTRUCT ps; switch(uMsg) { case WM_CREATE: cxSource=GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXSIZE); cySource=GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYCAPTION); return 0; case WM_SIZE: cxClient=LOWORD(lParam); cyClient=HIWORD(lParam); case WM_PAINT: hdcClient=BeginPaint(hwnd,&ps); hdcWindow=GetWindowDC(hwnd); StretchBlt(hdcClient,0,0,cxClient,cyClient,hdcWindow,0,0,cxSource,cySource,MERGECOPY); ReleaseDC(hwnd,hdcWindow); EndPaint(hwnd,&ps); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd,uMsg,wParam,lParam); }