星期二, 十二月 15, 2009

IE getElementById display

Could not get the display property. Invalid argument

使用obj.style.display='none'
出现错误:
Could not get the display property. Invalid argument

function hider() {
var label, control;

if(document.getElementById && (label = document.getElementById('hidden1'))
&& (control = document.getElementById('hidden2'))
&& label.style && control.style)
{
label.style.display = control.style.display
= ('none' == label.style.display) ? '' : 'none';
}

星期二, 十二月 01, 2009

clear window update store directory

clear window update store directory

%systemdrive%\windows\SoftwareDistribution

clear

星期五, 十一月 20, 2009

wxwidgets convet wxString to C Style char

wxString 提供的 c_str,fn_str,char_str等都source code encoding相关

如果想转换成功,必须注意编译的encoding选择。

比如如果打开了unicode的编译选择,wxWidgets想从一个wxString得到一个 c Style的char *
最安全的方法为:
wxString asc=wxString("this is 汉字");
char *=asc.mb_str(wxConvUTF8);

curl 如何在mingw下使用


首先从http://curl.haxx.se/下载最新的源代码包。
比如 curl-7.19.7.tar.gz
1.然后将其展开到一个目录下,将来将要引用这里面的内容,include和lib
2.进入lib目录下:运行 mingw32-make -f Makefile.m32 编译生成所有的库.libcur.a及libcurl.dll等
3.进入/curl/docs/examples/ 编译个测试程序:
gcc -DCURL_STATICLIB -I ../../include -L ../../lib simple.c -o simple -lcurl -lws2_32 -lwinmm

运行simple.exe,能够正常运行。
CodeBlocks 里如何使用libcurl 实现static link(静态连接,避免运行使用libcurl.dll)

在codeblocks里可以在项目属性build options link setting 里加入 libcur.a的包,以及定义编译使用静态链接的属性
CURL_STATICLIB或者在使用的代码里加入:

#define CURL_STATICLIB

codeblock配置如图:


注意:如果编译的时候出现符号错误:
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_set_optionA'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_initA'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_set_optionA'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_simple_bind_sA'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_search_sA'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_first_entry'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_get_dnA'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_first_attributeA'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_get_values_lenA'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_value_free_len'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_memfreeA'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_next_attributeA'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_memfreeA'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_next_entry'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_err2stringA'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_unbind_s'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_msgfree'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_err2stringA'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_set_optionA'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_simple_bind_sA'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ber_free'
curl-7.19.7\lib\libcurl.a(ldap.o) undefined reference to `_imp__ldap_err2stringA'

这是需要连接mingw32的 ldap32 .这个需要在项目的build option link lib 里加入:
D:\MinGW\lib\libwldap32.a,顺序要注意.

libwldap32.a必须在libcurl.a的后面

星期一, 十一月 16, 2009

Windows rundll32 utility

Any program using the Windows file association mechanism can be started with the rundll32 utility.

用一个编辑器,打开一个默认后缀的文件:

RUNDLL32.EXE SHELL32.DLL,OpenAs_RunDLL c:\temp\a.txt

ere a list of what is available
rundll32 shell32,Control_RunDLL                     Run The Control Panel
rundll32 shell32,Control_RunDLL X Start applet X of Control Panel
("X" = any CPL filename)
rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,4 Regional setting, Date tab

rundll32 shell32,OpenAs_RunDLL \dir\filename.txt Open The 'Open With...' Window
rundll32 shell32,ShellAboutA Info-Box Open 'About Window Window'
rundll32 shell32,Control_RunDLL desk.cpl Open Display Properties
rundll32 user,cascadechildwindows Cascade All Windows
rundll32 user,tilechildwindows Minimize All Child-Windows
rundll32 user,repaintscreen Refresh Desktop
rundll32 keyboard,disable Lock The Keyboard
rundll32 mouse,disable Disable Mouse
rundll32 user,swapmousebutton Swap Mouse Buttons
rundll32 user,setcursorpos Set Cursor Position To (0,0)
rundll32 user,wnetconnectdialog Show 'Map Network Drive' Window
rundll32 user,wnetdisconnectdialog Show 'Disconnect Network Disk' Window
rundll32 user,disableoemlayer Display The BSOD (blue screen of death)Window
rundll32 diskcopy,DiskCopyRunDll Show Copy Disk Window
rundll32 rnaui.dll,RnaWizard Run 'Internet Connection Wizard'
rundll32 shell32,SHFormatDrive Run 'Format Disk (A)' Window
rundll32 shell32,SHExitWindowsEx -1 Cold Restart Of Windows Explorer
rundll32 shell32,SHExitWindowsEx 1 Shut Down Computer
rundll32 shell32,SHExitWindowsEx 0 Logoff Current User
rundll32 shell32,SHExitWindowsEx 2 Windows9x Quick Reboot
rundll32 krnl386.exe,exitkernel Force Windows 9x To Exit (no confirmation)
rundll32 rnaui.dll,RnaDial "MyConnect" Run 'Net Connection' Dialog
rundll32 msprint2.dll,RUNDLL_PrintTestPage Choose & Print Test Page Of Current Printer
rundll32 user,setcaretblinktime Set New Cursor Rate Speed
rundll32 user, setdoubleclicktime Set New DblClick Speed (Rate)
rundll32 sysdm.cpl,InstallDevice_Rundll Hardware installation wizard
rundll32 user,MessageBeep Default beep sound
rundll32 user32.dll,MessageBeep Default beep sound (XP)
rundll32 shell32.dll,Control_RunDLL appwiz.cpl Add/remove programs
rundll32 shell32.dll,Control_RunDLL timedate.cpl,,0 Date/time settings
rundll32 shell32.dll,Control_RunDLL odbccp32.cpl ODBC settings

rundll32.exe url.dll,FileProtocolHandler http:\\www.rgagnon.com
rundll32.exe url.dll,FileProtocolHandler c:\mypdf.pdf
Open the associated application
rundll32 amovie.ocx,RunDll /play /close c:\mymovie.mpg
Play multimedia (movie or sound)

Rundll32.exe powrprof.dll,SetSuspendState Sleep Put the computer in Sleep mode


Privacy (IE)
rundll32.exe InetCpl.cpl,ClearMyTracksByProcess 8 Internet temporary files
rundll32.exe InetCpl.cpl,ClearMyTracksByProcess 2 Cookies
rundll32.exe InetCpl.cpl,ClearMyTracksByProcess 1 History
rundll32.exe InetCpl.cpl,ClearMyTracksByProcess 16 Forms Data
rundll32.exe InetCpl.cpl,ClearMyTracksByProcess 32 Passwords
rundll32.exe InetCpl.cpl,ClearMyTracksByProcess 255 Delete everything

星期二, 十一月 03, 2009

mysql get table index SQL command

1.show index from tablename
2.select * from information_schema.statistics where table_name='tableName' ;

星期一, 十一月 02, 2009

Mysql 性能分析


EXPLAIN
SELECT * FROM table IGNORE INDEX (indexname) WHERE

星期三, 十月 28, 2009

网络地址类型一览

URL: http://publib.boulder.ibm.com/infocenter/zvm/v5r4/topic/com.ibm.zvm.v54.kijl0/hcsk7b3014.htm

The type of a IPv6 address is identified by the high-order bits of the address, as follows:

Table 2. Types of IPv6 Addresses
Address type Binary prefix IPv6 notation
Unspecified 00 . . . 0 (128 bits) ::/128
Loopback 00 . . . 1 (128 bits) ::1/128
Multicast 11111111 FF00::/8
Link-local unicast 1111111010 FE80::/10
Site-local unicast 1111111011 FEC0::/10
Global unicast (everything else)

Three categories of IP addresses are supported in IPv6:

Unicast
An identifier for a single interface. A packet sent to a unicast address is delivered to the interface identified by that address. It can be link-local scope, site-local scope, or global scope.
Multicast
An identifier for a group of interfaces (typically belonging to different nodes). A packet sent to a multicast address is delivered to all interfaces identified by that address.
Anycast
An identifier for a group of interfaces (typically belonging to different nodes). A packet sent to an anycast address is delivered to the closest member of a group, according to the routing protocols' measure of distance.

Anycast addresses are taken from the unicast address spaces (of any scope) and are not syntactically distinguishable from unicast addresses. Anycast is described as a cross between unicast and multicast. Like multicast, multiple nodes may be listening on an anycast address. Like unicast, a packet sent to an anycast address will be delivered to one (and only one) of those nodes. The exact node to which it is delivered is based on the IP routing tables in the network.

There are no broadcast addresses in IPv6. Multicast addresses have superseded this function.

Unicast IPv6 Addresses

IPv6 unicast addresses can be aggregated with prefixes of arbitrary bit-length similar to IPv4 addresses under Classless Interdomain Routing (CIDR).

A unicast address has the following format:

Figure 8. Unicast Address Format
n bits 128-n bits
network prefix interface ID

There are several types of unicast addresses in IPv6: global unicast, site-local unicast, and link-local unicast. There are also some special-purpose subtypes of global unicast, such as IPv6 addresses with embedded IPv4 addresses. Additional address types or subtypes can be defined in the future.

Global Unicast Addresses

The general format for IPv6 global unicast addresses is:

Figure 9. Global Unicast Address Format
n bits m bits 128-n-m bits
global routing prefix subnet ID interface ID

The global routing prefix is a (typically hierarchically-structured) value assigned to a site (a cluster of subnets/links). The subnet ID is an identifier of a link within the site. The interface ID is used to identify an interface on a link; interface IDs are required to be unique within a subnet prefix.

All global unicast addresses other than those that start with B'000' have a 64-bit interface ID field (that is, n + m = 64). Global unicast addresses that start with B'000' have no such constraint on the size or structure of the interface ID field.

Examples of global unicast addresses that start with B'000' are IPv6 address with embedded IPv4 addresses. These include IPv4-mapped IPv6 addresses and IPv4-compatible IPv6 addresses.

Local Use Address

There are two types of local-use unicast addresses defined: link-local and site-local. The link-local address is for use on a single link and the site-local address is for use in a single site.

Link-local Addresses

Link-local addresses have the following format:

Figure 10. Link-local address format
10 bits 54 bits 64 bits
1111111010 0 interface ID

A link-local address is required on each physical interface. Link-local addresses are designed to be used for addressing on a single link for purposes such as automatic address configuration, neighbor discovery, or in the absence of routers. It also may be used to communicate with other nodes on the same link. A link-local address is automatically assigned.

Routers will not forward any packets with link-local source or destination addresses to other links.

Site-local Addresses

Site-local addresses have the following format:

Figure 12. Site-local address format
10 bits 38 bits 16 bits 64 bits
1111111011 0 subnet ID interface ID

Site-local addresses are designed to be used for addressing inside of a site without the need for a global prefix. A site-local address cannot be reached from another site. A site-local address is not automatically assigned to a node. It must be assigned using automatic or manual configuration.

Routers will not forward any packets with site-local source or destination addresses outside of the site.

Loopback Address

The unicast address 0:0:0:0:0:0:0:1 is called the loopback address. It cannot be assigned to any physical interface. It may be thought of as a link-local unicast address assigned to a virtual interface (typically called the loopback interface) that allows local applications to send messages to each other.

The loopback address cannot be used as the source address in IPv6 packets that are sent outside of a node. An IPv6 packet with a destination address of loopback cannot be sent outside of a node and be forwarded by an IPv6 router. A packet received on an interface with destination address of loopback will be dropped.

Unspecified Address

The address 0:0:0:0:0:0:0:0 is called the unspecified address. It will not be assigned to any node. It indicates the absence of an address. One example of its use is in the Source Address field of any IPv6 packets sent by an initializing host before it has learned its own address.

The unspecified address cannot be used as the destination address of IPv6 packets or in IPv6 routing headers. An IPv6 packet with a source address of unspecified cannot be forwarded by an IPv6 router.

IPv4-mapped IPv6 Addresses

These addresses hold an embedded global IPv4 address. They are used to represent the addresses of IPv4 nodes as IPv6 addresses to applications that are enabled for IPv6 and are using AF_INET6 sockets. This allows IPv6 enabled applications always to deal with IP addresses in IPv6 format regardless of whether the TCP/IP communications are occurring over IPv4 or IPv6 networks. The dual-mode TCP/IP stack performs the transformation of the IPv4-mapped addresses to and from native IPv4 format. IPv4-mapped addresses have the following format:

Figure 14. IPv4-mapped IPv6 address
80 bits 16 32 bits
0000...0000 FFFF IPv4 address

Examples:

  • In IPv6-IPv4 decimal form:
    ::FFFF:129.144.52.38
  • In IPv6-compressed form
    ::FFFF:8190:3426
IPv4-compatible IPv6 Addresses

These addresses hold an embedded global IPv4 address. They are used dynamically to tunnel IPv6 packets over IPv4 networks. IPv6 nodes that use this technique are assigned special IPv6 unicast addresses which hold an IPv4 address in the low-order 32-bits. IPv4-compatible IPv6 addresses have the following format:

Figure 15. IPv4-compatible IPv6 address
80 bits 16 32 bits
0000...0000 0000 IPv4 address

Examples:

  • In IPv6-IPv4 decimal form
    ::129.144.52.38
  • In IPv6-compressed form
    ::8190:3426
Multicast IPv6 Addresses

An IPv6 multicast address is an identifier for a group of interfaces (typically on different nodes). It is identified with a prefix of 11111111 or FF in hexadecimal notation. It provides a way of sending packets to multiple destinations. An interface may belong to any number of multicast groups.

Multicast address format

Binary 11111111 at the start of the address identifies the address as being a multicast address. Multicast addresses have the following format:

Figure 16. Multicast address format
8 4 4 112 bits
11111111 flags scope group ID
Figure 17. Flags in multicast address
 ---------------
| 0 | 0 | 0 | T |

---------------
  • The 3 high-order flags are reserved, and must be initialized to 0.
  • T = 0 indicates a permanently-assigned (well-known) multicast address, assigned by the Internet Assigned Number Authority (IANA).
  • T = 1 indicates a non-permanently assigned (transient) multicast address.

Scope is a 4-bit multicast scope value used to limit the scope of the multicast group. Group ID identifies the multicast group, either permanent or transient, within the given scope.

Multicast scope

The scope field indicates the scope of the IPv6 internetwork for which the multicast traffic is intended. The size of this field is 4 bits. In addition to information provided by multicast routing protocols, routers use multicast scope to determine whether multicast traffic can be forwarded. For multicast addresses there are 14 possible scopes (some are still unassigned), ranging from interface-local to global (including both link-local and site-local).

The following table lists the defined values for the scope field:

Table 3. Multicast scope field values
Value Scope
0 Reserved
1 Interface-local scope (same node)
2 Link-local scope (same link)
3 Subnet-local scope
4 Admin-local scope
5 Site-local scope (same site)
8 Organization-local scope
E Global scope
F Reserved
All other scope field values are currently undefined.

For example, traffic with the multicast address of FF02::2 has a link-local scope. An IPv6 router never forwards this type of traffic beyond the local link.

Interface-local
The interface-local scope spans a single interface only. A multicast address of interface-local scope is useful only for loopback delivery of multicasts within a node, for example, as a form of interprocess communication within a computer. Unlike the unicast loopback address, interface-local multicast addresses may be joined on any interface.
Link-local
Link-local addresses are used by nodes when communicating with neighboring nodes on the same link. The scope of the link-local address is the local link.
Subnet-local
Subnet-local scope is given a different and larger value than link-local to enable possible support for subnets that span multiple links.
Admin-local
Admin-local scope is the smallest scope that must be administratively configured, that is, not automatically derived from physical connectivity or other, non-multicast-related configuration.
Site-local
The scope of a site-local address is the site or organization internetwork. Addresses must remain within their scope. A router must not forward packets outside of its scope.
Organization-local
This scope is intended to span multiple sites belonging to a single organization.
Global
Global scope is used for uniquely identifying interfaces anywhere in the Internet.
Multicast groups

Group ID identifies the multicast group, either permanent or transient, within the given scope. The size of this field is 112 bits. Permanently assigned groups can use the group ID with any scope value and still refer to the same group. Transient assigned groups can use the group ID in different scopes to refer to different groups. Multicast addresses from FF01:: through FF0F:: are reserved, well-known addresses. Use of these group IDs for any other scope values, with the T flag equal to 0, is not allowed.

All-nodes multicast groups

These groups identify all IPv6 nodes within a given scope. Defined groups include:

  • Interface-local all-nodes group (FF01::1)
  • Link-local all-nodes group (FF02::1)
All-routers multicast groups

These groups identify all IPv6 routers within a given scope. Defined groups include:

  • Interface-local all-routers group (FF01::2)
  • Link-local all-routers group (FF02::2)
  • Site-local all-routers group (FF05::2)
Solicited-node multicast group

For each unicast address which is assigned to an interface, the associated solicited-node multicast group is joined on that interface. The solicited-node multicast address facilitates the efficient querying of network nodes during address resolution.

Anycast IPv6 Addresses

An IPv6 anycast address is an identifier for a set of interfaces (typically belonging to different nodes). A packet sent to an anycast address is delivered to one of the interfaces identified by that address (the nearest interface), according to the routing protocols' measure of distance. It uses the same formats as a unicast address, so one cannot differentiate between a unicast and an anycast address simply by examining the address. Instead, anycast addresses are defined administratively.

For more information about IPv6 addressing, see RFC 3513, Internet Protocol Version 6 (IPv6) Addressing Architecture.

Java中如何得到网卡的IP地址而不是127.0.0.1

tip:最后发现,如果是web程序可以通过,javax.servlet.http .HttpServletRequest里的:getServerName()可以用来得到外部IP,很奇怪。getLocalAddr().getHostAddress()的结果不同.


String ipaddress="";
java.util.Enumeration interfaces = java.net.NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements())
{
java.net.NetworkInterface card = (java.net.NetworkInterface) interfaces.nextElement();
java.util.Enumeration addresses = card.getInetAddresses();
if (addresses == null)
continue;

while (addresses.hasMoreElements())
{
java.net.InetAddress address = (java.net.InetAddress) addresses.nextElement();
if(!address.isLoopbackAddress())//skip 127.0.0.1 address
{
if(address.isSiteLocalAddress())//yes,it,not NIC link address
{
ipaddress=address.getHostAddress();
break;
}
}
}
}

星期日, 十月 25, 2009

wxButton 如何捕获Enter回车事件

动态事件connect 需要使用wxEVT_COMMAND_BUTTON_CLICKED事件,而不是wxEVT_KEY_DOWN

wxButton *toclip = new wxButton(books,ID_BUTTON_TO_CLIP, wxT("复制剪贴板"), wxPoint(x,y));
toclip ->Connect(wxEVT_COMMAND_BUTTON_CLICKED ,wxCommandEventHandler(GlobalEvtHandler::OnPagingHandler));

星期三, 十月 21, 2009

get jboss tomcat http server config port and SSL etc

通过MBean jmx的方式来发现系统配置是个比较好的program思路
发现Mbean的几个方法如下:
那个可以工作要看不同的jboss 版本。第一个一般是可以的

1.MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer(null).get(0);
2.MBeanServer server = org.jboss.mx.util.MBeanServerLocator.locateJBoss();

InitialContext ctx = new InitialContext(table); // From table

MBeanServerConnection server = (MBeanServerConnection) ctx.lookup("jmx/invoker/HttpAdaptor");

System.out.println("Version = "
+ (String)server.getAttribute(new ObjectName("jboss.system:type=Server"), new String("Version")));


JBOSS 允许SSL及配置的数字签名文件
早server.xml或tomcat config.xml文件中加入两个属性
keystoreFile="${user.home}/.keystore" keystorePass="changeit"

然后到.keystore指定的目录下运行如下命令:

%JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA

跟随提示,密码同keystorePass属性指定的保持一致就可以了

all is ok.



星期三, 十月 14, 2009

wxWidgets 连续打开两个Dialog造成exception的原因

使用wxwidgets打开wxDialog出现一个奇怪的问题.

代码如下:
原因:
Destroy();造成了异常。
只需要最后一次打开Dialog的时候,调用Destroy()就可以了。
不知道为什么,很奇怪。

最后发现:这样解决了一场问题,但是,引用程序不会退出了,挂死了!!!!

经过再次的研究,在每次点ok按钮 退出Dialog的时候,要调用:EndModal(wxID_OK);
奇怪之极。要加入
dlg.EndModal(wxID_OK);
dlg2.EndModal(wxID_OK);



void test()
{
wxDialog dlg;
dlg.Create(NULL, wxNewId(), _T("Step 1"),
wxDefaultPosition, wxSize(500,300));
wxPanel* bgpanel=new wxPanel(&dlg, wxID_ANY, wxDefaultPosition, wxSize(dlg.GetSize().GetWidth(),dlg.GetSize().GetHeight()), wxTAB_TRAVERSAL|wxWANTS_CHARS, _T("Step 1"));
wxButton* ok = new wxButton(bgpanel,wxID_OK,_("ok"),wxPoint(bgpanel->GetSize().GetWidth()/2-50,bgpanel->GetSize().GetHeight()-60));

dlg.ShowModal();
dlg.Destroy();

wxDialog dlg2;
dlg2.Create(NULL, wxNewId(), _T("Step 2"),
wxDefaultPosition, wxSize(500,300));
wxPanel* bgpane2=new wxPanel(&dlg2, wxID_ANY, wxDefaultPosition, wxSize(dlg2.GetSize().GetWidth(),dlg2.GetSize().GetHeight()), wxTAB_TRAVERSAL|wxWANTS_CHARS, _T("step 1"));
wxButton* ok2 = new wxButton(bgpane2,wxID_OK,_("ok"),wxPoint(bgpane2->GetSize().GetWidth()/2-50,bgpane2->GetSize().GetHeight()-60));

dlg2.ShowModal();
dlg2.Destroy();
}

星期四, 九月 03, 2009

wxDateTime时间格式

strftime(3)

Name

strftime - format date and time

Synopsis

#include <time.h>
size_t strftime(char *s, size_t max, const char *format, const struct tm
*tm);
The strftime() function formats the broken-down time tm according to the format specification format and places the result in the character array s of size max.

Ordinary characters placed in the format string are copied to s without conversion. Conversion specifications are introduced by a '%' character, and terminated by a conversion specifier character, and are replaced in s as follows:

%a
The abbreviated weekday name according to the current locale.
%A
The full weekday name according to the current locale.
%b
The abbreviated month name according to the current locale.
%B
The full month name according to the current locale.
%c
The preferred date and time representation for the current locale.
%C
The century number (year/100) as a 2-digit integer. (SU)
%d
The day of the month as a decimal number (range 01 to 31).
%D
Equivalent to %m/%d/%y. (Yecch -- for Americans only. Americans should note that in other countries %d/%m/%y is rather common. This means that in international context this format is ambiguous and should not be used.) (SU)
%e
Like %d, the day of the month as a decimal number, but a leading zero is replaced by a space. (SU)
%E
Modifier: use alternative format, see below. (SU)
%F
Equivalent to %Y-%m-%d (the ISO 8601 date format). (C99)
%G
The ISO 8601 year with century as a decimal number. The 4-digit year corresponding to the ISO week number (see %V). This has the same format and value as %y, except that if the ISO week number belongs to the previous or next year, that year is used instead. (TZ)
%g
Like %G, but without century, i.e., with a 2-digit year (00-99). (TZ)
%h
Equivalent to %b. (SU)
%H
The hour as a decimal number using a 24-hour clock (range 00 to 23).
%I
The hour as a decimal number using a 12-hour clock (range 01 to 12).
%j
The day of the year as a decimal number (range 001 to 366).
%k
The hour (24-hour clock) as a decimal number (range 0 to 23); single digits are preceded by a blank. (See also %H.) (TZ)
%l
The hour (12-hour clock) as a decimal number (range 1 to 12); single digits are preceded by a blank. (See also %I.) (TZ)
%m
The month as a decimal number (range 01 to 12).
%M
The minute as a decimal number (range 00 to 59).
%n
A newline character. (SU)
%O
Modifier: use alternative format, see below. (SU)
%p
Either 'AM' or 'PM' according to the given time value, or the corresponding strings for the current locale. Noon is treated as 'pm' and midnight as 'am'.
%P
Like %p but in lowercase: 'am' or 'pm' or a corresponding string for the current locale. (GNU)
%r
The time in a.m. or p.m. notation. In the POSIX locale this is equivalent to '%I:%M:%S %p'. (SU)
%R
The time in 24-hour notation (%H:%M). (SU) For a version including the seconds, see %T below.
%s
The number of seconds since the Epoch, i.e., since 1970-01-01 00:00:00 UTC. (TZ)
%S
The second as a decimal number (range 00 to 60). (The range is up to 60 to allow for occasional leap seconds.)
%t
A tab character. (SU)
%T
The time in 24-hour notation (%H:%M:%S). (SU)
%u
The day of the week as a decimal, range 1 to 7, Monday being 1. See also %w. (SU)
%U
The week number of the current year as a decimal number, range 00 to 53, starting with the first Sunday as the first day of week 01. See also %V and %W.
%V
The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week. See also %U and %W. (SU)
%w
The day of the week as a decimal, range 0 to 6, Sunday being 0. See also %u.
%W
The week number of the current year as a decimal number, range 00 to 53, starting with the first Monday as the first day of week 01.
%x
The preferred date representation for the current locale without the time.
%X
The preferred time representation for the current locale without the date.
%y
The year as a decimal number without a century (range 00 to 99).
%Y
The year as a decimal number including the century.
%z
The time-zone as hour offset from GMT. Required to emit RFC 822-conformant dates (using "%a, %d %b %Y %H:%M:%S %z"). (GNU)
%Z
The time zone or name or abbreviation.
%+
The date and time in date(1) format. (TZ) (Not supported in glibc2.)
%%
A literal '%' character.

Some conversion specifications can be modified by preceding the conversion specifier character by the E or O modifier to indicate that an alternative format should be used. If the alternative format or specification does not exist for the current locale, the behaviour will be as if the unmodified conversion specification were used. (SU) The Single Unix Specification mentions %Ec, %EC, %Ex, %EX, %Ey, %EY, %Od, %Oe, %OH, %OI, %Om, %OM, %OS, %Ou, %OU, %OV, %Ow, %OW, %Oy, where the effect of the O modifier is to use alternative numeric symbols (say, roman numerals), and that of the E modifier is to use a locale-dependent alternative representation.

The broken-down time structure tm is defined in <time.h>. See also ctime(3).

Return Value

The strftime() function returns the number of characters placed in the array s, not including the terminating null byte, provided the string, including the terminating null byte, fits. Otherwise, it returns 0, and the contents of the array is undefined. (Thus at least since libc 4.4.4; very old versions of libc, such as libc 4.4.1, would return max if the array was too small.)

Note that the return value 0 does not necessarily indicate an error; for example, in many locales %p yields an empty string.

Environment

The environment variables TZ and LC_TIME are used.

Conforming to

SVr4, C89, C99. There are strict inclusions between the set of conversions given in ANSI C (unmarked), those given in the Single Unix Specification (marked SU), those given in Olson's timezone package (marked TZ), and those given in glibc (marked GNU), except that %+ is not supported in glibc2. On the other hand glibc2 has several more extensions. POSIX.1 only refers to ANSI C; POSIX.2 describes under date(1) several extensions that could apply to strftime() as well. The %F conversion is in C99 and POSIX.1-2001.

In SUSv2, the %S specified allowed a range of 00 to 61, to allow for the theoretical possibility of a minute that included a double leap second (there never has been such a minute).

Glibc Notes

Glibc provides some extensions for conversion specifications. (These extensions are not specified in POSIX.1-2001, but a few other systems provide similar features.) Between the % character and the conversion specifier character, an optional flag and field width may be specified. (These precede the E or O modifiers, if present.)

The following flag characters are permitted:

_
(underscore) Pad a numeric result string with spaces.
-
(dash) Do not pad a numeric result string.
  • Pad a numeric result string with zeros even if the conversion specifier character uses space-padding by default.
^
Convert alphabetic characters in result string to upper case.
#
Swap the case of the result string. (This flag only works with certain conversion specifier characters, and of these, it is only really useful with %Z).

An optional decimal width specifier may follow the (possibly absent) flag. If the natural size of the field is smaller than this width, then the result string is padded (on the left) to the specified width.

Bugs

Some buggy versions of gcc complain about the use of %c: warning: '%c' yields only last 2 digits of year in some locales. Of course programmers are encouraged to use %c, it gives the preferred date and time representation. One meets all kinds of strange obfuscations to circumvent this gcc problem. A relatively clean one is to add an intermediate function
size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm) {
return strftime(s, max, fmt, tm);

}

Example

The program below can be used to experiment with strftime().
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
char outstr[200];
time_t t;
struct tm *tmp;
t = time(NULL);
tmp = localtime(&t);
if (tmp == NULL) {
perror("localtime");
exit(EXIT_FAILURE);
}
if (strftime(outstr, sizeof(outstr), argv[1], tmp) == 0) {
fprintf(stderr, "strftime returned 0");
exit(EXIT_FAILURE);
}
printf("Result string is \"%s\"\n", outstr);
exit(EXIT_SUCCESS);
} /* main */
Some examples of the result string produced by the glibc implementation of strftime() are as follows:
$ ./a.out "%m"
Result string is "11"
$ ./a.out "%5m"
Result string is "00011"
$ ./a.out "%_5m"
Result string is " 11"

See Also

date(1), time(2), ctime(3), setlocale(3), sprintf(3), strptime(3)

星期四, 八月 20, 2009

SQLITE 3支持多线程并发访问。

需要在编译成dll或.o的时候,加入编译选项-DSQLITE_THREADSAFE=2

gcc -c sqlite3.c -o sqlite3.dll -DSQLITE_THREADSAFE=2

http://sqlite.org/threadsafe.html

星期三, 八月 19, 2009

gcc编译 vtable undefined reference错误

通过在基类中定义虚函数virtual,然后要求子类覆盖,从而实现多态是常见技术

但是这种定义,在link的时候出现 vtable ..undefined reference to 的错误,原因是gcc实现
C++规范的时候的问题,解决这个问题,是需要必须顶一个空的virtual,这样造成了,编译器
检查强迫子类覆盖的失效,非常的不爽。virtual myfunction (){}; 语法来规避错误
有人建议使用 virtual myfunction ()=0;但没有成功


http://gcc.gnu.org/faq.html#vtables
  1. class Port
  2. {
  3. private:
  4. char *brand;
  5. char style[20]; // i.e. tawny, ruby, vintage
  6. int bottles;
  7. public:
  8. Port(const char *br = "none", const char *st = "none", int b = 0);
  9. Port(const Port &p); // copy constructor
  10. virtual ~Port() { delete [] brand;}
  11. Port & operator=(const Port &p);
  12. Port & operator+=(int b);
  13. Port & operator-=(int b);
  14. int BottleCount() const {return bottles;}
  15. virtual void Show() const;
  16. friend ostream &operator<<(ostream &os, const Port &p);
  17. };
  18. class VintagePort : public Port
  19. {
  20. private:
  21. char * nickname; // i.e. The Noble, or Old Velvet, etc.
  22. int year; // vintage year
  23. public:
  24. VintagePort();
  25. VintagePort(const char *br, int b, const char *nn, int y);
  26. VintagePort(const VintagePort &vp);
  27. ~VintagePort() {delete [] nickname;}
  28. void Show() const;
  29. friend ostream & operator<<(ostream &os, const VintagePort & vp);
  30. };

星期六, 八月 15, 2009

wxWidgets RTTI 使用

为了让使用类新Java class.forName,动态载入class的方法,计划用指定class 名字,
然后再c++中载入该类.经过研究,发现wxWidgets支持RTTI。

首先需要在编译选项中加入wxUSE_EXTENDED_RTTI选项,
然后使用类似下面的方法:
#ifndef AIBASE_H
#define AIBASE_H

#include
#include

class AIBase:public wxObject,public wxThread
{

public:
AIBase();
~AIBase();
virtual void *Entry();//logic code in here
virtual void OnExit();
protected:
private:
DECLARE_DYNAMIC_CLASS(AIBase);
};

#endif // AIBASE_H

注意类必须继承来自wxObject,而且必须加入public的修饰符。

否则继承自AIBase的子类会出现,
is an inaccessible base of 'wxObject'

注意:
DECLARE_DYNAMIC_CLASS用来class定义头文件中
IMPLEMENT_DYNAMIC_CLASS用在实现的CPP 代码文件中

可以参看:
http://wiki.wxwidgets.org/RTTI

星期三, 八月 05, 2009

wxWidgets动态事件表

wxWidgets动态事件表




使用动态事件映射方法的原因,可能是你想在程序运行的不同时刻使用不同的映射关系,或者因为你使用的那种语言(例如python)不支持静态映射,或者仅仅是因为你更喜欢动态映射。因为动态映射的方法可以使你更精确的控制事件表的细节,你甚至可以单独的将事件表中的某一个条目在运行期打开或者关闭,而前面说的PushEventHandler和PopEventHandler的方法只能针对整个事件表进行处理。除此以外,动态事件处理还允许你在不同的类之间共享事件函数。
——《WxWidgets跨平台GUI开发》
导言
在wxWidgets中,相对于静态事件表那种僵死并且不知其所以然的方法,我更喜欢动态事件表,亲自Connect,还可以随时Disconnect。
但是,在写动态事件表时,会遇到一个问题,wxWidgets的官方文档中的事件处理部份,对于静态事件表所需的各种事件类型的宏叙述详尽,却对动态事件表所需的事件类型语焉不详,这给我们的使用带来了麻烦。需要的知识一方面零星分布于wx文档中,另一方面被冗长的代码掩映在中。此文的目的,就是为动态事件表的爱好者提供一个方便查询的手册,希望能给大家帮助。
大部份写GUI常用的wx类(包括窗口、对话框、控件)都继承于三个类:wxWindowwx、wxEvtHandler、wxObject。因此,大多数情况下,这三个类的成员函数是我们可以顺手牵过来用的。动态事件表的使用中,最为重要的函数Connect和Disconnect就是 wxEvtHandler的成员函数,我们可以牵过来给我们手头这个要处理事件的wx类用。
先看看官方文档里对Connect函数的介绍(我对其进行了翻译、精简,有时,为了解释的明晰,作一些补充说明):
#TRANSLATE BEGIN

wxEvtHandler::Connect
Connect函数被重载了三次,各有各的用途。
第一个版本:范围捕杀 ( [id, lastid] 且 eventType)
void Connect(int id, int lastId, wxEventType eventType, wxObjectEventFunction function, wxObject* userData = NULL, wxEvtHandler* eventSink = NULL)
第二个版本:精确狙击(id 且 eventType)
void Connect(int id, wxEventType eventType, wxObjectEventFunction function, wxObject* userData = NULL, wxEvtHandler* eventSink = NULL)
第三个版本:分门别类 (仅 eventType)
void Connect(wxEventType eventType, wxObjectEventFunction function, wxObject* userData = NULL, wxEvtHandler* eventSink = NULL)
该函数动态地将所给事件处理函数 与 EventHandler、ID 甚至事件类型联系起来。这是静态事件表的一种替代选择。
按:EventHandler直译为事件处理器,或可译为“事件手柄”(生动地模仿句柄)?后文使用“事件手柄”。
参数意义:
id
你要和事件处理函数联系起来的ID(可以是窗口ID、菜单ID、控件ID)。对于没有这个参数的重载版本,id被默认设为 wxID_ANY。
当和lastid连用时,表达的是一个ID范围,即大小介于id和last id之间的所有ID,都会被Connect函数与事件处理函数联系起来。
按:实在没必要连“ID”都译成“标识符”……其实看技术文档时,我最头痛的是一堆汉字堆在那里,包括看数学书时……
lastId
参见id中的介绍。
eventType
你要和事件处理函数联系起来的Event Type。按:Event Type直译为“事件类型”并不恰当,因为事件类型是指形如wxMouseEvent这样的东西,而这里所指,是形如wxEVT_MOTION这样的东西。准确地说,应该称之为“事件标识符”或“事件ID”。下文使用“事件ID”。一个事件类型里,会有若干事件ID,比wxMouseEvent里除了wxEVT_MOTION,还有wxEVT_LEFT_DOWN等等等事件ID。 因此可以把事件ID作为对事件类型的一个细分。
function
事件处理函数。注意这个函数应当被显式转换为正确的类型。对于类型为wxFooEvent的事件,转换使用宏wxFooEventHandler。
userData
你要和事件表项联系起来的数据。(暂时我还不知道这个有什么用)
eventSink
告诉Connect函数,你要调用的事件处理函数是谁的成员函数。如果该参数为 NULL, 那么Connect函数将使用this指针 。按:正是这个参数允许了我们在不同类中共享事件处理函数。
例子:frame->Connect( wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnQuit) );对例子的解释:wxID_EXIT是之前赋给了某一个菜单项的ID。当该菜单被选择时,会产生一个ID为wxEVT_COMMAND_MENU_SELECTED的事件。因此MyFrame::OnQuit在被显式转换为wxCommandEventHandler型的“事件手柄”之后,被Connect拉过来处理该事件。 #TRANSLATE END
就不再翻译Disconnect函数的文档了,因为除了函数名不同,它的所有参数和Connect是一模一样的。它的用途就是断开Connect所建立起来的联系。
实践中写事件处理的时候,通常使用的是Connect的后两种重载版本。参数userData和eventSink的使用是比较少的,而且也有默认值,一般不去理它就可以了。
参数id是你赋给产生了这个事件的窗口、菜单或控件的,你自己心里是清楚的。问题顶多是,你需要使用系统默认的那些ID(比如上面例子里的 wxID_EXIT),而你不知道哪个还哪个。那些ID的列表在官方文档里是有的,不过为了本文作为手册的完整性,将在本文最后给出。
有时是不需要id的,比如鼠标移动的事件:
frame->Connect(wxEVT_MOTION,wxMouseEventHandler(MyFrame::OnMouseMove));
直接把事件ID与事件手柄联系起来。 参数function的问题大一些,就是这个显式强制类型转换的这个Handler,具体叫wx什么EventHandler呢?这个问题也好解决,因为官方文档里的 Classes By Category里的Event小节已经给出了形如wxFooEvent这样的事件类型的列表,只需要在相应的事件类型后面加上Handler就可以了。同样为了本文作为手册的完整性,将在本文后面给出全部Handler的列表。
最大的问题出在参数eventType上。形如wxEVT_MOTION、wxEVT_COMMAND_MENU_SELECTED这样的事件ID的名字,我们从何得知?这些奇形怪状的名字,纵然我们英语很强,也未必能造出和wxWidgets定义的一模一样的名字啊。比如写惯MFC的同好们很容易将鼠标移动事件ID写为wxMOUSEMOVE或wxMOUSE_MOVE,可这却是错的。最糟糕的是,文档中没有提供这些名字的列表!
有些同好可能发现了,对大部份事件类型的静态事件表的宏的说明中,包含了这方面的重要信息,例如wxPaintEvent里:
EVT_PAINT(func) Process a wxEVT_PAINT event.
左边是静态事件表需要的,右边是动态事件表需要的。左手静态,右手动态,好潇洒啊!然而,倘若你要处理窗口关闭事件(假设该事件的产生不是通过菜单选择,而是点窗口右上角的红叉叉),你跑到wxCloseEvent那里一看:
EVT_CLOSE(func) Process a close event, supplying the member function. This event applies to wxFrame and wxDialog classes.
你晕了……为什么文档编写者连这都不肯告诉你?!于是你尝试着用wxEVT_CLOSE,编译器告诉你不对。已经习惯了没事翻翻头文件的你就跑到里去找了,一搜索就出来了。原来是wxEVT_CLOSE_WINDOW,这可真是情理之中意料之外啊,反正我当时是接近吐血了……
所幸这个情况并没有出现在大多数基本的事件里,但实际中总会需要处理那些不那么基本的事件的,每次都在这个细节上卡这么久的壳太不划算了。所以我把事件 ID列表从中抽出来并加以翻译,大家放在手边备查吧。这是本文的主要写作目的。

星期二, 八月 04, 2009

wxWidgets-2.8.10 undefined reference to `wxXmlResource::LoadIconW(wxString const

在C++代码中调用XRC资源
wxXmlResource::Get()->LoadIcon(_T("appIco"));
链接的时候出现:
 undefined reference to `wxXmlResource::LoadIconW(wxString const|


这个错误非常的奇怪,只是包含wx/xrc/xmlres.h,则出现这个错误
经过分析发现LoadIconW在wx/msw/winundef.h中有如下定义:

#ifdef LoadIcon
    #undef LoadIcon
    inline HICON LoadIcon(HINSTANCE hInstance, LPCTSTR lpIconName)
    {
        #ifdef _UNICODE
            return LoadIconW(hInstance, lpIconName);
        #else // ANSI
            return LoadIconA(hInstance, lpIconName);
       

星期一, 七月 20, 2009

c string to wxstring

wxwidgets的字符串转换的确让人发狂

c++ string如何转换为wxString就需要耐心。

这里是一些文章:

http://wiki.wxwidgets.org/WxString#Converting_a_Normal_String_to_a_wxString

实际的语法是这样的:
string result="hello world";

wxMessageBox(wxString(result.c_str(), wxConvUTF8));

char* chars = "你好,世界!";

c string to wxstring

wxwidgets的字符串转换的确让人发狂

c++ string如何转换为wxString就需要耐心。

这里是一些文章:

http://wiki.wxwidgets.org/WxString#Converting_a_Normal_String_to_a_wxString

实际的语法是这样的:
string result="hello world";

wxMessageBox(wxString(result.c_str(), wxConvUTF8));

boost 编译如何做?

如果安装了mingw,可以用gcc来编译boost.
在编译之前,必须首先装了cybgin或mingw或者visual c++ studio 2008,免费版本的可以在网络上直接下载.

在编辑boost必须手边编译好bjam.
这个在下载的boost 1.39解压缩的包里的:boost_1_39_0\tools\jam
在安装了vs c++ studio 2008或gcc之后就可以直接运行:build_dist.bat
如果要gcc.修改文件最后一句call .\build.bat 为 call .\build.bat gcc
就可以了。

boost编译完后,可以把所有lib和头文件复制到一个指定的目录下
这个动作需要在命令行指定install 参数

编译好bjam后,复制到安装的boost根目录下.
然后可以直接运行bjam了。

标准编译的,支持多线程,用gcc编译,编译的选项包括:
bjam install --toolset=gcc --prefix="c:\boost_1_38_0" release toolset=gcc threading=multi link=static


注意:如果不指定toolset和prefix选项,boost默认使用 mscv编译
和c:\boost_1_39_0目录安装

boost编译支持的选项可以通过bjam --help 来查看。意思如下:


--build-dir= 编译的临时文件会放在builddir里(编译完就可删除)

--stagedir= 存放编译后库文件的路径,默认是stage

--build-type=complete 编译所有版本(确切地说是相当于:variant=release, threading=multi;

link=shared|static;runtime-link=shared)

variant=debug|release 编译什么版本(Debug or Release?)

link=static|shared 使用静态库还是动态库。

threading=single|multi 单线程还是多线程库。

runtime-link=static|shared 决定是静态还是动态链接C/C++标准库。

--with- 只编译指定的库,如输入--with-regex就只编译regex库了。

--show-libraries 显示需要编译的库名称

星期五, 七月 10, 2009

wxGrid如何catch key event?

在wxWidgets 2.8.10中,
想让wxGrid catch 键盘事件,比如光标,必须在建立wxGrid的时候,需要加入wxWANTS_CHARS.

Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS, _T("ID_GRID1"));

其次:
加入事件定义,比如如下:

Connect(ID_GRID1,wxEVT_GRID_SELECT_CELL,(wxObjectEventFunction)&bonusFrame::OnGrid1CellLeftClick);

如下:
void bonusFrame::OnGrid1CellLeftClick(wxGridEvent& ev)
{
wxLogMessage(_T("Left click at row %d, col %d"), ev.GetRow(), ev.GetCol());
ev.Skip();//必须的。
}

这样就可以获得键盘光标事件了
经过一些列的需求驱动,发现了如何在wxFrame下,如何定义热键的方法
wxWidgets设计的非常的糟糕。
这里的文章很全面:

http://wiki.wxwidgets.org/Catching_key_events_globally

星期三, 七月 01, 2009

如何在唯一的wxWidgets执行文件中包含资源数据的步骤

编写xrc文件,手工编写是要让人崩溃的,可以下载http://wxformbuilder.org/ 下载用来
工具制作xrc文件

wxWidgets for C++从资源文件中静态装载图像


在wxWidgets中装载图像是非常容易的,但是如果将图像文件和可执行文件放到一起,在发布时只需要发布可执行文件,要实现这种功能,一般可以使用资 源文件来解决。在windows下的资源文件的源文件是*.rc,编译后叫*.res。在linux下类似,源文件为*.xrc,编译后叫*.xres。 但它们是xml格式的,要装载这种资源文件也得动态进行装载。相当于配置文件。

如果想将其直接编译进可执行文件。需要一个工具wxrc。这个工作在wxWidgets中的utils/wxrc目录中,可自己编译,mingw32-make -f makefile.gcc UNICODE=1 BUILD=release。可使用这个工具将*.xrc 生成c++代码,如果是图像,就将其转换成字符数组。然后和其它程序一起进行编译。可使用wxrc -c main.xrc -v -o main.h

main.xrc的格式如下:
<?xml version="1.0"?>
<resource version="2.3.0.1">
<object class="wxBitmap" name="background">background.jpg</object>
</resource>

生成的main.h的格式如下:

//
// This file was automatically generated by wxrc, do not edit by hand.
//

#include
<wx/wxprec.h>

#ifdef __BORLANDC__
#pragma hdrstop

在Visual C++的项目中添加XRC文件
虽然wxWidgets提供了XRC文件的编译器,但是把XRC的文件直接添加到Visual C++的项目中的话确没有任何效果,因为Visual C++默认能够处理的文件类型并不包含XRC文件。其实通过Visual C++的"自定义生成步骤"可以让XRC文件被自动编译:



引用:
打开项目中XRC文件的属性页。
选择"自定义生成步骤"。
在"命令行"处输入" /c /o $(InputDir)$(InputName).cpp $(InputPath)"。
在"输出"处输入"$(InputDir)$(InputName).cpp"。
在"附加依赖项"处输入XRC文件里引用的资源文件名(比如图片文件之类的),让这些资源文件被更新时XRC文件也会被重新编译。
按"确定"按钮关闭属性页。
编译XRC文件产生一个同名的C++源文件。
把XRC文件的目录下同名的C++源文件添加到项目中。
完成上步骤后,就可以让Visual C++自动把XRC文件的内容集成到二进制程序中了,以后XRC文件如果有什么改动,生成项目时会自动更新二进制程序里的XRC内容。


6 获得Windows应用程序实例句柄
声明如下函数:
代码:
    extern "C"
{
WXDLLIMPEXP_BASE HINSTANCE wxGetInstance();


}
这是wxWidgets内部使用的函数,用于获得HINSTANCE类型的。Windows应用程序实例句柄。

wxGridCellAttr SetTextColour windowXP得到异常

wxGridCellAttr SetTextColour exception
wxGridCellAttr *attrRed = new wxGridCellAttr();
attrRed->SetTextColour(wxColour(wxT("#0000ff")));
得到异常。
修改为以下语句则正常工作:

attrRed->SetTextColour(wxColour(0,0,255));

class静态成员变量link时候出现 undefined reference 错误

例子:
头文件
a.h
class a
{
public:
 static string a;
}

a.cpp
// declare class static objects
string a::format;
这样就可以解决这种link出现的  undefined reference 的错误

星期六, 六月 27, 2009

如何处理CodeBlock编译链接出现undefined rererence 的错误.

编译时候出现 :filename.cpp|| undefined reference to `CoCreateInstance@20
这种错误,是codeblock的一个bug.
需要把 链接的库加载项目的的鼠标右键的properties..里,而不是build options..里
选择properties打开project/target options窗口,右下角的按钮 Project's build options...打开
Project build options窗口,这个窗口同项目鼠标右键菜单中的build options竟然不同一,所以在设置中往往
在“正确”设置后,出现了错误,这两个窗口往往都需要同时设置,从最后产生的编译命令行分析,不过是重复加入,实在是奇怪。

需要把mingw\lib下面的库和wxWidges lib\gcc_lib或gcc_dll下面的库都加入到 ,Link  setting 下的link Libraries 里,全部加入


星期五, 六月 26, 2009

JBOSS通过JAAS框架验证用户后,如何得到用户所有的角色?

代码:

private void findRole() throws PolicyContextException {

// Get the Authenticated Subject
Subject subject = (Subject) PolicyContext.getContext("javax.security.auth.Subject.container");

// Now look for a Group called Roles
Set principals = subject.getPrincipals(Principal.class);
Iterator iter = principals.iterator();
while(iter.hasNext()) {
Principal p = (Principal)iter.next();
if(p instanceof SimpleGroup) {
SimpleGroup sg = (SimpleGroup)p;
if("Roles".equals(sg.getName())) {
Enumeration en = sg.members();
while(en.hasMoreElements()) {
String role = en.nextElement().toString();
if(role != null) {
setRole(role);
}
}
}
}
}
}

星期一, 六月 22, 2009

如何在wxWidgets 编译生成wxdbgrid组件

命令行,

wxWidgets-2.8.10\build\msw>mingw32-make -f makefile.gcc UNICODE=1 BUILD=release MONOLITHIC=0  USE_ODBC=1 USE_GUI=1


则lib\gcc_lib下得到libwxmsw28u_dbgrid.a

星期四, 六月 11, 2009

如何用cygwin在控制台 显示彩色的字符

由于cygwin支持mingw,而mingw是不依赖cygwin.dll的。而cygwin.dll是在window下模拟
Linux的API的库,这样造成了一些现实彩色字符的不同技术。

cygwin.dll直接至此ANSI 颜色控制,支持ESC 累得颜色编码,所以直接用printf("\033[1;34m hello \033[0m“)就可以打印出一个蓝色的字符串了。

 但是如果不是用cygwin.dll,而是通过-mno-cygwin编译选项,是用window crt.dll库,则ANSI颜色控制码失去了作用。此时必须使用window下的方法。

 所以,这就要求代码能区别本程序的依赖,是否使用了-mno-cygwin编译出来的代码。

 通过深入研究,发现了 -mno-cygwin编译的依赖宏,并在自己的程序根据是否有特定的宏的出现,作为信号灯来识别。
步骤如下:
发现编译器预编译的宏
g++-3 -E -dM  -mno-cygwin -c testdb.cpp  >2.txt
 生成编译器预编译文件,发现了定义的宏,通过搜索发现了:__MINGW_H 宏。
因此在自己的文件中加入:

#ifdef __MINGW_H
static int MINGW_FLAG=1;
#else
static int MINGW_FLAG=0;

Linux ANSI 颜色控制

控制码 ^ESC,在VI状态下用Ctrl+v,ESC的组合输入,


在C语言中,可以通过printf直接打印出控制符号


ANSI控制码的说明

具体的摘抄一些如下:
[0m 关闭所有属性
[1m 设置高亮度
[4m 下划线
[5m 闪烁
[7m 反显
[8m 消隐
[30m -- [37m 设置前景色
[40m -- [47m 设置背景色
[nA 光标上移n行
[nB 光标下移n行
[nC 光标右移n行
[nD 光标左移n行
[y;xH设置光标位置
[2J 清屏
[K 清除从光标到行尾的内容
[s 保存光标位置
[u 恢复光标位置
[?25l 隐藏光标
[?25h 显示光标

星期日, 六月 07, 2009

SQLITE 使用g++来编译

http://www.mail-archive.com/sqlite-users@sqlite.org/msg30132.html

SQLite is ANSI C, so youshould compile it with gcc. It will still be usable within your C++library/project, as sqlite3.h qualifies all functions extern "C".

gcc -c sqlite3.c

g++ -c main.cpp

g++ -o program main.o sqlite3.o -lpthread -ldl

星期五, 五月 01, 2009

Netbean 6.5 同cygwin c/c++ 工作生成独立.exe文件



cygwin编译生成的.exe在命令行运行的时候,会出现 需要 cygwin1.dll的提示。
非常的不方便.exe的发布。

根据提示可以在c/c++的项目 c++ 编译器里 额外的选项里加入 -mno-cygwin来利用mingw生成独立的.exe
并避免协议法律上的问题。
如图:


不过需要安装的额外的包包含如下:
通过http://cygwin.com/setup.exe 安装如下包
http://wiki.openttd.org/Cygwin
    • binutils: The GNU assembler, linker and binary utilities
    • gcc: C compiler
    • gcc-g++: GCC C++ compiler
    • gcc-mingw-core: Mingw32 support headers and libraries for GCC
    • gcc-mingw-g++: Mingw32 support headers and libraries for GCC C++
    • make: The GNU version of the 'make' utility
    • mingw-runtime: MinGW Runtime
    • subversion: A version control system
  • In the Libs section, you will need:
    • crypt: Encryption/Decryption utility and library
    • zlib: The zlib compression and decompression library
    • mingw-runtime: MinGW Runtime
    • w32api: Win32 API header and library import files
  • In the Mingw section, you will need:
    • mingw-zlib: mingw version of the zlib compression and decompression library.
  • Optionally you might want to install:
    • libpng12-devel from the Grahpics section for making PNG screenshots and loading PNG heightmaps.
    • libfreetype2-devel from the Devel section for using Windows' font in OpenTTD.

星期二, 四月 28, 2009

Visual C++ Express 2008 快捷键

调试快捷键

F7,生成解决方案(生成.exe 或项目目标)
F5,运行当前解决方案


编辑快捷键

Shift+Alt+Enter: 切换全屏编辑 Ctrl+B,T / Ctrl+K,K: 切换书签开关
Ctrl+B,N / Ctrl+K,N: 移动到下一书签 Ctrl+B,P: 移动到上一书签
Ctrl+B,C: 清除全部标签 Ctrl+I: 渐进式搜索
Ctrl+Shift+I: 反向渐进式搜索 Ctrl+F: 查找
Ctrl+Shift+F: 在文件中查找 F3: 查找下一个
Shift+F3: 查找上一个 Ctrl+H: 替换
Ctrl+Shift+H: 在文件中替换 Alt+F12: 查找符号(列出所有查找结果)
Ctrl+Shift+V: 剪贴板循环 Ctrl+左右箭头键: 一次可以移动一个单词
Ctrl+上下箭头键: 滚动代码屏幕,但不移动光标位置。 Ctrl+Shift+L: 删除当前行
Ctrl+M,M: 隐藏或展开当前嵌套的折叠状态 Ctrl+M,P: 停止大纲显示
Ctrl+M,L: 将所有过程设置为相同的隐藏或展开状态 Ctrl+E,S: 查看空白
Ctrl+E,W: 自动换行 Ctrl+G: 转到指定行
Shift+Alt+箭头键: 选择矩形文本 Alt+鼠标左按钮: 选择矩形文本
Ctrl+Shift+U: 全部变为大写 Ctrl+U: 全部变为小写

代码快捷键

Ctrl+J / Ctrl+K,L: 列出成员
Ctrl+Shift+空格键 / Ctrl+K,P: 参数信息

Ctrl+K,I: 快速信息
Ctrl+E,
Ctrl+C / Ctrl+K,Ctrl+C: 注释选定内容
Ctrl+E,
Ctrl+U / Ctrl+K,Ctrl+U: 取消选定注释内容
Ctrl+K,M: 生成方法存根

Ctrl+K,X: 插入代码段 Ctrl+K,S: 插入外侧代码
F12: 转到所调用过程或变量的定义 tab两次: 代码补齐
Alt+鼠标左按钮: 选择矩形文本
Ctrl+Shift+U: 全部变为大写
Ctrl+U: 全部变为小写

窗口快捷键

Ctrl+W,W: 浏览器窗口 Ctrl+W,S: 解决方案管理器 Ctrl+W,C: 类视图
Ctrl+W,E: 错误列表 Ctrl+W,O: 输出视图 Ctrl+W,P: 属性窗口
Ctrl+W,T: 任务列表 Ctrl+W,X: 工具箱 Ctrl+W,B: 书签窗口
Ctrl+W,U: 文档大纲 Ctrl+D,B: 断点窗口 Ctrl+D,I: 即时窗口
Ctrl+Tab: 活动窗体切换 Ctrl+Shift+N: 新建项目 Ctrl+Shift+O: 打开项目
Ctrl+Shift+S: 全部保存 Shift+Alt+C: 新建类 Ctrl+Shift+A: 新建项

VC++ Express 2008 和SQLite 一起工作

首先要下载最新的sqlite.dll,这个是纯粹C的,如果需要C++需要一个CPP的wrapper版本。
目前网络上的版本都不够及时更新,所以是个大问题。这里是比较出名的cppsqlite
http://www.codeproject.com/KB/database/CppSQLite.aspx?fid=34722&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=26

SQLITE网站上有如何编译的步骤:

http://www.sqlite.org/cvstrac/wiki?p=HowToCompile

http://www.sqlite.org/download.html 这里搜索dll可以发现最新的dll .zip下载。里面包含一个.def的文件

这个需要在安装VC++ Express 2008后,在命令行用lib来注册

星期一, 三月 30, 2009

MYSQL JDBC CachedRowSetImpl 临时表错误

问题:
In a stored procedure, if a result set is selected from a temporary table and then
deleted, a MySQLSyntaxErrorException occurs from the driver trying to perform SHOW FULL
COLUMNS on the non-existent temporary table.

解决方法:在mysql URL 里加入:
"useDynamicCharsetInfo=false"

Jboss deploy/mysql-ds.xml里加入如下语句:

<connection-url>jdbc:mysql://localhost:3306/mrp?useUnicode=TRUE</connection-url>
<connection-property name="characterEncoding">utf8</connection-property>
<connection-property name="useDynamicCharsetInfo">false</connection-property>

星期二, 三月 24, 2009

Windows环境下配置Apache 2.2.x + SSL

1.下载apache带ssl的模块

Win32 Binary including OpenSSL 0.9.8i (MSI Installer): apache_2.2.11-win32-x86-openssl-0.9.8i.msi [PGP] [MD5]

2.在安装目录bin下生成证书

openssl req -new -x509 -nodes -keyout server.key -out server.crt -subj /C=US/ST=Desert/L=SnakeTown/O=SnakeOilCo/OU=IT/CN=snakeoil.com -config ../conf/openssl.cnf

3.配置apache支持SSL
----------
设置Apache支持SSL
----------
注意: 本设置步骤针对针对Apache 2.2.x版本, 如果正在使用的是Apache 2.0.x版本, 请摸索相似的设置.

在Apache的conf目录中用文本编辑器打开httpd.conf
1. 去掉下面设置行前面的#
LoadModule ssl_module modules/mod_ssl.so
2. 去掉下面设置行前面的# (在2.0.x版本中没有这一项)
Include conf/extra/httpd-ssl.conf

3. 在Apache的conf/extra目录中打开httpd-ssl.conf, 更改如下设置. [apache安装目录]是指Apache的安装目录, 比如c:/Apache; my-server的两个文件就是前一个步骤制作的文件, 文件的位置就是这些文件在磁盘中的位置 (在2.0.x版本中这些设置仍然在 httpd.conf文件中进行)
SSLMutex default
SSLCertificateFile "[Apache安装目录]/conf/ssl/my-server.der.crt"
SSLCertificateKeyFile "[Apache安装目录]/conf/ssl/my-server.key"

4.测试

----------
测试
----------
1. 保存设置文件
2. 在开始菜单中运行Apache的Test Configuration工具, 检查设置文件是否正确
3. 重新启动Apache 2.2.x
4. 顺利启动之后, 在浏览器中输入
https://localhost 看看是否可以访问, 如果可以访问, 则设置成功!

星期五, 一月 09, 2009

SQLITE超强select case语法

1.动态决定输出,

select case
when red1%7=0 or red2%7=0 or red3%7=0 or red4%7=0 or red5%7=0 or red6%7=0 then 7
when red1%9=0 or red2%9=0 or red3%9=0 or red4%9=0 or red5%9=0 or red6%9=0 then 9
when red1%11=0 or red2%11=0 or red3%11=0 or red4%11=0 or red5%11=0 or red6%11=0 then 11
else term
end as result,rowid,count(*)
from _DBHISTORY group by result
2.标准switch case
select column_value case
when 1 then 1
when 2 then 2
else
3
end as result,rowid

from tableName