21上位机VC MFC实现图片导航界面
功能展示
带图片导航的程序也很常见,当前例程就实现了图片导航效果。当用户鼠标在图片上滑过时,按钮显示热点效果的图片,使用户知道当前的操作,通过单击不同的图片实现相应功能,效果如图
21上位机VC MFC实现图片导航界面
要点提示 当前的图片导航界面实例主要通过按钮控件的显示与隐藏来实现。首先在初始时,将按钮控件全部隐藏,然后在鼠标滑过当前按钮时为按钮控件设置显示图片,并显示当前的按钮,从而达到按钮的热点效果;
实现功能
1.新建一个对话框的应用程序 2.添加五个位图,一个为程序背景,四个为按钮用图片。添加四个按钮控件设置为FLAT,BITMAP属性。添加一图片控件,设置位图属性并选择一位图为背景; 3.在初始化函数中将四个按钮隐藏 GetDlgItem(IDC_BUTTON1)->ShowWindow(SW_HIDE); GetDlgItem(IDC_BUTTON2)->ShowWindow(SW_HIDE); GetDlgItem(IDC_BUTTON3)->ShowWindow(SW_HIDE); GetDlgItem(IDC_BUTTON4)->ShowWindow(SW_HIDE); 并设置他们的位置 CRect rc; GetDlgItem(IDC_BUTTON1)->GetWindowRect(rc); GetDlgItem(IDC_BUTTON1)->MoveWindow(25,140,rc.Width(),rc.Height()); GetDlgItem(IDC_BUTTON2)->MoveWindow(25,190,rc.Width(),rc.Height()); GetDlgItem(IDC_BUTTON3)->MoveWindow(25,240,rc.Width(),rc.Height());
GetDlgItem(IDC_BUTTON4)->MoveWindow(25,290,rc.Width(),rc.Height()); 添加鼠标移动处理消息,并在里面处理按钮的热点效果,实现按钮的显示与隐藏 ClientToScreen(&point); int x = point.x; int y = point.y; CString str; CRectrect1,rect2,rect3,rect4; GetDlgItem(IDC_BUTTON1)->GetWindowRect(rect1); GetDlgItem(IDC_BUTTON2)->GetWindowRect(rect2); GetDlgItem(IDC_BUTTON3)->GetWindowRect(rect3); GetDlgItem(IDC_BUTTON4)->GetWindowRect(rect4);
str.Format("%d,%d",x,y); SetDlgItemText(IDC_EDIT1,str);
if(rect1.PtInRect(point)) { HBITMAP hbmp; hbmp =(HBITMAP):oadImage(AfxFindResourceHandle(MAKEINTRESOURCE(IDB_BITMAP1), RT_GROUP_ICON),MAKEINTRESOURCE(IDB_BITMAP1),IMAGE_BITMAP, 0, 0, 0); CButton *p =(CButton *)GetDlgItem(IDC_BUTTON1); p->ShowWindow(SW_SHOW); p->SetFocus(); p->SetBitmap(hbmp); } elseif(rect2.PtInRect(point)) { HBITMAP hbmp; hbmp =(HBITMAP):oadImage(AfxFindResourceHandle(MAKEINTRESOURCE(IDB_BITMAP2), RT_GROUP_ICON),MAKEINTRESOURCE(IDB_BITMAP2),IMAGE_BITMAP, 0, 0, 0); CButton *p =(CButton *)GetDlgItem(IDC_BUTTON2); p->ShowWindow(SW_SHOW); p->SetBitmap(hbmp); }
elseif(rect3.PtInRect(point)) { HBITMAP hbmp; hbmp =(HBITMAP):oadImage(AfxFindResourceHandle(MAKEINTRESOURCE(IDB_BITMAP3), RT_GROUP_ICON),MAKEINTRESOURCE(IDB_BITMAP3),IMAGE_BITMAP, 0, 0, 0); CButton *p =(CButton *)GetDlgItem(IDC_BUTTON3); p->ShowWindow(SW_SHOW); p->SetBitmap(hbmp); } elseif(rect4.PtInRect(point)) { HBITMAP hbmp; hbmp =(HBITMAP):oadImage(AfxFindResourceHandle(MAKEINTRESOURCE(IDB_BITMAP4), RT_GROUP_ICON),MAKEINTRESOURCE(IDB_BITMAP4),IMAGE_BITMAP, 0, 0, 0); CButton *p =(CButton *)GetDlgItem(IDC_BUTTON4); p->ShowWindow(SW_SHOW); p->SetBitmap(hbmp); } else { GetDlgItem(IDC_BUTTON1)->ShowWindow(SW_HIDE); GetDlgItem(IDC_BUTTON2)->ShowWindow(SW_HIDE); GetDlgItem(IDC_BUTTON3)->ShowWindow(SW_HIDE); GetDlgItem(IDC_BUTTON4)->ShowWindow(SW_HIDE); }
下面我们来演示整个功能实现的过程
源码及视频下载 (仅在电脑可见)
|