|
Your copy constructor is not being called. The reason for this can be found in the partial disassembly of the line
mc1.Foo(2, mc1, mc2);
31: mc1.Foo(2, mc1, mc2);
00401090 mov eax,dword ptr [ebp-0Ch] ---->points to mc2.b and loads it to eax
00401093 push eax ----->push value to stack for function
00401094 mov ecx,dword ptr [ebp-10h] ---->points to mc2.a and loads it to eax
00401097 push ecx ----->push value to stack for function
00401098 mov edx,dword ptr [ebp-4] ---->points to mc1.b and loads it to eax
0040109B push edx ----->push value to stack for function
0040109C mov eax,dword ptr [ebp-8] ---->points to mc1.a and loads it to eax
0040109F push eax ----->push value to stack for function
004010A0 push 2 ----->This is the first arg
004010A2 lea ecx,[ebp-8]
004010A5 push ecx
004010A6 call @ILT+0(MyClass::Foo) (00401005)
004010AB add esp,18h
This seems to be compiler optimization if I am not mistaken. However if you write
MyClass mc2(mc1); then the value of mc2 members a & b are 0 i.e. your copy constructor is called.
Atul
Sonork 100.13714 netdiva
|
|
|
|
|
Thanks for the answers, now it’s clear. As the disassembly shows, the compiler generated ‘default copy constructor’ and ignored the user-defined copy constructor. Surely, in this situation, the compiler must warn about what it is doing? Interesting, what the standard says about user defined copy constructors. Does it mention that copy constructors are not applicable in some cases? And how many case are there ?
|
|
|
|
|
Hi,
I'm writing a MIDI program that will write something on an Edit control of dialog whenever there is a MIDI message input.
The callback function for handling MIDI input event needs to be either global or a static member function of such a dialog class. How can I make the callback function calls a member function of that dialog class ? (in order to change the text in the Edit control).
I have tried to make a global pointer and sets it to point to CMainFrame objects in order to access levels of members down to the dialog object. But this causes an invalid page fault in module MFC42D.DLL
Any suggestion will be highly appreciated.
T. Tanprasert (T_Tanprasert@yahoo.com)
|
|
|
|
|
this?
http://www.codeproject.com/useritems/callback_adapter.asp
t!
|
|
|
|
|
|
If I want to draw a picture (ownerdraw buttun) on a button, how can I do så that picture won't be "deleted". I mean I've tried pressing another button that painted a line on another. but when I drag the dialog outside the screen the line dissapeard. Thats ofcourse... but how to keep it there so not my WM_PAINT steal my line or picture?
Hope you understand me!
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
The draw message the button gets should always redraw, the same way that WM_PAINT always does. How are you handling the drawing of the button ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
Is it a Big deal to do that stuff ??
See my problem is our Art director has given me a task to create a fancy shaped toolbar which is a mixture of Office2K type Flat toolbars and Mac os type round edges etc.
I tried to study some of the very good toolbar classes available on CodeProject, but it seems that I can Draw only within the buttons area. not on the edges or Title bar of the toolbar(when its floating) so I need some guidance of how to go about this kind of a stuff.
Gurus please guide me .. I dont mind working hard to write a Toolbar class from the scratch.
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
The NCPAINT message lets you draw around the edges. If you decide to roll your own, look through the MFC source first to see how it all works.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
Ya I am trying to do some drawing in NCPAINT handler ...
But some how I am not able to draw in the full rectangle ..
Just look at the following code and please what is wrong in the code..
CWindowDC cpDC (this);
CRect rcClip;
GetClientRect(&rcClip);
cpDC.FillSolidRect (rcClip,RGB(255,0,0));
the above code does not fill the full rectangle , it still leaves so many margins ..
Also please tell me the differnce between GetWindowRect and GetClientRect ..
Thank you very much
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
1 - GetClientRect is the problem
2 - GetWindowRect gets the whole window area, usually in screen coordinates ( i.e. relative to the top left ), and GetClientRect gets the client area only ( the bit you can draw in OnPaint ).
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
Thanks a lot you have been a great help.
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
I have standart generated by ClassWizard SDI MFC-app. I want that some operation invoked by user that may be performed a while was displayed like dialog with progress bar and "Cancel" button. And while it's displaying, operation should performs, progress bar should displays appropriate value and so on till operation has been completed or user has clicked "Cancel"
What's the easiest way to implement that. After searching through MSDN some implementation approach has appeared but it's so difficult.
Thanks in advance.
|
|
|
|
|
It depends on what the process is. If it's under your control ( i.e. you are working with a set of your own data, using your code ), then a modeless dialog box, with a flag being set by pressing the cancel button, and the flag state checked after each iteration through the process taking place in a loop would be the best way.
If you're formating a hard drive, or some other process not taking place in your code, you'll need a thread.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
Thanks but I can't understand how can I implement it in MFC way. Would you mind show me the way My task is first ie I want to operate own data
Thanks in advance
|
|
|
|
|
Morozov Alexey wrote:
My task is first ie I want to operate own data
So you don't have a task, you just want to know how to do it ?
CWaitDialog dialog; // A modeless dialog that creates itself in it's constructor
for (int i=0;i<10000000;++i)
{
// do something
if (dialog.bStopNow)
{
// Any necessary cleanup
break;
}
}
is all I had in mind.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
You could create a new worker thread. This worker thread can do the background stuff and keep updating the progress control. Thus the cancel button on your main window will still be receptive and not frozen as you might be experiencing now.
Nish
The lady in red is dancing with me
Cheek to cheek
There's nobody here
It's just you and me
It's where I wanna be
But I hardly know this beauty by my side
I'll never forget the way you look tonight
|
|
|
|
|
This being the obvious solution, I guessed it may be the 'too hard' solution he found in MSDN.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
You're about right It's no so hard, but I thought that building new thread, organizing some kind of inter-thread sinchronization is too big to doing such small task. Besides really I have had separate thread that perform that task already. But it's so bulky That why I decided to ask simplier solution.
|
|
|
|
|
Morozov Alexey wrote:
That why I decided to ask simplier solution.
I have always found that the simpler solutions are often the right solutions. The complicated solutions make you feel nice, but often just ends up in a mess.
KISS is actually true [except for the 2nd 'S']
Nish
The lady in red is dancing with me
Cheek to cheek
There's nobody here
It's just you and me
It's where I wanna be
But I hardly know this beauty by my side
I'll never forget the way you look tonight
|
|
|
|
|
Morozov Alexey wrote:
After searching through MSDN some implementation approach has appeared but it's so difficult.
Have you checked Feb'97 issue of MSJ - "Wicked Code" column by Jeff Prosise contains ready-to-use CWaitDialog class. The article may be in MSDN on your harddisk, if it's not there, go to msdn.microsoft.com
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thanks a lot
I'll be searching more carefully in future. Sh*t, why did I can't find it myself It's really what I need.
|
|
|
|
|
Ok I posted before and some helpful folks advised me that I should use messages to communicate between my Dialog application and my threads connecting to a serial device. Trouble is I'm stuck on what the handles and messages are to send the messages so here's where I'm at:
Added this to .h file:
//}}AFX_MSG
afx_msg LRESULT OnCustomMessage(WPARAM w, LPARAM l);
DECLARE_MESSAGE_MAP()
Added this to .cpp file
const UINT wm_Message = RegisterWindowMessage(_T("A8479983-30B2-11d6-BD06-0010A4FDB6CB"));
//..snip ..//
ON_REGISTERED_MESSAGE(wm_Message, OnCustomMessage)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
And this is in the thread:
CString *ps = new CString("Thread is busy.");
::PostMessage(HWND_BROADCAST, wm_Message, (WPARAM)0, (LPARAM)ps);
So as I understand it, the thread posts the message wm_Message and when the window receives the message it calls the function OnCustomMessage. I'm pretty sure using HWND_BROADCAST is wrong, as it isnt working anyway. What handle do I need to give the post message function?? and the next question is how do I get this handle from the thread??
Hopefully this will be the best way of doing what I want to do? The aim is to have a dialog that connects to the serial device and updates List Box control with records in the device. The record selected is then requested from the device and saved to a file. The whole time I also want a richedit box to be displaying progress messages, and maybe updating a progress bar too! Is sending messages back and forth the way to do this or is there another way of sharing the data between the dialog and the threads?
Sorry for the long message and thanks again for any help
-Mark
|
|
|
|
|
Mark,
Change the HWND_BROADCAST to the window handle of the parent.
ie. PostMessage(hWndParent, wm_Message, (WPARAM)0, (LPARAM)ps);
The hWndParent handle can be passed into the thread during creation or maybe simply via another custom message...
A note of caution. Posting messages with pointers to memory is bad news. Make sure that memory posted from the thread to the parent is not cleaned up/garbled before or during the parent's processing of the message. In your example, your passing a new instance of a CString() which needs to be cleaned up by the parent.
|
|
|
|
|
Thanks for the reply,
This is what I'm calling to start the thread:
HANDLE myConnectThread = AfxBeginThread(ConnectThread, (LPVOID)this);
So how would I change it to pass it the hWndParent? Also how do I get the hWndParent value?? is it this->m_hWnd??? This whole handle thing has got me slightly confused.
Also I know how the parent needs to clean up the CString! A helpful person from here has already brought it to my attention!
Is there any better way of doing all this though?? I mean because these threads are static I obviously cant access the member variables of the dialog class directly. Is there other ways of making threads where I could be able to do this? I see there are other ways of meaking threads ie: CreateThread or _beginThread, whats the difference with the one I'm using and which would be betst?
Thanks
-Mark
|
|
|
|