窗口始终浮在上面的图钉按钮示例程序(详细编程)

类别:VC语言 点击:0 评论:0 推荐:

 

 

 

PushPin类图钉按钮

 类原作者:PJ Naughter  类改进、使用评论、示例作者: 龚建伟      ◆◆龚建伟技术主页◆

 

    PushPin类能做出象VC6中Properties对话框图钉按钮,示例程序中修改了原类,并能真正将窗口“钉”在最上层,保持可见(Keep Visible). 在VC6中使用,编出的程序可在9X/ME/2K运行。推荐给大家试试,有好作品别忘了给我寄一份。

首先下载类的源程序:下载(含我做的示例程序)

好了,如果是初学VC的朋友,先跟着做示例程序吧,老鸟则自已去看程序吧。

 

1. 新建项目:在VC6中用MFC新建一个基于对话框的PushPinTest项目,并在对话框中加入一个按钮控件(示例中对话框左上角那个按钮)IDC_BUTTON_VISIBLE,特别注意:要把按钮的Properties->Style中,选上Ower draw, Bitmap, Notify属性。

2.在项目中插入类文件:把PushPin.cpp和PushPin.h文件copy 到项目文件夹下(注意:你要是想做得和我和示例一样具有keep visible功能,就在我做示例程序中copy,不要用原作者的类文件,因为示例程序中的类文件是经过改进的)

单击Project->Add to Project->Files中,在文件选择对话框中选上PushPin.cpp和PushPin.h文件,单击OK; 怎么样,在ClassView中看到了CPushPinButton类吧。 打开ClassWizard若看不到CPushPinButton类,可关闭ClassWizard(不用关闭VC),在项目文件夹下把PushPinTest.clw文件删除,再打开ClassWizard,会看到提示:"The classwizard database doesn't exist,.....,would you like to build it from your source files?",选Yes,出现一个对话框,单击 Add All,再单击OK,好了,在ClassWizard中可以看到CPushPinButton类了。

并将我做的示例程序中res文件夹中的位图pinned.bmp,unpinned.bmp Import到项目中,对应ID分别为: IDB_PINNED_BITMAP,IDB_UNPINNED_BITMAP。

3. 为按钮控件IDC_BUTTON_VISIBLE添加一个CPushPinButton控制变量

首先,在PushPinTestDlg.h中加上:#include "PushPin.h"

打开ClassWizard->Member Variable为IDC_BUTTON_VISIBLE添加一个CPushPinButton控制变量m_ctrlPushPin.

4.利用ClassWizard为IDC_BUTTON_VISIBLE添加BN_CLICKED消息处理函数,名称用缺省名称OnButtonVisible(),在函数中加入如下代码:

void CPushPinTestDlg::OnButtonVisible() 
{
m_ctrlPushPin.ProcessClick();
m_bVisible=!m_bVisible;
if(m_bVisible)
{
SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
}
else
{
SetWindowPos(&wndBottom, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOREDRAW);
BringWindowToTop();
}
}

其中m_bVisible是BOOL型变量,你可以在ClassView在CPushPinTestDlg中单击鼠标右键,Add Member Variable中加入,并在CPushPinTestDlg类构造函数中加入m_bVisible=FALSE:

CPushPinTestDlg::CPushPinTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPushPinTestDlg::IDD, pParent)
{.....m_bVisible=FALSE;}

大功告成,Build -> Run 吧,好了吗?有问题告诉我

本文地址:http://com.8s8s.com/it/it3059.htm