BCGControlBar使用(六)

实现图像热区

HotSpotDemo

 【原创】BCGControlBar使用(六)

其中对话框中客户区所显示的是一副图像。

 

(1)建立一个对话框和所要显示的图像。

(2)对话框的头文件

 CBCGPHotSpotImageCtrl m_Image;

 void InitImage ();

消息 afx_msg void OnClickHotSpot();

 

(3)Cpp文件

 ON_BN_CLICKED(IDC_IMAGE, OnClickHotSpot)

 

void CHotSpotDemoDlg::InitImage ()
{
 CRect rectClient;
 GetClientRect (rectClient);

 m_Image.Create (rectClient, this, IDC_IMAGE);

 m_Image.SetImage (IDR_IMAGE);//IDR_IMAGE是图像的ID
 m_Image.SetHighlightHotArea (82, 45);

 m_Image.AddHotSpot (1, CRect (CPoint (75, 145), CSize (128, 14)));
 m_Image.AddHotSpot (2, CRect (CPoint (75, 169), CSize (80, 14)));
 m_Image.AddHotSpot (3, CRect (CPoint (75, 197), CSize (96, 14)));

 CSize sizeImage = m_Image.GetImageSize ();

 CRect rectWindow;
 GetWindowRect (rectWindow);

 int cx = rectWindow.Width () - rectClient.Width () + sizeImage.cx;
 int cy = rectWindow.Height () - rectClient.Height () + sizeImage.cy;

 SetWindowPos (NULL, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
}

void CHotSpotDemoDlg::OnClickHotSpot()
{
 switch (m_Image.GetHotSpot ())
 {
 case 1:
  BCGPShowAboutDlg (AFX_IDS_APP_TITLE);
  break;

 case 2:
  ::ShellExecute (NULL, NULL, _T("http://www.bcgsoft.com"), NULL, NULL, NULL);
  break;

 case 3:
  OnCancel ();
  break;
 }
}

posted on 2010-08-16 17:41  carekee  阅读(472)  评论(0)    收藏  举报