Can we include two Message Maps in one class?
-
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;
}
// In .cpp file
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?
You are setting the parent of your button to the
m_cdRadViewer
window. Then that window will receive theBN_CLICKED
notfication instead of yourMyClass
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.
-
You are setting the parent of your button to the
m_cdRadViewer
window. Then that window will receive theBN_CLICKED
notfication instead of yourMyClass
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.
-
You are setting the parent of your button to the
m_cdRadViewer
window. Then that window will receive theBN_CLICKED
notfication instead of yourMyClass
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.
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.
-
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?
-
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.
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.
-
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[^]
-
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.
-
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.