gta5怎么离开掩体:怎样在PropertySheet中添加按钮

来源:百度文库 编辑:中财网 时间:2024/04/28 12:47:22

Adding a Button to CPropertySheet


This article was contributed by Jeremy Davis.

In my app I use a CPropertySheet and CPropertyPages to display properties for individual days. If the user wanted all the weeks days to be Setup with the same properties, I wanted a way to copy an individual day's properties to all the other days of the week. The solution I came up with was to create a "Copy" button in the CPropertySheet rather than in each CPropertyPage as show in the picture below...
     本文的目的是在PropertySheet中添加一个copy挖掘,如下图所示。

  1、用ClassWizard从CPropertySheet中派出出一个类CMyPropertySheet;
      2、在CMyPropertySheet.h中添加一个成员变量CButton m_ButtonCopy;在资源文件resource.h中添加一个资源ID:#define IDC_BUTTON_COPY 0x2000,这个ID就是我们将要用到的Copy按钮的ID;
  3、重载CPropertySheet::OnInitDialog函数,并插入以下代码:
  First sub-class CPropertySheet with a class of your own using ClassWizard, say CMyPropertySheet.
      Next in your MyPropertySheet.h add a member function CButton m_ButtonCopy. Also in your resource.h add a #define IDC_BUTTON_COPY 0x02000. where 0x02000 is a resource ID that has not been used yet.
      Then over-ride the CPropertySheet::OnInitDialog function and insert the following code...

CRect rect, tabrect;int width;//Get button sizes and positionsGetDlgItem(IDOK)->GetWindowRect(rect);GetTabControl()->GetWindowRect(tabrect);ScreenToClient(rect); ScreenToClient(tabrect);//New button -> width, height and Y-coordiate of IDOK// -> X-coordinate of tab controlwidth = rect.Width();rect.left = tabrect.left; rect.right = tabrect.left + width;//Create new "Add" button and set standard fontm_ButtonCopy.Create("Copy",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE|WS_TABSTOP, rect, this, IDC_BUTTON_COPY);m_ButtonCopy.SetFont(GetFont());

运行程序,可以看到Copy按钮了,但此时点按钮并不会有什么动作。为了处理该按钮的鼠标单击事件,需要在消息映射表中添加如下一行代码:
If your were to compile at this point you would now see the new Copy button in the CPropertySheet; however the button would not do anything. To handle a single button click added the following line to your message map declaration...

BEGIN_MESSAGE_MAP(CMyPropertySheet, CPropertySheet)//{{AFX_MSG_MAP(CMyPropertySheet)// NOTE - the ClassWizard will add and remove mapping macros here.//}}AFX_MSG_MAPON_BN_CLICKED(IDC_BUTTON_COPY, OnButtonCopy)END_MESSAGE_MAP()

最后,添加一个函数OnButtonCopy(),在里面添加自己的代码就行了。
Lastly add a helper function called OnButtonCopy() and insert your code for when the button is clicked.

Download demo project - 17 KB

Download source - 2 KB

Date Last Updated: March 5, 1999