|
Hi Christian,
Thanks for your reply. The truth is that my drawing function is a lot more complicated than the example i showed in my message. I am going through three "for" loops to display 3D dispersions on a map.
I chose to use a pictureBox because i thought it would be easier to handle the map displaying (zooming in/out, panning etc) by specifying it as the pictureBox->image, and then drawing the rest on top and following the same zooming, panning etc. Not sure it is the best way to go about it, just chose it.
To cut a long story short, apart from removing the flickering from my drawing i wanted to use double buffering to also improve the speed of my displays because these are displayed in real time (would like to anyway every 10 seconds). I did manage to implement the GDI+ double buffering i was straggling with (amazingly enough i was drawing in "bmpBuf" and was displaying "bmpBufr" >:E). However, although the flickering went away the displaying speed did not improve enough.
Do you think the .NET way of handling double buffering would do better (i read that the .NET way is more optimized http://www.windowsforms.net/articles/windowsformspainting.aspx). Any help how do make this work? This is what i tried
pictureBoxMap->SetStyle(ControlStyles::UserPaint, true);
pictureBoxMap->SetStyle(ControlStyles::AllPaintingInWmPaint, true);
pictureBoxMap->SetStyle(ControlStyles::DoubleBuffer, true);
pictureBoxMap->UpdateStyles();
Or any other suggestion how to improve the displaying speed would be much appreciated.
Thanks
george
george
|
|
|
|
|
Yes, you need to draw it yourself and turn on double buffering. Always use provided code first, assume a library author has been paid to take the time to provide the best possible implimentation.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello All!
I have been unable to receive a Byte[] in MC++. Whats the right syntax
this is the C# dll method.
public byte[] GetPictureBytes(Image _Pic)
{
byte[] _rtval = null;
MemoryStream mstr = new MemoryStream();
_Pic.Save(mstr, ImageFormat.Jpeg);
_rtval = mstr.GetBuffer();
return _rtval;
}
Now i have to call this C# dll method in VC++.NET 2005
the syntax that i m using to call and receive this byte array is as follows but its creating some error.
"
array<byte^>^ myImage = gcnew array<byte^>^(1);
myImage = dllobj->GetPictureBytes(_myImage);
"
OR
"array<byte^>^ myImage = gcnew array<byte^>^(1);
myImage = dllobj->GetPictureBytes(_myImage);"
// dllobj is of C# dll Class type that contains metod GetPictureBytes(Image _Pic);
// _myImage is Image type
i have used some other combinations also to receive the Byte array but cant having some errors. Plz guide me writing correct syntax to receive this Byte array in VC++.Net
THNX in Advance
-- modified at 5:55 Wednesday 16th August, 2006
|
|
|
|
|
hello friends;
I am currently trying to write a program that would detect if the colour red.
Basically i need to be able to set it up to monitor a certain portion of my screen (ie, bottom left, box shape) and when it detect a certian chape of red, it will return 1 or 0, or any type of return.
If this is to complicated to explain or to logn to quickly write a short code for it, i understand and thank you for your time in reading this post.
Thank you.
- Droz -
___ ___
/\/\ /\ | |
|
|
|
|
|
To read/set the color of a pixel, there are two Win32/GDI calls, GetPixel() and SetPixel(). Try to find counterparts in managed GDI+. Otherwise, you may have to platform invoke Win32.
Best,
Jun
|
|
|
|
|
Thank you Jun,
i'll look into those functions, thank you.
- Droz -
___ ___
/\/\ /\ | |
|
|
|
|
|
I want to register a sample fax routing dll on Windows XP,
I have found this sample DLL from Windows SDK.
I can not register it, while on Windows 2000 it can be registerered.
On Windows XP the error message is:
"The modem did not accept the command sent to it. verify the configured modem
matches the attached modem."
Anyone could help me plase?
|
|
|
|
|
|
I have DirectX.Capture .dll file and i want to use function in dll but i don't know how to use .dll function in c++.net .
dll function from article 's DirectX.Capture .
|
|
|
|
|
simply #include the header file and
put the .lib file in the linker section.
if u do not have the header file but you know the signature
then use [DllImport] to call the methods from the dll.
first one is the easiest way.
^-^
@|@
- redCat
|
|
|
|
|
Each time when I plug in USB memory stick to the pc, there is a window pops out. I have application to indicate whether a USB memory stick presents.I don't want this auto window to pop out. How shall I resolve it??
|
|
|
|
|
Well, you could buy a Mac...
Seriously, how does this have anything to do with programming, let alone C++/CLI ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Uhm..
This is the problem encountered during programming.
I thought there would be some script can be used to solve it.
Anyway, I fund the solution.
|
|
|
|
|
I'm writing VC++ .net framework code.
I need to retrieve the windows WM_DEVCHANGE message
Shall I use virtual void WndProc( Message* m ) override function or LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) function??
How shall I add either of them to my Form class???
May you write down the format?
|
|
|
|
|
No need to go for WindowPrc as this is an additional work. Becase its already available as part of the framework class library. Given below is a working sample on VS2005. Copy this code in to the .h file of your Form.
virtual void WndProc( Message% m ) override<br />
{ <br />
switch ( m.Msg )<br />
{<br />
case WM_ACTIVATEAPP: <br />
this->Invalidate();<br />
break;<br />
}<br />
Form::WndProc( m );<br />
}
you have to include windows.h for WM_ACTIVATEAPP to work.
cheers..Milton Kb.
|
|
|
|
|
m.LParam is a System::IntPtr, I have problem to convert m.LParam to a
PDEV_BROADCAST_HDRstructure.
I tried:
PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)(m->LParam);
compiler gives error:
error C2440: 'type cast' : cannot convert from 'System::IntPtr' to 'PDEV_BROADCAST_HDR'No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
I tried:
lpdb = (PDEV_BROADCAST_HDR)(m->GetLParam(__typeof(PDEV_BROADCAST_HDR)));
compiler generates following error:
error C3181: 'PDEV_BROADCAST_HDR' : invalid operand for __typeof, expected a fully defined managed type
What is the correct way?
|
|
|
|
|
try PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)(m.LParam.ToPointer());
cheers..Milton KB.
|
|
|
|
|
Thanks a lot Milton,
It works.
Vicky
|
|
|
|
|
Guess u forgot the fact that C++/CLI ^ pointer operator and the tracking reference operator % are not equivalent to its native like counterpart operators * pointer and the & reference. Actually ^ is a handle to its managed heap object and its not a pointer to that. But the handle can provide us with the underlying pointer just like we did.
cheers..Milton KB
|
|
|
|
|
Yup, You are right.
Thanks for the detail explaination for C++/CLI handle which is new to me.
vicky
|
|
|
|
|
Why is the .NET graphics in windows forms app is so slow, manualy ploting some N points line segments using double buffer takes considerable time compared to say builder compiled app?
Is there special tips to make it faster.
9ine
|
|
|
|
|
9ine wrote: ploting some N points line segments using double buffer
Are you drawing into an Image and then displaying the Image on the Window?
led mike
|
|
|
|
|
This is the whole code to render some float array to a form
/////////data////////////////////////////////////////////////////////
Bitmap *canvas = new Bitmap(1280,1024);
Graphics *memg = Graphics::FromImage(canvas);
memg->SmoothingMode = SmoothingMode::HighSpeed;
/////////////////////////////////////////////////////////////////////
private: System::Void p2Dform_Paint(System::Object *sender, System::Windows::Forms::PaintEventArgs *e)
{
paint();
}
private: System::Void p2Dform_Resize(System::Object *sender, System::EventArgs *e)
{
resize();
}
private: void p2Dform::paint(void)
{
Graphics *g = CreateGraphics();
System::Drawing::Rectangle rect(0,0,ClientSize.Width,ClientSize.Height);
//draw image data
g->DrawImage(canvas,0,0,rect,GraphicsUnit::Pixel);
g->Dispose();
}
private: void p2Dform::resize(void)
{
memg->FillRectangle(wbrush,0,0,ClientSize.Width,ClientSize.Height);
//draw file data to memg
draw(ClientSize.Width,ClientSize.Height,color,m_data,len,miny,maxy);
paint();
}
private: void p2Dform::draw(int width,int height,int color, float *data,int len,float minY,float maxY)
{
bpen = new Pen(Color::FromArgb(color));
float stepx,stepy,X1,Y1,X2,Y2;
stepx = float(width-1 - addX*2)/float(len-1);
stepy = float(height-1 - addY*2)/Math::Abs(float(maxY-minY));
for(int i=1; i<len; i++)
{
X1 = stepx*float(i-1);
X2 = stepx*float(i);
Y1 = data[i-1];
if(minY < 0) Y1 += (-1.0f)*minY;
if(minY > 0) Y1 -= minY;
Y1 = float(height-1) - Y1*stepy;
Y2 = data[i];
if(minY < 0) Y2 += (-1.0f)*minY;
if(minY > 0) Y2 -= minY;
Y2 = float(height-1) - Y2*stepy;
memg->DrawLine(bpen,X1+addX,Y1-addY,X2+addX,Y2-addY);
}
bpen->Dispose();
}
9ine
|
|
|
|
|
I can't follow the code.
what does this do? Graphics *g = CreateGraphics();
I don't understand why you have this:
Bitmap *canvas = new Bitmap(1280,1024);
Graphics *memg = Graphics::FromImage(canvas);
memg->SmoothingMode = SmoothingMode::HighSpeed;
and then in paint() you have this: g->DrawImage(canvas,0,0,rect,GraphicsUnit::Pixel);
So you are drawing the bitmap into the graphics object of the bitmap?
led mike
|
|
|
|
|
the float data needs to be drawn once if there is resize event in the form. the data is drawn to memg graphics object. from which it is drawn to a form if it is obscured and then released by another window.
if the form itself resized the data plot needs to be redrawn to fit changed dimensions of the form.
this is double buffer. the float data is put into memg object wich then is painted to a form, so we dont see flick due to clearing the form and ploting data directly to a form.
Graphics *g = CreateGraphics();
creates graphics objects of the form in OnPaint event and the memg object is painted into it.
paint() and resize() is just stubs for OnPaint() and OnResize() events
9ine
|
|
|
|