Miten tehdään tiedostonavausikkuna?
C++, windowsohjelmointi ja tiedoston avaus-boxi
Kleptomaani
2259
0Äänestä
Muut lukivat myös
Ketjusta on poistettu 1 sääntöjenvastainen viesti.
Odottaa vastausta
Näihin keskusteluihin ei ole vielä vastattu. Ole ensimmäinen.
Vastaukset 2
Vanhimmat
http://msdn.microsoft.com/msdnmag/issues/0800/c/default.aspx
http://www.codeguru.com/dialog/bitmap_preview_dialog.shtml
tai sitten
CFileExportDialog dialog("Save As Type", // title
"Windows Bitmap (*.bmp)|JPEG Compressed Image (*.jpg)|" // filter string..
"Windows Meta File (*.wmf)|Windows Enhanced Meta File (*.emf)", // with file types
"visualization.jpg"); // default filename (may be omitted)
if (dialog.DoModal() == IDOK) {
CString filename = dialog.GetPathName();
int filetype = dialog.GetFilterIndex();
SaveFile(filename, filetype); // defined somewhere in the application
}
Koodi on alla. Kannattaa ladata Microsoft Platform SDK (löytyy osoitteesta http://www.microsoft.com/msdownload/platformsdk/sdkupdate/ ,josta löytyy alla oleva esimerkki.
Toivottavasti tästä oli apua.
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 '' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
//
ofn.lpstrFile[0] = '';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All*.*Text*.TXT";
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);