2011年5月30日

mysql 开发指南

1.创建索引

create index PENALTIES_AMOUNT on penalties(amount);

删除: drop index  PENALTIES_AMOUNT;

2.创建索引


create view  number_sets (matchno,difference) as select matchno,abs(won-lost) from matches;

删除: drop view  number_sets;

使用方法:
select * from number_sets;

3.对用户限制在某个表操作
 grant select ,update on players  to dinnery

posted @ 2011-05-30 17:23 alon 阅读(28) 评论(0) 编辑

2010年2月4日

pro javascript techniques(精通JAVASCRIPT)读书

第一章。现代JS程序设计

分离式DOM脚本编程

使用DOM定位并操作不同的DOM元素

 

<html>
<head>
<title> introduction to the dom </title>
<script>
//我们必须在文档完成加载后再操作DOM
window.onload = function() {
//获取文档中的所有 <li>
var li = document.getElementsByTagName("li");
//并给它们全部添加一个黑边框
for(var j=0;j<li.length;j++)
  {
  li[j].style.border = "1px solid #000";
  }
  //添加事件处理函数
  for(var i=0;i< li.length;i++)
  {
  li[i].onmouseover = function()
  {
  this.style.backgroundColor = 'blue';
  };

  li[i].onmouseout = function(){
this.style.backgroundColor = 'white';  //大小写必须全对,否则不显示。
  };

  }
 //获取ID 为 'everywhere'的元素,并从文档中删除
var every = document.getElementById("everywhere");
every.parentNode.removeChild(every);
};
</script>
</head>
<body>
<h1> introduction to the dom</h1>
<ul>
<li id="everywhere">it can be found.</li>
<li class="test"> it's easy to use.</li>
</ul>
</body>
</html>

 第二章   面向对象的JS

引用

1.多个变量引用同一个对象

//将OBJ 设置为空对象
var obj = new Object();
// objRef 现在是另一个对象的引用
var objRef  = obj;
//修改原对象的一个属性
obj.oneProperty = true;
//我们现在看到,这个改变在两个变量中都反映出来了,因为他们引用的是同一对象)
alert(obj.oneProperty == objRef.oneProperty);
2. 自修改对象的例子
//创建一个数组
var items = new Array("one","two");
//创建数组的一个引用
var itemsRef = items;
//将一个元素添加到原数组中
items.push("six");
//这两数组长度一样,因为他们指向同一个数组对象

 3.修改对象的引用,同时保持完整性
//将items 设置为字符串的数组
var items = new Array("one","two");
//将itemsRef 设置为items的引用
var itemsRef = items;
//将items 设置为一个新对象
items = new Array("new","array");
//items 和itemsRef 现在指向不同的对象了。
alert(items != itemsRef);

 

4.修改对象而生成新对象
//将item设置为一个新的字符串对象
var item = "test";
//itemRef 现在指向同一个字符串对象
var itemRef = item;
//将一些新文本接在这字符串后面, 注意,这会创建一个新的对象,而非修改原对象
item += "ing";

//item 和 itemRef值不相等了,因为新的字符串对象已被创建
alert(item != itemRef);

 

 

