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

#include "stdafx.h"
#include "demo.h"
#include "demoTools.h"
#include "demoConfCtrlDlg.h"
#include "afxdialogex.h"
#include "HwmSdkAgent.h"
#include "demoAddAttendeeDlg.h"
#include "demoAddAttendeeDlg.h"
#include "demoStartShareDlg.h"
#include "demoSetTransparentWndDlg.h"
#include "demoSetShareStrategyDlg.h"
#include "demoSetShareAudioDlg.h"
#include "demoAVDeviceCtrlDlg.h"
#include "demoGeneralWatchDlg.h"
#include "demoAnnotationSaveConfigDlg.h"
#include "demoSetAutoHideToolBarDlg.h"
#include "demoSubtitleSettingDlg.h"
#include "demoOpenWaitingroomDlg.h"
#include "OperateLocalRecord.h"
#include "demoApplyHostRoleDlg.h"
#include "demoData.h"

// demoConfCtrlDlg 对话框

IMPLEMENT_DYNAMIC(demoConfCtrlDlg, CDialogEx)

demoConfCtrlDlg::demoConfCtrlDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_CONF_CTRL_DIALOG, pParent)
{

}

demoConfCtrlDlg::~demoConfCtrlDlg()
{
}

void demoConfCtrlDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(demoConfCtrlDlg, CDialogEx)
    ON_BN_CLICKED(IDC_BUTTON_GO_START_SHARE, &demoConfCtrlDlg::OnBnClickedButtonGoStartShare)
    ON_BN_CLICKED(IDC_BUTTON_STOP_SHARE, &demoConfCtrlDlg::OnBnClickedButtonStopShare)
    ON_BN_CLICKED(IDC_BUTTON_LEAVE_CONF, &demoConfCtrlDlg::OnBnClickedButtonLeaveConf)
    ON_BN_CLICKED(IDC_BUTTON_STOP_CONF, &demoConfCtrlDlg::OnBnClickedButtonStopConf)
    ON_BN_CLICKED(IDC_BUTTON_GO_ADD_ATTENDEES, &demoConfCtrlDlg::OnBnClickedButtonGoAddAttendees)
    ON_BN_CLICKED(IDC_BUTTON_GO_SET_TRANS_WIN, &demoConfCtrlDlg::OnBnClickedButtonGoSetTransWin)
    ON_BN_CLICKED(IDC_BUTTON_SET_SHARE_STRATEGY, &demoConfCtrlDlg::OnBnClickedButtonSetShareStrategy)
    ON_BN_CLICKED(IDC_BUTTON_SET_SHARE_AUDIO, &demoConfCtrlDlg::OnBnClickedButtonSetShareAudio)
    ON_BN_CLICKED(IDC_BUTTON_AVDEVICE_CTRL, &demoConfCtrlDlg::OnBnClickedButtonAvdeviceCtrl)
    ON_BN_CLICKED(IDC_BUTTON_GENERAL_WATCH, &demoConfCtrlDlg::OnBnClickedButtonGeneralWatch)
    ON_BN_CLICKED(IDC_BUTTON_SET_ANNOTATION_INFO, &demoConfCtrlDlg::OnBnClickedButtonSetAnnotationInfo)
    ON_BN_CLICKED(IDC_BUTTON_START_ANNOTATION, &demoConfCtrlDlg::OnBnClickedButtonStartAnnotation)
    ON_BN_CLICKED(IDC_BUTTON_SAVE_ANNOTATION, &demoConfCtrlDlg::OnBnClickedButtonSaveAnnotation)
    ON_BN_CLICKED(IDC_BUTTON_STOP_ANNOTATION, &demoConfCtrlDlg::OnBnClickedButtonStopAnnotation)
    ON_BN_CLICKED(IDC_BUTTON_SET_AUTO_HIDE_TOOLBAR, &demoConfCtrlDlg::OnBnClickedButtonSetAutoHideToolbar)
    ON_BN_CLICKED(IDC_BUTTON_GET_SELF_SHARE_STATE, &demoConfCtrlDlg::OnBnClickedButtonGetSelfShareState)
    ON_BN_CLICKED(IDC_BUTTON_SUBTITLE_SETTING, &demoConfCtrlDlg::OnBnClickedButtonSubtitleSetting)
    ON_BN_CLICKED(IDC_BUTTON_OPEN_WAITINGROOM, &demoConfCtrlDlg::OnBnClickedButtonOpenWaitingroom)
    ON_BN_CLICKED(IDC_BUTTON_OPERATE_LOCALRECORD, &demoConfCtrlDlg::OnBnClickedButtonOperateLocalrecord)
    ON_BN_CLICKED(IDC_BUTTON_OPEN_VIRTUALBG_SETTING_PAGE, &demoConfCtrlDlg::OnBnClickedButtonOpenVirtualbgSettingPage)
    ON_BN_CLICKED(IDC_BUTTON_GET_CONF_LOCAL_RECORD_STATUS, &demoConfCtrlDlg::OnBnClickedButtonGetConfLocalRecordStatus)
    ON_BN_CLICKED(IDC_BUTTON_GET_SELF_LOCAL_RECORD_PERMISSION, &demoConfCtrlDlg::OnBnClickedButtonGetSelfLocalRecordPermission)
    ON_BN_CLICKED(IDC_BUTTON_REQUEST_LOCAL_RECORD_PERMISSION, &demoConfCtrlDlg::OnBnClickedButtonRequestLocalRecordPermission)
    ON_BN_CLICKED(IDC_BUTTON_APPLY_HOST_ROLE, &demoConfCtrlDlg::OnBnClickedButtonApplyHostRole)
    ON_BN_CLICKED(IDC_BUTTON_GET_SUBTITLE_PAGE_OPENED, &demoConfCtrlDlg::OnBnClickedButtonGetSubtitlePageOpened)
    ON_BN_CLICKED(IDC_BUTTON_GET_WAITINGROOM_OPENED, &demoConfCtrlDlg::OnBnClickedButtonGetWaitingroomOpened)
    ON_BN_CLICKED(IDC_BUTTON_GET_VIRTUAL_BACKGROUND_SETTING_PAGE_OPENED, &demoConfCtrlDlg::OnBnClickedButtonGetVirtualBackgroundSettingPageOpened)
