我有一個以前的用vc6開發的小示例,移植到vs2005上去,今天突然發現了一個小問題:直接使用vs2005生成的項目編譯后工具欄的風格是xp風格(圖1),而移植上去的項目工具欄風格卻是2k風格(圖2)。

(圖1)

(圖2)
當然我很清楚,這是manifest導致的問題,于是自然在vs2005直接生產的項目里去尋找manifest文件,結果沒發現,轉至項目目錄下也沒有發現。感覺很是奇怪,于是我全項目搜索“manifest”,發現stdafx.h里有如下代碼:
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_IA64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
記得在vs2003里面是默認生成一個manifest,不同項目里面的manifest內容大同小異。而在vs2005里面是通過一個擴展的#pragma comment指令來生成manifest,該指令在vs2003中是無效的。編譯器內部具體采用什么手段就不得而知,也無暇細究,不過大概思想就是強制使用高版本的common control達到漂亮的顯示效果。我在c6轉到vs2005的工程對應位置加上后,即達到了圖1的效果,包括所有的common控件都切換到了xp風格。
這里注意幾點:
1、必須使用unicode編譯,否則無法達到效果。vs2005默認生產的項目是基于unicode編譯的。至于網上所說的手動添加manifest文件的方法我沒有試驗過。
2、上面的#pragma comment指令只在vs2005中有效,在vs2003里面必須手動把編譯字節碼改為unicode才可使common控件變為xp風格。
3、common控件的xp風格最終還是取決于操作系統還有就是當前的顯示主題,在2k的機器上是無法顯示出xp風格的,在xp以上的機器上如果選擇2k經典主題還是無法顯示出xp風格。
posted on 2007-02-28 19:36
萬連文 閱讀(3206)
評論(0) 編輯 收藏 引用 所屬分類:
亂七八糟