2009年9月22日		  
		
			
					
			使用wininet
一般流程:
1,
BOOL AFXAPI AfxParseURLEx(
LPCTSTR pstrURL,
DWORD& dwServiceType,
CString& strServer,
CString& strObject,
INTERNET_PORT& nPort,
CString& strUsername,
CString& strPassword,
DWORD dwFlags = 0
);  使用该函数解析URP
其中 strServer  :The first segment of the URL following the service type.
2,
GetHttpConnection()
3,
OpenRequest()
4,
AddRequestHeaders() 通用头 域包含请求和响应消息都支持的头域
5,
SendRequest
6,
QueryInfo
 
					
			
		 
	
	
		
	
	2009年5月20日		  
		
			
					
			
用pDC->SetBkMode(TRANSPARENT);
设置透明后,要改变控件的文字就会发生文字重叠,如果不使用透明就不会,请问在透明状态下改变文字如何不发生重叠?
static的背景已经是透明的了,那么残留的文本应该是画在static的父窗口上的。
办法有了:在给static 设置新的文本之后(不是之前!)刷新父窗口。
void CTestStaticDlg::OnTimer(UINT nIDEvent) 
{
       CString strTime;
       CTime time = CTime::GetCurrentTime();
       strTime = time.Format("%y年%m月%d日 %H:%M:%S");
 
       GetDlgItem(IDC_STATIC)->SetWindowText(strTime);
       GetDlgItem(IDC_STATIC)->GetParent()->RedrawWindow(); //就这两句话而已,呵呵
       CDialog::OnTimer(nIDEvent);
}
					
			
		 
	
	
		
	
	2009年4月23日		  
		
			
					
			PreTranslateMessage(MSG*   pMsg)     
  {   
  if(   pMsg->message   ==   WM_KEYDOWN   )   
  {                   
  switch(   pMsg->wParam   )   
  {   
  case   VK_RETURN:   
  AfxMessageBox("return");   
  }   
  }   
  return   CDialog::PreTranslateMessage(pMsg);   
  }   
重写该函数,  就可以截获键盘消息.
			
		
			
		 
	
	
		
	
	2009年4月22日		  
		
			
					
			
 1 void CTestdbDlg::OnOK()
void CTestdbDlg::OnOK() 
 2

 {
{
 3 // TODO: Add extra validation here
    // TODO: Add extra validation here
 4 //AfxOleInit();
    //AfxOleInit();    
 5 CoInitialize(NULL);  //初始化
    CoInitialize(NULL);  //初始化
 6 //打开数据库
    //打开数据库
 7 _ConnectionPtr m_pConnection;
    _ConnectionPtr m_pConnection;
 8 try
    try
 9
 
     {
{
10 m_pConnection.CreateInstance("ADODB.Connection");
        m_pConnection.CreateInstance("ADODB.Connection");
11 //    ASSERT(m_pConnection != NULL);
        //    ASSERT(m_pConnection != NULL);
12 _bstr_t strConnect="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb;Persist Security Info=False";
        _bstr_t strConnect="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb;Persist Security Info=False";
13 m_pConnection->ConnectionTimeout=5; //设置超时时间为5秒
        m_pConnection->ConnectionTimeout=5; //设置超时时间为5秒
14 m_pConnection->Open(strConnect,"","",adModeUnknown);
        m_pConnection->Open(strConnect,"","",adModeUnknown);
15 }
    }
16 catch(_com_error e)
    catch(_com_error e)
17
 
     {
{
18 AfxMessageBox(e.ErrorMessage());
        AfxMessageBox(e.ErrorMessage());
19 }
    }
20 _RecordsetPtr m_pRecordset; //一个指向Recordset对象的指针
    _RecordsetPtr m_pRecordset; //一个指向Recordset对象的指针
21 //查询
    //查询 
22 CString    sql="select sno From [sn]  ";
    CString    sql="select sno From [sn]  ";
23 try
      try
24
 
       {
{ 
25 m_pRecordset.CreateInstance(__uuidof(Recordset));
            m_pRecordset.CreateInstance(__uuidof(Recordset));
26 m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
            m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
27 while(!m_pRecordset->GetadoEOF())
            while(!m_pRecordset->GetadoEOF())
28
 
             {
{
29 _variant_t var;
                _variant_t var;
30 var=m_pRecordset->GetCollect("sno");
                var=m_pRecordset->GetCollect("sno");
31 if(var.vt != VT_NULL)
                if(var.vt != VT_NULL)
32
 
                 {
{
33 CString strValue =(LPCSTR)_bstr_t(var);
                     CString strValue =(LPCSTR)_bstr_t(var);
34 MessageBox(strValue);
                     MessageBox(strValue);
35 }
                }
36 m_pRecordset->MoveNext();
                m_pRecordset->MoveNext();
37 }
            }
38 }
      }
39
 catch(_com_error e)/**////捕捉异常
      catch(_com_error e)/**////捕捉异常
40
 
       {
{
41 AfxMessageBox(e.ErrorMessage());
        AfxMessageBox(e.ErrorMessage());
42 AfxMessageBox(e.Source());
        AfxMessageBox(e.Source());
43 AfxMessageBox(e.Description());
            AfxMessageBox(e.Description());   
44 }
      }
45 //更新
    //更新
46 _bstr_t    sql2="update [sn] set name='sss' where sno=3";
     _bstr_t    sql2="update [sn] set name='sss' where sno=3";
47 _variant_t RecordsAffected;
    _variant_t RecordsAffected;
48 m_pConnection->Execute(sql2,&RecordsAffected,adCmdText);
    m_pConnection->Execute(sql2,&RecordsAffected,adCmdText);
49
 m_pRecordset->Close();/**////关闭记录集
    m_pRecordset->Close();/**////关闭记录集
50
 m_pConnection->Close();/**////关闭连接
    m_pConnection->Close();/**////关闭连接
51 //    AfxOleTerm();
//    AfxOleTerm();
52 CoUninitialize();
    CoUninitialize();
53 
         
54 }
} 
在连接数据库之前要添加#import "C:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF","adoEOF")
路径根据本机设置修改  
rename("EOF","adoEOF")  //重新命名
					
			
		
 
	
	
		
	
	2009年4月20日		  
		
			
					
			
