Posted on 2007-11-25 20:47
蜀山兆孨龘 阅读(1064)
评论(0) 编辑 收藏
用 NetBeans 开发一个简单的 Windows XP 程序 - 其一 |
Developing A simple Windows XP Application with NetBeans - Part 1 |
首先创建一个名为 WinHello 的项目,在“源代码”节点下新建 WinHello.c,代码的内容如下: |
First create a project with the name WinHello, and then create a new WinHello.c under "Source Files" node with the following code: |
- #include <windows.h>
- #include <commctrl.h>
-
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- PSTR szCmdLine, int iCmdShow) {
- INITCOMMONCONTROLSEX init;
- init.dwSize = sizeof(init);
- init.dwICC = ICC_STANDARD_CLASSES;
- InitCommonControlsEx(&init);
- MessageBox(NULL, TEXT("再来!"), TEXT("哈哈~"), 0);
- return 0;
- }
|
注意末尾处最好再加上一个回车符,因为我们将用 MinGW GCC 来编译,遵循 UNIX 的规矩总是好的。行 6~9 指明用 Windows XP 风格初始化程序,但这还不够,我们还需要一个资源脚本和一个清单文件来显示调用 Comctl32.dll 版本 6(默认状态下自动调用版本 5,也就是 Windows 9x/2000 风格)。在“资源文件”节点下新建资源脚本 resource.rc 和清单文件 WinHello.exe.manifest。resource.rc 的内容如下: |
Attention it's best to add a CR in the end, because we'll compile it with MinGW GCC, so it's always good to follow the UNIX conventions. Line 6~9 indicates Windows XP style will be used to initialize the application, but that's not enough. We still need a resource script and a manifest file to explicitly invoke Comctl32.dll version 6 (version 5 is automatically invoked by default which is Windows 9x/2000 style). Create a new resource script resource.rc and a manifest file WinHello.exe.manifest. The content of resource.rc is as below: |
- #include <windows.h>
-
- CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "Winhello.exe.manifest"
|
WinHello.exe.manifest 的内容如下: |
The content of WinHello.exe.manifest is as below: |
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
- <assemblyIdentity
- version="1.0.0.0"
- processorArchitecture="X86"
- name="zhyi.zhyi.Winhello"
- type="win32"
- />
- <description>Description.</description>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity
- type="win32"
- name="Microsoft.Windows.Common-Controls"
- version="6.0.0.0"
- processorArchitecture="X86"
- publicKeyToken="6595b64144ccf1df"
- language="*"
- />
- </dependentAssembly>
- </dependency>
- </assembly>
|
到现在为止,所有的源文件都准备好了,接下来是编译。为避免一篇文章过长,且看下回分解。 |
By now all source files are ready, and next job is compiling. For avoiding a too long article, please read the next part. |