|
To add to what others have said:
1. Passing by value has the added perk of letting you to change the value of "val" inside your function (just like any other local variable), which may prove convenient.
2. Passing by const reference gives the possibility for the function to actually alter the value of "val" by casting away the constness. I know this is silly since most likely you're the one who's writing the function, but it does add to why its just better to pass native types by value instead of const reference.
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
|
|
|
|
|
Hi all.
When not using the "Document/View architecture support" in the step 1 of AppWizard, Must the view of a program be an object whose class is derived from CWnd?
i wanna write a program without "document/view architecture support" and its view is a CView object or a CHtmlView object. i try accept the default value(using the object whose class---CMyView derived from CWnd as the view), and after finishing the wizard, i change the base class of CMyView from CWnd into CHtmlView(include the BEGIN_MESSAGE_MAP macro, IMPLEMENT_DYNCREATE macro), it can run, but it crashes when it close. why?
|
|
|
|
|
Grant Chan wrote:
view is a CView object or a CHtmlView object
Well, every CHtmlView IS derived from CWnd : CWnd::CView::CScrollView::CFormView::CHtmlView is the chan of derivations.
Grant Chan wrote:
it can run, but it crashes when it close. why
What? When? Where?
Need input!
|
|
|
|
|
First thanks for your reply.
jhwurmbach wrote:
Well, every CHtmlView IS derived from CWnd: CWnd::CView::CScrollView::CFormView::CHtmlView is the chan of derivations.
i known that CWnd::CView::CScrollView::CFormView::CHtmlView is the chain, but my question is why CMyView can be derived from CWnd, but cannot be derived from CHtmlView?
jhwurmbach wrote:
What? When? Where?
Need input!
debug assertion failed
Program: ...
File: dbghelp.c
Line: 1011
Expression: _CrtIsValidHeapPointer(pUserData)
|
|
|
|
|
Grant Chan wrote:
my question is why CMyView can be derived from CWnd, but cannot be derived from CHtmlView?
Oh, I see. Sorry for missreading you!
So, you got an dialog-based application, right? That Is, your main Window is derived from CDialog. So you can't simply drop in a CView-derived CHtmlView which depends on having a document to work with. You would need a single-document doc/view program for providing the doc/view infrastructure.
But you can surely place a IE-window on your dialog, using COM and the like.
I have no idea how you would do this in detail, though.
Sorry for being not helpful
|
|
|
|
|
No. my application is an SDI application
|
|
|
|
|
Oh, well, then its simple!
(If you happen to have a similar problem yourself before and spent a whole day googling for a solution, that is
Look at the call stack in your debugger: You will see that the first function (counted top down) with a familiar name is CView::PostNCDestroy() .
Clicking on that line you see a 'delete this; '.
CViews are meant to be constructed on the heap and delete themself after use. You have constructed your window on the stack.
So sumply override PostNCDestroy() in your derived class and do not call the base class.
That should do it!
|
|
|
|
|
jhwurmbach wrote:
do not call the base class
i just overrided the CMyView::PostNcDestroy() with nothing:
void CMyView::PostNcDestroy()
{}
it works(thank god), but i still wanna know how can i simply do that, i mean i'm afraid that will be a memory leak, cos' that's a "delete" operation originally.
And note that if i use MFC appWizard with "Document/view support" checked and change the base view class from CView into CHtmlView, there is no need to override the PostNcDestroy function, it will close successfully. why must i do that?(do u think i'm boring...?)
whatever, thanks again for your help above.
|
|
|
|
|
Without doc/view you don't need to (you must not) delete, because your CHtmlView is on the stack (you simply made a variable like 'CHtmlView htv; ').
As you probably know (I dont know your programming background), delete is for disposing variables made on the heap (as in 'CHtmlView* pHtv = new CHtmlView; '). Calling delete on a variable that is not on the heap (or calling it twice) is not correct.
If you check doc/view in the App wizard, MFC constructs your CView (or derived class like CHtmlView) somehow 'behind your back', using new.
In this case, when the View decides it has to go away, it calls 'delete this; ', and frees its own memory.
|
|
|
|
|
After finding the creation of view by MFC, i feel it's pretty implicit(created in CreateObject() ).
|
|
|
|
|
How do I change the cursor when the mouse pointer is on a button or on a notified picture???
|
|
|
|
|
There is a message WM_SETCURSOR. Deal with in your control and your are ready.
Try it @ home. (B&B)
|
|
|
|
|
use setcursor() on focus message handler
|
|
|
|
|
Can we get a little more help on this issue. I have been trying to do this for the past week but no luck...I have four ownerdrawn windows on my main window for which I would like to use the hand cursor like in internet explorer but all I get is the stinken' arrow. Here is the code that I use.
WM_MOUSEMOVE:
x = LOWORD (lParam);
y = HIWORD (lParam);
RECT rect;
GetWindowRect(hwndView, &rect); // Handle to one of the owner drawn buttons
if ( ( x >= rect.left && x <= rect.right ) &&
( y >= rect.bottom && y <= rect.top )
)
ShowCursor(hCursor);
break;
All with no luck...Is there a difference in the coordinates of the mouse and the ones received by GetWindowRect? If so shouldn't the mouse cursor appear somewhere else on the window...for me, just the stinken' arrow
|
|
|
|
|
anonymous wrote:
Is there a difference in the coordinates of the mouse and the ones received by GetWindowRect?
Yes! As MSDN clearly states (in the entry for WM_MOUSEMOVE ):"The coordinate is relative to the upper-left corner of the client area."
So a simple ClientToScreen() on the mouse coordinates should help.
|
|
|
|
|
Thanks for the help, finally got it working but it wasn't the screen coordinates that were the problem. I didn't pay attention to the fact that WM_MOUSEMOVE is posted TO THE WINDOW THE CURSOR IS UNDER! In my case the buttons so what I needed to do is basically subclass the window which worked great...thanks for your help...I do have another question on this if you could help me with it. Although not a tragedy, when I click on the button now the cursor changes to an arrow and then back which is fine because it is a quick change but for other buttons which invoke dialog boxes then the cursor stays into an arrow over the button where it should be a hand. Is there a way to make the cursor be a hand until it is out of the window regardless of clicking?
|
|
|
|
|
I've been trying to add panes to a Status Bar, and have run into problems with the MS documentation about doing so. Similarly, I've searched the CodeProject list of articles to see if there might be examples on this subject.
Does anybody know of any, or a website, or anything?
Thanks. I appreciate it.
William
|
|
|
|
|
I did the following in my CMainFrame::OnCreate() function. I have a SDI application and wanted a button added to the status bar.
It may not be what you are looking for, but may inspire you in the correct direction.
// The following code allows a button to be added to the status bar
// Add an indicator, with width, ..
m_wndStatusBar.AddIndicator( 1, IDC_BUTTON_STATUS_BAR );
int idx = m_wndStatusBar.CommandToIndex( IDC_BUTTON_STATUS_BAR );
m_wndStatusBar.SetPaneWidth( idx, 15 );
m_wndStatusBar.SetPaneStyle( idx, m_wndStatusBar.GetPaneStyle( idx ) | SBPS_NOBORDERS );
// Create a pane window, and append it to status bar
m_pBtnCommStatus = new CButton;
m_pBtnCommStatus->Create( _T(""), WS_CHILD | WS_VISIBLE | BS_FLAT | BS_BITMAP, CRect(0, 0, 0, 0), &m_wndStatusBar, IDC_BUTTON_STATUS_BAR );
HINSTANCE hInstance = AfxGetInstanceHandle();
// Set the Icon for the button on the status bar.
m_pBtnCommStatus->SetBitmap( ::LoadBitmap( hInstance, MAKEINTRESOURCE(IDB_BITMAP5) ) );
m_wndStatusBar.AddControl( m_pBtnCommStatus, IDC_BUTTON_STATUS_BAR );
Hope this helps
regards
|
|
|
|
|
CMyClass
public:
CMyClass(void);
~CMyClass(void);
#include "stdafx.h"
#include "myclass.h"
CMyClass::CMyClass(void)
{
}
CMyClass::~CMyClass(void)
{
}
When compiling it generates:
c:\x\Project\myclass.cpp(6): error C2533: 'CMyClass::CMyClass' : constructors not allowed a return type
???
Any ideas?
|
|
|
|
|
Did you have the keyword "class" preceding "CMyClass" along with the appropriate braces in its definition?
William
|
|
|
|
|
yes, I just forgot to indicate it my post.
BTW: the class was generated by "add class/generic c++ class"
after eliminating everything that is the full code:
#pragma once
class CMyClass
{
public:
CMyClass(void);
~CMyClass(void);
}
<pre>
<pre>
#include "stdafx.h"
#include "myclass.h"
CMyClass::CMyClass(void)
{
}
CMyClass::~CMyClass(void)
{
}
and that the new error message:
c:\x\Project\MyClass.cpp(6): error C2533: 'CMyClass::__ctor' : constructors not allowed a return type
|
|
|
|
|
Other than the semicolon missing at the end of the class definition (which the compiler would have caught anyway and you would've fixed already), I don't see anything erroneous in the way you have declared and defined the ctor.
Everything looks correct which means the real error is NOT with your constructor. The real error will be with something the compiler didn't like before it reached the constructor. If there is nothing between the class definition and where the constructor appears in it, then the problem is NOT with the way you have defined the class. The problem will be with something that appears before the class definition.
You can rule out there is something wrong with the class and its ctor, and look somewhere else ahead.
William
|
|
|
|
|
It is the missing semicolon. The compiler thinks you are trying to return the class.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
need ~CMyClass() ,This function can't have vairable to pass!!!
|
|
|
|
|
a new workspace solved the problem. The old workspace without the newly added class still compiles fine. Strange thing.
Anyway thanks for your help.
|
|
|
|