본문 바로가기

Windows/Windows API

파일 열기

OPENFILENAME ofn;     // common dialog box structure
char szFile[260];     // buffer for file name
HWND hwnd;             // owner window
HANDLE hf;             // file handle

// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
//
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
//
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

// Display the Open dialog box.

if (GetOpenFileName(&ofn)==TRUE)
    hf = CreateFile(ofn.lpstrFile, GENERIC_READ,
        0, (LPSECURITY_ATTRIBUTES) NULL,
        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
        (HANDLE) NULL);

'Windows > Windows API' 카테고리의 다른 글

프린트 속성창  (0) 2013.10.01
프린트 창열기  (0) 2013.10.01
폰트 선택  (0) 2013.10.01
색선택  (0) 2013.10.01
다이얼 로그 박스에 변수 전달하기 (DialogBoxParam)  (0) 2013.10.01