#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    88
    Rep Power
    11

    Syntax Hightlighting?


    Hello all,

    I sort of have 2 questions.

    My first one is: How would you go about doing syntax highlighting?

    My second is: How do you use a windows edit box have more than one colour in it :p

    Help is greatly appreciated!

    Regards,
    Someonewhois
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,592
    Rep Power
    4207
    I'll answer the questions in reverse order:

    2. Use a RichEdit component instead of an Edit component. This supports using multiple colours/fonts/text attributes within the same edit box.

    1. Fastest way is to Google for "Syntax Highlight visual C++" or something like that, depending on your dev environment. There are several samples available on the web to do this.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    88
    Rep Power
    11
    Hi, thanks for your response.

    In google, "Syntax Highlight" will just give me editors that have syntax highlighting with them.

    I want to write a text editor myself (which I can do easily) with highlighting.

    How would I go about making all text between < and > blue, and between " and " red?

    Thanks for your help!

    Regards,
    Someonewhois
  6. #4
  7. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    11
    Everytime user types a char, check if it's ", if so, make it red(RichEdit), and keep coloring red until user puts another ", something like that, it gets more complicated.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    88
    Rep Power
    11
    Hm I'll try that. Thanks. :)
  10. #6
  11. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,592
    Rep Power
    4207
    Originally posted by someonewhois
    Hi, thanks for your response.

    In google, "Syntax Highlight" will just give me editors that have syntax highlighting with them.

    I want to write a text editor myself (which I can do easily) with highlighting.
    if you search for "Syntax Highlight Visual C++" in Google, there are a couple of example links returned on the first page of results.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    88
    Rep Power
    11
    Oh, sorry, I only tried syntax highlighting, will try. Thanks for your help. :)
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Bulgaria
    Posts
    22
    Rep Power
    0

    Re: Syntax Hightlighting?


    Originally posted by someonewhois
    Hello all,

    I sort of have 2 questions.

    My first one is: How would you go about doing syntax highlighting?

    My second is: How do you use a windows edit box have more than one colour in it :p

    Help is greatly appreciated!

    Regards,
    Someonewhois
    Syntax coloring is not an easy thing. First of all you need to have background on windows themselves and the Windows messaging system. In Windows all objects (in the general sense, not C++) you work in on the desktop are windows Ė buttons, scrollbars, comboboxes, treeviews, listviews, etc., are windows. The window is an opaque internal structure in Windows and you can manipulate it with a handle to it (since Windows is not open source you donít know the members of this structure, Microsoft never revealed it.). Now, how a window is being created: Every window pertain to certain class (it is a Windows class structure, not a C++ class). In the class structure you specify things like the class name of the window, background, cursor, icon, etc. The first thing is to fill the WNDCLASS structure and call RegisterClass to register that class with Windows. In one of the fields of WNDCLASS you specify a pointer to the window procedure of that window that will handle the messages for it.
    Then you call CreateWindow with the name if the class and some styles, position, etc. Well, you may know all this, but it is important to say, because in fact there isnít an easy way in Windows to do syntax color highlighting. The edit control is a window that has a firm predefined logic, it is a simple text manipulator, and it is not intended for syntax highlighting. Donít try to subclass it to do coloring because it is so hard that it seems simpler to create your own edit control from the scratch. Ií ve already tryied this approach. The RichEdit control is more sophisticated and you can do some sort of highlighting in it, but it is also limited. If you need a really custom coloring editor like that in Visual Studio or EditPlus you need to create it from the scratch, ie. register your window class and handle all the messages like WM_CHAR, WM_KEYDOWN, WM_PAINT, WM_LBUTTONDOWN, etc. This way you can define any behavior of your custom edit control. When you finish it you just call CreateWindow with your preregistered class name and embbed it on whatever application you want. Act like Microsoft. In their products they donít use the predefined controls, they build custom controls from the scratch like the edit controls in Word, Excel, Visual Studio.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    88
    Rep Power
    11
    Hi,

    Yes, I understand the windows architecture. ;)

    I completly follow your idea, but does something like Editplus use it's own edit box?

    Thanks for your feedback.

    Regards,
    Someonewhois

IMN logo majestic logo threadwatch logo seochat tools logo