0

I am making an app with ImGUI to choose pictures. So I need to call "OPENFILENAME" to call a dialog window, and there is my code to do it:

OPENFILENAME ofn;
::memset(&ofn, 0, sizeof(ofn));
TCHAR f1[MAX_PATH];
f1[0] = 0;
ofn.lStructSize = sizeof(ofn);
ofn.nFilterIndex = 2;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFile = f1;
ofn.Flags = OFN_FILEMUSTEXIST;
if (::GetOpenFileName(&ofn) != FALSE)
{
    show_path = TRUE;
}

But later I need to have a path to image, which I chose in char type and lpstrFile is a THCAR type. I found anything to make THCAR into char. Am I doing choosing file in right way, and if yes, how can I get in usual char format a path to file?

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
Daniil
  • 1
  • 1
  • 1
    What exactly is your problem now? Getting a path or converting from TCHAR to char string? BTW, you tagged this with `imgui`, doesn't that framework provide ways to query users for paths? Anyway, as a new user, please take the [tour] and read [ask]. – Ulrich Eckhardt Nov 09 '19 at 20:31
  • @UlrichEckhardt actually my problem is how to choose file and get path to it in string format. Because I think a way, that I wrote may be wrong. ImGUI doesn't provide way to do it, so I need to use some system built-in functions. – Daniil Nov 10 '19 at 08:23
  • Okay, then take a step aside and solve this outside your regular project and without use of imgui first, then integrate it.You get this from the OS using above method, only that you don't use the TCHAR variant but the WCHAR variant (i.e. `GetOpenFileNameW()`, search for examples). For your info, anything using TCHAR should be considered transitive code which is by now obsolete. The native character type is rather WCHAR or `wchar_t` on MS Windows. As target datatype for the filename, use a `std::filesystem::path`, which is easily constructed from such a string. – Ulrich Eckhardt Nov 10 '19 at 11:51

0 Answers0