|
Have you single-stepped through the code using the debugger? What is the value of rc along the way?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
#include <iostream>
using namespace std;
const int size = 3;
class vector{
int v[size];
public:
vector();
vector(int *x);
friend vector operator * (int a, vector b);
friend vector operator * (vector b, int a);
friend istream & operator >> (istream &, vector &);
friend ostream & operator << (ostream &, vector &);
};
in the above code the i am having problem understanding the friend f^n Quote: friend istream & operator >> (istream &, vector &);
here's what i know, so istream is for input streaming of data & ostream for output, and does & epresents some kind of reference to function >> ?
It is really confusing, please explain.
Thank you.
|
|
|
|
|
friend istream & operator >> (istream &, vector &);
That is just for telling the computer the extraction operator (>> ) is friend of the vector class.
The reference (& ) is part of the extraction operator signature, e.g.
istream & operator >> (istream & is, vector & v);
Because such a operator
- takes a reference to
istream and a reference to a vector as arguments. - returns a reference to a
istream . Incidentally this the magic underneath the extraction operator chaining, for instance:
cin >> v >> i; ->
(cin >> v) >> i; ->
cin >> i; ->
cin;
|
|
|
|
|
Hi
I have a class which derives from CScrollView and i have a message map in it whose base class is CScrollView as follows:
class MyClass : public CScrollView
{
public :
DECLARE_MESSAGE_MAP();
void OnButtonSelect();
void Init();
CButton m_button;
}
BEGIN_MESSAGE_MAP(MyClass , CScrollView)
ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
ON_BN_CLICKED(1010, OnButtonSelect)
END_MESSAGE_MAP()
MyClass::Init()
{
m_button.Create(_T("Hi"),, BS_PUSHBUTTON, CRect(0, 0, 80, 20), m_cdRadViewer, 1010);
m_button.ShowWindow(SW_SHOW);
}
MyClass:OnButtonSelect()
{
AfxMessageBox(_T("hi, button Clicked"));
}
In the above code, when i click on button, OnButtonSelect() is not getting called even i added the button notification message in Message Map. After investigation i understood, the Base class mentioned in Message map and my class is from CScrollView and it cannot inherit the button features.
If this is true, how can i access the button message in my function.
I want to create the buttons in runtime and want to do some operation based on the button click.
Is it possible to notify in case if my class is derived from CScrollView?
modified 15-Mar-18 5:40am.
|
|
|
|
|
In DECLARE_MESSAGE_MAP you have:
void OnButtonSelect();
but in BEGIN_MESSAGE_MAP you have:
ON_BN_CLICKED(1010, OnMyButtonClicked)
which is not defined.
|
|
|
|
|
Sorry its typo. The same function available in .h and .cpp. I corrected it now.
But still not working.
modified 15-Mar-18 6:01am.
|
|
|
|
|
You are setting the parent of your button to the m_cdRadViewer window. Then that window will receive the BN_CLICKED notfication instead of your MyClass instance window.
You have to pass the correct window:
m_button.Create(_T("Hi"), BS_PUSHBUTTON, CRect(0, 0, 80, 20), this, 1010); Note that I have also removed an additional comma which would make your code throw a compilation error.
|
|
|
|
|
Hey, Many thanks. It was working fine if i give this as window in CButton Create. But on my window i am loading active x control and hence i am giving active x control object so that it will always render on top of the window.
If i give "this", the button will be visible, once i load the active x control, the control will be on top and button will go back and thats the reason i gave active x control object instead of "this"
I will investigate like how to render it on top of active x control window, by creating it on "this" window.
modified 15-Mar-18 7:14am.
|
|
|
|
|
Jochen
Even i gave the style of my button as push_button, why it appears as flat one without any push behavior. I added the button to the main window by this. I dint even loaded the active x control but even then it looks like flat button. Even i click on that button there is no depth i can see on it, there is no response from the button.
for (int i = 0; i < 1; i++)
{
m_button[i].Create(_T("Hi"), BS_PUSHBUTTON | WS_CHILD, CRect(0, 250, 120, 300), this, 101);
m_button[i].ShowWindow(SW_SHOW);
}
My class is derived from CTabView. I dint added any view yet. Just on that window i created this button at the bottom , i mean on the tab control bar to simulate it as a tab.
|
|
|
|
|
Sampath579 wrote: My class is derived from CTabView. I dint added any view yet. Just on that window i created this button at the bottom , i mean on the tab control bar to simulate it as a tab.
but CTabView and "the tab control bar" are different windows! Don't they?
|
|
|
|
|
My class is just derived from CTabView. I dint add any view or functionality except adding a button. Even though they are different, during button creation i gave "this" (which one does it refer? tab control or TabView) as the parent window. If "this" refers to tabcontrol then it should behave normally. right? Even i want to add button on TabControl bar itself but not on view.
|
|
|
|
|
I don't know why that happens. I have just tried it with a simple dialog based app and the button looks like those from the dialog template.
|
|
|
|
|
You can see my window with tab control and the look of the button in below link. I just created a class which inherits from CTabView which created a window with tabcontrol and added a code to create a button at bottom of the window. But the button does not look like push button.
Imgur: The magic of the Internet[^]
|
|
|
|
|
It looks exactly like a Pushbutton to me. Are you using the correct themes and version of the Windows Common Controls[^]?
|
|
|
|
|
Instead of inheriting a class from CTabview, this time i inherited from CScrollView and created a button on it which you can see in below link. This button perfectly looks like pushbutton and when i click on the button, there is some interaction i can see, i.e., button movement in and out. You can even observe a border on this button since i clicked on it.
Imgur: The magic of the Internet[^]
I am not understanding how this behaviour is getting differ from a CTabView class to CScrollView class.
|
|
|
|
|
I wonder if the problem is that the CTabView has not been designed to allow what you want. Perhaps you should switch to the underlying CMFCTabCtrl Class[^], and roll your own version.
|
|
|
|
|
I created a class which inherits from CTabView as follows:
class CTabClass : public CTabView
{
void OnCreate()
{
m_CView = RUNTIME_CLASS(CDocumentView);
AddView(m_CView,_T("Tab1"));
AddView(m_CView,_T("Tab2"));
}
}
I want only one view for all the tabs. Is it possible in MFC?
|
|
|
|
|
How many more times do you plan to repost this question? We have explained why this will not do what you want, and given some suggestions for finding an alternative approach. Please try some of those suggestions for yourself.
|
|
|
|
|
Yes, it could work, but not like you tried above ... think that m_CView is the same CView instance on every tab, which is impossible ... but you can try to create a new instance on every AddView call, something like that:
AddView(new CYourView(),_T("Tab1"));
AddView(new CYourView(),_T("Tab2"));
this is simplistic approach, that I wrote it just you see the point, but in a real situation, you have to elaborate this: create any instance of CYourView object you need, add every one of them in an array of pointers, and supply this pointers on AddView call as first argument. Do you understand what I say ?
|
|
|
|
|
And the solution that I just give you is more as you see why your approach is not working than to be applied in your application ... because the creation of your CYourView is not that simple ... they must be attached at you CDocument, and so on ...
Because you have problems in completing your task, this reveal that your approach is not right ... you have to think to another ...
|
|
|
|
|
I can create different views successfully if i create objects for each individual view as you said
AddView(new MyView(),_T("tab1"));
AddView(new MyView(),_T("tab2"));
But my requirement is not create multiple view objects, only one view object should be available and multiple tabs should exists. The single view should keep on refreshing when tabs are changed.
|
|
|
|
|
"only one view object should be available and multiple tabs should exists"
If you need just one view, why you need tabs then ?
|
|
|
|
|
Based on user selection, the graphics on the CView should change. On this CView i will load some Active X control to render the graphics on this window.
If i create multiple CViews with new object, then i have to load the Active X Control on each CView which is a costly operation and memory increases and it not a good way to deal as there are many issues with memory, performance and other areas in my application.
Thats why i want multiple tabs with one single view to solve my issue.
|
|
|
|
|
Then you should simulate tabs with some simple buttons, which will change the CYourView content ...
|
|
|
|
|