Writing a text editor

This is a discussion on Writing a text editor within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Salem I thought you wanted to try to write your own, rather than just configure someone else's ...

  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,185
    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
    32,824
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    493
    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
    32,824
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    32,824
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    32,824
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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

Page 3 of 5 FirstFirst 12345 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 19
    Last Post: 05-30-2007, 06: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, 08: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, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21