END_MESSAGE_MAP()


// demoConfCtrlDlg 消息处理程序

/**
* 开启共享
*/
void demoConfCtrlDlg::OnBnClickedButtonGoStartShare()
{
    //发起共享弹框
    demoStartShareDlg dlg;
    INT_PTR nResponse = dlg.DoModal();
}

/**
* 停止共享
*/
void demoConfCtrlDlg::OnBnClickedButtonStopShare()
{
    //结束共享
    int ret = hwmsdkagent::StopShare();
    if (hwmsdk::HWM_COMMON_SUCCESS != ret)
    {
        CTools::OutputRetStr("StopShare error");
    }
}

/**
* 离开会议
*/
void demoConfCtrlDlg::OnBnClickedButtonLeaveConf()
{
    int ret = hwmsdkagent::LeaveConf();
    if (hwmsdk::HWM_COMMON_SUCCESS != ret)
    {
        CTools::OutputRetStr("LeaveConf error");
    }
}

/**
* 结束会议
*/
void demoConfCtrlDlg::OnBnClickedButtonStopConf()
{
    int ret = hwmsdkagent::EndConf();
    if (hwmsdk::HWM_COMMON_SUCCESS != ret)
    {
        CTools::OutputRetStr("EndConf error");
    }
}

/**
* 打开添加与会者窗口
*/
void demoConfCtrlDlg::OnBnClickedButtonGoAddAttendees()
{
    //添加与会者窗口
    demoAddAttendeeDlg dlg;
    INT_PTR nResponse = dlg.DoModal();
}

/**
* 打开设置共享透明窗口
*/
void demoConfCtrlDlg::OnBnClickedButtonGoSetTransWin()
{
    //设置透明窗口弹框
    demoSetTransparentWndDlg dlg;
    INT_PTR nResponse = dlg.DoModal();
}


void demoConfCtrlDlg::OnBnClickedButtonSetShareStrategy()
{
    //设置屏幕共享策略
    demoSetShareStrategyDlg dlg;
    INT_PTR nResponse = dlg.DoModal();
}


void demoConfCtrlDlg::OnBnClickedButtonSetShareAudio()
{
    //设置共享音频
    demoSetShareAudioDlg dlg;
    INT_PTR nResponse = dlg.DoModal();
}


void demoConfCtrlDlg::OnBnClickedButtonAvdeviceCtrl()
{
    // 开关音视频设备
    demoAVDeviceCtrlDlg dlg;
    INT_PTR nResponse = dlg.DoModal();
}

void demoConfCtrlDlg::OnBnClickedButtonGeneralWatch()
{
    // 选看
    demoGeneralWatchDlg dlg;
    INT_PTR nResponse = dlg.DoModal();
}

void demoConfCtrlDlg::OnBnClickedButtonSetAnnotationInfo()
{ 
    HWND annoWnd = GetAnnoWnd();
    // 设置标注渲染窗口
    hwmsdkagent::HwmAnnotationWndInfo info{};
    info.renderHandle = annoWnd;
    int ret = hwmsdkagent::SetAnnotationWindow(&info);
    if (ret != hwmsdk::HWM_COMMON_SUCCESS)
    {
        AfxMessageBox(_T("Set Annotation info failed"));
    }
}

void demoConfCtrlDlg::OnBnClickedButtonStartAnnotation()
{
    HWND annoWnd = GetAnnoWnd();
    // 开启标注
    hwmsdkagent::HwmAnnotationWndInfo info{};
    info.renderHandle = annoWnd;
    int ret = hwmsdkagent::StartAnnotation(&info);
    if (ret != hwmsdk::HWM_COMMON_SUCCESS)
    {
        AfxMessageBox(_T("Start Annotation failed"));
    }
}

