现在的位置: 首页 > 综合 > 正文

自定义MessageBox消息图标 .

2013年08月08日 ⁄ 综合 ⁄ 共 3738字 ⁄ 字号 评论关闭

效果图:

实现代码:

  1. int SetMessageBoxInfo(CString parm_text, CString parm_caption,  
  2.                                int parm_style, int parm_icon_id)  
  3. {  
  4.     MSGBOXPARAMS msg_info;  
  5.     memset(&msg_info, 0, sizeof(MSGBOXPARAMS));   
  6.   
  7.     // 初始化结构体大小   
  8.     msg_info.cbSize = sizeof(MSGBOXPARAMS);   
  9.   
  10.     // 拥有的窗口句柄,指定一个值   
  11.     msg_info.hwndOwner = NULL;   
  12.   
  13.     // 如果你不使用的图标资源,并不需要明确。
      
  14.     msg_info.hInstance = AfxGetApp()->m_hInstance;           
  15.   
  16.     // 指定的文本将显示在消息框   
  17.     msg_info.lpszText = parm_text;   
  18.   
  19.     // 消息框显示在标题指定标题的人   
  20.     msg_info.lpszCaption = parm_caption;   
  21.   
  22.     // 消息框样式指定   
  23.     msg_info.dwStyle = parm_style | MB_USERICON;   
  24.   
  25.     // 使用图标资源的人表示,为了使用这种说法,是一定要因素dwStyle
      
  26.     // MB_USERICON 你必须得到明确。   
  27.     msg_info.lpszIcon = MAKEINTRESOURCE(parm_icon_id);  
  28.   
  29.     // 定义消息框,根据打印信息。   
  30.     int result = MessageBoxIndirect(&msg_info);   
  31.   
  32.     // 在选定按钮的消息框的ID返回一个值。    
  33.     return result;   
  34. }    

按钮测试事件:

  1. void CewwDlg::OnBnClickedButton1()  
  2. {  
  3.   
  4.     SetMessageBoxInfo("←自定义消息图标测试","King.Sollyu",MB_OKCANCEL, IDI_ICON1);  
  5.   
  6. }  

自定义按钮内容 连接:

http://blog.csdn.net/kingsollyu/article/details/6077014

效果图:

实现代码:

  1. int SetMessageBoxInfo(CString parm_text, CString parm_caption,  
  2.                                int parm_style, int parm_icon_id)  
  3. {  
  4.     MSGBOXPARAMS msg_info;  
  5.     memset(&msg_info, 0, sizeof(MSGBOXPARAMS));   
  6.   
  7.     // 初始化结构体大小   
  8.     msg_info.cbSize = sizeof(MSGBOXPARAMS);   
  9.   
  10.     // 拥有的窗口句柄,指定一个值   
  11.     msg_info.hwndOwner = NULL;   
  12.   
  13.     // 如果你不使用的图标资源,并不需要明确。
      
  14.     msg_info.hInstance = AfxGetApp()->m_hInstance;           
  15.   
  16.     // 指定的文本将显示在消息框   
  17.     msg_info.lpszText = parm_text;   
  18.   
  19.     // 消息框显示在标题指定标题的人   
  20.     msg_info.lpszCaption = parm_caption;   
  21.   
  22.     // 消息框样式指定   
  23.     msg_info.dwStyle = parm_style | MB_USERICON;   
  24.   
  25.     // 使用图标资源的人表示,为了使用这种说法,是一定要因素dwStyle
      
  26.     // MB_USERICON 你必须得到明确。   
  27.     msg_info.lpszIcon = MAKEINTRESOURCE(parm_icon_id);  
  28.   
  29.     // 定义消息框,根据打印信息。   
  30.     int result = MessageBoxIndirect(&msg_info);   
  31.   
  32.     // 在选定按钮的消息框的ID返回一个值。    
  33.     return result;   
  34. }    

按钮测试事件:

  1. void CewwDlg::OnBnClickedButton1()  
  2. {  
  3.   
  4.     SetMessageBoxInfo("←自定义消息图标测试","King.Sollyu",MB_OKCANCEL, IDI_ICON1);  
  5.   
  6. }  

自定义按钮内容 连接:

http://blog.csdn.net/kingsollyu/article/details/6077014

抱歉!评论已关闭.