Loading ...
Sorry, an error occurred while loading the content.

Re: PostMessage from a child to the MainFrm

Expand Messages
  • Maryam
    ... the list ... PostMessage ... work ... your ... HWND ... I have tried , but it doesn t work. when I define the HWND in this way,however,no error is
    Message 1 of 7 , Feb 4, 2007
    View Source
    • 0 Attachment
      --- In wtl@yahoogroups.com, gchen <chengang31@...> wrote:
      >
      > Maryam wrote:
      > > I need to Post a Message from a child to the MainFrm to clean
      the list
      > > of a combobox right after I have closed the child, I use
      PostMessage
      > > inside the OnFinalMessage function,but the postmessage does not
      work
      > > properly because it doesn't find the m_hWnd it needs.
      > > does anybody have any idea to implement this situation?
      > >
      >
      > Why not simply add a HWND data memeber, like m_hWndOfMainFrm, in
      your
      > child frame (I assume you mean child frame), after creating child
      > frame, you assign the MainFrame's m_hWnd to it, then you have a
      HWND
      > to post message later.
      >
      > My 2 cents
      > cg
      >

      I have tried , but it doesn't work. when I define the HWND in this
      way,however,no error is reported,but the message won't be posted to
      the PreTranslateMsg of MainFrm.
      Actually I can't understand how messaging is done in WTL?
      As you know the PostMessage in WTL is defined as below:

      BOOL PostMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0)

      when I go to it's definition in ATL header(atlwin.h) I find:

      BOOL PostMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0)
      throw()
      {
      ATLASSERT(::IsWindow(m_hWnd));
      return ::PostMessage(m_hWnd,message,wParam,lParam);
      }
      this code brings up some questions:
      1-the m_hWnd in this code refers to which window?
      2-when we write a code like this: PstMessage(XXX);
      -XXX is defined as a message;
      where is the message posted?
    • Ryan Ginstrom
      ... I have taken to using a Broadcaster/Broker framework using Loki::AssocVector, boost::signal, boost::shared_ptr, and boost::bind. Classes interested in
      Message 2 of 7 , Feb 4, 2007
      View Source
      • 0 Attachment
        > Behalf Of Ingar Steinsland
        > Although I am not VERY happy about the solution, it works.
        > And AfxGetApp is available everywhere in our application.
        > Perhaps anyone has a better solution?

        I have taken to using a Broadcaster/Broker framework using
        Loki::AssocVector, boost::signal, boost::shared_ptr, and boost::bind.

        Classes interested in various messages/data sources register themselves as
        signal sources, or subscribe to those signals.

        The cool thing about this approach is that classes don't have to be windows
        (or get chained from window classes) to get messages, and senders/receivers
        don't need to know anything about each other, just the messages they are
        interested in. This has been very effective for decoupling.

        The down side, of course, is pulling in all this machinery to get it
        working. Although I was surprised that adding the boost/Loki libraries above
        only added about 50KB to my executable, and made it much more flexible in
        the bargain.

        Regards,
        Ryan

        --
        Ryan Ginstrom
      • Maryam
        Dear Ingar I don t get the idea,why have you defined a new CMainFrame pointer? what s the use of this pointer in messaging problem I have described? will you
        Message 3 of 7 , Feb 4, 2007
        View Source
        • 0 Attachment
          Dear Ingar

          I don't get the idea,why have you defined a new CMainFrame pointer?
          what's the use of this pointer in messaging problem I have described?

          will you explain more about this method?

          Thank you anyway,
          Maryam.

          --- In wtl@yahoogroups.com, Ingar Steinsland <ingar@...> wrote:
          >
          > Hi Maryam,
          >
          > In our project we have done the following:
          >
          > In stdafx.h":
          >
          > class CMainFrame;
          > extern CMainFrame* pWndMain;
          >
          > inline CMainFrame * AfxGetApp() {return pWndMain;}
          >
          > And then in our main startup module:
          >
          >
          > CAppModule _Module;
          > CMainFrame *pWndMain; // BUG: It works, but I am not very
          happy
          > about the solution
          >
          > ....
          >
          > pWndMain=new CMainFrame;
          >
          > LabField_Register(hInst); // Register special
          > LabelCraft EDIT control
          >
          > CMessageLoop theLoop;
          > _Module.AddMessageLoop(&theLoop);
          >
          > .....
          >
          > Although I am not VERY happy about the solution, it works. And
          AfxGetApp
          > is available everywhere
          > in our application. Perhaps anyone has a better solution?
          >
          > Another thing we have seen (off topic) is that after we do
          a "delete
          > pWndMain", we cannot restart the
          > appication with "pWndMain=new CMainFrame;" We get all sorts of
          error
          > messages, so it seems to me
          > that WTL does not clean up properly after the main class has been
          > deleted. Any ideas?
          >
          > Best regards,
          > Ingar
          >
          >
          >
          > Maryam wrote:
          >
          > > I need to Post a Message from a child to the MainFrm to clean
          the list
          > > of a combobox right after I have closed the child, I use
          PostMessage
          > > inside the OnFinalMessage function,but the postmessage does not
          work
          > > properly because it doesn't find the m_hWnd it needs.
          > > does anybody have any idea to implement this situation?
          > >
          > > Regards,
          > > Maryam Kasravi.
          > >
          > >
          >
          >
          >
          > --
          >
          _____________________________________________________________________
          ____
          > Ingar Rune Steinsland, LabelCraft AS, P.O. Box 229, 1541 Vestby,
          Norway
          > Phone: 47+64982400/64982402 Cell: +4790055401 Fax: 47-
          64982401
          > email: ingar@... web: www.labelcraft.net
          >
          _____________________________________________________________________
          ____
          >
        • Ingar Steinsland
          Hi Maryam, Having a global pointer to CMainFrame makes it very easy to communicate with the CMainFrame class. You can, from any part of the program: 1) Sending
          Message 4 of 7 , Feb 4, 2007
          View Source
          • 0 Attachment
            Hi Maryam,

            Having a global pointer to CMainFrame makes it very easy to communicate with
            the CMainFrame class. You can, from any part of the program:

            1) Sending messages to CMainFram window using the m_hWnd handle in
            CMainFrame
            2) Calling functions in CMainFrame directly (without having to post
            messages).

            One example: Our program is language independent, reading ALL the messages
            from a text file. We have made a public function in CMainFrame called
            Txt_LoadString(int id,TCHAR buffer,int buflen).
            From obvious reasons it is very important that this function is
            globally accessible from anywhere in the program.

            Best regards,
            Ingar


            Maryam wrote:

            > Dear Ingar
            >
            > I don't get the idea,why have you defined a new CMainFrame pointer?
            > what's the use of this pointer in messaging problem I have described?
            >
            > will you explain more about this method?
            >

            > Thank you anyway,
            > Maryam.
            >
            > --- In wtl@yahoogroups.com <mailto:wtl%40yahoogroups.com>, Ingar
            > Steinsland <ingar@...> wrote:
            > >
            > > Hi Maryam,
            > >
            > > In our project we have done the following:
            > >
            > > In stdafx.h":
            > >
            > > class CMainFrame;
            > > extern CMainFrame* pWndMain;
            > >
            > > inline CMainFrame * AfxGetApp() {return pWndMain;}
            > >
            > > And then in our main startup module:
            > >
            > >
            > > CAppModule _Module;
            > > CMainFrame *pWndMain; // BUG: It works, but I am not very
            > happy
            > > about the solution
            > >
            > > ....
            > >
            > > pWndMain=new CMainFrame;
            > >
            > > LabField_Register(hInst); // Register special
            > > LabelCraft EDIT control
            > >
            > > CMessageLoop theLoop;
            > > _Module.AddMessageLoop(&theLoop);
            > >
            > > .....
            > >
            > > Although I am not VERY happy about the solution, it works. And
            > AfxGetApp
            > > is available everywhere
            > > in our application. Perhaps anyone has a better solution?
            > >
            > > Another thing we have seen (off topic) is that after we do
            > a "delete
            > > pWndMain", we cannot restart the
            > > appication with "pWndMain=new CMainFrame;" We get all sorts of
            > error
            > > messages, so it seems to me
            > > that WTL does not clean up properly after the main class has been
            > > deleted. Any ideas?
            > >
            > > Best regards,
            > > Ingar
            > >
            > >
            > >
            > > Maryam wrote:
            > >
            > > > I need to Post a Message from a child to the MainFrm to clean
            > the list
            > > > of a combobox right after I have closed the child, I use
            > PostMessage
            > > > inside the OnFinalMessage function,but the postmessage does not
            > work
            > > > properly because it doesn't find the m_hWnd it needs.
            > > > does anybody have any idea to implement this situation?
            > > >
            > > > Regards,
            > > > Maryam Kasravi.
            > > >
            > > >
            > >
            > >
            > >
            > > --
            > >
            > __________________________________________________________
            > ____
            > > Ingar Rune Steinsland, LabelCraft AS, P.O. Box 229, 1541 Vestby,
            > Norway
            > > Phone: 47+64982400/64982402 Cell: +4790055401 Fax: 47-
            > 64982401
            > > email: ingar@... web: www.labelcraft.net
            > >
            > __________________________________________________________
            > ____
            > >
            >
            >



            --
            _________________________________________________________________________
            Ingar Rune Steinsland, LabelCraft AS, P.O. Box 229, 1541 Vestby, Norway
            Phone: 47+64982400/64982402 Cell: +4790055401 Fax: 47-64982401
            email: ingar@... web: www.labelcraft.net
            _________________________________________________________________________
          Your message has been successfully submitted and would be delivered to recipients shortly.