soui-新建工程示例

  1. 使用项目向导建立工程
  2. 在uires.idx里面的IMG字段添加图片资源
  3. 在skin.xml里面定义skin的类型和资源
  4. 在dlg_main.xml里面布局控件和skin
  5. 响应按钮事件:
EVENT_MAP_BEGIN
...
EVENT_NAME_COMMAND(L"btn_msgbox",OnBtnMsgBox)
EVENT_MAP_END()

新建一个页面

新建xml布局文件,添加对应的图片,皮肤资源。

新建c++类,然后复制工程中的MainDlg.h 和 .cpp的内容。

载入皮肤

imgArrow = (SImageWnd*)FindChildByName(L"icon_refund");
ISkinObj *pSkin = GETSKIN(L"skin_refund", 100);
imgArrow->SetSkin(pSkin);

设置SLink字体颜色

SLink* link = (SLink*)FindChildByName(L"link_receipt");
SwndStyle &style = link->GetStyle();
style.SetTextColor(0, RGBA(0xc0, 0xc0, 0xc0, 0xff));
link->Invalidate();

设置属性

具体的属性需要查看相关控件的代码

SImageButton* imgArrow = (SImageButton*)FindChildByName(L"btn_zfb");
imgArrow->SetAttribute(L"skin", L"skin_zfbSelected");

创建模态窗口

动态从文件中创建。资源目录需要和app放在一起。

//由于资源中使用了相对路径,需要将当前路径指定到资源所在位置
SStringT strCurDir = SApplication::getSingleton().GetAppDir();
strCurDir += _T("\\filewnd");
SetCurrentDirectory(strCurDir);
if (GetFileAttributes(_T("dlg_password.xml")) == INVALID_FILE_ATTRIBUTES)
{
SMessageBox(m_hWnd, _T("没有找到资源文件!"), _T("错误"), MB_OK | MB_ICONSTOP);
return;
}
SHostDialog fileDlg(_T("file:test.xml"));
fileDlg.DoModal(m_hWnd);

动态从xml文件名中创建

调用

dlgModal mDlg(_T("layout:xml_passwordDlg"));
mDlg.DoModal(m_hWnd);

自定义类

class dlgModal : public SHostDialog
{
public:
dlgModal();
dlgModal(SStringT xmlName);
~dlgModal();
void OnOK();
void OnClose();

SStringT m_strMsg; //消息XML
int m_nRepeat; //重复次数

EVENT_MAP_BEGIN()
EVENT_ID_COMMAND(IDOK, OnOK)
EVENT_NAME_COMMAND(L"dlg_pwd_btnClose", OnClose)
EVENT_MAP_END()

};


#include "stdafx.h"
#include "dlgModal.h"


dlgModal::dlgModal() :SHostDialog(_T("layout:xml_passwordDlg"))
{
m_nRepeat = 1;
}


dlgModal::dlgModal(SStringT xmlName) :SHostDialog(xmlName)
{
m_nRepeat = 1;
}

dlgModal::~dlgModal()
{
}

void dlgModal::OnOK()
{
EndDialog(IDOK);
}

void dlgModal::OnClose()
{
EndDialog(IDOK);
}

异步事件

EVENT_NAME_HANDLER