| | |
| | | #include "Servo.h" |
| | | #include "MsgDlg.h" |
| | | #include "afxdialogex.h" |
| | | #include <memory> |
| | | |
| | | |
| | | // CMsgDlg 对话框 |
| | |
| | | CMsgDlg::CMsgDlg(CWnd* pParent /*=nullptr*/) |
| | | : CDialogEx(IDD_DIALOG_MSG, pParent) |
| | | { |
| | | m_uiThreadId = ::GetCurrentThreadId(); |
| | | m_nCompleteCode = 0; |
| | | m_dwData = 0; |
| | | m_dwDataEx = 0; |
| | |
| | | m_crTitle = CR_MSGBOX_TITLE; |
| | | m_crMessage = CR_MSGBOX_MESSAGE; |
| | | m_nIcon = MSG_BOX_TIP; |
| | | m_bDelayClose = FALSE; |
| | | } |
| | | |
| | | CMsgDlg::CMsgDlg(CString strTitle, CString strMessage) |
| | | : CDialogEx(IDD_DIALOG_MSG, NULL) |
| | | { |
| | | m_uiThreadId = ::GetCurrentThreadId(); |
| | | m_strTitle = strTitle; |
| | | m_strMessage = strMessage; |
| | | m_crBkgnd = CR_MSGBOX_BKGND; |
| | |
| | | CMsgDlg::CMsgDlg(int nIcon, CString strTitle, CString strMessage) |
| | | : CDialogEx(IDD_DIALOG_MSG, NULL) |
| | | { |
| | | m_uiThreadId = ::GetCurrentThreadId(); |
| | | m_strTitle = strTitle; |
| | | m_strMessage = strMessage; |
| | | m_crBkgnd = CR_MSGBOX_BKGND; |
| | |
| | | CDialogEx::DoDataExchange(pDX); |
| | | } |
| | | |
| | | bool CMsgDlg::IsUiThread() const |
| | | { |
| | | return ::GetCurrentThreadId() == m_uiThreadId; |
| | | } |
| | | |
| | | LRESULT CMsgDlg::OnMsgSetTitle(WPARAM wParam, LPARAM lParam) |
| | | { |
| | | std::unique_ptr<CString> str(reinterpret_cast<CString*>(lParam)); |
| | | SetTitle(*str); |
| | | return 0; |
| | | } |
| | | |
| | | LRESULT CMsgDlg::OnMsgSetMessage(WPARAM wParam, LPARAM lParam) |
| | | { |
| | | std::unique_ptr<CString> str(reinterpret_cast<CString*>(lParam)); |
| | | SetMessage(*str); |
| | | return 0; |
| | | } |
| | | |
| | | LRESULT CMsgDlg::OnMsgSetIcon(WPARAM wParam, LPARAM lParam) |
| | | { |
| | | SetIcon(static_cast<int>(wParam)); |
| | | return 0; |
| | | } |
| | | |
| | | LRESULT CMsgDlg::OnMsgSetMarquee(WPARAM wParam, LPARAM lParam) |
| | | { |
| | | SetMarquee((BOOL)wParam, (int)lParam); |
| | | return 0; |
| | | } |
| | | |
| | | LRESULT CMsgDlg::OnMsgDelayClose(WPARAM wParam, LPARAM lParam) |
| | | { |
| | | DelayClose((int)wParam); |
| | | return 0; |
| | | } |
| | | |
| | | LRESULT CMsgDlg::OnMsgSetComplete(WPARAM wParam, LPARAM lParam) |
| | | { |
| | | SetCompleteCode((int)wParam); |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | BEGIN_MESSAGE_MAP(CMsgDlg, CDialogEx) |
| | | ON_WM_TIMER() |
| | | ON_WM_CTLCOLOR() |
| | | ON_WM_SIZE() |
| | | ON_MESSAGE(WM_MSGDLG_SET_TITLE, &CMsgDlg::OnMsgSetTitle) |
| | | ON_MESSAGE(WM_MSGDLG_SET_MESSAGE, &CMsgDlg::OnMsgSetMessage) |
| | | ON_MESSAGE(WM_MSGDLG_SET_ICON, &CMsgDlg::OnMsgSetIcon) |
| | | ON_MESSAGE(WM_MSGDLG_SET_MARQUEE, &CMsgDlg::OnMsgSetMarquee) |
| | | ON_MESSAGE(WM_MSGDLG_DELAY_CLOSE, &CMsgDlg::OnMsgDelayClose) |
| | | ON_MESSAGE(WM_MSGDLG_SET_COMPLETE, &CMsgDlg::OnMsgSetComplete) |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | |
| | | |
| | | void CMsgDlg::SetCompleteCode(int code) |
| | | { |
| | | if (!IsUiThread()) { |
| | | PostMessage(WM_MSGDLG_SET_COMPLETE, (WPARAM)code, 0); |
| | | return; |
| | | } |
| | | m_nCompleteCode = code; |
| | | CWnd* pProgressCtrl = GetDlgItem(IDC_PROGRESS1); |
| | | if(pProgressCtrl != nullptr) pProgressCtrl->ShowWindow(SW_HIDE); |
| | |
| | | |
| | | void CMsgDlg::SetIcon(int nIcon) |
| | | { |
| | | if (!IsUiThread()) { |
| | | PostMessage(WM_MSGDLG_SET_ICON, (WPARAM)nIcon, 0); |
| | | return; |
| | | } |
| | | m_nIcon = nIcon; |
| | | if (::IsWindow(m_hWnd)) { |
| | | UpdateIcon(); |
| | |
| | | |
| | | void CMsgDlg::SetTitle(CString strTitle) |
| | | { |
| | | if (!IsUiThread()) { |
| | | CString* pStr = new CString(strTitle); |
| | | if (!PostMessage(WM_MSGDLG_SET_TITLE, 0, (LPARAM)pStr)) { |
| | | delete pStr; |
| | | } |
| | | return; |
| | | } |
| | | m_strTitle = strTitle; |
| | | if (::IsWindow(m_hWnd) && GetDlgItem(IDC_LABEL_TITLE) != NULL) { |
| | | SetWindowText(m_strTitle); |
| | |
| | | |
| | | void CMsgDlg::SetMessage(CString strMessage) |
| | | { |
| | | if (!IsUiThread()) { |
| | | CString* pStr = new CString(strMessage); |
| | | if (!PostMessage(WM_MSGDLG_SET_MESSAGE, 0, (LPARAM)pStr)) { |
| | | delete pStr; |
| | | } |
| | | return; |
| | | } |
| | | m_strMessage = strMessage; |
| | | if (::IsWindow(m_hWnd) && GetDlgItem(IDC_LABEL_MSG) != NULL) { |
| | | SetDlgItemText(IDC_LABEL_MSG, m_strMessage); |
| | |
| | | |
| | | void CMsgDlg::SetMarquee(_In_ BOOL fMarqueeMode, _In_ int nInterval) |
| | | { |
| | | if (!IsUiThread()) { |
| | | PostMessage(WM_MSGDLG_SET_MARQUEE, (WPARAM)fMarqueeMode, (LPARAM)nInterval); |
| | | return; |
| | | } |
| | | if (!::IsWindow(m_hWnd)) { |
| | | return; |
| | | } |
| | |
| | | |
| | | void CMsgDlg::DelayClose(int nDelay) |
| | | { |
| | | SetTimer(1, nDelay, NULL); |
| | | if (!IsUiThread()) { |
| | | PostMessage(WM_MSGDLG_DELAY_CLOSE, (WPARAM)nDelay, 0); |
| | | return; |
| | | } |
| | | if (!m_bDelayClose) { |
| | | m_bDelayClose = TRUE; |
| | | SetTimer(1, nDelay, NULL); |
| | | } |
| | | } |
| | | |
| | | void CMsgDlg::ShowCloseButton(BOOL bVisible) |
| | |
| | | BOOL CMsgDlg::OnInitDialog() |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | m_uiThreadId = ::GetCurrentThreadId(); |
| | | |
| | | SetWindowText(m_strTitle); |
| | | SetDlgItemText(IDC_LABEL_TITLE, m_strTitle); |