2014-01-15 4 views
2

C++의 OPENFILENAME 구조체에서 사용자 지정 템플릿을 사용하려고하는데 정확히 무엇을 잘못하고 있는지 알 수 없습니다. 여기에 지금까지 무엇을 가지고 :Windows API 사용자 지정 대화 상자 템플릿 용 리소스를 사용하는 방법?

#include <windows.h> 
#include <iostream> 
#include "resource.h" 

void main() { 
    HWND hwnd = NULL;// owner window 

    OPENFILENAME ofn; 
    CHAR File[256]; 
    ZeroMemory(&ofn, sizeof(OPENFILENAME)); 

    ofn.lStructSize = sizeof(OPENFILENAME); 
    ofn.hwndOwner = hwnd; 
    ofn.hInstance = NULL; 
    ofn.lpstrCustomFilter = NULL; 
    ofn.nMaxCustFilter = 0; 
    ofn.nFilterIndex = 0; 
    ofn.lpstrFile = File; 
    ofn.lpstrFile[0] = '\0'; 
    ofn.nMaxFile = sizeof(File); 
    ofn.lpstrFileTitle = NULL; 
    ofn.nMaxFileTitle = MAX_PATH; 
    ofn.lpstrInitialDir = NULL; 
    ofn.lpstrTitle = NULL; 
    ofn.Flags = OFN_ENABLETEMPLATE; 
    ofn.nFileOffset = 0; 
    ofn.nFileExtension = 0; 
    ofn.lpstrDefExt = NULL; 
    ofn.lCustData = 0L; 
    ofn.lpfnHook = NULL; 
    ofn.lpTemplateName = "IDD_DIALOGBAR"; 


    if (GetOpenFileName(&ofn)==TRUE) 
    { 
     //do something with filename 
    } 

    std::cout << CommDlgExtendedError(); 
} 

IDD_DIALOGBAR 내가 프로젝트에 추가 사용자 정의 자원이다. Visual Studio에서 비어있는 새 C++ 프로젝트를 만든 다음 솔루션 탐색기에서 프로젝트 이름을 마우스 오른쪽 단추로 클릭 한 다음 "추가"-> "리소스"를 클릭하여이 작업을 수행했습니다. 그런 다음 사용 가능한 리소스 목록에서 "IDD_DIALOGBAR"을 선택했습니다. 이렇게하면 프로젝트에 새 리소스가 추가되어 Visual Studio에서 "리소스 뷰"로 전환 할 때 볼 수 있습니다.

프로그램을 실행할 때 대화 상자가 전혀 나타나지 않습니다. CommDlgExtendedError()의 결과는 CDERR_FINDRESFAILURE: The common dialog box function failed to find a specified resource입니다.

는 또한

ofn.lpTemplateName = MAKEINTRESOURCE(IDD_DIALOGBAR)

ofn.lpTemplateName = "IDD_DIALOGBAR"

을 변경 시도하지만 다른 오류 메시지가 결과 :

CDERR_DIALOGFAILURE: The dialog box could not be created. The common dialog box function's call to the DialogBox function failed. For example, this error occurs if the common dialog box call specifies an invalid window handle.

무엇이 누락 되었습니까? 리소스를 올바르게 참조하지 않습니까?

+0

템플릿을 잊어 버린 사용자 지정 컨트롤을 사용할 수 있습니다. –

답변

0

ofn.hInstance은 대화 상자 템플릿 리소스가있는 모듈 (실행 파일 또는 DLL)의 HINSTANCE으로 설정해야합니다.