1.) 在BCB6中已自带了ghiplus.h文件,故只需要生成gdiplus.lib文件就可以:
在命令行下运行implib gdiplus.lib gdiplus.dll。(如果ghiplus.dll不在当前文件夹下,注意写完整路径)
2.) 在工程的编译选项中加入STRICT条件编译:
Project-->Options-->Directories/Conditionals-->Condtionals-->点击旁边的\"...\"按钮-->输入STRICT,然后Add。
3.) 在工程中加入Gdiplus.lib:
Project-->Add To Project-->找到Gdiplus.lib添加进来。
4.) 在工程的.h文件中包含所需的头文件,注意先后顺序:
#include \"math.hpp\"
#include <algorithm>
using std::min;
using std::max;
#include \"gdiplus.h\"
using namespace Gdiplus;
完整示例代码在这里下载(查看页面)http://www.ccrun.com/src/v.asp?id=36
.h文件中:
private: // User declarations
ULONG_PTR m_GdiplusToken;
Gdiplus::GdiplusStartupInput m_GdiplusStartupInput;
int __fastcall SetTransparent(LPWSTR lpSkinFile, int nTran);
BLENDFUNCTION m_Blend;
HDC m_hdcMemory;
Gdiplus::Image *m_Image;
public: // User declarations
__fastcall TfrmMain(TComponent* Owner);
__fastcall ~TfrmMain(void);
.cpp文件中:
//---------------------------------------------------------------------------
// 用GDI+实现半透明渐变的特效窗口
// by ccrun(老妖) - [email protected]
//---------------------------------------------------------------------------
// Welcome C++Builder Study - http://www.ccrun.com
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include \"uMain.h\"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource \"*.dfm\"
TfrmMain *frmMain;
//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
: TForm(Owner)
{
BorderStyle = bsNone;[Page]
// init GDI+
GdiplusStartup(&m_GdiplusToken, &m_GdiplusStartupInput, NULL);
//
m_Blend.BlendOp = 0; // the only BlendOp defined in Windows 2000
m_Blend.BlendFlags = 0; // nothing else is special ...
m_Blend.AlphaFormat = 1; // ...
))
SetTransparent(WideString(\"test.png\"), 100);
// Stay on top
SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
//---------------------------------------------------------------------------
__fastcall TfrmMain::~TfrmMain(void)
{
GdiplusShutdown(m_GdiplusToken);