This site is for P2P development and test software ONLY!

Adding an own Prefs Page

Effect:
Get your own space in the Prefs to place controls etc

Difficulty:
fairly easy

Files to modify:
PreferencesDlg.cpp
PreferencesDlg.h
OwnPrefs.cpp
OwnPrefs.h

Notes:
Look for the posted codeblock and add the new lines at the end. The changes are all tagged.
I gonna post 2 lines of official code before the changes.
[hr]


We start with PreferencesDlg.cpp:
[php]
CPreferencesDlg::CPreferencesDlg()
{
[...]
m_wndScheduler.m_psp.dwFlags &= ~PSH_HASHELP;
m_wndProxy.m_psp.dwFlags &= ~PSH_HASHELP;

// Own Prefs
m_wndOwnPrefs.m_psp.dwFlags &= ~PSH_HASHELP;

[...]
CTreePropSheet::SetPageIcon(&m_wndTweaks, _T("TWEAK"));
#if defined(_DEBUG) || defined(USE_DEBUG_DEVICE)
CTreePropSheet::SetPageIcon(&m_wndDebug, _T("Preferences"));
#endif

// Own Prefs
CTreePropSheet::SetPageIcon(&m_wndOwnPrefs, _T("TWEAK"));

[...]
AddPage(&m_wndWebServer);
AddPage(&m_wndTweaks);

// Own Prefs
AddPage(&m_wndOwnPrefs);

[/php]


Next function:
[php]
void CPreferencesDlg::Localize()
{
[...]
m_wndScheduler.Localize();
m_wndProxy.Localize();

// pp
m_wndOwnPrefs.Localize();

[...]
CTreeCtrl* pTree = GetPageTreeControl();
if (pTree)
{
[...]
pTree->SetItemText(GetPageTreeItem(12), RemoveAmbersand(GetResString(IDS_PW_WS)));
pTree->SetItemText(GetPageTreeItem(13), RemoveAmbersand(GetResString(IDS_PW_TWEAK)));

// Own Prefs
pTree->SetItemText(GetPageTreeItem(14), RemoveAmbersand(_T("Own Prefs")));

// change 14 -> 15 here
#if defined(_DEBUG) || defined(USE_DEBUG_DEVICE)
pTree->SetItemText(GetPageTreeItem(15), _T("Debug"));
#endif
}
[...]
[/php]
[hr]


Now for PreferencesDlg.h:
[php]
[...]
#include "otherfunctions.h"
#include "TreePropSheet.h"

// Own Prefs
#include "ppgOwnPrefs.h"

[...]
public:
CPreferencesDlg();
virtual ~CPreferencesDlg();

// Own Prefs
CPPgOwnPrefs m_wndOwnPrefs;
[...]
[/php]

That's it.
[hr]


The next steps are to be done in the IDE. First download this archive [60 kB] and extract the files into your srchybrid folder. It also contains all other files named above with all changes done. If you prefer you can simply merge the changes file to file. The files & tut have been tested and they compile w/o errors under VS.2k3.

Prefs are interface files, so the have to be added to the sections "interface source" (.cpp) and "interface header" (.h):

1. In your "Project Explorer" right-click on "Interface Source"
2. click "add" -> "Existing Element"
3. select "PPgOwnPrefs.cpp" & OK
4. Same for the .h file in "Interface Header"

Both files should appear at the end of the sections now.

Now create the empty dialog. Change to Rescource view and:

1. select "emule.rc" -> "Dialogs".
2. Right-click on "Dialog" and choose "Add" -> "Add Rescource" -> "New".
3. A new & empty dialog opens up. Delete the two buttons.
4. Size the dialog to 227x246 pixel (size is shown in the status bar).
5. Give it the ID "IDD_PPG_OWNPREFS" (Properties) and save.

0 comments:

发表评论