BOOL CpropSheet::OnInitDialog() 
{
CPropertySheet::OnInitDialog(); GetDlgItem(ID_APPLY_NOW)->SetWindowText("");
GetDlgItem(ID_APPLY_NOW)->EnableWindow(true);
return TRUE;  // return TRUE unless you set the focus to a control
              // EXCEPTION: OCX Property Pages should return FALSE
}我想把属性表单的应用按钮给弄亮拿来用,上面的代码好像弄亮了。接着怎么去响应这个按钮点击的命令??????????????????????

解决方案 »

  1.   

    响应OnCommand消息啊...
    你用的是CPropertyPage么?
      

  2.   

    在你的CXXXPropertyPage类中,重写OnApply,就ok了。详情查看msdn,CPropertyPage。
      

  3.   

    哦,那么一次只能处理1个页面,能在Sheet中吗,就想1次处理全部的属性页,
      

  4.   

    就这样行吗?点击onAooly的时候,自动让它初始化所有的属性页,这样每个属性页上的控件有值了,我就可以处理这些值了。
      

  5.   

    自定义一个按钮,直接处理。
      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 control
    width = rect.Width();
    rect.left = tabrect.left; rect.right = tabrect.left + width;//Create new "Add" button and set standard font
    m_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_MAP
    ON_BN_CLICKED(IDC_BUTTON_COPY, OnButtonCopy)
    END_MESSAGE_MAP()
    最后,添加一个函数OnButtonCopy(),在里面添加自己的代码就行了。
      

  6.   

    差不多能满足了。一般的使用
    首先要了解的是CPropertySheet实际上是由一个TabCtrl加多个Page和多个按钮组成
    这里强调一点,DoModal的时候并没有把所有的PAGE都创建出来,只有在SetActivePage的时候才创建
    所以如果你初始化的代码在OnInitDialog,那么刚开始最好先用SetActivePage切换一下在讲述之前,大家可以先看看《深入浅出CPropertySheet》(翻译的不错)
    http://www.vckbase.com/document/viewdoc/?id=427 
    其实原文后面还有一个例子,不过原理上帖中也表现出来了,就是窗口的移动MoveWindow和HeaderCtrl的创建等
    参见 http://www.codeguru.com/Cpp/controls/propertysheet/article.php/c3973/
    所以在此一些简单按钮的隐藏和移动及其Enable使能就不多说了一、布局修改
    a.修改字体 
    重载OnInitDialog,CreateFont创建字体pFont
    SendMessageToDescendants(WM_SETFONT, (WPARAM)pFont->GetSafeHandle(), TRUE);
    如果字体的改变(如高度、宽度)可能需要改变控件的位置,这样看起来才和谐一点,参见 
    Prpfont.exe sample demonstrates how to set the desired font for your CPropertyPages in Visual C++
    http://support.microsoft.com/default.aspx?scid=kb;en-us;142170b.设置初始的焦点 
    GetPage(0)->SetModified ();//使应用按钮有效
    SendMessage(DM_SETDEFID,ID_APPLY_NOW); //也可设置到自己添加的按钮中c.改变大小Resizable(这类文章和发问比较多,所以主要帖URL,见谅) 
    使用ResizableLib(适用于几乎所有窗口,Dialog,PropSheet,SDI,MDI等) 
    http://www.codeproject.com/dialog/ResizableLib.asp 
    也可参看Resizable CPropertySheet 
    http://www.codeproject.com/property/resizableproperties.asp 
    http://www.codeguru.com/Cpp/controls/propertysheet/sizing/article.php/c599/ 
    运行期间动态进行调整大小,避免切换后又恢复原来大小,参见
    http://support.microsoft.com/default.aspx?scid=kb;en-us;143291 注:如果自己在OnInitDialog做MoveWindow的时候要记住代码放到CPropertySheet::OnInitDialog();后d.向导方式
    最简单的就是设置模式 SetWizardMode //注意最前和最后页的SetWizardButtons
    后来添加了Wizard97 风格,主要有两块地方填充的,左边的叫WATERMARK和上部的叫HEADER
    注:左边和上部一般不能同时显示,所以要想显示WATERMARK,需要在PAGE中设置PSP_HIDEHEADER风格(VC7默认才设了)添加WIZARD97风格,同时设置对应的位图
    psh.dwFlags =  PSH_WIZARD97|PSH_WATERMARK|PSH_HEADER; 
    psh.pszbmWater = MAKEINTRESOURCE(IDB_WATERMARK);
    psh.pszbmHeader =    MAKEINTRESOURCE(IDB_BANNER);如果要HEADER中显示文本TITLE也可设置PSP_USEHEADERTITLE和PSP_USEHEADERSUBTITLE,如
    psp.dwFlags =           PSP_DEFAULT|PSP_USEHEADERTITLE|PSP_USEHEADERSUBTITLE;
    psp.pszHeaderTitle =    MAKEINTRESOURCE(IDS_TITLE1);
    psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_SUBTITLE1);更多的详情有兴趣的可自行搜索,如6.0版本中PROPSHEETPAGE新添的hActCtx等,在此点到为止e.内嵌入对话框中和Modeless 
    ps.Create(this);//如果要内嵌添加,WS_CHILD|WS_VISIBLE
    ps.ShowWindow(SW_SHOW);
    但这时候出来的是没有标准按钮,想要添加可重载OnInitDialog
    BOOL CMySheet::OnInitDialog()
    {
       m_bModeless = FALSE;
       m_nFlags |= WF_CONTINUEMODAL;   BOOL bResult = CPropertySheet::OnInitDialog();   m_bModeless = TRUE;
       m_nFlags &= ~WF_CONTINUEMODAL;
       return bResult;
    }
    P.S.焦点切换后子属性框(modeless)僵死,请在OnInitDialog中添加 
    ModifyStyleEx(0,WS_EX_CONTROLPARENT); 二、标签TabCtrl的操作
    a.修改Text 
    有三种方法 
    m_pPage1=newCPage1(IDS_MYCAPTION);//idofstringresource m_pPage1->m_psp.dwFlags|=PSP_USETITLE; 
    m_pPage1->m_psp.pszTitle=_T("MyCaption"); 运行时也可修改标签
    TC_ITEM ti; 
    ti.mask=TCIF_TEXT; 
    ti.pszText=pszText; 
    VERIFY(GetTabControl()->SetItem(nPage,&ti)); b.Tab使用Scrollbar而不是用多行
    EnableStackedTabs(FALSE);即可,原理就是GetTabControl()->ModifyStyle(TCS_MULTILINE, TCS_SINGLELINE)
    c.如何调整标签位置(下面或者左右)一般自画,参考: 
    http://www.codeguru.com/Cpp/controls/controls/tabcontrols/article.php/c6385/ d.Disable Tab中如果要重画TabItem使其看起来灰化,也可以看Paul的CTabCtrlWithDisable
    http://www.microsoft.com/msj/0398/c0398.aspxe.CPropertySheet页中的标题栏中显示指定数量的属性页,如:标题栏要求每行显示5个属性页 
    可使用 MutliRowTabView 参见 http://www.codeguru.com/Cpp/controls/propertysheet/article.php/c623/ 三、消息的响应
    a.获得CPropertySheet的WM_CLOSE消息 
    http://dev.csdn.net/develop/article/35/35982.shtm比较简便地实现了此功能,
    但需要覆盖每个属性页的OnApply函数,且不利于宏观同步未完成的任务. 
    现提供一个通过覆盖CMyPropertySheet类的OnCommand函数实现此功能的方法. 
    OnCommand的实现代码如下: 
    BOOL CMyPropertySheet::OnCommand(WPARA MwParam,LPARAM lParam) b.NOTIFY的响应 如:Disable 某个TAB
    BOOL CMySheet::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
       {
           NMHDR* pnmh = (NMHDR*)lParam;
           // tab is about to change
           if (TCN_SELCHANGING == pnmh->code)
               // save the current page index
               m_nLastActive = GetActiveIndex ();
           // tab has been changed
           else if (TCN_SELCHANGE == pnmh->code)
           {
               // get the current page index
               int nCurrentPage = GetActiveIndex ();
               // if current page is in our map of disabled pages
               if (m_DisabledPages.Lookup (nCurrentPage, nCurrentPage))
               // activate the previous page
               PostMessage (PSM_SETCURSEL, m_nLastActive);
           }
           return CPropertySheet::OnNotify(wParam, lParam, pResult);
       }c.如何响应上下文帮助   
    Title Bar添加问号(?)按钮的响应:添加WN_HELP响应
    ON_WM_HELPINFO()//添加函数BOOL OnHelpInfo(HELPINFO*)
    如果响应底部的帮助按钮(原理:一般按钮的点击映射)
    ON_COMMAND(IDHELP, OnHelp)//添加函数BOOL OnHelp()
      

  7.   

    什么是倒分?第一次碰到,汗
    CPropertyPage::OnApply
    virtual BOOL OnApply( );Return ValueNonzero if the changes are accepted; otherwise 0. ResThis member function is called by the framework when the user chooses the OK or the Apply Now button. When the framework calls this function, changes made on all property pages in the property sheet are accepted, the property sheet retains focus, and OnApply returns TRUE (the value 1). Before OnApply can be called by the framework, you must have called SetModified and set its parameter to TRUE. This will activate the Apply Now button as soon as the user makes a change on the property page.Override this member function to specify what action your program takes when the user clicks the Apply Now button. When overriding, the function should return TRUE to accept changes and FALSE to prevent changes from taking effect.The default implementation of OnApply calls OnOK.For more information about notification messages sent when the user presses the Apply Now or OK button in a property sheet, seePSN_APPLY in the Win32 documentation. ExampleSee the example for CPropertyPage::OnOK.
    《深入浅出CPropertySheet》
    [[email protected]][/email]
    第一次使用回复