Window to Window comms - Parent to Parent

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Window to Window comms - Parent to Parent

    Dear all
    I wondered if you could help me solve this puzzle. Scenario is as follows: there are two unrelated windows (i.e. both windows are parents to different children), defined in two different source files.
    For example, I have a main window and a footer window, both visible. Then how do I communicate to the main window that the footer window wants to, for example, display something else on the main window?

    I know I can use WM_SendMessageNoPara(hWinMain, WM_FOOTER_BUTTON_BACK); in the footer callback. However that relies on having the main window handle (hWinMain) declared as global. Is there a way to communicate between the two parents without using globals? What's the best way?

    Thanks

    The post was edited 1 time, last by mjanas10 ().

  • Hi,

    Yes, it is possible without global variables. You can simply react on WM_GET_ID in the callback of a window and write a unique ID into pMsg->Data.v. This way you can use WM_GetDialogItem() to get the window handle via the ID.

    Attached is an example on how to do this.

    As long you know the IDS you could also get the handle of a child window of another window, like:

    C Source Code

    1. hItem = WM_GetDialogItem(WM_HBKWIN, ID_MAINWIN);
    2. hItem = WM_GetDialogItem(hItem, ID_CHILD);
    3. hItem = WM_GetDialogItem(hItem, ID_CHILD_OF_CHILD);
    4. hItem = WM_GetDialogItem(hItem, ID_CHILD_OF_CHILD_OF_CHILD);


    Regards
    Sven
    Files
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.