WTL學習筆記 5 系統面板管理

2021-09-07 23:31:11 字數 3778 閱讀 2393

概念:每個控制項都有part和state的概念,這個同在wpf和silverlight的visual state的概念是相同的。只不過silverlight可以手寫xaml,而傳統win32只能函式獲採樣式

如checkbox的狀態,作業系統其實定義了多個狀態的,根據狀態不同進行切換而已

每個控制項都有自己的**特性,如上checkbox各種狀態的樣式,可借助drawthemebackground等方法將控制項部分狀態樣式輸出

wtl的ctheme和cthemeimpl對內建的win32相關的theme函式進行了封裝

ctheme屬於原生封裝,cthemeimpl則是進行了加工.使用起來更加方便.

如金山開源控制項庫中,雖然重繪了button等控制項,但並非全部控制項重新定義.如radiobutton和checkbox就可以使用內建的控制項樣式.為了不使用內建的建立方法建立這些控制項,那麼就可以基於自己的架構之上,再結合theme相關函式繪製需要的控制項.

1.cbkwintheme的封裝

該類是金山衛士下的乙個檔案bkwin\bktheme.h

其功能同wtl的ctheme,對區域性的幾個重要的函式進行了輕量封裝

需要注意的是使用uxtheme.dll,是以載入dll的方式來進行的,最常用的方法莫過於drawthemebackground

//

// class name: bktheme

// description: windows theme(xp later)

// creator: zhangxiaoxuan

// version: 2009.5.12 - 1.0 - create

//#pragma once

#include

#include

#include

class

bkwinthemefunc

static

bool isvalid()

static

htheme openthemedata(hwnd hwnd, lpcwstr pszclasslist)

else

return

null;

}static

hresult closethemedata(htheme htheme)

else

return

e_notimpl;

}static

hresult drawthemebackground(htheme htheme, hdc hdc, int

ipartid, int

istateid, const

rect *prect, optional

const

rect *pcliprect)

else

return

e_notimpl;

}static

else

return

e_notimpl;

}enum

;static

lpcwstr themename(int

nid)

;static int

namescount = sizeof(names) / sizeof(lpcwstr) - 1;

if (nid >= 0 && nid

< namescount)

return

names[bkthemenamebutton];

else

return

null;

}private:

bool m_bthemevalid;

fnopenthemedata m_pfnopenthemedata;

fnclosethemedata m_pfnclosethemedata;

fndrawthemebackground m_pfndrawthemebackground;

fnsetwindowtheme m_pfnsetwindowtheme;

static

bkwinthemefunc* ms_pinstance;

static

bkwinthemefunc* _instance()

// static bkwinthemefunc& _instance()

//

};__declspec(selectany) bkwinthemefunc* bkwinthemefunc::ms_pinstance = null;

template

t_nthemeid, int

t_partid>

class

cbkwintheme

~cbkwintheme()

bool isvalid()

bool opentheme(hwnd hwnd)

void

drawbackground(hdc hdc, int

istateid, const

rect *prect)

protected:

htheme m_htheme;

};typedef

cbkwintheme

<:bkthemenamebutton bp_checkbox> cbkcheckboxtheme;

typedef

cbkwintheme

<:bkthemenamebutton bp_radiobutton> cbkradioboxtheme;

2.checkbox和radiobox的實現

cbkwindow 之前有講到過,這裡只貼相關onpaint方法,請先忽略其他,只注意theme的drawbackground方法,剛好可以用到此處.

class 

cbkcheckbox : public

cbkwindow

void

onpaint(cdchandle dc)

else

m_rcwindow.left += checkboxsize + checkboxspacing;

m_style.m_ntextalign &= ~dt_bottom;

m_style.m_ntextalign |= dt_vcenter;

__super::onpaint(dc);

m_rcwindow.left -= checkboxsize + checkboxspacing;

}protected:

cbkcheckboxtheme m_theme;

};

class 

cbkradiobox : public

cbkwindow

virtual

bool load(tixmlelement* ptixmlelem)

void

onpaint(cdchandle dc)

else

__super::onpaint(dc);

}protected:

cbkradioboxtheme m_theme;

};

這也算是一種辦法,如果只想建立部分控制項樣式又想利用原有的控制項樣式的話,可以利用此法,記錄一

WTL 學習筆記 幾則技巧

wtl 學習筆記 幾則技巧 l 在wtl專案中插入atl控制項。有點不明白,wtl本身就是擴充套件atl,但wtl嚮導產生的工程,竟不能使用atl控制項。還得手工加一些東西來欺騙vs6,vs6才讓插入atl控制項。1.在工程增加乙個atl.idl檔案,並排除在編譯之外。library atl 2.在...

WTL學習筆記 4 控制項加強

1.chyperlink 擴充套件了static text控制項 url超連結 2.cchecklistviewctrlimpl 乙個以checkbox為元素的listview控制項 3.cwaitcursor ccustomwaitcursor 建構函式中載入等待的圖示,析構函式中還原,省去了手動...

寶塔面板配置管理筆記

wget o install.sh sudo bash install.sh 1,mysql5.7最好記憶體2g以上 1,要在目錄加乙個public目錄 2,解鎖public下 user.ini許可權 chattr i user.ini 修改執行目錄許可權 sudo vim user.ini 3,也...