11 2012 档案
摘要:使用python,是因为他的美;以下说明常用的字符编码在python中的应用:s = "中国a"print repr(s) #输出原始字符 是以十六进制表示# '\xd6\xd0\xb9\xfaa'#Ansi字符串我们最熟悉,英文占一个字节,汉字2个字节,以一个\0结尾,常用于txt文本文件#Unicode字符串,每个字符(汉字、英文字母)都占2个字节,以2个连续的\0结尾#utf-8英文1个字节,中文3个字节s1 = s.decode('gbk') //以十六进制存储就是已经编过码的了 所以要解码#u'\u4e2d\u56fda
阅读全文
摘要:最近在写code时,需要频繁使用到stat函数,为了更好的容错和log,就需要利用好st_mode。ok, 先看一下struct stat的结构。struct stat {dev_t st_dev; /* device */ino_t st_ino; /* inode */mode_t st_mode; /* protection */nlink_t st_nlink; /* number of hard links */uid_t st_uid; /* user ID of ...
阅读全文
摘要:MFC中的argc和argv参数在consloe程序中,通常用main(int argc,char*const*argv),自动就得到这两个参数,在MFC多文档程序中,需要用到这两个参数,直接使用__argc,__argv即可。
阅读全文
摘要:BOOL CCreateStatusBarDlg::OnInitDialog(){ CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE).
阅读全文
摘要:str1 = 'md "I:\mr\%s\qjyy" && xcopy /e "E:\学通C++的24堂课\mr\%s\qjyy" "I:\mr\%s\qjyy"'str2 = 'md "I:\mr\%s\sl" && xcopy /e "E:\学通C++的24堂课\mr\%s\sl" "I:\mr\%s\sl"'str3 = 'md "I:\mr\%s\zmhh" &&
阅读全文
摘要:BOOL CToolTipDlg::OnInitDialog(){ CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if ...
阅读全文
摘要:BOOL CSizeStatusbarDlg::OnInitDialog(){ CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); .
阅读全文
摘要:BOOL CProgressStatusBarDlg::OnInitDialog(){ CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALS.
阅读全文
摘要:void CSelRectDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemM...
阅读全文
摘要:void CSelRectDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemM...
阅读全文
摘要:WM_CTLCOLOR事件HBRUSH CFontDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here if(nCtlColor == CTLCOLOR_EDIT) //判断是否为编辑框控件 pDC->SetBkColor(m_Color); //设置文本背景颜色 //pDC->Se...
阅读全文
摘要:CString estr1 = "有志者,事竟成,破釜沉舟,百二秦关终属楚\r\n"; estr1 += "苦心人,天不负,卧薪尝胆,三千越甲可吞吴\r\n"; SetDlgItemText(IDC_EDIT1, estr1); SetDlgItemText(IDC_BUTTON1, "字体");void CFontDlg::OnFont() { // TODO: Add your control notification handler code here CFont * TempFont = m_Text.GetFont(); /
阅读全文
摘要:void CTestDlg::OnOpen() { // TODO: Add your control notification handler code here //bOpenFileDialog(TRUE):'打开'对话框 //lpszDefExt:扩展名 //lpszFileName:文件名称 //dwFlags:自定义文件对话框 //lpszFilte:用于指定对话框过滤的文件类型(文件类型说明和扩展名间用"|"分隔,每种文件类型间用"|"分隔,末尾用"||"结束.) //pParentWnd:标识文件对话框
阅读全文
摘要:void CWelcomeDlg::OnClose() { // TODO: Add your message handler code here and/or call default if(MessageBox("Are you sure close this windows?", "closing", MB_OKCANCEL|MB_ICONQUESTION) == IDOK) { CDialog::OnClose(); } //创建一个基于对话框的应用程序. //通过类向导选择WM_CLOSE消息事件 //在对话框的消息事件...
阅读全文
摘要:Login dlg; if(dlg.DoModal()!=IDOK) { OnOK(); }void Login::OnOK() { // TODO: Add extra validation here //CEdit *pEdit1 = (CEdit *)GetDlgItem(IDC_EDIT1); //CEdit *pEdit2 = (CEdit *)GetDlgItem(IDC_EDIT2); //CString e1, e2; //pEdit1->GetWindowText(e1); //pEdit2->Get...
阅读全文
摘要:BOOL CBeginDlg::OnInitDialog(){ SetTimer(1, 100, NULL); //触发定时器}void CBeginDlg::OnTimer(UINT_PTR nIDEvent){ // TODO: 在此添加消息处理程序代码和/或调用默认值 //MessageBox(L"hello"); CRect rc; CRect rect; GetWindowRect(&rect); rc.CopyRect(&rect); CPoint pOint; GetCursorPos(&pOint); CString ...
阅读全文
摘要:BOOL CWelcomeDlg::PreTranslateMessage(MSG* pMsg) //Called to filter messages before they are dispatched{ // TODO: Add your specialized code here and/or call the base class if(pMsg->message == WM_KEYDOWN && pMsg->wParam == 27) { CString s; s.Format("The wParam= %d The message =...
阅读全文
摘要:CBegin dlg; if(dlg.DoModal()!=IDCANCEL) { OnOK(); }BOOL CBegin::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here SetTimer(1, 2000, NULL); //1:Specifies a nonzero timeridentifier //2000:Specifies the time-out...
阅读全文
摘要:CWnd* pWnd = GetTopWindow(); while(pWnd!=NULL) { int i = pWnd->GetDlgCtrlID(); CString str; str.Format("ID是:%d", i); //pWnd->SetWindowText(str); if(i!=-1) MessageBox(str); pWnd = pWnd->GetNextWindow(); }
阅读全文
摘要:BOOL CMfcDlg::OnInitDialog(){ CDialog::OnInitDialog(); this->SetWindowText("蟒蛇软件站"); return TRUE; }void CCalcDlg::OnCalc(){ CString strText = _T(""); GetWindowText(strText); SetDlgItemText(IDC_EDIT1, strText); SetWindowText("pythonschool.com");}void CDemoDlg::OnTest1
阅读全文
摘要://创建一个基于对话框的工程,向对话框中添加静态文本,编辑框和组合框控件CComboBox m_Symbo;CEdit m_SecOpt;CEdit m_Result;CEdit m_FirstOpt;enum Symbo {PLUS, SUB, MUL,DIV};template <class Type>class CCalc{public: Type Calc(Type &refFirstOpt, Type &refSecOpt, Symbo Opt) { switch (Opt) { case PLUS: ret...
阅读全文
摘要:#include "Book.h"//模式对话框的创建CBook book; //定义CBook对象book.DoModal(); //调用DoModal方法显示模态对话框CBook *pbook;pbook = new CBook();pbook->DoModal();delete pbook;//非模式对话框的创建if(!IsWindow(m_book.m_hWnd)){ m_book.Create(IDD_Book, NULL);}m_book.ShowWindow(SW_SHOW);//在创建模式对话框时,定义的是局部变量,而创建非模式对话框时创建的是成员变量
阅读全文
摘要://C++语言 实现类对象的单模式创建//对于单例模式而言,既然要保证类有且仅有一个实例,就需要其他的类不能实例化该类.//因此,需要将构造方法设置成私有的,即使用private关键字修饰.//同时,在类中提供一个静态方法,该方法的返回值是该类的一个实例.#include "stdafx.h"#include "iostream.h"class Emperor{private: static Emperor *pEmperor; static int count; Emperor() { count++; }public: static Em...
阅读全文
摘要:////////////////////////////////////////////////////////////////// File: getfileversion.cpp// Description: 获取EXE文件的属性详细信息// Created: 2012-10-18// Author:pythonschool.com/////////////////////////////////////////////////////////////////*The following code shows how to get FILEINFO value from resource
阅读全文
摘要://C++语言 通过类模板实现加法计算器#include "stdafx.h"#include <iostream>using namespace std;template <class T>class Calculate //声明一个模板类{ public: Calculate(T a, T b); public: T Add(); T Substraction(); void display(); private: T m_a; T m_b;};template <class T>Calc...
阅读全文
摘要://#C++语言 对动物的行为实现多态#include <iostream>using namespace std;class CAnimal{public: virtual void Cry()=0;//纯虚函数};class CDog:public CAnimal{public: virtual void Cry() { cout << "wang wang! The dog sound!\n" << endl; }};class CCat:public CAnimal{public: virtual void Cry() { ...
阅读全文
摘要://#C++语言 重载"="运算符#include "stdafx.h"#include <iostream>#include <string>using namespace std;class CStudent{private: char m_Name[10]; //学生姓名 int m_Age; //年龄 double m_Height; //身高public: CStudent(){}; //通过构造函数初始化类数据 CStudent(char *name, int age, double height); void dis
阅读全文
摘要://C++语言 在析构函数中释放类中的资源#include "stdafx.h"#include <iostream>#include <string>using namespace std;class CTest{private: char *m_Buffer;public: CTest(char *text); ~CTest(); void display();};CTest::CTest(char *text){ m_Buffer = new char[255]; strcpy(m_Buffer, text);}CTest::~CTest(){
阅读全文
摘要://C++语言 通过构造函数初始化学生信息#include "stdafx.h"#include <iostream>#include <string>using namespace std;/*class CStudent{private: char m_Name[10]; int m_Age; double m_Height;public: CStudent(char *name, int age, double height) { strcpy(m_Name, name); m_Age = age; m_Height...
阅读全文
摘要://类模板的使用//针对不同数据类型要设计不同版本的类,但是内部的实现是一样的.这样做不但重复劳动还容易出错,后期和调试的工作量相当大.类模板解决了上述的问题.//#类模板的声明和实例化//类模板能够为类的数据成员,成员函数的参数,返回值提供动态参数化的机制,使得用户可以方便地设计出功能更为灵活的类./*temple <class T>class Calculate{ public: Calculate(T a, T b); T Add(); T Subtraction(); private: T m_a; T ...
阅读全文
摘要://运算符重载//C++提供了许多内置数据类型,如整形、浮点型、字符型等,也提供了相应的运算符(+,-,>,<等),用于进行数据的数学运算和逻辑运算.//重载运算符的格式如下://函数类型 operator 运算符号 (参数列表)//{对运算符的重载处理}//使用重载运算符实现类的加法运算#include <iostream>using namespace std;class Man //声明一个Man类{public: Man(int a = 0, int h = 0); Man operator +(Man &a); //重载"+"实现相
阅读全文
摘要://在类中采取了不少的有效措施以增强数据的安全性,例如使用private,但是有些数据往往需要共享,所以有时无意之中的误操作便会改变有关的数据,这时可以使用const修饰符,即把有关的成员声明为常量.//**不能在构造函数的定义中为常成员变量赋初值.//**可以使用参数初始化表对const型成员变量进行初始化.如:CShop::CShop(int size):m_size(size){}//const函数的使用#include "stdafx.h"#include <iostream>using namespace std;class CShop{private
阅读全文
摘要://c++语言 友元类和友元方法//友元函数:如果在一个类的外面定义了一个函数(该函数不属于这个类),当类中用friend对该函数进行声明后, 该函数就可以访问类中的所有成员.//友元函数分为:将普通函数声明为友元函数,将其他类中的成员函数声明为友元函数.//***将普通函数声明为友元函数#include "stdafx.h"#include <iostream>using namespace std;class CShop //声明一个CShop类{public: CShop(int size, int price); void ShowSize(); voi
阅读全文
摘要://c++语言 静态成员数据和静态方法//对象与对象之间的成员变量是相互独立的.要想共用数据,则需要使用静态成员或静态方法//#只要在类中声明静态成员变量,即使不定义对象,也可以为静态成员变量分配空间,进而可以使用静态成员变量.(因为静态成员变量在对象创建之前就已经被分配了内存空间)//#静态成员变量虽然在类中,但它并不是随对象的建立而分配空间的,也不是随对象的撤销而释放(一般的成员在对象建立时会分配空间,在对象撤销时会释放).静态成员变量是在程序编译时分配空间,而在程序结束时释放空间.//#初始化静态成员变量要在类的外面进行.初始化的格式如下:数据类型 类名::静态成员变量名 = 初值;//
阅读全文
摘要://c++语言 内联方法//一般在类体中定义的成员函数都是很小的,而系统调用时却会花费很多的时间.在这种情况下,最好将类体内的成员函数定义为内联函数.//这样在程序中调用这些成员函数时,并不是真正地执行函数的调用过程,而是直接将函数的代码插入到程序中调用点的位置,大大减速少了调用成员函数的时间开销.//内联函数要用关键字 inline进行声明.例如:class A{public: inline void display() { cout << "this is a class of A" << endl; }};//其实,在类体中定义的成员函数是可以
阅读全文
摘要://纯虚函数//在基类中预留出一个成员函数名,此函数并不是为自己所用,而是派生类需要使用,具体功能由派生类根据实际情况重新进行定义.//virtual 函数类型 函数名称(参数列表) = 0;//纯虚函数是没有函数体的,也就是说在基类中不需要对纯虚函数进行定义//最后面的"=0"并不是表示函数的返回值为0,它只是起形式上的作用,用来说明这个虚函数是纯虚函数//这是一条声明语句,所以在句子的最后要加";"号//纯虚函数只有函数的名称而不具备函数的功能,只是为了派生类的特殊功能调用保留函数的名称.//如果在一个类中声明纯虚函数,而在派生类中却没有重新对该函数
阅读全文
摘要://覆盖成员函数//rect.CShape::display()通过作用域限定符":"指定调用了基类中的成员函数.#include "stdafx.h"#include <iostream>using namespace std;class CShape{private: int m_color;public: CShape(int color=10); void display();};CShape::CShape(int color){ m_color = color;}void CShape::display(){ cout <&
阅读全文
摘要://析构函数的调用//在一般情况下,调用析构函数的次序正好与调用构造函数的次序相反//最先被调用的构造函数,其对应的析构函数最后被调用.#include "stdafx.h"#include <iostream>using namespace std;class CPen{public: CPen(int size=10); ~CPen(); int GetSize(); int SetSize(int size); void Write();private: int m_size;};CPen::CPen(int size){ m_size = si...
阅读全文
摘要://复制构造函数#include "stdafx.h"#include <iostream>using namespace std;class CPen{private: int m_size;public: CPen(int size); CPen(CPen &pen); int GetSize(); void Write();};CPen::CPen(int size){ m_size = size;}CPen::CPen(CPen &pen){ m_size = pen.GetSize(); cout << "size
阅读全文
摘要://构造函数并不是由用户来调用的,而是在建立对象的同时自动执行;并且构造函数的名称与类的名称必须是一致的,而不是由用户任意命名的.#include "stdafx.h"#include <iostream>using namespace std;class CPen{public: CPen(); //默认构造函数的声明 CPen(int size); //构造函数的声明 int GetSize(); int SetSize(int size); void Write();private: int m_size;};CPen::CPen() //默认构造函数..
阅读全文
摘要:下面以描述"用户"为例,介绍类的声明.为了简化类的声明,我们认为"用户"具有名称和密码两个属性,并且具有实现登录功能.class CUser //声明一个类{public: char m_Username[128]; //定义数据成员 char m_Password[128]; bool Login() //定义方法 { if(strcmp(m_Username, "MR")==0 && strcmp(m_Password, "KJ")==0) { cout << "登录成功&
阅读全文
摘要:#include <iostream.h>#include <io.h>#include <string.h>#include "stdlib.h"const int MAXLEN = 1024; //定义最大目录长度unsigned long FILECOUNT = 0; //记录文件数量void ListDir(const char* pchData){ _finddata_t fdata; //定义文件查找结构对象 long done; char tempdir[MAXLEN] = {0}; //定义一个临时字符数组 strcat(
阅读全文
摘要:int (&array)[10] 中的括号是不可以活力的,如果省略了括号,"[]"运算符的优先级高于"&"运算符,便成了引用数组,而在C++语言中定义引用数组是非法的.int (&array)[10] 的格式是合法的,表示定义一个引用对象,它可以指向(严格地说应该是取代)具有10个元素的数组.这里回忆一下指针数组的定义.int *parray[5]; //定义一个指针数组对里如果对"*parray"使用括号括起来,其性质就变了.例如:int (*parray)[5]; //定义一个整形指针,可以指向5个元素的整
阅读全文

浙公网安备 33010602011771号