Google

星期三, 十月 29, 2008

VIDE

VIDE is the V Integrated Development Environment for the GNU g++ compiler and the standard Sun Java Development Kit. The current release is Version 2.00 for MS-Windows and Linux (RedHat 6.x, 7.x, 8.x; Mandrake 8.x; others).
http://www.objectcentral.com/objectcentral/vide.htm

标签: , , , , ,

Quincy

Quincy is freeware open-source. It is a simple programming environment for C/C++ on Windows. It contains an editor, a compiler, a debugger, and graphics and GUI toolkits.

Because of it's simple interface, Quincy is ideal for learning C or C++ programming.

With integrated support for FLTK and the FLUID GUI builder, Quincy is also a rapid application development (RAD) tool for Windows GUI programs.

http://www.codecutter.net/tools/quincy/

标签: , , ,

Anjuta IDE

Anjuta is a versatile Integrated Development Environment (IDE) for C and C++ on GNU/Linux. It has been written for GTK/GNOME and features a number of advanced programming facilities. These include project management, application wizards, an on-board interactive debugger, and a powerful source editor with source browsing and syntax highlighting.

Anjuta is an effort to marry the flexibility and power of text-based command-line tools with the ease-of-use of the GNOME graphical user interface. That is why it has been made as user-friendly as possible.

Any sort of suggestions or patches for Anjuta are also most welcome.

Remember, this program is under the license of the GPL.
Please read the file COPYING that comes with the distribution for details.
Help wanted!

* Software Developers [New Code, Fixes, etc...]
* Editors [Manuals, Articles]
* Artists [Icons, images, splash]

Please go to the mailing list section to join or subscribe to the development mailing list to start contributing.

http://www.anjuta.org/

标签: ,

BVRDE - 远程C++开发环境

BVRDE is an Integrated Development Environment (IDE) for C and C++. It is designed to make cross-platform development easy. Its features include project management, application wizards, an integrated interactive debugger, and a powerful source editor with source browsing and syntax highlighting.

The goal of this tool is to allow a developer to compile and debug applications entirely on a remote computer, while editing and issuing compile and debug commands through a local interface. BVRDE supports a variety of network protocols to allow connectivity with various remote systems. This includes FTP and secure & encrypted protocols such as SSH and SFTP.

http://bvrde.sourceforge.net/

标签: , , , , ,

星期四, 九月 11, 2008

OTcl - Object Tcl Extensions

The CMT project has adopted OTcl as the base for the CMT Media Playback API, but unfortunately found MIT Version 0.96 to be lacking a couple of needed features, as well as not being compatible with Tcl/Tk 8.0. We are therefore including our modified version of OTcl with CMT 4.0.

What is OTcl?

OTcl, short for MIT Object Tcl, is an extension to Tcl/Tk for object-oriented programming. It shouldn't be confused with the IXI Object Tcl extension by Dean Sheenan. Some of OTcl's features as compared to alternatives are:

  • designed to be dynamically extensible, like Tcl, from the ground up
  • builds on Tcl syntax and concepts rather than importing another language
  • compact yet powerful object programming system (draws on CLOS, Smalltalk, and Self)
  • fairly portable implementation (2000 lines of C, without core hacks)

For documentation about objects, classes, and their capabilities, see the following reference pages:

标签: , ,

星期一, 八月 25, 2008

孟岩《来自巴西的Lua语言新星让我脸红》及网友评论

一种自由软件的脚本语言 Lua ,由于在游戏界日益成为主流脚本语言(得到著名的卢卡斯艺术公司两款游戏采用,并在GameDev.net的调查中高居脚本语言榜首),最近引起了业界的广泛关注。
Lua (葡萄牙语,义为月亮)是一种轻量级的强大的扩展语言,用纯ANSI C编写,最初版本只有6000行代码,却实现了垃圾收集、反射、面向对象等机制。Lua 是由巴西里约热内卢天主教大学计算机系的Roberto Ierusalimschy 等人于1993年开发的。
最近,Roberto Ierusalimschy 撰写的《Programming in Lua》一书也已经出版
---tangl_99

Python是荷兰人写的,Ruby是日本人写的,Lua是巴西人写的,我这个中国人只能在这里脸红。
---孟岩

不必人人制轮胎,难道你不想躺在轮胎做的吊床上休息?
---牡蛎

只选对的,不选贵的。
---路人甲

转载自tangl_99的blog孟岩的blog

Python是荷兰人写的,Ruby是日本人写的,Lua是巴西人写的,我这个中国人只能在这里脸红。
Lua是所有动态语言中间平均效率最高的一个。它最初是以Library的形式存在,纯粹只是用作C/C++的一个扩展。现在不仅发展出了解释器,还发展 出了编译器。游戏开发里Lua是使用最广泛的脚本语言。当世界上第一本Lua图书上市销售的时候,一位读者评价道:"Lua is a real gem."
(牡蛎到没有听过Lua、Python或者Ruby的编译器——.NET的冒牌货除外)

Lua很棒,Lua是巴西人发明的,这些都令我不爽,但是还不至于脸红,最多眼红。
让我脸红的是Lua的源代码,百分之一百的ANSI C,一点都不掺杂。在任何支持ANSI C编译器的平台上都可以轻松编译通过。我试过,真是一点废话都没有。
我1996年就学会了C,1997年就跑去研究Win32 API,后来是C++,STL,Java... 直到2002年看到C Interfaces and Implementations,才知道仅仅用ANSI C就可以实现一个强大的优美的library,直到2004年看到Lua的源代码才知道仅仅用ANSI C就可以实现一个非常快的虚拟机、非常棒的解释器/编译器和非常漂亮的语言实现。
这8年我都干什么去了?
---孟岩

http://www.chinaitpower.com/2005September/2005-09-13/204728.html

标签: , , , , , , ,

星期三, 五月 14, 2008

;)

C/C++还是最棒的

Object Pascal也不错,至少目前Free Pascal的发展比Delphi的命运好像好一点

Python易学易用,语法太灵活了,缩进还是没有;号爽

UML 2.0还没有达到易用,易懂的程度,也许以后描述问题不用它了吧

PHP做网站很不错,CodeIgniter框架也不错,就是对XHTML的支持,特别是UTF-8的支持不是很理想。

标签: , , , , , , ,

星期日, 五月 04, 2008

Lua入门

Lua是一个被设计成用于扩展C/C++编程的轻量级脚本语言。不幸的是,网上很少有关于这个语言的在线教程。我主要通过阅读其源代码来了解它是怎样工作并且通过一些发布的程序学习它。希望,通过下面的教程,会让学习Lua更加简单。

本教程涵盖了Lua5.1。在Lua的每一个版本中都有一些非常不同之处。下面的示例代码将不能在老版本的Lua下运行。如果你仍然在使用老版本而且不愿意升级,不用担心,我已经在文章底部提供了4.0和5.0教程的源代码下载连接。好了,让我们开始吧!

首先,你需要下载Lua。你需要从Lua下载页面去下载源代码。如果你需要编译好了的二进制库,你能在LuaBinaries 中找到你想要的库(lib or dll)。

现在,我们需要安装Lua。在Linux下,你应该先解压文件,然后以root 用户在命令行键入"make linux"和"make linux install"。如果你需要帮助,请参考源代码文件夹中的INSTALL文件。现在,我下载了windows平台下的二进制库包并把它们解压到"C:\ Program Files\lua5.1"。

在Linux下不需要我们做任何设置,但是在windows平台下我们必须配置Visual C++,以便让编译器和连接器找到Lua文件。

  1. 打开Visual C++,选择Tools菜单中的选项菜单。
  2. 展开"项目",并选择"VC++ 目录"。
  3. 选择"包含文件",添加一个新路径"C:\Program Files\lua5.1\include"。
  4. 在选择"库文家",添加路径"C:\Program Files\lua5.1\lib\dll"(这里假设你下载的库为dll,你也可以下载静态链接库)。
  5. 确定。

现在你可以开始编译你的第一个Lua应用了。

使用Lua开始你的第一个程序

这个程序简短且直接,下面做一点说明:

  1. lua_open()返回一个指向Lua解释器的一个指针。
  2. luaL_openlibs()用于装载Lua库,它提供了一些简单的函数,如:print。
  3. 通过调用luaL_dofile()执行脚本。它的作用是读取并解释脚本。
  4. 最后,通过lua_close()函数关闭Lua。

保存文件为luatest.cpp。如果你直接使用C而不是C++,将文件名改为luatest.c,然后将extern "C"删除。

#include 
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
/* Lua解释器指针 */
lua_State* L;
int main ( int argc, char *argv[] )
{
/* 初始化Lua */
L = lua_open();
/* 载入Lua基本库 */
luaL_openlibs(L);
/* 运行脚本 */
luaL_dofile(L, "test.lua");
/* 清除Lua */
lua_close(L);
/* 暂停 */
printf( "Press enter to exit…" );
getchar();
return 0;
}

下面是test.lua的内容。

-- simple test
print "Hello, World!"

编译

在Linux下,在命令行键入:

g++ luatest.cpp -llua -ldl -o luatest

然后,键入下列命令运行:

./luatest

如果没有问题,程序将在终端输出Hello, World!

在Visual C++你将需要进行下列步骤:

  1. 创建一个新的空Win32控制台应用工程。
  2. 将"luatest.cpp"加入你的工程。
  3. 选择项目菜单中的属性菜单。
  4. 在"连接器"的"输入"栏目的"附加依赖项"中输入"lua5.1.lib"。
  5. 确定。

此时,按F7构建程序。

如果你采用的是dll库,请确保将其放在应用程序的目录中或者windows系统能够找到它的地方。如果你采用的是静态连接库,则不需要。 (Groov0V翻译,转载自CSDN)

谢谢这么简洁清晰的表述
g++ luatest.cpp `pkg-config lua5.1 --libs --cflags` -o luates

http://www.wujianrong.com/archives/2007/10/lua.html

标签: ,

Flex

Overview of Flex

