GDI+实现半透明渐变的特效窗口2008-07-18 10:34:43 来源:中国自学编程网 作者:佚名 点击:
偶然间甜石榴兄弟给我一个东东,是BlueCrab用VC写的利用GDI+技术实现半透明渐变窗口的特效,看起来很不错。在此对BlueCrab和甜石榴深表感谢。ccrun(老妖)花了点时间将其在BCB中实现,并实现了简单的动态换肤 ![]() 偶然间甜石榴兄弟给我一个东东,是BlueCrab用VC写的利用GDI+技术实现半透明渐变窗口的特效,看起来很不错。在此对BlueCrab和甜石榴深表感谢。ccrun(老妖)花了点时间将其在BCB中实现,并实现了简单的动态换肤。效果图:
在C++Builder中使用GDI+的方法和代码网上遍地都是,这里为了完整性,简单说说流程: 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 using std::min; using std::max; #include "gdiplus.h" using namespace Gdiplus; 完整示例代码在这里下载(查看页面)http://www.ccrun.com/src/v.asp?id=36 .h文件中:private: //Userdeclarations ULONG_PTRm_GdiplusToken; Gdiplus::GdiplusStartupInputm_GdiplusStartupInput; int__fastcallSetTransparent(LPWSTRlpSKINFile,intnTran); BLENDFUNCTIONm_Blend; HDC m_hdcMemory; Gdiplus::Image*m_Image; public: //Userdeclarations __fastcallTfrmMain(TComponent*Owner); __fastcall~TfrmMain(void); .cpp文件中: //--------------------------------------------------------------------------- //用GDI+实现半透明渐变的特效窗口 //byccrun(老妖)-info@ccrun.com //--------------------------------------------------------------------------- //WelcomeC++BuilderStudy-http://www.ccrun.com //--------------------------------------------------------------------------- #include #pragmahdrstop #include"uMain.h" //--------------------------------------------------------------------------- #pragmapackage(smart_init) #pragmaresource"*.dfm" TfrmMain*frmMain; //--------------------------------------------------------------------------- __fastcallTfrmMain::TfrmMain(TComponent*Owner) :TForm(Owner) { BorderStyle=bsNone; //initGDI+ GdiplusStartup(&m_GdiplusToken,&m_GdiplusStartupInput,NULL); // m_Blend.BlendOp=0; //theonlyBlendOpdefinedinWindows2000 m_Blend.BlendFlags=0; //nothingelseisspecial... m_Blend.AlphaFormat=1; //... m_Blend.SourceConstantAlpha=255;//AC_SRC_ALPHA // if(FileExists(ExtractFilePath(ParamStr(0))+"\\test.png")) SetTransparent(WideString("test.png"),100); //Stayontop SetWindowPos(Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVESWP_NOSIZE); } //--------------------------------------------------------------------------- __fastcallTfrmMain::~TfrmMain(void) { GdiplusShutdown(m_GdiplusToken);//CloseGDI+ } //--------------------------------------------------------------------------- int__fastcallTfrmMain::SetTransparent(LPWSTRlpSkinFile,intnTran)
|