HWND demoConfCtrlDlg::GetAnnoWnd()
{
    HWND annoWnd = NULL;
    if (demoData::GetInstance().GetAnnoWnd() != nullptr)
    {
        annoWnd = demoData::GetInstance().GetAnnoWnd()->m_hWnd;
    }

    if (!IsWindow(annoWnd))
    {
        int width = 1080;
        int height = 720;
        CustomWnd* annoTemp = new CustomWnd(width, height, WS_EX_APPWINDOW, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP);
        if (annoTemp != nullptr)
        {
            annoTemp->ShowWindow(SW_SHOW);
            annoTemp->UpdateWindow();
            annoWnd = annoTemp->m_hWnd;
            demoData::GetInstance().SetAnnoWnd(annoTemp);
        }
    }
    ::EnableWindow(annoWnd, true);
    return annoWnd;
}


void demoConfCtrlDlg::OnBnClickedButtonSaveAnnotation()
{
    // 保存标注
    demoAnnotationSaveConfigDlg dlg;
    INT_PTR nResponse = dlg.DoModal();
}

void demoConfCtrlDlg::OnBnClickedButtonStopAnnotation()
{
    int ret = hwmsdkagent::StopAnnotation();
    if (ret != hwmsdk::HWM_COMMON_SUCCESS)
    {
        AfxMessageBox(_T("Stop Annotation failed"));
    }
}

void demoConfCtrlDlg::OnBnClickedButtonSetAutoHideToolbar()
{
    // 设置自动隐藏会控栏
    demoSetAutoHideToolBarDlg dlg;
    INT_PTR nResponse = dlg.DoModal();
}

void demoConfCtrlDlg::OnBnClickedButtonGetSelfShareState()
{
    int ret = hwmsdkagent::GetSelfShareState();
    if (ret != hwmsdk::HWM_COMMON_SUCCESS)
    {
        AfxMessageBox(_T("GetSelfShareState failed"));
    }
}

void demoConfCtrlDlg::OnBnClickedButtonSubtitleSetting()
{
    // 字幕设置
    demoSubtitleSettingDlg dlg;
    INT_PTR nResponse = dlg.DoModal();
}


void demoConfCtrlDlg::OnBnClickedButtonOpenWaitingroom()
{
    // 开关等候室
    demoOpenWaitingroomDlg dlg;
    INT_PTR nResponse = dlg.DoModal();
}


void demoConfCtrlDlg::OnBnClickedButtonOperateLocalrecord()
{
    // 操作本地录制
    OperateLocalRecord dlg;
    INT_PTR nResponse = dlg.DoModal();
}


void demoConfCtrlDlg::OnBnClickedButtonOpenVirtualbgSettingPage()
{
    int ret = hwmsdkagent::OpenVirtualBackgroundSettingPage();
    if (ret != hwmsdk::HWM_COMMON_SUCCESS)
    {
        AfxMessageBox(_T("OpenVirtualBackgroundSettingPage failed"));
    }
}


void demoConfCtrlDlg::OnBnClickedButtonGetConfLocalRecordStatus()
{
    int ret = hwmsdkagent::GetConfLocalRecordStatus();
    if (ret != hwmsdk::HWM_COMMON_SUCCESS)
    {
        AfxMessageBox(_T("GetConfLocalRecordStatus failed"));
    }
}


void demoConfCtrlDlg::OnBnClickedButtonGetSelfLocalRecordPermission()
{
    int ret = hwmsdkagent::GetSelfHasLocalRecordPermission();
    if (ret != hwmsdk::HWM_COMMON_SUCCESS)
    {
        AfxMessageBox(_T("GetSelfHasLocalRecordPermission failed"));
    }
}


void demoConfCtrlDlg::OnBnClickedButtonRequestLocalRecordPermission()
{
    int ret = hwmsdkagent::RequestLocalRecordPermission();
    if (ret != hwmsdk::HWM_COMMON_SUCCESS)
    {
        AfxMessageBox(_T("RequestLocalRecordPermission failed"));
    }
}


void demoConfCtrlDlg::OnBnClickedButtonApplyHostRole()
{
    // 申请主持人
    demoApplyHostRoleDlg dlg;
    INT_PTR nResponse = dlg.DoModal();
}


void demoConfCtrlDlg::OnBnClickedButtonGetSubtitlePageOpened()
{
    int ret = hwmsdkagent::GetSubtitlePageOpened();
    if (ret != hwmsdk::HWM_COMMON_SUCCESS)
    {
        AfxMessageBox(_T("GetSubtitlePageOpened failed"));
    }
}


void demoConfCtrlDlg::OnBnClickedButtonGetWaitingroomOpened()
{
    int ret = hwmsdkagent::GetWaitingRoomOpened();
    if (ret != hwmsdk::HWM_COMMON_SUCCESS)
    {
        AfxMessageBox(_T("GetWaitingRoomOpened failed"));
    }
}


void demoConfCtrlDlg::OnBnClickedButtonGetVirtualBackgroundSettingPageOpened()
{
    int ret = hwmsdkagent::GetVirtualBackgroundSettingPageOpened();
    if (ret != hwmsdk::HWM_COMMON_SUCCESS)
    {
        AfxMessageBox(_T("GetVirtualBackgroundSettingPageOpened failed"));
    }
}
