// demoRenameSelfDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "demoRenameSelfDlg.h"
#include "afxdialogex.h"
#include "HwmSdkAgent.h"
#include "demoTools.h"

// demoRenameSelfDlg 对话框

IMPLEMENT_DYNAMIC(demoRenameSelfDlg, CDialogEx)

demoRenameSelfDlg::demoRenameSelfDlg(CWnd* pParent /*=NULL*/)
    : CDialogEx(demoRenameSelfDlg::IDD, pParent)
{

}

demoRenameSelfDlg::~demoRenameSelfDlg()
{
}

void demoRenameSelfDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_EDIT_DISPLAY_NAME, m_edit);
}


BEGIN_MESSAGE_MAP(demoRenameSelfDlg, CDialogEx)
    ON_BN_CLICKED(IDOK, &demoRenameSelfDlg::OnBnClickedOk)
END_MESSAGE_MAP()


// demoRenameSelfDlg 消息处理程序


void demoRenameSelfDlg::OnBnClickedOk()
{
    // TODO: 在此添加控件通知处理程序代码
    CString strEdit;
    m_edit.GetWindowText(strEdit);
    string tempString = CTools::UNICODE2UTF(strEdit.GetString());
    if(tempString.empty() || tempString.length() >= HWM_MAX_DISPLAY_NAME_LEN)
    {
        CTools::OutputRetStr("Rename self param error");
        return;
    }
    char name[HWM_MAX_DISPLAY_NAME_LEN + 1] = {0};
    //name赋值
    strncpy_s(name, (char *)tempString.c_str(), HWM_MAX_DISPLAY_NAME_LEN);
    int ret = hwmsdkagent::RenameSelf(name);
    if(ret != hwmsdk::HWM_COMMON_SUCCESS)
    {
        CTools::OutputRetStr("Renamel self error");
        return;
    }

    CDialogEx::OnOK();
}
