折騰了很久終於弄明白如何在Eclipse CDT環境中編譯Windows編程所需的資源文件了。步驟如下:
1. 在project中加入資源文件resources.rc,然後鼠標右擊該文件,在彈出菜單中選擇“proterties”,如下圖所示:
2. 在對話框中找到"C/C++ Builder"->"Tool Chain Editor"頁面,在右下方的"Select tool"下拉框中選擇"Resource Compiler(rc)",如下圖所示:
3. 在settings頁面的Tool Settings頁籤,Command編輯框中輸入windres,如下圖所示:
4. 在settings頁面中,切換到Build Steps標籤頁,在Custom Build Step Applicapability下拉列表中選擇"Apply Custom Build step Overriding Other Tools";在Additional input file names編輯框中輸入資源文件名resources.rc,在Output file names編輯框中輸入resources.o,在Command編輯框中輸入"windres -O coff -i ..\resources.rc -o resources.o",如下圖所示:
5. 點擊"Apply and Close"按鈕。
6. 編譯project,會發現CDT執行了資源文件的編譯命令,並將編譯後的資源文件鏈接到了可執行文件中:
7. 運行編譯後的程序,可以看到resources.rc中的菜單出現在窗口中,程序圖標也出現在窗口的左上角: