|
Then there's no reason to search the individual lines.
For each keyword you need to search the entire text. That means using the Find() method that takes
an index of a starting point. Start at index 0. When you find a keyword, hilight it. Do the next search from
the end of the previous found keyword. Repeat until you reach the end of the text (Find() fails).
In your current code, you're only using methods to find ONE keyword. What I'm trying to convey to you is, you'll need to
write proper code to do what you want. Here's an example (untested):
array<String^>^ keyword = gcnew array<String^>{"int", "void", "float", "double", "longint"};
<font color="Green">
for(int i = 0; i < keyword->Length; i++)
{
String ^key = keyword[i];
<font color="Green">
int TextIndex = srcTextBox->Find(key, 0, RichTextBoxFinds::MatchCase);
<font color="Green">
while (TextIndex >= 0)
{
srcTextBox->Select(TextIndex, key->Length);
srcTextBox->SelectionColor = Color::Blue;
TextIndex += key->Length;
if (TextIndex >= srcTextBox->TextLength)
break;
<font color="Green">
TextIndex = srcTextBox->Find(key, TextIndex, RichTextBoxFinds::MatchCase);
}
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark
Thank you very much . Your code helps me alot
|
|
|
|
|
Hi everyone,
currently I am writing a wrapper for some native library which offers a hand full of callbacks.
I wrote some .net events which are called when these callbacks are triggered.
So far no problems, but I cannot work with the result strings etc. from the application that uses my assembly, because the events are still called from a thread different from the UI thread.
Is there any chance to call the events through some dispatcher within my mixed assembly? I would like to avoid that the user has to write some code on his own to dispatch the events.
Since that is the expected event behavior, is it possible that I am doing something wrong at all?
Sincerly,
Roland
|
|
|
|
|
Don Rolando wrote: from the application that uses my assembly, because the events are still called from a thread different from the UI thread.
Not sure I understand you correctly but it sounds like you are saying that your application code is registering an event handler for an event published in a class in the library. The library fires the event from a worker thread and therefore the application codes event handler is executing on the worker thread.
If that is correct I would point out first that from a library design stand point, that doesn't seem like a good idea. The library should managed the thread communications such that the event fires on the main thread.
However a simple solution is to have your application event handler call BeginInvoke to update the UI components.
You can find much information[^] about this topic
led mike
|
|
|
|
|
You understood it correctly; but the bad news is that I cannot modify the design of the library which is embedded in my assembly. I have these callbacks fired from the lib-file's worker thread.
I have thought about BeginInvoke myself, but in this case I cannot hide the dispatching process from the user (or can I?), because it must be implemented in the app's event handler - so the user has to write that code himself.
I would need that dispatching process in between the callback from the worker thread in the lib file and the event handler.
|
|
|
|
|
Have a deeper insight on BeginInvoke I realized that I could also do this on the event's delegate. So more or less I could start the invocation within my assembly;
anyhow, I can't get it work in C++/CLI, because either the event is not recognized as a data member (seems to be a C++/CLI specific behavior, as I read so far) or the AsyncCallback structure will not work, grrr.
Does anyone have a short code snippet how to invoke some event in C++/CLI correctly?
|
|
|
|
|
Don Rolando wrote: Does anyone have a short code snippet how to invoke some event in C++/CLI correctly?
I never looked at the them but I bet you will find an example in the introductory CLI articles here on CodeProject. Look under the "Chapters" menu.
led mike
|
|
|
|
|
Don Rolando wrote: I cannot modify the design of the library which is embedded in my assembly. I have these callbacks fired from the lib-file's worker thread.
Don Rolando wrote: I cannot hide the dispatching process from the user (or can I?), because it must be implemented in the app's event handler - so the user has to write that code himself.
That information is very confusing. If it is your assembly, why can't you modify it?
led mike
|
|
|
|
|
The assembly is from me, right... but not the linked lib-file which generates it's own worker threads and calls the callbacks. That's kind of a black box which's architectural design I cannot modify in any way.
But I can try to start the dispatching when firing the event out of these callbacks. That's still within the assembly (but would however not beautify the general architecture),
Silly thing is that I could not find examples for BeginInvoke on delegates for C++/CLI so far... only on controls or in C#; and I read that C++/CLI is different in that case and cannot be handled the same way... but I will get it work soon, I am sure.
|
|
|
|
|
Hello all,
I'd very grateful for your help with compilation error I get after migrating from Visual Studio .NET 2003 to Visual Studio 2005.
class A is a managed class which contains pointer pPtr to unmanaged class as public member
class B is a managed class, derived from A.
In constructor of B there is an initialization of pPtr
after migrating from Visual Studio .NET 2003 to Visual Studio 2005 I get a compilation error:
cannot access a private member of class A (pPtr)
I'm using Old Syntax.
Thanks in advance,
Maya
|
|
|
|
|
mayag wrote: I'm using Old Syntax.
I don't recommend that.
As to your problem the newer C++ compilers are more standards compliant than the old ones. private is private, as in, not visible to derived classes. If you want derived classes to access the member make it protected, although this is not a normal design holding the principle of encapsulation but that is another matter.
Also Microsoft maintains a page of the breaking changes between compliers which could help you. There are also like a migration guide or something. Also here on CodeProject there exists an excellent set of articles introducing the CLI language extensions, I highly recommend those to anyone new to CLI.
led mike
|
|
|
|
|
i have a major problem with the HtmlDocument HtmlElement ... methods...
im tryn to code a browser in wich i can automaticle fill a form and submit it.
this is the form code <code>form name="loginform" method="POST" action="/login.php">
<input class="loginname" type="text" name="name" value="" style="width:8em;" maxlength="60" />
<input class="passwort" type="password" name="password" value="" style="width:8em;" maxlength="60" />
<input type="submit" name="login" value="Login" style="width:7em;" /><br /></code>
this are my attempts
<code> HtmlDocument ^doc = webBrowser1->Document;
label1->Text = doc->Title->ToString();
//HtmlElement ^feld1 = webBrowser1->Document->GetElementsByTagName("name");
//HtmlElement ^feld1 = webBrowser1->Document->Forms->GetElementsByName("loginname");
//feld1->SetAttribute("HALLO",name);
//doc->GetElementsByTagName("loginname");
HtmlElementCollection ^feld2 = webBrowser1->Document->Forms;
feld2->GetElementsByName("loginname");
//HtmlDocument ^feld2 = webBrowser1->Document->Forms->GetElementsByName("name");
//feld2->SetAttribute("Hallo",name);
//HtmlElement ^button = webBrowser1->Document->GetElementById("Login");
//button->InvokeMember;
//HtmlInputDocument ^name = doc("name",0);
//doc->HtmlDocument::Forms::get();
//doc->GetElementsByTagName("login");
//doc->Forms->GetElementsByName("login");
//doc->GetElementById("login")</code>
can anyone help me with this? i'm desperated
|
|
|
|
|
Is there some specific reason you don't just make a HTTP Post request?
led mike
|
|
|
|
|
well i like to understand this methodes. because i need them later to find links and pictures in the document
|
|
|
|
|
I assume you are working inside of DOM from the web browser object?
If so you directly interact with the elements them self, no need to try to submit the post directly as the browser object will do that for you.
System::String^ part = "XYZ";
HtmlElement^ x = WebBrowser::Document::GetElementById("PartNum");
if (x != nullptr)
{
x->SetAttribute("value", part);
x = WebBrowser::Document::GetElementById("Submit");
if (x != nullptr)
{
x->InvokeMember("click");
}
}
|
|
|
|
|
How do I read in words from a text file one at a time? I do not want the blank space or puncuation.
The file is long.
|
|
|
|
|
While there's still data in the file
{
Read an arbitrary amount of the file
Loop through the data read, parsing out the words
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
So like this?
while (!eof())<br />
while (fin != '\n')<br />
{<br />
fin >> words[i];<br />
i++;<br />
}<br />
}
|
|
|
|
|
Something like that should work, although it looks like you're parsing lines, not words.
Many stream classes have built-in support for reading lines of text, but I know of none that
parse words.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The thing is I need to read them in from a file. Then check then againest the words before it and place them in a binary tree and if that word is in the tree I need to increament a counter to show that there are 2 or have ever many of that word are in the file.
Cary
|
|
|
|
|
|
led Mike.
thanks so much this is a great help.
|
|
|
|
|
Okay I have a question
const int MAX = 30;<br />
char fileName[MAX];<br />
char name[MAX];<br />
cout << "enter the file name: " << endl;<br />
cin >> name;<br />
fileName = name + ".txt";
My question is when I try and compile this it give me this error.
invalid operands of types `char[30]' and `const char[5]' to binary `operator+'
What is wrong with this code. I was told it is correct however I can not get it to compile.
led mike thanks for the great help on the last problem.
modified on Wednesday, April 2, 2008 3:55 PM
|
|
|
|
|
Cary D. Rutherford wrote: What is wrong with this code.
You can't concatenate char arrays like that in C/C++.
Here's one way you could build fileName:
strcpy(fileName, name);
strcat(fileName, ".txt");
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark. I was told wrong. I thank you for clearing this up for me.
Now it works and I understand.
Thank you again.
Cary
|
|
|
|