Status Bar所提供的消息相當的詭異。Status Bar里面的Items的數量以及寬度要一次性設置好,每次修改的時候都要推翻重建一次,只不過里面的Text倒是可以單獨改掉。在XP底下有效的raise border似乎在Vista就沒有了。看來Vista已經從偽3D徹底轉向了2D了。
Status Bar在CreateWindowEx的時候會自動將自己放在窗口的最底下,每一次修改Status Bar的尺寸的時候,它又會自動把自己放在窗口的最底下。當然,你可以讓他出現在最上面。雖然如此,但是我封裝的時候還是想自由地修改尺寸和位置,當且僅當我想讓他出現在窗口最下面的時候他才出現在窗口最下面,于是我只好截獲Status Bar的WM_SIZE消息并扔掉了。
當初為每一個控件都自動Subclass掉的想法還真是正確啊……
下面是設置Item屬性的代碼,相當惡心啊。雖然我封裝的時候仍然給了additem、insertitem和deleteitem,但是卻不得不寫成這個樣子。下面這幾個是protected函數,專門用來刷新屬性的。
1 void VL_WinStatus::RefreshItem(VInt Index)
2 {
3 INT wParam=Index;
4 if(FItems[Index].Border)
5 {
6 if(FItems[Index].Raise)
7 {
8 wParam|=SBT_POPOUT;
9 }
10 }
11 else
12 {
13 wParam|=SBT_NOBORDERS;
14 }
15 VUnicodeString Text=FItems[Index].TextLeft+L'\t'+FItems[Index].TextCenter+L'\t'+FItems[Index].TextRight;
16 SendMessage(FHandle,SB_SETTEXT,wParam,(LPARAM)Text.Buffer());
17 }
18
19 void VL_WinStatus::RefreshItems()
20 {
21 INT Borders[3];
22 SendMessage(FHandle,SB_GETBORDERS,0,(LPARAM)Borders);
23 VInt w=Borders[0];
24 VInt h=Borders[1];
25 VInt s=Borders[2];
26 INT Rights[STATUS_BAR_MAX_ITEM_COUNT]={0};
27 VInt CurrentRight=w;
28 for(VInt i=0;i<FItems.GetCount();i++)
29 {
30 if(i==FItems.GetCount()-1 && FItems[i].Width==0)
31 {
32 Rights[i]=-1;
33 }
34 else
35 {
36 CurrentRight+=FItems[i].Width;
37 Rights[i]=CurrentRight;
38 CurrentRight+=s;
39 }
40 }
41 SendMessage(FHandle,SB_SETPARTS,FItems.GetCount(),(LPARAM)Rights);
42 for(VInt i=0;i<FItems.GetCount();i++)
43 {
44 RefreshItem(i);
45 }
46 }
posted on 2008-08-15 23:34
陳梓瀚(vczh) 閱讀(1546)
評論(1) 編輯 收藏 引用 所屬分類:
C++