這兩天為解決PPC Today界面的顯示問題著實費了不少腦筋。主要有三個問題:
1. 點擊條目后高亮顯示,點擊其他條目后取消高亮顯示問題。
2. 按上下鍵選擇條目后,條目不高亮顯示的問題。
3. 由于Today界面中的條目字體大小是按照系統設置的,是可變的,因此就遇到一個獲取系統字體大小的問題。
前兩個問題的高亮顯示,是依靠標志位來繪制的,獲取到條目被選中后,就置標志位為TRUE,否則置為FALSE,然后會進行重繪。重繪時,依靠標志位來判斷是否需要高亮繪制條目。獲取條目的顏色使用的是TODAYM_GETCOLOR消息,通過發送這個消息,可以獲取條目的普通和高亮的顏色。
關于按上下鍵選擇。MSDN Online上說,會觸發WM_TODAYCUSTOM_USERNAVIGATION事件。但是,我在做時,并沒有觸發該事件。后來發現,該事件的觸發條件與TODAYLISTITEM中的dwSelectability設置有關,具體可參照
http://www.codeguru.com/cpp/w-p/ce/pocketpc/article.php/c9269__1/。具體做法是在WM_TODAYCUSTOM_QUERYREFRESHCACHE事件中截獲TODAYLISTITEM結構體,并將其中的dwSelectability設置為2。TODAYLISTITEM的參數意義見下表:
Value Name and Type |
Description |
DWORD: Type |
Custom Items must have Type = 4 |
DWORD: Enabled |
0 or 1; 1 causes Today panel to show your component; nevertheless, the user can control it via the Today applet in the Control Panel |
DWORD: Options |
if equals 1, the "Options" button in the Today applet will be enabled |
SZ: DLL |
Pull path to your component |
DWORD : Selectability |
New feature in Win Mobile 2003 SE; allows receiving additional notifications Values are used as follows:
- 0 or does not exist—component cannot be selected at all
- 1—selections are manages automatically. In other words, your component will receive messages like WM_LBUTTONXXX
- 2—the Today screen will send notification messages to your component when the user sets/releases focus or presses navigation keys
|
對于上下鍵選擇,需要注意的是,處理完WM_TODAYCUSTOM_USERNAVIGATION事件后,需要返回FALSE,以使系統進行其他操作,否則,再按上下鍵就不會上下移動。
關于字體大小的設置,處理源代碼如下:
1
LOGFONT lf;
2
memset(&lf,0,sizeof(LOGFONT));
3
int iFontSizePixel;
4
SHGetUIMetrics(SHUIM_FONTSIZE_PIXEL,&iFontSizePixel, sizeof(iFontSizePixel), NULL);
5
lf.lfHeight = -iFontSizePixel;
6
HFONT hNewFont = CreateFontIndirect(&lf);
7
HGDIOBJ hOldFont = SelectObject(hdc, hNewFont);
8
9
DrawText(hdc , theApp.m_strBarText , theApp.m_strBarText.GetLength() ,
10
&rect , DT_VCENTER | DT_LEFT | DT_INTERNAL);
Selectability參數被設置為2后,需要處理WM_TODAYCUSTOM_ACTION消息,來啟動程序。