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. Accessing menu options from an embedded dialog

Accessing menu options from an embedded dialog

Scheduled Pinned Locked Moved C / C++ / MFC
9 Posts 3 Posters 0 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.
  • T Offline
    T Offline
    Trevy
    wrote on last edited by
    #1

    I am still having problems creating an application using menus. I created a dialog based application that has an embedded dialog in the main dialog. The embedded dialog contains two tabs, one tab displays a dialog showing temperature readings (among other things), the other tab displays database values. I placed a menu on the main dialog. When I select celsius from the menu of the main dialog I want the celsius value to display on one of the embedded dialogs. I have tried different strategies, but none seem to work. I tried to use the ON_COMMAND function, but I am not getting any results. My code works if I put buttons on the embedded dialog, however, I want to use the menu resource instead of buttons. Specifically, I select celsius from the menu of the main dialog, I want the raw units currently displayed in the embedded dialog to be changed to celsius values. Any suggestions will be appreciated. Thanks

    Trevy

    L 1 Reply Last reply
    0
    • T Trevy

      I am still having problems creating an application using menus. I created a dialog based application that has an embedded dialog in the main dialog. The embedded dialog contains two tabs, one tab displays a dialog showing temperature readings (among other things), the other tab displays database values. I placed a menu on the main dialog. When I select celsius from the menu of the main dialog I want the celsius value to display on one of the embedded dialogs. I have tried different strategies, but none seem to work. I tried to use the ON_COMMAND function, but I am not getting any results. My code works if I put buttons on the embedded dialog, however, I want to use the menu resource instead of buttons. Specifically, I select celsius from the menu of the main dialog, I want the raw units currently displayed in the embedded dialog to be changed to celsius values. Any suggestions will be appreciated. Thanks

      Trevy

      L Offline
      L Offline
      lucy 0
      wrote on last edited by
      #2

      I would assume you handle the menu by your main dialog, and pass the message down to your embedded dialog for further process. say, CMyMainDialog::OnMenuCelsius () { SendMessage (pEmbedDialog->m_hwnd, WUM_MENU_CELCIUS); } CMyEmbedDialog::WindowProc (UINT message, WPARAM wParam, LPARAM lParam ) { if (message == WUM_MENU_CELCIUS) { /* display raw units to celcius values */ } }

      T 1 Reply Last reply
      0
      • L lucy 0

        I would assume you handle the menu by your main dialog, and pass the message down to your embedded dialog for further process. say, CMyMainDialog::OnMenuCelsius () { SendMessage (pEmbedDialog->m_hwnd, WUM_MENU_CELCIUS); } CMyEmbedDialog::WindowProc (UINT message, WPARAM wParam, LPARAM lParam ) { if (message == WUM_MENU_CELCIUS) { /* display raw units to celcius values */ } }

        T Offline
        T Offline
        Trevy
        wrote on last edited by
        #3

        Thanks Lucy for your help. I am a beginner using MFC and I am still having problems with the concept of using messages. Can you tell me what I am doing wrong. I am getting the error C3861: 'WM_MENU_CELSIUS' identifier not found, even with argument-dependent lookup In my header file: // Create and assign pointers to each embedded window _3DSEmbeddedDialog *m_dPointer[2]; In my .cpp file for main dialog: BEGIN_MESSAGE_MAP(CMotionAnalyzerDlg, CDialog) ...... ON_COMMAND(ID_TEMPERATURE_CELSIUS, OnTemperatureCelsius) WM_MENU_CELSIUS() END_MESSAGE_MAP() //2 embedded dialogs. Celsius temperature should display in the //moteDataDlg dialog box m_dPointer[0] = &moteDataDlg; m_dPointer[1] = &databaseDlg; void CMotionAnalyzerDlg::OnTemperatureCelsius() { SendMessage(m_dPointer[0], WM_MENU_CELSIUS); } In my .cpp file for embedded dialog moteDataDlg: void MoteDataDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if (message==WM_MENU_CELSIUS) { celsiusFlag = !celsiusFlag; AfxBeginThread(MyThreadProc, this); } } Thanks for taking the time to help me.

        Trevy

        L J 2 Replies Last reply
        0
        • T Trevy

          Thanks Lucy for your help. I am a beginner using MFC and I am still having problems with the concept of using messages. Can you tell me what I am doing wrong. I am getting the error C3861: 'WM_MENU_CELSIUS' identifier not found, even with argument-dependent lookup In my header file: // Create and assign pointers to each embedded window _3DSEmbeddedDialog *m_dPointer[2]; In my .cpp file for main dialog: BEGIN_MESSAGE_MAP(CMotionAnalyzerDlg, CDialog) ...... ON_COMMAND(ID_TEMPERATURE_CELSIUS, OnTemperatureCelsius) WM_MENU_CELSIUS() END_MESSAGE_MAP() //2 embedded dialogs. Celsius temperature should display in the //moteDataDlg dialog box m_dPointer[0] = &moteDataDlg; m_dPointer[1] = &databaseDlg; void CMotionAnalyzerDlg::OnTemperatureCelsius() { SendMessage(m_dPointer[0], WM_MENU_CELSIUS); } In my .cpp file for embedded dialog moteDataDlg: void MoteDataDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if (message==WM_MENU_CELSIUS) { celsiusFlag = !celsiusFlag; AfxBeginThread(MyThreadProc, this); } } Thanks for taking the time to help me.

          Trevy

          L Offline
          L Offline
          lucy 0
          wrote on last edited by
          #4

          WM_MENU_CELSIUS is not a standard message. It's a user message. You have to define it. For example, in your header file moteDataDlg.h, add the following: #define WM_MENU_CELSIUS (WM_USER + 100) for more information on WM_USER, check its entry in MSDN. All the best!

          J T 2 Replies Last reply
          0
          • T Trevy

            Thanks Lucy for your help. I am a beginner using MFC and I am still having problems with the concept of using messages. Can you tell me what I am doing wrong. I am getting the error C3861: 'WM_MENU_CELSIUS' identifier not found, even with argument-dependent lookup In my header file: // Create and assign pointers to each embedded window _3DSEmbeddedDialog *m_dPointer[2]; In my .cpp file for main dialog: BEGIN_MESSAGE_MAP(CMotionAnalyzerDlg, CDialog) ...... ON_COMMAND(ID_TEMPERATURE_CELSIUS, OnTemperatureCelsius) WM_MENU_CELSIUS() END_MESSAGE_MAP() //2 embedded dialogs. Celsius temperature should display in the //moteDataDlg dialog box m_dPointer[0] = &moteDataDlg; m_dPointer[1] = &databaseDlg; void CMotionAnalyzerDlg::OnTemperatureCelsius() { SendMessage(m_dPointer[0], WM_MENU_CELSIUS); } In my .cpp file for embedded dialog moteDataDlg: void MoteDataDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if (message==WM_MENU_CELSIUS) { celsiusFlag = !celsiusFlag; AfxBeginThread(MyThreadProc, this); } } Thanks for taking the time to help me.

            Trevy

            J Offline
            J Offline
            JudyL_MD
            wrote on last edited by
            #5

            Trevy wrote:

            BEGIN_MESSAGE_MAP(CMotionAnalyzerDlg, CDialog) ...... ON_COMMAND(ID_TEMPERATURE_CELSIUS, OnTemperatureCelsius) WM_MENU_CELSIUS() END_MESSAGE_MAP()

            First, remove WM_MENU_CELSIUS from the MessageMap - you're handling it yourself from the WindowProc. Next, WM_MENU_CELSIUS a user-defined windows message. You need to define it. #define WM_MENU_CELSIUS WM_APP Lastly, I would change your SendMessage to PostMesasge. The difference is whether you wait for the message to be processed. Judy

            1 Reply Last reply
            0
            • L lucy 0

              WM_MENU_CELSIUS is not a standard message. It's a user message. You have to define it. For example, in your header file moteDataDlg.h, add the following: #define WM_MENU_CELSIUS (WM_USER + 100) for more information on WM_USER, check its entry in MSDN. All the best!

              J Offline
              J Offline
              JudyL_MD
              wrote on last edited by
              #6

              That really should be WM_APP not WM_USER. I've had instances where WM_USER has been used by some of the newer MFC classes. I don't remember off-hand which one it was but I had a problem in one of my apps that was do to something else also using WM_USER. When I changed my define to WM_APP the problem went away. Judy

              L 1 Reply Last reply
              0
              • J JudyL_MD

                That really should be WM_APP not WM_USER. I've had instances where WM_USER has been used by some of the newer MFC classes. I don't remember off-hand which one it was but I had a problem in one of my apps that was do to something else also using WM_USER. When I changed my define to WM_APP the problem went away. Judy

                L Offline
                L Offline
                lucy 0
                wrote on last edited by
                #7

                thank you. that's good to know. I read wm_app again, and noticed it's said as follows: "Message numbers in the second range (WM_USER through 0x7FFF) can be defined and used by an application to send messages within a private window class. These values cannot be used to define messages that are meaningful throughout an application, because some predefined window classes already define values in this range. For example, predefined control classes such as BUTTON, EDIT, LISTBOX, and COMBOBOX may use these values. Messages in this range should not be sent to other applications unless the applications have been designed to exchange messages and to attach the same meaning to the message numbers. "

                1 Reply Last reply
                0
                • L lucy 0

                  WM_MENU_CELSIUS is not a standard message. It's a user message. You have to define it. For example, in your header file moteDataDlg.h, add the following: #define WM_MENU_CELSIUS (WM_USER + 100) for more information on WM_USER, check its entry in MSDN. All the best!

                  T Offline
                  T Offline
                  Trevy
                  wrote on last edited by
                  #8

                  Still having problems. I know this should be simple, however, this is the second day I have been working on this problem and I still cannot seem to solve the problem. Thank you for your help or I would not have gotten this far. Thanks to Judy also. void CMotionAnalyzerDlg::OnTemperatureCelsius() { //m_dPointer[0]->SendMessage(WM_MENU_CELSIUS,0,0); SendMessage(m_dPointer[0]->m_hWnd, WM_MENU_CELSIUS); } In the function OnTemperatureCelsius() of the main dialog, if I use the statement SendMessage(m_dPointer[0]->m_hWnd, WM_MENU_CELSIUS); I get error C2664: CWnd::SendMessageA: cannot convert parameter 1 from HWND to UINT. m_dPointer[0] refers to the embedded dialog (moteDataDlg). I tried an alternate statement that I saw when searching for an answer. If I use the statement m_dPointer[0]->SendMessage(WM_MENU_CELSIUS,0,0), my application compiles but do not run. Also, I am using the WindowProc correctly in my embedded dialog (moteDataDlg), I use LRESULT for the return value, initially, I used void. In the header file I declared: protected: LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); LRESULT MoteDataDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if (message==WM_MENU_CELSIUS) { celsiusFlag = !celsiusFlag; AfxBeginThread(MyThreadProc, this); } return 0; }

                  Trevy

                  J 1 Reply Last reply
                  0
                  • T Trevy

                    Still having problems. I know this should be simple, however, this is the second day I have been working on this problem and I still cannot seem to solve the problem. Thank you for your help or I would not have gotten this far. Thanks to Judy also. void CMotionAnalyzerDlg::OnTemperatureCelsius() { //m_dPointer[0]->SendMessage(WM_MENU_CELSIUS,0,0); SendMessage(m_dPointer[0]->m_hWnd, WM_MENU_CELSIUS); } In the function OnTemperatureCelsius() of the main dialog, if I use the statement SendMessage(m_dPointer[0]->m_hWnd, WM_MENU_CELSIUS); I get error C2664: CWnd::SendMessageA: cannot convert parameter 1 from HWND to UINT. m_dPointer[0] refers to the embedded dialog (moteDataDlg). I tried an alternate statement that I saw when searching for an answer. If I use the statement m_dPointer[0]->SendMessage(WM_MENU_CELSIUS,0,0), my application compiles but do not run. Also, I am using the WindowProc correctly in my embedded dialog (moteDataDlg), I use LRESULT for the return value, initially, I used void. In the header file I declared: protected: LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); LRESULT MoteDataDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if (message==WM_MENU_CELSIUS) { celsiusFlag = !celsiusFlag; AfxBeginThread(MyThreadProc, this); } return 0; }

                    Trevy

                    J Offline
                    J Offline
                    JudyL_MD
                    wrote on last edited by
                    #9

                    It looks ok to me. Time to break out the debugger. Put a breakpoint on your SendMessage and follow the execution to see where it doesn't work. Judy

                    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