Flex is a tool for generating scanners. A scanner, sometimes called a tokenizer, is a program which recognizes lexical patterns in text. The flex program reads user-specified input files, or its standard input if no file names are given, for a description of a scanner to generate. The description is in the form of pairs of regular expressions and C code, called rules. Flex generates a C source file named, "lex.yy.c", which defines the function yylex(). The file "lex.yy.c" can be compiled and linked to produce an executable. When the executable is run, it analyzes its input for occurrences of text matching the regular expressions for each rule. Whenever it finds a match, it executes the corresponding C code.

http://flex.sourceforge.net/

标签: , ,

星期二, 四月 08, 2008

Introduction to wxWidgets

Introduction

wxWidgets formerly known as wxWindows is a framework for developing cross-platform GUI applications in C++. Julian Smart started the framework in 1992 at the Artificial Intelligence Applications Institute, University of Edinburgh. In 1995, a port to Xt was released by Markus Holzem. In May 1997, the Windows and the GTK+ ports were merged and put into a CVS repository.

What is wxWidgets

wxWidgets gives you a single, easy-to-use API for writing GUI applications on multiple platforms. Link it with the appropriate library for your platform (Windows/Unix/Mac) and compiler (almost any popular C++ compiler), and your application will adopt the look and feel appropriate to that platform. On top of the great GUI functionality, wxWindows gives you: online help, network programming, streams, clipboard and drag and drop, multithreading, image loading and saving in a variety of popular formats, database support, HTML viewing and printing, and much more.

Who should use wxWidgets

wxWidgets is a framework very much similar to MFC, except for a few negative points of its own. Those MFC programmers who are aware of the growing number of Linux users and who want to write cross platform GUI applications can use wxWidgets. With wxWidgets, it is very easy to use a framework based on C++ and it has a proven record of 13 years. In fact, wxWidgets is very stable and is supported on:

  • Windows 3.1, Windows 95/98, Windows NT, Windows 2000/XP, Windows ME, Windows CE.
  • Linux and other UNIX platforms with GTK+.
  • UNIX with Motif or the free Motif clone Lesstif.
  • Mac OS.
  • Embedded platforms are being investigated. See the wxUniversal project.
  • An OS/2 port is in progress, and you can also compile wxWidgets for GTK+ or Motif on OS/2.
http://www.codeproject.com/KB/library/wxwidgets.aspx

标签: ,

wxDb/wxDbTable wxODBC Overview

he wxODBC classes were designed for database independence. Although SQL and ODBC both have standards which define the minimum requirements they must support to be in compliance with specifications, different database vendors may implement things slightly differently. One example of this is that Oracle requires all user names for the datasources to be supplied in uppercase characters. In situations like this, the wxODBC classes have been written to make this transparent to the programmer when using functions that require database-specific syntax.

Currently several major databases, along with other widely used databases, have been tested and supported through the wxODBC classes. The list of supported databases is certain to grow as more users start implementing software with these classes, but at the time of the writing of this document, users have successfully used the classes with the following datasources:

  • DB2
  • DBase (IV, V)**
  • Firebird
  • INFORMIX
  • Interbase
  • MS SQL Server (v7 - minimal testing)
  • MS Access (97, 2000, 2002, and 2003)
  • MySQL (2.x and 3.5 - use the 2.5x drivers though)
  • Oracle (v7, v8, v8i)
  • Pervasive SQL
  • PostgreSQL
  • Sybase (ASA and ASE)
  • XBase Sequiter
  • VIRTUOSO

An up-to-date list can be obtained by looking in the comments of the function wxDb::Dbms in db.cpp, or in the enumerated type wxDBMS in db.h.

**dBase is not truly an ODBC datasource, but there are drivers which can emulate much of the functionality of an ODBC connection to a dBase table. See the wxODBC Known Issues section of this overview for details.

http://docs.wxwidgets.org/2.8.0/wx_odbcoverview.html#wxodbcconfiguringyoursystem

标签: , ,

http://www.xml4wx.org/

XML for wxWidgets is an open source XML parser writen in C++ for use with the wxWidgets cross platform GUI toolkit. This is not the same classes/library included with wxWidgets, but a complete re-write.
  • Designed to be as reasonably standards compliant as possible
  • Includes DOM 1.0, XPath 1.0, XSLT 1.0 and SAX-like implementation
  • Many convienience functions for common functionality makes it easy to use
  • Completely embedable - link your project with the static library
  • Inheritable class structure allows creation of special-use DOM's
  • Easily extendable XPath and XSLT functions so that you can implement the functions you need
  • The open source, relativly simple design makes it easy to solve issues while developing

The biggest feature is that it is a piece of cake to work with an in memory XML Document from your C++ code. Instead of having to write specialized C++ classes/structures to represent your xml, you can simply use the iDOMDocument as-is. You can think of the XML4WX DOM as a giant Hash table that also has a stateless search and reporting engines built in.

Other XML DOMS (xmllib2, Xerces, MS XML) require you to write large ammounts of C++ code to access the data. If your xml changes, you'll have to re-write the container classes and re-compile your application. With XML4WX, if you write your XPath queries carefully, your C++ code will continue to work.

标签: , ,

星期五, 四月 04, 2008

Resources Explorer


(
Full Size Image)

ResExplorer is a tool that helps you find resources in EXE or DLL files. The first time you use it, it makes a list of files with resource counts. After that, it can show you a selected resource in a selected file (image and attributes). It is possible to save this to a file or the Clipboard. Some formats are available; these are compatible with Visual Studio (such as BMP, AVI, VAW, RES, ICO, or CUR). The program can easily be extended to support all other resource types.

A management of table of the symbols makes it possible to replace the numerical values indicating the resources by symbols such those defined in the files Resource.h


(Full Size Image)

Special tooltips give attribute details.


(Full Size Image)

This tool is an example of MFC usage (sources available): SDI with variable splitter windows (list view, tree view, and scroll view) to show files listing and tree, and a list for resource attributes.

Parts are directly usable in other applications such as for example:

  • Management of the columns and sorting in CListCtrl in Report mode: Utilities.cpp and Utilities.h.
  • Edition in place of subitems in CListCtrl in Report mode: ListCtrlEx.cpp and ListCtrlEx.h.
  • Display and writing in file of the resoures Bitmap, icon and Curseur: BitmapRW.cpp and BitmapRW.h

It does not use special classes to read resources in the EXE or DLL files.

A help (in French) is implemented but is it necessary to use this tool.

About the Author
Courbevoie (France)

