BCGControlBar使用(八)

消息提示框

PopupDemo

MSN样式



自定义样式

1.创建CMSNDlg类(含控件摆放),派生于CBCGPPopupDlg,必须是子(child)类型

void CMSNDlg::OnDraw (CDC* pDC)
{
 CBCGPPopupDlg::OnDraw (pDC);

 CRect rectClient;
 GetClientRect (rectClient);

 CSize sizeLogo = m_imgLogo.GetImageSize ();

 CBCGPDrawState ds;
 m_imgLogo.PrepareDrawImage (ds);

 m_imgLogo.Draw (pDC,
  rectClient.right - sizeLogo.cx - 5,
  rectClient.bottom - sizeLogo.cy - 5,
  0);

 m_imgLogo.EndDrawImage (ds);
}


BOOL CMSNDlg::OnInitDialog()
{
 CBCGPPopupDlg::OnInitDialog();
 
 m_Options.m_bAlwaysUnderlineText = FALSE;
 m_Options.m_bDefaultClickProcess = FALSE;
 
 m_btnRL.m_bMultilineText = TRUE;
 m_btnRL.m_bAlwaysUnderlineText = FALSE;
 m_btnRL.m_bDefaultClickProcess = TRUE;

 m_imgLogo.Load (IDB_LOGO);
 m_imgLogo.SetTransparentColor (RGB (236, 0, 140));
 m_imgLogo.SetSingleImage ();

 return TRUE;  // return TRUE unless you set the focus to a control
               // EXCEPTION: OCX Property Pages should return FALSE
}

void CMSNDlg::OnButton1()
{
 ::ShellExecute (NULL, NULL, _T("http://www.bcgsoft.com"), NULL, NULL, NULL);
}

void CMSNDlg::OnOptions()
{
 // TODO: Add your control notification handler code here
 
}

 

2.创建CMyPopupDlg类,同样派生于CBCGPPopupDlg

BOOL CMyPopupDlg::OnInitDialog()
{
 CBCGPPopupDlg::OnInitDialog();

 LOGFONT lf;
 m_wndFrom.GetFont ()->GetLogFont (&lf);

 lf.lfWeight = FW_BOLD;
 m_fontBold.CreateFontIndirect (&lf);
 
 m_wndFrom.SetFont (&m_fontBold);
 m_btnFlag.SetImage (IDB_FLAG);
 m_btnDelete.SetImage (IDB_DELETE);

 m_btnRL.m_bMultilineText = TRUE;
 m_btnRL.m_bAlwaysUnderlineText = FALSE;
 m_btnRL.m_bDefaultClickProcess = TRUE;
 
 return TRUE;  // return TRUE unless you set the focus to a control
               // EXCEPTION: OCX Property Pages should return FALSE
}

void CMyPopupDlg::OnDelete()
{
 GetParent ()->PostMessage (WM_CLOSE);
}

void CMyPopupDlg::OnFlag()
{
 GetParent ()->PostMessage (WM_CLOSE);
}

void CMyPopupDlg::OnButton1()
{
 GetParent ()->PostMessage (WM_CLOSE);
}

 

3.在需要使用的时候

 CBCGPPopupWindow* pPopup = new CBCGPPopupWindow;

 pPopup->SetAnimationType ((CBCGPPopupMenu::ANIMATION_TYPE) m_nAnimation);
 pPopup->SetAnimationSpeed (m_nAnimationSpeed);
 pPopup->SetTransparency ((BYTE)m_nTransparency);
 pPopup->SetSmallCaption (m_bSmallCaption);//标题栏只有几个小点,见自定义样式
 pPopup->SetAutoCloseTime (m_bAutoClose ? m_nAutoCloseTime * 1000 : 0);

 if (m_nPopupSource == 0)
 {
  if (m_nVisualMngr == 5) // MSN-style
  {
   pPopup->Create (this, IDD_DIALOG2, NULL, //IDD_DIALOG2对应CMSNDlg
    m_ptPopup, RUNTIME_CLASS (CMSNDlg));
  }
  else
  {
   pPopup->Create (this, IDD_DIALOG1,
    m_menuPopup.GetSubMenu (0)->GetSafeHmenu (), //下箭头对应的下拉菜单
    m_ptPopup, RUNTIME_CLASS (CMyPopupDlg));
  }
 }
 else
 {
  // Create indirect:
  CBCGPPopupWndParams params;

  if (m_nIcon > 0)
  {
   params.m_hIcon = m_Icons.ExtractIcon (m_nIcon - 1);
  }

  params.m_strText = m_strText;
  params.m_strURL = m_strLink;
  params.m_nURLCmdID = 101;

  pPopup->Create (this, params, NULL, m_ptPopup);
 }

 HICON hIcon = (HICON) ::LoadImage (::AfxGetResourceHandle (),
  MAKEINTRESOURCE (IDR_MAINFRAME),
    IMAGE_ICON, ::GetSystemMetrics (SM_CXSMICON), ::GetSystemMetrics (SM_CYSMICON), 0);

 pPopup->SetIcon (hIcon, FALSE);
 pPopup->SetWindowText (_T("Message"));

你可能感兴趣的:(BCGControlBar使用(八))