foobar2000 SDK  2015-08-03
preferences.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 #include "resource.h"
3 
4 // Sample preferences interface: two meaningless configuration settings accessible through a preferences page and one accessible through advanced preferences.
5 
6 
7 // These GUIDs identify the variables within our component's configuration file.
8 static const GUID guid_cfg_bogoSetting1 = { 0xbd5c777, 0x735c, 0x440d, { 0x8c, 0x71, 0x49, 0xb6, 0xac, 0xff, 0xce, 0xb8 } };
9 static const GUID guid_cfg_bogoSetting2 = { 0x752f1186, 0x9f61, 0x4f91, { 0xb3, 0xee, 0x2f, 0x25, 0xb1, 0x24, 0x83, 0x5d } };
10 
11 // This GUID identifies our Advanced Preferences branch (replace with your own when reusing code).
12 static const GUID guid_advconfig_branch = { 0x28564ced, 0x4abf, 0x4f0c, { 0xa4, 0x43, 0x98, 0xda, 0x88, 0xe2, 0xcd, 0x39 } };
13 // This GUID identifies our Advanced Preferences setting (replace with your own when reusing code) as well as this setting's storage within our component's configuration file.
14 static const GUID guid_cfg_bogoSetting3 = { 0xf7008963, 0xed60, 0x4084, { 0xa8, 0x5d, 0xd1, 0xcd, 0xc5, 0x51, 0x22, 0xca } };
15 
16 
17 enum {
21 };
22 
23 static cfg_uint cfg_bogoSetting1(guid_cfg_bogoSetting1, default_cfg_bogoSetting1), cfg_bogoSetting2(guid_cfg_bogoSetting2, default_cfg_bogoSetting2);
24 
25 static advconfig_branch_factory g_advconfigBranch("Sample Component", guid_advconfig_branch, advconfig_branch::guid_branch_tools, 0);
26 static advconfig_integer_factory cfg_bogoSetting3("Bogo setting 3", guid_cfg_bogoSetting3, guid_advconfig_branch, 0, default_cfg_bogoSetting3, 0 /*minimum value*/, 9999 /*maximum value*/);
27 
28 class CMyPreferences : public CDialogImpl<CMyPreferences>, public preferences_page_instance {
29 public:
30  //Constructor - invoked by preferences_page_impl helpers - don't do Create() in here, preferences_page_impl does this for us
31  CMyPreferences(preferences_page_callback::ptr callback) : m_callback(callback) {}
32 
33  //Note that we don't bother doing anything regarding destruction of our class.
34  //The host ensures that our dialog is destroyed first, then the last reference to our preferences_page_instance object is released, causing our object to be deleted.
35 
36 
37  //dialog resource ID
38  enum {IDD = IDD_MYPREFERENCES};
39  // preferences_page_instance methods (not all of them - get_wnd() is supplied by preferences_page_impl helpers)
41  void apply();
42  void reset();
43 
44  //WTL message map
46  MSG_WM_INITDIALOG(OnInitDialog)
47  COMMAND_HANDLER_EX(IDC_BOGO1, EN_CHANGE, OnEditChange)
48  COMMAND_HANDLER_EX(IDC_BOGO2, EN_CHANGE, OnEditChange)
49  END_MSG_MAP()
50 private:
51  BOOL OnInitDialog(CWindow, LPARAM);
52  void OnEditChange(UINT, int, CWindow);
53  bool HasChanged();
54  void OnChanged();
55 
57 };
58 
59 BOOL CMyPreferences::OnInitDialog(CWindow, LPARAM) {
60  SetDlgItemInt(IDC_BOGO1, cfg_bogoSetting1, FALSE);
61  SetDlgItemInt(IDC_BOGO2, cfg_bogoSetting2, FALSE);
62  return FALSE;
63 }
64 
65 void CMyPreferences::OnEditChange(UINT, int, CWindow) {
66  // not much to do here
67  OnChanged();
68 }
69 
72  if (HasChanged()) state |= preferences_state::changed;
73  return state;
74 }
75 
77  SetDlgItemInt(IDC_BOGO1, default_cfg_bogoSetting1, FALSE);
78  SetDlgItemInt(IDC_BOGO2, default_cfg_bogoSetting2, FALSE);
79  OnChanged();
80 }
81 
83  cfg_bogoSetting1 = GetDlgItemInt(IDC_BOGO1, NULL, FALSE);
84  cfg_bogoSetting2 = GetDlgItemInt(IDC_BOGO2, NULL, FALSE);
85 
86  OnChanged(); //our dialog content has not changed but the flags have - our currently shown values now match the settings so the apply button can be disabled
87 }
88 
90  //returns whether our dialog content is different from the current configuration (whether the apply button should be enabled or not)
91  return GetDlgItemInt(IDC_BOGO1, NULL, FALSE) != cfg_bogoSetting1 || GetDlgItemInt(IDC_BOGO2, NULL, FALSE) != cfg_bogoSetting2;
92 }
94  //tell the host that our state has changed to enable/disable the apply button appropriately.
95  m_callback->on_state_changed();
96 }
97 
98 class preferences_page_myimpl : public preferences_page_impl<CMyPreferences> {
99  // preferences_page_impl<> helper deals with instantiation of our dialog; inherits from preferences_page_v3.
100 public:
101  const char * get_name() {return "Sample Component";}
103  // This is our GUID. Replace with your own when reusing the code.
104  static const GUID guid = { 0x7702c93e, 0x24dc, 0x48ed, { 0x8d, 0xb1, 0x3f, 0x27, 0xb3, 0x8c, 0x7c, 0xc9 } };
105  return guid;
106  }
107  GUID get_parent_guid() {return guid_tools;}
108 };
109 
t_uint32 get_state()
Definition: preferences.cpp:70
Definition: pfc.h:71
static preferences_page_factory_t< preferences_page_myimpl > g_preferences_page_myimpl_factory
OnEditChange COMMAND_HANDLER_EX(IDC_BOGO2, EN_CHANGE, OnEditChange) END_MSG_MAP() private void OnEditChange(UINT, int, CWindow)
Definition: preferences.cpp:65
static cfg_uint cfg_bogoSetting2(guid_cfg_bogoSetting2, default_cfg_bogoSetting2)
const char * get_name()
Retrieves name of the prefernces page to be displayed in preferences tree (static string)...
typedef BOOL(WINAPI *pPowerSetRequest_t)(__in HANDLE PowerRequest
const preferences_page_callback::ptr m_callback
Definition: preferences.cpp:56
BEGIN_MSG_MAP(CMyPreferences) MSG_WM_INITDIALOG(OnInitDialog) COMMAND_HANDLER_EX(IDC_BOGO1
static const GUID guid_advconfig_branch
Definition: preferences.cpp:12
GUID get_guid()
Retrieves GUID of the page.
static advconfig_integer_factory cfg_bogoSetting3("Bogo setting 3", guid_cfg_bogoSetting3, guid_advconfig_branch, 0, default_cfg_bogoSetting3, 0, 9999)
void apply()
Applies preferences changes.
Definition: preferences.cpp:82
CMyPreferences(preferences_page_callback::ptr callback)
Definition: preferences.cpp:31
static const GUID guid_cfg_bogoSetting3
Definition: preferences.cpp:14
Generic integer config variable class. Template parameter can be used to specify integer type to use...
Definition: cfg_var.h:65
GUID get_parent_guid()
Retrieves GUID of parent page/branch of this page. See preferences_page::guid_* constants for list of...
Service factory helper around integer-specialized advconfig_entry_string implementation. Use this class to register your own integer entries in Advanced Preferences. Usage: static advconfig_integer_factory myint(name, itemID, parentID, priority, initialValue, minValue, maxValue);.
Definition: advconfig.h:227
static cfg_uint cfg_bogoSetting1(guid_cfg_bogoSetting1, default_cfg_bogoSetting1)
static const GUID guid_cfg_bogoSetting1
Definition: preferences.cpp:8
Service factory helper around standard advconfig_branch implementation. Use this class to register yo...
Definition: advconfig.h:131
void reset()
Resets this page&#39;s content to the default values. Does not apply any changes - lets user preview the ...
Definition: preferences.cpp:76
static const GUID guid_cfg_bogoSetting2
Definition: preferences.cpp:9
static advconfig_branch_factory g_advconfigBranch("Sample Component", guid_advconfig_branch, advconfig_branch::guid_branch_tools, 0)
static const GUID guid_branch_tools
Definition: advconfig.h:25
uint32_t t_uint32
Definition: int_types.h:5