Bonjour un exemple simple d'utilisation d'"ApplicationProperties" de la bibliothèque C++ Juce
L'application affiche un slider à l'ouverture charge la valeur sauvegardée et sauve la valeur de ce slider à la fermeture.


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//==============================================================================
    class MainComponent  : public Component
    {
    public:
        MainComponent()
        {
            setOpaque (true);
            setSize (640, 480);
            addAndMakeVisible(mySlider);
            mySlider.setSliderStyle(Slider::SliderStyle::LinearVertical);
            initProperties();
            loadParams();
 
 
        }
 
        ~MainComponent()
        {
            saveParams();
 
        }
 
 
        void initProperties()
        {
            PropertiesFile::Options options;
            options.applicationName = ProjectInfo::projectName;
            options.filenameSuffix = ".settings";
            options.osxLibrarySubFolder = "Application Support";
            options.folderName = File::getSpecialLocation(File::SpecialLocationType::userApplicationDataDirectory).getChildFile("myApp").getFullPathName();
            options.storageFormat = PropertiesFile::storeAsXML;
 
            props.setStorageParameters(options);
        }
        void loadParams()
        {
 
            mySlider.setValue( props.getUserSettings()->getIntValue("mySlider"));
 
 
        }
        void saveParams()
        {
            props.getUserSettings()->setValue("mySlider", mySlider.getValue());
        }
 
        void paint (Graphics& g) override
        {
            g.fillAll (findColour (ResizableWindow::backgroundColourId));
        }
 
        void resized() override
        {
            mySlider.setBounds(10, 10, 100, getHeight()-20);
 
        }
 
    private:
        Slider   mySlider;
        ApplicationProperties props;
 
        JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
    };