The application architecture is actually very simple (as usual, I'm using WTL 8.0):
- A main frame window that contains the content views and any decorations
- A category view that shows the information categories in the safe
- A detail view showing the individual items in each category
- An item editing dialog
After creating your initial project, our first stop is to change the view window (see the source code):
class CCrypSafeView : public CTouchList<CCrypSafeView>, public CChildView<CCrypSafeView>
This means that our view will implement both a "touch list" and will also behave like a switchable child view. Next we need to remove the standard painting protocol and replace it with the touch list's:
virtual void DrawItem(HDC hDC, int iItem, CRect &rcItem);
Yes, we only need this because the list is painted item by item. Remove the OnPaint handler because it is not needed (it's implemented by the base class). I also added a default constructor where I placed the initial list of categories for the prototype:
CCrypSafeView::CCrypSafeView()
{
AddItem(new CTouchListItem(L"Credit Cards"));
AddItem(new CTouchListItem(L"Debit Cards"));
AddItem(new CTouchListItem(L"Mail Accounts"));
AddItem(new CTouchListItem(L"SIM Cards"));
AddItem(new CTouchListItem(L"User Accounts"));
AddItem(new CTouchListItem(L"Web Sites"));
}
Note that these items are not explicitly delete anywhere in the code because their pointers are reference counted (internally). Finally, let's see how to paint the items:
void CCrypSafeView::DrawItem(HDC hDC, int iItem, CRect &rcItem)
{
CDCHandle dc(hDC);
PTouchListItem pItem = GetItem(iItem);
dc.DrawText(pItem->GetText(), -1, &rcItem, DT_LEFT);
}
Note that the PTouchListItem type is a typedef that denotes the reference-counted version of a pointer to a CTouchListItem object.

For the time being, you can take a peek at the first version of the code here.
P.S.: Anatoly, I have not included all of your changes yet.
2 comments:
Hello João,
I have to say that you are making a great effort regarding the CrypSafe application. But I have one comment about your work, don't you think that it will be a good idea to mention what do the person who will use this application need in order to compile it correctly? I tried to compile it both on VS2008 and VS2005, but I got a lot of errors, fixed many of them, but i keep getting more and more. So, can you please tell me what do I need or have exactly in order to compile correctly?
Thank you.
You are right - I will write a post on this subject pretty soon. Thanks for pointing this out!
Post a Comment