CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    201

    Question Dialog vs dialog (mfc)

    hello,

    the story;
    I have two dialogs (they belong to diff. processes)
    Dialog -A- has the focus (Dialog -B- is also on the screen),
    when I press a (control)-button in dialog -A- a text string has to be send
    to the edit control of Dialog -B-, using the keyboard event.
    but has Dialog -B- does not has the focus, nothing happens.
    Well, not what I want.

    quest;
    what can I do to make it work?

    regards,

    ger

  2. #2
    Join Date
    Feb 2002
    Posts
    3,788

    Re: Dialog vs dialog (mfc)

    Quote Originally Posted by TBBW View Post
    hello,

    the story;
    I have two dialogs (they belong to diff. processes)
    Dialog -A- has the focus (Dialog -B- is also on the screen),
    when I press a (control)-button in dialog -A- a text string has to be send
    to the edit control of Dialog -B-, using the keyboard event.
    but has Dialog -B- does not has the focus, nothing happens.
    Well, not what I want.

    quest;
    what can I do to make it work?

    regards,

    ger
    ::SendMessage (WM_USER_MSG, ...) from A to B.

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Dialog vs dialog (mfc)

    Bring Dialog B to the foreground and use SendInput.

  4. #4
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    201

    Re: Dialog vs dialog (mfc)

    @ Alin, tell a little bit more on the SendMessage

    @Arjay, I only control Dialog -A-
    I can do a FindWindow and set the focus to it.

    ger

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Dialog vs dialog (mfc)

    Quote Originally Posted by Alin View Post
    ::SendMessage (WM_USER_MSG, ...) from A to B.
    ...where WM_USER_MSG is a registered window message, isn't it?

    @To TBBW: Why do you want to send text from an edit control in a procss to an edit control in another process by using "using the keyboard event" ?.
    There are many other better methods.
    The easier one is sending WM_SETTEXT message.
    Last edited by ovidiucucu; April 30th, 2010 at 04:33 PM. Reason: typo
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  6. #6
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Dialog vs dialog (mfc)

    Oups!
    Quote Originally Posted by TBBW View Post
    @ Alin, tell a little bit more on the SendMessage
    Here is the story: http://msdn.microsoft.com/en-us/libr...50(VS.85).aspx
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  7. #7
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    201

    Re: Dialog vs dialog (mfc)

    I'm not transferring text from an edit control to an edit control.
    pushing a control button will send a static text string to the edit control of the other dialog.
    that is why i'm using the keyboard event, to simulate user input.

    as i'm still learning I do not know all options, I will have a go using the mention options.

    ger

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Dialog vs dialog (mfc)

    Using SendInput is the way to go.

  9. #9
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Dialog vs dialog (mfc)

    Quote Originally Posted by TBBW View Post
    I'm not transferring text from an edit control to an edit control.
    pushing a control button will send a static text string to the edit control of the other dialog.
    Please, excuse my ignorance!
    Why doing that via sending WM_SETTEXT is not possible?
    Last edited by ovidiucucu; April 30th, 2010 at 04:31 PM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  10. #10
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Dialog vs dialog (mfc)

    Call SetForegroundWindow before SendInput.

    See DiLascia's C++ Q&A from January 2005: "Sending Keystrokes to Any App" at http://msdn.microsoft.com/msdnmag/is...A/default.aspx

    Mike

  11. #11
    Join Date
    Oct 2009
    Location
    Holland
    Posts
    201

    Re: Dialog vs dialog (mfc)

    Thank you guys for all the much appriciated input !!

    the SetForegroundWindow() did the trick.
    tested both SendInput() and Keyboard_event()
    I could not observe any major diff. between them
    apart from the lines of codes needed.

    the only thing I observed, using the SendInput. Also the next, back buttons of the receiving
    dialog (Dialog -B-) are 'touched'. (this is the case if the control button sending the text is hit more
    than once.
    using the keyboard event did not created this problem.


    ger

  12. #12
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Dialog vs dialog (mfc)

    This unwanted behavior is an artifact of how you are using SendInput.

    Without seeing your code we can only speculate on what you are doing wrong.

  13. #13
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: Dialog vs dialog (mfc)

    Why not just get the pointer of first dialog in second dialog?
    A constructor of second dialog can take pointer of first dialog, and directly set the control's text.
    Yes, the appropriate control variable should be accessible to second dialog-class.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  14. #14
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: Dialog vs dialog (mfc)

    Oops. My bad! They are in different processes!
    You can use WM_SENDDATA to silently send the data to second dialog (application). The application would understand it, and would display the content.

    Please note that with Windows Vista and higher, UIPI and integrity may prevent sending messages from lower integrity process to higher integrity process!

    I would use named-pipes in this case.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  15. #15
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Dialog vs dialog (mfc)

    @Ajay - pretty sure the OP can't modify the source to Dialog B.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured