Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Системное программирование и WinAPI > Ошибка с GetOpenFileName


Автор: dreamer21 15.1.2010, 16:51
Код

OPENFILENAME ofn;

ZeroMemory(&ofn, sizeof(OPENFILENAME));

ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = NULL;
ofn.hInstance = hInst;
ofn.lpstrCustomFilter = "Äîêóìåíò Excell\0*.xls\0";
ofn.nMaxCustFilter = strlen(ofn.lpstrCustomFilter);
ofn.nFilterIndex = 0;
ofn.lpstrFilter = NULL;
ofn.lpstrFile = szSourceFile;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = "Âûáåðèòå ôàéë, êîòîðûé âû õîòèòå äîáàâèòü";
ofn.Flags = OFN_FILEMUSTEXIST;
ofn.lpstrDefExt = "xls";

GetOpenFileName(&ofn);


Функция не выводит окна диалога вообще и возвращает 0 всегда. При компиляции этого же кода в Visual Studio 2008 этой проблемы не возникало... Может значение какое-нибудь исправить надо?

Автор: GremlinProg 15.1.2010, 17:19
заменить:
1. lpstrCustomFilter - на lpstrFilter
2. nFilterIndex = 0 - на nFilterIndex = 1
убрать:
1. nMaxCustFilter
2. hInstance

ну и lpstrFilter соответственно занулять не надо

Автор: dreamer21 17.1.2010, 21:33
Спасибо, GremlinProg =) Проблема была решена:
Код

OPENFILENAME ofn;
    ZeroMemory(&ofn, sizeof(OPENFILENAME));
    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = NULL;
    ofn.lpstrFilter = "Äîêóìåíò Excell\0*.xls\0";
    ofn.lpstrCustomFilter = NULL;
    ofn.nFilterIndex = 0;
    ofn.lpstrFile = szSourceFile;
    ofn.nMaxFile=256;    
    ofn.lpstrTitle = "Âûáåðèòå ôàéë, êîòîðûé âû õîòèòå äîáàâèòü";
    ofn.lpstrInitialDir = NULL;
    ofn.Flags = OFN_FILEMUSTEXIST;
    ofn.lpstrDefExt = "xls";

Автор: GremlinProg 18.1.2010, 10:09
Цитата(OPENFILENAME Structure @  MSDN)

nFilterIndex Specifies the index of the currently selected filter in the File Types control. The buffer pointed to by lpstrFilter contains pairs of strings that define the filters. The first pair of strings has an index value of 1, the second pair 2, and so on. An index of zero indicates the custom filter specified by lpstrCustomFilter. You can specify an index on input to indicate the initial filter description and filter pattern for the dialog box. When the user selects a file, nFilterIndex returns the index of the currently displayed filter. If nFilterIndex is zero and lpstrCustomFilter is NULL, the system uses the first filter in the lpstrFilter buffer. If all three members are zero or NULL, the system does not use any filters and does not show any files in the file list control of the dialog box.

Код

ofn.nFilterIndex = 1;

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)