Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can we include two Message Maps in one class?

Can we include two Message Maps in one class?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
13 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Sampath579

    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?

    J Offline
    J Offline
    Jochen Arndt
    wrote on last edited by
    #4

    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.

    S 2 Replies Last reply
    0
    • J Jochen Arndt

      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.

      S Offline
      S Offline
      Sampath579
      wrote on last edited by
      #5

      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.

      1 Reply Last reply
      0
      • J Jochen Arndt

        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.

        S Offline
        S Offline
        Sampath579
        wrote on last edited by
        #6

        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.

        V J 2 Replies Last reply
        0
        • S Sampath579

          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.

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #7

          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?

          S 1 Reply Last reply
          0
          • S Sampath579

            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.

            J Offline
            J Offline
            Jochen Arndt
            wrote on last edited by
            #8

            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.

            S 1 Reply Last reply
            0
            • V Victor Nijegorodov

              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?

              S Offline
              S Offline
              Sampath579
              wrote on last edited by
              #9

              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.

              1 Reply Last reply
              0
              • J Jochen Arndt

                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.

                S Offline
                S Offline
                Sampath579
                wrote on last edited by
                #10

                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[^]

                L 1 Reply Last reply
                0
                • S Sampath579

                  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[^]

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #11

                  It looks exactly like a Pushbutton to me. Are you using the correct themes and version of the Windows Common Controls[^]?

                  S 1 Reply Last reply
                  0
                  • L Lost User

                    It looks exactly like a Pushbutton to me. Are you using the correct themes and version of the Windows Common Controls[^]?

                    S Offline
                    S Offline
                    Sampath579
                    wrote on last edited by
                    #12

                    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.

                    L 1 Reply Last reply
                    0
                    • S Sampath579

                      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.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #13

                      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.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups