1,滑動塊的實現
更改的代碼如下:
void CMFCButtonTestDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知處理程序代碼
CButton* radio1 = (CButton*)GetDlgItem(IDC_RADIO1);
CButton* radio2 = (CButton*)GetDlgItem(IDC_RADIO2);
CButton* check1 = (CButton*)GetDlgItem(IDC_CHECK1);
CButton* check2 = (CButton*)GetDlgItem(IDC_CHECK2);
//CListBox* list = (CListBox*)GetDlgItem(IDC_LIST1);
//CEditView* edit = (CEditView*)GetDlgItem(IDC_EDIT1);
CString str;
CString strr;
//CString myEdit;
int index = 0;
strr.Format(_T("%d"), spinHope.GetPos());
if (radio1->GetCheck() == TRUE)
{
str.Append(_T("tom "));
}
if (radio2->GetCheck() == TRUE)
{
str.Append(_T("andy "));
}
mylist.ResetContent();
if (check1->GetCheck() == TRUE)
{
//str.Append(_T("ENGLISH"));
//mylist.InsertString(index++, str + _T("english "));
if (m_cdCom.GetCurSel() == 0)
{
mylist.InsertString(index++, str + _T("english.female ") + strr);
}
else
{
mylist.InsertString(index++, str + _T("english.male ") + strr);
}
}
if (check2->GetCheck() == TRUE)
{
//str.Append(_T(" MATH"));
//mylist.InsertString(index++, str + _T("math"));
if (m_cdCom.GetCurSel() == 0)
{
mylist.InsertString(index++, str + _T("math.female ")+ strr);
}
else
{
mylist.InsertString(index++, str + _T("math.male ")+ strr);
}
}
//edit->GetWindowTextW(myEdit);
UpdateData(TRUE); //從對話框將數據更新到後臺的應用程序,這個時候應用程序纔會將對話框數據賦給otherEditStr
if (otherEditStr.IsEmpty()!= TRUE)
{
mylist.InsertString(index++, str + otherEditStr + strr);
}
//AfxMessageBox(str);
}
void CMFCButtonTestDlg::OnCustomdrawSlider1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
// TODO: 在此添加控件通知處理程序代碼
CString str;
CStatic* st = (CStatic*)GetDlgItem(IDC_STATIC10);//得到靜態文本//GetDlgItem(IDC_STATIC10)得到指針
str.Format(_T("%d%%"), slider.GetPos());
st->SetWindowTextW(str); //將str裏面的值賦給st
slider.GetPos();//得到滑動塊的值
*pResult = 0;
}
運行結果如下:
2,MFC對話框
3,文件對話框
void CMFCFileDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知處理程序代碼
CString file_path_name;
CString file_name;
CString fileExt;
CFileDialog dlg(TRUE);//打開文件對話框
if (dlg.DoModal() == IDOK)//將打開文件對話框給顯示出來
{
file_path_name = dlg.GetPathName();
file_name = dlg.GetFileName();
fileExt = dlg.GetFileExt();
}
CStatic* st1 =(CStatic*) GetDlgItem(IDC_STATIC_MSG1);
CStatic* st2 = (CStatic*)GetDlgItem(IDC_STATIC_MSG2);
CStatic* st3 = (CStatic*)GetDlgItem(IDC_STATIC_MSG3);
st1->SetWindowTextW(file_path_name);//SetWindowTextW()該函數改變指定窗口的標題欄的文本內容
st2->SetWindowTextW(file_name);
st3->SetWindowTextW(fileExt);
}
運行結果如下: