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. Accessing values from dialog window

Accessing values from dialog window

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

    Hi,, I am retriving the some values frm previous window and storeing them the dialog i want to access those values in the thread function how to do that ??? below code i am seting the values for m_ctrlSNAME & m_ctrlSLOCATION which are displyed correctly i want to access these values in thread function but the values are not getting added to loc,can u please help me with this... BOOL CStatusDlg::OnInitDialog() { CDialog::OnInitDialog(); m_ctrlSNAME.SetWindowText(sfile); m_ctrlSLOCATION.SetWindowText(slocation); HANDLE hr; hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,this,0,0); return TRUE; } ------------------ UINT WorkerThreadProc(LPVOID Param) { CStatusDlg status; CString loc = status.slocation + status.sfile; -- --- } Regards, Vinay Charan.

    C D 2 Replies Last reply
    0
    • V VinayCool

      Hi,, I am retriving the some values frm previous window and storeing them the dialog i want to access those values in the thread function how to do that ??? below code i am seting the values for m_ctrlSNAME & m_ctrlSLOCATION which are displyed correctly i want to access these values in thread function but the values are not getting added to loc,can u please help me with this... BOOL CStatusDlg::OnInitDialog() { CDialog::OnInitDialog(); m_ctrlSNAME.SetWindowText(sfile); m_ctrlSLOCATION.SetWindowText(slocation); HANDLE hr; hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,this,0,0); return TRUE; } ------------------ UINT WorkerThreadProc(LPVOID Param) { CStatusDlg status; CString loc = status.slocation + status.sfile; -- --- } Regards, Vinay Charan.

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      vinaycool wrote:

      UINT WorkerThreadProc(LPVOID Param) { CStatusDlg status; CString loc = status.slocation + status.sfile; -- --- }

      What you are doing here is simply declaring a new instance of the CStatusDlg class (CDialog classes are still classes even if they are GUI 'components' ;) ). So, you are not accessing the data from the 'dialog' that is on the screen. I won't suggest you to pass the dialog through the thread data because it's bad to share MFC classes across thread. What you can do is send the required data only to your thread. But I think your design is not correct: if you start your thread in OnInitDialog, the user has not entered data on your dialog so the data is not valid. Why not start your thread later, when the user has entered data and requested your thread to be started (in general, if the thread is required for processing, the user start the processing right ?)


      Cédric Moonen Software developer
      Charting control

      V 1 Reply Last reply
      0
      • C Cedric Moonen

        vinaycool wrote:

        UINT WorkerThreadProc(LPVOID Param) { CStatusDlg status; CString loc = status.slocation + status.sfile; -- --- }

        What you are doing here is simply declaring a new instance of the CStatusDlg class (CDialog classes are still classes even if they are GUI 'components' ;) ). So, you are not accessing the data from the 'dialog' that is on the screen. I won't suggest you to pass the dialog through the thread data because it's bad to share MFC classes across thread. What you can do is send the required data only to your thread. But I think your design is not correct: if you start your thread in OnInitDialog, the user has not entered data on your dialog so the data is not valid. Why not start your thread later, when the user has entered data and requested your thread to be started (in general, if the thread is required for processing, the user start the processing right ?)


        Cédric Moonen Software developer
        Charting control

        V Offline
        V Offline
        VinayCool
        wrote on last edited by
        #3

        Hi Cédric Moonen, Thank you u very much for the reply. I have 3 dialog window, in which I am accepting data from the user in the 2nd dialog window and when the user press on start process ,it should display 3rd window and start processing immediately after dialog load so in the 3rd dialog window user has option or no need to enter any data. Since I have to 2 process Dialog load and also process I have used the Thread so that dialog loads and also processing also takes place .. For processing of data I need to access those values can u please tell me is there any way to do that … I want both the values in the thread function in the loc field can u help me with this…

        R 1 Reply Last reply
        0
        • V VinayCool

          Hi Cédric Moonen, Thank you u very much for the reply. I have 3 dialog window, in which I am accepting data from the user in the 2nd dialog window and when the user press on start process ,it should display 3rd window and start processing immediately after dialog load so in the 3rd dialog window user has option or no need to enter any data. Since I have to 2 process Dialog load and also process I have used the Thread so that dialog loads and also processing also takes place .. For processing of data I need to access those values can u please tell me is there any way to do that … I want both the values in the thread function in the loc field can u help me with this…

          R Offline
          R Offline
          Russell
          wrote on last edited by
          #4

          UINT WorkerThreadProc(LPVOID Param) You can access to the parameters through Param variable, if you are not still using that: interpret it as a pointer to the dialog that contains the variable members, and then reach the values:-D. If you are using Param in another way:( you could create a struct:) where you can store every information that needs to be passed to the thread. But, be carefull:~ : if you create a local (like in OnInitistance)instance of the structure, that will be destroyed when the function ends, i.e. before that the thread ends,....so goodby to the paramenters:(! You can solve this problem using a memeber variable into the first dialog or with dynamical memory allocation (but others problems cames to free the memory:sigh:). hope be clear

          V 2 Replies Last reply
          0
          • V VinayCool

            Hi,, I am retriving the some values frm previous window and storeing them the dialog i want to access those values in the thread function how to do that ??? below code i am seting the values for m_ctrlSNAME & m_ctrlSLOCATION which are displyed correctly i want to access these values in thread function but the values are not getting added to loc,can u please help me with this... BOOL CStatusDlg::OnInitDialog() { CDialog::OnInitDialog(); m_ctrlSNAME.SetWindowText(sfile); m_ctrlSLOCATION.SetWindowText(slocation); HANDLE hr; hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,this,0,0); return TRUE; } ------------------ UINT WorkerThreadProc(LPVOID Param) { CStatusDlg status; CString loc = status.slocation + status.sfile; -- --- } Regards, Vinay Charan.

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            vinaycool wrote:

            hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,this,0,0);

            You'll need to use AfxBeginThread() here.

            vinaycool wrote:

            CStatusDlg status;

            status will need to be a pointer to a CStatusDlg. You need to cast Param to this.


            "The largest fire starts but with the smallest spark." - David Crow

            V 2 Replies Last reply
            0
            • R Russell

              UINT WorkerThreadProc(LPVOID Param) You can access to the parameters through Param variable, if you are not still using that: interpret it as a pointer to the dialog that contains the variable members, and then reach the values:-D. If you are using Param in another way:( you could create a struct:) where you can store every information that needs to be passed to the thread. But, be carefull:~ : if you create a local (like in OnInitistance)instance of the structure, that will be destroyed when the function ends, i.e. before that the thread ends,....so goodby to the paramenters:(! You can solve this problem using a memeber variable into the first dialog or with dynamical memory allocation (but others problems cames to free the memory:sigh:). hope be clear

              V Offline
              V Offline
              VinayCool
              wrote on last edited by
              #6

              Hi _Russell_, Thanks for the wondeful reply and thanks a lot for giveing lot of information. I am very much new to VC++ and threds ,i just learned threads by some sample notes i am really very new to it ... can u please tell me how i have access the values in the thread without any problem can u please tell me with some examples or some code please.. BOOL CStatusDlg::OnInitDialog() { CDialog::OnInitDialog(); m_ctrlSNAME.SetWindowText(sfile); m_ctrlSLOCATION.SetWindowText(slocation); CString str; HANDLE hr; hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,this,0,0); return TRUE; } -------------------------------------------------------------- UINT WorkerThreadProc(LPVOID Param) { CStatusDlg status; //CString loc = status.slocation + status.sfile; char * d =(char *) (LPCTSTR) loc; return true; } ------------------------------------------------------------ please give me some solution so that i can access values from InitDialog and ican use them in Thread. will be watiing for your responce...

              1 Reply Last reply
              0
              • D David Crow

                vinaycool wrote:

                hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,this,0,0);

                You'll need to use AfxBeginThread() here.

                vinaycool wrote:

                CStatusDlg status;

                status will need to be a pointer to a CStatusDlg. You need to cast Param to this.


                "The largest fire starts but with the smallest spark." - David Crow

                V Offline
                V Offline
                VinayCool
                wrote on last edited by
                #7

                hi, Thanks for the responce ... Can u please tell me with an example so that i can understand the things well.

                1 Reply Last reply
                0
                • D David Crow

                  vinaycool wrote:

                  hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,this,0,0);

                  You'll need to use AfxBeginThread() here.

                  vinaycool wrote:

                  CStatusDlg status;

                  status will need to be a pointer to a CStatusDlg. You need to cast Param to this.


                  "The largest fire starts but with the smallest spark." - David Crow

                  V Offline
                  V Offline
                  VinayCool
                  wrote on last edited by
                  #8

                  Hi, I got the solutiion ..Thanks a lot for all the help ....:)

                  1 Reply Last reply
                  0
                  • R Russell

                    UINT WorkerThreadProc(LPVOID Param) You can access to the parameters through Param variable, if you are not still using that: interpret it as a pointer to the dialog that contains the variable members, and then reach the values:-D. If you are using Param in another way:( you could create a struct:) where you can store every information that needs to be passed to the thread. But, be carefull:~ : if you create a local (like in OnInitistance)instance of the structure, that will be destroyed when the function ends, i.e. before that the thread ends,....so goodby to the paramenters:(! You can solve this problem using a memeber variable into the first dialog or with dynamical memory allocation (but others problems cames to free the memory:sigh:). hope be clear

                    V Offline
                    V Offline
                    VinayCool
                    wrote on last edited by
                    #9

                    Hi, I got the solutiion ..Thanks a lot for all the help ....:) -- modified at 3:20 Thursday 18th May, 2006

                    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