VC Picture Control 图片点击事件

VC 中Picture Control 添加图片和点击事件,比C#等语言稍微较麻烦

一、添加图片

1、在窗体添加Picture Control控件

VC Picture Control 图片点击事件

2、代码添加图片

	HBITMAP hBmpWSUS = (HBITMAP)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDB_BITMAP_WSUS), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);	// 关联图片ID
	HBITMAP hBmpVIRUS = (HBITMAP)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDB_BITMAP_VIRUS), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);
	HBITMAP hBmpSOFT = (HBITMAP)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDB_BITMAP_SOFT), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);


	CStatic *pStaticWSUS = (CStatic*)GetDlgItem(IDC_PIC_WSUS);		// 获取指向静态控件的指针
	pStaticWSUS->ModifyStyle(0xF, SS_BITMAP|SS_CENTERIMAGE);		// 设置静态控件的样式,使其位图居中显示
	pStaticWSUS->SetBitmap(hBmpWSUS);								// 设置静态控件的显示位图

	CStatic *pStaticVIRUS = (CStatic*)GetDlgItem(IDC_PIC_VIRUSLIST);		
	pStaticVIRUS->ModifyStyle(0xF, SS_BITMAP|SS_CENTERIMAGE);		
	pStaticVIRUS->SetBitmap(hBmpVIRUS);		

	CStatic *pStaticSOFT = (CStatic*)GetDlgItem(IDC_PIC_SOFTLIST);		
	pStaticSOFT->ModifyStyle(0xF, SS_BITMAP|SS_CENTERIMAGE);		
	pStaticSOFT->SetBitmap(hBmpSOFT);


3、图片显示效果

二、点击事件

1、设置Picture Control 的 notify 属性为 true

2、头文件.h添加三个方法

public:
afx_msg void OnStnClickedPicWsus();
afx_msg void OnStnClickedPicViruslist();
afx_msg void OnStnClickedPicSoftlist();

3、源码.cpp文件添加消息映射

BEGIN_MESSAGE_MAP(Main, CDialog)

ON_STN_CLICKED(IDC_PIC_WSUS, &Main::OnStnClickedPicWsus)
ON_STN_CLICKED(IDC_PIC_VIRUSLIST, &Main::OnStnClickedPicViruslist)
ON_STN_CLICKED(IDC_PIC_SOFTLIST, &Main::OnStnClickedPicSoftlist)

...
END_MESSAGE_MAP()

4、实现单击事件方法

void Main::OnStnClickedPicWsus()
{
wsusDlg.ShowWindow(TRUE);
virusListDlg.ShowWindow(FALSE);
softListDlg.ShowWindow(FALSE);
}

void Main::OnStnClickedPicViruslist()
{
virusListDlg.ShowWindow(TRUE);
wsusDlg.ShowWindow(FALSE);
softListDlg.ShowWindow(FALSE);
}

void Main::OnStnClickedPicSoftlist()
{
softListDlg.ShowWindow(TRUE);
wsusDlg.ShowWindow(FALSE);
virusListDlg.ShowWindow(FALSE);
}

你可能感兴趣的:(图片)