1.在VC6中使用 GDI+:你得从网上弄个 GDI+ for XP 的库,把它解压后,将所有文件还包括子目录中的文件复制到你的项目目录。
在 stdafx.h中加入以下代码:
#define UNICODE
#ifndef ULONG_PTR
#define ULONG_PTR unsigned long*
#endif
#include "gdiplus.h" 请修改为你的头文件路径
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib") 请修改为你的.lib文件路径
我的项目名为Test,所以在TestApp中加入全局变量
ULONG_PTR gdiplusToken;
在 BOOL CTestApp::InitInstance()中加入这两行:
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
记住在线程退出后要御掉GDI+,它很占资源的,在 int CTestApp::ExitInstance() 中加入这行:
GdiplusShutdown(gdiplusToken);
2.在要贴的对话的OnPaint() 函数中加入以下代码:
例如:
void CDlgUserManagement::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
//建立图形对象
Graphics mGraphics( dc.GetSafeHdc() );
//装入图像文件
Image img( L"bk.jpg", TRUE );
//在指定区域pdestPoints显示图像 (根据背景大小按比例缩放)
CRect rcClient;
GetClientRect( &rcClient );
BOOL bWidth = rcClient.Width() / img.GetWidth() > rcClient.Height() / img.GetHeight();
// if ( bWidth )
// {
// mGraphics.DrawImage( &img, 0, 0, rcClient.Width(), rcClient.Width() * img.GetHeight() / img.GetWidth() );
// }
// else
// {
// mGraphics.DrawImage(&img, 0, 0, rcClient.Height() * img.GetWidth() / img.GetHeight(), rcClient.Height() );
// }//缩放
mGraphics.DrawImage(&img, 0, 0, img.GetWidth(), img.GetHeight());//原始大小
// Do not call CDialog::OnPaint() for painting messages
}
最后Rebuild All