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. Calling a Dialog from another Dialog

Calling a Dialog from another Dialog

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++com
4 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.
  • S Offline
    S Offline
    Sayan Mukherjee
    wrote on last edited by
    #1

    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

    P P 2 Replies Last reply
    0
    • S Sayan Mukherjee

      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

      P Offline
      P Offline
      Prem Kumar
      wrote on last edited by
      #2

      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.

      S 1 Reply Last reply
      0
      • S Sayan Mukherjee

        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

        P Offline
        P Offline
        Paul M Watt
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • P Prem Kumar

          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.

          S Offline
          S Offline
          Sayan Mukherjee
          wrote on last edited by
          #4

          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

          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