📄 bcmsgdlg.cpp
字号:
str = m_Grid.GetText();
if (str.GetLength()==0)
{ // need create message window
if (g_TempMsgsVec.num >= MSG_MAX)
{
MessageBox(TEXT("消息数量已经到达最大!"), TEXT("警告"), MB_OK | MB_ICONWARNING);
return;
}
CMsgTypeDlg dlgMsgCreate;
if ((dlgMsgCreate.DoModal())==IDOK)
{
msgChangeType = MSGCTYPE_ADD;
CMsgShowDlg dlgMsgShow;
dlgMsgShow.DoModal();
UpdateMessageList();
}
}
else
{
// Modify Message, only show Message Edit Window
memset(szTempMsgName, 0, sizeof(szTempMsgName)); // fill message name
strcpy(szTempMsgName, str.GetBuffer(str.GetLength()));
// fill message body
//
g_TempMsg.msg.ChannelSelect = g_TempMsgsVec.msgAry[idx].msg.ChannelSelect; // default to channel A
g_TempMsg.msg.InterMSGGapTime = g_TempMsgsVec.msgAry[idx].msg.InterMSGGapTime;
g_TempMsg.msg.MSGFormat = g_TempMsgsVec.msgAry[idx].msg.MSGFormat; // default to BC-RT
g_TempMsg.msg.RetryEnable = g_TempMsgsVec.msgAry[idx].msg.RetryEnable;
g_TempMsg.blocklen = g_TempMsgsVec.msgAry[idx].blocklen;
for (i = 0; i < MSGBLOCKSIZE; i++) // block data
{
g_TempMsg.msg.MSGBlock[i] = g_TempMsgsVec.msgAry[idx].msg.MSGBlock[i];
}
msgChangeType = MSGCTYPE_MODIFY;
CMsgShowDlg dlgMsgShow;
dlgMsgShow.DoModal();
UpdateMessageList();
}
}
void CBCMsgDlg::OnBcmsgBtAdd()
{
// TODO: Add your control notification handler code here
// TODO: Add your control notification handler code here
if (g_TempMsgsVec.num >= MSG_MAX)
{
MessageBox(TEXT("消息数量已经到达最大!"), TEXT("警告"), MB_OK | MB_ICONWARNING);
return;
}
if (Button_GetCheck(::GetDlgItem(this->m_hWnd, IDC_BCMSG_CK_FROMF)) != BST_UNCHECKED)
{
// Add message from file
AddMessageFromFile();
}
else
{
// Add message by user
//
CMsgTypeDlg dlgMsgCreate;
if ((dlgMsgCreate.DoModal())==IDOK)
{
msgChangeType = MSGCTYPE_ADD;
CMsgShowDlg dlgMsgShow;
dlgMsgShow.DoModal();
}
}
// Add New Message to list
//
UpdateMessageList();
}
void CBCMsgDlg::OnBcmsgBtDel()
{
// TODO: Add your control notification handler code here
long y=0;
int rt=0;
char c[80];
int len=0;
if (g_TempMsgsVec.num == 0)
{
MessageBox(TEXT("消息数量已经为 0 !"), TEXT("警告"), MB_OK | MB_ICONWARNING);
return;
}
y = this->m_Grid.GetRowSel();
rt = MsgDel(&g_TempMsgsVec, y-1);
switch (rt)
{
case -1: // ! channel Error
// don't warry
break;
case -2: // ! message length error
MessageBox(TEXT("消息数量已经为 0 !"), TEXT("警告"), MB_OK | MB_ICONWARNING);
break;
case -3: // ! idx > len
MessageBox(TEXT("idx 大于现有消息总量!"), TEXT("警告"), MB_OK | MB_ICONWARNING);
break;
default:
break;
}
if (m_Grid.GetRows()==2)
{
UpdateMessageList();
}
else
{
m_Grid.RemoveItem(y);
}
len = g_TempMsgsVec.num;
itoa(len, c, 10);
::SetWindowText(::GetDlgItem(m_hWnd, IDC_BCMSG_ED_MSGCNT), c);
}
void CBCMsgDlg::OnBcmsgBtClear()
{
// TODO: Add your control notification handler code here
if (g_TempMsgsVec.num == 0)
{
MessageBox(TEXT("消息数量已经为 0 !"), TEXT("警告"), MB_OK | MB_ICONWARNING);
return;
}
::MsgClear(&g_TempMsgsVec);
msgChangeType = MSGCTYPE_INIT;
UpdateMessageList();
}
void CBCMsgDlg::OnBcmsgBtSave()
{
// TODO: Add your control notification handler code here
FILE *pf;
INT len=0;
INT i=0;
DWORD cnt=0;
CString strpath;
len = g_TempMsgsVec.num;
cnt = len;
if (len == 0)
{
MessageBox(TEXT("消息数量为 0 !"), TEXT("警告"), MB_OK | MB_ICONWARNING);
return;
}
CFileDialog OpenDlg(FALSE, TEXT(".msg"), TEXT("BC Msg.msg"),
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
TEXT("消息文件 (*.msg)|*.msg||"), NULL);
if ((OpenDlg.DoModal())!=IDOK)
{
return;
}
strpath = OpenDlg.GetPathName(); // create file
pf = fopen(strpath, "w+b");
if (pf==NULL)
{
MessageBox("创建文件失败!", "错误", MB_OK | MB_ICONERROR);
return;
}
fwrite("SMSG", sizeof(char), 4, pf); // write message Head flag
fwrite(&cnt, sizeof(cnt), 1, pf); // write message count
for (i=0; i<len; i++) // write message body
{
fwrite(g_TempMsgsVec.msgAry[i].msgname, sizeof(g_TempMsgsVec.msgAry[i].msgname), 1, pf);
fwrite(&(g_TempMsgsVec.msgAry[i].blocklen), sizeof(g_TempMsgsVec.msgAry[i].blocklen), 1, pf);
fwrite(&(g_TempMsgsVec.msgAry[i].msg.MSGFormat), sizeof(g_TempMsgsVec.msgAry[i].msg.MSGFormat), 1, pf);
fwrite(&(g_TempMsgsVec.msgAry[i].msg.ChannelSelect), sizeof(g_TempMsgsVec.msgAry[i].msg.ChannelSelect), 1, pf);
fwrite(&(g_TempMsgsVec.msgAry[i].msg.InterMSGGapTime), sizeof(g_TempMsgsVec.msgAry[i].msg.InterMSGGapTime), 1, pf);
fwrite(&(g_TempMsgsVec.msgAry[i].msg.RetryEnable), sizeof(g_TempMsgsVec.msgAry[i].msg.RetryEnable), 1, pf);
fwrite(&(g_TempMsgsVec.msgAry[i].msg.MSGBlock), sizeof(g_TempMsgsVec.msgAry[i].msg.MSGBlock), 1, pf);
}
fclose(pf); // close file
}
void CBCMsgDlg::AddMessageFromFile()
{
FILE *pf;
CString strpath;
int len=0;
int i=0;
DWORD j=0;
DWORD cnt=0;
char flag[8];
int rt=0;
char c[256];
CHAR szTempMsgName[MSGNAME_MAX];
memset(flag, 0, sizeof(flag));
memset(c, 0, sizeof(c));
len = g_TempMsgsVec.num;
CFileDialog OpenDlg(TRUE, TEXT(".msg"), TEXT("BC Msg.msg"),
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
TEXT("消息文件 (*.msg)|*.msg||"), NULL);
if ((OpenDlg.DoModal())!=IDOK)
{
return;
}
strpath = OpenDlg.GetPathName(); // create file
pf = fopen(strpath, "r+b");
if (pf==NULL)
{
MessageBox("打开文件失败!", "错误", MB_OK | MB_ICONERROR);
return;
}
if (fread(flag, sizeof(char), 4, pf)!=4) // read message Head flag
{
fclose(pf);
MessageBox("加载消息文件失败!", "错误", MB_OK | MB_ICONERROR);
return;
}
else
{
if (strcmp(flag, "SMSG")!=0)
{
fclose(pf);
MessageBox("非消息文件类型!", "错误", MB_OK | MB_ICONERROR);
return;
}
}
if (fread(&cnt, sizeof(cnt), 1, pf)!=1) // read message count
{
fclose(pf);
MessageBox("加载消息文件失败!", "错误", MB_OK | MB_ICONERROR);
return;
}
else
{
if (cnt > MSG_MAX)
{
fclose(pf);
MessageBox("文件中消息数量出错!", "错误", MB_OK | MB_ICONERROR);
return;
}
}
while ((feof(pf) == 0)&&(len < MSG_MAX)&&(j < cnt)) // read message body
{
fread(szTempMsgName, sizeof(szTempMsgName), 1, pf);
for(int u = 0; u < MSGNAME_MAX; u++)
{
g_TempMsg.msgname[u] = szTempMsgName[u];
}
fread(&(g_TempMsg.blocklen), sizeof(g_TempMsg.blocklen), 1, pf);
fread(&(g_TempMsg.msg.MSGFormat), sizeof(g_TempMsg.msg.MSGFormat), 1, pf);
fread(&(g_TempMsg.msg.ChannelSelect), sizeof(g_TempMsg.msg.ChannelSelect), 1, pf);
fread(&(g_TempMsg.msg.InterMSGGapTime), sizeof(g_TempMsg.msg.InterMSGGapTime), 1, pf);
fread(&(g_TempMsg.msg.RetryEnable), sizeof(g_TempMsg.msg.RetryEnable), 1, pf);
fread(&g_TempMsg.msg.MSGBlock, sizeof(g_TempMsg.msg.MSGBlock), 1, pf);
rt = MsgAdd(&g_TempMsgsVec, &g_TempMsg, 0);
switch (rt)
{
case 0: // Message Overflow Error
MessageBox(TEXT("消息总量超出,无法添加消息到列表!"), TEXT("信息提示"), MB_OK | MB_ICONEXCLAMATION);
len = MSG_MAX;
break;
case -1: // channel No. Error
// don't warry
break;
case -2: // find same message, but not needn't modify
sprintf(c, "发现同名消息{%s},确认更新该消息吗?", szTempMsgName);
if (MessageBox(TEXT(c), TEXT("信息提示"), MB_OKCANCEL | MB_ICONEXCLAMATION)==IDOK)
{
//::MsgQueue_Add(i, 1); // modify message
}
break;
case -3: // message name is NULL
// don't warry
break;
default: // OK
len++;
break;
}
j++;
}
g_TempMsgsVec.num = len;
fclose(pf); // close file
msgChangeType = MSGCTYPE_INIT;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -