您的位置:首页 > 产品设计 > UI/UE

cppquery 简单的数据绑定对话框

2013-12-31 14:31 176 查看
上一篇文章: cppquery:用C++模仿jquery的探索

获取cppquery: https://github.com/coderebot/cppquery
在本文中,我们用绑定的方法来实现一个对话框:将高度和宽度值绑定到一个对话框上,并能够修改。如图

当然,从windows编程上来说,这只是一个非常入门的功能。我们从这里出发,来看看我们能够简化到何种程度。

该窗口只有一个简单的函数来实现:(在文件demo_dialog_get_int_values.cpp)

int gWidth = 300;
int gHeight = 400;

void demo_dialog_get_int_values(HINSTANCE hInst, HWND hParent)
{
//MessageBox(0, _T("Test Get Int Values"), _T("Get Int Value"), 0);

Dialog dialog(hInst, IDD_DIALOG_GETINTVALUES, hParent);
dialog.intNumber(IDC_EDIT_WIDTH).bind(&gWidth);
dialog.intNumber(IDC_EDIT_HEIGHT).bind(&gHeight);

wchar_t szText[100];
if(dialog.doModel())
{
wsprintf(szText, L"Get New Width=%d, Height=%d", gWidth, gHeight);

}
else
{
wsprintf(szText, L"Error!");
}
MessageBox(0, szText, L"Result", 0);
}


首先,我们声明了一个dialog

Dialog dialog(hInst, IDD_DIALOG_GETINTVALUES, hParent);
传递的这些参数,是为了适应模板资源来创建对话框

然后,将变量绑定到对话框的控件上

dialog.intNumber(IDC_EDIT_WIDTH).bind(&gWidth);
dialog.intNumber(IDC_EDIT_HEIGHT).bind(&gHeight);
最后,以模态方式显示对话框

if(dialog.doModel())


然后,我们将它和菜单绑定起来 (cppquerytest.cpp)

window.loadMenu(hInstance, MAKEINTRESOURCE(IDC_CPPQUERY))
.onCommand(IDM_EXIT, BIND(DestroyWindow, window.hwnd()))
.onDestroy(BIND(PostQuitMessage, 0))
.onCommand(IDM_ABOUT, BIND(DoDialogModel,hInstance, window.hwnd(), IDD_ABOUTBOX, about_handles))
//for demos
//for dialog demos
.onCommand(ID_DIALOG_GETINTVALUES, BIND(demo_dialog_get_int_values, hInstance, window.hwnd()))
//end demos
.show(nCmdShow)
.update()
.doModel();
请关注:

.onCommand(ID_DIALOG_GETINTVALUES, BIND(demo_dialog_get_int_values, hInstance, window.hwnd()))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: