锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
鍏稿瀷鐨勪唬鐮佹槸錛?br>GetDlgItem(ID)->SetWindowText(Caption)
浜庢槸錛屼粖澶╂兂鍒頒慨鏀筊adioButton鐨勪唬鐮佸氨鍑烘潵浜嗐?br>
CButton *p_MyBut = new CButton(); |
BOOL Create( LPCTSTR lpszCaption, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID ); |
CButton* CTextEditorView::NewMyButton(int nID,CRect rect,int nStyle) { CString m_Caption; m_Caption.LoadString( nID ); //鍙栨寜閽爣棰?br>CButton *p_Button = new CButton(); ASSERT_VALID(p_Button); p_Button->Create( m_Caption, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | nStyle, rect, this, nID ); //鍒涘緩鎸夐挳 return p_Button; } |
CButton *p_MyBut[3]; p_MyBut[0] = NewMyButton( ID_MYBUT1, CRect(10,20,50,35), BS_DEFPUSHBUTTON ); p_MyBut[1] = NewMyButton( ID_MYBUT2, CRect(55,20,95,35), 0 ); p_MyBut[2] = NewMyButton( ID_MYBUT3, CRect(100,20,140,35), 0 ); |
BEGIN_MESSAGE_MAP(CTextEditorView, CFormView) //{{AFX_MSG_MAP(CTextEditorView) ON_BN_CLICKED(IDC_ICONBUT0, OnIconbut0) //}}AFX_MSG_MAP END_MESSAGE_MAP() |
BEGIN_MESSAGE_MAP(CTextEditorView, CFormView) //{{AFX_MSG_MAP(CTextEditorView) ON_BN_CLICKED(IDC_ICONBUT0, OnIconbut0) //}}AFX_MSG_MAP ON_BN_CLICKED(ID_MYBUT1, OnMybut1) ON_BN_CLICKED(ID_MYBUT2, OnMybut2) ON_BN_CLICKED(ID_MYBUT3, OnMybut3) END_MESSAGE_MAP() |
protected: //{{AFX_MSG(CTextEditorView) afx_msg void OnIconbut0(); //}}AFX_MSG DECLARE_MESSAGE_MAP() |
protected: //{{AFX_MSG(CTextEditorView) afx_msg void OnIconbut0(); //}}AFX_MSG afx_msg void OnMybut1(); afx_msg void OnMybut2(); afx_msg void OnMybut3(); DECLARE_MESSAGE_MAP() |
void CTextEditorView::OnMybut1() { MessageBox( "鍝堬紒浣犲崟鍑諱簡鍔ㄦ佹寜閽? ); } void CTextEditorView::OnMybut2() { …… } void CTextEditorView::OnMybut3() { …… } |
if( p_MyBut[0] ) delete p_MyBut[0]; |
CButton* CTextEditorView::NewMyRadio(int nID,CRect rect,int nStyle) { 銆CString m_Caption; 銆m_Caption.LoadString( nID ); //鍙栨寜閽爣棰?br>銆CButton *p_Radio = new CButton(); 銆ASSERT_VALID(p_Radio); 銆p_Radio->Create( m_Caption, WS_CHILD | WS_VISIBLE | nStyle | WS_TABSTOP | BS_AUTORADIOBUTTON, rect, this, nID ); //鍒涘緩鎸夐挳 銆return p_Radio; } |
CButton *p_MyRadio[3]; p_MyRadio[0] = NewMyRadio( IDC_MYRADIO1, CRect(15,90,60,105), WS_GROUP ); p_MyRadio[1] = NewMyRadio( IDC_MYRADIO2, CRect(15,108,60,123), 0 ); p_MyRadio[2] = NewMyRadio( IDC_MYRADIO3, CRect(15,126,60,141), 0 ); |
int m_SelRadio; |
CButton *p_MyRadio[3]; p_MyRadio[0] = NewMyRadio( IDC_MYRADIO1, CRect(15,90,60,105), WS_GROUP ); p_MyRadio[1] = NewMyRadio( IDC_MYRADIO2, CRect(15,108,60,123), 0 ); p_MyRadio[2] = NewMyRadio( IDC_MYRADIO3, CRect(15,126,60,141), 0 ); p_MyRadio[m_SelRadio]->SetCheck(1); //璁劇疆絎竴涓崟閫変負閫変腑鐘舵? |
BEGIN_MESSAGE_MAP(CTextEditorView, CFormView) //{{AFX_MSG_MAP(CTextEditorView) ON_BN_CLICKED(IDC_ICONBUT0, OnIconbut0) //ClassWizard鍦ㄦ澶勬坊鍔?br>//}}AFX_MSG_MAP ON_BN_CLICKED(IDC_MYRADIO1, OnMyRadio1) //鍗曢夋寜閽? ON_BN_CLICKED(IDC_MYRADIO2, OnMyRadio2) //鍗曢夋寜閽? ON_BN_CLICKED(IDC_MYRADIO3, OnMyRadio3) //鍗曢夋寜閽? END_MESSAGE_MAP() |
protected: //{{AFX_MSG(CTextEditorView) afx_msg void OnIconbut0(); //ClassWizard鍦ㄦ澶勬坊鍔?br>//}}AFX_MSG afx_msg void OnMyRadio1(); //鍗曢夋寜閽? afx_msg void OnMyRadio2(); //鍗曢夋寜閽? afx_msg void OnMyRadio3(); //鍗曢夋寜閽? DECLARE_MESSAGE_MAP() |
//鍗曞嚮鍗曢夋寜閽? void CTextEditorView::OnMyRadio1() { m_SelRadio=0; } //鍗曞嚮鍗曢夋寜閽? void CTextEditorView::OnMyRadio2() { m_SelRadio=1; } //鍗曞嚮鍗曢夋寜閽? void CTextEditorView::OnMyRadio3() { m_SelRadio=2; } |
CTextEditorView::~CTextEditorView() { int i; for( i=0; i<3; i++) { if(p_MyRadio[i]) delete p_MyRadio[i]; } } |
鏂規硶涓錛?/span>API閮ㄥ垎錛?/span>
// OPENFILENAME ofn;
// char szFile[MAX_PATH];
// ZeroMemory(&ofn,sizeof(ofn));
// ofn.lStructSize = sizeof(ofn);
// ofn.lpstrFile = szFile;
// ofn.lpstrFile[0] = TEXT('\0');
// ofn.nMaxFile = sizeof(szFile);
// ofn.lpstrFilter = TEXT("all\0*.*\0jpg\0*.jpg\0bmp\0*.bmp\0"); //瀹氫箟涓変釜閫夐」錛?/span>all錛?/span>text鍜?/span>exe
// ofn.nFilterIndex = 1; //瀹氫箟棣栭夐」鏄摢涓涓?/span>
// ofn.lpstrFileTitle = NULL;
// ofn.nMaxFileTitle = 0;
// ofn.lpstrInitialDir = NULL;
// ofn.Flags = OFN_EXPLORER |OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
// if(GetOpenFileName(&ofn))
// {
// ::SetDlgItemText(this->m_hWnd,IDC_EDIT1,szFile);
// }
鏂規硶浜屻?/span>MFC瀹炵幇
// CFileDialog dlg(TRUE, NULL, NULL,
// OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
// NULL);
//
// if(dlg.DoModal() == IDOK)
// {
// szFilename = dlg.GetPathName();
// ::MessageBox(NULL,szFilename,NULL,MB_OK);
// }
娉ㄦ剰錛氭墦寮鏂囦歡鐨勬柟寮忓拰鎵撳紑鏂囦歡澶圭殑鏂瑰紡鏄笉鍚岀殑銆傛墦寮鏂囦歡鐨勬柟寮忔槸涓嶆柇鐨勬墦寮鐩村埌鍑虹幇鏈涓烘枃浠訛紝鍚﹀垯閬囧埌鏂囦歡澶硅繕瑕佺戶緇墦寮銆傝屾墦寮鏂囦歡澶瑰垯鏄彧瑕侀夋嫨鍒頒竴涓礬寰勭殑鏂囦歡澶瑰氨鎵撳紑銆?/span>
涓嬮潰鐨勮繖縐嶆柟寮忔槸鎵撳紑鏂囦歡澶?/span>錛?/span>MFC瀹炵幇銆?/span>
static TCHAR strDirName[MAX_PATH];
BROWSEINFO bi;
CString szString = TEXT("閫夋嫨涓涓簮鏂囦歡瀛愭枃浠跺す");
bi.hwndOwner = ::GetFocus();
bi.pidlRoot = NULL;
bi.pszDisplayName = strDirName;
bi.lpszTitle = szString;
bi.ulFlags = BIF_BROWSEFORCOMPUTER | BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
bi.iImage = 0;
LPITEMIDLIST pItemIDList = ::SHBrowseForFolder(&bi);
if(pItemIDList == NULL)
{
return ;
}
::SHGetPathFromIDList(pItemIDList, strDirName);
CString str = strDirName;
if(str != "" && str.Right(1) != '\\')
str += '\\';
::SetDlgItemText(this->m_hWnd,IDC_EDIT1,str);
BROWSEINFO bi;
bi.hwndOwner = ::GetFocus();
bi.pidlRoot = NULL;
bi.pszDisplayName = strDirName;
bi.lpszTitle = lpszTitle;
bi.ulFlags = BIF_BROWSEFORCOMPUTER | BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
bi.iImage = 0;
LPITEMIDLIST pItemIDList = ::SHBrowseForFolder(&bi);
if(pItemIDList == NULL)
{
return "";
}
::SHGetPathFromIDList(pItemIDList, strDirName);
CString str = strDirName;
if(str != "" && str.Right(1) != '\\')
str += '\\';
return str;
}
鏈緇堝緱鍒扮殑str灝辨槸閭d釜璺緞鐨勫悕瀛椼備笂闈㈢殑鍑芥暟濡傛灉鍜屼笅闈㈣繖涓厤濂椾嬌鐢ㄧ殑璇濓紝闇瑕佹敞鎰忓姞濡?\",鍥犱負闇瑕佸涓涓傝繖涓嚱鏁扮殑鐩殑灝辨槸涓轟簡鎵撳紑涓涓枃浠跺す鐨勫璇濇璁╀綘閫夋嫨銆?br>
3.VOID CFileIO::GetFileNamesInDir(CStringArray &StringArray, LPCTSTR lpszExpression)
{
// The File Name should apply with "d:\\fp\\temp.bmp" Style
CFileFind FileFind;
if(!FileFind.FindFile(lpszExpression))
return;
BOOL bFound;
do{
bFound = FileFind.FindNextFile();
if(!FileFind.IsDirectory())
StringArray.Add(FileFind.GetFileName());
}while(bFound);
}
浼犲叆涓涓礬寰勶紝寰楀埌璇ヨ礬寰勪笅闈㈢殑鎵鏈夌殑鏂囦歡鍚嶏紝榪樻槸瀛樺叆鏁扮粍錛屼笉榪囨病鏈夐偅浜涜礬寰勫悕錛岃屽彧鏄枃浠跺悕銆傝繕瑕佷笉浼氭悳绱笅闈㈢殑鎵鏈夌殑鏂囦歡澶癸紝鍙槸褰撳墠鏂囦歡澶逛笅闈㈡槸銆?br>浣嗘槸錛屼綘鍙互鐢ㄤ笂闈㈣繖涓変釜鍑芥暟鍋氬緢澶氫簨鎯呬簡銆傞掑綊璋冪敤錛屽畬鍏ㄥ彲浠ュ疄鐜頒箣…………
4.涓婇潰璇村埌浜嗛掑綊璋冪敤銆備笅闈㈢殑榪欎釜灝辨槸瀹為檯鐨勫疄鐜頒簡璇誨彇涓涓洰褰曚笅闈㈡墍鏈夌殑鏂囦歡鍚嶏紝騫朵笖淇濆瓨鍦ㄤ竴涓狢String鏁扮粍涓紝鑰屼笖榪樻槸璇︾粏鐨勬枃浠惰礬寰勩?br>static void GetAllFilePathInDir( CStringArray &strArray, CString strDir, CString strExt )
{
CFileFind finder;
CString strFileName;
if( strDir.IsEmpty() )
return;
if( strDir.Right(2) != "\\" )
strDir = strDir + "\\";
BOOL bWorking = finder.FindFile( strDir + "*.*" );
while( bWorking )
{
bWorking = finder.FindNextFile();
if ( finder.IsDots() )
continue;
if ( finder.IsDirectory() )
{
GetAllFilePathInDir( strArray, finder.GetFilePath(), strExt );
continue;
}
strFileName = finder.GetFilePath();
strFileName.MakeLower();
CString needExt = GetFileExt( strExt );
CString srcExt = GetFileExt( strFileName );
if( strExt == "*.*" || needExt == srcExt )
{
strArray.Add( strFileName );
}
}
finder.Close();
}
涓涓吀鍨嬬殑璋冪敤鍙傛暟灝辨槸涓嬮潰鐨勮繖涓細
GetAllFilePathInDir(FilenameALL,szSourceFilename,"*.jpg");
for (int i = 0; i < FilenameALL.GetSize(); i++)
{
::MessageBox(NULL,FilenameALL.GetAt(i),"ok",MB_OK);
}
娉ㄦ剰錛屽墠闈㈢涓涓弬鏁版槸琛ㄧず瑕佸瓨鏀劇殑鏁扮粍錛岀浜屼釜鏄綘瑕佹煡鎵劇殑閭d釜璺緞錛岀涓変釜鏄煡鎵劇殑鏂囦歡鍚嶃傚彲浠ョ敤閫氶厤絎︽潵瀹炵幇鏌ユ壘銆傝繖鏍峰氨瀹屾垚浜嗗姛鑳姐?br>寮哄ぇ鐨凪FC銆傘傘傘?br>