|
See: http://home.socal.rr.com/samhobbs/VC/Collections.html
The CObList sample can probably be used as an exmple of a CObArray also, with the obvious variations.
I think, however, that a CArray would be good too and might be easier. If you used it as in:
CArray <cfieldsrecord, cfieldsrecord&=""> m_FieldsRecords;
then it would store and retrieve your class items and you could delete everything with a simple:
m_FieldsRecords.RemoveAll();
when you are through. So what was the problem with CArray? I have used them and they work well and are easy to use. I think it would be worthwhile to determine what the problem is and solve it.
|
|
|
|
|
Well In fact I did solve the problem with the CArray and again Im sorry for the poorly written post I was a little
mindboggled last night!!!
I have a class whose constructor is as follows
JPoint(CPoint CP, int state, int Ptool);
This is the object I needed an array of..
In a SetCoordinates function I had code similar to this:
FixedMap.Add(JPoint((100,100),0,1));
Still a newbee I assumed that (100,100) would be assumed to be the CPoint required by the JPoint constructor;
And the fact I recieved no compiler errors lead me to beleive it should work. But when it came draw the points in another function nothing was displayed...
The problem was not prefixing (100,100) with CPoint as follows
FixedMap.Add(JPoint(CPoint(100,100),0,1));
Shouldve known better right???
|
|
|
|
|
Can anyone tell me how to start a thread from inside a class's member function? I keep getting this error
C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)'
None of the functions with this name in scope match the target type
Is this because I'm compiling it as a DLL? The _beginthread call looks like this:
_beginthread(WindowThread, 0, NULL);
and WindowThread is defined as:
friend void WindowThread(PVOID pvoid);
What am I doing wrong? I declared WindowThread as a friend inside the class definition, and I also tried it as a global function outside of the class. I'm stuck.
Thanks for any help given,
- J Woltman
|
|
|
|
|
You should use _beginthreadex instead.
In class you define these:
// used for _beginthreadex
static DWORD WINAPI WriterStartThread(LPVOID);
// thread function which handles messages
virtual DWORD WriterThread(void);
// set when the thread has started running
HANDLE m_WriterThreadEvent; // write thread start event
// handle to the play thread
HANDLE m_WriterThreadHandle; // write thread handle
// thread identifier of play thread
DWORD m_WriterThreadID; // write thread identifier
This is in class function that starts the thread...
// start thread
m_WriterThreadHandle = (HANDLE)_beginthreadex(
(void *)((LPSECURITY_ATTRIBUTES)m_SecurityInfo),
0, // normal stack size
(PFBTEX)WriterStartThread,
(LPVOID)this, // pointer to this class
0, // instance data not used with callback threads
(unsigned *)&m_WriterThreadID
);
This is static member function that just acts to hand off call to the class virtual function.
It maps from the static domain into the class domain so that all thread processing can actually get to member variables.
// static
DWORD WINAPI MWCWaveFileWriter::WriterStartThread(
LPVOID lpData
){
// run member function
DWORD dwRetVal = ((PMWCWaveFileWriter)lpData)->WriterThread();
return( dwRetVal );
}
|
|
|
|
|
When I looked up the documentation, I found that my error was with the using of __stdcall instead of __cdecl function calls. Is there I way I can explicitly tell it to use __cdecl for just the thread function? (I know that is probably a basic question, but I don't know how)
Thanks for the reply,
- J Woltman
|
|
|
|
|
Okay, nevermind, I kept reading (RTFM, I know I know and I got it to work by adding __cdecl to the function declaration.
- j woltman
|
|
|
|
|
Declare as follows
<return type=""> __cdecl <function name="">(Function Arguments>);
For example...
BOOL __cdecl MyFunction(int, int);
|
|
|
|
|
Great... My last exmaple got MUTILATED by HTML parsers...
Okay, let's try again...
Declare as follows
{ReturnType} __cdecl {FunctionName}({Function Arguments});
For example...
BOOL __cdecl MyFunction(int, int);
And for the function that would be passed to the _beginthredex call, if it were a member function of a class, just add 'static' in front of all that...
static BOOL __cdecl MyFunction(int, int);
That prevents the compiler from adding the hidden 'this' parameter as the first argument.
|
|
|
|
|
I created a custom control derived from CWnd. I need to cascade many of these on a CFormView. I am able to create and cascade them but when I click on a portion of the top most control which is over another control, the control underneath receives the mouse input and not the top most one. I tried to disable the previous control but I need to receive WM_ messages for all the cascaded controls.
I also tried this with a standard CButton class and the same problem occured.
Does anyone know how to prevent this behaviour?
Thanks in advance
|
|
|
|
|
We do seem to have amazingly similar problems in spite of the applications being quite different. My application is for subitem editing of a list control, which also uses overlapped windows.
So thank you for mentioning SetWindowPos. There are so many functions like it and the documentation does not make it clear that SetWindowPos would be useful in my situation.
I think that something else I would have tried instead is BeginDeferWindowPos, EndDeferWindowPos and DeferWindowPos. I do not understand exactly what they do and how they work but they might be useful when the z-order of multiple windows needs to be specified. Are they not relevant to you situation?
|
|
|
|
|
Anyone know how to reset the z-order of a window's children to be a specified z-order? Actually, I only need to be able to specify which child to be on top. I am hoping to control which child window gets the mouse click this way. So far setting focus does not work to determine who gtets the mouse click. SetActiveWindow does not affect the z-order, and I think that there is nothing to counter-act it but I will attempt to ensure that that is not a problem.
|
|
|
|
|
To set the Z-Order:
SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE)
|
|
|
|
|
Thank you. I think it is working. Since I am using MFC, I converted your sample to:
m_pEditWindow->SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
There are still some problems with my program but it is likely that they are separate problems. I think that the z-order part is probably solved.
|
|
|
|
|
Hi all,
i have a problem with a function which writes a DIB to a BMP file. The strange thing is that it works with small pictures but fails with big ones
(it messes up the dimensions...)
The raw bitmap data is saved in a 32 bit format, so i have to convert it to 24 bit first. Here is the code...
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER bih;
unsigned char *data=(unsigned char*)malloc(3*m_nDataBr*m_nDataHo); // for the 24 bit data
unsigned char *p=(unsigned char*)m_pdwData; // this is the 32 bit data
for (int i=0, j=0; i<4*m_nDataBr*m_nDataHo; i++) {
data[j++]=p[i++];
data[j++]=p[i++];
data[j++]=p[i++];
}
// Initialize all structures
memset(&bfh, 0, sizeof(BITMAPFILEHEADER));
memset(&bih, 0, sizeof(BITMAPINFOHEADER));
bih.biSize=sizeof(bih);
bih.biBitCount=24;
bih.biHeight=m_nDataHo;
bih.biWidth=m_nDataBr;
bih.biPlanes=1;
bih.biCompression=BI_RGB;
// Fill in the Bitmap File Header
bfh.bfType=((WORD)('M'<<8)|'B');
// Calculate the size of the bitmap including the palette (which should be empty)
bfh.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+m_nDataHo*m_nDataBr*3;
bfh.bfReserved1=bfh.bfReserved2=0;
// Offset to actual bits is after palette
bfh.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
ASSERT(bfh.bfSize>sizeof(BITMAPFILEHEADER));
// Write the results
fwrite(&bfh, sizeof(BITMAPFILEHEADER), 1, f);
fwrite(&bih, sizeof(BITMAPINFOHEADER), 1, f);
fwrite(data, m_nDataHo*m_nDataBr*3, 1, f);
I really don't know what i am doing wrong here... if anybody could help me i really would be glad.
Chris
|
|
|
|
|
Hi Chris,
What exactly is the problem?
Are you able to open the image in some editor?
|
|
|
|
|
Well, if the image is not very big (lets say 200x200 pixels) then it's no problem at all. If it's bigger you
still can open it in a editor, but with some strange effects:
- it might be stretched
- some parts of the image might be grey, not colored
things like that.
|
|
|
|
|
Now I remember that Windows bitmaps must be 32-bits aligned, that is the length of each row must be a multiple of 4 (padded with zeroes).
So you have to re-code the loop which converts the image from 32 to 24 bits to do the alignment.
I forgot that!
Cheers,
Paolo.
|
|
|
|
|
You may also take a look at WINCAP sample in Knowledge Base art. no. Q97193, which contains the DIB API.
|
|
|
|
|
It works now, it was the 32bit-alignment...
BMP files really are a mess!
|
|
|
|
|
under www.imagemagick.org there is a really good image library for free.
No one should nowadays work so low-level like using those Platform SDK image functions, if he can avoid them.
|
|
|
|
|
I would like to add icons to my menu popup items
I am using SDK.
|
|
|
|
|
Im writing an application that displays an image from a web cam on a CFormView. I derived CCamWnd from CStatic
and override OnPaint to display the image. I wanted to take it to the next step and have it handle a windows
message. For example a doubleckick would switch between zoomed in and normal mode. I cant seem to get
the messages passed through to my class. I can get messages passed through to a class derived from
CEdit without a problem.
What is the difference between these two classes...why do they behave differently.
Any comments or suggestions would be greatly appreciated.
Paul Galla
|
|
|
|
|
A static control will notify you of double-clicks, as long as it has the SS_NOTIFY style set. It will send a STN_DBLCLK notification to the parent window via a WM_COMMAND message.
|
|
|
|
|
Is this possible to do using MFC classes?
Either way, where can I find information about this (preferably with source examples...)?
/XTSea
|
|
|
|
|
I use raw Windows sockets.
How to check whether the other side of the connection is closed?
Thanks
|
|
|
|