2013-04-14 21 views
1

我對在Windows對話框中出現UI元素(如按鈕)的因素有些困惑。我的混淆似乎出於以下意見:什麼因素控制對話框按鈕的外觀?

1-我在我的系統上安裝了visual studio 2010,當我創建一個MFC對話框時,.rc上的按鈕具有複雜的外觀,稍微圓角等等,當我構建MFC應用程序相同的外觀出現在生成的exe中。 vs 2010 project on win7

2-現在我得到一個在VC 6中開發的應用程序,將其轉換爲新的vs 2010項目。當我打開rc文件上面

rc file of the converted project

所描述的UI外觀是相同的,但是當我建立並運行應用程序,按鈕的UI外觀是舊的,單純的。 look in the running exe of the converted project

3我在舊代碼中包含了InitcommonControlEx(),並且沒有改變任何內容。也許它與此無關。

我的問題是什麼在控制ui元素的外觀?它是否與清單文件有關,它指示應用程序應使用哪個版本的Windows庫?

如果是這樣,我如何更新舊項目的清單文件,以便獲得新的UI外觀?

回答

1

在VS2010中,使用New Project嚮導創建一個MFC對話框應用程序(實際上任何MFC應用程序都可以)。爲所有選項選擇默認值並讓嚮導生成代碼。

當它這樣做,看文件stdafx.h和複製/粘貼以下塊到您的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 

您也可以通過項目/屬性做到這一點,但在代碼中做它,它贏得如果你與其他項目分享源代碼,那就不會中斷。

注意,書中有一個#ifdef _UNICODE,因爲共同控制的少數爲Unicode版本才能正常工作。但是,如果你需要和非UNICODE構建和僅使用「標準」 Windows控件(例如,沒有列表視圖或樹視圖等),這是確定刪除#ifdef

1

你說得對。你需要嵌入一個清單文件。

proper通過Properties-> Linker-> Manifest File-> Generate Manifest將清單嵌入MFC應用程序的方式。要啓用XP主題只使用在Additional Manifest Dependencies領域以下內容:

type='Win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df' language='*' 
1

如果您不想刪除的#ifdef _UNICODE聲明,你可以複製行

#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 

,並將其放置在你的stdafx.h文件的末尾。這確實EXACTLY了同樣的事情由上面的「茶」,推薦的步驟,但以更少的步驟。