MFC空控件 --- 使用下拉列表、微调按钮
来源:互联网 发布:ubuntu kill 不起作用 编辑:程序博客网 时间:2024/04/30 06:31
Ultimate Grid 支持很多种单元格类型,比如下拉列表、多选按钮、微调按钮、单选按钮等等。如果没有您所需要的标准单元格类型,自定义单元格类型也很容易。下拉列表、多选按钮等类型的单元格是内嵌的,而要添加非内嵌类型单元格需要调用CUGCtrl::AddCellType() 。
第1步 添加2个文件到项目
把 Ultimate Grid 源代码压缩包里面的CellTypes目录拷贝到D:\UG下
目录情况如下图:
接着再把CellTypes目录下的UGCTSpin.cpp文件添加到"Ultimate Grid"目录下,如下图:
项目“Addtional include directories:”处参数修改成“.\,..\include,..\skel,..\CellTypes”,如下图:
第2步 创建一个单元格类型对象
在MyCug.h头文件中包含UGCTSpin.h文件,再创建一个在MyCug类中类型为CUGSpinButtonType的public成员变量m_spin,代码如下:
C++ Code 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
第3步 在表格中添加2个类型的单元格
修改MyCug::OnSetup函数如下代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
第4步 修改MyCug::OnCellTypeNotify()函数
当用户点击微调按钮或下拉列表按钮时系统会调用MyCug::OnCellTypeNotify()函数。微调按钮有上下两个箭头,用户点击上箭头时,单元格内的数值会增加0.25,反之减少0.25。代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
第1步 添加2个文件到项目
把 Ultimate Grid 源代码压缩包里面的CellTypes目录拷贝到D:\UG下
目录情况如下图:
接着再把CellTypes目录下的UGCTSpin.cpp文件添加到"Ultimate Grid"目录下,如下图:
项目“Addtional include directories:”处参数修改成“.\,..\include,..\skel,..\CellTypes”,如下图:
第2步 创建一个单元格类型对象
在MyCug.h头文件中包含UGCTSpin.h文件,再创建一个在MyCug类中类型为CUGSpinButtonType的public成员变量m_spin,代码如下:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "ugctrl.h"
#include "resource.h"
//*******Add the New Header File
#include "UGCTSpin.h"
//#include"UGCelTyp.h"
classMyCug: public CUGCtrl
{
public:
//****** Create the New Object
CUGSpinButtonType m_spin;
#include
//*******
//#include
class
{
第3步 在表格中添加2个类型的单元格
修改MyCug::OnSetup函数如下代码:
C++ Code
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
void MyCug::OnSetup()
{
//******* Declare all variables
int index , num_cols, num_rows;
CUGCell cell;
CString heading, number;
//******* Enable the Menu
EnableMenu(TRUE);
//****** Set the Rows and Columns
SetNumberCols( 10);
SetNumberRows( 10);
//******* Get the number of Rows and Columns
num_rows = GetNumberRows();
num_cols = GetNumberCols();
//******* Add the Top Heading
for (index = 0; index < num_rows; index++)
{
heading.Format( "%d", index + 1);
QuickSetText(- 1, index, heading);
QuickSetAlignment(- 1, index, UG_ALIGNVCENTER );
}
//******* Add the Side Heading
for (index = 0; index < num_cols; index++)
{
heading.Format( "%d", index + 1);
QuickSetText(index, - 1, heading);
QuickSetAlignment(index, - 1, UG_ALIGNVCENTER );
}
//****** Populate the grid
for ( int x = 0; x < num_cols; x++)
{
for(int z = 0; z < num_rows; z++)
{
number.Format( "%d", ((x + 1) * (z + 1)));
QuickSetText(x, z, number);
QuickSetAlignment(x, z, UG_ALIGNVCENTER );
}
}
//****** Set the Spin Button cell type
int cell_index = AddCellType(&m_spin);
GetCell( 0, 0, &cell);
cell.SetCellType(cell_index);
SetCell( 0, 0, &cell);
//***** Set the Droplist cell type
GetCell( 2, 2, &cell);
cell.SetCellType(UGCT_DROPLIST);
cell.SetLabelText( "Sunday\nMonday\nTuesday\nWednesday\nThursday\nFriday\nSaterday\n");
SetCell( 2, 2, &cell);
}
{
}
第4步 修改MyCug::OnCellTypeNotify()函数
当用户点击微调按钮或下拉列表按钮时系统会调用MyCug::OnCellTypeNotify()函数。微调按钮有上下两个箭头,用户点击上箭头时,单元格内的数值会增加0.25,反之减少0.25。代码如下:
C++ Code
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
int MyCug::OnCellTypeNotify( long ID, int col, long row, long msg, long param)
{
UNREFERENCED_PARAMETER(ID);
UNREFERENCED_PARAMETER(col);
UNREFERENCED_PARAMETER(row);
UNREFERENCED_PARAMETER(msg);
UNREFERENCED_PARAMETER(param);
//****** Declare a CUGCell object
CUGCell cell;
if (ID == 4 && msg == UGCT_SPINBUTTONUP)
{
double number, newnumber;
GetCell(col, row, &cell);
number = cell.GetNumber();
newnumber = number + 0.25;
cell.SetNumber(newnumber);
SetCell(col, row, &cell);
}
if (ID == 4 && msg == UGCT_SPINBUTTONDOWN)
{
double number;
GetCell(col, row, &cell);
number = cell.GetNumber();
number = number - 0.25;
cell.SetNumber(number);
SetCell(col, row, &cell);
}
return TRUE;
}
{
}
0 0
- MFC空控件 --- 使用下拉列表、微调按钮
- 第6课 使用下拉列表、微调按钮
- MFC 微调控件使用
- MFC下拉列表框(Combox)控件使用方法
- MFC 列表控件的使用
- mfc中使用列表控件
- MFC列表控件的使用
- gtk 微调控件的使用
- 在MFC视图中创建按钮和下拉框控件
- 微调按钮
- 微调按钮
- MFC工具栏按钮下拉
- 用mfc实现组合框控件下拉列表显示
- MFC 转按钮控件的使用
- MFC下列表控件的使用
- MFC中ListCtrl列表控件的使用
- MFC中列表控件的使用
- MFC的列表控件的使用
- 11549 - Calculator Conundrum[暴力]
- IOS前奏之Object-C基础:类的构造函数和description(自描函数)
- sed命令
- 龟兔赛跑预测
- 黑马程序员——【C语言】输出整数在内存中的二进制形式
- MFC空控件 --- 使用下拉列表、微调按钮
- Android性能优化之实现双缓存的图片异步加载工具(LruCache+SoftReference) - 拿来即用
- wave
- 开发机就该把配置搞上去
- sprintf,你知道多少?
- PageRank算法解析及R语言实现
- LeetCode-Sqrt(x)
- 20150310的一些总结
- zoj_1205 Martian Addition