Downloads

  • ResExplorer.zip - Sources of ResExplorer release 2.0
  • ResExplorerHlp1.zip - Source of Help part 1
  • ResExplorerHlp2.zip - Source of Help part 2
  • http://www.codeguru.com/cpp/w-d/dislog/miscellaneous/article.php/c9063/

    标签:

    在Code::Blocks上使用wxWidgets-2.8.0 (二)——开发篇

    终于进入正题了,我们先建立一个最简单的demo:
    (1) 建立工程
    用new projects建立一个wxWidgets application,在project option里使用Using UNICODE static wxWidgets libraries,当然如果你编译的是其他类型的库就选其他的。
    这时建立的工程使用的却都是wxWidgets-2.6.0的配置,你需要自己修改wxWidgets的配置。
    在左边栏的工程上点右键->Build Options进行配置.
    (2) 配置Custom variables
    WX_DIR配置为wxWidgets config时设的--prefix的目录,我的就是mingw啦。
    WX_CFG配置为$(WX_DIR)\bin\wx-config。
    (3) 配置directory
    Compiler:
    $(WX_DIR)\include\wx-2.8
    $(WX_DIR)\lib\wx\include\msw-unicode-release-static-2.8

    Linker:
    $(WX_DIR)\lib

    Resource compiler
    $(WX_DIR)\include\wx-2.8
    (4) 配置Linker
    将原来的mswxu去掉,改成wx_mswu-2.8
    再加上lib目录下的其他几个libwx开头的库,如wxpng-2.8。
    注意这些库一定要排在所有库的最前面,否则link的时候仍然会出错。
    (5) 编译运行
    最重要的时刻到了, 点击Build and Run吧!怎么样,出错了吧,因为还要改一些小地方:)
    这肯定是CB的bug了,你会看到new wxMenu时报错, 应该把""改成_(""), 这是因为我们现在建立的是Unicode程序,wxWidgets处理的字符串全都要加上"_()"这个宏.
    现在可以运行了吧~
    使用CB的wxSmith插件可以进行RAD开发, 大家可以看看这篇文章:
    http://wiki.codeblocks.org/index.php?title=WxSmith_Tutorial_%26_Pointers
    写的很详细,不过仍然是基于wx 2.6.0的,如果用在2.8的库上会出一些小错误,不过很好改,有空的话我再写吧~

    (6) something about CB
    CB的编辑器有个问题,就是对中文的支持不是很好,比如要把窗口的标题使用中文字符串就不行,不过这只是编辑器的问题,我们换个支持UTF-8的编辑器编辑这个源文件就可以了,比如emacs23:) 这样中文就能用在你的wxWidget里了吧~
    最后强烈推荐Code::Blocks,它的开发团队非常活跃,每天都会有进展,这点非常重要,听说Dev-CPP的原创人之一都已经跳槽到CB开发了~ 希望更多的人能支持这个IDE,毕竟开源界太缺少这样的工具了,虽然写代码我一般用emacs,但是要开发GUI程序的话,还是有个RAD工具最好了~

    http://aniluke.spaces.live.com/blog/cns!63F0E8C8F9B72D8A!412.entry

    标签: , ,

    星期四, 三月 20, 2008

    收集了些有用的网址,今天要用

    http://gql.sourceforge.net/
    Database Template Library --> https://sourceforge.net/project/showfiles.php?group_id=17082
    --> http://www.codeguru.com/cpp/data/mfc_database/dynamicdataaccess/article.php/c10629/
    RudeDatabase --> http://www.rudeserver.com/database/download.html
    Free Database or libraries --> http://www.thefreecountry.com/sourcecode/database.shtml
    XML Library --> http://xerces.apache.org/xerces-c/
    --> http://www.alphaworks.ibm.com/tech/xml4c XML4C --> xerces-c
    Expat --> http://www.jclark.com/xml/expat.html
    DB Access Library --> http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Relational_Database_Access

    标签: , , ,

    X Window下的字体缩放和TTF的应用

    X Window下的字体缩放和TTF的应用(转)


    字体属于最直观的东西,直接影响最终的显示和打印结果。在图形界面和所见既所得的要求下,如何发挥X Window在字体方面的能力,是大家十分关心的问题。现在XFree86 4.0已经出来,在TTF方面的扩展已经尘埃落定,所以有了本文。

    X Window在字体方面的能力十分强大。X Window的结构很清晰,统一使用X逻辑字体描述XLFD(X Logical Font Description)描述各式各样的字体。每增加一种字体,只是增加一个模块,XLFD并没有多大变化。这样保证了兼容性,避免系统出现大的动荡。但 负作用也是有的,随着功能的增加,我们会发现耗内存越来越多,速度自然也越来越慢了:-)

    X Window使用X字体服务器XFS处理字体。XFree86附带有一个网络字体服务器xfs,还有每一个X Server都是XFS。就性能而言,自然是内部的XFS快很多。目前XFree86 4.0支持bdf/pcf,Type1,TrueTypeFont等几种字体格式。

    其中bdf/pcf是最基本的格式,TTF可以完美实现无级缩放。
    X 逻辑字体描述(X Logical Font Description)的简单说明:
    // font fields
    // -fndry-fmly-wght-slant-sWdth-adstyl-pxlsz-ptSz-resx-resy-spc-avg Wdth-rgstry-encdng
    // fndry -> foundy
    // fmly -> family, font style
    // wght -> weight
    // slant
    // sWdth -> ? width
    // adstyl -> addtion style
    // pxlsz -> pixel size
    // ptSz -> point size
    // resx -> resolution x
    // resy -> resolution y
    // spc -> space
    // avgWdth -> average width
    // rgstry -> register
    // encdng -> encoding
    example:
    -cclib-song-medium-r-normal-jiantizi-16-160-75-75-c-160-gb2312.1980-0

    其中:
    cclib : 制造商
    song : 字体族, 宋体
    medium: 线权重(中等), 还有bold(粗体)选项
    r : 倾斜, r(Roman), i(Italic), o(Oblique)
    normal: 字符集宽度, 此外还有 condensed, narrow, double
    jiantizi: 附加说明(简体字)
    16: 以像素衡量的宽度.
    160: 点数*10
    75(1): 水平分辨率(dpi)
    75(2): 垂直分辨率(dpi)
    c: 间距, (?), m: fixed width, p: variable width
    160: 平均宽度(10*pixels)
    gb2312.1980: 注册字符集,标准名
    0: 第0套,基本集
    字体描述文件
    在字体同一目录下,有两个文件指导X window如何安装使用字体:
    fonts.dir/fonts.alias。虽然fonts.dir可由实用程序mkfontdir生成,但生成的文件中字体的次序不一定合适,所以有时需要人工调整。
    fonts.dir 格式:
    第一行:字体文件的数目
    后面:字体文件 X 逻辑字体描述(字体真名)
    ......
    fonts.dir example:
    2
    ccs16.pcf.gz -cclib-song-medium-r-normal-jiantizi-16-160-75-75-c-160-gb2312.1980-0
    ccs24.pcf.gz -cclib-song-medium-r-normal-jiantizi-24-240-75-75-c-240-gb2312.1980-0
    fonts.alias 格式:
    字体别名 X 逻辑字体描述(字体真名)
    ......
    fonts.alias example:
    ccs16 -cclib-song-medium-r-normal-jiantizi-16-160-75-75-c-160-gb2312.1980-0
    ccs24 -cclib-song-medium-r-normal-jiantizi-24-240-75-75-c-240-gb2312.1980-0
    这样在使用过程中,程序既可以使用字体真名,也可以使用字体别名装载X字体。

    X字体的使用
    应用程序调用XLoad(Query)Font函数装载字体。X window会尽量解释和装载字体,其中包括参数里使用"*","?"通配符,还有缩放字体。其中X 逻辑字体描述字段对字体缩放有直接影响的是pixel size/point size, average width字段。其中pixel size的优先级大于point size。也就是,如果传给XLoadFont的字体不存在,X window会根据现有的一个名字匹配,大小(pixel size/point size, average width)不同的字体,在内存里生成一个新字体。

    因为X window下的中文字体很少,一般只提供16和24点阵两种大小。所以字体缩放机制就显得很重要。这种机制的好处是只须提供少量的字体,就可以应付大多 数情况。缺点也是有的,就是生成字体的速度很慢,延迟是以秒记的。如果是GB2312字体还好,不到7000个字。而Unicode或GBK字体,汉字就 有20902多个,一个个进行缩放,延迟可想而知。但要注意的是,X window只是在装载生成字体时有延迟,字体生成后,XDraw*函数显示速度并没有延迟。
    下面举例说明。如果有字体:
    ccs16.pcf.gz -cclib-song-medium-r-normal-jiantizi-16-160-75-75-c-160-gb2312.1980-0
    想用字体:
    "-*-song-medium-r-normal-jiantizi-12-120-75-75-c-100-gb2312.1980-0"
    程序里只须直接调用即可:
    ......
    char *font_name = "-*-song-medium-r-normal-jiantizi-12-120-75-75-c-100-gb2312.1980-0";
    XFontStruct *zh_font;
    ......
    zh_font = XLoadFont(display, font_name);
    if (zh_font == NULL) {
    printf("not find this font: %s\n", font_name);
    exit(1);
    }
    ......

    这里要讨论字体缩放机制,是为了解决X外挂式中文平台的字符串定位问题。如果光标要定在两个字符之间,就要知道这点的位置。X应用程序一般是调用函数 XTextWidth(16),XTextExtents(16),XQueryTextExtents(16)以确定字符串的宽度。所以X外挂式中文平 台要截取这些函数以便对中英文混排的字符串进行准确定位。但有些程序为了速度,是调用XGetFontProperty函数或直接在 XFontStruct结构里取得单个字符的宽度,乘上字符个数得到字符串的宽度。如果ASCII字体有标准高宽比,也是没有问题。所谓标准高宽比就是 ASCII字体的宽:高为1/2,相应的中文字体就是1:1。如果不是这样,光标定位就有问题。再有就是字符高度,一般是中文字体略高于ASCII字体就 美观了。但具体数值要控制好,否则太矮不好看,太高又会被削去头部。所以字间距和行间距目前是很烦恼的问题。解决的方法可能有一些:
    1,截获更多的函数,或修改ASCII字体的高度和宽度。这要求对X window有很深的了解。这也是一个吃力不讨好的方案,因为总有疏漏,X window的函数也会发展和变化,那么就会有遗憾。cleex for Linux 1.0在速度和定位上较好地解决了这个问题,可能是使用了这个方案。
    2,使用字体缩放机制,使汉字大小和ASCII字体相匹配。这个方案的问题是装载字体的速度和耗费的资源。我实验了这个方案,使用NetScape浏览网 页,发现很多时间花在了装载字体上。而且,如何管理这些字体也是一个问题。使用TTF字体可能可以完美地解决这个问题。我使用TLC4.0的 ZhWinPro2.0,发现以前定位不准的软件都没有问题了。看来使用TTF字体是今后的方向。应该看到,一个好的XFS,就算不支持TTF,也可以实 现字体的无级缩放。只是bdf/pcf这类字体格式存储的字形信息少,在显示效果上就不及TTF完美,但装载速度感觉就比TTF快。并且在14点阵以 下,TTF的效果倒反不及bdf/pcf。因此今后bdf/pcf主要使用在小点阵低速的环境中,而TTF将用在强调细节和美观的环境里,如字处理。事实 上,X11R6以后的XLFD的功能十分强大,增加矩阵型XLFD和增强别名机制。只需通过XLFD的变换,就可以实现字体的缩放,倾斜,镜像,斜写和环 写的功能,如同MS WORD里的艺术字那样的效果。因为英文水平不高,不敢乱说,有兴趣的可以查看http://www.winehq.com/x11r6_fonts_94.pdf或者XFree86源代码的随机文档。

    TTF以曲线描述字体,可以在各种大小的环境下还原字形。在FreeType的随机文档里有一些这方面的介绍。可以说,XFree86有了TTF,就有了 在所见既所得方面和MS WINDOWS较量的实力。目前XFree86使用的TTF驱动模块是FreeType,这是底层的TTF解释模块,用来把TTF的字形描述转换为可用的 光栅字形。FreeType目前稳定的版本是1.3.1。因为在一些算法上和大公司有专利纠纷,他们决定FreeType依然是freedom。于是放弃 成熟的1.x版,加速开发更好的2.x。这官司让人关注,而FreeType的做法也让人敬佩。有了驱动模块,要想在XFree86下显示这些字,还需要 高一层的X字体服务器(XFS)。目前在XFree86下TTF的XFS有X-TT和xfsft两个,都是使用FreeType作为底层,在实现上个有特 色。XFree86 4.0目前接纳了这两个软件,同时也接纳了这两个软件对fonts.dir文件格式的扩展。

    X-TT是日本人的作品。可能同样是要使用汉字,X-TT显示的汉字感觉上要比xfsft的要美观些。X-TT还有一个特色就是把XFree86的字体处 理模块分离出来,做成一个动态链接库libfont.so。但是不知什么原因,XFree86 4.0没有接受这个方案,继续使用静态链接库font.a。

    X-TT目前可以通过XLFD的变换把ISO10646编码的TTF转化为GB2312,BIG5,JIS,KSC等编码标准的字体。但是X-TT软件本 身没有提供GBK编码的支持。国内两个提供使用TTF字体的Linux厂商(TurboLinux和红旗Linux)都选用X-TT作为XFS,同时提供 了GBK的支持。例如RF1.1把所有的转换表,包括GBK的,都做成动态链接库形式的convert modules,放在/usr/X11R6/lib/modules/codeconv下。如果这两个厂商的方案能进入X-TT的原始发行版中,进而进入 XFree86今后的发行版中,将是中国Linux界的一件大事。xfsft有一个特点就是比较小巧,功能不多,够用就行。XFree86 4.0缺省就是使用xfsft模块。xfsft在变换TTF的编码时,使用的是外部的转换表。这也是我从3.3.3.1到现在的4.0一直使用xfsft 的原因。xfsft本身也只提供了GB2312和BIG5的转换表,没有提供GBK的支持。但我从Unicode的网站下载了 GBK->Unicode的转换表,简单修改配置文件,就可以使用GBK编码标准的字体了。

    前面所说的显示字形美观问题,一个是指个人的感觉,另一个是指在小点阵下中文TTF的显示问题。所谓小点阵字体,是指14点阵以下的字体。目前不论是X- TT还是xfsft,在这种情况下,都不及同样大小的pcf字体美观(我对比使用的是cleex的12和14点阵字体,还有RF1.1提供的一个12点阵 的GB2312编码的点阵字体)。这是中文TTF的问题。观察我们的汉字笔画,点、横、竖、撇、捺、折、钩,从头到尾粗细都是变化的。在小点阵的情况 下,TTF既想表达这些变化,又要丢失一些细节,就会造成中文字横不平,竖不直,都有些打折,同时点和钩常常丢失,因此显示出来的中文字怎么看都不顺眼。 反观英文字母,基本上是粗细相等的线条,上面对比用的小点阵中文pcf字体,笔画基本上也是一条棍子捅到底。其实,在这种情况下,我们要求的不是细节,而 是中文字横平竖直的基本要求,所以TTF的曲线描述这时倒反成了累赘。为解决这个问题,现在的中文TTF都会内嵌小点阵字体。因为没有看过 FreeType,X-TT和xfsft的源代码,不能确定它们的实际效果。但目前MS WINDOWS95/98中文版在显示小点阵中文字体方面比X-TT和xfsft的要好。当然,这也是一个感觉。

    ISO10646的TTF通过XLFD变换而变化为其它编码标准的字体,可以算是Unicode在XFree86中的一个应用。通过这个功 能,XFree86只需一套ISO10646编码标准的TTF,就可以同时提供中文,日文,韩文的显示。关键就在于那些转换表的应用。原理很简 单,XLFD最后两个域是注册名和编码号,XFS在处理XLFD时,识别这两个区域,通过配置文件和转换表,就可以提供其它编码标准的字体。

    因为在XFree86 3.x下配置TTF的XFS有点麻烦,而且XFree86 3.x很快就成为历史,所以下面主要讨论在XFree86 4.0下如何配置xfsft以支持GBK。如果要使用X-TT,可以安装TLC4.X或RF1.1,不过两者都不好移植到其它Linux套件中。还有一个 是北京腾图出的Manderake Linux 7.0也是使用X-TT。

    取来ISO10646的TTF,放在一个目录中:
    #ls /usr/X11R6/lib/X11/fonts/FreeType -l
    -rw-r--r-- 1 root root 2496 May 3 10:04 encodings.dir
    -rw-r--r-- 1 root root 689 May 3 10:10 fonts.alias
    -rw-r--r-- 1 root root 1968 May 3 08:50 fonts.dir
    -rw-r--r-- 1 root root 1968 May 3 10:04 fonts.scale
    -rw-r--r-- 1 root root 3595788 Apr 8 08:54 fzfsjw.ttf
    -rw-r--r-- 1 root root 10210620 Apr 8 08:55 fzhtk.ttf
    -rw-r--r-- 1 root root 3759712 Apr 8 08:55 fzktjw.ttf
    -rw-r--r-- 1 root root 3978284 Apr 8 08:55 fzlsjw.ttf
    -rw-r--r-- 1 root root 2763072 Apr 8 08:55 fzssjw.ttf
    -rw-r--r-- 1 root root 9300964 Apr 8 08:55 fzssk.ttf
    -rw-r--r-- 1 root root 4762912 Apr 8 08:55 fzwbjw.ttf
    其中fzssk.ttf和fzhtk.ttf是ISO10646的TTF。
    制作fonts.dir和fonts.alias
    #cat /usr/X11R6/lib/X11/fonts/FreeType/fonts.dir
    13
    fzssjw.ttf -freetype-song-medium-r-normal-jiantizi-0-0-0-0-c-0-gb2312.1980-0
    fzktjw.ttf -freetype-kai-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0
    fzlsjw.ttf -freetype-lishu-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0
    fzwbjw.ttf -freetype-weibei-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0
    fzfsjw.ttf -freetype-fang-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0
    fzssk.ttf -freetype-song-medium-r-normal--0-0-0-0-c-0-iso10646.1993-1
    fzssk.ttf -freetype-song-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0
    fzssk.ttf -freetype-song-medium-r-normal--0-0-0-0-c-0-gb13000.1993-1
    fzssk.ttf -freetype-song-medium-r-normal--0-0-0-0-c-0-big5.eten-0
    fzhtk.ttf -freetype-hei-medium-r-normal--0-0-0-0-c-0-iso10646.1993-1
    fzhtk.ttf -freetype-hei-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0
    fzhtk.ttf -freetype-hei-medium-r-normal--0-0-0-0-c-0-gb13000.1993-1
    fzhtk.ttf -freetype-hei-medium-r-normal--0-0-0-0-c-0-big5.eten-0
    #cat /usr/X11R6/lib/X11/fonts/FreeType/fonts.alias
    -freetype-song-medium-r-normal--0-0-0-0-c-0-gb2312.1980-1
    -freetype-song-medium-r-normal--0-0-0-0-c-0-gb13000.1993-1
    -freetype-hei-medium-r-normal--0-0-0-0-c-0--gb2312.1980-1
    -freetype-hei-medium-r-normal--0-0-0-0-c-0-gb13000.1993-1
    把/usr/X11R6/lib/X11/fonts/FreeType加入XFree86的字体目录中,在/etc/X11/XF86Config中的Section "Files"加入
    FontPath "/usr/X11R6/lib/X11/fonts/FreeType/"

    上面-*-gb13000.1993-1就是GBK字体。这名字在概念上是有些错误,但目前也没有更好的名字,而且大家都这么用,也就习惯了。如果是使用 TLC4.X或RF1.1,设置到此可以结束了。如果是北京腾图出的Manderake Linux 7.0,把RF1.1的/usr/X11R6/lib/modules/codeconv/GB13000.so拷贝到相同的目录下也可以了。

    在XFree86 4.0下X-TT和xfsft是两个独立的模块,使用其中一个,就不能用另一个。如果在/etc/X11/XF86Config的Section "Module"是Load "freetype"则使用xfsft,如果是Load "xtt"则使用X-TT。

    如果安装有xfsft,就会有一个目录/usr/X11R6/lib/X11/fonts/encodings。
    其中CJK的编码转换表放在/usr/X11R6/lib/X11/fonts/encodings/large:
    #ls /usr/X11R6/lib/X11/fonts/encodings/large -l
    -rw-r--r-- 1 root wheel 65878 Mar 10 06:12 big5.eten-0.enc.gz
    -rw-r--r-- 1 root wheel 693 May 3 10:00 encodings.dir
    -rw-r--r-- 1 root root 105183 May 3 10:01 gb13000.1993-1.enc.gz
    -rw-r--r-- 1 root wheel 33215 Mar 10 06:12 gb2312.1980-0.enc.gz
    -rw-r--r-- 1 root wheel 184 Mar 10 06:12 jisx0201.1976-0.enc.gz
    -rw-r--r-- 1 root wheel 32847 Mar 10 06:12 jisx0208.1983-0.enc.gz
    -rw-r--r-- 1 root wheel 34392 Mar 10 06:12 jisx0208.1990-0.enc.gz
    -rw-r--r-- 1 root wheel 23811 Mar 10 06:12 jisx0212.1990-0.enc.gz
    -rw-r--r-- 1 root wheel 25951 Mar 10 06:12 ksc5601.1987-0.enc.gz
    #cat /usr/X11R6/lib/X11/fonts/encodings/large/encodings.dir
    9
    big5.eten-0 /usr/X11R6/lib/X11/fonts/encodings/large/big5.eten-0.enc.gz
    jisx0212.1990-0 /usr/X11R6/lib/X11/fonts/encodings/large/jisx0212.1990-0.enc.gz
    jisx0208.1990-0 /usr/X11R6/lib/X11/fonts/encodings/large/jisx0208.1990-0.enc.gz
    jisx0208.1983-0 /usr/X11R6/lib/X11/fonts/encodings/large/jisx0208.1983-0.enc.gz
    big5-0 /usr/X11R6/lib/X11/fonts/encodings/large/big5.eten-0.enc.gz
    gb2312.1980-0 /usr/X11R6/lib/X11/fonts/encodings/large/gb2312.1980-0.enc.gz
    gb13000.1993-1 /usr/X11R6/lib/X11/fonts/encodings/large/gb13000.1993-1.enc.gz
    jisx0201.1976-0 /usr/X11R6/lib/X11/fonts/encodings/large/jisx0201.1976-0.enc.gz
    ksc5601.1987-0 /usr/X11R6/lib/X11/fonts/encodings/large/ksc5601.1987-0.enc.gz
    其中gb13000.1993-1.enc.gz是GBK->Unicode编码转换表,是从Unicode下载转换表后按照enc文件格式自己制 作的。关于enc文件格式,可以看xfsft的随机文档,很简单的。因为gb13000.1993-1.enc.gz大于100kb,所以不能附上。
    接着制作TTF目录下的fonts.scale和encodings.dir
    #cp /usr/X11R6/lib/X11/fonts/FreeType/fonts.dir /usr/X11R6/lib/X11/
    fonts/FreeType/fonts.scale
    #cat /usr/X11R6/lib/X11/fonts/FreeType/encodings.dir
    9
    big5.eten-0 /usr/X11R6/lib/X11/fonts/encodings/large/big5.eten-0.enc.gz
    jisx0212.1990-0 /usr/X11R6/lib/X11/fonts/encodings/large/jisx0212.1990-0.enc.gz
    jisx0208.1990-0 /usr/X11R6/lib/X11/fonts/encodings/large/jisx0208.1990-0.enc.gz
    jisx0208.1983-0 /usr/X11R6/lib/X11/fonts/encodings/large/jisx0208.1983-0.enc.gz
    big5-0 /usr/X11R6/lib/X11/fonts/encodings/large/big5.eten-0.enc.gz
    gb2312.1980-0 /usr/X11R6/lib/X11/fonts/encodings/large/gb2312.1980-0.enc.gz
    gb13000.1993-1 /usr/X11R6/lib/X11/fonts/encodings/large/gb13000.1993-1.enc.gz
    jisx0201.1976-0 /usr/X11R6/lib/X11/fonts/encodings/large/jisx0201.1976-0.enc.gz
    ksc5601.1987-0 /usr/X11R6/lib/X11/fonts/encodings/large/ksc5601.1987-0.enc.gz
    重新启动XF86,打开一个xterm
    #xlsfonts | grep freetype
    -freetype-fang-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0
    -freetype-hei-medium-r-normal--0-0-0-0-c-0--gb2312.1980-1
    -freetype-hei-medium-r-normal--0-0-0-0-c-0-big5.eten-0
    -freetype-hei-medium-r-normal--0-0-0-0-c-0-gb13000.1993-1
    -freetype-hei-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0
    -freetype-hei-medium-r-normal--0-0-0-0-c-0-iso10646.1993-1
    -freetype-kai-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0
    -freetype-lishu-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0
    -freetype-song-medium-r-normal--0-0-0-0-c-0-big5.eten-0
    -freetype-song-medium-r-normal--0-0-0-0-c-0-gb13000.1993-1
    -freetype-song-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0
    -freetype-song-medium-r-normal--0-0-0-0-c-0-gb2312.1980-1
    -freetype-song-medium-r-normal--0-0-0-0-c-0-iso10646.1993-1
    -freetype-song-medium-r-normal-jiantizi-0-0-0-0-c-0-gb2312.1980-0
    -freetype-weibei-medium-r-normal--0-0-0-0-c-0-gb2312.1980-0
    #xfd -fn -freetype-song-medium-r-normal--0-0-0-0-c-0-gb13000.1993-1 &

    http://www.bross.cn/modules/discuz/viewthread.php?tid=359

    标签: , ,

    字体缩放

    自己定义字体,选进设备描述表,用,释放
    如果在OnSize()中:
    CClientDC dc;
    CFont font;
    LOGFONT log;
    GetObject(::GetStockObject(DEFAULT_GUI_FONT),sizeof(log),&log);
    log.lfHeight=20; //改
    log.lfWidth=20; //改
    log.lfCharSet=GB2312_CHARSET;
    lstrcpy(log.lfFaceName,"宋体"); //改
    font.CreateFontIndirect(&log);
    CFont* oldfont=pDC->SelectObject(&font);
    dc->TextOut("LLM");
    dc->SelectObject(oldfont);

    http://topic.csdn.net/t/20021101/13/1139652.html

    感觉可行

    标签: ,

    星期五, 三月 14, 2008

    ExtCreateRegion用法

    VC的代码
    HRGN CreateStretchRgn( HRGN hSrcRgn,
    float xScale ,
    float yScale ,
    int xOffset ,
    int yOffset )
    {
    XFORM xForm;
    xForm.eDx = 0;
    xForm.eDy = 0;
    xForm.eM11 = xScale;
    xForm.eM12 = 0;
    xForm.eM21 = 0;
    xForm.eM22 = yScale;
    HRGN hRgn = NULL ;

    DWORD dwCount = GetRegionData( hSrcRgn , 0 , NULL );
    BYTE* pRgnData =(BYTE*) malloc( dwCount );
    if( pRgnData )
    {
    dwCount = GetRegionData( hSrcRgn , dwCount , (RGNDATA*)pRgnData );
    hRgn = ExtCreateRegion( &xForm , dwCount , (RGNDATA*)pRgnData );
    free( pRgnData );

    if( hRgn )
    {
    OffsetRgn( hRgn , xOffset, yOffset );
    return hRgn;
    }
    }
    return NULL;
    }

    标签:

    星期五, 二月 29, 2008

    D语言

    Digital Mars C and C++ Compilers for Win32, Win16, DOS32 and DOS. Fastest compile/link times, powerful optimization technology, Design by Contract, complete library source, HTML browsable documentation, disassembler, librarian, resource compiler, make, etc., command line and GUI versions, tutorials, sample code, online updates, Standard Template Library, and much more.

    D Programming Language spec

    http://www.digitalmars.com/

    标签: ,

    沉积2+年,CodeBlocks升级!

    Code::Blocks 8.02 has been released!
    Thursday, 28 February 2008 18:34
    Our long awaited release is finally here! Representing the hard work of 14+ developers for more 2+ years since our last official release (and many changes in the roadmap in between), it is finally made available to the general public.
    For your convenience, we provide binaries for all platforms Code::Blocks supports:
    Windows 2000 / XP / Vista
    Linux (Ubuntu & Debian, 32 & 64 bits)
    MacOSX 10.4+
    Binaries for other Linux distros will be made available in the following days. So, without further ado, head over to the downloads section and get it while it's hot!
    The Code::Blocks Team

    http://www.codeblocks.org/

    标签: , , ,

    星期五, 二月 22, 2008

    Excel File Format Documentation

    Excel File Format Documentation

    1. Microsoft Documentation
      • Download the Escher File Format Documentation
      • Read the Escher File Format Documentation online (this document is very very large!)
      • Pocket Excel File Format
      • Q147732 Records needed to make a BIFF 5 file excel can use
      • Q147942 DOCERR: Microsoft Excel Internal format table doc has errors
      • Q284441 DOC: Excel BIFF8 FORMAT Record Documentation Is Incomplete
      • Q284436 DOC: Excel BIFF8 Extended Rich String Formatting Run Is 4 Bytes
      • Q269168 HOWTO: Distinguish Between Excel 97 and Excel 2000/2002 Files
      • Q207475 DOC: Excel BIFF8 CONTINUE Record Information Is Incomplete
      • Q195237 LABEL Doc Error in MS Excel 97 Developer's Kit
      • Q184647 Xl97: BIFF Records Documentation Error in MS Excel 97 Developer's Kit
    2. 3rd Party Documentation

    Source Code to deal with the Excel File Format

    No matter what programming language you use, there is something here for you.
    1. For C programmers:
      • xlhtml - A c program for reading excel files.
      • xlreader Another c program for reading excel files
    2. For Java Programmers:
      • ExcelRead A java program for reading excel files
      • POI A java project to read and write Excel and OLE files
      • A java program to read and write the Pocket Excel file format.
    3. For Perl Programmers:
    4. For other languages:
    http://chicago.sourceforge.net/devel/docs/excel/

    标签: , , ,

    星期三, 一月 23, 2008

    Auto update with wxHTTP and ofstream

    #include
    #include

    //[...]
    // progress bar with 100 units ... declared as wxGauge progress;
    progress = new wxGauge(this, ID_Progress, 100, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL);
    //[...]

    bool GetUpdate::DownloadUpdate()
    {
    wxHTTP http;
    http.SetTimeout(120);
    http.Connect(_T("www.example.com"));
    wxInputStream *httpStream = http.GetInputStream(_T("/file.exe"));

    if (http.GetError() == wxPROTO_NOERR)
    {
    size_t chunks = 100;
    size_t chunkSize = httpStream->GetSize() / chunks;
    char *fileContent = new char[chunkSize];

    wxFFile file(_T("file.exe"), _T("wb"));

    for (size_t i = 0; i <= chunks; i++)
    {
    progress->SetValue(i * 100/chunks);
    httpStream->Read(fileContent, chunkSize);

    file.Write(fileContent, httpStream->LastRead());
    }
    file.Flush();

    wxDELETE(fileContent);
    }

    http.Close();
    wxDELETE(httpStream);
    return true;
    }

    标签: ,

    星期五, 十一月 23, 2007

    用UpdateResource修改EXE文件图标的多源码(已修正)

    注:转帖请包函作者信息.(作者:菜新)

    鄙视下百度空间,他姥姥...竟然限量字符40000字节!靠....

    一年前初学VB时我对这个API就特感兴趣,听说这个API可以更改图标资源,就更感兴趣了,后来试了试,发现修改其它资源貌似没多大问题,唯独修改图标时无果,我发现所修改的图虽说已经写入到资源文件中了,但是就是无法显示。后来到网上查了下,发现用UpdateResource修改EXE图标的没一个成功的,大致都是发生成功写入,无法正常显示的问题。罢矣,当时就琢磨着把该问题先放放,等日后有时间再好好折腾。

    无奈时间过得太快,忽忽悠悠就过了一年了,前几天,在整理去年的一些源码时发现了这个遗留在硬盘中的代码,一年前无奈自己所学浅溥,啥都不知道,但现在已经对API有了较深厚的认识,再加上对汇编的一些了解,我想此时不解决更待何时。

    在折腾这个API的期间也发生不少问题,最让我自责的就是差点被 CreateFile 这个API给Game Over,这个小伟知道(又是小伟?没办法啊,谁要咱和小伟太有缘了~)。还好自己最终醒悟,否则真的要好好鄙视鄙视自己。最初修改时还是和一年前一个样,这时我一直在回想一样年遇到这个问题的问题:所写图标的数据是不是完整的写到了资源文件中?想到此,我用eXeScope(一个PE资源文件查看工具)看了下写入到资源文件中的十六进制,又用UltraEdit-32以十六进制查看ico文件中的数据,发现没问题啊?一字节一字节都对得上,那问题出在哪了?没法,继续在Google游荡,终于找了一份有效的资料(网址现在不知扔哪去了),全E文,看得难受,不过大致的意思是说ICON是由一个结构组成,同PE那些什么NT头,DOS头的差不多,而所显示的图像数据包函于ICON类型结构的dwImageOffset偏移处。呵,这下总算搞明白为什么直接把ICON文件写入到资源文件中显示不了的问题了,也就是说在dwImageOffset偏移位置处才是咱所需要的图像数据,这不就啥都OK了么,爷爷的,原来咱从一开始就被ICON文件整得稀里糊涂,靠MS,当然也鄙视下自己的无知。另外还好找到的那份资料有点人性,把结构给咱标出来了,那么现在一切都顺理成章,不说多了,上代码:

    ===============================================

    Delphi Code:

    ===============================================

    //请自行添加到 Type 处
    PICONDIRENTRY = ^ICONDIRENTRY;
    ICONDIRENTRY = packed record
    bWidth: Byte;
    bHeight: Byte;
    bColorCount: Byte;
    bReserved: Byte;
    wPlanes: Word;
    wBitCount: Word;
    dwBytesInRes: DWORD;
    dwImageOffset: DWORD;
    end;

    PICONDIR = ^ICONDIR;
    ICONDIR = packed record
    idReserved: Word;
    idType: Word;
    idCount: Word;
    idEntries: ICONDIRENTRY;
    end;

    PGRPICONDIRENTRY = ^GRPICONDIRENTRY;
    GRPICONDIRENTRY = packed record
    bWidth: Byte;
    bHeight: Byte;
    bColorCount: Byte;
    bReserved: Byte;
    wPlanes: Word;
    wBitCount: Word;
    dwBytesInRes: DWORD;
    nID: Word;
    end;

    PGRPICONDIR = ^GRPICONDIR;
    GRPICONDIR = packed record
    idReserved: Word;
    idType: Word;
    idCount: Word;
    idEntries: GRPICONDIRENTRY;
    end;

    //////////////////////////////////////////////
    //函数说明:修改EXE图标
    //
    //参 数:IconFile 图标文件
    // ExeFile 被修改的EXE文件
    //
    //返回值: 成功为True,否则False
    /////////////////////////////////////////////
    function ChangeExeIcon(IcoFile, ExeFile: string): Boolean;
    var
    stID: ICONDIR;
    stGID: GRPICONDIR;

    pGrpIcon: PBYTE;
    pIcon: PBYTE;
    hUpdate: DWORD;
    nSize, nGSize: DWORD;
    hFile: THandle;
    dwReserved: DWORD;
    ret: Boolean;
    begin
    Result := False;

    hFile := CreateFile(PChar(IcoFile), GENERIC_READ, 0, nil, OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL, 0);
    if hFile = INVALID_HANDLE_VALUE then
    Exit;

    try
    ReadFile(hFile, stID, Sizeof(ICONDIR), dwReserved, nil);

    nSize := stID.idEntries.dwBytesInRes;
    GetMem(pIcon, nSize);
    SetFilePointer(hFile, stID.idEntries.dwImageOffset, nil, FILE_BEGIN);
    ReadFile(hFile, pIcon^, nSize, dwReserved, nil);

    stGID.idType := 1;
    stGID.idCount := stID.idCount;
    stGID.idReserved := 0;
    CopyMemory(@stGID.idEntries.bWidth, @stID.idEntries.bWidth, 12);
    stGID.idEntries.nID := 0;

    nGSize := Sizeof(GRPICONDIR);
    GetMem(pGrpIcon, nGSize);
    CopyMemory(pGrpIcon, @stGID, nGSize);

    hUpdate := BeginUpdateResource(PChar(ExeFile), False);
    try
    ret := UpdateResource(hUpdate, RT_GROUP_ICON, MAKEINTRESOURCE(1), 0, pGrpIcon, nGSize);
    ret := UpdateResource(hUpdate, RT_ICON, MAKEINTRESOURCE(1), 0, pIcon, nSize);
    finally
    EndUpdateResource(hUpdate, False);
    end;
    finally
    CloseHandle(hFile);
    end;

    Result := ret;
    end;

    ===============================================

    VB Code:

    ===============================================

    Option Explicit

    Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
    Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long
    Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
    Private Declare Function BeginUpdateResource Lib "kernel32" Alias "BeginUpdateResourceA" (ByVal pFileName As String, ByVal bDeleteExistingResources As Long) As Long
    Private Declare Function UpdateResource Lib "kernel32" Alias "UpdateResourceA" (ByVal hUpdate As Long, ByVal lpType As Long, ByVal lpName As Long, ByVal wLanguage As Long, lpData As Any, ByVal cbData As Long) As Long
    Private Declare Function EndUpdateResource Lib "kernel32" Alias "EndUpdateResourceA" (ByVal hUpdate As Long, ByVal fDiscard As Long) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Declare Function GetLastError Lib "kernel32" () As Long

    Private Const INVALID_HANDLE_VALUE = -1
    Private Const GENERIC_READ = &H80000000
    Private Const FILE_ATTRIBUTE_NORMAL = &H80
    Private Const FILE_BEGIN = 0
    Private Const OPEN_EXISTING = 3
    Private Const RT_ICON = 3&
    Private Const DIFFERENCE As Long = 11
    Private Const RT_GROUP_ICON As Long = (RT_ICON + DIFFERENCE)


    Private Type ICONDIRENTRY
    bWidth As Byte
    bHeight As Byte
    bColorCount As Byte
    bReserved As Byte
    wPlanes As Integer
    wBitCount As Integer
    dwBytesInRes As Long
    dwImageOffset As Long
    End Type

    Private Type ICONDIR
    idReserved As Integer
    idType As Integer
    idCount As Integer
    'idEntries As ICONDIRENTRY
    End Type

    Private Type GRPICONDIRENTRY
    bWidth As Byte
    bHeight As Byte
    bColorCount As Byte
    bReserved As Byte
    wPlanes As Integer
    wBitCount As Integer
    dwBytesInRes As Long
    nID As Integer
    End Type

    Private Type GRPICONDIR
    idReserved As Integer
    idType As Integer
    idCount As Integer
    idEntries As GRPICONDIRENTRY
    End Type

    '//////////////////////////////////////////////
    '//函数说明:修改EXE图标
    '//
    '//参 数:IconFile 图标文件
    '// ExeFile 被修改的EXE文件
    '//
    '//返回值: 成功为True,否则False
    '/////////////////////////////////////////////////////
    Private Function ChangeExeIcon(ByVal IconFile As String, ByVal ExeFile As String) As Boolean
    On Error GoTo cw

    Dim stID As ICONDIR
    Dim stIDE As ICONDIRENTRY
    Dim stGID As GRPICONDIR

    Dim hFile As Long
    Dim pIcon() As Byte, pGrpIcon() As Byte
    Dim nSize As Long, nGSize As Long
    Dim dwReserved As Long
    Dim hUpdate As Long
    Dim ret As Long

    hFile = CreateFile(IconFile, GENERIC_READ, 0, ByVal 0&, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
    If hFile = INVALID_HANDLE_VALUE Then Exit Function

    ret = ReadFile(hFile, stID, Len(stID), dwReserved, ByVal 0&)
    If ret = 0 Then GoTo cw

    ret = ReadFile(hFile, stIDE, Len(stIDE), dwReserved, ByVal 0&)

    nSize = stIDE.dwBytesInRes
    ReDim pIcon(nSize - 1)
    SetFilePointer hFile, stIDE.dwImageOffset, ByVal 0&, FILE_BEGIN
    ret = ReadFile(hFile, pIcon(0), nSize, dwReserved, ByVal 0&)
    If ret = 0 Then GoTo cw

    With stGID
    .idType = 1
    .idCount = stID.idCount
    .idReserved = 0
    CopyMemory stGID.idEntries, stIDE, 12
    .idEntries.nID = 0
    End With

    nGSize = Len(stGID)
    ReDim pGrpIcon(nGSize - 1)
    CopyMemory pGrpIcon(0), stGID, nGSize


    hUpdate = BeginUpdateResource(ExeFile, False)
    ret = UpdateResource(hUpdate, RT_GROUP_ICON, 1, 0, pGrpIcon(0), nGSize)
    ret = UpdateResource(hUpdate, RT_ICON, 1, 0, pIcon(0), nSize)
    EndUpdateResource hUpdate, False

    If ret = 0 Then GoTo cw
    ChangeExeIcon = True

    cw:
    CloseHandle hFile

    End Function

    ===============================================

    VC++ Code:

    ===============================================

    #include
    #include
    #include


    struct ICONDIRENTRY
    {
    BYTE bWidth;
    BYTE bHeight;
    BYTE bColorCount;
    BYTE bReserved;
    WORD wPlanes;
    WORD wBitCount;
    DWORD dwBytesInRes;
    DWORD dwImageOffset;
    };


    struct ICONDIR
    {
    WORD idReserved;
    WORD idType;
    WORD idCount;
    //ICONDIRENTRY idEntries;
    };


    struct GRPICONDIRENTRY
    {
    BYTE bWidth;
    BYTE bHeight;
    BYTE bColorCount;
    BYTE bReserved;
    WORD wPlanes;
    WORD wBitCount;
    DWORD dwBytesInRes;
    WORD nID;
    };

    struct GRPICONDIR
    {
    WORD idReserved;
    WORD idType;
    WORD idCount;
    GRPICONDIRENTRY idEntries;
    };


    //////////////////////////////////////////////
    //函数说明:修改EXE图标
    //
    //参 数:IconFile 图标文件
    // ExeFile 被修改的EXE文件
    //
    //返回值: 成功为True,否则False
    /////////////////////////////////////////////
    bool ChangeExeIcon(LPWSTR IconFile, LPWSTR ExeFile)
    {
    ICONDIR stID;
    ICONDIRENTRY stIDE;
    GRPICONDIR stGID;
    HANDLE hFile;
    DWORD nSize, nGSize, dwReserved;
    HANDLE hUpdate;
    PBYTE pIcon, pGrpIcon;
    BOOL ret;

    hFile = CreateFile(IconFile, GENERIC_READ, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if (hFile == INVALID_HANDLE_VALUE)
    {
    return false;
    }

    ZeroMemory(&stID, sizeof(ICONDIR));
    ret = ReadFile(hFile, &stID, sizeof(ICONDIR), &dwReserved, NULL);

    ZeroMemory(&stIDE, sizeof(ICONDIRENTRY));
    ret = ReadFile(hFile, &stIDE, sizeof(ICONDIRENTRY), &dwReserved, NULL);

    nSize = stIDE.dwBytesInRes;
    pIcon = (PBYTE)malloc(nSize);
    SetFilePointer(hFile, stIDE.dwImageOffset, NULL, FILE_BEGIN);
    ret = ReadFile(hFile, (LPVOID)pIcon, nSize, &dwReserved, NULL);
    if (!ret)
    {
    CloseHandle(hFile);
    return false;
    }

    ZeroMemory(&stGID, sizeof(GRPICONDIR));
    stGID.idCount = stID.idCount;
    stGID.idReserved = 0;
    stGID.idType = 1;
    CopyMemory(&stGID.idEntries, &stIDE, 12);
    stGID.idEntries.nID = 0;

    nGSize = sizeof(GRPICONDIR);
    pGrpIcon = (PBYTE)malloc(nGSize);
    CopyMemory(pGrpIcon, &stGID, nGSize);


    hUpdate = BeginUpdateResource(ExeFile, false);
    ret = UpdateResource(hUpdate, RT_GROUP_ICON, MAKEINTRESOURCE(1), 0, (LPVOID)pGrpIcon, nGSize);
    ret = UpdateResource(hUpdate, RT_ICON, MAKEINTRESOURCE(1), 0, (LPVOID)pIcon, nSize);
    EndUpdateResource(hUpdate, false);
    if (!ret)
    {
    CloseHandle(hFile);
    return false;
    }

    CloseHandle(hFile);
    return true;
    }

    ===============================================

    ASM Code:

    ===============================================


    .386
    .model flat,stdcall
    option casemap:none

    include windows.inc
    include user32.inc
    includelib user32.lib
    include kernel32.inc
    includelib kernel32.lib

    ICONDIRENTRY STRUCT
    bWidth BYTE ?
    bHeight BYTE ?
    bColorCount BYTE ?
    bReserved BYTE ?
    wPlanes WORD ?
    wBitCount WORD ?
    dwBytesInRes DWORD ?
    dwImageOffset DWORD ?
    ICONDIRENTRY ENDS

    ICONDIR STRUCT
    idReserved WORD ?
    idType WORD ?
    idCount WORD ?
    ;idEntries ICONDIRENTRY <>
    ICONDIR ENDS

    GRPICONDIRENTRY STRUCT
    bWidth BYTE ?
    bHeight BYTE ?
    bColorCount BYTE ?
    bReserved BYTE ?
    wPlanes WORD ?
    wBitCount WORD ?
    dwBytesInRes DWORD ?
    nID WORD ?
    GRPICONDIRENTRY ENDS

    GRPICONDIR STRUCT
    idReserved WORD ?
    idType WORD ?
    idCount WORD ?
    idEntries GRPICONDIRENTRY <>
    GRPICONDIR ENDS

    .data

    szIcon db 'a.ico', 0
    szFile db 'a.exe', 0

    .code

    //////////////////////////////////////////////
    //函数说明:修改EXE图标
    //
    //参 数:IconFile 图标文件
    // ExeFile 被修改的EXE文件
    //
    //返回值: 成功为True,否则False
    /////////////////////////////////////////////

    _ChangeExeIcon proc IconFile, ExeFile

    local @stID: ICONDIR
    local @stIDE: ICONDIRENTRY
    local @stGID: GRPICONDIR

    local @hFile: DWORD
    local @dwReserved: DWORD
    local @nSize: DWORD
    local @nGSize: DWORD
    local @pIcon: DWORD
    local @pGrpIcon: DWORD
    local @hUpdate: DWORD
    local @ret: DWORD

    invoke CreateFile, IconFile, GENERIC_READ, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
    mov @hFile, eax

    .if eax == INVALID_HANDLE_VALUE
    xor eax, eax
    ret
    .endif

    invoke RtlZeroMemory, addr @stID, sizeof @stID
    invoke ReadFile, @hFile, addr @stID, sizeof @stID, addr @dwReserved, NULL

    invoke RtlZeroMemory, addr @stIDE, sizeof @stIDE
    invoke ReadFile, @hFile, addr @stIDE, sizeof @stIDE, addr @dwReserved, NULL

    push @stIDE.dwBytesInRes
    pop @nSize

    invoke GlobalAlloc, GPTR, @nSize
    mov @pIcon, eax

    invoke SetFilePointer, @hFile, @stIDE.dwImageOffset, NULL, FILE_BEGIN
    invoke ReadFile, @hFile, @pIcon, @nSize, addr @dwReserved, NULL
    cmp eax, 0
    je err

    invoke RtlZeroMemory, addr @stGID, sizeof @stGID
    push @stID.idCount
    pop @stGID.idCount
    mov @stGID.idReserved, 0
    mov @stGID.idType, 1
    invoke RtlMoveMemory, addr @stGID.idEntries, addr @stIDE, 12
    mov @stGID.idEntries.nID, 0

    mov @nGSize, sizeof @stGID
    invoke GlobalAlloc, GPTR, @nGSize
    mov @pGrpIcon, eax
    invoke RtlMoveMemory, @pGrpIcon, addr @stGID, @nGSize


    ;开始修改
    invoke BeginUpdateResource, ExeFile, FALSE
    mov @hUpdate, eax
    invoke UpdateResource, @hUpdate, RT_GROUP_ICON, 1, 0, @pGrpIcon, @nGSize
    invoke UpdateResource, @hUpdate, RT_ICON, 1, 0, @pIcon, @nSize
    mov @ret, eax
    invoke EndUpdateResource, @hUpdate, FALSE

    .if @ret == FALSE
    jmp err
    .endif

    ;成功后到此一日游
    invoke GlobalFree, @pIcon
    invoke CloseHandle, @hFile
    mov eax, 1
    ret

    err:
    ;失败后到此一日游
    invoke GlobalFree, @pIcon
    invoke CloseHandle, @hFile
    xor eax, eax
    ret

    _ChangeExeIcon endp

    ;==========================程序入口=============================
    start:

    invoke _ChangeExeIcon, offset szIcon, offset szFile
    invoke ExitProcess, NULL

    end start


    以上分别用四种语言写的一个用UpdateResource修改EXE文件图标代码示例,希望对你有用。你不会VB?那你可用Delphi的,你不会 Delphi?那你可用VC++的,你不会VC++的?那就用ASM的,你不会用ASM的?那你就用VB的。。。如果你都不会,那么可无视本文。

    最近驱动也没怎么学,主要就是练习用ASM与C/C++写代码,俺是先打好基础,然后再猛追花花与炉子,要不然还怎么在0Ginr混??花花、炉子、小伟?你们说呢??嘿嘿~~

    http://hi.baidu.com/cxwr/blog/item/9d7f53387efe5af1b211c780.html
    感谢google,感谢baidu,感谢菜新。

    标签: , ,

    星期六, 十一月 03, 2007

    如何调用.so中的类

    class Base
    {
    public:
    virtual ~Base() {}

    virtual void show() = 0;
    };

    typedef Base* create_obj();
    typedef void destroy_obj(Base*);


    #include "myso01.h"
    #include <iostream>

    class ABC : public Base
    {
    public:
    void show();
    };

    void ABC::show()
    {
    std::cout << "ABC" << std::endl;
    }

    extern "C" Base* create()
    {
    return new ABC;
    }

    extern "C" void destroy(Base* p)
    {
    delete p;
    }


    #include "myso01.h"
    #include <iostream>
    #include <dlfcn.h>

    int main()
    {
    void* p_lib = dlopen("./myso01.so", RTLD_LAZY);
    if (!p_lib)
    {
    std::cout << dlerror() << std::endl;
    return 1;
    }


    create_obj* create_abc = (create_obj*)dlsym(p_lib, "create");

    char* dlsym_error = dlerror();
    if (dlsym_error)
    {
    std::cout << dlsym_error << std::endl;
    return 1;
    }

    destroy_obj* destroy_abc = (destroy_obj*)dlsym(p_lib, "destroy");
    dlsym_error = dlerror();
    if (dlsym_error)
    {
    std::cout << dlsym_error << std::endl;
    return 1;
    }

    Base* p_abc = create_abc();

    p_abc->show();

    destroy_abc(p_abc);

    dlclose(p_lib);

    return 0;
    }

    http://bbs.chinaunix.net/thread-1010447-1-1.html

    标签:

    星期二, 九月 25, 2007

    Windows中删除自己的程序(C/C++版本)

    这才是真正能删除自己的程序
    ////////////////////////////////////////////////////////

    #include
    #include

    BOOL SelfDelete()
    {
    SHELLEXECUTEINFO sei;

    TCHAR szModule [MAX_PATH],
    szComspec[MAX_PATH],
    szParams [MAX_PATH];

    // get file path names:
    if((GetModuleFileName(0,szModule,MAX_PATH)!=0) &&
    (GetShortPathName(szModule,szModule,MAX_PATH)!=0) &&
    (GetEnvironmentVariable("COMSPEC",szComspec,MAX_PATH)!=0))
    {
    // set command shell parameters
    lstrcpy(szParams,"/c del ");
    lstrcat(szParams, szModule);
    lstrcat(szParams, " > nul");

    // set struct members
    sei.cbSize = sizeof(sei);
    sei.hwnd = 0;
    sei.lpVerb = "Open";
    sei.lpFile = szComspec;
    sei.lpParameters = szParams;
    sei.lpDirectory = 0;
    sei.nShow = SW_HIDE;
    sei.fMask = SEE_MASK_NOCLOSEPROCESS;

    // increase resource allocation to program
    SetPriorityClass(GetCurrentProcess(),
    REALTIME_PRIORITY_CLASS);
    SetThreadPriority(GetCurrentThread(),
    THREAD_PRIORITY_TIME_CRITICAL);

    // invoke command shell
    if(ShellExecuteEx(&sei))
    {
    // suppress command shell process until program exits
    SetPriorityClass(sei.hProcess,IDLE_PRIORITY_CLASS);
    SetProcessPriorityBoost(sei.hProcess,TRUE);

    // notify explorer shell of deletion
    SHChangeNotify(SHCNE_DELETE,SHCNF_PATH,szModule,0);
    return TRUE;
    }
    else // if error, normalize allocation
    {
    SetPriorityClass(GetCurrentProcess(),
    NORMAL_PRIORITY_CLASS);
    SetThreadPriority(GetCurrentThread(),
    THREAD_PRIORITY_NORMAL);
    }
    }
    return FALSE;
    }
    全文:http://www.codeguru.com/cpp/w-p/win32/article.php/c4533/#more

    标签: ,

    星期三, 九月 19, 2007

    搭建跨平台编程环境Code::Blocks+wxWidgets

    Windows下
    1. 到Code::Blocks官方网站http://www.codeblocks.org下载Code::Blocks+MingGW安装包,下载后用默认设置安装。

    2. 设 置环境变量,给Path环境变量加上C:\Program Files\CodeBlocks\bin。对于Windows XP,具体方法是鼠标右击“我的电脑”,在弹出菜单中选择“属性”;在出现的对话框点选“高级”标签,然后点击下方的“环境变量”按钮,在“系统变量”中 选中“Path”并点击“编辑”按钮;在弹出对话框的“变量值”一栏的末尾加上“;C:\Program Files\CodeBlocks\bin”(引号不用加);“确定”所有对话框即可。建议重启一次计算机以使新环境变量彻底生效。

    3. 到wxWidgets官方网站http://www.wxwidgets.org下载wxWidgets安装包,下载后用默认设置安装。

    4. 打开一个命令行控制台(开始菜单->程序/所有程序->附件->命令提示符),执行下列代码进行编译:

      1. C:
      2. cd \wxWidgets-2.6.2\build\msw\
      3. mingw32-make -f makefile.gcc BUILD=release clean
      4. mingw32-make -f makefile.gcc BUILD=release

      这时候漫长的编译过程,先去干点别的

    5. ……(干别的事情)

    6. 待编译完成,打开Code::Blocks,新建一个wxWidgets工程,编译看看能不能运行。

    7. 如果以Using wxWidgets DLL建立的工程,可能运行的时候会报告缺少wxmsw26_gcc_custom.dll文件。此时可选如下三种做法之一使得程序能找到该dll:

      1. 复制C:\wxWidgets-2.6.2\lib\gcc_dll\wxmsw26_gcc_custom.dll到C:\WINDOWS\system32\;

      2. 复制C:\wxWidgets-2.6.2\lib\gcc_dll\wxmsw26_gcc_custom.dll到工程所在的文件夹;

      3. 给Path环境变量加上C:\wxWidgets-2.6.2\lib\gcc_dll\,方法仿上文所述。

    8. 如 果以Using static wxWidgets library建立的工程,可能编译(build)的时候会报告ld找不到wxmsw库。此时在菜单中选择Project -> Build options,在弹出对话框中点选“Linker”标签;点击列表中的“wxmsw”,并点击“Edit”按钮,然后将其改为“wxbase26”并确 定;点击“Add”按钮,在弹出对话框输入“wxmsw26_core”并确定,然后用旁边的三角按钮将其提升到最顶端;再编译工程即可。如果程序还用到 其它的库,还要在此添加,并注意先后顺序。

    FreeBSD下
    1. 从ports安装Code::Blocks

      以root身份执行:

      1. cd /usr/ports/devel/codeblocks/
      2. make install clean

      按理执行此命令后即会自动安装wxgtk2和wxgtk2-common两个port。如果没有安装请自行安装。

    2. 回复普通用户身份。打开Code::Blocks(可以在命令行下执行codeblocks打开,如果是csh的shell,刚安装完时需要先执行rehash),新建一个wxWidgets工程并尝试编译,如果能通过,则安装成功。

    3. 如果编译时报告`wxgtk2-2.6-config: No such file or directory,那么打开一个term,执行:

      1. wxgtk2-2.6-config --cflags

      执 行后不要关闭该term。点击Code::Blocks菜单Project->Build options,在弹出的对话框中的Compiler标签中点选Other options标签,用刚才term中输出的内容替换掉`wxgtk2-2.6-config --cflags`这一句。再在term中执行:

      1. wxgtk2-2.6-config --libs

      然后在Code::Blocks中刚才的Build options对话框里点选Linker标签,在Other linker options中用term中的输出替换掉`wxgtk2-2.6-config --libs`这一句。

    4. 重新编译工程就应该能通过了。

    http://blog.csdn.net/lixinye0123/archive/2006/12/10/1437638.aspx

    标签: , , ,

    星期六, 九月 15, 2007

    关于C语言中const指针的问题

    发信人: impactite (流星坠地*临风听雨), 信区: Programming
    标 题: Re: 关于C语言中const指针的问题
    发信站: BBS 水木清华站 (Wed May 15 14:56:24 2002)
    const int *p也就是:
    int const* p;
    表示p是一个指向常整型数据的指针,该指针的地址可以改变,
    即可以指向其它的变量,但不能通过引用该指针而改变其指向的内容
    C中的指针有四种:
    (1) type *p;
    (2) type const *p;
    (3) type *const p;
    (4) type const * const p;
    其中,type为任何一个数据类型,假设为int吧。
    第一种指针是指向变量数据的变量指针,
    指针的地址可以改变,其指针指向的内容也可以改变;
    第二种指针是指向常量数据的变量指针,
    指针的地址可以改变,但其指向的内容不允许改变;
    第三种指针是指向变量数据的常量指针,
    指针的地址不允许改变,但其指向的内容可以改变;
    第四种指针是指向常量数据的常量指针,
    指针的地址不允许改变,其指向的内容也不可以改变。
    【 在 Arnald (终结者) 的大作中提到: 】
    : const int* p意味着什么?
    : p值不能改变吗?

    标签:

    星期一, 九月 10, 2007

    Linus Torvalds炮轰C++

    Linux之父Linus Torvalds为了Linux内核开发而专门打造的版本控制软件Git已经引起

    了业界的广泛关注。昨天,有一位Dmitry Kakurin老兄在查看了源代码之后,发现使用

    的是纯C而非C++,表示不可理解,他直言:"别拿可移植性说事儿,这是屁话(BS,

    bullshit)。"(此外,他还批评Git蛮力地直接操作文本,既�嗦又易错,而且很难

    跟上高层代码逻辑。)



      这个BS引起了Torvalds的强烈反应,他用"*YOU* are full of bullshit."(你

    才满嘴屁话呢)作为自己反驳的开场白。接着,他先转向了对C++的罕见的火药味十足

    的炮轰:



      "C++是一种糟糕的(horrible)语言。而且因为有大量不够标准的程序员在使用

    而使情况更糟,以至于极容易产生彻头彻尾的垃圾(total and utter crap)。老实

    说,选择C就是为了把C++程序员踢出去。……我有这样的结论,任何喜欢用C++而不是C

    开发项目的程序员可能都是我希望踢出去的人,免得他们来搞乱我参与的项目。C++会

    导致非常非常糟糕的设计选择。你们这些C++程序员总是一上来就用语言的那些'漂亮

    的'库特性比如STL、Boost 和其他彻头彻尾的垃圾,这可能对你们的程序有所'帮

    助',但是却会导致:



      当库无法工作时无穷无尽的折磨(别跟我说什么STL尤其是Boost很稳定而且可移植

    性很好,那全是屁话,而且一点都不可笑)。低效的抽象编程模型,可能在两年之后你

    会注意到有些抽象效果不怎么样,但是所有代码已经依赖于围绕它设计的'漂亮'对象

    模型了,如果不重写应用程序,就无法改正。



      "也就是说,使用优秀的、高效的、系统级的和可移植的C++的唯一方式,最终还

    是限于使用C本身具有的所有特性。项目限制只用C,意味着参与的人不会捣乱,也意味

    着会得到许多真正懂得底层问题,而不会折腾那些白痴'对象模型'垃圾的程序员。



      "所以,我很抱歉,但是对于Git这样效率是主要目标的软件,C++的所谓优点只是

    巨大的错误。而我们将看不到这一点的人排除在外却成了一个巨大的附加优势。



      如果你想要用C++写的版本控制系统,去玩Monotone吧。他们确实使用了'真格的

    数据库',使用了'漂亮的面向对象库'、使用了'漂亮的C++抽象'。可是说老实

    话,所有这些对某些计算机专业人士而言富于吸引力的设计决定。



    转自:http://www.linuxdiyf.com/viewarticle.php?id=58478

    标签: ,

    星期日, 七月 22, 2007

    php + clucene extension的安装

    CLuceneSF上面的一个对Lucene(一个用Java写的全文检索引擎工具包)的移植,做为Lucene的C++的重新实现,以带来更快的检索速度,但是一直还不stable.这里仅仅是尝试php+clucene扩展的安装,具体应用先不管.

    安装环境:
    Freebsd 6.0 + apache 2.2 + php 5.1.2

    apache+php的安装就不说了,网上一抓一大把,注意clucene扩展必须在php5以上才能安装.

    • 首先安装clucene

    1.下载clucene
    直奔它的首页–clucene.sourceforge.net,下载clucene 0.9.10
    2.编译clucene

    tar xzvf clucene-0.9.10.tar.gz
    cd clucene-0.9.10
    ./autogen.sh
    ./configure
    make

    这样clucene就安装好了,为了让其它程序可以调用clucene,这里把编译好的lib放到系统lib目录下

    cp src/.libs/libclucene.* /usr/local/lib
    cp src/CLucene.h /usr/local/include/
    cp -r src/CLucene /usr/local/include/

    • 安装clucene php extension

    1.下载clucene php extension
    在pecl.php.net有下载,拖回来就是
    http://pecl.php.net/package/clucene

    2.编译clucene php extension

    tar xzvf clucene-0.0.9.tgz
    cd clucene-0.0.9
    cp -r /usr/local/include/Clucene include/ #编译时要把clucene的include文件弄一份
    cp -r /usr/local/include/Clucene.h include/
    phpize
    ./configure
    make

    编译完成,这里会生成一个clucene.so,我们把它放在php的extension目录下(没有就建一个),然后修改php.ini

    加入
    extension=clucene.so

    重启apache之后看phpinfo

    php+clucene

    至此安装就算完成了,demo嘛在examples目录下有一个,命令行调用方式(根据已有的index检索):
    php clucene.php “Your query”

    BTW:新出的zend framework也有lucene模块,但是功能还不完善,现在0.1.2好像只能建立索引,检索功能尚在开发中

    作者: volcano 发表于3月 22, 2006 at 2:28 pm

    版权信息: 可以任意转载, 转载时请务必以超链接形式标明文章原始出处作者信息及此声明

    标签: , , ,

    辽ICP备05003652号
    流风洄雪听天籁,轻云蔽日看落花

    Powered by Blogger