943,099 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 509
  • C++ RSS
Feb 5th, 2010
0

[ask] syntax highlighting (c++ builder)

Expand Post »
i am confused about syntax highlighting, if i am paste text from clipboard to RichEdit, the syntax highlighling doesnt work perfectly.

here is my code :
C++ Syntax (Toggle Plain Text)
  1. //On header(FWDesign.h) define
  2. TStringList *htmltag;
  3. TStringList *atribut;
  4.  
  5. //On FormCreate
  6. void __fastcall TFWDesign::FormCreate(TObject *Sender)
  7. {
  8. htmltag = new (TStringList);
  9. atribut = new (TStringList);
  10.  
  11. htmltag->Add("html");
  12. htmltag->Add("body");
  13. htmltag->Add("h1");
  14. htmltag->Add("h2");
  15. htmltag->Add("h3");
  16. htmltag->Add("h4");
  17. htmltag->Add("h5");
  18. htmltag->Add("h6");
  19. htmltag->Add("p");
  20. htmltag->Add("br");
  21. htmltag->Add("hr");
  22. htmltag->Add("b");
  23. htmltag->Add("big");
  24. htmltag->Add("blockquote");
  25. htmltag->Add("center");
  26. htmltag->Add("code");
  27. htmltag->Add("font");
  28. htmltag->Add("i");
  29. htmltag->Add("pre");
  30. htmltag->Add("s");
  31. htmltag->Add("small");
  32. htmltag->Add("strike");
  33. htmltag->Add("strong");
  34. htmltag->Add("u");
  35. htmltag->Add("Address");
  36. htmltag->Add("form");
  37. htmltag->Add("input");
  38. htmltag->Add("textarea");
  39. htmltag->Add("button");
  40. htmltag->Add("select");
  41. htmltag->Add("option");
  42. htmltag->Add("frame");
  43. htmltag->Add("frameset");
  44. htmltag->Add("iframe");
  45. htmltag->Add("img");
  46. htmltag->Add("map");
  47. htmltag->Add("a");
  48. htmltag->Add("link");
  49. htmltag->Add("ul");
  50. htmltag->Add("ol");
  51. htmltag->Add("li");
  52. htmltag->Add("table");
  53. htmltag->Add("th");
  54. htmltag->Add("tr");
  55. htmltag->Add("td");
  56. htmltag->Add("style");
  57. htmltag->Add("div");
  58. htmltag->Add("span");
  59. htmltag->Add("head");
  60. htmltag->Add("title");
  61. htmltag->Add("meta");
  62. htmltag->Add("script");
  63. htmltag->Add("marquee");
  64.  
  65. atribut->Add("align");
  66. atribut->Add("valign");
  67. atribut->Add("width");
  68. atribut->Add("height");
  69. atribut->Add("border");
  70. atribut->Add("bgcolor");
  71. atribut->Add("background");
  72. atribut->Add("cellpadding");
  73. atribut->Add("cellspacing");
  74. atribut->Add("href");
  75. atribut->Add("src");
  76. atribut->Add("target");
  77. atribut->Add("rowspan");
  78. atribut->Add("colspan");
  79. atribut->Add("type");
  80. atribut->Add("rows");
  81. atribut->Add("cols");
  82. atribut->Add("method");
  83. atribut->Add("action");
  84. atribut->Add("name");
  85. atribut->Add("value");
  86. atribut->Add("language");
  87. atribut->Add("id");
  88. atribut->Add("class");
  89. atribut->Add("alt");
  90. atribut->Add("rel");
  91. atribut->Add("content");
  92. atribut->Add("http-equiv");
  93. atribut->Add("charset");
  94. atribut->Add("face");
  95. atribut->Add("color");
  96. atribut->Add("size");
  97. }
  98.  
  99. //on RichEdit Change
  100. void __fastcall TFWDesign::RichEdit1Change(TObject *Sender)
  101. {
  102. ::SendMessage(RichEdit1->Handle, WM_SETREDRAW, false, 0);//disable richedit
  103. if ( RichEdit1->Modified )
  104. {
  105. int pawal;
  106. AnsiString teks;
  107.  
  108. pawal = RichEdit1->SelStart;
  109.  
  110. RichEdit1->SelStart = ::SendMessage( RichEdit1->Handle,EM_FINDWORDBREAK,
  111. WB_MOVEWORDLEFT,pawal );
  112.  
  113. RichEdit1->SelLength = ::SendMessage( RichEdit1->Handle,EM_FINDWORDBREAK,
  114. WB_MOVEWORDRIGHT,RichEdit1->SelStart ) -
  115. RichEdit1->SelStart ;
  116.  
  117. teks = RichEdit1->SelText;
  118.  
  119. teks = teks.TrimLeft();
  120. teks = teks.TrimRight();
  121.  
  122. for(int i=0;i<htmltag->Count;i++)
  123. {
  124. if (teks==htmltag->Strings[i])
  125. {
  126. RichEdit1->SelAttributes->Color=clBlue;
  127. }
  128. }
  129.  
  130. for(int i=0;i<atribut->Count;i++)
  131. {
  132. if (teks==atribut->Strings[i])
  133. {
  134. RichEdit1->SelAttributes->Color=clRed;
  135. }
  136. }
  137. RichEdit1->SelStart=pawal;
  138. RichEdit1->SelAttributes->Color=clBlack;
  139. }
  140.  
  141. ::SendMessage(RichEdit1->Handle, WM_SETREDRAW, true, 0);//enable richedit
  142. ::InvalidateRect(RichEdit1->Handle, 0, true);//setfocus richedit
  143.  
  144. }

thanks in advance.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chotib is offline Offline
3 posts
since Jan 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: converting to lowest terms ...
Next Thread in C++ Forum Timeline: Little problem with loop "for"





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC