Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. RichEdit with Treeview - associating and saving

RichEdit with Treeview - associating and saving

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++designdata-structuresjson
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kayembi
    wrote on last edited by
    #1

    Hi, I am currently working on a small app that I hope to make partly a combination of a basic word processor with an Explorer-like tree. Thus, on the left there is a tree view and on the right there is a Rich Edit box. The tree view represents virtual "documents" in a virtual filing system. By clicking or right-clicking in the tree view, you can select or create a new virtual document. The currently selected document should be shown in the rich edit box on the right, which can be typed from scratch or edited etc. I am using the straight Windows API SDK with _no_ MFC, and I am still a relative novice code - after a few small apps, this is my first attempt at writing a piece of software I would really like to use, so please forgive me for asking basic design questions, but here goes: 1) What is the best way of associating the text in a rich edit box with a tree view item? I was initially thinking of associating a string (Rich Edit) with an HTREEITEM, as I have used this method before, eg: HTREEITEM tr1, tr2, tr3; char* str1, str2, str3; if(tree_item_selected == tr1) { ShowRichEditText(str1); } ..er, etc. Obviously, though, this is fundamentally flawed as it would mean that there would have to be a limit to how many HTREEITEMs -and therefore documents - the user could create. In other words, I would have to create a set (large) number of strings, and the same number of HTREEITEM pointers to use this method. I would probably have to create a thousand strings or HTREEITEMs or so to make sure the user didn't run out. Could someone please suggest a better way of doing this? In essence, I just need to be able to associate an arbitrary number of strings containing RTF text with an arbitrary number of HTREEITEMs. Sorry if this is a fairly stupid question. 2) If (1) is achieved, how would I then save it to file? Would I be able to save the info as a struct or some such and just use CreateFile() and WriteFile(), or would I need something more complicated to hold this sort of info? Many thanks to anyone who can give me some tips, pointers, or directions to non-MFC examples, and even more thanks to all those who have put up with my newbie questions and given me help over the past couple of months. :) Cheers, KB

    S 1 Reply Last reply
    0
    • K Kayembi

      Hi, I am currently working on a small app that I hope to make partly a combination of a basic word processor with an Explorer-like tree. Thus, on the left there is a tree view and on the right there is a Rich Edit box. The tree view represents virtual "documents" in a virtual filing system. By clicking or right-clicking in the tree view, you can select or create a new virtual document. The currently selected document should be shown in the rich edit box on the right, which can be typed from scratch or edited etc. I am using the straight Windows API SDK with _no_ MFC, and I am still a relative novice code - after a few small apps, this is my first attempt at writing a piece of software I would really like to use, so please forgive me for asking basic design questions, but here goes: 1) What is the best way of associating the text in a rich edit box with a tree view item? I was initially thinking of associating a string (Rich Edit) with an HTREEITEM, as I have used this method before, eg: HTREEITEM tr1, tr2, tr3; char* str1, str2, str3; if(tree_item_selected == tr1) { ShowRichEditText(str1); } ..er, etc. Obviously, though, this is fundamentally flawed as it would mean that there would have to be a limit to how many HTREEITEMs -and therefore documents - the user could create. In other words, I would have to create a set (large) number of strings, and the same number of HTREEITEM pointers to use this method. I would probably have to create a thousand strings or HTREEITEMs or so to make sure the user didn't run out. Could someone please suggest a better way of doing this? In essence, I just need to be able to associate an arbitrary number of strings containing RTF text with an arbitrary number of HTREEITEMs. Sorry if this is a fairly stupid question. 2) If (1) is achieved, how would I then save it to file? Would I be able to save the info as a struct or some such and just use CreateFile() and WriteFile(), or would I need something more complicated to hold this sort of info? Many thanks to anyone who can give me some tips, pointers, or directions to non-MFC examples, and even more thanks to all those who have put up with my newbie questions and given me help over the past couple of months. :) Cheers, KB

      S Offline
      S Offline
      Steve S
      wrote on last edited by
      #2

      OK, I'll bite; it's not like I was busy or nuffink. A tree view item can have an arbitrary piece of data associated with it. This is not predefined or limited to what it can be (outside the fact it's an LPARAM in size). This means it can be the index in an array of CStrings, or a pointer to a CString, or anything you want it to be. When you select a tree item, you can then ask what it's data is, and use that as the basis for locating/displaying. There's a caveat. You might need to manage the freeing of such data when items are deleted from the tree, either all at once, or one at a time. Experiment in DEBUG mode if you're using MFC and you'll find out if you've new-ed without a delete, although reading the documentation could tell you as well ;P Steve S

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups