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. Can a WorkerThread do a SendMessage to a CDialog

Can a WorkerThread do a SendMessage to a CDialog

Scheduled Pinned Locked Moved C / C++ / MFC
9 Posts 6 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.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    Hi, I have a Worker thread started in my main thread CWinAPP and I am trying to do a SendMessage to a CDIalog seems I can only do a Send/PostMessage to the CMainFrame Main Window can someone corrabrate or dispute this and if so is there a way to get a Message to the CDialog thanks

    S CPalliniC E C 4 Replies Last reply
    0
    • F ForNow

      Hi, I have a Worker thread started in my main thread CWinAPP and I am trying to do a SendMessage to a CDIalog seems I can only do a Send/PostMessage to the CMainFrame Main Window can someone corrabrate or dispute this and if so is there a way to get a Message to the CDialog thanks

      S Offline
      S Offline
      Sivaraman Dhamodharan
      wrote on last edited by
      #2

      What kind of communication you want to make with the dialog? Is that dialog is alive when you send the message? Note that the Post message will not block your thread, and sendmessage will.

      Programming Article

      F 1 Reply Last reply
      0
      • F ForNow

        Hi, I have a Worker thread started in my main thread CWinAPP and I am trying to do a SendMessage to a CDIalog seems I can only do a Send/PostMessage to the CMainFrame Main Window can someone corrabrate or dispute this and if so is there a way to get a Message to the CDialog thanks

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        Before trying to use threads to communicate with the GUI I strongly suggest you reading some Newcomer's articles about. You may start, for instance with "Using Worker Threads"[^].

        Veni, vidi, vici.

        In testa che avete, signor di Ceprano?

        1 Reply Last reply
        0
        • S Sivaraman Dhamodharan

          What kind of communication you want to make with the dialog? Is that dialog is alive when you send the message? Note that the Post message will not block your thread, and sendmessage will.

          Programming Article

          F Offline
          F Offline
          ForNow
          wrote on last edited by
          #4

          The Thread is Created in the CWinApp::Initinstance seems like either Send/PostMessage always references the MainWinow CMainFrame I keep on getting CInvalidArg exception because my WIndow Handle is the CDialog

          1 Reply Last reply
          0
          • F ForNow

            Hi, I have a Worker thread started in my main thread CWinAPP and I am trying to do a SendMessage to a CDIalog seems I can only do a Send/PostMessage to the CMainFrame Main Window can someone corrabrate or dispute this and if so is there a way to get a Message to the CDialog thanks

            E Offline
            E Offline
            Eugen Podsypalnikov
            wrote on last edited by
            #5

            Please answer :) : - Whereby does the secondory thread know the dialog ? - When will the first message be sent ?

            They sought it with thimbles, they sought it with care; They pursued it with forks and hope; They threatened its life with a railway-share; They charmed it with smiles and soap. :)

            F 1 Reply Last reply
            0
            • E Eugen Podsypalnikov

              Please answer :) : - Whereby does the secondory thread know the dialog ? - When will the first message be sent ?

              They sought it with thimbles, they sought it with care; They pursued it with forks and hope; They threatened its life with a railway-share; They charmed it with smiles and soap. :)

              F Offline
              F Offline
              ForNow
              wrote on last edited by
              #6

              I save a CWnd * or Cialog * pointer in a global object on the heap The thread retervies that pointer However it seems that the Send/PostMessage can only send messages to the CMainFrame

              E A 2 Replies Last reply
              0
              • F ForNow

                I save a CWnd * or Cialog * pointer in a global object on the heap The thread retervies that pointer However it seems that the Send/PostMessage can only send messages to the CMainFrame

                E Offline
                E Offline
                Eugen Podsypalnikov
                wrote on last edited by
                #7

                Do you have such an "if" statement ? :) :

                {
                //..

                HWND hDlg = g_pcDialog->GetSafeHwnd();
                if (hDlg) {
                ::SendMessage(hDlg, WM_COMMAND, IDOK, 0);
                }

                //..
                }

                They sought it with thimbles, they sought it with care; They pursued it with forks and hope; They threatened its life with a railway-share; They charmed it with smiles and soap. :)

                1 Reply Last reply
                0
                • F ForNow

                  I save a CWnd * or Cialog * pointer in a global object on the heap The thread retervies that pointer However it seems that the Send/PostMessage can only send messages to the CMainFrame

                  A Offline
                  A Offline
                  Albert Holguin
                  wrote on last edited by
                  #8

                  ForNow wrote:

                  However it seems that the Send/PostMessage can only send messages to the CMainFrame

                  That's not true... you can post messages to any HWND[^] (which is the appropriate method versus saving a CWnd or CDialog). In another words, you can send messages to anything that has a window associated with it (not the only way, but it's a good generic statement), which sort of leads to a common way of messaging to classes that don't have other framework characteristics, make an invisible window for them that others can use as messaging targets.

                  1 Reply Last reply
                  0
                  • F ForNow

                    Hi, I have a Worker thread started in my main thread CWinAPP and I am trying to do a SendMessage to a CDIalog seems I can only do a Send/PostMessage to the CMainFrame Main Window can someone corrabrate or dispute this and if so is there a way to get a Message to the CDialog thanks

                    C Offline
                    C Offline
                    Chuck OToole
                    wrote on last edited by
                    #9

                    Note that SendMessage() cannot be used to send messages to controls that were *not* created by the thread sending the message. See my answer to This Question[^]

                    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