码迷,mamicode.com
首页 > 其他好文 > 详细

gdi显示bmp文件

时间:2017-10-17 10:01:07      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:cti   logs   dcl   instance   amp   icon   idc   define   argc   

/*
 * 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文件

标签:cti   logs   dcl   instance   amp   icon   idc   define   argc   

原文地址:http://www.cnblogs.com/hatsusakana/p/7679877.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!