使用Mailslots的好处是,你很容易将他们集成到你的MFC程序中。
BEGIN_MESSAGE_MAP(UserList, CDialog)
ON_MESSAGE(MAILSLOT_NOTIFY_MSG, OnMailSlotNotify)
END_MESSAGE_MAP()
LRESULT UserList::OnMailSlotNotify(WPARAM w, LPARAM l)
{
MailSlotMessage msg;
while (m_mailSlot.Read(msg)) {
if (msg.MsgType() == MailSlotMessage::TEXT) {
MailSlotDlg * pWnd = GetDlg(msg.FromComputerName(),
msg.FromUserName());
if (pWnd)
pWnd->AddMessageToHistory(msg);
} else {
if (msg.MsgText() == LOGIN_MSG) {
RefreshList();
}
}
}
return 1;
}