|
Luc,
The project that the article is discussing is much more complicated than what I was looking for. If I understand it correctly, it is providing home-brewed context-sensitive help functionality. I was trying to use the built-in "What's This?" mode, but with my own button to start it, rather than the '?' button in the title bar.
Between you and Mike, it is clear to me that the system was not written with this goal in mind, and there is no easy way to accomplish what I am after. I will have to find a different way to provide the functionality I am looking for.
Thank you both for your help.
|
|
|
|
|
You're welcome.
If the article's approach is more complex than you anticipated, there is probably good
cause for it. Why not adopt their methods? I trust it works...
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi,
I'm using Windows Forms C++.
I'm getting the user to add commands to a listbox then they click on a button and this runs the commands in the listbox.
The problem I have is, I don't know how to run these commands from an index number because they are currently being run in the order shown below and not in the order of where they are in the listbox.
Does anyone have any ideas?
do<br />
{<br />
if(lstCommands->Items->Count > 0)<br />
{<br />
<br />
if(lstCommands->Items->Contains("Move forward")) <br />
{<br />
protocol_test(2, distance, 0);<br />
<br />
}<br />
else if(lstCommands->Items->Contains("Move Back"))<br />
{<br />
<br />
protocol_test(3, distance, 0);<br />
<br />
}<br />
else if(lstCommands->Items->Contains("Turn Right"))<br />
{<br />
protocol_test(4, distance, degrees);<br />
<br />
lstCommands->Items->Remove("Turn Right");<br />
}<br />
else if(lstCommands->Items->Contains("Turn Left"))<br />
{<br />
<br />
protocol_test(5, distance, degrees);<br />
}<br />
<br />
}<br />
else if(lstCommands->Text->Empty)<br />
{<br />
MessageBox::Show("No Commands selected","No Commands",MessageBoxButtons::OKCancel,MessageBoxIcon::Exclamation);<br />
} <br />
} while(!lstCommands->Items->Count == 0);<br />
|
|
|
|
|
newkid wrote: Does anyone have any ideas?
Yes. An Object Oriented Design would be far easier to understand. In this regard finding errors would be relatively simple.
If/then and switch statements are the simplest form of instance –specific behavior….
The more paths through a program the less likely the program is to be correct….
The proliferation of conditionals reduces reliability….
This problem is compounded when conditionals are duplicated.
These problems can all be eliminated by converting the conditional
logic to messages, either with subclasses or delegation. Kent Beck - Implmentation Patterns
led mike
|
|
|
|
|
hi
I am working in complete 'C' environment on UNIX. I have to convert signed char and signed char* to unsigned char and unsigned char* respectively.
I have read that using (unsigned char) is not very safe and can cause.
Please suggest me any way I can do this conversion. Is there some function I have to write?
Please help
think because thats what matters
|
|
|
|
|
Welcome to CodeProject
The Windows platform now includes the .NET platform and this forum is specifically for using Microsoft Visual C++ versions with language extensions for the .NET platform. That is why the forum name says "managed C++" in reference to the managed memory (garbage collected) enforcement of the platform. For C or standard C++ questions you want to use the Visual C++ / MFC forum.
vikramaditya234 wrote: I have to convert signed char and signed char* to unsigned char and unsigned char* respectively.
There are two things in play when casting from signed to unsigned. First the sizeof() of the source and target types. If the source is larger than the target then you can lose data since you have less bits to hold the data. The second is the use of the sign bit called Two's Complement[^].
led mike
|
|
|
|
|
I am using Managed C++ under Microsoft Visual 2005 on a Windows forms application.
I have a BufferedGraphics object where I paint the information (in a double buffer approach), while in OnPaint function I am rendering it to the display.
I would like to use more graphics objects to be rendered in an “Overwrite” way to the display. This is similar to different layers of image to be painted together.
In Win32 I was able to do this using BitBlt, specifying SRCCOPY as raster operation.
How can I do it using BufferedGraphics ?
Thank you.
|
|
|
|
|
The equivalent to BitBlt() is Graphics::DrawImage(). You should be able to use that to draw
multiple bitmaps to your BufferedGraphics Graphics object.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thank you, Mark.
Indeed, DrawImage can be used for this but I am not happy about how it works for me: after clearing the bitmaps using FillRectangle, the bitmaps are not drawn one "on top" of the other; instead I only get the last one.
Regards,
Cristian
|
|
|
|
|
cristian.fatu wrote: the bitmaps are not drawn one "on top" of the other; instead I only get the last one.
Where do the rest of them go then? If the last one is larger than the previous ones, then of course you'll only see the last one.
That's the same behavior as BitBlt() (which you can use as well - just get a DC from the Graphics object).
Otherwise something is wrong with the code.
If you want them to blend, then you'll need to use 32bpp ARGB bitmaps.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
All the bitmaps are equals in size, they are created by code.
Finnaly I implemented my functionality by avoiding this "overwritten" approach. I am using an "empty" screen BufferedGraphics object that I am rendering to the current BufferedGraphics object every time I clear the screen and then I repaint all the layers to the current BufferedGraphics object (being double buffered I can afford it).
Thank you for the involvment.
|
|
|
|
|
Hi,
In MSvisual studio is there is any function available to select a word in a richtextbox.
OR Can you tell me how to find more than one time occurence word .
Thanks
|
|
|
|
|
rose196 wrote: Can you tell me how to find more than one time occurence word
Maybe RichTextBox::Find()[^]
At least one of the overloads takes a starting point index. You can repeatedly search from the end of
previous successful Find calls.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I need to change the colour of particular word in a file.
So that i store that word in array then find the length of the file.
I Put it in for loop. if the word is found then it will change the color.
Now my problem is if the word is occur more than one time the color not changed.
can you tell me what is the mistake ?
I used Mc++, my code is as follows.
array<String^>^ keyword = gcnew array<String^>{"int", "void", "float","double","longint"};
int len = keyword->Length;
int Lines = this->srcTextBox->Lines->Length;
for(int i=0;i<Lines;i++)
{
for(int j=0;j<len;j++)
{
String ^searchStr = this->srcTextBox->Lines[i];
String ^key = keyword[j];
bool found;
found = searchStr->Contains(key);
if(found)
{
if(this->srcTextBox->Find(key,RichTextBoxFinds::MatchCase))
{
this->srcTextBox->SelectionColor = Color::Blue;
}
}
}
}
Thanks
|
|
|
|
|
rose196 wrote: if(this->srcTextBox->Find(key,RichTextBoxFinds::MatchCase))
You should be checking if Find() returns >= 0
I'm not a big forms user, but I'm pretty sure you need to select the text if you want to see
a color change.
Maybe something like this...
int FoundTextIndex = this->srcTextBox->Find(key,RichTextBoxFinds::MatchCase);
if(FoundTextIndex >= 0)
{
this->srcTextBox->Select(FoundTextIndex, key->Length);
this->srcTextBox->SelectionColor = Color::Blue;
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
Thanks for reply
I tried with your code. But I didn't get the result.
I have one doubt.
Using find() same word occurence in more than line search is passible.
Thanks.
modified on Thursday, April 3, 2008 5:26 AM
|
|
|
|
|
I don't understand why you are searching both the "Lines" strings and the RichTextBox text.
If you need multiple searches in the Lines strings, use the String::IndexOf() method instead of Contains().
rose196 wrote: Using find() same word occurence in more than line search is passible.
I don't know what you mean. The Find() methods search all the text in the textbox. You can
use it to find all occurrences of a string in the textbox text, but you need to loop.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
Thanks for your replay.
Now i'll explain what i am doing.
I read the file and display that file in the richtextbox. Now what i want means file displayed in the richtextbox has certain keywords. I want to display that keyword in color.
Ok,
For this i Wrote the code as i said above. Now my problem is some keywords is presented in multiple line, that keyword color is not changed while i am executing.
forexample.
if keyword "int" is present in the 1st line and 4th line. the 1st line "int" keyword color is changed 4thline "int" keyword color is not changed.
I dont know why?
Now can you give idea.
Thanks.
|
|
|
|
|
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
|
|
|
|