在对话框类中添加如下函数
BOOL CRegister::PreTranslateMessage(MSG *pMsg)
{
 if(WM_KEYFIRST <= pMsg->message && pMsg->message <= WM_KEYLAST) 
 { 
  if(pMsg->wParam == VK_RETURN ||pMsg->wParam ==VK_ESCAPE)//按回车键不响应 
  { 
   return true; 
  } 
 } 
 return CDialog::PreTranslateMessage(pMsg); 
}
					
			
		 
	
	
		
	
	2009年3月25日		  
		
			
					
			OO的精髓是继承、封装和多态
继承就是说:你的爱人会继承做你女朋友时的相当多的优点,因为这些优点对你都是public的,但同时她也会继承以前的更多的缺点,因为其中很多缺点对你是protected,继承后才让你能访问。  
封装就是说:许多不想让你知道的东西她会封装起来,你只能通过她提供的有限的接口来访问到被接口函数做了手脚的东西。  
多态就是说:在她心情不同时,你去访问以她为参数的一个函数得到的结果是不同的。比如对她说“我爱你” 。 
			
		
			
		 
	
	
		
	
	2009年3月21日		  
		
			
					
			  虚函数有时候也被称为方法。它可以使有差异的实体对象公用一种方法实现不同的操作。
    虚函数能克服类型域解决方案中的缺陷,它使程序员能够在基类声明一些能够在各个派生类里面重新定义的函数。编译器和装载程序能保证对象和应用于他们的函数之间的正确对应关系。
 class Employee
{
     string name;
 public:
     Employee(const  string &name);
    virtual void print() const;
}
void Employee::print() const
{
    cout<<name<endl;
}
 
关键字virtual指明print的作用就像是一个界面,既可以服务本类print函数,又可以服务于派生类的print函数。对于派生类定义的print函数,编译器保证对于生成的每一个实体对象都能调用正确的print函数。
    在派生类中对于有关函数的参数类型必须于虚函数的的参数类型相同,但可以在返回值类型上不同。
    所谓的多态性就是从Employee中取得了正确的行为,而不依赖于实际使用的是哪一种Employee。一个带有虚函数的类型被称为是一个多态类型。在C++要取得多态行为,被调用的函数必须是虚函数,而对象必须是通过指针或者引用操作。如果直接操作一个对象(而不是通过指针或者引用),它的确切类型已经被编译器所知,就不需要多态了。
    为了实现多态性,编译器必须在类的每个对象里存储某种类型信息,并且在需要虚函数的时候利用这些信息。在典型的实例中,所需要的空间是一个指针。只有那些包含了虚函数的类才需要这点空间,而不是任何对象,甚至不是任何派生类的对象。使用时,只需要为含有虚函数的类付出开销。
					
			
		 
	
	
		
	
	2009年3月20日		  
		
			
					
			
#include <iostream> 
using namespace std; 
class A 
{
 friend double count(A&); 
public: 
 A(double t, double r):total(t),rate(r){} 
 private: 
 double total; 
 double rate; 
}; 
double count(A&a) 
{ 
 a.total+=a.rate*a.total; 
 return a.total; 
} 
int main(void ) 
{ 
 A x(100,0.5),y(50,0.1); 
 cout<<count(x)<<"  "<<count(y)<<endl;
 cout<<count(x) <<"\n"; 
    return 0; 
} 
这段代码是什么意思??
					
			
		 
	
	
		
	
	2009年3月19日		  
		
			
					
			类成员默认访问权限为私有(private),结构体成员默认访问权限为公共public
从class继承默认是私有继承,从struct继承默认是公有继承。
结构体类型不包括操作。
			
		
			
		 
	
		
			
					
			(一)const修饰参数。const只能修饰输入参数。
   如果输入参数是指针型的,用const修饰可以防止指针被意外修改。
(二)const修饰函数返回值。
   函数返回const指针,表示该指针不能被改动,只能把该指针赋给const修饰的同类型指针变量。
 (三)const+成员函数。
任何不修改数据成员的函数都应该声明为const类型,如果const成员函数修改了数据成员或者调用了其他函数修改数据成员,编译器都将报错!
(四)const 修饰变量,表示该变量不能被修改。
    1、const char  *p 表示 指向的内容不能改变
    2、char * const p,就是将P声明为常指针,它的地址不能改变,是固定的,但是它的内容可以改变。
    3、这种const指针是前两种的结合,使得指向的内容和地址都不能发生变化.
         const double pi = 3.14159;
         const double *const pi_ptr = π