#include "CWaitRecord.h"
#include "resource.h"
IMPLEMENT_DYNAMIC(CWaitRecord, CDialog)

CWaitRecord::CWaitRecord(CWnd* pParent)
    : CDialog(IDD_CMAPEDITOR_WAITRECORD, pParent)
{
}

CWaitRecord::~CWaitRecord()
{
}

void CWaitRecord::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
}

BOOL CWaitRecord::OnInitDialog()
{
    CDialog::OnInitDialog();
    timeid = SetTimer(1, 15, nullptr);
    return 0;
}

BEGIN_MESSAGE_MAP(CWaitRecord, CDialog)
    ON_BN_CLICKED(IDOK, &CWaitRecord::OnBnClickedOk)
    ON_WM_TIMER()
END_MESSAGE_MAP()

void CWaitRecord::OnBnClickedOk()
{
}


void CWaitRecord::OnTimer(UINT_PTR nIDEvent)
{
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    if (nIDEvent == timeid)
    {
        HANDLE hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, NULL, L"OcStore_Record");
        if (hMapFile)
        {
            void* data = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
            if (!data)
            {
                EndDialog(IDOK);
                return;
            }
            int BuffSize = ((int*)data)[0];
            DWORD* inputData = (DWORD*)((char*)data + 4);
            int len = (BuffSize - 4) / sizeof(DWORD);
            outRecord.resize(len);
            memcpy_s(outRecord.data(), sizeof(DWORD) * len, inputData, sizeof(DWORD) * len);
            //完成数据接收关闭游戏端
            ((int*)data)[0] = 0;
            UnmapViewOfFile(data);
            CloseHandle(hMapFile);
            EndDialog(IDOK);
        }
    }
    CDialog::OnTimer(nIDEvent);
}
