gdi顯示bmp文件
阿新 • • 發佈:2017-10-17
eat cpp src instance llb reat itme [] title
/* * gdi顯示bmp文件 */ #include "windows.h" #include "stdio.h" #define CLASSNAME "GDI_BMPPLAYER" #define TITLENAME "GDI_BMPPLAYER" LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) { switch(message) { case WM_DESTROY: { PostQuitMessage(0); return 0; }break; } return DefWindowProc(hwnd,message,wParam,lParam); } int main(int argc,char *argv[]) { if(argc != 2) { printf("gdi_bmpplayer.exe [bmpfile]\n"); return -1; } WNDCLASS wndclass; wndclass.style=CS_HREDRAW|CS_VREDRAW; wndclass.lpfnWndProc=WndProc; wndclass.cbClsExtra=0; wndclass.cbWndExtra=0; wndclass.hInstance=NULL; wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION); wndclass.hCursor=LoadCursor(NULL,IDC_ARROW); wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName=NULL; wndclass.lpszClassName=CLASSNAME; if(!RegisterClass(&wndclass)) { return FALSE; } HWND hwnd = CreateWindow(CLASSNAME,TITLENAME,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT, 800,600,NULL,NULL,NULL,NULL); ShowWindow(hwnd,SW_SHOW); UpdateWindow(hwnd); HDC hdcBuf = CreateCompatibleDC(NULL); HBITMAP hBitmap = (HBITMAP)LoadImage(NULL,argv[1], IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION); BITMAP bitmap; GetObject(hBitmap,sizeof(bitmap),&bitmap); SelectObject(hdcBuf, hBitmap); MSG msg;GetMessage(&msg,NULL,0,0); while(msg.message != WM_QUIT) { if(PeekMessage( &msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { HDC hdc = GetDC(hwnd); BitBlt(hdc, 0, 0, bitmap.bmWidth,bitmap.bmHeight, hdcBuf, 0, 0, SRCCOPY); ReleaseDC(hwnd,hdc); } } DeleteObject(hBitmap); DeleteDC(hdcBuf); return msg.wParam; }
gdi顯示bmp文件