用 NetBeans 開發(fā)一個(gè)簡單的 Windows XP 程序 - 其二 |
Developing A simple Windows XP Application with NetBeans - Part 2 |
在項(xiàng)目節(jié)點(diǎn)上右鍵轉(zhuǎn)到“屬性 → C/C++ → C 編譯器”節(jié)點(diǎn),在“命令行”中設(shè)置“其他選項(xiàng)”為 -mwindows;再轉(zhuǎn)到“鏈接器 → 庫”,單擊“庫”右邊的省略號(hào)按鈕,接著單擊“添加選項(xiàng)”,設(shè)置“其他選項(xiàng)”為 -lcomctl32。 |
Right click the project node and go to "Properties → C/C++ → C Compiler" node, in "Command Line" set "Additonal Options" to -mwindows; then go to "Linker → Libraries", click the ellipsis button to the right of "Libraries", click "Add Option" and set "Other Option" to -lcomctl32. |
這時(shí)如果直接執(zhí)行“生成項(xiàng)目”,則會(huì)輸出以下錯(cuò)誤: |
If we directly execute "Build Project" right now, the following errors will be complained: |
- WinHello.c:6: error: `INITCOMMONCONTROLSEX' undeclared (first use in this function)
- WinHello.c:6: error: (Each undeclared identifier is reported only once
- WinHello.c:6: error: for each function it appears in.)
- WinHello.c:6: error: parse error before "init"
- WinHello.c:7: error: `init' undeclared (first use in this function)
- WinHello.c:8: error: `ICC_STANDARD_CLASSES' undeclared (first use in this function)
|
結(jié)構(gòu)體 INITCOMMONCONTROLSEX 在 commctrl.h 中聲明,commctrl.h 位于 mingw\include。打開這個(gè)頭文件,查找 INITCOMMONCONTROLSEX,發(fā)現(xiàn)它包含在一段預(yù)處理指令中: |
Constuct INITCOMMONCONTROLSEX is decleared in commctrl.h, which is inside mingw\include. Open this header file and search INITCOMMONCONTROLSEX, and the following segment of preprocessed commands will be found: |
- #if
(_WIN32_IE >= 0x0300)
typedef struct tagINITCOMMONCONTROLSEX {
DWORD dwSize;
DWORD dwICC;
} INITCOMMONCONTROLSEX,*LPINITCOMMONCONTROLSEX;
#endif
|
再查找 _WIN32_IE,找到: |
Then search _WIN32_IE and find: |
- #if
0
#define _WIN32_IE 0x0300
#endif
|
#if 0 表示在默認(rèn)情況下,永遠(yuǎn)不會(huì)定義 _WIN32_IE。注釋掉行 1 和行 3,再編譯,仍然出錯(cuò): |
#if 0 means _WIN32_IE would never be definded by default. Comment line 1 and line 3, compile and still gets errors: |
- WinHello.c:8: error: `ICC_STANDARD_CLASSES' undeclared (first use in this function)
- WinHello.c:8: error: (Each undeclared identifier is reported only once
- WinHello.c:8: error: for each function it appears in.)
|
像上面一樣去查找 ICC_STANDARD_CLASSES,這次要把 windef.h 中的 WINVER 改為 0x0501。我覺得不必?fù)?dān)心改了這些會(huì)帶來什么壞處。這些變量存在的意義是定義或不定義一些 API,以便為不同版本的 Windows 開發(fā)程序。如今 Windows Vista 已經(jīng)出來了,世界進(jìn)步很快,有新東西為什么不用呢? |
Search ICC_STANDARD_CLASSES as above, and this time modify WINVER in windef.h to 0x0501. I don't think it necessary to warry that these modifications do any thing bad. The purpose of the existance of these variables is to define some APLs or not, for the sake of developing applications for various versions of Windows. Windows Vista has been present, and the world is rapidly progressing, so why not use new things? |
現(xiàn)在編譯運(yùn)行,不會(huì)出錯(cuò)了,但風(fēng)格是 9x/2000 那種老土的,這是因?yàn)槟J(rèn)情況下 NetBeans 不知道如何編譯 rc 文件。解決這一問題的辦法是自定義一個(gè) Makefile。 |
Compile, run, and no error now, but the style is ugly as 9x/2000's, that's because by default NetBeans dosen't know how to compile rc files. The solution to this peoblem is to write a custom Makefile. |
好像差不多長了,下次繼續(xù)。 |
This seems long enough and is to be continued next time. |