/* * Author: Leng_que * Date: 2010-4-24 21:40:45 * E-mail: leng_que@yahoo.com.cn * Description: The sample program only tell someone how to show a bitmap to desktop center. */ #include <afxwin.h> #pragma comment(lib, "LIBCMT.LIB") #pragma comment(linker, "/subsystem:windows /NODEFAULTLIB:libc.lib") int ShowPicToDesktop(char *pszPicName) { HBITMAP hBmp = (HBITMAP)LoadImage(NULL, pszPicName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); HDC hDesktopDC = GetDC(NULL); HDC hMemDC = CreateCompatibleDC(hDesktopDC); SelectObject(hMemDC, hBmp); BITMAP bmpInfo; CBitmap* cBmp = CBitmap::FromHandle(hBmp); cBmp->GetBitmap(&bmpInfo); int iFullWidth = GetSystemMetrics(SM_CXSCREEN); int iFullHeight = GetSystemMetrics(SM_CYSCREEN); int iBmpWidth = bmpInfo.bmWidth; int iBmpHeight = bmpInfo.bmHeight; int iX = (iFullWidth-iBmpWidth)/2; int iY = (iFullHeight-iBmpHeight)/2; BitBlt(hDesktopDC, iX, iY, iBmpWidth, iBmpHeight, hMemDC, 0, 0, SRCCOPY); ReleaseDC(NULL, hMemDC); ReleaseDC(NULL, hDesktopDC); DeleteObject(hBmp); return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { ShowPicToDesktop(".//Demo.bmp"); return 0; }