Thread: Writing a text editor

  1. #31
    Registered User
    Join Date
    May 2008
    Location
    IR, Iran
    Posts
    103
    Quote Originally Posted by Salem View Post
    I thought you wanted to try to write your own, rather than just configure someone else's "editor" template.
    yes, actually this is my C++ project in university.

    In university we are learning Deitel C++ book. this text editor should written by C++ classes, strings and File.
    we never practice graphical app, but my teacher said it'd better to work graphical!

    once I ask him to help me a little, and he said you should write a string class....

  2. #32
    Registered User
    Join Date
    May 2008
    Location
    IR, Iran
    Posts
    103
    I have one question from catch22.net tutorial

    when I download its codes and compile it, it run successfully; but when I wrote the whole code by my own visual studio give C2440: '=' : cannot convert from 'HANDLE' to 'HINSTANCE' and error C2664: 'LoadImageA' : cannot convert parameter 1 from 'HANDLE' to 'HINSTANCE' errors. I don't know where's the problem, even when I completely copy and paste code this errors happens again

  3. #33
    Registered User
    Join Date
    May 2008
    Location
    IR, Iran
    Posts
    103
    seems that you no longer support me through this.
    If you don't wanna help any more, please close this thread

  4. #34
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    All we know was that you had a HANDLE parameter when you should have had an HINSTANCE. How are we supposed to know any more than that?

  5. #35
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It is probably a case of "newer compilers being more finicky" - HINSTANCE is used for the first parameter to LoadImage(). It also seems like you are trying to assign a HINSTANCE to a HANDLE, which the compiler also won't like.

    HINSTANCE is a form of HANDLE, but all handles aren't the same - so mixing and matching won't work. Use the correct type.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #36
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > seems that you no longer support me through this.
    Who said that?
    I though you'd gotten enough information to at least make a start, and be getting on with making some progress, maybe making a few mistakes (and learning stuff in the process), and generally having a fun time creating a real program.

    If you've got new questions about what you've achieved, then ask them.

    But we're not going to hand you a completed editor just because you ask enough questions.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #37
    Registered User
    Join Date
    May 2008
    Location
    IR, Iran
    Posts
    103
    Quote Originally Posted by Salem View Post
    > seems that you no longer support me through this.
    Who said that?
    I was , sorry about that

    Quote Originally Posted by Salem View Post
    If you've got new questions about what you've achieved, then ask them.
    Once I wrote a simple editor by using MFC, but it was so simple and I think my teacher wouldn't accept that, so I decide to write a console editor.
    I know that I have to write a string class.
    but what a string needed?
    how would it work?

    Quote Originally Posted by Salem View Post
    But we're not going to hand you a completed editor just because you ask enough questions.
    I never mean that, I just need some simple help

  8. #38
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What you need in your string class will depend on how you go about doing the rest of the editor, so it is hard to suggest anything. I can almost certainly say that you need a way to insert and remove character(s) at a certain index - but beyond that it's hard to say since it's a bit of a "where do we split between string class and generic text management".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #39
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    497
    try looking at the devC++ example if you have no idea how a graphical text editor looks like , or how you can make one!
    personally id prefer to go with the console app rather than graphical editor , because thats a big change ! you know , you havent mastered C++ yet , still you are planning to write a graphical one ?
    trust me pal, go for the easiest one if your teacher doesnt care ! (after that you ve mastered C++ abit more , you can switch to GUI version)
    good luck
    Last edited by Masterx; 01-17-2009 at 01:34 AM.
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  10. #40
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you've discounted using any kind of GUI text widget to do a lot of the work for you, then it's back to basics.

    Think about
    - insert a character in a line
    - delete a character
    - insert a line
    - delete a line
    - cursor to next line
    - find a string
    -- from the current position
    -- etc etc
    -- the whole file
    - replace a string
    -- all the modes which find can do.

    Code:
    class editor {
      private:
        char buff[1000][100];  // easy to manipulate, but very slow
      public:
        insert( char c, int line );
    }
    Sooner or later, you'll want to replace the array with something which is both dynamic and more efficient.

    But that's just fine - the whole C++ class thing allows you to alter the private data without affecting users.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #41
    Registered User
    Join Date
    May 2008
    Location
    IR, Iran
    Posts
    103
    Quote Originally Posted by Salem View Post
    Code:
    class editor {
      private:
        char buff[1000][100];  // easy to manipulate, but very slow
      public:
        insert( char c, int line );
    }
    I have one question from the code above:
    why buffer should be 2D array?
    I have little knowledge about buffer. I couldn't find a good resource for this.

  12. #42
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Why do you think it's 2D?

    It's 2D because that's what text looks like on a page.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  13. #43
    Registered User
    Join Date
    May 2008
    Location
    IR, Iran
    Posts
    103
    would you tell me more about buffer and how it works, or give me an article.
    I couldn't find anything

  14. #44
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Like
    buff[lineNumber][cursorXPosition];

    It's just an array, there's no magic here.

    But you'll find yourself moving a lot of data around when you insert/delete things.

    But one step at a time OK, since it seems you're still in baby steps.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  15. #45
    Registered User
    Join Date
    May 2008
    Location
    IR, Iran
    Posts
    103
    I know
    It was a simple mistake, I understand it
    sorry about that

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 19
    Last Post: 05-30-2007, 05:47 PM
  2. dtextp: a codeforming text editor
    By dwks in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 05-18-2007, 07:11 AM
  3. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Text editor with font color
    By KingoftheWorld in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-15-2003, 01:45 PM