|
Hello.
I just wrote a code in C++. It should calculate something but for it we need a external File. Now I have to type in the whole Path. That's annoying.
Is there a possibility to open an "openfiledialog"?
Now I have this code copied but it won't work-.-:
OPENFILENAME ofn; char szFile[1000]; HWND hwnd = GetConsoleWindow(); HANDLE hf;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
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;
if (GetOpenFileName(&ofn)==TRUE)
hf = CreateFile(ofn.lpstrFile, GENERIC_READ,
0, (LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
(HANDLE) NULL);
Can you see there any mistakes or can you post a better code for it?
Is there even a possibility for it, but without using MFC or .NET?
Greets
PS: Sorry for my bad english. I'm from Germany.
modified 18-Jan-13 13:39pm.
|
|
|
|
|
What does won't work mean?
|
|
|
|
|
oh sry. I meant it doesn't work.
The compiler runs the Code and I get no errors. But it doesn't show the OpenFileDialog. Only the next command.
|
|
|
|
|
So you're getting to the CreateFile() method?
|
|
|
|
|
Just copied another code of the initalizon of the OPENFILENAME structure and it worked.
|
|
|
|