Accessing menu options from an embedded dialog
-
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
-
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
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 */ } }
-
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 */ } }
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
-
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
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!
-
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
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
-
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!
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
-
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
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. "
-
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!
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
-
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