|
Hi,
I concur with Mark, multithreading typically will not help.
Most of the flickering is due to the fact that things get erased (or background painted) before the foreground gets painted, so your drawing is absent for a while. This is most noticeable when there isn't much calculation going on, i.e. as soon as the painting is done, a new cycle starts with erasure and repaint, erasure being the faster of the two.
Here is what improves the behavior:
- increase the painting performance by optimizing the code; e.g. avoid creating and disposing objects in your Paint method, use the Graphics from PaintEventArgs (don't use CreateGraphics), keep your Fonts, Pens, Brushes in class members, etc.
- only repaint what needs repainting, use the clip rectangle to determine whether each part of your drawing needs a repaint before painting it;
- set your Form, Panel, or whatever Container is relevant to DoubleBuffered; when
double-buffered the container does not erase, it just overpaints what is already in place.
- possibly, depends on your needs: limit the repaint frequency; rather than repaint (i.e. call invalidate) for every mouse movement, maybe set up a Forms.Timer to repaint at a fixed frequency of say 10Hz.
FWIW: when you need to track mouse movements (say some rubber banding stuff) there is a ControlPaint class that supports this, however it is not very easy to use it correctly since it can paint outside your container, so when another Form overlaps your container it could disrupt that Form's content.
modified on Tuesday, January 6, 2009 12:40 PM
|
|
|
|
|
Hi
I have a code sample in C# where the user has created a delegate and while calling BeginInvoke it passes an instance of ASyncCallback object with the function to be called when the asynchronous function returns. However when i try to do something similar in Managed C++ the delegate object doesnt have a BeginInvoke function. Moreover if I use the BeginInvoke of the windows form instance the argument list of the overloaded BeginInvoke function doesnt shows the ASyncCallback argument.
Anybody has any idea why the difference in delegates in C# and Managed c++ and why ASyncCallback argument is not available in BeginInvoke for Managed C++.
Thanks
gsm
|
|
|
|
|
gurindersm wrote: I have a code sample in C#
Can you show the sample?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi
Sorry for the delay...
here is the code snippet from the C# sample.
IAsyncResult ar;
// Define a delegate for the ReadReport method.
ReadReportDelegate MyReportDelegate = new ReadReportDelegate(ReadReport);
// The BeginInvoke method calls ReadReport
// The method has the same parameters as the ReadReport function,
// plus two additional parameters:
// GetInputReportData is the callback procedure that executes when the ReadReport function returns.
// MyReportDelegate is the asynchronous delegate object.
// The last parameter can optionally be an object passed to the callback.
ar = MyReadInputReportDelegate.BeginInvoke
( hRdHndl,
hRHndl,
hWndl,
ref devD,
ref ReportBuffer,
ref Success,
new AsyncCallback(GetInputReportData),
MyReportDelegate );
Thanks
gsm
|
|
|
|
|
I don't have your ReadReportDelegate class, but here's an example of
the basic pattern
public ref class SomeClass
{
public:
delegate void MyDel(int a, int b);
void MyDelFunc(int a, int b)
{
}
static void MyAsyncCallback(IAsyncResult ^result)
{
SomeClass^ This = (SomeClass^)result->AsyncState;
...
}
void MakeAsyncCall(void)
{
MyDel ^MyDelegate = gcnew MyDel(this, &SomeClass::MyDelFunc);
int a = 1;
int b = 2;
MyDelegate->BeginInvoke(a, b, gcnew AsyncCallback(MyAsyncCallback), this);
}
Everything's identical to C# except the usual language syntax differences
(^ for object references, gcnew instead of new, -> instead of ., etc.).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark ..
I think i should have just compiled my code instead of going through all the member function of the delegate i created in my program.
By the way do u see BeginInvoke as a member function, i can see it in C# but not in C++. Although the code compiles and works absolutely fine.
Thanks
gsm
|
|
|
|
|
gurindersm wrote: By the way do u see BeginInvoke as a member function, i can see it in C# but not in C++.
I can see that in VS2008 and not on 2005. Strange!
|
|
|
|
|
I am working on VS2005 may be thats the reason I didnt see it....
Thanks
gsm
|
|
|
|
|
gurindersm wrote: By the way do u see BeginInvoke as a member function
Intellisense you mean? I can see it there on VS 2008 (C++).
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi..
i have an application(i.e. an access control system).. im asked to use tcp/ip to collect the information from the application when there is access violation... can some one temme how to proceed with this.. and after getting the instance of access violation, im supposed to pass the information to another application(written in c++) to take an action(record the event from a cctv where it is happening)..
do some one have any idea regarding this...
|
|
|
|
|
What was wrong with this[^]?
|
|
|
|
|
i want to connect my SQL server 2005 data base through c++ code.. please soem one help me..
more precisely, when ever there is a update in the data base i have to pass the values of the field to another application thru c++ code..
|
|
|
|
|
|
Hi. I am a newbie at managed c++. The thing I am trying to is pass an "managed unsigned char array" reference between objects, so that all the objects will be using the sama array, and assign newly created arrays to that array reference. I can't pass the reference in all the function calls, so I am trying to pass the array reference in the constructor and store it in an managed array reference variable. But when I try to declare that variable I am getting, "cannot declare interior __gc pointer or reference as a member of 'TestClass'". How can I achieve my goal? Hope I made myself clear. Thanks in advance
|
|
|
|
|
randomVariable wrote: so I am trying to pass the array reference in the constructor and store it in an managed array reference variable
Did you mean something like this?
ref class TestClass{
array<System::Char ^> ^arr;
public:
TestClass(array<System::Char ^> ^arr){
this->arr = arr;
}
}; This code will compile correctly.
|
|
|
|
|
Thanks for your answer. I'm using the old syntax.And that is not I am trying to do. I want to store a reference to reference type as a class member, so I would be able to assign a completely new array to that reference. Like this:
typedef unsigned char ByteArrayType __gc[];
__gc class TestClass
{
private:
ByteArrayType& arrayRef;
public:
TestClass(ByteArrayType& arrayRef)
{
this->arrayRef=arrayRef;
}
}
As I said before, I am a newbie at managed c++ so it is possible there are syntax errors, or logic errors. The compiler gives the error in the bold line..
modified on Wednesday, December 24, 2008 3:27 PM
|
|
|
|
|
A __gc * IS a reference, so the type should be __gc *.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
My problem: I made
1- A new MFC application (exe) (c++ .net 2005), dialog based.
2- Get from the toolbox a control which is "Picture Control".
3- Set the type of the control to Bitmap in the property window of the control.
4- Add new bitmap to the resources at which this bitmap is 32 bit color depth picture.
5- Set the Image property of the "Picture" control to the previous Bitmap ID in the
property window of the control.
6- Build and run the application on WinXP and make sure that the appliction is enabling XP theme.
Note to enable it if it is not enabled write this line in "Additional Manifest Dependencies"
in linker node, in Manifest file Node:
type='Win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df' language='*'
When I do all this steps just part of the picture is displayed while if take the application and run it in Win server the picture is displayed perfert.
anyone knows the reason and a solution for that???
thanks
|
|
|
|
|
fire storm wrote: 1- A new MFC application
Please post on the correct board![^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I have some problem compiling a managed C++ dll (a wrapper wround a unmanaged c++ dll).
It is very odd because it compiles fine on my laptop and desktop in the UK.
I am now In France for Xmas (merry Xmas to you guys by the way), I grabbed the code straight out from the source control (that is to say that it's exactly the same than what I compiled in the UK) and I get the following error:
error C2065 '_Ax': undeclared identifier from the vextor.h class!
from here exactly:
// TEMPLATE CLASS vector
template<class _Ty,
class _Ax>
class vector
: public _Vector_val<_Ty, _Ax>
Is there something missing zith my install on this machine?
It's using Vista and VS2008 SP1 Beta
Any help would be appreciated as I'm a bit baffled.
Cheers,
Regis
|
|
|
|
|
I don't think anyone could help you given that rather minimalist snippet you provided. Does the source include <vector> - Note that it is not vector.H anymore, stdlib file name conventions are followed since vs2005, the current declaration in C:\Program Files\Microsoft Visual Studio 9.0\VC\include\vector looks like:
template<class mode="hold" />
class _Ax = allocator<_Ty> >
class vector;
Perhaps you have an old copy of the vc6 vector.h that is in your include path, and the incorrect declaration
(#include <vector.h> instead of #include <vector>> ) is causing it to be incorrectly picked up? If you set configuration properties->C++->Advanced->show Includes to yes, the compiler output window will show a list of the include files actually used. this might help track down the prioblem.
|
|
|
|
|
hotbridge wrote: VS2008 SP1 Beta
Beta??
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I've upgraded to SP1 and the problem is sorted.
Cheers
|
|
|
|
|
Hi, when I was programming in console mode if I needed to display only 2 decimal values of a variable (e.g. Variable1) I would write this simple code:
cout << "Variable1 = " << setprecision (2) << fixed << Variable1 << endl;
But now in C++/CLI environment how can I display this value inside a textbox showing only 2 decimal values?
Can I add some attributes to the following code?
textBox1->Text= Variable1.ToString();
And what about if I wanted to display it in Hexadecimal and/or in Upper case notation?
Many thanks in advance!
|
|
|
|
|
so you decided to use some type's ToString() method but you did not consider reading up about it?
|
|
|
|