Calling a Dialog from another Dialog
-
Hi, I have an MFC executable (.EXE) that is a dialog with some controls. On double-clicking a particular control, I want a second dialog to popup and some information to be passed from the calling dialog to the called dialog. For this I was trying to use a user-defined windows message (WM_POPDLG) and passing the information in a malloc-ed pointer using SendMessage(). The information will be packed into the WPARAM parameter. Before sending the message, I will create the called dialog using Create(). I will retrieve the information in the PreTranslateMessage() function of the called dialog. WM_POPDLG has been defined as: #define WM_POPDLG ((WM_APP) + 100) When I implemented this idea, I found that the PreTranslateMessage() is not getting called at all. Create() worked fine. My question: What do I need to do so that the message sent by SendMessage() hits the right place and gets processed correctly. Am I missing out something? Note: I do not want the called window to become visible before processing the message in PreTranslateMessage(). With best regards, Sayan Email:sayanmukherjee@indiatimes.com
-
Hi, I have an MFC executable (.EXE) that is a dialog with some controls. On double-clicking a particular control, I want a second dialog to popup and some information to be passed from the calling dialog to the called dialog. For this I was trying to use a user-defined windows message (WM_POPDLG) and passing the information in a malloc-ed pointer using SendMessage(). The information will be packed into the WPARAM parameter. Before sending the message, I will create the called dialog using Create(). I will retrieve the information in the PreTranslateMessage() function of the called dialog. WM_POPDLG has been defined as: #define WM_POPDLG ((WM_APP) + 100) When I implemented this idea, I found that the PreTranslateMessage() is not getting called at all. Create() worked fine. My question: What do I need to do so that the message sent by SendMessage() hits the right place and gets processed correctly. Am I missing out something? Note: I do not want the called window to become visible before processing the message in PreTranslateMessage(). With best regards, Sayan Email:sayanmukherjee@indiatimes.com
The way of handling the messages is by creating handler for that message. like using ON_MESSAGE(WM_POPDLG,OnPopDlg) Dont use the 'PreTranslateMessage'. Also the 'SendMessage' will not return unless the message is processed. But i think u could set the information in the dialog using, member variables like CSecondDlg *pdlg = new CSecondDlg(this) ; pDlg->m_Data = Data ;//Set the Data u want pDlg->Create(..) ; //Then call create The Send message I think only needs to be used if u have to communicate with a window created by another module, or in another process.
-
Hi, I have an MFC executable (.EXE) that is a dialog with some controls. On double-clicking a particular control, I want a second dialog to popup and some information to be passed from the calling dialog to the called dialog. For this I was trying to use a user-defined windows message (WM_POPDLG) and passing the information in a malloc-ed pointer using SendMessage(). The information will be packed into the WPARAM parameter. Before sending the message, I will create the called dialog using Create(). I will retrieve the information in the PreTranslateMessage() function of the called dialog. WM_POPDLG has been defined as: #define WM_POPDLG ((WM_APP) + 100) When I implemented this idea, I found that the PreTranslateMessage() is not getting called at all. Create() worked fine. My question: What do I need to do so that the message sent by SendMessage() hits the right place and gets processed correctly. Am I missing out something? Note: I do not want the called window to become visible before processing the message in PreTranslateMessage(). With best regards, Sayan Email:sayanmukherjee@indiatimes.com
If you are creating a dialog class that is derived from CDialog, you can simply add a member variable in the CDialog derived class, set that member with your allocated data in the main dialog before you display your second dialog. Then you will be able to access that data in your OnDialogInit handler of your second dialog. If you are simply calling CreateDialog or DialogBox to display your dialog, then call CreateDialogParam, or DialogBoxParam instead and set the dwInitParam to the allocated data pointer. In your OnInitDialog handler, the LPARAM of that message will be this pointer.
-
The way of handling the messages is by creating handler for that message. like using ON_MESSAGE(WM_POPDLG,OnPopDlg) Dont use the 'PreTranslateMessage'. Also the 'SendMessage' will not return unless the message is processed. But i think u could set the information in the dialog using, member variables like CSecondDlg *pdlg = new CSecondDlg(this) ; pDlg->m_Data = Data ;//Set the Data u want pDlg->Create(..) ; //Then call create The Send message I think only needs to be used if u have to communicate with a window created by another module, or in another process.
Hi, Thank you for your reply. Why is it that PreTranslateMessage() should not be used? All messages to the window pass through this function. Isn't it the obvious place to trap the working of a message? Or, is it reserved for system messages only? I have tried the code with PreTranslateMessage() and it is not just working. The code inside is just not getting called for the user-defined message. All other messages are passing through the function as expected. Am I missing out something? With best regards, Sayan Email:sayanmukherjee@indiatimes.com