用 NetBeans 开发一个简单的 Windows XP 程序 - 其二 |
Developing A simple Windows XP Application with NetBeans - Part 2 |
在项目节点上右键转到“属性 → C/C++ → C 编译器”节点,在“命令行”中设置“其他选项”为 -mwindows;再转到“链接器 → 库”,单击“库”右边的省略号按钮,接着单击“添加选项”,设置“其他选项”为 -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. |
这时如果直接执行“生成项目”,则会输出以下错误: |
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)
|
结构体 INITCOMMONCONTROLSEX 在 commctrl.h 中声明,commctrl.h 位于 mingw\include。打开这个头文件,查找 INITCOMMONCONTROLSEX,发现它包含在一段预处理指令中: |
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 表示在默认情况下,永远不会定义 _WIN32_IE。注释掉行 1 和行 3,再编译,仍然出错: |
#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。我觉得不必担心改了这些会带来什么坏处。这些变量存在的意义是定义或不定义一些 API,以便为不同版本的 Windows 开发程序。如今 Windows Vista 已经出来了,世界进步很快,有新东西为什么不用呢? |
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? |
现在编译运行,不会出错了,但风格是 9x/2000 那种老土的,这是因为默认情况下 NetBeans 不知道如何编译 rc 文件。解决这一问题的办法是自定义一个 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. |
好像差不多长了,下次继续。 |
This seems long enough and is to be continued next time. |