I am learning how to play audio files by watching Tutorial: Build an audio player.
In a new Console juce project(I made), referring to the code of the tutorial, I made a FileChooser dialog.
However, the result is different from when I run the project file of the tutorial.
In the tutorial’s project, the FileChooser dialog runs at high dpi:
but, in my Console project, the FileChooser dialog runs at low dpi:
Why do I get these results?
Need additional settings?
+Additional questions
The callback lambda function is not executed.
Why?
using namespace std;
using namespace juce;
int main (int argc, char* argv[])
{
system("chcp 65001");
ScopedJuceInitialiser_GUI _SJI_GUI;
auto chooser = make_unique<FileChooser>("Select a Wave file to play...",
juce::File{},
"*.wav");
auto chooserFlags = juce::FileBrowserComponent::openMode
| juce::FileBrowserComponent::canSelectFiles;
chooser->launchAsync(chooserFlags, [](const FileChooser& fc)
{
cout << "---------" << endl;
auto file = fc.getResult();
cout << file.getFileName() << endl;
DBG("message");
});
int ccc;
cin >> ccc;
return 0;
}
I think I found the answer to my Additional question.
After searching and studying all day, I found out that the lambda function is executed in the MessageManager.
I noticed the existence of runDispatchLoop and executed it in main(), but found that the main thread hangs.
I created a new Thread class (MainMessageThread) so that the runDispatchLoop function can be executed independently of the main thread.
Finally, the lambda function is executed.
If someone needs a message event in the console application, please refer to the code below.
class MainMessageThread : public juce::Thread
{
public:
MainMessageThread() : Thread("MainMessageThread")
{
startThread();
std::cout << (wait(1000) ? "MainMessageThread start" : "MainMessageThread fail") << std::endl;
}
~MainMessageThread()
{
juce::MessageManager::getInstanceWithoutCreating()->stopDispatchLoop();
stopThread(1000);
}
void run() override
{
juce::ScopedJuceInitialiser_GUI SJI_GUI;
notify();
juce::MessageManager::getInstance()->runDispatchLoop();
std::cout << "MainMessageThread stop" << std::endl;
}
};
int main (int argc, char* argv[])
{
system("chcp 65001"); //UTF-8
std::cout << "start main" << std::endl;
MainMessageThread MMT; //An object that can handle message events independently of the main thread.
std::unique_ptr<juce::FileChooser> chooser;
juce::MessageManager::callAsync([&chooser]() {
chooser = std::make_unique<juce::FileChooser>("Select a Wave file to play...",
juce::File{},
"*.wav");
auto chooserFlags = juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles;
chooser->launchAsync(chooserFlags, [](const juce::FileChooser& fc) {
auto file = fc.getResult();
std::cout << "lambda function" << std::endl;
});
});
int wait;
std::cin >> wait;
return 0;
}
However, I wonder if this is the correct solution.
Can anyone answer this?
+Still not finding a solution to the main question.
Even a small hint is fine, please help me solve the problem.
I think I’ve found a solution to my main question.
Setting Project Properties > Configuration Properties > Manifest Tool > Input and Output > DPI Awareness > Per Monitor High Dpi Aware in Visual Studio solves the window dialog.
Other windows probably can be resolved with the Desktop::getInstance().setGlobalScaleFactor(DPI) function.
If you have a better way, please anytime to comment.
1 Like