接觸qt都挺多年了,今天開始打算把這幾年攢下的qt資源記錄下來,留個存檔吧。今天記錄的是windows下(只有win vista|win7支援)的玻璃磨砂效果封裝處理,記得最開始接觸這個效果的時候還是上學時期,當時只會mfc o__o "…
封裝類中使用到三個系統函式dwmiscompositionenabled、dwmenableblurbehindwindow、dwmextendframeintoclientarea,這三個系統函式度娘都有很多說明【可以參考這裡】,我這裡簡單說下:
dwmiscompositionenabled:判斷是否相容dwm模式,返回true,表示支援玻璃磨砂效果,否則為不支援;
dwmenableblurbehindwindow:開啟或關閉指定區域的玻璃磨砂效果;
dwmextendframeintoclientarea:視窗邊框向客戶區擴充套件的玻璃磨砂效果;
封裝類中使用動態載入方式來引用這3個系統庫dwmapi.dll,因為使用這個封裝類的程式可能要跑在xp系統中,而xp中是沒有dwmapi.dll這個系統庫的。
原始碼
qownaeroclass.h
#ifndef qownaeroclass_h
#define qownaeroclass_h
#include#include#include#ifndef dwm_bb_enable
//*****************用於xp下的結構定義************
#define dwm_bb_enable 0x00000001 // fenable has been specified
#define dwm_bb_blurregion 0x00000002 // hrgnblur has been specified
#define dwm_bb_transitiononmaximized 0x00000004 // ftransitiononmaximized has been specified
typedef struct _dwm_blurbehind
dwm_blurbehind, *pdwm_blurbehind;
#endif
typedef struct _margins
margins, *pmargins;
typedef hresult (winapi* mydwmiscompositionenabled)(bool *pbenable);
typedef hresult (winapi* mydwmextendframeintoclientarea)(hwnd hwnd,const margins *pmargins);
typedef hresult (winapi* mydwmenableblurbehindwindow)(hwnd hwnd,const dwm_blurbehind *pdwm_bulr);
class qownaeroclass
;public:
//返回是否具有透明效果
static bool iscompositionenabled();
//取消透明效果
static bool cancelaerostyle(hwnd hwnd);
//設定全域性透明效果
static bool setaerostyle(hwnd hwnd,bool bframe=true,int npadding = 6, qrect* pnewrect = null);
//獲取系統版本資訊
static systype getsysversion();
//dwm介面
static mydwmiscompositionenabled m_mydwmiscompositionenabledfun;
static mydwmextendframeintoclientarea m_mydwmextendframeintoclientareafun;
static mydwmenableblurbehindwindow m_mydwmenableblurbehindwindowfun;
//初始化dwm介面
static bool initdwmport();
//介面dll
static qlibrary m_dwnlib;
private:
};#endif // qownaeroclass_h
qownaeroclass.cpp
#include "qownaeroclass.h"
#include mydwmiscompositionenabled qownaeroclass::m_mydwmiscompositionenabledfun=null;
mydwmextendframeintoclientarea qownaeroclass::m_mydwmextendframeintoclientareafun=null;
mydwmenableblurbehindwindow qownaeroclass::m_mydwmenableblurbehindwindowfun=null;
qlibrary qownaeroclass::m_dwnlib;
qownaeroclass::qownaeroclass(void)
qownaeroclass::~qownaeroclass(void)
//初始化dwm介面,theme介面
bool qownaeroclass::initdwmport()
m_dwnlib.setfilename("dwmapi.dll");
if(!m_dwnlib.load())
return false;
m_mydwmiscompositionenabledfun = (mydwmiscompositionenabled)m_dwnlib.resolve("dwmiscompositionenabled");
m_mydwmextendframeintoclientareafun = (mydwmextendframeintoclientarea)m_dwnlib.resolve("dwmextendframeintoclientarea");
m_mydwmenableblurbehindwindowfun = (mydwmenableblurbehindwindow)m_dwnlib.resolve("dwmenableblurbehindwindow");
if(m_mydwmenableblurbehindwindowfun == null ||
m_mydwmextendframeintoclientareafun == null ||
m_mydwmiscompositionenabledfun == null)
return true;
}//返回是否具有透明效果
bool qownaeroclass::iscompositionenabled()
else
/*winrect.left += 6;
winrect.top += 6;
winrect.bottom -= 6;
winrect.right -= 6;*/
hrgn hrgn = ::createrectrgn(newrect.left,newrect.top,newrect.right,newrect.bottom);
blurbehind.hrgnblur = hrgn;
m_mydwmenableblurbehindwindowfun(hwnd,
&blurbehind);
} return true;
}//獲取系統版本資訊
qownaeroclass::systype qownaeroclass::getsysversion()
else if((version.dwmajorversion==5)&&(version.dwminorversion>0))
else if((version.dwmajorversion==6)&&(version.dwminorversion==0))
return vista;
else if((version.dwmajorversion>=6))
return win7;
} else if(version.dwplatformid==ver_platform_win32_windows)
if ((version.dwmajorversion == 4) && (version.dwminorversion >= 90) )
}return unknow;
}
android 毛玻璃效果實現
通過imageutils生成模糊bitmap.這個bitmap只能設定在imageview 上不能設定到其他布局的background屬性上。imageutils 來自 srcbitmp 要轉換的bitmap,radius 模糊半徑 0.25 recycle 是否 bitmap bitmapblur...
名片效果實現
模仿qq空間 微博等滑鼠懸浮在人名上時,顯示使用者詳細資訊 大體思路是將名片卡隱藏在頁面中,當懸浮時將名片卡移動到滑鼠邊,滑鼠移開時隱藏名片卡。本文的js使用了jquery 使用者名稱跟名片卡 如下 只是為了顯示類名,具體內容按需補充 使用者名稱 js 如下 var showmsgcardcontr...
抽屜效果實現
import viewcontroller.h define maxy 60 inte ce viewcontroller property nonatomic,weak uiview mainview property nonatomic,weak uiview leftview property...