Click here to Skip to main content
12,881,813 members (28,018 online)

Comments by Iain Clarke, Warrior Programmer (Top 15 by date)

This question does not make a lot of sense. C# had forms. MFC has windows and dialogs. If you have a dialog box, and a graph control on it, then I am guessing you are adding a double click handler to your dialog box, when you should be adding a notify handler, with the notify code and control ID.
Without knowing what "graph" is, we can't really help you any more that that.
Do a search for ON_NOTIFY, and NM_DBLCLK, and some information about standard controls will show up for you.
Well, I can do VT_BYREF | VT_I4 to "connect" to a (..., ref int, ...) function, so the marshaller is clever enough there. Just VT_ARRAY | x means the marshaller has to package up a safearray with its contents to pass to the other end too.

My problem is that the marshaller does not "bring back" the array afterwards...

I have done some reading into MarshalAs which started to look hopeful, but that might be just for C# to c++ (ie, PInvoke), not COM to C#.

You: "each value is a gray level from 0 to 255"... sounds like 1 byte to me!

As you have 1024 pixels, your data is already a multiple of 4, so I don't think you need padding. You might have the values in the BITMAPHEADER wrong? And maybe you're saying you;re using a palette, when your data is already in colour?

I'd start with a simple 16x16 array, with all colours being simple, and work up from there. If your 24 bit colour values are "backwards", then you might just have to copy them to another buffer, re-arranging them as you go.

Didn't you say your data is 1 byte, and greyscale?

In which case, R=G=B!

But I think the confusion may be in how intel stores numbers:
0x12345678 stored in ram becomes: 78 56 34 12

Trust me, you can use COLORREF type and RGB macro for this.

I guess you have a CDC of some sorts, and are doing SetPixel in a loop?

If so, throw the loop away, and do:
::SetDIBitsToDevice (*pDC, ...., &m_pBlockOfBytes, &m_bmiPrePreparedBitmapStructure, DIB_RGB_COLORS);

Your block of bytes is where your numerical values are - bytes 0-1024, followed by bytes 1040-2047, and so on. It's not quite the same as a 1040x1024 array, but it's equivalent.

You can also prepare your bitmap array in advance too:
m_pbmi = (BITMAPINFO *)malloc (sizeof (BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD));
ZeroMemory (m_pbmi, sizeof (BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD));
m_pbmi->bmiHeader.... = ...;
for (int n = 0; n < 256; n++)
m_pbmi->bmiColors [n].rgbRed = n;
m_pbmi->bmiColors [n].rgbGreen = n;
m_pbmi->bmiColors [n].rgbBlue = n;

As I said before, this is a complex function, but powerful. Once you've done the initial setup work, you can just change one of your data bytes, invalidate your window, and in your paint / ondraw function, you can just call the one line setdibitstodevice function, and you're done!

It's MILES faster than 1 million setpixels.

There's an example linked from the website I showed above, but I agree it's not very clear.

Unfortunately, any code I can paste in here belongs to previous customers, but I can recommend just looking at the msdn pages, and for BITMAPINFO structure too.
Have you read here:
It apparently is a bit obsolete now...

If one of the solutions here helped you, you should "Accept" the solution so others will know it was a good one.

And then people like me will know that your question has been answered.

If they did not help, and you found out the answer yourself, then you should add a comment to your original question.

Glad CP helped you,

This does not actually help the user... Whether the different views are tabbed, or have a more proper window frame does not change his problem.


ps, I would be a bit surprised to see a MDI classic program now, but tabbed documents are still MDI...
This is going to be a little hard to understand, but when you do, you'll go "ahah!!".

When you pass an object by value, the function gets a whole new object to play with - it's copied from the "original".

If you pass a pointer to an object, then the function gets a pointer to the original. If you make changes to the object in the function, then the original gets changed. Try experiment with this - make a function, taking a pointer to something simple, like a CPoint.

When you define a pointer to an object, you don't have to define the object. A pointer to anything is the same size. [99% true]. A pointer is just a memory location value. The compiler is nice, and makes sure you don't make easy mistakes, but that's all it is.

The problem with pointers, is that it is not all that difficult to make mistakes. People can set them to NULL, and so on.

References are just like pointers. They're just pointers in a fancy suit. It's just harder to make mistakes. You can't have NULL for example.

More than this, you'll need to go get a book - but I hope this has given you something to think about, and experiment with.

A reference
Iain Clarke, Warrior Programmer - 19 mins ago
Have a look here:
In short.
A depends on B.
B depends on C.
C depends on A.

I hope that helped,

Have a look here:
In short.
A depends on B.
B depends on C.
C depends on A.

I hope that helped,

This is a question, or maybe comment, not an answer.
Pretty much any charting answer is "look at Cedric's control" !

You da chart guy!

Reason for my vote of 5
Answers the question, and attempts to educate the questioner also

Advertise | Privacy | Mobile
Web02 | 2.8.170422.1 | Last Updated 1 Jan 1900
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid