접기
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
// static BOOL s_bFlag = FALSE;
switch (iMessage) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_LBUTTONDOWN: {
OPENFILENAME OFN;
TCHAR lpstrFile[MAX_PATH]=TEXT("");
TCHAR szFileTitle[MAX_PATH];
TCHAR InitDir[MAX_PATH];
static TCHAR CustFilter[40]=TEXT("사운드 파일");
memset(&OFN, 0, sizeof(OPENFILENAME));
OFN.lStructSize = sizeof(OPENFILENAME);
OFN.hwndOwner =hWnd;
OFN.lpstrFilter =TEXT("텍스트 파일\0*.txt\0HTML 파일\0*.htm;*.html\0")
TEXT("그림파일\0*.bmp;*.jpg;*.gif\0모든 파일(*.*)\0*.*\0");
OFN.nFilterIndex =3;
OFN.lpstrCustomFilter =CustFilter;
OFN.nMaxCustFilter =40;
OFN.lpstrFile =lpstrFile;
OFN.nMaxFile =MAX_PATH;
OFN.lpstrTitle =TEXT("파일을 선택해 주십시오");
OFN.lpstrFileTitle =szFileTitle;
OFN.nMaxFileTitle =MAX_PATH;
OFN.lpstrDefExt ="abc";
/* GetWindowsDirectory(InitDir,MAX_PATH);
OFN.lpstrInitialDir=InitDir; */
if (GetOpenFileName (&OFN)!=0) {
... OFN.lpstrFile ...OFN.lpstrFileTitle ...OFN.nFileOffset ...OFN.nFileExtension ...
}
}
return 0;
...
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
접기 접기
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
switch (iMessage) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_LBUTTONDOWN: {
OPENFILENAME OFN;
static TCHAR lpstrFile[10000]=TEXT("");
static TCHAR str[32000]=TEXT("");
TCHAR *p;
TCHAR Name[MAX_PATH];
TCHAR szTmp[MAX_PATH];
memset(&OFN, 0, sizeof(OPENFILENAME));
OFN.lStructSize = sizeof(OPENFILENAME);
OFN.hwndOwner =hWnd;
OFN.lpstrFilter =TEXT("모든 파일(*.*)\0*.*\0");
OFN.lpstrFil e=lpstrFile;
OFN.nMaxFile =10000;
OFN.Flags =OFN_EXPLORER | OFN_ALLOWMULTISELECT ;
if (GetOpenFileName (&OFN)!=0) {
p=lpstrFile;
lstrcpy(Name, p);
if (*(p+lstrlen(Name)+1)==0) {
wsprintf(str,TEXT("%s 파일 하나만 선택했습니다"),Name);
} else {
wsprintf(str,TEXT("%s 디렉토리에 있는 다음 파일들이 선택되었습니다")
TEXT("\r\n\r\n"), Name);
int i=1;
for (;;) {
p=p+lstrlen(Name)+1;
if (*p==0)
break;
lstrcpy(Name,p);
wsprintf(szTmp,TEXT("%d번째 파일 = %s \r\n"),i++,Name);
lstrcat(str,szTmp);
}
}
MessageBox(hWnd,str,TEXT("선택한 파일"),MB_OK);
} else {
if (CommDlgExtendedError()==FNERR_BUFFERTOOSMALL) {
MessageBox(hWnd,TEXT("버퍼 크기가 너무 작습니다"),TEXT("에러"),MB_OK);
}
}
}
return 0;
...
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
접기
접기
#include <commdlg.h>
// Begin default media search at root directory
#define DEFAULT_MEDIA_PATH TEXT("\\\0")
// Open File Dialog ...
static OPENFILENAME ofn={0} ;
static BOOL bSetInitialDir = FALSE ;
ofn.lStructSize = sizeof(OPENFILENAME) ;
ofn.hwndOwner = m_hWnd ;
ofn.lpstrFilter = FILE_FILTER_TEXT ;
ofn.lpstrCustomFilter = NULL ;
ofn.nFilterIndex = 1 ;
ofn.lpstrFile = m_szFileName ;
ofn.nMaxFile = MAX_PATH ;
ofn.lpstrTitle = TEXT("Open Media File...\0") ;
ofn.lpstrFileTitle = NULL ;
ofn.lpstrDefExt = TEXT("*\0") ;
ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST ;
// Remember the path of the first selected file
if (bSetInitialDir == FALSE)
{
ofn.lpstrInitialDir = DEFAULT_MEDIA_PATH ;
bSetInitialDir = TRUE ;
}
else
ofn.lpstrInitialDir = NULL ;
// Retrieve the name of the selected file
WCHAR wFileName[MAX_PATH] ;
if (GetOpenFileName ((LPOPENFILENAME)&ofn))
{
#ifndef UNICODE
MultiByteToWideChar(CP_ACP, 0, m_szFileName, -1, wFileName, MAX_PATH) ;
#else
lstrcpy(wFileName, m_szFileName);
#endif
}
else
return E_ABORT ;
접기