soui-模态对话框的使用

继承SHostDialog.
使用的时候遇到个问题。那就是在DoModal之前想要设置界面的显示文字和布局,而soui在DoModal之前还没有创建完整,所以查找控件返回null.
曲线救国,发现设置成员变量是可以访问的,然后在showWindow的时候,自动调整一下就可以了。

使用:

wstring ver = L"当前版本号 V";
ver += APP_VERSION;

CDlgNotifyModal dlg(L"layout:xml_notify");
dlg.m_strTips = L"检查版本失败";
dlg.m_strVer = ver;
dlg.m_btnCount = 1;
dlg.m_btn1Text = L"确认";
dlg.DoModal(m_hWnd);
#pragma once
class CDlgNotifyModal : public SHostDialog
{
public:
CDlgNotifyModal();
CDlgNotifyModal(SStringT xmlName);
~CDlgNotifyModal();

void OnClose();
void OnBtnConfirm();
void OnBtnLater();
void setDisplayType(const int type, const wstring strInfo, const wstring strVer);
void OnShowWindow(BOOL bShow, UINT nStatus);

EVENT_MAP_BEGIN()
EVENT_NAME_COMMAND(L"btn_close", OnClose)
EVENT_NAME_COMMAND(L"btn_confirm", OnBtnConfirm)
EVENT_NAME_COMMAND(L"btn_later", OnBtnLater)

EVENT_MAP_END()
BEGIN_MSG_MAP_EX(CDlgNotifyModalDlg)
//MSG_WM_CLOSE(OnCancel)
//MSG_WM_KEYDOWN(OnKeyDown)
CHAIN_MSG_MAP(SHostDialog)
REFLECT_NOTIFICATIONS_EX()
MSG_WM_SHOWWINDOW(OnShowWindow)
END_MSG_MAP()

wstring m_strTips, m_strVer, m_btn1Text,m_btn2Text;
int m_btnCount;

};
#include "stdafx.h"
#include "DlgNotifyModal.h"

#define NOTIFY_TYPE_1BTN 1
#define NOTIFY_TYPE_2BTN 2

CDlgNotifyModal::CDlgNotifyModal() :SHostDialog(_T("layout:xml_notify"))
{
}


CDlgNotifyModal::CDlgNotifyModal(SStringT xmlName) : SHostDialog(xmlName)
{

}

CDlgNotifyModal::~CDlgNotifyModal()
{
}


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

void CDlgNotifyModal::OnBtnConfirm()
{
EndDialog(IDOK);
}

void CDlgNotifyModal::OnBtnLater()
{
EndDialog(IDCANCEL);
}


//type 通知信息的类型,对应不同的布局
void CDlgNotifyModal::setDisplayType(const int type, const wstring strInfo, const wstring strVer)
{
SStatic* txt = nullptr;
if (false == strInfo.empty())
{
txt = (SStatic*)FindChildByName(L"txt_info");
txt->SetWindowTextW(strInfo.c_str());
}
if (false == strVer.empty())
{
txt = (SStatic*)FindChildByName(L"txt_ver");
txt->SetWindowTextW(strVer.c_str());
txt->SetVisible(TRUE);
}
else
{
txt = (SStatic*)FindChildByName(L"txt_ver");
txt->SetVisible(FALSE);
}

if (NOTIFY_TYPE_1BTN == type)
{
SImageButton* pBtn = (SImageButton*)FindChildByName(L"btn_confirm");
if (pBtn)
{
pBtn->Move(112, 136, 192, 32);
pBtn->SetWindowTextW(m_btn1Text.c_str());
}
pBtn = (SImageButton*)FindChildByName(L"btn_later");
pBtn->SetVisible(FALSE);
}
else if (NOTIFY_TYPE_2BTN == type)
{
SImageButton* pBtn = (SImageButton*)FindChildByName(L"btn_confirm");
pBtn->Move(208, 136, 128, 32);
pBtn->SetWindowTextW(m_btn1Text.c_str());

pBtn = (SImageButton*)FindChildByName(L"btn_later");
pBtn->Move(72, 136, 128, 32);
pBtn->SetWindowTextW(m_btn2Text.c_str());
pBtn->SetVisible(TRUE);
}

::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}

void CDlgNotifyModal::OnShowWindow(BOOL bShow, UINT nStatus)
{
setDisplayType(m_btnCount, m_strTips, m_strVer);
}