在单文档的应用程序中,我在对话框中设置一个按钮标题为Rec,现在我想设置它的功能是一点击它,按钮的标题变为UnRe,再一次点击它按钮标题变为Rec,怎么弄啊

解决方案 »

  1.   

    AfxGetMainWnd()->SetWindowText(_T("UnRe"));
      

  2.   

    点击的时候判断按钮的文字是什么,然后改变: C**Dlg:OnBtn1() 

      CString strCaption; 
      GetDlgItem(IDB_REC)->  GetWindowText(strCaption); 
      if(strCaption == "Rec") 
      { 
         GetDlgItem(IDB_REC)->  SetWindowText("UnRec");     
      } 
      else 
         GetDlgItem(IDB_REC)->  SetWindowText("Rec");  
    }我在你上个帖子中说了,你试过了不行吗?
      

  3.   

    CString str;
    if(GetDlgItemText(IDC_BUTTON2,str),str=="Rec")
    {
    SetDlgItemText(IDC_BUTTON2,"UnRec");
    }
    else
    {
    SetDlgItemText(IDC_BUTTON2,"Rec");
    }我已经测试通过了。把以上代码写到你的Button事件中即可。注意把IDC_BUTTON2换成你工程那个按钮的ID.
      

  4.   

    运行出来界面以后,点击其按钮会出来Unhandled exception in SDIComm1.exe(MFC42D.DLL):OXCOOOOOO5:Access Violation的错误
      

  5.   

    str=="Rec"这样判断不行,可以用str.Compare。做法很多,还可以用一个标志变量,或者用关联值变量等。