ListView

29 7 月, 2011

list-view controls中一个item代表一行,设置这行的信息通过subitem。

Each item can have one or more subitems. A subitem is a string that, in report view, is displayed in a column separate from the item’s icon and label. All items in a list-view control have the same number of subitems. The number of subitems is determined by the number of columns in the list-view control. When you add a column to a list-view control, you specify its associated subitem index. The iItem member is the zero-based index of the item. The iSubItem member is the one-based index of a subitem or zero if the structure contains information about an item. To change the attributes of a list-view item, use the LVM_SETITEM message, specifying the address of an LVITEM structure. The mask member of this structure specifies the item attributes you want to change. For example, to change only the text of an item or subitem, use the LVM_SETITEMTEXT message.

Report (details) view: Each item appears on its own line, with information arranged in columns. The leftmost column is always left justified and contains the small icon and label. Subsequent columns contain subitems as specified by the application.

示例代码:

HWND hWnd = GetDlgItem(hDlg, IDC_LIST1);
ListView_SetExtendedListViewStyle(hWnd, LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES);
LVCOLUMN lvc = {0};
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvc.fmt = LVCFMT_CENTER;
lvc.cx = 20;
lvc.iSubItem = 0;
lvc.pszText = TEXT(“”);
ListView_InsertColumn(hWnd, 0, &lvc);
lvc.cx = 100;
lvc.iSubItem = 1;
lvc.pszText = TEXT(“编号”);
ListView_InsertColumn(hWnd, 1, &lvc);
LVITEM lvi = {0};
lvi.mask = LVIF_TEXT;
lvi.iItem = 0;
lvi.iSubItem = 0;
lvi.pszText = TEXT(“”);
ListView_InsertItem(hWnd, &lvi);
ListView_SetItemText(hWnd, 0, 1, TEXT(“1”));
lvi.iItem = 1;
ListView_InsertItem(hWnd, &lvi);
ListView_SetItemText(hWnd, 1, 1, TEXT(“2”));

 

 

 

 

 

 

 

 

 

 

参考资料:http://msdn.microsoft.com/en-us/library/bb774737(v=VS.85).aspx

Copy Constructor的构建操作

28 7 月, 2011

合成的拷贝构造函数和合成的默认构造函数一样,也是在必要的时候才由编译器产生出来。这里的“必要”是指类不展现bitwise copy semantics时。

一般,类如C语言中仅包含内建数据类型的结构体一样,则是具有bitwise copy semantics的,编译器不合成拷贝构造函数。

有四种情况一个类不展现出bitwise copy semantics:

1. 当class内含一个member object而后者的class声明有一个copy constructor(不论是被设计者明确地声明,或是被编译器合成)。

2. 当class继承自一个base class而后者存在有一个copy constructor时(同上)。

3. 当class声明了一个或多个virtual functions时。

4. 当class派生自一个继承链,其中有一个或多个virtual base classes时。

Default Constructor的建构操作

27 7 月, 2011

1. 合成的默认构造函数会在编译器需要的时候被编译器产生出来。如类中包含其他类对象,即使构造函数已经被明确定义出来,编译器也会扩充已存在的构造函数,在其中安插一些代码。

2. 还有两种情况合成默认构造函数:类中声明或继承一个virtual function;类派生自一个继承链,其中有一个或更多的虚基类。编译器要在其中安插设置vptr和vtbl的代码。

总结:有四种情况,会导致“编译器必须为未声明constructor之classes合成一个default constructor”。C++ Stardand把那些合成物成为implicit nontrivial default constructors。被合成出来的constructor只能满足编译器(而非程序)的需要。它之所以能够完成任务,是借着“调用member object或base class的default constructor”或是“为每一个object初始化其virtual function机制或virtual base class机制”而完成。至于没有存在那四种情况而又没有声明任何constructor的classes,我们说它们拥有的是implicit trivial default constructors,它们实际上并不会被合成出来。

在合成的default constructor中,只有base class subobjects和member class objects会被初始化。所有其它的nonstatic data member,如整数、整数指针、整数数组等等都不会被初始化。这些初始化操作对程序而言或许有需要,但对编译器则并非必要。如果程序需要一个“把某指针设为0”的default constructor,那么提供它的人应该是程序员。

C++新手一般有两个常见的误解:

1. 任何class如果没有定义default constructor,就会被合成出一个来。

2. 编译器合成出来的default constructor会明确设定“class内每一个data member的默认值”。

如你所见,没有一个是真的!

Object Lessons

27 7 月, 2011

1. 在没有使用virtual的情况下,C++类对象的布局与C结构体的一样。

2. C++中,类的成员变量有static和nonstatic两种;类的成员函数有static、nonstatic和virtual三种。

3. C++对象模型中,static成员变量被置于所有类对象之外,nonstatic成员变量被置于每个类对象之内;static和nonstatic成员函数都被置于所有类对象之外,virtual functions的支持如下:每个类对象被添加了一个指向vtbl的指针vptr,vtbl由类根据virtual functions产生,每一项为一个指向virtual function的指针,通常第1项为类的类型信息;vptr的设置和重置由类的构造函数、析构函数和拷贝赋值运算符自动完成。

古剑奇谭1.5.8修改方法

27 5 月, 2011

彼岸浮灯篇,修改方兰生攻击力,WinHex修改0x878E和0x8796地址起连续四字节。貌似最大攻击力也就9999?