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. How to spawn CDialog by CWinThread?

How to spawn CDialog by CWinThread?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++helptutorial
5 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.
  • P Offline
    P Offline
    pkyiu
    wrote on last edited by
    #1

    Hi gentlemen, I am newbie to MFC programming and I have a problem creating a dialog on a separate thread from the main application. My situation is: by clicking an icon on a toolbar, a dialog will be prompted and asking for input. As entered the numbers and clicked "OK", these parameters will be passed to the main application to run in a loop and the result will be displayed. Without threading, the displayed result is obstructed by the dialog and applying the InValidateRect function is not satisfactory since the toolbar now becomes invisible. Now I have create a "CSub" class based on CDialog and a "CDialogThread" class based on CWndThread. My question is, how to instruct the dialog to run on the thread, then how to pass the threaded dialog parameter back to the main application? Thank you very much! :)

    A K 2 Replies Last reply
    0
    • P pkyiu

      Hi gentlemen, I am newbie to MFC programming and I have a problem creating a dialog on a separate thread from the main application. My situation is: by clicking an icon on a toolbar, a dialog will be prompted and asking for input. As entered the numbers and clicked "OK", these parameters will be passed to the main application to run in a loop and the result will be displayed. Without threading, the displayed result is obstructed by the dialog and applying the InValidateRect function is not satisfactory since the toolbar now becomes invisible. Now I have create a "CSub" class based on CDialog and a "CDialogThread" class based on CWndThread. My question is, how to instruct the dialog to run on the thread, then how to pass the threaded dialog parameter back to the main application? Thank you very much! :)

      A Offline
      A Offline
      Arman S
      wrote on last edited by
      #2

      From what you explained I do not see any reason of introducing a new thread at least as far as the dialog concerns. Without threading, the displayed result is obstructed by the dialog and applying the InValidateRect function is not satisfactory since the toolbar now becomes invisible. This is not so clear. Why does the toolbar become invisible. What's the relationship between the dialog and InvalidateRect?

      -- ===== Arman

      P 1 Reply Last reply
      0
      • P pkyiu

        Hi gentlemen, I am newbie to MFC programming and I have a problem creating a dialog on a separate thread from the main application. My situation is: by clicking an icon on a toolbar, a dialog will be prompted and asking for input. As entered the numbers and clicked "OK", these parameters will be passed to the main application to run in a loop and the result will be displayed. Without threading, the displayed result is obstructed by the dialog and applying the InValidateRect function is not satisfactory since the toolbar now becomes invisible. Now I have create a "CSub" class based on CDialog and a "CDialogThread" class based on CWndThread. My question is, how to instruct the dialog to run on the thread, then how to pass the threaded dialog parameter back to the main application? Thank you very much! :)

        K Offline
        K Offline
        kasturi_haribabu
        wrote on last edited by
        #3

        Dear, You need not take that much pain to accomplish this. If all you need to inform is a count and some other simple parameters, why dont you put them in the APP, and once you got the parameters from the dialog, AfxGetAPP(), update / set variables and then... your task is done... regards, haribabu

        P 1 Reply Last reply
        0
        • A Arman S

          From what you explained I do not see any reason of introducing a new thread at least as far as the dialog concerns. Without threading, the displayed result is obstructed by the dialog and applying the InValidateRect function is not satisfactory since the toolbar now becomes invisible. This is not so clear. Why does the toolbar become invisible. What's the relationship between the dialog and InvalidateRect?

          -- ===== Arman

          P Offline
          P Offline
          pkyiu
          wrote on last edited by
          #4

          Hi Arman, Thank you for your reply. The application is a MDI and the dialog is called by a function of the CView class. After the dialog passes the parameters to this function, it runs a loop which preforms a calculation and display results on the childframe window. I tried to use InvalidateRect(NULL,NULL,true) inside the function before the loop but all the icons on the toolbar disappears and only reappears after the loop completes. If use InvalidateRect(m_hWnd,NULL,true) then the dialog only vanish if I clicked "OK" while the dialog is upon the childframe window. If the dialog is partially away from the childframe window, then it remains appear despite I clicked "OK". I was told that creating a separate processing thread for the dialog will solve the problem but I have little idea on multi threading with MFC. Hope you understand and thank you very much! :)

          1 Reply Last reply
          0
          • K kasturi_haribabu

            Dear, You need not take that much pain to accomplish this. If all you need to inform is a count and some other simple parameters, why dont you put them in the APP, and once you got the parameters from the dialog, AfxGetAPP(), update / set variables and then... your task is done... regards, haribabu

            P Offline
            P Offline
            pkyiu
            wrote on last edited by
            #5

            Hi, thank you very much. Do you mean the following? (1)in APP.cpp CDialog dialog int t1 = dialog.parameter1 (2)in View.cpp T1 = AfxgetApp()->t1 :)

            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