判断对象类型
 1. typeof
    if(typeof num == "string )
     num  = parseInt(num);
 2. 使用构造函数属性来判断对象的类型
   //检测我们的数学实际上是否为字符串
     if(nu.constructor ==  String)
      num = parseInt(num);
    //是否为数组
 if(str.constructor == Array)
     str = str.join(',');

   变量的类型检测

变量                    typeof变量            变量。构造函数
{an:"object"}           object                 Object
["an","array"]          object                 Array
function(){}            function               Function
"a string"              string                 String
55                      number                 Number
true                    boolean                Boolean
new User()              object                 User

 

 

一个函数,可以用来严格维护传入函数的所有参数
//用一个变量类型列表严格检查一个参数列表
function strict(types, args)
{
  //保证类型的数量和参数的数量相匹配
  if(types.length != args.length)
  {
  //否则抛出一个有用的异常
  throw "Invalid number of arguments .Expected " + types.length + ", received " + args.length + " instead.";

  }
   //遍历所有的参数,检查它们的类型
    for(var i=0 ; i < args.length ; i++)
 {
 if(args[i].constructor != types[i])
 {
 throw "Invalid argument type. Expected " + types[i].name + ",received " + args[i].constructor.name + " instead.";
 }
 }
  }
  //一个简单的函数,打印用户列表
  function userList(prefix, num,users)
  {
  //保证prefix 是字符串, num 是数字 , users 是数组
  strict( [String,Number,Array], arguments);
  //遍历 'num' 个用户
  for(var i=0; i <num ;i++)
  {
  //显示每个用户的信息
  print( prefix + ":" + users[i]);
  }
  }

 

 

闭包:(closure)
1.闭包如何使代码更清晰
//找出ID为‘main'的元素
var obj = document.getElementById("main");
//修改样式
obj.style.border = "1px solid red";
//初始化一个在一秒后执行的回调函数( callback)
setTimeout(function() {
//它将隐藏此对象
obj.style.display = 'none';
},1000);

//一个用于延时显示警告信息的通用函数
function delayedAlert(msg,time) {
//初始化一个封装的回调函数
setTimeout(function() {
// 它将使用包含本函数的外围函数传入的 msg变量
alert(msg);
},time};
}

//用两个参数调用 delayedAlert函数
delayedAlert("welcome!",2000);

 

posted @ 2010-02-04 10:19 alon 阅读(39) 评论(0) 编辑

2010年1月26日

Rundll32使用技巧 使用Shell打开选择文件对话框以及其它

Rundll32包含了很多系统的指令,下面是我摘录的关于Rundll32可以执行的命令集合。

To bring up the "Format - 3 1/2  Floppy (A:)" window:
rundll32.exe shell32.dll,SHFormatDrive

To bring up the Control Panel "Date/Time Properties" window:
rundll32.exe shell32.dll,Control_RunDLL timedate.cpl

To bring up the Control Panel "Display Properties" window:
rundll32.exe shell32.dll,Control_RunDLL desk.cpl

To bring up the Control Panel "Display Properties" window and open the third tab (the third tab is 2 because the first tab is 0):
rundll32.exe shell32.dll,Control_RunDLL timedate.cpl,@0,2

To bring up the Control Panel "Network" window:
rundll32.exe shell32.dll,Control_RunDLL netcpl.cpl

To bring up the Control Panel "System Properties" window:
rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl

To shut windows down using the Windows 3.1 API:
rundll user,exitwindows
or you can use the number that Quick View displays alongside the function name:
rundll user,#7

To try for a reboot using the Windows 3.1 API:
rundll user,exitwindowsexec
or
rundll user,#246

To shut Windows down using the Win32 API
rundll32 user.exe,#7

Make a beep
rundll user,messagebeep
rundll32 user.exe,messagebeep
rundll32 user.exe,#104

Shuts off COM2 serial port if the port was opened under the Windows 3.1 API
rundll user,closecomm
rundll32 user.exe,closecomm
rundll32 user.exe,#207

Polite windows restart
rundll user,exitwindowsexec

Polite power off
rundll user,exitwindows
rundll32 user.exe,exitwindows
rundll32 user.exe,#7

Forced immediate logoff
rundll32 user32.dll,ExitWindowsEx

Open DUN (dial up networking exported file):
rundll32.exe rnaui.dll,RnaRunImport

Start a dialup connection by name
rundll32.exe rnaui.dll,RnaDial %1

NetMeeting Speeddial CNF:
rundll32.exe msconf.dll,OpenConfLink %l

H.323 -or- Intel IPhone Internet telephony:
rundll32.exe msconf.dll,NewMediaPhone %l

URL Callto:
rundll32.exe msconf.dll,CallToProtocolHandler %l

URL:
rundll32.exe shdocvw.dll,OpenURL %l

URL Rlogin / Telnet / TN3270:
rundll32.exe url.dll,TelnetProtocolHandler %l

Email rfc822 EML:
rundll32.exe c:\windows\SYSTEM\mailnews.dll,EMLFileHandler

News rfc822 NWS:
rundll32.exe c:\windows\SYSTEM\mailnews.dll,News_RunDLL

URL File:
rundll32.exe url.dll,FileProtocolHandler %l

URL Mailto:
rundll32.exe c:\windows\SYSTEM\mailnews.dll,Mail_RunDLL

INF install:
C:\WINDOWS\rundll.exe setupx.dll,InstallHinfSection DefaultInstall 132

INF active install
rundll32.exe advpack.dll,LaunchINFSection %1, DefaultInstall

New briefcase
C:\WINDOWS\rundll32.exe syncui.dll,Briefcase_Create %1!d! %2

New LNK
RunDLL32 AppWiz.Cpl,NewLinkHere %1

open aif
rundll32 amovie.ocx,RunDll %1

play aif
rundll32 amovie.ocx,RunDll /play /close %1

open auf
C:\WINDOWS\rundll32.exe C:\WINDOWS\SYSTEM\amovie.ocx,RunDll /open %1

play auf
C:\WINDOWS\rundll32.exe C:\WINDOWS\SYSTEM\amovie.ocx,RunDll /play /close %1

open avi
C:\WINDOWS\rundll32.exe C:\WINDOWS\SYSTEM\amovie.ocx,RunDll /open %1

play avi
C:\WINDOWS\rundll32.exe C:\WINDOWS\SYSTEM\amovie.ocx,RunDll /play /close %1

open channel file
rundll32 cdfview.dll,OpenChannel %L

subscribe to channel
rundll32 cdfview.dll,Subscribe %L

print HTML
rundll32.exe C:\WINDOWS\SYSTEM\MSHTML.DLL,PrintHTML "%1"

printto HTML
rundll32.exe C:\WINDOWS\SYSTEM\MSHTML.DLL,PrintHTML "%1" "%2" "%3" "%4"

open midi
C:\WINDOWS\rundll32.exe C:\WINDOWS\SYSTEM\amovie.ocx,RunDll /open %1

play midi
C:\WINDOWS\rundll32.exe C:\WINDOWS\SYSTEM\amovie.ocx,RunDll /play /close %1

open MOV
rundll32 amovie.ocx,RunDll %1

play MOV
rundll32 amovie.ocx,RunDll /play /close %1

open MPEG
C:\WINDOWS\rundll32.exe C:\WINDOWS\SYSTEM\amovie.ocx,RunDll /open %1

play MPEG
C:\WINDOWS\rundll32.exe C:\WINDOWS\SYSTEM\amovie.ocx,RunDll /play /close %1

open sound
C:\WINDOWS\rundll32.exe C:\WINDOWS\SYSTEM\amovie.ocx,RunDll /open %1

play sound
C:\WINDOWS\rundll32.exe C:\WINDOWS\SYSTEM\amovie.ocx,RunDll /play /close %1

open unknown file
C:\WINDOWS\rundll32.exe shell32.dll,OpenAs_RunDLL %1

install screensaver
C:\WINDOWS\rundll32.exe desk.cpl,InstallScreenSaver %l
 

More great RUNDLL tips:
http://www.mvps.org/vb/tips/shellcpl.txt

http://www.rgagnon.com/pbdetails/pb-0204.html 

posted @ 2010-01-26 21:18 alon 阅读(151) 评论(0) 编辑

数据类型转换示例

刚接触VC编程的朋友往往对许多数据类型的转换感到迷惑不解,本文将介绍一些常用数据类型的使用。 

我们先定义一些常见类型变量借以说明 

int i = 100; 
long l = 2001; 
float f=300.2; 
double d=12345.119; 
char username[]="女侠程佩君"; 
char temp[200]; 
char *buf; 
CString str; 
_variant_t v1; 
_bstr_t v2; 

一、其它数据类型转换为字符串 

短整型(int) 
itoa(i,temp,10);///将i转换为字符串放入temp中,最后一个数字表示十进制 
itoa(i,temp,2); ///按二进制方式转换 
长整型(long) 
ltoa(l,temp,10); 


二、从其它包含字符串的变量中获取指向该字符串的指针 

CString变量 
str = "2008北京奥运"; 
buf = (LPSTR)(LPCTSTR)str; 
BSTR类型的_variant_t变量 
v1 = (_bstr_t)"程序员"; 
buf = _com_util::ConvertBSTRToString((_bstr_t)v1); 

三、字符串转换为其它数据类型 
strcpy(temp,"123"); 

短整型(int) 
i = atoi(temp); 
长整型(long) 
l = atol(temp); 
浮点(double) 
d = atof(temp); 

四、其它数据类型转换到CString 
使用CString的成员函数Format来转换,例如: 

整数(int) 
str.Format("%d",i); 
浮点数(float) 
str.Format("%f",i); 
字符串指针(char *)等已经被CString构造函数支持的数据类型可以直接赋值 
str = username; 

五、BSTR、_bstr_t与CComBSTR 

CComBSTR、_bstr_t是对BSTR的封装,BSTR是指向字符串的32位指针。 
char *转换到BSTR可以这样: BSTR b=_com_util::ConvertStringToBSTR

("数据");///使用前需要加上头文件comutil.h 
反之可以使用char *p=_com_util::ConvertBSTRToString(b); 


六、VARIANT 、_variant_t 与 COleVariant 

VARIANT的结构可以参考头文件VC98\Include\OAIDL.H中关

于结构体tagVARIANT的定义。 
对于VARIANT变量的赋值:首先给vt成员赋值,指明数据类型,

再对联合结构中相同数据类型的变量赋值,举个例子: 
VARIANT va; 
int a=2001; 
va.vt=VT_I4;///指明整型数据 
va.lVal=a; ///赋值 

对于不马上赋值的VARIANT,最好先用

Void VariantInit(VARIANTARG FAR* pvarg);进行初始化,其本质

是将vt设置为VT_EMPTY,下表我们列举vt与常用数据的对应关系: 

unsigned char bVal; VT_UI1 
short iVal; VT_I2 
long lVal; VT_I4 
float fltVal; VT_R4 
double dblVal; VT_R8 
VARIANT_BOOL boolVal; VT_BOOL 
SCODE scode; VT_ERROR 
CY cyVal; VT_CY 
DATE date; VT_DATE 
BSTR bstrVal; VT_BSTR 
IUnknown FAR* punkVal; VT_UNKNOWN 
IDispatch FAR* pdispVal; VT_DISPATCH 
SAFEARRAY FAR* parray; VT_ARRAY|* 
unsigned char FAR* pbVal; VT_BYREF|VT_UI1 
short FAR* piVal; VT_BYREF|VT_I2 
long FAR* plVal; VT_BYREF|VT_I4 
float FAR* pfltVal; VT_BYREF|VT_R4 
double FAR* pdblVal; VT_BYREF|VT_R8 
VARIANT_BOOL FAR* pboolVal; VT_BYREF|VT_BOOL 
SCODE FAR* pscode; VT_BYREF|VT_ERROR 
CY FAR* pcyVal; VT_BYREF|VT_CY 
DATE FAR* pdate; VT_BYREF|VT_DATE 
BSTR FAR* pbstrVal; VT_BYREF|VT_BSTR 
IUnknown FAR* FAR* ppunkVal; VT_BYREF|VT_UNKNOWN 
IDispatch FAR* FAR* ppdispVal; VT_BYREF|VT_DISPATCH 
SAFEARRAY FAR* FAR* pparray; VT_ARRAY|* 
VARIANT FAR* pvarVal; VT_BYREF|VT_VARIANT 
void FAR* byref; VT_BYREF 

_variant_t是VARIANT的封装类,其赋值可以使用强制类型转换,

其构造函数会自动处理这些数据类型。 
例如: 
long l=222; 
ing i=100; 
_variant_t lVal(l); 
lVal = (long)i; 

COleVariant的使用与_variant_t的方法基本一样,请参考如下例子: 
COleVariant v3 = "字符串", v4 = (long)1999; 
CString str =(BSTR)v3.pbstrVal; 
long i = v4.lVal; 

七、其它 

对消息的处理中我们经常需要将WPARAM或LPARAM

等32位数据(DWORD)分解成两个16位数据(WORD),例如: 
LPARAM lParam; 
WORD lovalue = LOWORD(lParam);///取低16位 
WORD hivalue = HIWORD(lParam);///取高16位 
对于16位的数据(WORD)我们可以用同样的方法分解成

高低两个8位数据(BYTE),例如: 
WORD wvalue; 
BYTE lovalue = LOBYTE(wvalue);///取低8位 
BYTE hivalue = HIBYTE(wvalue);///取高8位

posted @ 2010-01-26 21:17 alon 阅读(35) 评论(0) 编辑

VC常用数据类型

VC常用数据类型(2006.11.26):

类型              字节数 位数   范围        备注意:
char               1      8    -128-127
signed char        1      8    -128-127
unsigned char      1      8     0-255
short int          2      16   -32768-32767
signed short int   2      16   -32768-32767
unsigned short int 2      16   0-65535
int                4      32   -2147483648-2147483647
signed int         4      32   -2147483648-2147483647
unsigned int       4      32   0-4294967259
long int           4      32   -2147483648-2147483647
signed long int    4      32   -2147483648-2147483647
unsigned long int  4      32   0-4294967259
long            4         32  -2,147,483,648 to 2,147,483,647
float           4         32              3.4E +/- 38 (7 digits)
double          8         64              1.7E +/- 308 (15 digits)
long double     10        80               1.2E +/- 4932 (19 digits)
以下为windef.h中有关VC常用数据类型的定义:

typedef unsigned long       DWORD;
typedef int                 BOOL;
typedef unsigned char       BYTE;
typedef unsigned short      WORD;
typedef float               FLOAT;
typedef FLOAT               *PFLOAT;
typedef BOOL near           *PBOOL;
typedef BOOL far            *LPBOOL;
typedef BYTE near           *PBYTE;
typedef BYTE far            *LPBYTE;
typedef int near            *PINT;
typedef int far             *LPINT;
typedef WORD near           *PWORD;
typedef WORD far            *LPWORD;
typedef long far            *LPLONG;
typedef DWORD near          *PDWORD;
typedef DWORD far           *LPDWORD;
typedef void far            *LPVOID;
typedef CONST void far      *LPCVOID;
typedef int                 INT;
typedef unsigned int        UINT;
typedef unsigned int        *PUINT;
typedef WORD                ATOM;
1.使用sizeof( )可以得到任何对象占用的字节数,例如如果有一个char类型的变量a, 则sizeof(a)会返1.
2.还可以借助typedef定义自己的数据类型,例如typedef myint unsigned int;后myint就等价于unsigned int.

posted @ 2010-01-26 21:14 alon 阅读(55) 评论(0) 编辑

delphi基础

1.集合的用法
(1)
IN 判断是否存在

type
TCharset = set of char;
var
t: TCharset;

begin
t:= ['a','b','s'];
if 's' in t then
ShowMessage('in');
end;

判断是否缺乏

if not ('m' in t) then
// do something
(2)增加删除
+ ,-
Include(t,'m');
ExClude(t,'a');
(3)交集
if ['a','b']*t=['a','b'];
2.什么时候用new
 new()给指向已知大小的结构的指针分配内参,记住用Dispose()释放new()申请的任何内存
  用GetMem()或AllowMem()给未知大小的结构分配内存。并用FreeMem()清除
   AllowMem()比GetMem()安全,因为把申请到的内存初始为零
3. 创建命名类型完成a对b的赋值
type
PtrInteger = ^Integer;
var
a,b:PtrInteger;
4.类型别名
type
MInt :Integer;
强类型(strongly typed):
type
 MInt  = type integer; (MInt 与Integer不兼容)
5.类型转换

只有两个变量的数据占用的内存大小相同时才能进行

浮点转整数:Trimc()或者Round()
整数到浮点: 使用赋值
6.字符串资源:
resourcestring:
resstring ='resource'
7.参数传递
--------------------------------------
1.值参数
procedure fun(s:string);
2.引用参数
procedure fun(var s:string);
3.常量参数
procedure fun(const s:string);
4.开放数组
function fun(a:array of integer):integer;
使用high(),low(),sizeof()获得数组信息
----------------------------------------
8.

 

 

posted @ 2010-01-26 21:12 alon 阅读(21) 评论(0) 编辑

c#基础

 -.
1.数据类型存储
 *1.堆栈:存储固定长度的数据,如int(占4字节).   值类型
 *2.堆:存储可变长度的数据,如字符串.           引用类型
结构是值类型,类是引用类型
2.多维数组
 string[,] Name={{"Lennon","John"},{"MAC","Paul"}};
3.
internal  变量只能在当前程序中被访问
protected internal 变量只能在当前程序中被访问,或者在派生当前类型的其他类型中被访问
4. Static
 必须通过类直接访问该变量,而不能通过实例访问
5.Checked 与Unchecked
  执行溢出检查
  
   byte b= 255;
   checked{
    b++;
    }
6. is  检查对象是否与特定的类型兼容.
 int i =10;
if(i is object)
{
}

7.类方法
  virtual 方法可以被其派生的类重写
  New  方法隐藏了同名的继承方法
  Abstract 这个虚拟方法定义了方法名,但没有提供执行方式.不能实例化,只能派生.
  override 方法重写继承的方法或抽象的方法
  Sealed  方法重写继承的虚拟方法,但不能被派生于这个类的其他类重写,必须和重写方法一起使用。
8.方法输入参数
*1.
using System;
class ParentClass
{
 static void SomeFunction(int[] ints,int i)
 {
  ints[0]=1000;
  i=0;

 }
 public static void Main()
 {
  int i = 200;
  int[] ints={1,2,3,4};
  SomeFunction(ints,i);
  Console.WriteLine("i="+i);
  Console.WriteLine("ints[0]="+ints[0]);
 }
}
结果 200 ,1000  数组的值将改变.
*2.
using System;
class ParentClass
{
 static void SomeFunction(int[] ints,ref int i)
 {
  ints[0]=1000;
  i=0;

 }
 public static void Main()
 {
  int i = 200;
  int[] ints={1,2,3,4};
  SomeFunction(ints,ref i);
  Console.WriteLine("i="+i);
  Console.WriteLine("ints[0]="+ints[0]);
 }
}
 结果 0,1000 两方面值都将改变。 Ref用法
9. Out用法
using System;
class ParentClass
{
   static void SomeFunction(out int i)
   {
    i= 200;
   }

 public static void Main()
 {
   int i ;
   SomeFunction(out i);
   Console.WriteLine(i);

 }
}

 ----------------------------------
  二: 类
1.实例和静态方法
 如果方法不试图访问实例数据或其他实例方法,可以声明为static.不能在声明为static的方法中访问实例字段.

 public class TestClass
{
 private static unit minpasswordlength = 6;
 public static uint getminpasswordlength()
{
 return mimpasswordlength;
}
2.命名空间别名
 using alias = NameSpaceName;
3.属性
*1.private static uint MinPasswordLength
{
get
{
return minPasswordLength;
}
set
{
if(value<=10)
minPasswordLength = value;
else
Console.WriteLine("Error");
}
}

 

*2.
 public bool ChangePassword(string oldPassword,string newPassword)
{
if(oldPassword==Password&&newPassword.Length>=minPasswordLength)
{
Password =newPassword;
return true;
}
else
{
return false;
}
}

*3.
public decimal SubTotal{
   get{return _price*_quantity;}
}

4.Const
   值不能改变,并且必须在定义的时候设置。
   public const uint MaxPasswordLength  = 6;
   隐式静态,对它必须用静态成员的语法,也就是类名.
   Authenticator Julian   = new Authenticator();
   uint Max1 = Authenticator.maxPasswordLength;
   uint Max2 = Julian.maxPasswordLength;
 

 

 

posted @ 2010-01-26 21:11 alon 阅读(35) 评论(0) 编辑

vc笔记

1.
句柄(HANDLE)的东西。可以这样去理解句柄,Windows程序中产生的任何资源(要占用某一块或大或小的内存),如图标,光标,窗口,应用程序的实例(已加载到内存运行中的程序)。操作系统每产生一个这样的资源时,都要将它们放入相应的内存,并为这些内存指定一个唯一的标识号,这个标识号即该资源的句柄。
2.创建光标
CClientDC dc(this);
CFont font;
font.CreatePointFont(200,"宋体");
dc.SetTextColor(RGB(0,0,255));
dc.SelectObject(&font);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
CreateSolidCaret(tm.tmAveCharWidth/8,tm.tmHeight);
ShowCaret();

 

VC++深入详解  2007.1.16
第一章: windows程序内部运行机制
1. HWND 类型标识窗口。HINSTANCE 实例句柄.
2. typeded struct _WNDCLASS {}
位或操作: style = CS_HREDRAW|CS_VREDRAW;
取反~:
与&:
 去掉先前style 的CS_VREDRAW: style=style&~CS_VREDRAW;
3:回调函数: 不是由该函数的实现方直接调用,而是在特定的事件或条件发生时由另外一方调用,用于对该事件或条件进行响应。
实现机制:
*1: 定义一个回调函数.
*2: 提供函数实现的一方在初始化的时候,将回调函数的函数指针注册给调用者。
*3: 当特定的事件或条件发生的时候,调用者使用函数指针调用回调函数对事件进行处理。
 WNDPROC的定义(它被定义为指向窗口过程函数指针类型,格式必须与WNDPROC相同。
 typedef LRESULT (CALLBACK* WNDPROC)(HWND,UINT,WPARAM,LPARAM);
 WINDOWS程序中,回调函数必须遵循_stdcall 调用约定, 所以要使用CALLBACK.
4.HICON LoadIcon(HINSTANCE ,LPCTSTR)
 LPCTSTR: CONST CHAR * 指向字符常量的指针。 用MAKEINTRESOURCE转换图标ID(整数).
5. GetMessage 除WM_QUIT外返回非0,WM_QUIT返回0,出现错误返回-1.
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);  //虚拟键消息转为字符消息,投递到调用线程的消息队列。
DispatchMessage(&msg);
}
非0即为真
MSDN:
BOOL bRet;
while((bRet = GetMessage(&msg,NULL,0,0))!=0)
{
if(bRet==-1)
{
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
第二章 C++
1. 结构体默认情况下,其成员是公有(Public)的,类默认情况下,其成员是私有的。
2.多态: 在基类的函数前加上virtual关键字,在派生类中重写该函数,运行时将会根据对象的实际类型来调用相应的函数。

c++的多态性是由虚函数来实现的,而不是纯虚函数,在子类中如果有对基类虚函数的覆盖定义,无论该覆盖定义是否有virtual关键字,都是虚函数。

3.纯虚函数:
virtual void fun()=0
在派生类中必须完全实现基类的纯虚函数。

第四章:
1.SDK画线
 HDC dc;
 dc = ::GetDC(m_hWnd);
 MoveToEx(dc,m_pt.x,m_pt.y,NULL);
 LineTo(dc,point.x,point.y);
        ::ReleaseDC(m_hWnd,hdc);

  MFC 画线
 
        CDC* pdc = GetDC();
 pdc->MoveTo(m_pt.x,m_pt.y);
 pdc->LineTo(point.x,point.y);
 ReleaseDC(pdc);
 CClientDC 类画线 //可画到工具栏
 CClientDC dc(GetParent());
 dc.MoveTo(m_pt.x,m_pt.y);
 dc.LineTo(point.x,point.y);

 CWindowDC 类画线  //可画到工具栏,菜单栏
 CWindowDC dc(GetParent());
 dc.MoveTo(m_pt.x,m_pt.y);
 dc.LineTo(point.x,point.y);

                   //在桌面上画线
        CWindowDC dc(GetDesktopWindow());
 dc.MoveTo(m_pt.x,m_pt.y);
 dc.LineTo(point.x,point.y);
2.彩色线条
CPen pen(PS_SOLID,1,RGB(255,0,255));
CClientDC dc(this);
CPen *pens = dc.SelectObject(&pen);
dc.MoveTo(m_pt.x,m_pt.y);
dc.LineTo(point.x,point.y);
dc.SelectObject(pens);
PS_DASH:画笔的宽度小于等于1时,才有效。
3.

简单笔刷
CBrush brush(RGB(255,0,255));
CClientDC  dc(this);
dc.FillRect(CRect(m_pt,point),&brush);
位图刷
CBitmap bmp;
bmp.LoadBitmap(IDR_FFFTYPE);
CBrush brush(&bmp);
CClientDC dc(this);
dc.FillRect(CRect(m_pt,point),&brush);
透明刷
CClientDC dc(this);
CBrush *pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
CBrush *pOldBrush = dc.SelectObject(pBrush);
dc.Rectangle(CRect(m_pt,point));
dc.SelectObject(pOldBrush);
画刷句柄转换成画刷对象  FromHandle
4.静态成员函数和静态成员变量属于类本身,在类加载的时候,即为它们分配了空间,所以可以通过类名::函数名 或类名:变量名来访问,而非静态成员函数和非静态成员属于对象的方法和数据,也就是应该首先产生类的对象,然后通过类的对象去引用。
 在静态成员函数中是不能调用非静态成员的,包括非静态成员函数和非静态成员变量。
第五章:
1.文本插入符
 CClientDC dc(this);
 TEXTMETRIC tm;
 dc.GetTextMetrics(&tm);
 CreateSolidCaret(tm.tmAveCharWidth/8,tm.tmHeight);
 ShowCaret();
 BMP插入符
CBitmap  bmp;
bmp.LoadBitmap(IDB_BITMAP1);
CreateCaret(&bmp);
ShowCaret();
2.路径P159
对GetTextMetrics函数来说,它获得的是设备描述表中当前字体的度量信息,而GetTextExtent函数则是
获得某个特定的字符串在窗口中显示时所占据的宽度和高度。
第六章:
1.响应菜单项命令的顺序依次是:视类,文档类,框架类,应用程序类。

 

 

 

 

posted @ 2010-01-26 21:10 alon 阅读(36) 评论(0) 编辑

2010年1月23日

big c++ 读书笔记

第4章 基本控制流

  零警告编译

  int pennies = static_cast<int>(100 * (amount_due - amount_paid));

 输入确定

 

#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
 double area;
 cout<< "Please enter the area of a square:";
 cin>>area;


 if(cin.fail())
 {
  cout<<"error:bad input\n";
  return 1;
 }

 if( area < 0)
 {
  cout<<"error : negaive area\n";
  return 1;
 }
}

 函数注释风格

  /**

   计算

  @param  x

  @param y

  @return

 **/

 

 

#include<iostream>
#include<string>
#include<cmath>
using namespace std;

/**
 测试两个浮点数是否相近
 @param x
 @param y
 @return true 若近识相等则为真
 **/

bool approx_equal(double x,double y)
{
 const double EPSION = 1E-14;
 if(x==0) return fabs(y) <= EPSION;
 if(y==0) return fabs(x) <= EPSION;
 return fabs(x-y) / max(fabs(x),fabs(y)) <= EPSION;
}
int main()
{
  double x;
  cout<<"Enter a number;";
  cin >>x;

  double y;
  cout<<"Enter another number;";
  cin>>y;

  if(approx_equal(x,y))
   cout<<"the numbers are approximately equal.\n";
  else
   cout<<" the numbers are different.\n";
  return 0;
}

 

 第九章

 

  1. C++中 实现数据项序列有更好的办法: 向量结构。

  2.vector<double> salaries;

  salaries[0] = 32000;

 若定义向量时不带长度参数,它将是空的并不能保持元素。

  3.

 

 

 

posted @ 2010-01-23 00:54 alon 阅读(73) 评论(0) 编辑

2010年1月21日

15个mysql使用管理命令

15个mysql使用管理命令

In all the 15 mysqladmin command-line examples below, tmppassword is used as the MySQL root user password. Please change this to your MySQL root password.
1. How to change the MySQL root user password?
# mysqladmin -u root -ptmppassword password 'newpassword'

# mysql -u root -pnewpassword
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
2. How to check whether MySQL Server is up and running?
# mysqladmin -u root -p ping
Enter password:
mysqld is alive3. How do I find out what version of MySQL I am running?
Apart from giving the ‘Server version’, this command also displays the current status of the mysql server.

# mysqladmin -u root -ptmppassword version
mysqladmin  Ver 8.42 Distrib 5.1.25-rc, for redhat-linux-gnu on i686
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version          5.1.25-rc-community
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/lib/mysql/mysql.sock
Uptime:                 107 days 6 hours 11 min 44 sec

Threads: 1  Questions: 231976  Slow queries: 0  Opens: 17067
Flush tables: 1  Open tables: 64  Queries per second avg: 0.254. What is the current status of MySQL server?
# mysqladmin -u root -ptmppassword status
Uptime: 9267148
Threads: 1  Questions: 231977  Slow queries: 0  Opens: 17067
Flush tables: 1  Open tables: 64  Queries per second avg: 0.25The status command displays the following information:

Uptime: Uptime of the mysql server in seconds
Threads: Total number of clients connected to the server.
Questions: Total number of queries the server has executed since the startup.
Slow queries: Total number of queries whose execution time waas more than long_query_time variable’s value.
Opens: Total number of tables opened by the server.
Flush tables: How many times the tables were flushed.
Open tables: Total number of open tables in the database.
5. How to view all the MySQL Server status variable and it’s current value?
# mysqladmin -u root -ptmppassword extended-status
+-----------------------------------+-----------+
| Variable_name                     | Value     |
+-----------------------------------+-----------+
| Aborted_clients                   | 579       |
| Aborted_connects                  | 8         |
| Binlog_cache_disk_use             | 0         |
| Binlog_cache_use                  | 0         |
| Bytes_received                    | 41387238  |
| Bytes_sent                        | 308401407 |
| Com_admin_commands                | 3524      |
| Com_assign_to_keycache            | 0         |
| Com_alter_db                      | 0         |
| Com_alter_db_upgrade              | 0         |6. How to display all MySQL server system variables and the values?
# mysqladmin  -u root -ptmppassword variables
+---------------------------------+---------------------------------+
| Variable_name                   | Value                           |
+---------------------------------+---------------------------------+
| auto_increment_increment        | 1                               |
| basedir                         | /                               |
| big_tables                      | OFF                             |
| binlog_format                   | MIXED                           |
| bulk_insert_buffer_size         | 8388608                         |
| character_set_client            | latin1                          |
| character_set_database          | latin1                          |
| character_set_filesystem        | binary                          |

skip.....

| time_format                     | %H:%i:%s                        |
| time_zone                       | SYSTEM                          |
| timed_mutexes                   | OFF                             |
| tmpdir                          | /tmp                            |
| tx_isolation                    | REPEATABLE-READ                 |
| unique_checks                   | ON                              |
| updatable_views_with_limit      | YES                             |
| version                         | 5.1.25-rc-community             |
| version_comment                 | MySQL Community Server (GPL)    |
| version_compile_machine         | i686                            |
| version_compile_os              | redhat-linux-gnu                |
| wait_timeout                    | 28800                           |
+---------------------------------+---------------------------------+7. How to display all the running process/queries in the mysql database?
# mysqladmin -u root -ptmppassword processlist
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 20 | root | localhost |    | Sleep   | 36   |       |                  |
| 23 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+You can use this command effectively to debug any performance issue and identify the query that is causing problems, by running the command automatically every 1 second as shown below.

# mysqladmin -u root -ptmppassword -i 1 processlist
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 20 | root | localhost |    | Sleep   | 36   |       |                  |
| 23 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+

+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 24 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+8. How to create a MySQL Database?
# mysqladmin -u root -ptmppassword create testdb

# mysql -u root -ptmppassword
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 705
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| sugarcrm           |
| testdb             |
+--------------------+
4 rows in set (0.00 sec)

Note: To display all tables in a database, total number of columns, row, column types, indexes etc., use the mysqlshow command that we discussed in our previous articles.

9. How to Delete/Drop an existing MySQL database?
# mysqladmin -u root -ptmppassword drop testdb
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.

Do you really want to drop the 'testdb' database [y/N] y
Database “testdb” dropped

# mysql -u root -ptmppassword
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 707
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> show databases;
+——————–+
| Database           |
+——————–+
| information_schema |
| mysql              |
| sugarcrm           |
+——————–+
3 rows in set (0.00 sec)10. How to reload/refresh the privilege or the grants tables?
# mysqladmin -u root -ptmppassword reload;Refresh command will flush all the tables and close/open log files.

# mysqladmin -u root -ptmppassword refresh11. What is the safe method to shutdown the MySQL server?
# mysqladmin -u root -ptmppassword shutdown

# mysql -u root -ptmppassword
ERROR 2002 (HY000): Can't connect to local MySQL server
through socket '/var/lib/mysql/mysql.sock'Note: You can also use “/etc/rc.d/init.d/mysqld stop” to shutdown the server. To start the server, execute “/etc/rc.d/init.d/mysql start”

12. List of all mysqladmin flush commands.
# mysqladmin -u root -ptmppassword flush-hosts
# mysqladmin -u root -ptmppassword flush-logs
# mysqladmin -u root -ptmppassword flush-privileges
# mysqladmin -u root -ptmppassword flush-status
# mysqladmin -u root -ptmppassword flush-tables
# mysqladmin -u root -ptmppassword flush-threadsflush-hosts: Flush all information in the host cache.
flush-privileges: Reload the grant tables (same as reload).
flush-status: Clear status variables.
flush-threads: Flush the thread cache.
13. How to kill a hanging MySQL Client Process?
First identify the hanging MySQL client process using the processlist command.

# mysqladmin -u root -ptmppassword processlist
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 20 | root | localhost |    | Sleep   | 64   |       |                  |
| 24 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+Now, use the kill command and pass the process_id as shown below. To kill multiple process you can pass comma separated process id’s.

# mysqladmin -u root -ptmppassword kill 20

# mysqladmin -u root -ptmppassword processlist
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 26 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+14. How to start and stop MySQL replication on a slave server?
# mysqladmin  -u root -ptmppassword stop-slave
Slave stopped

# mysqladmin  -u root -ptmppassword start-slave
mysqladmin: Error starting slave: The server is not configured as slave;
fix in config file or with CHANGE MASTER TO15. How to combine multiple mysqladmin commands together?
In the example below, you can combine process-list, status and version command to get all the output together as shown below.

# mysqladmin  -u root -ptmppassword process status version
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host      | db | Command | Time | State | Info             |
+----+------+-----------+----+---------+------+-------+------------------+
| 43 | root | localhost |    | Query   | 0    |       | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+

Uptime: 3135
Threads: 1  Questions: 80  Slow queries: 0  Opens: 15  Flush tables: 3
Open tables: 0  Queries per second avg: 0.25

mysqladmin  Ver 8.42 Distrib 5.1.25-rc, for redhat-linux-gnu on i686
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version          5.1.25-rc-community
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/lib/mysql/mysql.sock
Uptime:                 52 min 15 secYou can also use the short form as shown below:

# mysqladmin  -u root -ptmppassword pro stat verUse the option -h, to connect to a remote MySQL server and execute the mysqladmin commands as shown below.

# mysqladmin  -h 192.168.1.112 -u root -ptmppassword pro stat ver

 

posted @ 2010-01-21 00:04 alon 阅读(168) 评论(0) 编辑