星期五, 六月 25, 2010
ABAP 动态定义select help
编写自己的 trigger POV 事件.更加灵活
*&---------------------------------------------------------------------*
*& Report Z_SEARCH_HELP
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_SEARCH_HELP NO STANDARD PAGE HEADING.
TABLES: pa0001.
parameters: ppernr type pa0001-pernr .
DATA: i_return TYPE ddshretval OCCURS 0 WITH HEADER LINE,
c TYPE c VALUE 'S'.
* Search Help for Ppernr-low
AT SELECTION-SCREEN ON VALUE-REQUEST for ppernr.
message 'request value?' type 'I'.
TYPES: BEGIN OF t_pernr,
pernr LIKE pa0001-pernr,
ename LIKE pa0001-ename,
END OF t_pernr.
DATA: it_pa0001 TYPE STANDARD TABLE OF t_pernr WITH HEADER LINE.
SELECT pernr ename from pa0001
INTO CORRESPONDING FIELDS OF TABLE it_pa0001
where pa0001~endda = '99991231' .
* WHERE zsdo~kunnr IN sokunnr.
DELETE it_pa0001 WHERE pernr = '00000000'.
SORT it_pa0001 BY pernr.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'PERNR'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'PERNR'
value_org = c
TABLES
value_tab = it_pa0001
return_tab = i_return.
如何在用户登录时sap时自动执行一特定程序
1)SE37然后如图操作
使用函数 'NAVIGATION_SET_START_TCODE' ,用该函数可以设置用户和一个TCODE,该TCODE当用户登录sap系统后就可以自动执行。sap对应的程 序:ADMIN_SET_START_TRANSACTION_FO
2)使用用户出口(user Exit)
该用户出口的模块名称是:SUSR0001,你可以在该单元里增加你的代码进行相应的控制。.
SAP用户登录增强示例
* Transaction CMOD -> Utiliteis -> SAP Enhancements
* Exit Name SUSR0001
* Double click EXIT_SAPLSUSF_001
* Double click ZXUSRU01
* Insert -> include zsesschk.
** zsesschk limits the number of login sessions per user
* in a certain client
* It runs from user exit SUSR0001 after the SAP Login
* n-1 is the number of concurrent sessions allowed
TABLES: UINFO.
DATA: N TYPE I VALUE 2. "Upper limit of login sessions
DATA: OPCODE TYPE X VALUE 2, I TYPE I, A(60).
DATA: BEGIN OF BDC_TAB1 OCCURS 5.
INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDC_TAB1.
DATA: BEGIN OF USR_TABL OCCURS 10.
INCLUDE STRUCTURE UINFO.
DATA: END OF USR_TABL.
* Exclude Limit login by Users
IF SY-UNAME <> 'XXX'
AND SY-UNAME <> 'XXX'.
CALL 'ThUsrInfo' ID 'OPCODE' FIELD OPCODE
ID 'TAB' FIELD USR_TABL-*SYS*.
LOOP AT USR_TABL.
IF SY-UNAME = USR_TABL-BNAME AND SY-MANDT = USR_TABL-MANDT.
I = I + 1.
ENDIF.
ENDLOOP.
IF I >= N.
A = 'You have already '.
A+17(2) = I - 1.
A+19(25) = 'login sessions in client '.
A+44(4) = SY-MANDT.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
TITEL = 'UNSUCCESSFUL LOGIN'
TXT1 = A
TXT2 = 'You are not allowed to log in'.
MOVE: 'SAPMSSY0' TO BDC_TAB1-PROGRAM,
'120' TO BDC_TAB1-DYNPRO,
'X' TO BDC_TAB1-DYNBEGIN.
APPEND BDC_TAB1.CLEAR BDC_TAB1.
MOVE: 'BDC_OKCODE' TO BDC_TAB1-FNAM,
'/nex' TO BDC_TAB1-FVAL.
APPEND BDC_TAB1.CLEAR BDC_TAB1.
CALL TRANSACTION 'SM04' USING BDC_TAB1 MODE 'N'.
ENDIF.
ENDIF.
星期一, 六月 14, 2010
Emacs Lisp 如何配置. macrs 文件 c-x -c-f
(setq inferior-lisp-program "d:\\sbcl\\1.0.37\\sbcl.exe")
(require 'slime)
(slime-setup)
(add-to-list 'load-path "D:\\color-theme-6.6.0")
(require 'color-theme)
(eval-after-load "color-theme"
'(progn
(color-theme-initialize)
(color-theme-hober)))
星期六, 六月 12, 2010
Lisp 提示在read之后才出来
(format t "Please enter a number. ")
(let ((val (read)))
(if (numberp val)
val
(ask-number))))
(defvar val)
(setf val (ask-number))
(defparameter *s* (open "f:\\temp\\mytest.txt" :direction :output :if-does-not-exist :create :if-exists :append))
(format *s* "your input:~A~%" val)
(close *s*)
原因:
format 需要输出一个新行后,才会刷新,所以,加入~%
(format t "Please enter a number. ~%")
星期五, 六月 04, 2010
ABAP处理所有异常
语法,
TRY.
... " TRY block (application coding)
CATCH cx_... cx_... ...
... " CATCH block (exception handler)
CATCH cx_... cx_... ...
... " CATCH block (exception handler)
...
CLEANUP.
... " CLEANUP block (cleanup context)
ENDTRY.
如果想处理所有异常,使用
catch cx_root.
- A TRY block, in which exceptions can occur.
This exception block consists of all the statements between the TRY and the CATCH statement. - One or more CATCH blocks for catching exceptions.
These exception blocks are initiated with CATCH and ended with a further CATCH, CLEANUP, or ENDTRY. - A CLEANUP block for cleanup work after the exceptions have been caught.
This statement block is initiated by CLEANUP and ended with ENDTRY. A TRY-ENDTRY structure must not contain more than one CLEANUP block in precisely this position.
星期一, 五月 31, 2010
LISP CDR 和 CAR意思
而 cons 就是透过这两个缓存器而实作的。) Cons 很容易使用:
星期五, 五月 28, 2010
如何在Java Mail中是用Log4j来记录Java Mail Debug 信息?的
但是这个debug是直接输出到System.out的,需要用 >>来截获。
不过Java Mail 提供了setDebugOut(PrintStream)的接口,
就用这个可以实现 Java Mail和 log4j的联合使用
首先编写一个PrintStream的类做一个Bridge 同 Log4j
package com.email;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.log4j.*;
/**
*
* @author U253MIS038
*/
public class LoggingOutputStream extends OutputStream
{
protected boolean hasBeenClosed = false;
protected byte[] buf;
protected int count;
private int bufLength;
public static final int DEFAULT_BUFFER_LENGTH = 2048;
protected Logger logger;
protected Level level;
private LoggingOutputStream()
{
}
public LoggingOutputStream(Logger log, Level level)
throws IllegalArgumentException {
if (log == null) {
throw new IllegalArgumentException("cat == null");
}
if (level == null) {
throw new IllegalArgumentException("priority == null");
}
this.level = level;
logger = log;
bufLength = DEFAULT_BUFFER_LENGTH;
buf = new byte[DEFAULT_BUFFER_LENGTH];
count = 0;
}
public void close()
{
flush();
hasBeenClosed = true;
}
public void write(final int b) throws IOException
{
if (hasBeenClosed) {
throw new IOException("The stream has been closed.");
}
if (count == bufLength)
{
final int newBufLength = bufLength + DEFAULT_BUFFER_LENGTH;
final byte[] newBuf = new byte[newBufLength];
System.arraycopy(buf, 0, newBuf, 0, bufLength);
buf = newBuf;
bufLength = newBufLength;
}
buf[count] = (byte) b;
count++;
}
public void flush()
{
if (count == 0)
{
return;
}
if (count == 1 && ((char) buf[0]) == '\n')
{
reset();
return;
}
final byte[] theBytes = new byte[buf.length];
System.arraycopy(buf, 0, theBytes, 0, count);
logger.log(level, new String(theBytes));
reset();
}
private void reset()
{
count = 0;
}
}
2,然后再调用Java Mail中使用如下方法实现了定向
static Logger log = Logger.getLogger( email.class );
Properties props = System.getProperties();
config = new PropertiesConfiguration(PROP_FILE);
String mailip = config.getString("EMAIL_SERVER_IP");
props.put("mail.smtp.host", mailip);
Session session = Session.getInstance(props, null);
session.setDebugOut(new PrintStream(new LoggingOutputStream(Logger.getRootLogger(),Level.DEBUG), true));
session.setDebug(enableDebug);
星期一, 五月 24, 2010
java 如何确定一个对象是否数组?
Java array reflection: isArray vs. instanceof
那个方法好呢?if(obj.getClass().isArray()) {}
and
if(obj instanceof Object[]) {}
| In general, use the At the JVM level, the The reflective approach ( There are two special cases: null references and references to primitive arrays. A null reference will cause Applied to a primitive array, the |
Ifobjis of typeint[]say, then that will
have an arrayClassbut not be an instance ofObject[].
So what do you want to do withobj. If you are going to
cast it, go withinstanceof. If you are going to use
reflection, then use.getClass().isArray().
总结:
isArray的方位更加广泛。
instance Object[]不能确别int[]等数组。
所以,那个更好,要看自己的具体情况了
星期六, 五月 15, 2010
Lisp命名规则2
低级函数用%开始和技术(%SUM%).语言标准名字的定义只允许用字母(A-Z)和*,+,-,/,1,2,<,=,> &
self-evaluating:
自执行
最重要的两个自执行常量:T和NIL代表 true和false.
另一类最重要的自执行符号是关键词符号.其名字以:开始
最基本的程序组件:
函数,变量,及宏
function,variable,macro
星期五, 五月 14, 2010
Lisp的命名
的名字是否用在变量,函数或其它东西一无所知。.它只是按照字符序列读出并被代表一个对象的名字。
几乎所有的字符都可用在名字中.空白字符不行,因为在list中元素也是用空白字符来分割的.
数字也可以用在名字中的一部分而不是解释成一个数字.相似的,名字可以包含一个句号(.),但无法阅读
只包含一个句号的名字。10个字符用于其他目的而不能在名字中出现:
- 1.开始和结束括号() open and close parentheses
- 2.双引号和单引号 "' double and single quotes
- 3.反引号(`)backtick
- 4.逗号 comma,
- 5.冒号: colon
- 6.分号;semicolon
- 7.反斜线 \ backslash
- 8.竖线| vertical bar
星期一, 五月 10, 2010
Re: Lisp注释语句.
缩进规则:
函数调用形式参数对齐
宏和特殊形式针对最后一个左括号缩进两格
;;;; 文件级别注释
;;; 段落级别注释
;; 函数内部代码注释
; 函数内部代码单行注释,放在代码后面
在阅读 Practical Common Lisp书的时候,突然想到LISP的注释符号应该是如何写呢?
google了下。
http://www.cc.gatech.edu/computing/classes/cs2360/ghall/style/com_mechanics.html
单句注释;分号表示 ;;;header
块注释 #|
Notes:zh
#
另外一种非常规的注释,是在代码中用“ ”来表示,比如下列代码(defun mumble_fcn ( arg1 arg2 )
"This function takes two arbitrary arguments and returns some
arbitrarily random result. NOTE: both arguments should be non-nil."
(do-random-thing (do-random-thing arg1 ) arg2 ))
星期五, 五月 07, 2010
SAP NetWeaver Composition Environment 7.2 Trial Version 安装 步骤 Create secure store 出现错误
首先下载了jdk 1.6.0_07之上的版本,我下载的是 1.6.0_20版本,并且下载了jce 6的文件,很小只有8K.
安装到步骤时候出现错误:
安装 :18/29的时候,Create secure store
根据提示打开错误日志:
C:\Program Files\sapinst_instdir\NW72_DEV_ADA\SERVER\SecureStoreCreate.log
发现如下提示:
FATAL: Main class "com.sap.security.core.server.secstorefs.SecStoreFS" cannot be started:
FATAL: java.lang.ExceptionInInitializerError
at javax.crypto.Cipher.getInstance(DashoA13*..)
at javax.crypto.Cipher.getInstance(DashoA13*..)
at iaik.security.provider.IAIK.a(Unknown Source)
at iaik.security.provider.IAIK.addAsJDK14Provider(Unknown Source)
at iaik.security.provider.IAIK.addAsJDK14Provider(Unknown Source)
at com.sap.security.core.server.secstorefs.Crypt.<clinit>(Crypt.java:85)
at com.sap.security.core.server.secstorefs.SecStoreFS.setSID(SecStoreFS.java:177)
at com.sap.security.core.server.secstorefs.SecStoreFS.handleCreate(SecStoreFS.java:838)
at com.sap.security.core.server.secstorefs.SecStoreFS.main(SecStoreFS.java:1308)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sap.engine.offline.OfflineToolStart.main(OfflineToolStart.java:161)
Caused by: java.lang.SecurityException: Cannot set up certs for trusted CAs
at javax.crypto.SunJCE_b.<clinit>(DashoA13*..)
... 14 more
Caused by: java.lang.SecurityException: Cannot locate policy or framework files!
at javax.crypto.SunJCE_b.i(DashoA13*..)
at javax.crypto.SunJCE_b.g(DashoA13*..)
at javax.crypto.SunJCE_b$1.run(DashoA13*..)
at java.security.AccessController.doPrivileged(Native Method)
... 15 more
FATAL: com.sap.engine.offline.OfflineToolStart will abort now with exitcode 2
Solution:
copy
C:\Program Files\Java\jre6\lib\security 下所有文件到sap临时安装JVM目录下,
如果有提示是否需要覆盖,不要覆盖SAP原来的文件。
to
C:\Program Files\sapinst_instdir\NW72_DEV_ADA\SERVER\sapjvm\sapjvm_6\jre\lib\security
Lisp注释语句.
google了下。
http://www.cc.gatech.edu/computing/classes/cs2360/ghall/style/com_mechanics.html
单句注释;分号表示 ;;;header
块注释 #|
Notes:zh
#
另外一种非常规的注释,是在代码中用“ ”来表示,比如下列代码
(defun mumble_fcn ( arg1 arg2 )
"This function takes two arbitrary arguments and returns some
arbitrarily random result. NOTE: both arguments should be non-nil."
(do-random-thing (do-random-thing arg1 ) arg2 ))
星期二, 四月 20, 2010
数据库Auto time stamp字段
ts2 TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
MSSQL:支持:
版本戳 timestamp 字段类型。
星期一, 四月 19, 2010
星期二, 一月 26, 2010
jsp code too large for try statement
在JAVA_OPTS里加入以下变量:
1.java -Dcom.sun.tools.javac.main.largebranch=true
java lib\tools.jar 包内
注意,如果装有多个版本的JDK,需要通过设置JAVA_HOME来指明使用的JDK的路径
只是在path中加入是不够的。
星期三, 一月 06, 2010
Linux文件名包含特殊字符无法使用通配符:Argument list too long
会出现:Argument list too long错误
简单解决办法,同find 一起使用
find . -exec grep -l "搜索字符" "{}" \;
列出包含 “搜索字符”的文件名
星期二, 十二月 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
星期三, 十月 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:
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:
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:
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:
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 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
- class Port
- {
- private:
- char *brand;
- char style[20]; // i.e. tawny, ruby, vintage
- int bottles;
- public:
- Port(const char *br = "none", const char *st = "none", int b = 0);
- Port(const Port &p); // copy constructor
- virtual ~Port() { delete [] brand;}
- Port & operator=(const Port &p);
- Port & operator+=(int b);
- Port & operator-=(int b);
- int BottleCount() const {return bottles;}
- virtual void Show() const;
- friend ostream &operator<<(ostream &os, const Port &p);
- };
-
- class VintagePort : public Port
- {
- private:
- char * nickname; // i.e. The Noble, or Old Velvet, etc.
- int year; // vintage year
- public:
- VintagePort();
- VintagePort(const char *br, int b, const char *nn, int y);
- VintagePort(const VintagePort &vp);
- ~VintagePort() {delete [] nickname;}
- void Show() const;
- friend ostream & operator<<(ostream &os, const VintagePort & vp);
- };
星期六, 八月 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
订阅:
博文 (Atom)
使用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
%systemdrive%\windows\SoftwareDistribution
clear
星期五, 十一月 20, 2009
wxwidgets convet wxString to C Style char
如果想转换成功,必须注意编译的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
用一个编辑器,打开一个默认后缀的文件:
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
2.select * from information_schema.statistics where table_name='tableName' ;
星期一, 十一月 02, 2009
星期三, 十月 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:
| 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:
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:
| 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:
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:
| 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:
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:
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:
---------------
| 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:
| 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
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回车事件
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的几个方法如下:
那个可以工作要看不同的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 tablekeystoreFile="${user.home}/.keystore" keystorePass="changeit"
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文件中加入两个属性
然后到.keystore指定的目录下运行如下命令:
%JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA
跟随提示,密码同keystorePass属性指定的保持一致就可以了all is ok.
星期三, 十月 14, 2009
wxWidgets 连续打开两个Dialog造成exception的原因
代码如下:
原因:
Destroy();造成了异常。
只需要最后一次打开Dialog的时候,调用Destroy()就可以了。
不知道为什么,很奇怪。
最后发现:这样解决了一场问题,但是,引用程序不会退出了,挂死了!!!!
经过再次的研究,在每次点ok按钮 退出Dialog的时候,要调用:EndModal(wxID_OK);
奇怪之极。要加入
dlg.EndModal(wxID_OK);
dlg2.EndModal(wxID_OK);
{
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时间格式
Name
strftime - format date and timeSynopsis
#include <time.h>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.
size_t strftime(char *s, size_t max, const char *format, const struct tm
*tm);
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 functionsize_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>Some examples of the result string produced by the glibc implementation of strftime() are as follows:
#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 */
$ ./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支持多线程并发访问。
gcc -c sqlite3.c -o sqlite3.dll -DSQLITE_THREADSAFE=2
http://sqlite.org/threadsafe.html
星期三, 八月 19, 2009
gcc编译 vtable undefined reference错误
但是这种定义,在link的时候出现 vtable ..undefined reference to 的错误,原因是gcc实现
C++规范的时候的问题,解决这个问题,是需要必须顶一个空的virtual,这样造成了,编译器
检查强迫子类覆盖的失效,非常的不爽。virtual myfunction (){}; 语法来规避错误
有人建议使用 virtual myfunction ()=0;但没有成功
http://gcc.gnu.org/faq.html#vtables
class Port { private: char *brand; char style[20]; // i.e. tawny, ruby, vintage int bottles; public: Port(const char *br = "none", const char *st = "none", int b = 0); Port(const Port &p); // copy constructor virtual ~Port() { delete [] brand;} Port & operator=(const Port &p); Port & operator+=(int b); Port & operator-=(int b); int BottleCount() const {return bottles;} virtual void Show() const; friend ostream &operator<<(ostream &os, const Port &p); }; class VintagePort : public Port { private: char * nickname; // i.e. The Noble, or Old Velvet, etc. int year; // vintage year public: VintagePort(); VintagePort(const char *br, int b, const char *nn, int y); VintagePort(const VintagePort &vp); ~VintagePort() {delete [] nickname;} void Show() const; friend ostream & operator<<(ostream &os, const VintagePort & vp); };
星期六, 八月 15, 2009
wxWidgets RTTI 使用
然后再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'
注意:
IMPLEMENT_DYNAMIC_CLASS用在实现的CPP 代码文件中
http://wiki.wxwidgets.org/RTTI
星期三, 八月 05, 2009
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,编译器告诉你不对。已经习惯了没事翻翻头文件的你就跑到
所幸这个情况并没有出现在大多数基本的事件里,但实际中总会需要处理那些不那么基本的事件的,每次都在这个细节上卡这么久的壳太不划算了。所以我把事件 ID列表从
。
星期二, 八月 04, 2009
wxWidgets-2.8.10 undefined reference to `wxXmlResource::LoadIconW(wxString const
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
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
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 编译如何做?
在编译之前,必须首先装了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=
--stagedir=
--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-
--show-libraries 显示需要编译的库名称
星期五, 七月 10, 2009
wxGrid如何catch key event?
想让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