1 // HelpDlg.cpp : 实现文件 2 // 3 4 #include "stdafx.h" 5 #include "MusicPlayer2.h" 6 #include "MessageDlg.h" 7 8 9 // CMessageDlg 对话框 10 11 #define MESSAGE_DLG_ICON_SIZE (theApp.DPI(32)) 12 13 IMPLEMENT_DYNAMIC(CMessageDlg, CDialog) 14 15 CMessageDlg::CMessageDlg(CWnd* pParent /*=NULL*/) 16 : CDialog(IDD_MESSAGE_DIALOG, pParent) 17 { 18 19 } 20 21 CMessageDlg::~CMessageDlg() 22 { 23 } 24 25 void CMessageDlg::SetWindowTitle(LPCTSTR str) 26 { 27 m_title = str; 28 } 29 30 void CMessageDlg::SetInfoText(LPCTSTR str) 31 { 32 m_info = str; 33 } 34 35 void CMessageDlg::SetMessageText(LPCTSTR str) 36 { 37 m_message = str; 38 } 39 40 void CMessageDlg::SetLinkInfo(LPCTSTR text, LPCTSTR url) 41 { 42 m_link_text = text; 43 m_link_url = url; 44 } 45 46 void CMessageDlg::SetMessageIcon(HICON hIcon) 47 { 48 m_icon = hIcon; 49 } 50 51 void CMessageDlg::SetInfoStaticSize(int cx) 52 { 53 if (m_icon != NULL && m_info_static.GetSafeHwnd() != NULL) 54 { 55 CRect rc_info{ m_rc_info }; 56 rc_info.left = m_rc_info.left + MESSAGE_DLG_ICON_SIZE + theApp.DPI(8); 57 if (cx > 0) 58 rc_info.right = cx; 59 m_info_static.MoveWindow(rc_info); 60 } 61 } 62 63 void CMessageDlg::DoDataExchange(CDataExchange* pDX) 64 { 65 CDialog::DoDataExchange(pDX); 66 DDX_Control(pDX, IDC_HELP_EDIT, m_message_edit); 67 DDX_Control(pDX, IDC_INFO_STATIC, m_info_static); 68 } 69 70 71 BEGIN_MESSAGE_MAP(CMessageDlg, CDialog) 72 ON_WM_GETMINMAXINFO() 73 ON_NOTIFY(NM_CLICK, IDC_SYSLINK1, &CMessageDlg::OnNMClickSyslink1) 74 ON_WM_PAINT() 75 ON_WM_SIZE() 76 END_MESSAGE_MAP() 77 78 79 // CMessageDlg 消息处理程序 80 81 82 BOOL CMessageDlg::OnInitDialog() 83 { 84 CDialog::OnInitDialog(); 85 86 // TODO: 在此添加额外的初始化 87 88 SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME), FALSE); // 设置小图标 89 90 //获取初始时窗口的大小 91 CRect rect; 92 GetWindowRect(rect); 93 m_min_size.cx = rect.Width(); 94 m_min_size.cy = rect.Height(); 95 96 SetWindowText(m_title); 97 m_info_static.SetWindowText(m_info); 98 m_message_edit.SetWindowText(m_message); 99 100 CWnd* pLinkCtrl = GetDlgItem(IDC_SYSLINK1); 101 if (pLinkCtrl != nullptr) 102 { 103 pLinkCtrl->ShowWindow(m_show_link_ctrl); 104 pLinkCtrl->SetWindowText(_T("<a>") + m_link_text + _T("</a>")); 105 } 106 107 //设置图标的位置 108 if (m_icon != NULL) 109 { 110 CRect rc_edit; 111 m_message_edit.GetWindowRect(rc_edit); 112 ScreenToClient(rc_edit); 113 m_icon_pos.x = rc_edit.left; 114 m_icon_pos.y = (rc_edit.top - MESSAGE_DLG_ICON_SIZE) / 2; 115 116 m_info_static.GetWindowRect(m_rc_info); 117 ScreenToClient(m_rc_info); 118 SetInfoStaticSize(0); 119 } 120 121 return TRUE; // return TRUE unless you set the focus to a control 122 // 异常: OCX 属性页应返回 FALSE 123 } 124 125 126 void CMessageDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI) 127 { 128 // TODO: 在此添加消息处理程序代码和/或调用默认值 129 //限制窗口最小大小 130 lpMMI->ptMinTrackSize.x = m_min_size.cx; //设置最小宽度 131 lpMMI->ptMinTrackSize.y = m_min_size.cy; //设置最小高度 132 133 CDialog::OnGetMinMaxInfo(lpMMI); 134 } 135 136 137 void CMessageDlg::OnNMClickSyslink1(NMHDR *pNMHDR, LRESULT *pResult) 138 { 139 // TODO: 在此添加控件通知处理程序代码 140 if(!m_link_url.IsEmpty()) 141 ShellExecute(NULL, _T("open"), m_link_url, NULL, NULL, SW_SHOW); //打开超链接 142 143 *pResult = 0; 144 } 145 146 147 void CMessageDlg::OnPaint() 148 { 149 CPaintDC dc(this); // device context for painting 150 // TODO: 在此处添加消息处理程序代码 151 // 不为绘图消息调用 CDialog::OnPaint() 152 153 CDrawCommon draw; 154 draw.Create(&dc, this); 155 draw.DrawIcon(m_icon, m_icon_pos, CSize(MESSAGE_DLG_ICON_SIZE, MESSAGE_DLG_ICON_SIZE)); 156 } 157 158 159 void CMessageDlg::OnSize(UINT nType, int cx, int cy) 160 { 161 CDialog::OnSize(nType, cx, cy); 162 163 // TODO: 在此处添加消息处理程序代码 164 SetInfoStaticSize(cx); 165 } 166